From e6e068637e28b9e08566d4b1c409a2080ec1e4ba Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 26 Jun 2023 20:44:00 +0800 Subject: [PATCH 1/2] fix crash problem Signed-off-by: mazhao --- .../src/interface/src/result_set.cpp | 24 ++++---- .../unittest/api/documentdb_find_test.cpp | 56 +++++++++++++++++++ 2 files changed, 68 insertions(+), 12 deletions(-) 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 2b97323a..2ab4fa81 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 @@ -194,19 +194,19 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat GLOGE("No node to cut"); return -E_NO_DATA; } - singlePath.emplace_back(node->GetItemField()); - size_t index = 0; - if (!context_->projectionTree.SearchTree(singlePath, index) && index == 0) { - allCutPath.emplace_back(singlePath); - } - if (!node->GetChild().IsNull()) { - JsonObject nodeNew = node->GetChild(); - CheckCutNode(&nodeNew, singlePath, allCutPath); - } - if (!node->GetNext().IsNull()) { + JsonObject nodeInstance = *node; + while (!nodeInstance.IsNull()) { + singlePath.emplace_back(nodeInstance.GetItemField()); + size_t index = 0; + if (!context_->projectionTree.SearchTree(singlePath, index) && index == 0) { + allCutPath.emplace_back(singlePath); + } + if (!nodeInstance.GetChild().IsNull()) { + JsonObject nodeChiled = nodeInstance.GetChild(); + CheckCutNode(&nodeChiled, singlePath, allCutPath); + } singlePath.pop_back(); - JsonObject nodeNew = node->GetNext(); - CheckCutNode(&nodeNew, singlePath, allCutPath); + nodeInstance = nodeInstance.GetNext(); } return E_OK; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index 50ac7575..0bcae90e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -78,6 +78,17 @@ static const char *g_document20 = "{\"_id\" : \"20\", \"name\":\"doc20\",\"ITEM\ static const char *g_document23 = "{\"_id\" : \"23\", \"name\":\"doc22\",\"ITEM\" : " "true,\"personInfo\":[{\"school\":\"b\", \"age\":15}, [{\"school\":\"doc23\"}, 10, " "{\"school\":\"doc23\"}, true, {\"school\":\"y\"}], {\"school\":\"b\"}]}"; +static const char *document0631 = R""({"_id":"city_11_com.acts.ohos.data.datasharetestclient_100", + "bundleName":"com.acts.ohos.data.datasharetestclient","key":"city","subscriberId":11, + "timestamp":1509100700,"userId":100,"value":{"type":1,"value":"xian"},"version":0})""; +static const char *document0632 = R""({"_id":"datashareproxy://com.acts.ohos.data.datasharetest/appInfo_11_com.acts.oh + os.data.datasharetest_100","bundleName":"com.acts.ohos.data.datasharetest","key":"datashareproxy://com.acts.ohos + .data.datasharetest/appInfo","subscriberId":11,"timestamp":1509100700,"userId":100, + "value":{"type":1,"value":"\"Qing\""},"version":0})""; +static const char *document0633 = + R""({"_id":"empty_11_com.acts.ohos.data.datasharetestclient_100","bundleName":"com.acts.ohos.data.datasharetestcl + ient","key":"empty","subscriberId":11,"timestamp":1509100700,"userId":100,"value":{"type":1,"value":"nobody sub"}, + "version":0})""; static std::vector g_data = { g_document1, g_document2, g_document3, g_document4, g_document5, g_document6, g_document7, g_document8, g_document9, g_document10, g_document11, g_document12, g_document13, g_document14, g_document15, g_document16, g_document17, g_document18, g_document19, g_document20, g_document23 }; @@ -1493,4 +1504,49 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest063, TestSize.Level1) EXPECT_EQ(GRD_Next(resultSet), GRD_NO_DATA); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } + +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest064, TestSize.Level1) +{ + char *colName1 = "data_"; + GRD_DB *test_db = nullptr; + std::string path = "./dataShare.db"; + int status = GRD_DBOpen(path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &test_db); + EXPECT_EQ(status, GRD_OK); + EXPECT_EQ(GRD_CreateCollection(test_db, colName1, "", 0), GRD_OK); + + EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0631, 0), GRD_OK); + EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0632, 0), GRD_OK); + EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0633, 0), GRD_OK); + + string document1 = "{\"_id\":\"key2_11_com.acts.ohos.data.datasharetestclient_100\"\ + ,\"bundleName\":\"com.acts.ohos.data.datasharetestclient\"\ + ,\"key\":\"key2\",\"subscriberId\":11,\"timestamp\":1509100700," + "\"userId\":100,\"value\":{\"type\":0,"; + string document2 = "\"value\":["; + string document3 = "5,"; + string document4 = document3; + for (int i = 0; i < 100000; i++) { + document4 += document3; + } + document4.push_back('5'); + string document5 = "]}}"; + string document0635 = document1 + document2 + document4 + document5; + EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0635.c_str(), 0), GRD_OK); + EXPECT_EQ(status, GRD_OK); + const char *filter = "{}"; + GRD_ResultSet *resultSet = nullptr; + const char *projection = "{\"id_\":true, \"timestamp\":true, \"key\":true, \"bundleName\": true, " + "\"subscriberId\": true}"; + Query query = { filter, projection }; + EXPECT_EQ(GRD_FindDoc(test_db, colName1, query, 1, &resultSet), GRD_OK); + char *value; + while (GRD_Next(resultSet) == GRD_OK) { + EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); + printf("value is ======>%s\n", value); + GRD_FreeValue(value); + } + EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); + EXPECT_EQ(GRD_DBClose(test_db, 0), GRD_OK); + DocumentDBTestUtils::RemoveTestDbFiles(path.c_str()); +} } // namespace -- Gitee From e73f0e970cec6c9473dc5520c819b72a8fd23758 Mon Sep 17 00:00:00 2001 From: mazhao Date: Tue, 27 Jun 2023 10:32:13 +0800 Subject: [PATCH 2/2] delete fuc Signed-off-by: mazhao --- .../src/oh_adapter/include/json_object.h | 1 - .../src/oh_adapter/src/json_object.cpp | 2 +- .../unittest/api/documentdb_find_test.cpp | 24 ++++--------------- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h index 664bd439..4f5efa4a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h @@ -37,7 +37,6 @@ public: explicit ValueObject(bool val); explicit ValueObject(double val); explicit ValueObject(const char *val); - explicit ValueObject(const std::string &val); ValueType GetValueType() const; bool GetBoolValue() const; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index a61824e6..5130029d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -43,7 +43,7 @@ ValueObject::ValueObject(double val) doubleValue = val; } -ValueObject::ValueObject(const std::string &val) +ValueObject::ValueObject(const char *val) { valueType = ValueType::VALUE_STRING; stringValue = val; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index 0bcae90e..ea1586be 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -35,6 +35,7 @@ namespace { std::string g_path = "./document.db"; GRD_DB *g_db = nullptr; constexpr const char *COLLECTION_NAME = "student"; +constexpr const char *colName = "data_"; const int MAX_COLLECTION_NAME = 511; const int MAX_ID_LENS = 899; @@ -78,17 +79,6 @@ static const char *g_document20 = "{\"_id\" : \"20\", \"name\":\"doc20\",\"ITEM\ static const char *g_document23 = "{\"_id\" : \"23\", \"name\":\"doc22\",\"ITEM\" : " "true,\"personInfo\":[{\"school\":\"b\", \"age\":15}, [{\"school\":\"doc23\"}, 10, " "{\"school\":\"doc23\"}, true, {\"school\":\"y\"}], {\"school\":\"b\"}]}"; -static const char *document0631 = R""({"_id":"city_11_com.acts.ohos.data.datasharetestclient_100", - "bundleName":"com.acts.ohos.data.datasharetestclient","key":"city","subscriberId":11, - "timestamp":1509100700,"userId":100,"value":{"type":1,"value":"xian"},"version":0})""; -static const char *document0632 = R""({"_id":"datashareproxy://com.acts.ohos.data.datasharetest/appInfo_11_com.acts.oh - os.data.datasharetest_100","bundleName":"com.acts.ohos.data.datasharetest","key":"datashareproxy://com.acts.ohos - .data.datasharetest/appInfo","subscriberId":11,"timestamp":1509100700,"userId":100, - "value":{"type":1,"value":"\"Qing\""},"version":0})""; -static const char *document0633 = - R""({"_id":"empty_11_com.acts.ohos.data.datasharetestclient_100","bundleName":"com.acts.ohos.data.datasharetestcl - ient","key":"empty","subscriberId":11,"timestamp":1509100700,"userId":100,"value":{"type":1,"value":"nobody sub"}, - "version":0})""; static std::vector g_data = { g_document1, g_document2, g_document3, g_document4, g_document5, g_document6, g_document7, g_document8, g_document9, g_document10, g_document11, g_document12, g_document13, g_document14, g_document15, g_document16, g_document17, g_document18, g_document19, g_document20, g_document23 }; @@ -1507,16 +1497,11 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest063, TestSize.Level1) HWTEST_F(DocumentDBFindTest, DocumentDBFindTest064, TestSize.Level1) { - char *colName1 = "data_"; GRD_DB *test_db = nullptr; std::string path = "./dataShare.db"; int status = GRD_DBOpen(path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &test_db); EXPECT_EQ(status, GRD_OK); - EXPECT_EQ(GRD_CreateCollection(test_db, colName1, "", 0), GRD_OK); - - EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0631, 0), GRD_OK); - EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0632, 0), GRD_OK); - EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0633, 0), GRD_OK); + EXPECT_EQ(GRD_CreateCollection(test_db, colName, "", 0), GRD_OK); string document1 = "{\"_id\":\"key2_11_com.acts.ohos.data.datasharetestclient_100\"\ ,\"bundleName\":\"com.acts.ohos.data.datasharetestclient\"\ @@ -1531,18 +1516,17 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest064, TestSize.Level1) document4.push_back('5'); string document5 = "]}}"; string document0635 = document1 + document2 + document4 + document5; - EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0635.c_str(), 0), GRD_OK); + EXPECT_EQ(GRD_InsertDoc(test_db, colName, document0635.c_str(), 0), GRD_OK); EXPECT_EQ(status, GRD_OK); const char *filter = "{}"; GRD_ResultSet *resultSet = nullptr; const char *projection = "{\"id_\":true, \"timestamp\":true, \"key\":true, \"bundleName\": true, " "\"subscriberId\": true}"; Query query = { filter, projection }; - EXPECT_EQ(GRD_FindDoc(test_db, colName1, query, 1, &resultSet), GRD_OK); + EXPECT_EQ(GRD_FindDoc(test_db, colName, query, 1, &resultSet), GRD_OK); char *value; while (GRD_Next(resultSet) == GRD_OK) { EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); - printf("value is ======>%s\n", value); GRD_FreeValue(value); } EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); -- Gitee