From bcb65b7a066f7d068106fdb051770988e6fbc68f Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 6 May 2023 20:21:11 +0800 Subject: [PATCH 1/2] Addresses the case insensitivity issue of Updata Signed-off-by: Jeremyzz --- .../src/oh_adapter/include/json_object.h | 4 +-- .../unittest/api/documentdb_data_test.cpp | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h index f2056984..c7a1ae8a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h @@ -60,7 +60,7 @@ using JsonFieldPath = std::vector; class JsonObject { public: - static JsonObject Parse(const std::string &jsonStr, int &errCode, bool caseSensitive = false); + static JsonObject Parse(const std::string &jsonStr, int &errCode, bool caseSensitive = true); ~JsonObject(); std::string Print() const; @@ -111,7 +111,7 @@ private: cJSON *cjson_ = nullptr; int jsonDeep_ = 0; bool isOwner_ = false; - bool caseSensitive_ = false; + bool caseSensitive_ = true; }; } // namespace DocumentDB #endif // JSON_OBJECT_H 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..0d1852ba 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 @@ -257,4 +257,37 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest006, TestSize.Level0) GLOGD("UpdateDataTest006: update data with flag: %u", flag); EXPECT_EQ(GRD_UpdateDoc(g_db, g_coll, filter.c_str(), document.c_str(), flag), GRD_INVALID_ARGS); } +} + +HWTEST_F(DocumentDBDataTest, UpdateDataTest007, TestSize.Level0) +{ + std::string filter = R""({"_id":"1234"})""; + std::string document = R""({"_id":"1234", "field1":{"c_field":{"cc_field":{"ccc_field":1}}}, "field2" : 2})""; + + EXPECT_EQ(GRD_InsertDoc(g_db, g_coll, document.c_str(), 0), GRD_OK); + + std::string updata = R""({"field1":1, "FIELD1":[1, true, 1.23456789, "hello world!", null]})""; + EXPECT_EQ(GRD_UpdateDoc(g_db, g_coll, filter.c_str(), updata.c_str(), 0), 1); + + GRD_ResultSet *resultSet = nullptr; + const char *projection = "{}"; + Query query = { filter.c_str(), projection }; + EXPECT_EQ(GRD_FindDoc(g_db, g_coll, query, 1, &resultSet), GRD_OK); + EXPECT_EQ(GRD_Next(resultSet), GRD_OK); + char *value = NULL; + EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); + string valueStr = value; + string repectStr = R""({"_id":"1234","field1":1,"field2":2,"FIELD1":[1,true,1.23456789,"hello world!",null]})""; + EXPECT_EQ((valueStr == repectStr), 1); + EXPECT_EQ(GRD_FreeValue(value), GRD_OK); + EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); +} + +HWTEST_F(DocumentDBDataTest, UpdateDataTest008, TestSize.Level0) +{ + std::string filter = R""({"_id":"1234"})""; + std::string updata = R""({"field1":1, "FIELD1":[1, true, 1.23456789, "hello world!", null]})""; + EXPECT_EQ(GRD_UpdateDoc(g_db, "grd_aa", filter.c_str(), updata.c_str(), 0), GRD_INVALID_FORMAT); + EXPECT_EQ(GRD_UpdateDoc(g_db, "gRd_aa", filter.c_str(), updata.c_str(), 0), GRD_INVALID_FORMAT); + } \ No newline at end of file -- Gitee From cd8a017a53e405573c829dba14cdc79b0460e90b Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 8 May 2023 21:36:12 +0800 Subject: [PATCH 2/2] fix code check Signed-off-by: Jeremyzz --- .../src/executor/document/document_check.cpp | 2 +- .../src/interface/src/collection.cpp | 4 ++-- .../src/interface/src/document_store.cpp | 12 ++++++------ .../src/oh_adapter/include/json_object.h | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp index 285036fc..25ba837d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp @@ -160,7 +160,7 @@ bool CheckCommon::CheckDocument(const std::string &updateStr, int &errCode) return false; } - JsonObject updateObj = JsonObject::Parse(updateStr, errCode); + JsonObject updateObj = JsonObject::Parse(updateStr, errCode, true); if (updateObj.IsNull() || errCode != E_OK) { GLOGE("Parse update document failed. %d", errCode); return false; 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 ab098f73..481457c0 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 @@ -158,7 +158,7 @@ int Collection::UpdateDocument(const std::string &id, const std::string &update, return -E_NO_DATA; } - JsonObject updateValue = JsonObject::Parse(update, errCode); + JsonObject updateValue = JsonObject::Parse(update, errCode, true); if (errCode != E_OK) { GLOGD("Parse upsert value failed. %d", errCode); return errCode; @@ -176,7 +176,7 @@ int Collection::UpdateDocument(const std::string &id, const std::string &update, return errCode; } GLOGD("Update document value."); - JsonObject originValue = JsonObject::Parse(valueGotStr, errCode); + JsonObject originValue = JsonObject::Parse(valueGotStr, errCode, true); if (errCode != E_OK) { GLOGD("Parse original value failed. %d %s", errCode, valueGotStr.c_str()); 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 210316d8..8cdb5264 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 @@ -142,7 +142,7 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri GLOGE("Check flags invalid."); return -E_INVALID_ARGS; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, caseSensitive); + JsonObject filterObj = JsonObject::Parse(filter, errCode, true); if (errCode != E_OK) { GLOGE("filter Parsed faild"); return errCode; @@ -222,7 +222,7 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri GLOGE("Check flags invalid."); return -E_INVALID_ARGS; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, caseSensitive); + JsonObject filterObj = JsonObject::Parse(filter, errCode, true); if (errCode != E_OK) { GLOGE("filter Parsed faild"); return errCode; @@ -290,7 +290,7 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri GLOGE("document's length is too long"); return -E_OVER_LIMIT; } - JsonObject documentObj = JsonObject::Parse(document, errCode, caseSensitive); + JsonObject documentObj = JsonObject::Parse(document, errCode, true); if (errCode != E_OK) { GLOGE("Document Parsed faild"); return errCode; @@ -332,7 +332,7 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri GLOGE("filter's length is too long"); return -E_OVER_LIMIT; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, caseSensitive); + JsonObject filterObj = JsonObject::Parse(filter, errCode, true); if (errCode != E_OK) { GLOGE("filter Parsed faild"); return errCode; @@ -388,7 +388,7 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string GLOGE("filter's length is too long"); return -E_OVER_LIMIT; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, caseSensitive); + JsonObject filterObj = JsonObject::Parse(filter, errCode, true); if (errCode != E_OK) { GLOGE("filter Parsed faild"); return errCode; @@ -407,7 +407,7 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string GLOGE("projection's length is too long"); return -E_OVER_LIMIT; } - JsonObject projectionObj = JsonObject::Parse(projection, errCode, caseSensitive); + JsonObject projectionObj = JsonObject::Parse(projection, errCode, true); if (errCode != E_OK) { GLOGE("projection Parsed faild"); return errCode; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h index c7a1ae8a..f2056984 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h @@ -60,7 +60,7 @@ using JsonFieldPath = std::vector; class JsonObject { public: - static JsonObject Parse(const std::string &jsonStr, int &errCode, bool caseSensitive = true); + static JsonObject Parse(const std::string &jsonStr, int &errCode, bool caseSensitive = false); ~JsonObject(); std::string Print() const; @@ -111,7 +111,7 @@ private: cJSON *cjson_ = nullptr; int jsonDeep_ = 0; bool isOwner_ = false; - bool caseSensitive_ = true; + bool caseSensitive_ = false; }; } // namespace DocumentDB #endif // JSON_OBJECT_H -- Gitee