From c8f77e911eba9189772b8317e3f6fedf4424a808 Mon Sep 17 00:00:00 2001 From: zqq Date: Fri, 21 Nov 2025 18:18:30 +0800 Subject: [PATCH] fixbug in not equal to Signed-off-by: zqq --- .../interfaces/include/cloud/cloud_store_types.h | 1 + .../libs/distributeddb/storage/src/sqlite/query_object.cpp | 3 ++- .../distributeddb/storage/src/sqlite/query_sync_object.cpp | 3 +++ .../src/sqlite/relational/sqlite_relational_store.cpp | 6 +++--- .../storage/src/sqlite/relational/sqlite_relational_store.h | 3 ++- .../test/unittest/common/common/rdb_general_ut.cpp | 1 + .../storage/distributeddb_query_object_helper_test.cpp | 4 ++-- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/frameworks/libs/distributeddb/interfaces/include/cloud/cloud_store_types.h b/frameworks/libs/distributeddb/interfaces/include/cloud/cloud_store_types.h index 2f0e5452f85..71dff8cf26e 100644 --- a/frameworks/libs/distributeddb/interfaces/include/cloud/cloud_store_types.h +++ b/frameworks/libs/distributeddb/interfaces/include/cloud/cloud_store_types.h @@ -168,6 +168,7 @@ enum class QueryNodeType : uint32_t { OR = 0x101, AND, EQUAL_TO = 0x201, + NOT_EQUAL_TO, BEGIN_GROUP = 0x301, END_GROUP }; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp index 6b8262180ec..d593c222b2e 100755 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp @@ -538,7 +538,8 @@ int QueryObject::CheckPrimaryKey(const std::map &primaryKeyMap) } std::set queryPkSet; for (const auto &queryObjNode : queryObjNodes_) { - if (queryObjNode.operFlag != QueryObjType::IN && queryObjNode.operFlag != QueryObjType::EQUALTO) { + if (queryObjNode.operFlag != QueryObjType::IN && queryObjNode.operFlag != QueryObjType::EQUALTO && + queryObjNode.operFlag != QueryObjType::NOT_EQUALTO) { continue; } std::string field = queryObjNode.fieldName; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp index 62a9aaacb42..649d1857d8d 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp @@ -523,6 +523,9 @@ int QuerySyncObject::TransformNodeType(const QueryObjNode &objNode, QueryNode &n node.fieldName = CloudDbConstant::CLOUD_KV_FIELD_KEY; node.type = QueryNodeType::IN; break; + case QueryObjType::NOT_EQUALTO: + node.type = QueryNodeType::NOT_EQUAL_TO; + break; default: LOGE("[Query] not support type %d", static_cast(objNode.operFlag)); errCode = -E_NOT_SUPPORT; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp index a32a1bb1d63..3cb6e5f948e 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp @@ -1279,11 +1279,11 @@ int SQLiteRelationalStore::CheckQueryValid(const CloudSyncOption &option) if (errCode != E_OK) { return errCode; } - return CheckObjectValid(option.priorityTask, object, isFromTable); + return CheckObjectValid(option.priorityTask, object, isFromTable, option.mode); } int SQLiteRelationalStore::CheckObjectValid(bool priorityTask, const std::vector &object, - bool isFromTable) + bool isFromTable, SyncMode mode) { RelationalSchemaObject localSchema = sqliteStorageEngine_->GetSchema(); for (const auto &item : object) { @@ -1304,7 +1304,7 @@ int SQLiteRelationalStore::CheckObjectValid(bool priorityTask, const std::vector } std::string tableName = item.GetRelationTableName(); TableInfo tableInfo = localSchema.GetTable(tableName); - if (!tableInfo.Empty()) { + if (!tableInfo.Empty() && mode != SYNC_MODE_CLOUD_CUSTOM_PUSH) { const std::map &primaryKeyMap = tableInfo.GetPrimaryKey(); errCode = item.CheckPrimaryKey(primaryKeyMap); if (errCode != E_OK) { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.h index 1ab33429a54..f6408d08203 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.h @@ -172,7 +172,8 @@ protected: int CheckQueryValid(const CloudSyncOption &option); - int CheckObjectValid(bool priorityTask, const std::vector &object, bool isFromTable); + int CheckObjectValid(bool priorityTask, const std::vector &object, bool isFromTable, + SyncMode mode); int CheckTableName(const std::vector &tableNames); diff --git a/frameworks/libs/distributeddb/test/unittest/common/common/rdb_general_ut.cpp b/frameworks/libs/distributeddb/test/unittest/common/common/rdb_general_ut.cpp index 7dd772ddae3..019843092d9 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/common/rdb_general_ut.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/common/rdb_general_ut.cpp @@ -509,6 +509,7 @@ void RDBGeneralUt::CloudBlockSync(const StoreInfo &from, const Query &query, Syn option.devices = { "CLOUD" }; option.mode = mode; option.query = query; + option.priorityTask = true; option.waitTime = DBConstant::MAX_TIMEOUT; RelationalTestUtils::CloudBlockSync(option, delegate, exceptStatus, callbackExpect); } diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_query_object_helper_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_query_object_helper_test.cpp index 5d07611eb6f..bd6263e7813 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_query_object_helper_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_query_object_helper_test.cpp @@ -222,7 +222,7 @@ std::vector> Query004GetExpectNode() .fieldName = "", .fieldValue = {} }, QueryNode { - .type = QueryNodeType::EQUAL_TO, + .type = QueryNodeType::NOT_EQUAL_TO, .fieldName = "field2", .fieldValue = {std::string("2")} }, QueryNode { @@ -279,7 +279,7 @@ HWTEST_F(DistributedDBQueryObjectHelperTest, Query004, TestSize.Level1) { std::vector inVal = {"1", "2", "3"}; Query query = Query::Select().From("table1").BeginGroup(). - EqualTo("field1", "1").And().EqualTo("field2", "2"). + EqualTo("field1", "1").And().NotEqualTo("field2", "2"). EndGroup().Or().BeginGroup().EqualTo("field1", "2").And().EqualTo("field2", "1").EndGroup(). From("table2").In("field3", inVal); -- Gitee