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 2b78f473c3d29dde30e837e9747f6f8b60c01d3f..ed128f1f0f8dbf7629f5c5deff94ef7cefddeed2 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 @@ -157,7 +157,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 ab098f736a871e9a63c63883f9062c560144ba5d..481457c06c02321463f1580822f9cc76a77173bd 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 f878a0eb6e51b1211a335d3eb84d466002a129db..f1790353c4f21f3b19d3198c0a4e3a4d9617fb54 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,7 +155,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 failed"); return errCode; @@ -236,7 +236,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 failed"); return errCode; @@ -304,7 +304,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 failed"); return errCode; @@ -346,7 +346,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 failed"); return errCode; @@ -402,7 +402,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 failed"); return errCode; @@ -421,7 +421,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 failed"); return errCode; 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 6f3aebb6e984d918eb52f92b1f9b990320131c6c..aceb6328fce28a3ab2248edd915e074db51be248 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 @@ -261,6 +261,38 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest006, TestSize.Level0) } 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); +} + +HWTEST_F(DocumentDBDataTest, UpdateDataTest009, TestSize.Level0) { const char *updateStr = R""({"field2":{"c_field":{"cc_field":{"ccc_field":{"ccc_field":[1,false,1.234e2,["hello world!"]]}}}}})""; int result = GRD_UpdateDoc(g_db, g_coll, "{\"field\" : 2}", updateStr, 0);