From 7ef80a837c7f0bd068222393491af9a6b79ff807 Mon Sep 17 00:00:00 2001 From: liao-yonghuang Date: Tue, 27 Jan 2026 15:21:38 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90cursor=E5=A4=B1=E6=95=88=E3=80=91?= =?UTF-8?q?=E3=80=90bugfix=E3=80=91=E4=BF=AE=E5=A4=8D=E5=BC=80=E5=BA=93?= =?UTF-8?q?=E5=90=8E=E9=A9=AC=E4=B8=8A=E5=90=8C=E6=AD=A5=E5=B9=B6=E8=BF=94?= =?UTF-8?q?=E5=9B=9EEXPIRED=5FCURSOR=E6=97=B6=E6=9C=AA=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=B5=84=E4=BA=A7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liao-yonghuang --- .../relational_sync_able_storage_extend.cpp | 4 +- ...single_ver_relational_storage_executor.cpp | 7 +-- ...e_single_ver_relational_storage_executor.h | 2 +- ...eddb_cloud_syncer_download_assets_test.cpp | 63 +++++++++++++++++++ 4 files changed, 69 insertions(+), 7 deletions(-) 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 da9201b5af1..2e5cfc51c2b 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 f1765f26aa1..f3d897c7b5e 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 28854059103..c88108c74d6 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 94ba847f889..04109dfd93e 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 -- Gitee