// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #include "sqliteDB.h" using namespace std; #define SQL_PREPARE(dpp, params, sdb, stmt, ret, Op) \ do { \ string schema; \ schema = Schema(params); \ sqlite3_prepare_v2 (*sdb, schema.c_str(), \ -1, &stmt , NULL); \ if (!stmt) { \ ldpp_dout(dpp, 0) <<"failed to prepare statement " \ <<"for Op("<(blob), blob_len); \ \ decode(param, b); \ }while(0); #define SQL_EXECUTE(dpp, params, stmt, cbk, args...) \ do{ \ const std::lock_guard lk(((DBOp*)(this))->mtx); \ if (!stmt) { \ ret = Prepare(dpp, params); \ } \ \ if (!stmt) { \ ldpp_dout(dpp, 0) <<"No prepared statement "<< dendl; \ goto out; \ } \ \ ret = Bind(dpp, params); \ if (ret) { \ ldpp_dout(dpp, 0) <<"Bind parameters failed for stmt(" <op, stmt, cbk); \ \ Reset(dpp, stmt); \ \ if (ret) { \ ldpp_dout(dpp, 0) <<"Execution failed for stmt(" <user_table.empty()) { params->user_table = getUserTable(); } if (params->user_table.empty()) { params->user_table = getUserTable(); } if (params->bucket_table.empty()) { params->bucket_table = getBucketTable(); } if (params->quota_table.empty()) { params->quota_table = getQuotaTable(); } if (params->lc_entry_table.empty()) { params->lc_entry_table = getLCEntryTable(); } if (params->lc_head_table.empty()) { params->lc_head_table = getLCHeadTable(); } p_params.user_table = params->user_table; p_params.bucket_table = params->bucket_table; p_params.quota_table = params->quota_table; p_params.lc_entry_table = params->lc_entry_table; p_params.lc_head_table = params->lc_head_table; p_params.op.query_str = params->op.query_str; bucket = params->op.bucket.info.bucket.name; if (!bucket.empty()) { if (params->object_table.empty()) { params->object_table = getObjectTable(bucket); } if (params->objectdata_table.empty()) { params->objectdata_table = getObjectDataTable(bucket); } if (params->object_view.empty()) { params->object_view = getObjectView(bucket); } if (params->object_trigger.empty()) { params->object_trigger = getObjectTrigger(bucket); } p_params.object_table = params->object_table; p_params.objectdata_table = params->objectdata_table; p_params.object_view = params->object_view; } return 0; } static int list_callback(void *None, int argc, char **argv, char **aname) { int i; for(i=0; i < argc; i++) { string arg = argv[i] ? argv[i] : "NULL"; cout<(&this->db, this->getDBname(), cct); dbops.RemoveUser = make_shared(&this->db, this->getDBname(), cct); dbops.GetUser = make_shared(&this->db, this->getDBname(), cct); dbops.InsertBucket = make_shared(&this->db, this->getDBname(), cct); dbops.UpdateBucket = make_shared(&this->db, this->getDBname(), cct); dbops.RemoveBucket = make_shared(&this->db, this->getDBname(), cct); dbops.GetBucket = make_shared(&this->db, this->getDBname(), cct); dbops.ListUserBuckets = make_shared(&this->db, this->getDBname(), cct); dbops.InsertLCEntry = make_shared(&this->db, this->getDBname(), cct); dbops.RemoveLCEntry = make_shared(&this->db, this->getDBname(), cct); dbops.GetLCEntry = make_shared(&this->db, this->getDBname(), cct); dbops.ListLCEntries = make_shared(&this->db, this->getDBname(), cct); dbops.InsertLCHead = make_shared(&this->db, this->getDBname(), cct); dbops.RemoveLCHead = make_shared(&this->db, this->getDBname(), cct); dbops.GetLCHead = make_shared(&this->db, this->getDBname(), cct); return 0; } void *SQLiteDB::openDB(const DoutPrefixProvider *dpp) { string dbname; int rc = 0; dbname = getDBfile(); if (dbname.empty()) { ldpp_dout(dpp, 0)<<"dbname is NULL" << dendl; goto out; } rc = sqlite3_open_v2(dbname.c_str(), (sqlite3**)&db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL); if (rc) { ldpp_dout(dpp, 0) <<"Cant open "<user_table); ret = exec(dpp, schema.c_str(), NULL); if (ret) ldpp_dout(dpp, 0)<<"DeleteUserTable failed " << dendl; ldpp_dout(dpp, 20)<<"DeleteUserTable suceeded " << dendl; return ret; } int SQLiteDB::DeleteBucketTable(const DoutPrefixProvider *dpp, DBOpParams *params) { int ret = -1; string schema; schema = DeleteTableSchema(params->bucket_table); ret = exec(dpp, schema.c_str(), NULL); if (ret) ldpp_dout(dpp, 0)<<"DeletebucketTable failed " << dendl; ldpp_dout(dpp, 20)<<"DeletebucketTable suceeded " << dendl; return ret; } int SQLiteDB::DeleteObjectTable(const DoutPrefixProvider *dpp, DBOpParams *params) { int ret = -1; string schema; schema = DeleteTableSchema(params->object_table); ret = exec(dpp, schema.c_str(), NULL); if (ret) ldpp_dout(dpp, 0)<<"DeleteObjectTable failed " << dendl; ldpp_dout(dpp, 20)<<"DeleteObjectTable suceeded " << dendl; return ret; } int SQLiteDB::DeleteObjectDataTable(const DoutPrefixProvider *dpp, DBOpParams *params) { int ret = -1; string schema; schema = DeleteTableSchema(params->objectdata_table); ret = exec(dpp, schema.c_str(), NULL); if (ret) ldpp_dout(dpp, 0)<<"DeleteObjectDataTable failed " << dendl; ldpp_dout(dpp, 20)<<"DeleteObjectDataTable suceeded " << dendl; return ret; } int SQLiteDB::DeleteQuotaTable(const DoutPrefixProvider *dpp, DBOpParams *params) { int ret = -1; string schema; schema = DeleteTableSchema(params->quota_table); ret = exec(dpp, schema.c_str(), NULL); if (ret) ldpp_dout(dpp, 0)<<"DeleteQuotaTable failed " << dendl; ldpp_dout(dpp, 20)<<"DeleteQuotaTable suceeded " << dendl; return ret; } int SQLiteDB::DeleteLCEntryTable(const DoutPrefixProvider *dpp, DBOpParams *params) { int ret = -1; string schema; schema = DeleteTableSchema(params->lc_entry_table); ret = exec(dpp, schema.c_str(), NULL); if (ret) ldpp_dout(dpp, 0)<<"DeleteLCEntryTable failed " << dendl; ldpp_dout(dpp, 20)<<"DeleteLCEntryTable suceeded " << dendl; return ret; } int SQLiteDB::DeleteLCHeadTable(const DoutPrefixProvider *dpp, DBOpParams *params) { int ret = -1; string schema; schema = DeleteTableSchema(params->lc_head_table); ret = exec(dpp, schema.c_str(), NULL); if (ret) ldpp_dout(dpp, 0)<<"DeleteLCHeadTable failed " << dendl; ldpp_dout(dpp, 20)<<"DeleteLCHeadTable suceeded " << dendl; return ret; } int SQLiteDB::ListAllUsers(const DoutPrefixProvider *dpp, DBOpParams *params) { int ret = -1; string schema; schema = ListTableSchema(params->user_table); ret = exec(dpp, schema.c_str(), &list_callback); if (ret) ldpp_dout(dpp, 0)<<"GetUsertable failed " << dendl; ldpp_dout(dpp, 20)<<"GetUserTable suceeded " << dendl; return ret; } int SQLiteDB::ListAllBuckets(const DoutPrefixProvider *dpp, DBOpParams *params) { int ret = -1; string schema; schema = ListTableSchema(params->bucket_table); ret = exec(dpp, schema.c_str(), &list_callback); if (ret) ldpp_dout(dpp, 0)<<"Listbuckettable failed " << dendl; ldpp_dout(dpp, 20)<<"ListbucketTable suceeded " << dendl; return ret; } int SQLiteDB::ListAllObjects(const DoutPrefixProvider *dpp, DBOpParams *params) { int ret = -1; string schema; map::iterator iter; map objectmap; string bucket; objectmap = getObjectMap(); if (objectmap.empty()) ldpp_dout(dpp, 20)<<"objectmap empty " << dendl; for (iter = objectmap.begin(); iter != objectmap.end(); ++iter) { bucket = iter->first; params->object_table = getObjectTable(bucket); schema = ListTableSchema(params->object_table); ret = exec(dpp, schema.c_str(), &list_callback); if (ret) ldpp_dout(dpp, 0)<<"ListObjecttable failed " << dendl; ldpp_dout(dpp, 20)<<"ListObjectTable suceeded " << dendl; } return ret; } int SQLObjectOp::InitializeObjectOps(string db_name, const DoutPrefixProvider *dpp) { PutObject = make_shared(sdb, db_name, cct); DeleteObject = make_shared(sdb, db_name, cct); GetObject = make_shared(sdb, db_name, cct); UpdateObject = make_shared(sdb, db_name, cct); ListBucketObjects = make_shared(sdb, db_name, cct); ListVersionedObjects = make_shared(sdb, db_name, cct); PutObjectData = make_shared(sdb, db_name, cct); UpdateObjectData = make_shared(sdb, db_name, cct); GetObjectData = make_shared(sdb, db_name, cct); DeleteObjectData = make_shared(sdb, db_name, cct); DeleteStaleObjectData = make_shared(sdb, db_name, cct); return 0; } int SQLInsertUser::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLInsertUser - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareInsertUser"); out: return ret; } int SQLInsertUser::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.tenant, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.user.uinfo.user_id.tenant.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.user_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.user.uinfo.user_id.id.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.ns, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.user.uinfo.user_id.ns.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.display_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.user.uinfo.display_name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.user_email, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.user.uinfo.user_email.c_str(), sdb); if (!params->op.user.uinfo.access_keys.empty()) { string access_key; string key; map::const_iterator it = params->op.user.uinfo.access_keys.begin(); const RGWAccessKey& k = it->second; access_key = k.id; key = k.key; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.access_keys_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, access_key.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.access_keys_secret, sdb); SQL_BIND_TEXT(dpp, stmt, index, key.c_str(), sdb); } SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.access_keys, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.user.uinfo.access_keys, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.swift_keys, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.user.uinfo.swift_keys, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.subusers, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.user.uinfo.subusers, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.suspended, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.user.uinfo.suspended, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.max_buckets, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.user.uinfo.max_buckets, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.op_mask, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.user.uinfo.op_mask, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.user_caps, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.user.uinfo.caps, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.admin, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.user.uinfo.admin, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.system, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.user.uinfo.system, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.placement_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.user.uinfo.default_placement.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.placement_storage_class, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.user.uinfo.default_placement.storage_class.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.placement_tags, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.user.uinfo.placement_tags, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.bucket_quota, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.user.uinfo.quota.bucket_quota, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.temp_url_keys, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.user.uinfo.temp_url_keys, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.user_quota, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.user.uinfo.quota.user_quota, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.type, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.user.uinfo.type, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.mfa_ids, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.user.uinfo.mfa_ids, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.user_attrs, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.user.user_attrs, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.user_ver, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.user.user_version.ver, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.user_ver_tag, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.user.user_version.tag.c_str(), sdb); out: return rc; } int SQLInsertUser::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLRemoveUser::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLRemoveUser - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareRemoveUser"); out: return ret; } int SQLRemoveUser::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.user_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.user.uinfo.user_id.id.c_str(), sdb); out: return rc; } int SQLRemoveUser::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLGetUser::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLGetUser - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); if (params->op.query_str == "email") { SQL_PREPARE(dpp, p_params, sdb, email_stmt, ret, "PrepareGetUser"); } else if (params->op.query_str == "access_key") { SQL_PREPARE(dpp, p_params, sdb, ak_stmt, ret, "PrepareGetUser"); } else if (params->op.query_str == "user_id") { SQL_PREPARE(dpp, p_params, sdb, userid_stmt, ret, "PrepareGetUser"); } else { // by default by userid SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareGetUser"); } out: return ret; } int SQLGetUser::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; if (params->op.query_str == "email") { SQL_BIND_INDEX(dpp, email_stmt, index, p_params.op.user.user_email, sdb); SQL_BIND_TEXT(dpp, email_stmt, index, params->op.user.uinfo.user_email.c_str(), sdb); } else if (params->op.query_str == "access_key") { if (!params->op.user.uinfo.access_keys.empty()) { string access_key; map::const_iterator it = params->op.user.uinfo.access_keys.begin(); const RGWAccessKey& k = it->second; access_key = k.id; SQL_BIND_INDEX(dpp, ak_stmt, index, p_params.op.user.access_keys_id, sdb); SQL_BIND_TEXT(dpp, ak_stmt, index, access_key.c_str(), sdb); } } else if (params->op.query_str == "user_id") { SQL_BIND_INDEX(dpp, userid_stmt, index, p_params.op.user.user_id, sdb); SQL_BIND_TEXT(dpp, userid_stmt, index, params->op.user.uinfo.user_id.id.c_str(), sdb); } else { // by default by userid SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.user_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.user.uinfo.user_id.id.c_str(), sdb); } out: return rc; } int SQLGetUser::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; if (params->op.query_str == "email") { SQL_EXECUTE(dpp, params, email_stmt, list_user); } else if (params->op.query_str == "access_key") { SQL_EXECUTE(dpp, params, ak_stmt, list_user); } else if (params->op.query_str == "user_id") { SQL_EXECUTE(dpp, params, userid_stmt, list_user); } else { // by default by userid SQL_EXECUTE(dpp, params, stmt, list_user); } out: return ret; } int SQLInsertBucket::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLInsertBucket - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareInsertBucket"); out: return ret; } int SQLInsertBucket::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; // user_id here is copied as OwnerID in the bucket table. SQL_BIND_INDEX(dpp, stmt, index, p_params.op.user.user_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.user.uinfo.user_id.id.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.tenant, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.tenant.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.marker, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.marker.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.bucket_id.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.size, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.bucket.ent.size, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.size_rounded, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.bucket.ent.size_rounded, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.creation_time, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.bucket.info.creation_time, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.count, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.bucket.ent.count, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.placement_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.placement_rule.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.placement_storage_class, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.placement_rule.storage_class.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.flags, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.bucket.info.flags, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.zonegroup, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.zonegroup.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.has_instance_obj, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.bucket.info.has_instance_obj, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.quota, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.bucket.info.quota, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.requester_pays, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.bucket.info.requester_pays, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.has_website, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.bucket.info.has_website, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.website_conf, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.bucket.info.website_conf, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.swift_versioning, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.bucket.info.swift_versioning, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.swift_ver_location, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.swift_ver_location.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.mdsearch_config, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.bucket.info.mdsearch_config, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.new_bucket_instance_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.new_bucket_instance_id.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.obj_lock, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.bucket.info.obj_lock, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.sync_policy_info_groups, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.bucket.info.sync_policy, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_attrs, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.bucket.bucket_attrs, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_ver, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.bucket.bucket_version.ver, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_ver_tag, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.bucket_version.tag.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.mtime, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.bucket.mtime, sdb); out: return rc; } int SQLInsertBucket::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; class SQLObjectOp *ObPtr = NULL; string bucket_name = params->op.bucket.info.bucket.name; struct DBOpPrepareParams p_params = PrepareParams; ObPtr = new SQLObjectOp(sdb, ctx()); objectmapInsert(dpp, bucket_name, ObPtr); SQL_EXECUTE(dpp, params, stmt, NULL); /* Once Bucket is inserted created corresponding object(&data) tables */ InitPrepareParams(dpp, p_params, params); (void)createObjectTable(dpp, params); (void)createObjectDataTable(dpp, params); (void)createObjectTableTrigger(dpp, params); out: return ret; } int SQLUpdateBucket::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLUpdateBucket - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); if (params->op.query_str == "attrs") { SQL_PREPARE(dpp, p_params, sdb, attrs_stmt, ret, "PrepareUpdateBucket"); } else if (params->op.query_str == "owner") { SQL_PREPARE(dpp, p_params, sdb, owner_stmt, ret, "PrepareUpdateBucket"); } else if (params->op.query_str == "info") { SQL_PREPARE(dpp, p_params, sdb, info_stmt, ret, "PrepareUpdateBucket"); } else { ldpp_dout(dpp, 0)<<"In SQLUpdateBucket invalid query_str:" << params->op.query_str << "" << dendl; goto out; } out: return ret; } int SQLUpdateBucket::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; sqlite3_stmt** stmt = NULL; // Prepared statement /* All below fields for attrs */ if (params->op.query_str == "attrs") { stmt = &attrs_stmt; } else if (params->op.query_str == "owner") { stmt = &owner_stmt; } else if (params->op.query_str == "info") { stmt = &info_stmt; } else { ldpp_dout(dpp, 0)<<"In SQLUpdateBucket invalid query_str:" << params->op.query_str << "" << dendl; goto out; } if (params->op.query_str == "attrs") { SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.bucket_attrs, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.bucket.bucket_attrs, sdb); } else if (params->op.query_str == "owner") { SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.creation_time, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.bucket.info.creation_time, sdb); } else if (params->op.query_str == "info") { SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.tenant, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.bucket.info.bucket.tenant.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.marker, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.bucket.info.bucket.marker.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.bucket_id, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.bucket.info.bucket.bucket_id.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.creation_time, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.bucket.info.creation_time, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.count, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.bucket.ent.count, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.placement_name, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.bucket.info.placement_rule.name.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.placement_storage_class, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.bucket.info.placement_rule.storage_class.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.flags, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.bucket.info.flags, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.zonegroup, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.bucket.info.zonegroup.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.has_instance_obj, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.bucket.info.has_instance_obj, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.quota, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.bucket.info.quota, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.requester_pays, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.bucket.info.requester_pays, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.has_website, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.bucket.info.has_website, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.website_conf, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.bucket.info.website_conf, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.swift_versioning, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.bucket.info.swift_versioning, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.swift_ver_location, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.bucket.info.swift_ver_location.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.mdsearch_config, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.bucket.info.mdsearch_config, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.new_bucket_instance_id, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.bucket.info.new_bucket_instance_id.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.obj_lock, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.bucket.info.obj_lock, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.sync_policy_info_groups, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.bucket.info.sync_policy, sdb); } SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.user.user_id, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.user.uinfo.user_id.id.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.bucket_ver, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.bucket.bucket_version.ver, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.mtime, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.bucket.mtime, sdb); out: return rc; } int SQLUpdateBucket::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; sqlite3_stmt** stmt = NULL; // Prepared statement if (params->op.query_str == "attrs") { stmt = &attrs_stmt; } else if (params->op.query_str == "owner") { stmt = &owner_stmt; } else if (params->op.query_str == "info") { stmt = &info_stmt; } else { ldpp_dout(dpp, 0)<<"In SQLUpdateBucket invalid query_str:" << params->op.query_str << "" << dendl; goto out; } SQL_EXECUTE(dpp, params, *stmt, NULL); out: return ret; } int SQLRemoveBucket::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLRemoveBucket - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareRemoveBucket"); out: return ret; } int SQLRemoveBucket::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); out: return rc; } int SQLRemoveBucket::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; objectmapDelete(dpp, params->op.bucket.info.bucket.name); SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLGetBucket::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLGetBucket - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareGetBucket"); out: return ret; } int SQLGetBucket::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); out: return rc; } int SQLGetBucket::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; class SQLObjectOp *ObPtr = NULL; params->op.name = "GetBucket"; ObPtr = new SQLObjectOp(sdb, ctx()); /* For the case when the server restarts, need to reinsert objectmap*/ objectmapInsert(dpp, params->op.bucket.info.bucket.name, ObPtr); SQL_EXECUTE(dpp, params, stmt, list_bucket); out: return ret; } int SQLListUserBuckets::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLListUserBuckets - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); if (params->op.query_str == "all") { SQL_PREPARE(dpp, p_params, sdb, all_stmt, ret, "PrepareListUserBuckets"); }else { SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareListUserBuckets"); } out: return ret; } int SQLListUserBuckets::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; sqlite3_stmt** pstmt = NULL; // Prepared statement if (params->op.query_str == "all") { pstmt = &all_stmt; } else { pstmt = &stmt; } if (params->op.query_str != "all") { SQL_BIND_INDEX(dpp, *pstmt, index, p_params.op.user.user_id, sdb); SQL_BIND_TEXT(dpp, *pstmt, index, params->op.user.uinfo.user_id.id.c_str(), sdb); } SQL_BIND_INDEX(dpp, *pstmt, index, p_params.op.bucket.min_marker, sdb); SQL_BIND_TEXT(dpp, *pstmt, index, params->op.bucket.min_marker.c_str(), sdb); SQL_BIND_INDEX(dpp, *pstmt, index, p_params.op.list_max_count, sdb); SQL_BIND_INT(dpp, *pstmt, index, params->op.list_max_count, sdb); out: return rc; } int SQLListUserBuckets::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; if (params->op.query_str == "all") { SQL_EXECUTE(dpp, params, all_stmt, list_bucket); } else { SQL_EXECUTE(dpp, params, stmt, list_bucket); } out: return ret; } int SQLPutObject::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLPutObject - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PreparePutObject"); out: return ret; } int SQLPutObject::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; int VersionNum = 0; struct DBOpPrepareParams p_params = PrepareParams; if (params->op.obj.state.obj.key.instance.empty()) { params->op.obj.state.obj.key.instance = "null"; } SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_instance, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.instance.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_ns, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.ns.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.acls, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.acls, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.index_ver, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.index_ver, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.tag, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.tag.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.flags, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.flags, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.versioned_epoch, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.versioned_epoch, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_category, sdb); SQL_BIND_INT(dpp, stmt, index, (uint8_t)(params->op.obj.category), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.etag, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.etag.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.owner, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.owner.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.owner_display_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.owner_display_name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.storage_class, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.storage_class.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.appendable, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.appendable, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.content_type, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.content_type.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.index_hash_source, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.index_hash_source.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_size, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.state.size, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.accounted_size, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.state.accounted_size, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.mtime, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.state.mtime, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.epoch, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.state.epoch, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_tag, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.state.obj_tag, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.tail_tag, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.state.tail_tag, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.write_tag, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.write_tag.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.fake_tag, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.state.fake_tag, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.shadow_obj, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.shadow_obj.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.has_data, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.state.has_data, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.is_versioned, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.is_versioned, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.version_num, sdb); SQL_BIND_INT(dpp, stmt, index, VersionNum, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.pg_ver, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.state.pg_ver, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.zone_short_id, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.state.zone_short_id, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_version, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.state.objv_tracker.read_version.ver, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_version_tag, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.objv_tracker.read_version.tag.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_attrs, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.state.attrset, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.head_size, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.head_size, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.max_head_size, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.max_head_size, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.obj_id.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.tail_instance, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.tail_instance.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.head_placement_rule_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.head_placement_rule.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.head_placement_storage_class, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.head_placement_rule.storage_class.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.tail_placement_rule_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.tail_placement.placement_rule.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.tail_placement_storage_class, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.tail_placement.placement_rule.storage_class.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.manifest_part_objs, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.objs, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.manifest_part_rules, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.rules, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.omap, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.omap, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.is_multipart, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj.is_multipart, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.mp_parts, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.mp_parts, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.head_data, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.head_data, sdb); out: return rc; } int SQLPutObject::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLDeleteObject::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLDeleteObject - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareDeleteObject"); out: return ret; } int SQLDeleteObject::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; if (params->op.obj.state.obj.key.instance.empty()) { params->op.obj.state.obj.key.instance = "null"; } SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_instance, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.instance.c_str(), sdb); out: return rc; } int SQLDeleteObject::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLGetObject::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLGetObject - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareGetObject"); out: return ret; } int SQLGetObject::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; if (params->op.obj.state.obj.key.instance.empty()) { params->op.obj.state.obj.key.instance = "null"; } SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_instance, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.instance.c_str(), sdb); out: return rc; } int SQLGetObject::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, list_object); out: return ret; } int SQLUpdateObject::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; struct DBOpParams copy = *params; string bucket_name; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLUpdateObject - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); if (params->op.query_str == "omap") { SQL_PREPARE(dpp, p_params, sdb, omap_stmt, ret, "PrepareUpdateObject"); } else if (params->op.query_str == "attrs") { SQL_PREPARE(dpp, p_params, sdb, attrs_stmt, ret, "PrepareUpdateObject"); } else if (params->op.query_str == "meta") { SQL_PREPARE(dpp, p_params, sdb, meta_stmt, ret, "PrepareUpdateObject"); } else if (params->op.query_str == "mp") { SQL_PREPARE(dpp, p_params, sdb, mp_stmt, ret, "PrepareUpdateObject"); } else { ldpp_dout(dpp, 0)<<"In SQLUpdateObject invalid query_str:" << params->op.query_str << dendl; goto out; } out: return ret; } int SQLUpdateObject::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; sqlite3_stmt** stmt = NULL; // Prepared statement /* All below fields for attrs */ if (params->op.query_str == "omap") { stmt = &omap_stmt; } else if (params->op.query_str == "attrs") { stmt = &attrs_stmt; } else if (params->op.query_str == "meta") { stmt = &meta_stmt; } else if (params->op.query_str == "mp") { stmt = &mp_stmt; } else { ldpp_dout(dpp, 0)<<"In SQLUpdateObject invalid query_str:" << params->op.query_str << dendl; goto out; } if (params->op.obj.state.obj.key.instance.empty()) { params->op.obj.state.obj.key.instance = "null"; } SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.obj_name, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.state.obj.key.name.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.obj_instance, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.state.obj.key.instance.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.mtime, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.state.mtime, sdb); if (params->op.query_str == "omap") { SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.omap, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.omap, sdb); } if (params->op.query_str == "attrs") { SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.obj_attrs, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.state.attrset, sdb); } if (params->op.query_str == "mp") { SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.mp_parts, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.mp_parts, sdb); } if (params->op.query_str == "meta") { SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.obj_ns, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.state.obj.key.ns.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.acls, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.acls, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.index_ver, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.index_ver, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.tag, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.tag.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.flags, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.flags, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.versioned_epoch, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.versioned_epoch, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.obj_category, sdb); SQL_BIND_INT(dpp, *stmt, index, (uint8_t)(params->op.obj.category), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.etag, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.etag.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.owner, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.owner.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.owner_display_name, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.owner_display_name.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.storage_class, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.storage_class.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.appendable, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.appendable, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.content_type, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.content_type.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.index_hash_source, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.state.obj.index_hash_source.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.obj_size, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.state.size, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.accounted_size, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.state.accounted_size, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.epoch, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.state.epoch, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.obj_tag, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.state.obj_tag, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.tail_tag, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.state.tail_tag, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.write_tag, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.state.write_tag.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.fake_tag, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.state.fake_tag, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.shadow_obj, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.state.shadow_obj.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.has_data, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.state.has_data, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.is_versioned, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.is_versioned, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.version_num, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.version_num, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.pg_ver, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.state.pg_ver, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.zone_short_id, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.state.zone_short_id, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.obj_version, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.state.objv_tracker.read_version.ver, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.obj_version_tag, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.state.objv_tracker.read_version.tag.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.obj_attrs, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.state.attrset, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.head_size, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.head_size, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.max_head_size, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.max_head_size, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.obj_id, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.obj_id.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.tail_instance, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.tail_instance.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.head_placement_rule_name, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.head_placement_rule.name.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.head_placement_storage_class, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.head_placement_rule.storage_class.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.tail_placement_rule_name, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.tail_placement.placement_rule.name.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.tail_placement_storage_class, sdb); SQL_BIND_TEXT(dpp, *stmt, index, params->op.obj.tail_placement.placement_rule.storage_class.c_str(), sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.manifest_part_objs, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.objs, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.manifest_part_rules, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.rules, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.omap, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.omap, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.is_multipart, sdb); SQL_BIND_INT(dpp, *stmt, index, params->op.obj.is_multipart, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.mp_parts, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.mp_parts, sdb); SQL_BIND_INDEX(dpp, *stmt, index, p_params.op.obj.head_data, sdb); SQL_ENCODE_BLOB_PARAM(dpp, *stmt, index, params->op.obj.head_data, sdb); } out: return rc; } int SQLUpdateObject::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; sqlite3_stmt** stmt = NULL; // Prepared statement if (params->op.query_str == "omap") { stmt = &omap_stmt; } else if (params->op.query_str == "attrs") { stmt = &attrs_stmt; } else if (params->op.query_str == "meta") { stmt = &meta_stmt; } else if (params->op.query_str == "mp") { stmt = &mp_stmt; } else { ldpp_dout(dpp, 0)<<"In SQLUpdateObject invalid query_str:" << params->op.query_str << dendl; goto out; } SQL_EXECUTE(dpp, params, *stmt, NULL); out: return ret; } int SQLListBucketObjects::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLListBucketObjects - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareListBucketObjects"); out: return ret; } int SQLListBucketObjects::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; if (params->op.obj.state.obj.key.instance.empty()) { params->op.obj.state.obj.key.instance = "null"; } SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.min_marker, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.min_marker.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.prefix, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.prefix.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.list_max_count, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.list_max_count, sdb); out: return rc; } int SQLListBucketObjects::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, list_object); out: return ret; } int SQLListVersionedObjects::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLListVersionedObjects - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareListVersionedObjects"); out: return ret; } int SQLListVersionedObjects::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; if (params->op.obj.state.obj.key.instance.empty()) { params->op.obj.state.obj.key.instance = "null"; } SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.list_max_count, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.list_max_count, sdb); out: return rc; } int SQLListVersionedObjects::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, list_object); out: return ret; } int SQLPutObjectData::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLPutObjectData - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PreparePutObjectData"); out: return ret; } int SQLPutObjectData::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; if (params->op.obj.state.obj.key.instance.empty()) { params->op.obj.state.obj.key.instance = "null"; } SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_instance, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.instance.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_ns, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.ns.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.obj_id.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj_data.part_num, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj_data.part_num, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj_data.offset, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj_data.offset, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj_data.data, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj_data.data, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj_data.size, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.obj_data.size, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj_data.multipart_part_str, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj_data.multipart_part_str.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.mtime, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.state.mtime, sdb); out: return rc; } int SQLPutObjectData::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLUpdateObjectData::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLUpdateObjectData - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareUpdateObjectData"); out: return ret; } int SQLUpdateObjectData::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; if (params->op.obj.state.obj.key.instance.empty()) { params->op.obj.state.obj.key.instance = "null"; } SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_instance, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.instance.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.obj_id.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.mtime, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.state.mtime, sdb); out: return rc; } int SQLUpdateObjectData::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLGetObjectData::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLGetObjectData - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareGetObjectData"); out: return ret; } int SQLGetObjectData::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; if (params->op.obj.state.obj.key.instance.empty()) { params->op.obj.state.obj.key.instance = "null"; } SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_instance, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.instance.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.obj_id.c_str(), sdb); out: return rc; } int SQLGetObjectData::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, get_objectdata); out: return ret; } int SQLDeleteObjectData::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLDeleteObjectData - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareDeleteObjectData"); out: return ret; } int SQLDeleteObjectData::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; if (params->op.obj.state.obj.key.instance.empty()) { params->op.obj.state.obj.key.instance = "null"; } SQL_BIND_INDEX(dpp, stmt, index, p_params.op.bucket.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.bucket.info.bucket.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.name.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_instance, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.state.obj.key.instance.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.obj_id, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.obj.obj_id.c_str(), sdb); out: return rc; } int SQLDeleteObjectData::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLDeleteStaleObjectData::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLDeleteStaleObjectData - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareDeleteStaleObjectData"); out: return ret; } int SQLDeleteStaleObjectData::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.obj.mtime, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, params->op.obj.state.mtime, sdb); out: return rc; } int SQLDeleteStaleObjectData::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLInsertLCEntry::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLInsertLCEntry - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareInsertLCEntry"); out: return ret; } int SQLInsertLCEntry::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.index, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.index.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.entry.get_bucket().c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.status, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.lc_entry.entry.get_status(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.start_time, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.lc_entry.entry.get_start_time(), sdb); out: return rc; } int SQLInsertLCEntry::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLRemoveLCEntry::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLRemoveLCEntry - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareRemoveLCEntry"); out: return ret; } int SQLRemoveLCEntry::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.index, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.index.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.bucket_name, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.entry.get_bucket().c_str(), sdb); out: return rc; } int SQLRemoveLCEntry::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLGetLCEntry::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; sqlite3_stmt** pstmt = NULL; // Prepared statement struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLGetLCEntry - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); if (params->op.query_str == "get_next_entry") { pstmt = &next_stmt; } else { pstmt = &stmt; } SQL_PREPARE(dpp, p_params, sdb, *pstmt, ret, "PrepareGetLCEntry"); out: return ret; } int SQLGetLCEntry::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; sqlite3_stmt** pstmt = NULL; // Prepared statement if (params->op.query_str == "get_next_entry") { pstmt = &next_stmt; } else { pstmt = &stmt; } SQL_BIND_INDEX(dpp, *pstmt, index, p_params.op.lc_entry.index, sdb); SQL_BIND_TEXT(dpp, *pstmt, index, params->op.lc_entry.index.c_str(), sdb); SQL_BIND_INDEX(dpp, *pstmt, index, p_params.op.lc_entry.bucket_name, sdb); SQL_BIND_TEXT(dpp, *pstmt, index, params->op.lc_entry.entry.get_bucket().c_str(), sdb); out: return rc; } int SQLGetLCEntry::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; sqlite3_stmt** pstmt = NULL; // Prepared statement if (params->op.query_str == "get_next_entry") { pstmt = &next_stmt; } else { pstmt = &stmt; } SQL_EXECUTE(dpp, params, *pstmt, list_lc_entry); out: return ret; } int SQLListLCEntries::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLListLCEntries - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareListLCEntries"); out: return ret; } int SQLListLCEntries::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.index, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.index.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.min_marker, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.min_marker.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.list_max_count, sdb); SQL_BIND_INT(dpp, stmt, index, params->op.list_max_count, sdb); out: return rc; } int SQLListLCEntries::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, list_lc_entry); out: return ret; } int SQLInsertLCHead::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLInsertLCHead - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareInsertLCHead"); out: return ret; } int SQLInsertLCHead::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_head.index, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_head.index.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_head.marker, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_head.head.get_marker().c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_head.start_date, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, static_cast(params->op.lc_head.head.start_date), sdb); out: return rc; } int SQLInsertLCHead::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLRemoveLCHead::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLRemoveLCHead - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareRemoveLCHead"); out: return ret; } int SQLRemoveLCHead::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_head.index, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_head.index.c_str(), sdb); out: return rc; } int SQLRemoveLCHead::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; SQL_EXECUTE(dpp, params, stmt, NULL); out: return ret; } int SQLGetLCHead::Prepare(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; struct DBOpPrepareParams p_params = PrepareParams; if (!*sdb) { ldpp_dout(dpp, 0)<<"In SQLGetLCHead - no db" << dendl; goto out; } InitPrepareParams(dpp, p_params, params); SQL_PREPARE(dpp, p_params, sdb, stmt, ret, "PrepareGetLCHead"); out: return ret; } int SQLGetLCHead::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int index = -1; int rc = 0; struct DBOpPrepareParams p_params = PrepareParams; SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_head.index, sdb); SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_head.index.c_str(), sdb); out: return rc; } int SQLGetLCHead::Execute(const DoutPrefixProvider *dpp, struct DBOpParams *params) { int ret = -1; // clear the params before fetching the entry params->op.lc_head.head = {}; SQL_EXECUTE(dpp, params, stmt, list_lc_head); out: return ret; }