diff --git a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage_extend.cpp b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage_extend.cpp index da9201b5af166640ba47f7e2c6f6423f7c73e2a5..2e5cfc51c2b3cdb043d81e9812ba148f1cfdc729 100644 --- a/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage_extend.cpp +++ b/frameworks/libs/distributeddb/storage/src/relational/relational_sync_able_storage_extend.cpp @@ -915,8 +915,8 @@ int RelationalSyncAbleStorage::DeleteOneCloudNoneExistRecord(const std::string & int errCode = E_OK; if (record.isNeedDelete) { IAssetLoader::AssetRecord removeAssets = {.gid = record.gid, .prefix = record.pkValues.at(0)}; - errCode = handle->GetCloudNoneExistRecordAssets(tableName, record.dataRowid, record.isExistAsset, - removeAssets); + errCode = handle->GetCloudNoneExistRecordAssets(GetSchemaInfo().GetTable(tableName), record.dataRowid, + record.isExistAsset, removeAssets); if (errCode != E_OK) { LOGE("[DeleteOneCloudNoneExistRecord] remove cloud not exist record assets failed.%d, tableName:%s", errCode, DBCommon::StringMiddleMaskingWithLen(tableName).c_str()); 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 f1765f26aa1db347fee4236854340cef6128e36d..f3d897c7b5ed107dd9c156db874a34c4c358cfce 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 @@ -2017,21 +2017,20 @@ int SQLiteSingleVerRelationalStorageExecutor::DropTempTable(const std::string &t return SQLiteRelationalUtils::DropTempTable(tableName, dbHandle_); } -int SQLiteSingleVerRelationalStorageExecutor::GetCloudNoneExistRecordAssets(const std::string &tableName, +int SQLiteSingleVerRelationalStorageExecutor::GetCloudNoneExistRecordAssets(const TableInfo &tableInfo, int64_t dataRowid, bool &isExistAsset, IAssetLoader::AssetRecord &removeAssets) { - TableInfo tableInfo = localSchema_.GetTable(tableName); for (const auto &fieldInfo : tableInfo.GetFieldInfos()) { Assets assets; int errCode = E_OK; if (fieldInfo.IsAssetType()) { - errCode = GetAssetOnTable(tableName, fieldInfo.GetFieldName(), {dataRowid}, assets); + errCode = GetAssetOnTable(tableInfo.GetTableName(), fieldInfo.GetFieldName(), {dataRowid}, assets); if (errCode != E_OK) { LOGE("[GetCloudNoneExistRecordAssets] failed to get cloud asset on table, %d.", errCode); return errCode; } } else if (fieldInfo.IsAssetsType()) { - errCode = GetCloudAssetsOnTable(tableName, fieldInfo.GetFieldName(), {dataRowid}, assets); + errCode = GetCloudAssetsOnTable(tableInfo.GetTableName(), fieldInfo.GetFieldName(), {dataRowid}, assets); if (errCode != E_OK) { LOGE("[GetCloudNoneExistRecordAssets] failed to get cloud assets on table, %d.", errCode); 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 28854059103cf45248c25f71faf87a45f670b0e4..c88108c74d66e09ae18f5e47ac07352926fc3a0a 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 @@ -292,7 +292,7 @@ public: #ifdef USE_DISTRIBUTEDDB_CLOUD int PutCloudGid(const std::string &tableName, std::vector &data) const; - int GetCloudNoneExistRecordAssets(const std::string &tableName, int64_t dataRowid, bool &isExistAsset, + int GetCloudNoneExistRecordAssets(const TableInfo &tableInfo, int64_t dataRowid, bool &isExistAsset, IAssetLoader::AssetRecord &removeAssets); int RemoveCloudNoneExistRecordAssets(const std::string &tableName, diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_download_assets_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_download_assets_test.cpp index 94ba847f88957872b2654c5625af4342c0230c4a..04109dfd93e7b66a9bf07b6eb04fee6c5bf4b5d7 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_download_assets_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/cloud/distributeddb_cloud_syncer_download_assets_test.cpp @@ -3125,5 +3125,68 @@ HWTEST_F(DistributedDBCloudSyncerDownloadAssetsTest, ExpireCursor003, TestSize.L g_virtualCloudDb->ForkQueryAllGid(nullptr); g_virtualAssetLoader->SetRemoveLocalAssetsCallback(nullptr); } + +/** + * @tc.name: ExpireCursor004 + * @tc.desc: Test open store and sync when query return EXPIRED_CURSOR + * @tc.type: FUNC + * @tc.require: + * @tc.author: liaoyonghuang + */ +HWTEST_F(DistributedDBCloudSyncerDownloadAssetsTest, ExpireCursor004, TestSize.Level0) +{ + /** + * @tc.steps:step1. init cloud data and sync to local, then close db + * @tc.expected: step1. return OK. + */ + int dataCount = 90; + InsertCloudDBData(0, dataCount, 0, ASSETS_TABLE_NAME); + CallSync({ASSETS_TABLE_NAME}, SYNC_MODE_CLOUD_MERGE, DBStatus::OK); + EXPECT_EQ(g_mgr.CloseStore(g_delegate), DBStatus::OK); + g_delegate = nullptr; + /** + * @tc.steps:step2. open db + * @tc.expected: step2. return OK. + */ + ASSERT_EQ( + g_mgr.OpenStore(g_storePath, STORE_ID, RelationalStoreDelegate::Option{.observer = g_observer}, g_delegate), + DBStatus::OK); + ASSERT_EQ(g_delegate->SetCloudDB(g_virtualCloudDb), DBStatus::OK); + ASSERT_EQ(g_delegate->SetIAssetLoader(g_virtualAssetLoader), DBStatus::OK); + DataBaseSchema dataBaseSchema; + GetCloudDbSchema(dataBaseSchema); + ASSERT_EQ(g_delegate->SetCloudDbSchema(dataBaseSchema), DBStatus::OK); + /** + * @tc.steps:step3. sync when query return EXPIRED_CURSOR + * @tc.expected: step3. return OK. + */ + g_virtualCloudDb->ForkAfterQueryResult([](VBucket &, std::vector &) { + return DBStatus::EXPIRED_CURSOR; + }); + g_virtualCloudDb->ForkQueryAllGid([](const std::string &, VBucket &, std::vector &) { + return DBStatus::QUERY_END; + }); + int removeCount = 0; + g_virtualAssetLoader->SetRemoveLocalAssetsCallback([&removeCount](std::map &assets) { + removeCount++; + return OK; + }); + g_observer->ClearChangedData(); + CallSync({ASSETS_TABLE_NAME}, SYNC_MODE_CLOUD_MERGE, DBStatus::OK, DBStatus::EXPIRED_CURSOR); + /** + * @tc.steps:step4. check data and asset observer + * @tc.expected: step4. return OK. + */ + EXPECT_EQ(removeCount, dataCount); + EXPECT_EQ(g_virtualAssetLoader->GetBatchRemoveCount(), 1); + auto changeData = g_observer->GetSavedChangedData(); + EXPECT_EQ(changeData.size(), 1u); + EXPECT_EQ(changeData[ASSETS_TABLE_NAME].tableName, ASSETS_TABLE_NAME); + EXPECT_EQ(changeData[ASSETS_TABLE_NAME].type, ChangedDataType::ASSET); + EXPECT_EQ(changeData[ASSETS_TABLE_NAME].primaryData[ChangeType::OP_DELETE].size(), static_cast(dataCount)); + g_virtualCloudDb->ForkAfterQueryResult(nullptr); + g_virtualCloudDb->ForkQueryAllGid(nullptr); + g_virtualAssetLoader->SetRemoveLocalAssetsCallback(nullptr); +} } // namespace #endif // RELATIONAL_STORE