diff --git a/frameworks/libs/distributeddb/common/src/query.cpp b/frameworks/libs/distributeddb/common/src/query.cpp index 7c4aed399bd98d806ad2e5e572a93b1d7d93a9e4..a2e5e65ad1122492bd8f31d26ed0c04313fc06cd 100644 --- a/frameworks/libs/distributeddb/common/src/query.cpp +++ b/frameworks/libs/distributeddb/common/src/query.cpp @@ -40,84 +40,98 @@ Query &Query::FromTable(const std::vector &tableNames) Query &Query::BeginGroup() { queryExpression_.BeginGroup(); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::EndGroup() { queryExpression_.EndGroup(); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::IsNotNull(const std::string &field) { queryExpression_.IsNotNull(field); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::PrefixKey(const std::vector &key) { queryExpression_.QueryByPrefixKey(key); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::SuggestIndex(const std::string &indexName) { queryExpression_.QueryBySuggestIndex(indexName); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::InKeys(const std::set &keys) { queryExpression_.InKeys(keys); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::OrderBy(const std::string &field, bool isAsc) { queryExpression_.OrderBy(field, isAsc); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::OrderByWriteTime(bool isAsc) { queryExpression_.SetSortType(isAsc); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::Limit(int number, int offset) { queryExpression_.Limit(number, offset); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::Like(const std::string &field, const std::string &value) { queryExpression_.Like(field, value); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::NotLike(const std::string &field, const std::string &value) { queryExpression_.NotLike(field, value); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::IsNull(const std::string &field) { queryExpression_.IsNull(field); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::And() { queryExpression_.And(); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } Query &Query::Or() { queryExpression_.Or(); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } diff --git a/frameworks/libs/distributeddb/common/src/query_expression.cpp b/frameworks/libs/distributeddb/common/src/query_expression.cpp index 4dd776a1dcbb8d18a630ca23dbe18d1fcc35766a..ff8b0832ae0ea126fc0d03e4ffc2afbebc740340 100644 --- a/frameworks/libs/distributeddb/common/src/query_expression.cpp +++ b/frameworks/libs/distributeddb/common/src/query_expression.cpp @@ -296,4 +296,14 @@ void QueryExpression::SetTables(const std::vector &tableNames) { tables_ = tableNames; } + +void QueryExpression::SetIsDeviceSyncQuery(bool isDeviceSync) +{ + isWithDeviceSyncQuery_ = isDeviceSync; +} + +bool QueryExpression::GetIsDeviceSyncQuery() const +{ + return isWithDeviceSyncQuery_; +} } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/include/query.h b/frameworks/libs/distributeddb/include/query.h index da287c7c22345915f3fc92ca3c7a09e8ef6e10d7..882b561b699075947ae51fe112d854c61a61bc16 100644 --- a/frameworks/libs/distributeddb/include/query.h +++ b/frameworks/libs/distributeddb/include/query.h @@ -41,6 +41,7 @@ public: FieldValue fieldValue; QueryValueType type = GetFieldTypeAndValue(value, fieldValue); ExecuteCompareOperation(QueryObjType::EQUALTO, field, type, fieldValue); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } @@ -50,6 +51,7 @@ public: FieldValue fieldValue; QueryValueType type = GetFieldTypeAndValue(value, fieldValue); ExecuteCompareOperation(QueryObjType::NOT_EQUALTO, field, type, fieldValue); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } @@ -59,6 +61,7 @@ public: FieldValue fieldValue; QueryValueType type = GetFieldTypeAndValue(value, fieldValue); ExecuteCompareOperation(QueryObjType::GREATER_THAN, field, type, fieldValue); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } @@ -68,6 +71,7 @@ public: FieldValue fieldValue; QueryValueType type = GetFieldTypeAndValue(value, fieldValue); ExecuteCompareOperation(QueryObjType::LESS_THAN, field, type, fieldValue); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } @@ -77,6 +81,7 @@ public: FieldValue fieldValue; QueryValueType type = GetFieldTypeAndValue(value, fieldValue); ExecuteCompareOperation(QueryObjType::GREATER_THAN_OR_EQUALTO, field, type, fieldValue); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } @@ -86,6 +91,7 @@ public: FieldValue fieldValue; QueryValueType type = GetFieldTypeAndValue(value, fieldValue); ExecuteCompareOperation(QueryObjType::LESS_THAN_OR_EQUALTO, field, type, fieldValue); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } @@ -111,6 +117,7 @@ public: } ExecuteCompareOperation(QueryObjType::IN, field, type, fieldValues); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } @@ -126,6 +133,7 @@ public: } ExecuteCompareOperation(QueryObjType::NOT_IN, field, type, fieldValues); + queryExpression_.SetIsDeviceSyncQuery(true); return *this; } diff --git a/frameworks/libs/distributeddb/include/query_expression.h b/frameworks/libs/distributeddb/include/query_expression.h index de4cf10ac5c9b3ca191e4f1860bb5b952b2c3ff6..8109cb5de097175da5c8d8b7728e5ac8006d1720 100644 --- a/frameworks/libs/distributeddb/include/query_expression.h +++ b/frameworks/libs/distributeddb/include/query_expression.h @@ -144,6 +144,9 @@ public: std::vector GetTables(); void SetTables(const std::vector &tableNames); + void SetIsDeviceSyncQuery(bool isDeviceSync = true); + bool GetIsDeviceSyncQuery() const; + private: void AssemblyQueryInfo(const QueryObjType queryOperType, const std::string &field, const QueryValueType type, const std::vector &value, bool isNeedFieldPath); @@ -157,6 +160,7 @@ private: std::set keys_; int sortType_ = 0; std::vector tables_; + bool isWithDeviceSyncQuery_ = false; }; // specialize for double diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp index b0fa01bcd1ced2155cffce4b1bb18ef808305bdd..0fed477c30b8efc5d087eb1ba67219cf78709cf7 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp @@ -80,6 +80,7 @@ QueryObject::QueryObject(const Query &query) keys_ = queryExpressions.GetKeys(); sortType_ = static_cast(queryExpressions.GetSortType()); tables_ = queryExpressions.GetTables(); + isWithDeviceSyncQuery_ = queryExpressions.GetIsDeviceSyncQuery(); } QueryObject::QueryObject(const std::list &queryObjNodes, const std::vector &prefixKey, diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h index 98391ff6d296e456f8633407e034b035045b93be..27e98a6f19aa2851f02e485bfd621e98f8c09575 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h @@ -81,6 +81,7 @@ protected: bool initialized_ = false; // use function need after init bool isTableNameSpecified_ = false; std::vector tables_; + bool isWithDeviceSyncQuery_ = true; private: int Parse(); 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 8f9b0d99bff130b25ce7cb363054b5d87e43f99f..392b4ebc7aa8533bc3797d8697bb51c91dbded23 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp @@ -366,4 +366,9 @@ std::vector QuerySyncObject::GetRelationTableNames() const { return tables_; } + +bool QuerySyncObject::GetIsDeviceSyncQuery() const +{ + return isWithDeviceSyncQuery_; +} } // namespace DistributedDB \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h index 547c87de12660e3249f6f6824db6e17d73555ddd..ec1931138ca54e84bae05790241e744fa0e075f9 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h @@ -53,6 +53,8 @@ public: std::vector GetRelationTableNames() const; + bool GetIsDeviceSyncQuery() const; + private: uint32_t CalculateLen() const; uint32_t CalculateIdentifyLen() const; 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 e17d827d1e07dfa15122f162ff3c9d2280e10c37..bd70776329f924b97cebfc95bd2cce637a3945a7 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 @@ -882,6 +882,10 @@ int SQLiteRelationalStore::Sync(const std::vector &devices, SyncMod return -E_INVALID_DB; } QuerySyncObject querySyncObject(query); + if (querySyncObject.GetIsDeviceSyncQuery()) { + LOGE("[RelationalStore] cloudSyncer was not support other query"); + return -E_NOT_SUPPORT; + } const auto tableNames = querySyncObject.GetRelationTableNames(); for (const auto &table: tableNames) { int errCode = ChkSchema(table); diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_interfaces_relational_cloud_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_interfaces_relational_cloud_sync_test.cpp index cf4403801d5a89829851b978c732fb2137677198..91e90191a0c2576b8d549f4f1df8c33dbf9b189f 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_interfaces_relational_cloud_sync_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/storage/cloud/distributeddb_interfaces_relational_cloud_sync_test.cpp @@ -470,7 +470,7 @@ HWTEST_F(DistributedDBInterfacesRelationalCloudSyncTest, CloudSyncTest003, TestS LOGD("expect get result upload worker1[primary key]:[local5 - local15)"); VBucket extend; - extend[CloudDbConstant::CURSOR_FIELD] = "0"; + extend[CloudDbConstant::CURSOR_FIELD] = std::to_string(0); std::vector data1; g_virtualCloudDb->Query(g_tables[0], extend, data1); for (int j = 25; j < 35; ++j) { @@ -519,5 +519,20 @@ HWTEST_F(DistributedDBInterfacesRelationalCloudSyncTest, CloudSyncTest004, TestS ASSERT_EQ(delegate->Sync({DEVICE_CLOUD}, SYNC_MODE_CLOUD_MERGE, query, callback, waitTime), DBStatus::OK); WaitForSyncFinish(syncProcess, waitTime); } + +/** + * @tc.name: CloudSyncTest005 + * @tc.desc: sync with device sync query + * @tc.type: FUNC + * @tc.require: + * @tc.author: bty + */ +HWTEST_F(DistributedDBInterfacesRelationalCloudSyncTest, CloudSyncTest005, TestSize.Level1) +{ + Query query = Query::Select().FromTable(g_tables).OrderBy("123", true); + int64_t waitTime = 30; + SyncProcess syncProcess; + ASSERT_EQ(delegate->Sync({DEVICE_CLOUD}, SYNC_MODE_CLOUD_MERGE, query, nullptr, waitTime), DBStatus::NOT_SUPPORT); +} } #endif // RELATIONAL_STORE \ No newline at end of file diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/virtual_cloud_db.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/virtual_cloud_db.cpp index 1c929b013409ff2264a72870e2c48391d4ea858e..7a3e860f72a955fe08382f00c1f29ae11845f6ed 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/virtual_cloud_db.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/virtual_cloud_db.cpp @@ -45,6 +45,7 @@ DBStatus VirtualCloudDb::BatchInsert(const std::string &tableName, std::vector