代码拉取完成,页面将自动刷新
diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp
index 4208888a3..5bfda5119 100644
--- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp
+++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_sqlite_ext.cpp
@@ -1380,8 +1380,8 @@ void ClearTheLogAfterDropTable(sqlite3 *db, const char *tableName, const char *s
if (tableType == DEVICE_TYPE) {
RegisterGetSysTime(db);
RegisterGetLastTime(db);
- std::string sql = "UPDATE " + logTblName + " SET data_key=-1, flag=0x03, timestamp=get_sys_time(0) "
- "WHERE flag&0x03=0x02 AND timestamp<" + std::to_string(dropTimeStamp);
+ std::string sql = "UPDATE " + logTblName + " SET data_key=-1, flag=flag|0x01, timestamp=get_sys_time(0) "
+ "WHERE flag&0x01=0x0 AND timestamp<" + std::to_string(dropTimeStamp);
(void)sqlite3_exec(db, sql.c_str(), nullptr, nullptr, nullptr);
} else {
HandleDropCloudSyncTable(db, tableStr);
diff --git a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp
index 28dff8f32..dc909a9f7 100644
--- a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp
+++ b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage.cpp
@@ -578,11 +578,11 @@ int RelationalSyncAbleStorage::SaveSyncDataItems(const QueryObject &object, std:
errCode = handle->SaveSyncItems(inserter);
ChangedData data = inserter.GetChangedData();
data.properties.isP2pSyncDataChange = !dataItems.empty();
- bool emptyChangedData = data.field.empty() && data.primaryData[OP_INSERT].empty() &&
- data.primaryData[OP_UPDATE].empty() && data.primaryData[OP_DELETE].empty();
DBDfxAdapter::FinishTracing();
- if (errCode == E_OK && !emptyChangedData) {
+ bool isEmptyChangedData = data.field.empty() && data.primaryData[OP_INSERT].empty() &&
+ data.primaryData[OP_UPDATE].empty() && data.primaryData[OP_DELETE].empty();
+ if (errCode == E_OK && !isEmptyChangedData) {
// dataItems size > 0 now because already check before
// all dataItems will write into db now, so need to observer notify here
// if some dataItems will not write into db in the future, observer notify here need change
diff --git a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_data_inserter.cpp b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_data_inserter.cpp
index 342676280..69c920fc1 100644
--- a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_data_inserter.cpp
+++ b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_data_inserter.cpp
@@ -248,15 +248,8 @@ int RelationalSyncDataInserter::GetDeleteSyncDataStmt(sqlite3 *db, sqlite3_stmt
int RelationalSyncDataInserter::GetSaveLogStatement(sqlite3 *db, sqlite3_stmt *&logStmt, sqlite3_stmt *&queryStmt)
{
- std::string conflictPk;
- std::string selCondition;
- if (mode_ == DistributedTableMode::COLLABORATION) {
- conflictPk = "ON CONFLICT(hash_key)";
- selCondition = " WHERE hash_key = ?;";
- } else {
- conflictPk = "ON CONFLICT(hash_key, device)";
- selCondition = " WHERE hash_key = ? AND device = ?;";
- }
+ /*
+ std::string conflictPk = "ON CONFLICT(data_key)";
const std::string tableName = DBConstant::RELATIONAL_PREFIX + query_.GetTableName() + "_log";
std::string dataFormat = "?, '" + hashDevId_ + "', ?, ?, ?, ?, ?";
std::string columnList = "data_key, device, ori_device, timestamp, wtimestamp, flag, hash_key";
@@ -267,11 +260,31 @@ int RelationalSyncDataInserter::GetSaveLogStatement(sqlite3 *db, sqlite3_stmt *&
" ori_device = excluded.ori_device, timestamp = excluded.timestamp, wtimestamp = excluded.wtimestamp,"
" flag = excluded.flag, cursor = excluded.cursor;";
int errCode = SQLiteUtils::GetStatement(db, sql, logStmt);
+ if (errCode != E_OK) {
+ LOGE("[info statement] Get log statement fail! errCode:%d", errCode);
+ return errCode;
+ }*/
+
+ const std::string logTableName = DBConstant::RELATIONAL_PREFIX + query_.GetTableName() + "_log";
+ std::string sql = "UPDATE " + logTableName + " SET device=?, ori_device=?, timestamp=?," +
+ "wtimestamp=?,flag=?, hash_key=? where data_key=? AND hash_key=?";
+ if (mode_ == DistributedTableMode::COLLABORATION) {
+ sql += " AND device=?";
+ }
+ int errCode = SQLiteUtils::GetStatement(db, sql, logStmt);
if (errCode != E_OK) {
LOGE("[info statement] Get log statement fail! errCode:%d", errCode);
return errCode;
}
- std::string selectSql = "SELECT " + columnList + " FROM " + tableName + selCondition;
+
+ std::string selCondition;
+ if (mode_ == DistributedTableMode::COLLABORATION) {
+ selCondition = " WHERE data_key = ?;";
+ } else {
+ selCondition = " WHERE hash_key = ? AND device = ?;";
+ }
+ std::string columnList = "data_key, device, ori_device, timestamp, wtimestamp, flag, hash_key";
+ std::string selectSql = "SELECT " + columnList + " FROM " + logTableName + selCondition;
errCode = SQLiteUtils::GetStatement(db, selectSql, queryStmt);
if (errCode != E_OK) {
SQLiteUtils::ResetStatement(logStmt, true, errCode);
@@ -375,8 +388,8 @@ int RelationalSyncDataInserter::BindHashKeyAndDev(const DataItem &dataItem, sqli
return errCode;
}
-int RelationalSyncDataInserter::SaveSyncLog(sqlite3 *db, sqlite3_stmt *statement, sqlite3_stmt *queryStmt,
- const DataItem &dataItem, int64_t rowid)
+int RelationalSyncDataInserter::SaveSyncLog(sqlite3_stmt *statement, sqlite3_stmt *queryStmt, const DataItem &dataItem,
+ int64_t rowid)
{
LogInfo logInfoGet;
int errCode = SQLiteRelationalUtils::GetLogInfoPre(queryStmt, mode_, dataItem, logInfoGet);
@@ -398,17 +411,27 @@ int RelationalSyncDataInserter::SaveSyncLog(sqlite3 *db, sqlite3_stmt *statement
}
// bind
- SQLiteUtils::BindInt64ToStatement(statement, 1, rowid); // 1 means dataKey index
+ std::vector<uint8_t> devId(logInfoBind.device.begin(), logInfoBind.device.end());
+ SQLiteUtils::BindBlobToStatement(statement, 1, devId); // 1 means dev index
std::vector<uint8_t> originDev(logInfoBind.originDev.begin(), logInfoBind.originDev.end());
SQLiteUtils::BindBlobToStatement(statement, 2, originDev); // 2 means ori_dev index
SQLiteUtils::BindInt64ToStatement(statement, 3, logInfoBind.timestamp); // 3 means timestamp index
SQLiteUtils::BindInt64ToStatement(statement, 4, logInfoBind.wTimestamp); // 4 means w_timestamp index
SQLiteUtils::BindInt64ToStatement(statement, 5, logInfoBind.flag); // 5 means flag index
SQLiteUtils::BindBlobToStatement(statement, 6, logInfoBind.hashKey); // 6 means hashKey index
+ SQLiteUtils::BindInt64ToStatement(statement, 7, rowid); // 7 means dataKey index
+ std::vector<uint8_t> oldHashDevId(hashDevId_.begin(), hashDevId_.end());
+ SQLiteUtils::BindBlobToStatement(statement, 8, oldHashDevId); // 8 means hash_key index in where condition
+ if (mode_ == DistributedTableMode::COLLABORATION) {
+ SQLiteUtils::BindBlobToStatement(statement, 9, devId); // 9 means dev index in where condition
+ }
errCode = SQLiteUtils::StepWithRetry(statement, false);
if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_DONE)) {
return E_OK;
}
+ if (errCode != E_OK) {
+ LOGE("lyh_test:SaveSyncLog failed ");
+ }
return errCode;
}
diff --git a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_data_inserter.h b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_data_inserter.h
index fd03889b3..0d9fc7f7d 100644
--- a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_data_inserter.h
+++ b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_data_inserter.h
@@ -74,8 +74,7 @@ public:
int BindHashKeyAndDev(const DataItem &dataItem, sqlite3_stmt *stmt, int beginIndex);
- int SaveSyncLog(sqlite3 *db, sqlite3_stmt *statement, sqlite3_stmt *queryStmt, const DataItem &dataItem,
- int64_t rowid);
+ int SaveSyncLog(sqlite3_stmt *statement, sqlite3_stmt *queryStmt, const DataItem &dataItem, int64_t rowid);
ChangedData &GetChangedData();
private:
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 5e432929c..ccff57786 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
@@ -443,8 +443,16 @@ int SQLiteRelationalStore::CreateDistributedTable(const std::string &tableName,
}
}
+ auto mode = sqliteStorageEngine_->GetProperties().GetDistributedTableMode();
+ std::string localIdentity; // collaboration mode need local identify
+ if (mode == DistributedTableMode::COLLABORATION) {
+ int errCode = syncAbleEngine_->GetLocalIdentity(localIdentity);
+ if (errCode != E_OK || localIdentity.empty()) {
+ LOGW("Get local identity failed: %d", errCode);
+ }
+ }
bool schemaChanged = false;
- int errCode = sqliteStorageEngine_->CreateDistributedTable(tableName, DBCommon::TransferStringToHex(""),
+ int errCode = sqliteStorageEngine_->CreateDistributedTable(tableName, DBCommon::TransferStringToHex(localIdentity),
schemaChanged, syncType, trackerSchemaChanged);
if (errCode != E_OK) {
LOGE("Create distributed table failed. %d", errCode);
@@ -1732,7 +1740,16 @@ int SQLiteRelationalStore::SetDistributedSchema(const DistributedSchema &schema)
LOGE("[RelationalStore] engine was not initialized");
return -E_INVALID_DB;
}
- auto [errCode, isSchemaChange] = sqliteStorageEngine_->SetDistributedSchema(schema);
+
+ auto mode = sqliteStorageEngine_->GetProperties().GetDistributedTableMode();
+ std::string localIdentity; // collaboration mode need local identify
+ if (mode == DistributedTableMode::COLLABORATION) {
+ int errCode = syncAbleEngine_->GetLocalIdentity(localIdentity);
+ if (errCode != E_OK || localIdentity.empty()) {
+ LOGW("Get local identity failed: %d", errCode);
+ }
+ }
+ auto [errCode, isSchemaChange] = sqliteStorageEngine_->SetDistributedSchema(schema, localIdentity);
if (errCode != E_OK) {
return errCode;
}
diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp
index 287802355..e1c3be34c 100644
--- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp
+++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.cpp
@@ -1080,7 +1080,8 @@ int SQLiteSingleRelationalStorageEngine::UpdateExtendField(const DistributedDB::
return handle->Commit();
}
-std::pair<int, bool> SQLiteSingleRelationalStorageEngine::SetDistributedSchema(const DistributedSchema &schema)
+std::pair<int, bool> SQLiteSingleRelationalStorageEngine::SetDistributedSchema(const DistributedSchema &schema,
+ const std::string &localIdentity)
{
std::lock_guard<std::mutex> autoLock(createDistributedTableMutex_);
auto schemaObj = GetSchema();
@@ -1099,7 +1100,7 @@ std::pair<int, bool> SQLiteSingleRelationalStorageEngine::SetDistributedSchema(c
LOGE("new schema version no upgrade old:%" PRIu32 " new:%" PRIu32, localSchema.version, schema.version);
errCode = -E_INVALID_ARGS;
} else {
- errCode = SetDistributedSchemaInner(schemaObj, schema);
+ errCode = SetDistributedSchemaInner(schemaObj, schema, localIdentity);
}
if (errCode == E_OK) {
SetSchema(schemaObj);
@@ -1108,7 +1109,7 @@ std::pair<int, bool> SQLiteSingleRelationalStorageEngine::SetDistributedSchema(c
}
int SQLiteSingleRelationalStorageEngine::SetDistributedSchemaInner(RelationalSchemaObject &schemaObj,
- const DistributedSchema &schema)
+ const DistributedSchema &schema, const std::string &localIdentity)
{
int errCode = E_OK;
auto *handle = static_cast<SQLiteSingleVerRelationalStorageExecutor *>(FindExecutor(true, OperatePerm::NORMAL_PERM,
@@ -1137,7 +1138,9 @@ int SQLiteSingleRelationalStorageEngine::SetDistributedSchemaInner(RelationalSch
continue;
}
tableInfo.SetDistributedTable(schemaObj.GetDistributedTable(table.tableName));
- errCode = handle->RenewTableTrigger(schemaObj.GetTableMode(), tableInfo, tableInfo.GetTableSyncType());
+ bool isNoPriKeyTable = tableInfo.IsNoPkTable();
+ errCode = handle->RenewTableTrigger(schemaObj.GetTableMode(), tableInfo, tableInfo.GetTableSyncType(),
+ isNoPriKeyTable ? localIdentity : "");
if (errCode != E_OK) {
LOGE("Failed to refresh trigger while setting up distributed schema: %d", errCode);
(void)handle->Rollback();
diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h
index c7e8f359e..ce9b1709e 100644
--- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h
+++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_relational_storage_engine.h
@@ -62,7 +62,7 @@ public:
const std::map<std::string, std::string> &sharedTableOriginNames);
int UpdateExtendField(const TrackerSchema &schema);
- std::pair<int, bool> SetDistributedSchema(const DistributedSchema &schema);
+ std::pair<int, bool> SetDistributedSchema(const DistributedSchema &schema, const std::string &localIdentity);
protected:
StorageExecutor *NewSQLiteStorageExecutor(sqlite3 *dbHandle, bool isWrite, bool isMemDb) override;
int Upgrade(sqlite3 *db) override;
@@ -124,7 +124,8 @@ private:
int CheckIfExistUserTable(SQLiteSingleVerRelationalStorageExecutor *&handle, const DataBaseSchema &cloudSchema,
const std::map<std::string, std::string> &alterTableNames, const RelationalSchemaObject &schema);
- int SetDistributedSchemaInner(RelationalSchemaObject &schemaObj, const DistributedSchema &schema);
+ int SetDistributedSchemaInner(RelationalSchemaObject &schemaObj, const DistributedSchema &schema,
+ const std::string &localIdentity);
RelationalSchemaObject schema_;
RelationalSchemaObject trackerSchema_;
diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp
index ba1b5c1da..feb80a7f5 100644
--- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp
+++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.cpp
@@ -1047,7 +1047,10 @@ int SQLiteSingleVerRelationalStorageExecutor::SaveSyncDataItem(RelationalSyncDat
bool isUpdate = isExist && mode_ == DistributedTableMode::COLLABORATION;
errCode = SaveSyncDataItem(item, isUpdate, saveStmt, inserter, rowid);
if (errCode == E_OK || errCode == -E_NOT_FOUND) {
- errCode = inserter.SaveSyncLog(dbHandle_, saveStmt.saveLogStmt, saveStmt.queryStmt, item, rowid);
+ errCode = inserter.SaveSyncLog(saveStmt.saveLogStmt, saveStmt.queryStmt, item, rowid);
+ }
+ if (errCode != E_OK) {
+ LOGE("lyh_test: %s", sqlite3_errmsg(dbHandle_));
}
return errCode;
}
diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.h
index edcc271ed..e69834cef 100644
--- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.h
+++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_executor.h
@@ -182,7 +182,8 @@ public:
int CheckIfExistUserTable(const std::string &tableName);
void SetLogicDelete(bool isLogicDelete);
- int RenewTableTrigger(DistributedTableMode mode, const TableInfo &tableInfo, TableSyncType syncType);
+ int RenewTableTrigger(DistributedTableMode mode, const TableInfo &tableInfo, TableSyncType syncType,
+ const std::string &localIdentity = "");
std::pair<int, uint32_t> GetAssetsByGidOrHashKey(const TableSchema &tableSchema, const std::string &gid,
const Bytes &hashKey, VBucket &assets);
diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp
index ecab72708..7c8765c77 100644
--- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp
+++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_single_ver_relational_storage_extend_executor.cpp
@@ -1139,10 +1139,10 @@ int SQLiteSingleVerRelationalStorageExecutor::BindStmtWithCloudGidInner(const st
}
int SQLiteSingleVerRelationalStorageExecutor::RenewTableTrigger(DistributedTableMode mode,
- const TableInfo &tableInfo, TableSyncType syncType)
+ const TableInfo &tableInfo, TableSyncType syncType, const std::string &localIdentity)
{
auto tableManager = LogTableManagerFactory::GetTableManager(mode, syncType);
- return tableManager->AddRelationalLogTableTrigger(dbHandle_, tableInfo, "");
+ return tableManager->AddRelationalLogTableTrigger(dbHandle_, tableInfo, localIdentity);
}
int SQLiteSingleVerRelationalStorageExecutor::DoCleanAssetId(const std::string &tableName,
diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp
index d2ea33b5b..cb39f4ae4 100644
--- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp
+++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp
@@ -241,7 +241,7 @@ int SQLiteUtils::GetStatement(sqlite3 *db, const std::string &sql, sqlite3_stmt
}
int errCode = sqlite3_prepare_v2(db, sql.c_str(), NO_SIZE_LIMIT, &statement, nullptr);
if (errCode != SQLITE_OK) {
- LOGE("Prepare SQLite statement failed:%d, sys:%d", errCode, errno);
+ LOGE("Prepare SQLite statement failed:%d, sys:%d, msg: %s", errCode, errno, sqlite3_errmsg(db));
errCode = SQLiteUtils::MapSQLiteErrno(errCode);
SQLiteUtils::ResetStatement(statement, true, errCode);
return errCode;
diff --git a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
index f7dfc105f..4036af459 100644
--- a/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
+++ b/frameworks/libs/distributeddb/test/unittest/common/storage/distributeddb_rdb_collaboration_test.cpp
@@ -2057,6 +2057,67 @@ HWTEST_F(DistributedDBRDBCollaborationTest, NormalSync021, TestSize.Level0)
EXPECT_EQ(callStatus, INVALID_ARGS);
}
+/**
+ * @tc.name: NormalSync022
+ * @tc.desc: Test drop table after sync.
+ * @tc.type: FUNC
+ * @tc.require:
+ * @tc.author: liaoyonghuang
+ */
+HWTEST_F(DistributedDBRDBCollaborationTest, NormalSync022, TestSize.Level0)
+{
+ /**
+ * @tc.steps: step1. Create device table and cloud table in COLLABORATION
+ * @tc.expected: step1.ok
+ */
+ ASSERT_NO_FATAL_FAILURE(InitDelegate());
+ std::string tableName = "noPriKeyTable";
+ std::string sql = "CREATE TABLE IF NOT EXISTS " + tableName + "(field1 INTEGER, field2 INT);";
+ ASSERT_EQ(SQLiteUtils::ExecuteRawSQL(db_, sql), E_OK);
+ auto distributedSchema = GetDistributedSchema(tableName, {"field1", "field2"});
+ deviceB_->SetDistributedSchema(distributedSchema);
+ EXPECT_EQ(delegate_->CreateDistributedTable(tableName, TableSyncType::DEVICE_COOPERATION), OK);
+ EXPECT_EQ(delegate_->SetDistributedSchema(distributedSchema), OK);
+ /**
+ * @tc.steps: step2. Insert one piece of data at each end
+ * @tc.expected: step2.ok
+ */
+ TableSchema tableSchema = {tableName, "", {{"field1", TYPE_INDEX<int64_t>}, {"field2", TYPE_INDEX<int64_t>}}};
+ ASSERT_EQ(RDBDataGenerator::InsertVirtualLocalDBData(0, 1, deviceB_, tableSchema), E_OK);
+ ASSERT_EQ(RDBDataGenerator::PrepareVirtualDeviceEnv(tableSchema.name, db_, deviceB_), E_OK);
+ sql = "insert into " + tableName + " values(1, 1)";
+ EXPECT_EQ(SQLiteUtils::ExecuteRawSQL(db_, sql), E_OK);
+ std::string checkLogCountSql = "select count(*) from " + DBCommon::GetLogTableName(tableName);
+ std::string checkDataCountSql = "select count(*) from " + tableName;
+ int logCount = 0;
+ int dataCount = 0;
+ EXPECT_EQ(SQLiteUtils::GetCountBySql(db_, checkLogCountSql, logCount), E_OK);
+ EXPECT_EQ(SQLiteUtils::GetCountBySql(db_, checkDataCountSql, dataCount), E_OK);
+ EXPECT_EQ(logCount, 1);
+ EXPECT_EQ(dataCount, 1);
+ /**
+ * @tc.steps: step3. Sync a piece of data
+ * @tc.expected: step3.ok
+ */
+ Query query = Query::Select(tableSchema.name);
+ DistributedDBToolsUnitTest::BlockSync(*delegate_, query, SYNC_MODE_PULL_ONLY, OK, {deviceB_->GetDeviceId()});
+ EXPECT_EQ(SQLiteUtils::GetCountBySql(db_, checkLogCountSql, logCount), E_OK);
+ EXPECT_EQ(SQLiteUtils::GetCountBySql(db_, checkDataCountSql, dataCount), E_OK);
+ EXPECT_EQ(dataCount, 2);
+ EXPECT_EQ(logCount, 2);
+ /**
+ * @tc.steps: step4. Drop table and check log count
+ * @tc.expected: step4.ok
+ */
+ checkLogCountSql.append(" where data_key = -1 and flag&0x01 = 0x1;");
+ EXPECT_EQ(SQLiteUtils::GetCountBySql(db_, checkLogCountSql, logCount), E_OK);
+ EXPECT_EQ(logCount, 0);
+ std::string dropTableSql = "drop table " + tableName;
+ EXPECT_EQ(SQLiteUtils::ExecuteRawSQL(db_, dropTableSql), E_OK);
+ EXPECT_EQ(SQLiteUtils::GetCountBySql(db_, checkLogCountSql, logCount), E_OK);
+ EXPECT_EQ(logCount, 2);
+}
+
/**
* @tc.name: InvalidSync001
* @tc.desc: Test remote set empty distributed schema and sync.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。