diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index edd37fd99443c827872629844ec41a863dcd2292..4c4354c477ab3157aa0c124152dd094a18a564df 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -899,6 +899,20 @@ void RdbGeneralStore::Report(const std::string &faultType, int32_t errCode, cons Reporter::GetInstance()->CloudSyncFault()->Report(msg); } +int32_t RdbGeneralStore::SetReference(const std::vector &references) +{ + std::vector properties; + for (const auto &reference : references) { + properties.push_back({reference.sourceTable, reference.targetTable, reference.refFields}); + } + auto status = delegate_->SetReference(properties); + if (status != DistributedDB::DBStatus::OK && status != DistributedDB::DBStatus::PROPERTY_CHANGED) { + ZLOGE("distributed table set reference failed, err:%{public}d", status); + return GeneralError::E_ERROR; + } + return GeneralError::E_OK; +} + int32_t RdbGeneralStore::SetDistributedTables(const std::vector &tables, int32_t type, const std::vector &references) { @@ -919,14 +933,11 @@ int32_t RdbGeneralStore::SetDistributedTables(const std::vector &ta return GeneralError::E_ERROR; } } - std::vector properties; - for (const auto &reference : references) { - properties.push_back({ reference.sourceTable, reference.targetTable, reference.refFields }); - } - auto status = delegate_->SetReference(properties); - if (status != DistributedDB::DBStatus::OK && status != DistributedDB::DBStatus::PROPERTY_CHANGED) { - ZLOGE("distributed table set reference failed, err:%{public}d", status); - return GeneralError::E_ERROR; + if (type == DistributedTableType::DISTRIBUTED_CLOUD) { + auto status = SetReference(references); + if (status != GeneralError::E_OK) { + return GeneralError::E_ERROR; + } } auto [exist, database] = GetDistributedSchema(observer_.meta_); if (exist && type == DistributedTableType::DISTRIBUTED_DEVICE) { diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 3f2d394ef85582957a4688e1ff5ce25da8166e59..dd7c60f61e9292a3b8aa0fe2c2db345c3ad01a36 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -59,6 +59,7 @@ public: bool IsBound(uint32_t user) override; bool IsValid(); int32_t Execute(const std::string &table, const std::string &sql) override; + int32_t SetReference(const std::vector &references); int32_t SetDistributedTables(const std::vector &tables, int32_t type, const std::vector &references) override; int32_t SetTrackerTable(const std::string& tableName, const std::set& trackerColNames,