From 842bbe88aff43d2ad79a509c038b5a7ab4955f99 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Fri, 5 May 2023 18:53:23 +0800 Subject: [PATCH 1/3] fix do not return faild when collection dont exsit bug Signed-off-by: Jeremyzz --- .../src/interface/src/document_store.cpp | 34 ++++++++++++++++++- .../unittest/api/documentdb_data_test.cpp | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp index 210316d8..a3856fb9 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp @@ -155,6 +155,13 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri } bool isOnlyId = true; auto coll = Collection(collection, executor_); + int IsCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!IsCollectionExist) { + return -E_INVALID_ARGS; + } errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); if (errCode != E_OK) { return errCode; @@ -235,6 +242,13 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri bool isOnlyId = true; bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); auto coll = Collection(collection, executor_); + int IsCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!IsCollectionExist) { + return -E_INVALID_ARGS; + } errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); if (errCode != E_OK) { return errCode; @@ -286,6 +300,13 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri return errCode; } auto coll = Collection(collection, executor_); + int IsCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!IsCollectionExist) { + return -E_INVALID_ARGS; + } if (document.length() + 1 > JSON_LENS_MAX) { GLOGE("document's length is too long"); return -E_OVER_LIMIT; @@ -321,7 +342,11 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri return errCode; } auto coll = Collection(collection, executor_); - if (!coll.IsCollectionExists(errCode)) { + int IsCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!IsCollectionExist) { return -E_INVALID_ARGS; } if (filter.empty()) { @@ -433,6 +458,13 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string ifShowId = true; } auto coll = Collection(collection, executor_); + int IsCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!IsCollectionExist) { + return -E_INVALID_ARGS; + } std::lock_guard lock(dbMutex_); if (!coll.FindDocument()) { GLOGE("no corresponding table name"); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp index 17ff76b7..fa4c609f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp @@ -150,7 +150,7 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest007, TestSize.Level0) { std::string filter = R""({"_id":"1234"})""; std::string val = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; - EXPECT_EQ(GRD_UpsertDoc(g_db, "collection_not_exists", filter.c_str(), val.c_str(), GRD_DOC_REPLACE), GRD_NO_DATA); + EXPECT_EQ(GRD_UpsertDoc(g_db, "collection_not_exists", filter.c_str(), val.c_str(), GRD_DOC_REPLACE), GRD_INVALID_ARGS); } /** -- Gitee From 8f3ac844fe6045bd9b37bc489a1e587c9009756d Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 8 May 2023 20:37:20 +0800 Subject: [PATCH 2/3] fix ddbMatster code check Signed-off-by: Jeremyzz --- .../gaussdb_rd_simple/src/interface/src/document_store.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp index a3856fb9..bbe24533 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp @@ -155,11 +155,11 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri } bool isOnlyId = true; auto coll = Collection(collection, executor_); - int IsCollectionExist = coll.IsCollectionExists(errCode); + bool isCollectionExist = coll.IsCollectionExists(errCode); if (errCode != E_OK) { return errCode; } - if (!IsCollectionExist) { + if (!isCollectionExist) { return -E_INVALID_ARGS; } errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); -- Gitee From 6c3cadff229501a9eae19b08f306dadb9241d5ca Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 8 May 2023 20:40:57 +0800 Subject: [PATCH 3/3] fix code check Signed-off-by: Jeremyzz --- .../src/interface/src/document_store.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp index bbe24533..b5111dc1 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp @@ -242,11 +242,11 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri bool isOnlyId = true; bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); auto coll = Collection(collection, executor_); - int IsCollectionExist = coll.IsCollectionExists(errCode); + bool isCollectionExist = coll.IsCollectionExists(errCode); if (errCode != E_OK) { return errCode; } - if (!IsCollectionExist) { + if (!isCollectionExist) { return -E_INVALID_ARGS; } errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); @@ -300,11 +300,11 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri return errCode; } auto coll = Collection(collection, executor_); - int IsCollectionExist = coll.IsCollectionExists(errCode); + bool isCollectionExist = coll.IsCollectionExists(errCode); if (errCode != E_OK) { return errCode; } - if (!IsCollectionExist) { + if (!isCollectionExist) { return -E_INVALID_ARGS; } if (document.length() + 1 > JSON_LENS_MAX) { @@ -342,11 +342,11 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri return errCode; } auto coll = Collection(collection, executor_); - int IsCollectionExist = coll.IsCollectionExists(errCode); + bool isCollectionExist = coll.IsCollectionExists(errCode); if (errCode != E_OK) { return errCode; } - if (!IsCollectionExist) { + if (!isCollectionExist) { return -E_INVALID_ARGS; } if (filter.empty()) { @@ -458,11 +458,11 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string ifShowId = true; } auto coll = Collection(collection, executor_); - int IsCollectionExist = coll.IsCollectionExists(errCode); + bool isCollectionExist = coll.IsCollectionExists(errCode); if (errCode != E_OK) { return errCode; } - if (!IsCollectionExist) { + if (!isCollectionExist) { return -E_INVALID_ARGS; } std::lock_guard lock(dbMutex_); -- Gitee