From 85937b804eee2a2ac725c3cbe95c54d8f83acb0b Mon Sep 17 00:00:00 2001 From: lianhuix Date: Thu, 27 Apr 2023 07:33:41 +0000 Subject: [PATCH] Fix return code for update/upsert & dropCollection Signed-off-by: lianhuix --- .../gaussdb_rd_simple/src/interface/src/collection.cpp | 9 ++++++--- .../src/interface/src/document_store.cpp | 4 ++++ .../src/oh_adapter/src/sqlite_store_executor_impl.cpp | 2 +- .../test/unittest/api/documentdb_collection_test.cpp | 2 +- .../test/unittest/api/documentdb_data_test.cpp | 4 ++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp index 4a7d28d9..899e368f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp @@ -115,7 +115,7 @@ int Collection::UpsertDocument(const std::string &id, const std::string &documen std::string valueGotStr = std::string(valueGot.begin(), valueGot.end()); if (errCode != E_OK && errCode != -E_NOT_FOUND) { - GLOGE("Get original document failed. %d", errCode); + GLOGW("Get original document failed. %d", errCode); return errCode; } else if (errCode == E_OK) { // document has been inserted GLOGD("Document has been inserted, append value."); @@ -166,8 +166,11 @@ int Collection::UpdateDocument(const std::string &id, const std::string &update) Value valueGot; errCode = executor_->GetData(name_, keyId, valueGot); std::string valueGotStr = std::string(valueGot.begin(), valueGot.end()); - if (errCode != E_OK) { - GLOGE("Get original document failed. %d", errCode); + if (errCode == -E_NOT_FOUND) { + GLOGW("Get original document not found."); + return -E_NOT_FOUND; + } else if (errCode != E_OK) { + GLOGW("Get original document failed. %d", errCode); return errCode; } 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 dd4055b4..3a0188e1 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 @@ -193,6 +193,8 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri errCode = coll.UpdateDocument(docId, update); if (errCode == E_OK) { errCode = 1; // update one record. + } else if (errCode == -E_NOT_FOUND) { + errCode = E_OK; } return errCode; } @@ -231,6 +233,8 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri errCode = coll.UpsertDocument(docId, document, isReplace); if (errCode == E_OK) { errCode = 1; // upsert one record. + } else if (errCode = -E_NOT_FOUND) { + errCode = E_OK; } return errCode; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp index ffe8c7be..9af80fa7 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp @@ -237,7 +237,7 @@ int SqliteStoreExecutor::DropCollection(const std::string &name, bool ignoreNonE } if (!isExists) { GLOGE("[sqlite executor] Drop collectoin failed, collection not exists."); - return -E_NO_DATA; + return -E_INVALID_ARGS; } } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp index a15df4df..63b72d43 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_collection_test.cpp @@ -198,7 +198,7 @@ HWTEST_F(DocumentDBCollectionTest, CollectionTest006, TestSize.Level0) EXPECT_EQ(GRD_DropCollection(g_db, "student", 0), GRD_OK); EXPECT_EQ(GRD_DropCollection(g_db, "student", 0), GRD_OK); - EXPECT_EQ(GRD_DropCollection(g_db, "student", CHK_NON_EXIST_COLLECTION), GRD_NO_DATA); + EXPECT_EQ(GRD_DropCollection(g_db, "student", CHK_NON_EXIST_COLLECTION), GRD_INVALID_ARGS); // Create collection with different option returnh OK after drop collection EXPECT_EQ(GRD_CreateCollection(g_db, "student", R""({"maxDoc":2048})"", 0), GRD_OK); 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 228978ba..3295851d 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 @@ -180,7 +180,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_OK); } /** @@ -211,7 +211,7 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest001, TestSize.Level0) { std::string filter = R""({"_id":"1234"})""; std::string updateDoc = R""({"name":"Xue"})""; - EXPECT_EQ(GRD_UpdateDoc(g_db, g_coll, filter.c_str(), updateDoc.c_str(), 0), GRD_NO_DATA); + EXPECT_EQ(GRD_UpdateDoc(g_db, g_coll, filter.c_str(), updateDoc.c_str(), 0), GRD_OK); } /** -- Gitee