diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp index 6bf152277f01eeeb88cd8e808814df1ab9819582..668718c8dd4158d8484459b5f03a239ed709c783 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp @@ -50,10 +50,8 @@ int32_t GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter return GRD_INVALID_ARGS; } int ret = db->store_->UpdateDocument(collectionName, filter, update, flags); - if (ret == 1) { - return 1; // The amount of text updated - } else if (ret == 0) { - return 0; + if (ret >= 0) { + return ret; } return TransferDocErr(ret); } @@ -65,10 +63,8 @@ int32_t GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter return GRD_INVALID_ARGS; } int ret = db->store_->UpsertDocument(collectionName, filter, document, flags); - if (ret == 1) { - return 1; // The amount of text updated - } else if (ret == 0) { - return 0; + if (ret >= 0) { + return ret; } return TransferDocErr(ret); } @@ -105,9 +101,6 @@ int32_t GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, uint32_ query.filter == nullptr || query.projection == nullptr) { return GRD_INVALID_ARGS; } - if (db->store_->IsCollectionOpening(collectionName)) { - return GRD_RESOURCE_BUSY; - } GRD_ResultSet *grdResultSet = new (std::nothrow) GRD_ResultSet(); if (grdResultSet == nullptr) { GLOGE("Memory allocation failed!"); @@ -116,7 +109,6 @@ int32_t GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, uint32_ int ret = db->store_->FindDocument(collectionName, query.filter, query.projection, flags, grdResultSet); if (ret != E_OK) { delete grdResultSet; - *resultSet = nullptr; return TransferDocErr(ret); } *resultSet = grdResultSet; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp index 19b681a2cf21adfab512f27ed140829d8f80a1d9..296dbe582273a1adb46a58fdecc21d667445bfa3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp @@ -29,7 +29,7 @@ int32_t GRD_Next(GRD_ResultSet *resultSet) GLOGE("resultSet is nullptr"); return GRD_INVALID_ARGS; }; - int ret = resultSet->resultSet_.GetNext(); + int ret = resultSet->resultSet_.GetNext(true, true); return TransferDocErr(ret); } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h index 950ca7b7c9409a836699bc5ce95c4bc17f2fe8d5..5c91d1d83e49107ce46cbf5543c7a992edf50efc 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h @@ -57,9 +57,15 @@ public: int Close(uint32_t flags); + int StartTransaction(); + int Commit(); + int Rollback(); + + bool IsCollectionExists(const std::string &collectionName, int &errCode); + + std::mutex dbMutex_; private: int GetViewType(JsonObject &jsonObj, bool &viewType); - std::mutex dbMutex_; KvStoreExecutor *executor_ = nullptr; std::map collections_; std::function closeNotifier_; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h index 208f6ecd5011ee3fe3becf67430d2ec0a9468c4d..f72a93c2e2a8b5965373d5000c70edb8d019ce08 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h @@ -35,12 +35,13 @@ public: int Init(DocumentStore *store, const std::string collectionName, const std::string &filter, std::vector> &path, bool ifShowId, bool viewType, bool &isOnlyId); int Init(DocumentStore *store, const std::string collectionName, const std::string &filter); - int GetNext(); + int GetNext(bool isNeedTransaction = false, bool isNeedCheckTable = false); int GetValue(char **value); int GetKey(std::string &key); int EraseCollection(); private: + int GetNextInner(bool isNeedCheckTable); int CutJsonBranch(std::string &jsonData); int CheckCutNode(JsonObject *node, std::vector singleCutPath, std::vector> &allCutPath); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp index 94f962c8e2ba71eb144a808262447d98af5b5151..a45056d06c56b6e63c68e87a5848dcf160979146 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp @@ -56,6 +56,14 @@ int Collection::InsertDocument(const Key &key, const Value &document) if (executor_ == nullptr) { return -E_INNER_ERROR; } + int errCode = E_OK; + bool isCollectionExist = IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!isCollectionExist) { + return -E_INVALID_ARGS; + } return executor_->InsertData(name_, key, document); } @@ -64,7 +72,7 @@ bool Collection::FindDocument() if (executor_ == nullptr) { return -E_INNER_ERROR; } - int errCode = 0; + int errCode = E_OK; return executor_->IsCollectionExists(name_, errCode); } @@ -90,6 +98,14 @@ int Collection::DeleteDocument(const Key &key) if (executor_ == nullptr) { return -E_INNER_ERROR; } + int errCode = E_OK; + bool isCollectionExist = IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!isCollectionExist) { + return -E_INVALID_ARGS; + } return executor_->DelData(name_, key); } @@ -111,7 +127,7 @@ int Collection::UpsertDocument(const std::string &id, const std::string &documen } if (!isCollExist) { GLOGE("Collection not created."); - return -E_NO_DATA; + return -E_INVALID_ARGS; } JsonObject upsertValue = JsonObject::Parse(document, errCode, true); @@ -167,7 +183,7 @@ int Collection::UpdateDocument(const std::string &id, const std::string &update, } if (!isCollExist) { GLOGE("Collection not created."); - return -E_NO_DATA; + return -E_INVALID_ARGS; } JsonObject updateValue = JsonObject::Parse(update, errCode, true); @@ -187,7 +203,6 @@ int Collection::UpdateDocument(const std::string &id, const std::string &update, GLOGE("Get original document failed. %d", errCode); return errCode; } - GLOGD("Update document value."); JsonObject originValue = JsonObject::Parse(valueGotStr, errCode, true); if (errCode != E_OK) { GLOGD("Parse original value failed. %d %s", errCode, valueGotStr.c_str()); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp index bf5e02a000dc85e9d010044fd6daf1fc3ed2ffad..60f50c1368ac24be7ffb0055eee28b5865cd5e7a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp @@ -56,6 +56,9 @@ int DocumentStore::CreateCollection(const std::string &name, const std::string & } std::lock_guard lock(dbMutex_); + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } errCode = executor_->StartTransaction(); if (errCode != E_OK) { return errCode; @@ -94,6 +97,9 @@ int DocumentStore::DropCollection(const std::string &name, uint32_t flags) bool ignoreNonExists = (flags != CHK_NON_EXIST_COLLECTION); std::lock_guard lock(dbMutex_); + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } errCode = executor_->StartTransaction(); if (errCode != E_OK) { return errCode; @@ -173,52 +179,48 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri return errCode; } bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); - Collection coll = Collection(collection, executor_); - if (isOnlyId) { - JsonObject filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); - std::string docId = idValue.GetStringValue(); - std::lock_guard lock(dbMutex_); - bool isCollectionExist = coll.IsCollectionExists(errCode); - if (errCode != E_OK) { - return errCode; - } - if (!isCollectionExist) { - return -E_INVALID_ARGS; - } - errCode = coll.UpdateDocument(docId, update, isReplace); - if (errCode == E_OK) { - errCode = 1; // upsert one record. - } else if (errCode == -E_NOT_FOUND) { - errCode = E_OK; - } - return errCode; - } - ResultSet resultSet; - InitResultSet(this, collection, filter, resultSet); std::lock_guard lock(dbMutex_); - bool isCollectionExist = coll.IsCollectionExists(errCode); - if (errCode != E_OK) { - return errCode; + if (executor_ == nullptr) { + return -E_INNER_ERROR; } - if (!isCollectionExist) { - return -E_INVALID_ARGS; - } - errCode = resultSet.GetNext(); - if (errCode == -E_NO_DATA) { - return 0; // The amount of text updated - } else if (errCode != E_OK) { + errCode = executor_->StartTransaction(); + if (errCode != E_OK) { return errCode; } std::string docId; - resultSet.GetKey(docId); + int count = 0; + auto coll = Collection(collection, executor_); + if (isOnlyId) { + auto filterObjChild = filterObj.GetChild(); + auto idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); + docId = idValue.GetStringValue(); + } else { + ResultSet resultSet; + InitResultSet(this, collection, filter, resultSet); + // no start transaction inner + errCode = resultSet.GetNext(false, true); + if (errCode == -E_NO_DATA) { + // no need to set count + errCode = E_OK; + goto END; + } else if (errCode != E_OK) { + goto END; + } + resultSet.GetKey(docId); + } errCode = coll.UpdateDocument(docId, update, isReplace); if (errCode == E_OK) { - errCode = 1; // update one record. + count++; } else if (errCode == -E_NOT_FOUND) { errCode = E_OK; } - return errCode; +END: + if (errCode == E_OK) { + executor_->Commit(); + } else { + executor_->Rollback(); + } + return (errCode == E_OK) ? count : errCode; } int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, @@ -271,69 +273,65 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri if (errCode != E_OK) { return errCode; } + std::lock_guard lock(dbMutex_); + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } + errCode = executor_->StartTransaction(); + if (errCode != E_OK) { + return errCode; + } Collection coll = Collection(collection, executor_); + int count = 0; + std::string targetDocument; + std::string docId; if (isOnlyId) { - std::lock_guard lock(dbMutex_); - bool isCollectionExist = coll.IsCollectionExists(errCode); - if (errCode != E_OK) { - return errCode; - } - if (!isCollectionExist) { - return -E_INVALID_ARGS; - } - JsonObject filterObjChild = filterObj.GetChild(); + auto filterObjChild = filterObj.GetChild(); ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); - std::string docId = idValue.GetStringValue(); + docId = idValue.GetStringValue(); JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); documentObj.InsertItemObject(0, idObj); - std::string addedIdDocument = documentObj.Print(); - errCode = coll.UpsertDocument(docId, addedIdDocument, isReplace); + targetDocument = documentObj.Print(); + } else { + bool isIdExist; + auto filterObjChild = filterObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID, isIdExist); if (!isIdExist) { + errCode = -E_INVALID_ARGS; + goto END; + } + ResultSet resultSet; + InitResultSet(this, collection, filter, resultSet); + errCode = resultSet.GetNext(false, true); + bool isfilterMatch = false; if (errCode == E_OK) { - errCode = 1; // upsert one record. - } else if (errCode == -E_NOT_FOUND) { - errCode = E_OK; + isfilterMatch = true; + } + docId = idValue.GetStringValue(); + JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); + documentObj.InsertItemObject(0, idObj); + targetDocument = documentObj.Print(); + Value ValueDocument; + Key key(docId.begin(), docId.end()); + errCode = coll.GetDocument(key, ValueDocument); + if (errCode == E_OK && !(isfilterMatch)) { + GLOGE("id exist but filter does not match, data conflict"); + errCode = -E_DATA_CONFLICT; + goto END; } - return errCode; - } - bool isIdExist; - JsonObject filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID, isIdExist); - if (!isIdExist) { - return -E_INVALID_ARGS; - } - std::lock_guard lock(dbMutex_); - bool isCollectionExist = coll.IsCollectionExists(errCode); - if (errCode != E_OK) { - return errCode; - } - if (!isCollectionExist) { - return -E_INVALID_ARGS; } - ResultSet resultSet; - InitResultSet(this, collection, filter, resultSet); - errCode = resultSet.GetNext(); - bool isfilterMatch = false; - if (errCode == E_OK) { - isfilterMatch = true; - } - std::string docId = idValue.GetStringValue(); - JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); - documentObj.InsertItemObject(0, idObj); - std::string addedIdDocument = documentObj.Print(); - Value ValueDocument; - Key key(docId.begin(), docId.end()); - errCode = coll.GetDocument(key, ValueDocument); - if (errCode == E_OK && !(isfilterMatch)) { - GLOGE("id exist but filter does not match, data conflict"); - return -E_DATA_CONFLICT; - } - errCode = coll.UpsertDocument(docId, addedIdDocument, isReplace); + errCode = coll.UpsertDocument(docId, targetDocument, isReplace); if (errCode == E_OK) { - errCode = 1; // upsert one record. + count++; } else if (errCode == -E_NOT_FOUND) { errCode = E_OK; } - return errCode; +END: + if (errCode == E_OK) { + executor_->Commit(); + } else { + executor_->Rollback(); + } + return (errCode == E_OK) ? count : errCode; } int DocumentStore::InsertDocument(const std::string &collection, const std::string &document, uint32_t flags) @@ -368,14 +366,6 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri Value value(document.begin(), document.end()); std::lock_guard lock(dbMutex_); Collection coll = Collection(collection, executor_); - bool isCollectionExist = coll.IsCollectionExists(errCode); - if (errCode != E_OK) { - return errCode; - } - if (!isCollectionExist) { - return -E_INVALID_ARGS; - } - Value ValueDocument; return coll.InsertDocument(key, value); } @@ -414,40 +404,40 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri if (errCode != E_OK) { return errCode; } + std::lock_guard lock(dbMutex_); + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } Collection coll = Collection(collection, executor_); + errCode = executor_->StartTransaction(); + if (errCode != E_OK) { + return errCode; + } + std::string id; if (isOnlyId) { - JsonObject filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); - std::string id = idValue.GetStringValue(); - Key key(id.begin(), id.end()); - std::lock_guard lock(dbMutex_); - bool isCollectionExist = coll.IsCollectionExists(errCode); + auto filterObjChild = filterObj.GetChild(); + auto idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); + id = idValue.GetStringValue(); + } else { + ResultSet resultSet; + InitResultSet(this, collection, filter, resultSet); + errCode = resultSet.GetNext(false, true); if (errCode != E_OK) { - return errCode; - } - if (!isCollectionExist) { - return -E_INVALID_ARGS; + goto END; } - return coll.DeleteDocument(key); + resultSet.GetKey(id); } - ResultSet resultSet; - InitResultSet(this, collection, filter, resultSet); - std::lock_guard lock(dbMutex_); - bool isCollectionExist = coll.IsCollectionExists(errCode); - if (errCode != E_OK) { - return errCode; - } - if (!isCollectionExist) { - return -E_INVALID_ARGS; +END: + if (errCode == E_OK) { + Key key(id.begin(), id.end()); + errCode = coll.DeleteDocument(key); } - errCode = resultSet.GetNext(); - if (errCode != E_OK) { - return errCode; + if (errCode == E_OK || errCode == E_NOT_FOUND) { + executor_->Commit(); + } else { + executor_->Rollback(); } - std::string id; - resultSet.GetKey(id); - Key key(id.begin(), id.end()); - return coll.DeleteDocument(key); + return errCode; } Collection DocumentStore::GetCollection(std::string &collectionName) { @@ -518,30 +508,38 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string } std::lock_guard lock(dbMutex_); Collection coll = Collection(collection, executor_); - bool isCollectionExist = coll.IsCollectionExists(errCode); + if (IsCollectionOpening(collection)) { + return -E_RESOURCE_BUSY; + } + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } + errCode = executor_->StartTransaction(); if (errCode != E_OK) { return errCode; } + bool isCollectionExist = coll.IsCollectionExists(errCode); if (!isCollectionExist) { - return -E_INVALID_ARGS; + errCode = -E_INVALID_ARGS; } - if (!coll.FindDocument()) { - GLOGE("no corresponding table name"); - return -E_INVALID_ARGS; + if (errCode != E_OK) { + goto END; } - int ret = InitResultSet(this, collection, filter, allPath, ifShowId, viewType, grdResultSet->resultSet_, isOnlyId); - if (ret == E_OK) { + errCode = InitResultSet(this, collection, filter, allPath, ifShowId, viewType, grdResultSet->resultSet_, isOnlyId); + if (errCode == E_OK) { collections_[collection] = nullptr; } - if (ret != E_OK) { - collections_.erase(collection); +END: + if (errCode == E_OK) { + executor_->Commit(); + } else { + executor_->Rollback(); } - return ret; + return errCode; } bool DocumentStore::IsCollectionOpening(const std::string collection) { - std::lock_guard lock(dbMutex_); if (collections_.find(collection) != collections_.end()) { GLOGE("DB is resource busy"); return true; @@ -629,4 +627,34 @@ int DocumentStore::Close(uint32_t flags) } return E_OK; } + +int DocumentStore::StartTransaction() +{ + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } + return executor_->StartTransaction(); +} +int DocumentStore::Commit() +{ + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } + return executor_->Commit(); +} +int DocumentStore::Rollback() +{ + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } + return executor_->Rollback(); +} + +bool DocumentStore::IsCollectionExists(const std::string &collectionName, int &errCode) +{ + if (executor_ == nullptr) { + return -E_INNER_ERROR; + } + return executor_->IsCollectionExists(collectionName, errCode); +} } // namespace DocumentDB \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp index 6fecf04e9f803aec0bce45dbd0ee2a39f779127b..3ea01a2b7ed9a54efcedac3cb9b244c09d6d7cf1 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -14,6 +14,8 @@ */ #include "result_set.h" #include "securec.h" + +#include "db_constant.h" #include "log_print.h" namespace DocumentDB { @@ -54,11 +56,24 @@ int ResultSet::Init(DocumentStore *store, const std::string collectionName, cons return E_OK; } -int ResultSet::GetNext() +int ResultSet::GetNextInner(bool isNeedCheckTable) { + int errCode = E_OK; + if (isNeedCheckTable) { + std::string lowerCaseName = collectionName_; + std::transform(lowerCaseName.begin(), lowerCaseName.end(), lowerCaseName.begin(), [](unsigned char c) { + return std::tolower(c); + }); + bool isCollectionExist = store_->IsCollectionExists(DBConstant::COLL_PREFIX + lowerCaseName, errCode); + if (errCode != E_OK) { + return errCode; + } + if (!isCollectionExist) { + return -E_INVALID_ARGS; + } + } if (!ifField_ && index_ == 0) { if (isOnlyId_) { - int errCode = 0; JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); @@ -68,7 +83,6 @@ int ResultSet::GetNext() ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); std::string idKey = idValue.GetStringValue(); if (idKey.empty()) { - GLOGE("id is empty"); return -E_NO_DATA; } Key key(idKey.begin(), idKey.end()); @@ -76,7 +90,6 @@ int ResultSet::GetNext() Collection coll = store_->GetCollection(collectionName_); errCode = coll.GetDocument(key, document); if (errCode == -E_NOT_FOUND) { - GLOGE("Cant get value from db"); return -E_NO_DATA; } std::string jsonData(document.begin(), document.end()); @@ -85,7 +98,6 @@ int ResultSet::GetNext() values.emplace_back(std::pair(idKey, jsonData)); matchDatas_ = values; } else { - int errCode = 0; Collection coll = store_->GetCollection(collectionName_); std::vector> values; JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); @@ -95,7 +107,6 @@ int ResultSet::GetNext() } errCode = coll.GetMatchedDocument(filterObj, values); if (errCode == -E_NOT_FOUND) { - GLOGE("Cant get value from db"); return -E_NO_DATA; } for (size_t i = 0; i < values.size(); i++) { @@ -104,7 +115,6 @@ int ResultSet::GetNext() matchDatas_ = values; } } else if (index_ == 0) { - int errCode = 0; Collection coll = store_->GetCollection(collectionName_); std::vector> values; JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); @@ -114,21 +124,40 @@ int ResultSet::GetNext() } errCode = coll.GetMatchedDocument(filterObj, values); if (errCode == -E_NOT_FOUND) { - GLOGE("Cant get value from db"); return -E_NO_DATA; } matchDatas_ = values; } index_++; if (index_ > matchDatas_.size()) { - GLOGE("No data in The value vector"); return -E_NO_DATA; } return E_OK; } +int ResultSet::GetNext(bool isNeedTransaction, bool isNeedCheckTable) +{ + int errCode = E_OK; + if (!isNeedTransaction) { + return GetNextInner(isNeedCheckTable); + } + std::lock_guard lock(store_->dbMutex_); + errCode = store_->StartTransaction(); + if (errCode != E_OK) { + return errCode; + } + errCode = GetNextInner(isNeedCheckTable); + if (errCode == E_OK || errCode == -E_NO_DATA) { + store_->Commit(); + } else { + store_->Rollback(); + } + return errCode; +} + int ResultSet::GetValue(char **value) { + std::lock_guard lock(store_->dbMutex_); if (index_ == 0 || (index_ > matchDatas_.size())) { GLOGE("The value vector in resultSet is empty"); return -E_NO_DATA; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp index d333d21a044db00e15bb3c6bcf83bc2148f278fb..295dfb1765ee229c1f845e6b478e9efd3b4386d5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp @@ -315,7 +315,6 @@ bool SqliteStoreExecutorImpl::IsCollectionExists(const std::string &name, int &e { bool isExists = false; std::string sql = "SELECT tbl_name FROM sqlite_master WHERE tbl_name=?;"; - errCode = SQLiteUtils::ExecSql( dbHandle_, sql, [name](sqlite3_stmt *stmt) {