From a729fa8be7aa5fd5e00c7874ccd6b03d08e8d3d9 Mon Sep 17 00:00:00 2001 From: lianhuix Date: Sat, 8 Oct 2022 14:36:13 +0800 Subject: [PATCH 1/5] Fix ICSL reviews Signed-off-by: lianhuix --- .../common/include/json_object.h | 2 +- .../common/include/relational/prepared_stmt.h | 2 +- .../relational/relational_result_set_impl.h | 2 +- .../relational/relational_schema_object.h | 2 +- .../distributeddb/common/src/db_common.cpp | 2 +- .../libs/distributeddb/common/src/parcel.cpp | 4 ++-- .../relational/relational_schema_object.cpp | 6 +++--- .../distributeddb/include/query_expression.h | 2 +- .../storage/src/sqlite/query_object.cpp | 7 +------ .../storage/src/sqlite/query_object.h | 1 - .../storage/src/sqlite/query_sync_object.cpp | 4 +++- .../sqlite/split_device_log_table_manager.h | 2 +- .../sqlite/sqlite_local_storage_executor.h | 19 +------------------ .../src/sqlite/sqlite_query_helper.cpp | 19 ------------------- .../sqlite_single_ver_natural_store.cpp | 2 +- .../sqlite/sqlite_single_ver_natural_store.h | 14 +++++++------- ...te_single_ver_natural_store_connection.cpp | 9 +++------ ...te_single_ver_schema_database_upgrader.cpp | 9 ++------- .../sqlite_single_ver_storage_engine.cpp | 12 ++++++------ .../src/sqlite/sqlite_storage_executor.h | 2 +- .../storage/src/sqlite/sqlite_utils.cpp | 2 +- 21 files changed, 38 insertions(+), 86 deletions(-) diff --git a/frameworks/libs/distributeddb/common/include/json_object.h b/frameworks/libs/distributeddb/common/include/json_object.h index 3d79c31acb5..aa2b0a37899 100644 --- a/frameworks/libs/distributeddb/common/include/json_object.h +++ b/frameworks/libs/distributeddb/common/include/json_object.h @@ -28,7 +28,7 @@ namespace DistributedDB { // JsonObject is the abstraction of JsonString, it hides the JsonLib that we use and other messy details. // JsonObject do not support concurrence inherently, use it locally or under mutex protection. -class JsonObject { +class JsonObject final { public: // Set max allowed nest depth and return the value before set. static uint32_t SetMaxNestDepth(uint32_t nestDepth); diff --git a/frameworks/libs/distributeddb/common/include/relational/prepared_stmt.h b/frameworks/libs/distributeddb/common/include/relational/prepared_stmt.h index 38eb2fe7cc1..ddcdd9df5ea 100644 --- a/frameworks/libs/distributeddb/common/include/relational/prepared_stmt.h +++ b/frameworks/libs/distributeddb/common/include/relational/prepared_stmt.h @@ -46,7 +46,7 @@ private: static const int VERSION_1 = 1; static const int CURRENT_VERSION = VERSION_1; - ExecutorOperation opCode_; + ExecutorOperation opCode_ = ExecutorOperation::MIN_LIMIT; std::string sql_; std::vector bindArgs_; }; diff --git a/frameworks/libs/distributeddb/common/include/relational/relational_result_set_impl.h b/frameworks/libs/distributeddb/common/include/relational/relational_result_set_impl.h index 995a7229281..dd1dc0f2dc0 100644 --- a/frameworks/libs/distributeddb/common/include/relational/relational_result_set_impl.h +++ b/frameworks/libs/distributeddb/common/include/relational/relational_result_set_impl.h @@ -28,7 +28,7 @@ namespace DistributedDB { class RelationalResultSetImpl : public ResultSet { public: RelationalResultSetImpl() - : isClosed_(false), dataSetSize_(0), index_(-1), dataSet_(), colNames_(), cacheDataSet_(), mutex_() + : isClosed_(false), dataSetSize_(0), index_(-1) {} ~RelationalResultSetImpl() = default; diff --git a/frameworks/libs/distributeddb/common/include/relational/relational_schema_object.h b/frameworks/libs/distributeddb/common/include/relational/relational_schema_object.h index 7cb622ff622..270b6220872 100644 --- a/frameworks/libs/distributeddb/common/include/relational/relational_schema_object.h +++ b/frameworks/libs/distributeddb/common/include/relational/relational_schema_object.h @@ -38,7 +38,7 @@ public: // Should be called on an invalid SchemaObject, create new SchemaObject if need to reparse int ParseFromSchemaString(const std::string &inSchemaString) override; - void AddRelationalTable(const TableInfo& tb); + void AddRelationalTable(const TableInfo& table); void RemoveRelationalTable(const std::string &tableName); diff --git a/frameworks/libs/distributeddb/common/src/db_common.cpp b/frameworks/libs/distributeddb/common/src/db_common.cpp index 9b51158ddca..c5eabb245e2 100644 --- a/frameworks/libs/distributeddb/common/src/db_common.cpp +++ b/frameworks/libs/distributeddb/common/src/db_common.cpp @@ -272,7 +272,7 @@ int DBCommon::RemoveAllFilesOfDirectory(const std::string &dir, bool isNeedRemov RemoveDirectories(fileList, OS::FileType::PATH); if (isNeedRemoveDir) { // Pay attention to the order of deleting the directory - if (OS::CheckPathExistence(dir) && OS::RemoveDBDirectory(dir.c_str()) != 0) { + if (OS::CheckPathExistence(dir) && OS::RemoveDBDirectory(dir) != 0) { LOGI("Remove the directory error:%d", errno); errCode = -E_SYSTEM_API_FAIL; } diff --git a/frameworks/libs/distributeddb/common/src/parcel.cpp b/frameworks/libs/distributeddb/common/src/parcel.cpp index 815597416fa..2a30404e31c 100644 --- a/frameworks/libs/distributeddb/common/src/parcel.cpp +++ b/frameworks/libs/distributeddb/common/src/parcel.cpp @@ -48,7 +48,7 @@ bool Parcel::IsError() const int Parcel::WriteBool(bool data) { - uint8_t value = data ? 1 : 0; + uint8_t value = (data ? 1 : 0); return WriteUInt8(value); } @@ -56,7 +56,7 @@ uint32_t Parcel::ReadBool(bool &val) { uint8_t intVal = 0; uint32_t len = ReadUInt8(intVal); - val = intVal == 1 ? true : false; + val = (intVal == 1); return len; } diff --git a/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp b/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp index fa8936ca516..6fa207c68c1 100644 --- a/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp +++ b/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp @@ -89,11 +89,11 @@ void RelationalSchemaObject::GenerateSchemaString() schemaString_ += "}"; } -void RelationalSchemaObject::AddRelationalTable(const TableInfo &tb) +void RelationalSchemaObject::AddRelationalTable(const TableInfo &table) { - tables_[tb.GetTableName()] = tb; + tables_[table.GetTableName()] = table; isValid_ = true; - if (tb.GetPrimaryKey().size() > 1) { // Table with composite primary keys + if (table.GetPrimaryKey().size() > 1) { // Table with composite primary keys // Composite primary keys are supported since version 2.1 schemaVersion_ = SchemaConstant::SCHEMA_CURRENT_VERSION; } diff --git a/frameworks/libs/distributeddb/include/query_expression.h b/frameworks/libs/distributeddb/include/query_expression.h index 5c931d45035..968d4de0136 100644 --- a/frameworks/libs/distributeddb/include/query_expression.h +++ b/frameworks/libs/distributeddb/include/query_expression.h @@ -69,7 +69,7 @@ struct QueryObjNode { bool IsValid() { return operFlag != QueryObjType::OPER_ILLEGAL && - type != QueryValueType::VALUE_TYPE_INVALID; + type != QueryValueType::VALUE_TYPE_INVALID; } }; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp index da9b9a479fa..cef020b87cc 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp @@ -14,6 +14,7 @@ */ #include "query_object.h" + #include "db_errno.h" #include "get_query_info.h" #include "log_print.h" @@ -267,7 +268,6 @@ int QueryObject::ParseNodeByOperFlag(const std::list::iterator &it default: return E_OK; } - return E_OK; } int QueryObject::CheckLinkerBefore(const std::list::iterator &iter) const @@ -282,11 +282,6 @@ int QueryObject::CheckLinkerBefore(const std::list::iterator &iter return E_OK; } -bool QueryObject::IsRelationalQuery() const -{ - return isTableNameSpecified_; -} - int QueryObject::CheckEqualFormat(const std::list::iterator &iter) const { if (!schema_.IsSchemaValid()) { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h index 4f71e0e8b3e..b62b2211361 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h @@ -108,7 +108,6 @@ private: void ClearNodesFlag(); void GetAttrFromQueryObjNodes(); int CheckInKeys() const; - bool IsRelationalQuery() const; SchemaObject schema_; // used to check and parse schema filed int limit_; 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 c42d8c42218..50b4b9d0ca8 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp @@ -23,6 +23,8 @@ namespace DistributedDB { namespace { const std::string MAGIC = "remote query"; +// Max value size of each QueryObjNode, current is In & NotIn predicate which is 128 +const int MAX_VALUE_SIZE = 128; int SerializeDataObjNode(Parcel &parcel, const QueryObjNode &objNode) { @@ -63,7 +65,7 @@ int DeSerializeDataObjNode(Parcel &parcel, QueryObjNode &objNode) uint32_t valueSize = 0; (void)parcel.ReadUInt32(valueSize); - if (parcel.IsError()) { + if (parcel.IsError() || valueSize > MAX_VALUE_SIZE) { return -E_INVALID_ARGS; } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.h b/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.h index 63a7612af1e..7e442ddf655 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.h @@ -34,5 +34,5 @@ private: std::string GetUpdateTrigger(const TableInfo &table, const std::string &identity) override; std::string GetDeleteTrigger(const TableInfo &table, const std::string &identity) override; }; -} +} // namespace DistributedDB #endif // SPLICT_DEVICE_LOG_TABLE_MANAGER_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.h index a1e6b5d2947..7726edf3be4 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.h @@ -59,23 +59,6 @@ public: // Roll back the transaction int RollBack(); - -private: - // Put the value to the sqlite database, used by Put &PutBach - int PutInner(const Key &key, const Value &value); - - // Delete the value from the sqlite database, used by Delete &DeleteBach - int DeleteInner(const Key &key); - - // Start the transaction - int StartTransactionInner(bool &isAuto); - - // Commit the transaction - int CommitInner(); - - // Roll back the transaction - int RollBackInner(); }; } // namespace DistributedDB - -#endif // SQLITE_DB_HANDLE_H +#endif // SQLITE_LOCAL_DB_HANDLE_H diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp index b1f04273611..42810d42bbb 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_query_helper.cpp @@ -678,7 +678,6 @@ std::string SqliteQueryHelper::MapKeywordSymbolToSql(const QueryObjNode &queryNo default: return ""; } - return sql; } std::string SqliteQueryHelper::MapValueToSql(const QueryObjNode &queryNode, bool placeholder) const @@ -748,24 +747,6 @@ int SqliteQueryHelper::BindFieldValue(sqlite3_stmt *statement, const QueryObjNod return SQLiteUtils::MapSQLiteErrno(errCode); } -std::string SqliteQueryHelper::MapCastTypeSql(const FieldType &type) const -{ - switch (type) { - case FieldType::LEAF_FIELD_BOOL: - case FieldType::LEAF_FIELD_INTEGER: - case FieldType::LEAF_FIELD_LONG: - return "INT"; - case FieldType::LEAF_FIELD_DOUBLE: - return "REAL"; - case FieldType::LEAF_FIELD_STRING: - return "TEXT"; - case FieldType::LEAF_FIELD_NULL: - return "NULL"; - default: - return ""; - } -} - std::string SqliteQueryHelper::GetFieldShape(const QueryObjNode &queryNode, const std::string &accessStr) { if (isRelationalQuery_) { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp index 871f853adce..1d11a549799 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp @@ -2051,7 +2051,7 @@ END: void SQLiteSingleVerNaturalStore::NotifyRemotePushFinished(const std::string &targetId) const { std::string identifier = DBCommon::VectorToHexString(GetIdentifier()); - LOGI("label:%s sourceTarget: %s{private} push finished", identifier.c_str(), targetId.c_str()); + LOGI("label:%.6s sourceTarget: %s{private} push finished", identifier.c_str(), targetId.c_str()); NotifyRemotePushFinishedInner(targetId); } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h index dd81bc7b0fb..9debf4ef01d 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h @@ -17,15 +17,15 @@ #include #include -#include "sync_able_kvdb.h" -#include "sqlite_single_ver_storage_engine.h" -#include "sqlite_utils.h" #include "isyncer.h" -#include "single_ver_natural_store_commit_notify_data.h" -#include "single_ver_kvdb_sync_interface.h" #include "kv_store_nb_conflict_data_impl.h" #include "runtime_context.h" +#include "single_ver_kvdb_sync_interface.h" +#include "single_ver_natural_store_commit_notify_data.h" #include "sqlite_single_ver_continue_token.h" +#include "sqlite_single_ver_storage_engine.h" +#include "sqlite_utils.h" +#include "sync_able_kvdb.h" namespace DistributedDB { class SQLiteSingleVerNaturalStore : public SyncAbleKvDB, public SingleVerKvDBSyncInterface { @@ -297,5 +297,5 @@ private: PushDataInterceptor dataInterceptor_; std::atomic maxLogSize_; }; -} -#endif +} // namespace DistributedDB +#endif // SQLITE_SINGLE_VER_NATURAL_STORE_H diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp index 25dbf5de583..9d5e0f220a9 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp @@ -62,7 +62,7 @@ SQLiteSingleVerNaturalStoreConnection::~SQLiteSingleVerNaturalStoreConnection() inline bool SQLiteSingleVerNaturalStoreConnection::IsFileAccessControlled() const { return RuntimeContext::GetInstance()->IsAccessControlled() && - kvDB_->GetMyProperties().GetSecLabel() > SecurityLabel::S2; + kvDB_->GetMyProperties().GetSecLabel() > SecurityLabel::S2; } int SQLiteSingleVerNaturalStoreConnection::CheckReadDataControlled() const @@ -406,8 +406,8 @@ int SQLiteSingleVerNaturalStoreConnection::TranslateObserverModeToEventTypes(uns case static_cast(SQLITE_GENERAL_NS_SYNC_EVENT): eventTypes.push_back(SQLITE_GENERAL_NS_SYNC_EVENT); break; - case (static_cast(SQLITE_GENERAL_NS_PUT_EVENT) - | static_cast(SQLITE_GENERAL_NS_SYNC_EVENT)): + case (static_cast(SQLITE_GENERAL_NS_PUT_EVENT) | + static_cast(SQLITE_GENERAL_NS_SYNC_EVENT)): eventTypes.push_back(SQLITE_GENERAL_NS_PUT_EVENT); eventTypes.push_back(SQLITE_GENERAL_NS_SYNC_EVENT); break; @@ -1557,9 +1557,6 @@ int SQLiteSingleVerNaturalStoreConnection::UnpublishToLocal(const Key &key, bool if (deletePublic && (syncRecord.flag & DataItem::DELETE_FLAG) != DataItem::DELETE_FLAG) { errCode = SaveEntry({hashKey, {}}, true); - if (errCode != E_OK) { - goto END; - } } END: diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp index 4aaaf25ce0b..70cf68ecb84 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp @@ -204,8 +204,9 @@ int SQLiteSingleVerSchemaDatabaseUpgrader::UpgradeIndexes(const IndexDifference uint32_t skipSize = newSchema_.GetSkipSize(); SchemaType theType = newSchema_.GetSchemaType(); // The order of index upgrade is not compulsory, we think order "decrease, change, increase" may be better. + LOGD("[SqlSingleSchemaUp][UpIndex] DecreaseIndex: %zu, ChangeIndex: %zu, IncreaseIndex: %zu", + indexDiffer.decrease.size(), indexDiffer.change.size(), indexDiffer.increase.size()); for (const auto &entry : indexDiffer.decrease) { - LOGI("[SqlSingleSchemaUp][UpIndex] DecreaseIndex : indexName=%s.", SchemaUtils::FieldPathString(entry).c_str()); int errCode = SQLiteUtils::DecreaseIndex(db_, entry); if (errCode != E_OK) { LOGE("[SqlSingleSchemaUp][UpIndex] DecreaseIndex fail, errCode=%d.", errCode); @@ -213,9 +214,6 @@ int SQLiteSingleVerSchemaDatabaseUpgrader::UpgradeIndexes(const IndexDifference } } for (const auto &entry : indexDiffer.change) { - LOGI("[SqlSingleSchemaUp][UpIndex] ChangeIndex : SkipSize=%u, indexName=%s, fieldCount=%zu, type=%s.", - skipSize, SchemaUtils::FieldPathString(entry.first).c_str(), entry.second.size(), - SchemaUtils::SchemaTypeString(theType).c_str()); int errCode = SQLiteUtils::ChangeIndex(db_, entry.first, entry.second, theType, skipSize); if (errCode != E_OK) { LOGE("[SqlSingleSchemaUp][UpIndex] ChangeIndex fail, errCode=%d.", errCode); @@ -223,9 +221,6 @@ int SQLiteSingleVerSchemaDatabaseUpgrader::UpgradeIndexes(const IndexDifference } } for (const auto &entry : indexDiffer.increase) { - LOGI("[SqlSingleSchemaUp][UpIndex] IncreaseIndex : SkipSize=%u, indexName=%s, fieldCount=%zu, type=%s.", - skipSize, SchemaUtils::FieldPathString(entry.first).c_str(), entry.second.size(), - SchemaUtils::SchemaTypeString(theType).c_str()); int errCode = SQLiteUtils::IncreaseIndex(db_, entry.first, entry.second, theType, skipSize); if (errCode != E_OK) { LOGE("[SqlSingleSchemaUp][UpIndex] IncreaseIndex fail, errCode=%d.", errCode); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp index a5b63634d2c..157b23c5e6a 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp @@ -17,17 +17,17 @@ #include +#include "db_common.h" +#include "db_constant.h" #include "db_errno.h" +#include "kvdb_manager.h" #include "log_print.h" -#include "db_constant.h" +#include "param_check_utils.h" +#include "platform_specific.h" +#include "runtime_context.h" #include "sqlite_single_ver_database_upgrader.h" #include "sqlite_single_ver_natural_store.h" #include "sqlite_single_ver_schema_database_upgrader.h" -#include "platform_specific.h" -#include "runtime_context.h" -#include "db_common.h" -#include "kvdb_manager.h" -#include "param_check_utils.h" namespace DistributedDB { namespace { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.h index 10abd5db26d..1730cfe86e4 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.h @@ -16,8 +16,8 @@ #ifndef SQLITE_STORAGE_EXECUTOR_H #define SQLITE_STORAGE_EXECUTOR_H -#include "sqlite_import.h" #include "macro_utils.h" +#include "sqlite_import.h" #include "storage_executor.h" namespace DistributedDB { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp index 08c1d8a7714..96905deef4d 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp @@ -1772,7 +1772,7 @@ void SQLiteUtils::JsonExtractByPath(sqlite3_context *ctx, int argc, sqlite3_valu int errCode = SchemaUtils::ParseAndCheckFieldPath(path, outPath); if (errCode != E_OK) { sqlite3_result_error(ctx, "[JsonExtract] Path illegal.", USING_STR_LEN); - LOGE("[JsonExtract] Path=%s illegal.", path); + LOGE("[JsonExtract] Path illegal."); return; } // Parameter Check Done Here -- Gitee From 6e7c8165048d6c365b9ccfaba1463c8ac4b1c255 Mon Sep 17 00:00:00 2001 From: lianhuix Date: Tue, 25 Oct 2022 19:05:36 +0800 Subject: [PATCH 2/5] Fix review issues Signed-off-by: lianhuix --- .../distributeddb/common/src/db_common.cpp | 2 +- .../common/src/evloop/src/event_impl.cpp | 2 +- .../common/src/evloop/src/event_impl.h | 2 +- .../relational/relational_row_data_set.cpp | 2 +- .../common/src/schema_negotiate.cpp | 4 +- .../communicator/src/combine_status.cpp | 2 +- .../interfaces/src/kv_store_delegate_impl.cpp | 32 +++---- .../src/kv_store_nb_conflict_data_impl.cpp | 6 +- .../src/kv_store_nb_delegate_impl.cpp | 92 +++++++++---------- .../src/kv_store_nb_delegate_impl.h | 4 +- .../src/kv_store_result_set_impl.cpp | 10 +- .../interfaces/src/kv_store_result_set_impl.h | 2 +- .../relational_store_changed_data_impl.cpp | 4 +- .../relational/relational_store_instance.h | 2 - .../relational_store_sqlite_ext.cpp | 1 - .../relational/relational_sync_able_storage.h | 6 +- .../storage/src/relational_store_instance.cpp | 9 -- .../src/relational_sync_able_storage.cpp | 7 ++ .../storage/src/sqlite/query_object.cpp | 6 +- .../storage/src/sqlite/query_object.h | 2 +- .../sqlite_single_ver_database_upgrader.h | 1 - ...single_ver_relational_storage_executor.cpp | 4 +- ...e_single_ver_relational_storage_executor.h | 2 - .../sqlite/sqlite_single_ver_result_set.cpp | 22 ++--- .../src/sqlite/sqlite_single_ver_result_set.h | 6 +- .../sqlite_single_ver_storage_engine.cpp | 3 - .../storage/src/sqlite/sqlite_utils.cpp | 2 +- .../syncer/src/subscribe_manager.cpp | 2 +- .../syncer/src/subscribe_manager.h | 2 +- .../distributeddb/syncer/src/sync_engine.cpp | 2 +- ...eddb_single_ver_p2p_subsribe_sync_test.cpp | 4 +- 31 files changed, 114 insertions(+), 133 deletions(-) diff --git a/frameworks/libs/distributeddb/common/src/db_common.cpp b/frameworks/libs/distributeddb/common/src/db_common.cpp index c5eabb245e2..1243b2aca7f 100644 --- a/frameworks/libs/distributeddb/common/src/db_common.cpp +++ b/frameworks/libs/distributeddb/common/src/db_common.cpp @@ -31,7 +31,7 @@ namespace { if (item.fileType != type) { continue; } - int errCode = OS::RemoveFile(item.fileName.c_str()); + int errCode = OS::RemoveFile(item.fileName); if (errCode != E_OK) { LOGE("Remove file failed:%d", errno); } diff --git a/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp b/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp index 4a70a3aeb61..0f29cc09ce6 100644 --- a/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp +++ b/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp @@ -44,7 +44,7 @@ EventImpl::EventImpl(EventTime timeout) }); } -EventImpl::EventImpl(EventFd fd, EventsMask events, EventTime timeout) +EventImpl::EventImpl(const EventFd &fd, EventsMask events, EventTime timeout) : fd_(fd), events_(events), revents_(0), diff --git a/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.h b/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.h index 48964b55851..df9caae0df5 100644 --- a/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.h +++ b/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.h @@ -26,7 +26,7 @@ class EventLoopImpl; class EventImpl : public IEvent { public: explicit EventImpl(EventTime timeout); - EventImpl(EventFd fd, EventsMask events, EventTime timeout); + EventImpl(const EventFd &fd, EventsMask events, EventTime timeout); ~EventImpl() override; int SetAction(const EventAction &action, const EventFinalizer &finalizer) override; diff --git a/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp b/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp index e602066006e..629ed080869 100644 --- a/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp +++ b/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp @@ -141,7 +141,7 @@ void RelationalRowDataSet::SetRowData(std::vector &&data) data_ = data; for (const auto &rowData : data_) { serialLength_ += rowData->CalcLength(); - }; + } } int RelationalRowDataSet::Insert(RelationalRowData *rowData) diff --git a/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp b/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp index e1669b7f748..3167c58e55a 100644 --- a/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp +++ b/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp @@ -231,7 +231,7 @@ int SchemaNegotiate::DeserializeData(Parcel &parcel, RelationalSyncOpinion &opin std::string magicStr; (void)parcel.ReadString(magicStr); if (magicStr != MAGIC) { - LOGE("Deserialize sync opinion failed while read MAGIC string [%s]", magicStr.c_str()); + LOGE("Deserialize sync opinion failed while read MAGIC string"); return -E_INVALID_ARGS; } uint32_t version; @@ -258,7 +258,7 @@ int SchemaNegotiate::DeserializeData(Parcel &parcel, RelationalSyncOpinion &opin (void)parcel.ReadUInt32(requirePeerConvert); tableOpinion.requirePeerConvert = static_cast(requirePeerConvert); (void)parcel.EightByteAlign(); - opinion[tableName] = tableOpinion; + opinion[tableName] = tableOpinion; } return parcel.IsError() ? -E_INVALID_ARGS : E_OK; } diff --git a/frameworks/libs/distributeddb/communicator/src/combine_status.cpp b/frameworks/libs/distributeddb/communicator/src/combine_status.cpp index b3ecf81e66a..8157e0953c3 100644 --- a/frameworks/libs/distributeddb/communicator/src/combine_status.cpp +++ b/frameworks/libs/distributeddb/communicator/src/combine_status.cpp @@ -63,7 +63,7 @@ void CombineStatus::SetFragmentCount(uint16_t inFragCount) bool CombineStatus::IsFragNoAlreadyExist(uint16_t inFragNo) const { - return (combinedFragmentNo_.count(inFragNo) != 0) ? true : false; + return (combinedFragmentNo_.count(inFragNo) != 0); } void CombineStatus::CheckInFragmentNo(uint16_t inFragNo) diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp index d1a0be44495..badcf0c2195 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp @@ -34,7 +34,7 @@ namespace DistributedDB { namespace { - const std::string INVALID_CONNECTION = "[KvStoreDelegate] Invalid connection for operation"; + constexpr const char *INVALID_CONNECTION = "[KvStoreDelegate] Invalid connection for operation"; } KvStoreDelegateImpl::KvStoreDelegateImpl(IKvDBConnection *conn, const std::string &storeId) : conn_(conn), @@ -66,7 +66,7 @@ DBStatus KvStoreDelegateImpl::Put(const Key &key, const Value &value) return TransferDBErrno(errCode); } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -83,7 +83,7 @@ DBStatus KvStoreDelegateImpl::PutBatch(const std::vector &entries) return TransferDBErrno(errCode); } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -100,7 +100,7 @@ DBStatus KvStoreDelegateImpl::Delete(const Key &key) return TransferDBErrno(errCode); } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -117,7 +117,7 @@ DBStatus KvStoreDelegateImpl::DeleteBatch(const std::vector &keys) return TransferDBErrno(errCode); } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -134,7 +134,7 @@ DBStatus KvStoreDelegateImpl::Clear() return TransferDBErrno(errCode); } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -177,7 +177,7 @@ void KvStoreDelegateImpl::GetKvStoreSnapshot(KvStoreObserver *observer, } } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); callback(DB_ERROR, nullptr); } @@ -210,7 +210,7 @@ DBStatus KvStoreDelegateImpl::RegisterObserver(KvStoreObserver *observer) } if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -248,7 +248,7 @@ DBStatus KvStoreDelegateImpl::UnRegisterObserver(const KvStoreObserver *observer } if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -272,7 +272,7 @@ DBStatus KvStoreDelegateImpl::UnRegisterObserver(const KvStoreObserver *observer DBStatus KvStoreDelegateImpl::StartTransaction() { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -287,7 +287,7 @@ DBStatus KvStoreDelegateImpl::StartTransaction() DBStatus KvStoreDelegateImpl::Commit() { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -302,7 +302,7 @@ DBStatus KvStoreDelegateImpl::Commit() DBStatus KvStoreDelegateImpl::Rollback() { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -340,7 +340,7 @@ DBStatus KvStoreDelegateImpl::Rekey(const CipherPassword &password) return TransferDBErrno(errCode); } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -374,7 +374,7 @@ DBStatus KvStoreDelegateImpl::Export(const std::string &filePath, const CipherPa return TransferDBErrno(errCode); } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -404,7 +404,7 @@ DBStatus KvStoreDelegateImpl::Import(const std::string &filePath, const CipherPa return TransferDBErrno(errCode); } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -431,7 +431,7 @@ DBStatus KvStoreDelegateImpl::Close() DBStatus KvStoreDelegateImpl::Pragma(PragmaCmd cmd, PragmaData ¶mData) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } int errCode; diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp index 36e8b0bdca2..ceb254a552c 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp @@ -49,18 +49,16 @@ bool KvStoreNbConflictDataImpl::IsDeleted(ValueType type) const { if (type == ValueType::OLD_VALUE) { return data_.oldData.isDeleted; - } else { - return data_.newData.isDeleted; } + return data_.newData.isDeleted; } bool KvStoreNbConflictDataImpl::IsNative(ValueType type) const { if (type == ValueType::OLD_VALUE) { return data_.oldData.isLocal; - } else { - return data_.newData.isLocal; } + return data_.newData.isLocal; } void KvStoreNbConflictDataImpl::SetConflictData(const KvDBConflictEntry &conflictData) diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp index 4d0cb7cccdb..488ace66522 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp @@ -18,22 +18,22 @@ #include #include -#include "platform_specific.h" -#include "log_print.h" #include "db_constant.h" #include "db_errno.h" #include "db_types.h" -#include "param_check_utils.h" -#include "store_types.h" -#include "kvdb_pragma.h" -#include "kvdb_manager.h" -#include "kv_store_errno.h" -#include "kv_store_observer.h" #include "kv_store_changed_data_impl.h" +#include "kv_store_errno.h" #include "kv_store_nb_conflict_data_impl.h" +#include "kv_store_observer.h" #include "kv_store_result_set_impl.h" -#include "sync_operation.h" +#include "kvdb_manager.h" +#include "kvdb_pragma.h" +#include "log_print.h" +#include "param_check_utils.h" #include "performance_analysis.h" +#include "platform_specific.h" +#include "store_types.h" +#include "sync_operation.h" namespace DistributedDB { namespace { @@ -61,7 +61,7 @@ namespace { {EXEC_CHECKPOINT, PRAGMA_EXEC_CHECKPOINT}, }; - const std::string INVALID_CONNECTION = "[KvStoreNbDelegate] Invalid connection for operation"; + constexpr const char *INVALID_CONNECTION = "[KvStoreNbDelegate] Invalid connection for operation"; } KvStoreNbDelegateImpl::KvStoreNbDelegateImpl(IKvDBConnection *conn, const std::string &storeId) @@ -97,7 +97,7 @@ DBStatus KvStoreNbDelegateImpl::GetEntries(const Key &keyPrefix, std::vector &entries) return TransferDBErrno(errCode); } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } DBStatus KvStoreNbDelegateImpl::DeleteBatch(const std::vector &keys) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -307,7 +307,7 @@ DBStatus KvStoreNbDelegateImpl::PublishLocal(const Key &key, bool deleteLocal, b return OK; } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -328,14 +328,14 @@ DBStatus KvStoreNbDelegateImpl::UnpublishToLocal(const Key &key, bool deletePubl return OK; } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } DBStatus KvStoreNbDelegateImpl::PutLocalBatch(const std::vector &entries) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -353,7 +353,7 @@ DBStatus KvStoreNbDelegateImpl::PutLocalBatch(const std::vector &entries) DBStatus KvStoreNbDelegateImpl::DeleteLocalBatch(const std::vector &keys) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -390,7 +390,7 @@ DBStatus KvStoreNbDelegateImpl::RegisterObserver(const Key &key, unsigned int mo } if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -424,7 +424,7 @@ DBStatus KvStoreNbDelegateImpl::UnRegisterObserver(const KvStoreObserver *observ } if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -448,7 +448,7 @@ DBStatus KvStoreNbDelegateImpl::UnRegisterObserver(const KvStoreObserver *observ DBStatus KvStoreNbDelegateImpl::RemoveDeviceData(const std::string &device) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } if (device.empty() || device.length() > DBConstant::MAX_DEV_LENGTH) { @@ -473,7 +473,7 @@ DBStatus KvStoreNbDelegateImpl::Sync(const std::vector &devices, Sy bool wait = false) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -492,7 +492,7 @@ DBStatus KvStoreNbDelegateImpl::Sync(const std::vector &devices, Sy const Query &query, bool wait) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -514,7 +514,7 @@ DBStatus KvStoreNbDelegateImpl::Sync(const std::vector &devices, Sy DBStatus KvStoreNbDelegateImpl::Pragma(PragmaCmd cmd, PragmaData ¶mData) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -536,12 +536,12 @@ DBStatus KvStoreNbDelegateImpl::Pragma(PragmaCmd cmd, PragmaData ¶mData) DBStatus KvStoreNbDelegateImpl::SetConflictNotifier(int conflictType, const KvStoreNbConflictNotifier ¬ifier) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } if (!ParamCheckUtils::CheckConflictNotifierType(conflictType)) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return INVALID_ARGS; } @@ -583,7 +583,7 @@ END: DBStatus KvStoreNbDelegateImpl::Rekey(const CipherPassword &password) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -599,7 +599,7 @@ DBStatus KvStoreNbDelegateImpl::Rekey(const CipherPassword &password) DBStatus KvStoreNbDelegateImpl::Export(const std::string &filePath, const CipherPassword &passwd, bool force) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -632,7 +632,7 @@ DBStatus KvStoreNbDelegateImpl::Export(const std::string &filePath, const Cipher DBStatus KvStoreNbDelegateImpl::Import(const std::string &filePath, const CipherPassword &passwd) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -664,7 +664,7 @@ DBStatus KvStoreNbDelegateImpl::Import(const std::string &filePath, const Cipher DBStatus KvStoreNbDelegateImpl::StartTransaction() { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -679,7 +679,7 @@ DBStatus KvStoreNbDelegateImpl::StartTransaction() DBStatus KvStoreNbDelegateImpl::Commit() { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -694,7 +694,7 @@ DBStatus KvStoreNbDelegateImpl::Commit() DBStatus KvStoreNbDelegateImpl::Rollback() { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -729,7 +729,7 @@ DBStatus KvStoreNbDelegateImpl::Close() DBStatus KvStoreNbDelegateImpl::CheckIntegrity() const { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -739,7 +739,7 @@ DBStatus KvStoreNbDelegateImpl::CheckIntegrity() const DBStatus KvStoreNbDelegateImpl::GetSecurityOption(SecurityOption &option) const { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } return TransferDBErrno(conn_->GetSecurityOption(option.securityLabel, option.securityFlag)); @@ -748,7 +748,7 @@ DBStatus KvStoreNbDelegateImpl::GetSecurityOption(SecurityOption &option) const DBStatus KvStoreNbDelegateImpl::SetRemotePushFinishedNotify(const RemotePushFinishedNotifier ¬ifier) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -763,7 +763,7 @@ DBStatus KvStoreNbDelegateImpl::SetRemotePushFinishedNotify(const RemotePushFini DBStatus KvStoreNbDelegateImpl::GetInner(const IOption &option, const Key &key, Value &value) const { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -779,7 +779,7 @@ DBStatus KvStoreNbDelegateImpl::GetEntriesInner(const IOption &option, const Key &keyPrefix, std::vector &entries) const { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -794,7 +794,7 @@ DBStatus KvStoreNbDelegateImpl::GetEntriesInner(const IOption &option, DBStatus KvStoreNbDelegateImpl::PutInner(const IOption &option, const Key &key, const Value &value) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -818,7 +818,7 @@ DBStatus KvStoreNbDelegateImpl::PutInner(const IOption &option, const Key &key, DBStatus KvStoreNbDelegateImpl::DeleteInner(const IOption &option, const Key &key) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -853,7 +853,7 @@ DBStatus KvStoreNbDelegateImpl::SetEqualIdentifier(const std::string &identifier const std::vector &targets) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -869,7 +869,7 @@ DBStatus KvStoreNbDelegateImpl::SetEqualIdentifier(const std::string &identifier DBStatus KvStoreNbDelegateImpl::SetPushDataInterceptor(const PushDataInterceptor &interceptor) { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -886,7 +886,7 @@ DBStatus KvStoreNbDelegateImpl::SubscribeRemoteQuery(const std::vector #include #include #include +#include -#include "store_types.h" #include "db_types.h" +#include "store_types.h" #include "ikvdb_connection.h" #include "kv_store_nb_conflict_data.h" #include "kv_store_nb_delegate.h" diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp index 11c3e61929c..0e4d1141487 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.cpp @@ -18,7 +18,7 @@ #include "db_errno.h" namespace DistributedDB { -const int KvStoreResultSetImpl::INIT_POSTION = -1; +const int KvStoreResultSetImpl::INIT_POSITION = -1; KvStoreResultSetImpl::KvStoreResultSetImpl(IKvDBResultSet *resultSet) : resultSet_(resultSet) @@ -36,7 +36,7 @@ int KvStoreResultSetImpl::GetCount() const int KvStoreResultSetImpl::GetPosition() const { if (resultSet_ == nullptr) { - return INIT_POSTION; + return INIT_POSITION; } return resultSet_->GetPosition(); } @@ -48,8 +48,8 @@ bool KvStoreResultSetImpl::Move(int offset) if (aimPos > INT_MAX) { return MoveToPosition(INT_MAX); } - if (aimPos < INIT_POSTION) { - return MoveToPosition(INIT_POSTION); + if (aimPos < INIT_POSITION) { + return MoveToPosition(INIT_POSITION); } return MoveToPosition(aimPos); } @@ -128,7 +128,7 @@ bool KvStoreResultSetImpl::IsBeforeFirst() const if (GetCount() == 0) { return true; } - if (position <= INIT_POSTION) { + if (position <= INIT_POSITION) { return true; } return false; diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.h b/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.h index 6092dcb64fc..45082535d68 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.h +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_result_set_impl.h @@ -110,7 +110,7 @@ public: DBStatus GetRow(std::map &data) const override; private: - static const int INIT_POSTION; + static const int INIT_POSITION; IKvDBResultSet * const resultSet_; }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp index 4afb818b656..45638fa122d 100644 --- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp @@ -16,9 +16,7 @@ #include "relational_store_changed_data_impl.h" namespace DistributedDB { -RelationalStoreChangedDataImpl::~RelationalStoreChangedDataImpl() -{ -} +RelationalStoreChangedDataImpl::~RelationalStoreChangedDataImpl() = default; DB_API std::string RelationalStoreChangedDataImpl::GetDataChangeDevice() const { diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_instance.h b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_instance.h index c2be0738cf0..ac94a227a23 100644 --- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_instance.h +++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_instance.h @@ -33,8 +33,6 @@ public: static int ReleaseDataBaseConnection(RelationalStoreConnection *connection); - int CheckDatabaseFileStatus(const std::string &id); - // public for test mock static IRelationalStore *GetDataBase(const RelationalDBProperties &properties, int &errCode); 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 96f44a8f9a6..4646d97e121 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 @@ -84,7 +84,6 @@ private: SHA256_CTX *context_ = nullptr; }; - const uint64_t MULTIPLES_BETWEEN_SECONDS_AND_MICROSECONDS = 1000000; using Timestamp = uint64_t; diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h b/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h index 82968e5e3c4..0ef33e4f664 100644 --- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h +++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h @@ -19,7 +19,6 @@ #include "lru_map.h" #include "relational_db_sync_interface.h" #include "relationaldb_properties.h" -#include "runtime_context.h" #include "sqlite_single_relational_storage_engine.h" #include "sqlite_single_ver_relational_continue_token.h" @@ -100,10 +99,7 @@ public: int LocalDataChanged(int notifyEvent, std::vector &queryObj) override; int InterceptData(std::vector &entries, const std::string &sourceID, - const std::string &targetID) const override - { - return E_OK; - } + const std::string &targetID) const override; int CheckAndInitQueryCondition(QueryObject &query) const override; void RegisterObserverAction(const RelationalObserverAction &action); diff --git a/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp b/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp index 363b308908d..cb1fc43a3b9 100644 --- a/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp +++ b/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp @@ -63,15 +63,6 @@ int RelationalStoreInstance::ReleaseDataBaseConnection(RelationalStoreConnection return errCode; } -int RelationalStoreInstance::CheckDatabaseFileStatus(const std::string &id) -{ - std::lock_guard lockGuard(storeLock_); - if (dbs_.count(id) != 0 && dbs_[id] != nullptr) { - return -E_BUSY; - } - return E_OK; -} - static IRelationalStore *GetFromCache(const RelationalDBProperties &properties, int &errCode) { errCode = E_OK; diff --git a/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp b/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp index c9b5f3eb184..493e03ef658 100644 --- a/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp +++ b/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp @@ -391,6 +391,7 @@ int RelationalSyncAbleStorage::GetSyncDataNext(std::vector & } const auto fieldInfos = storageEngine_->GetSchemaRef().GetTable(token->GetQuery().GetTableName()).GetFieldInfos(); std::vector fieldNames; + fieldNames.resize(fieldInfos.size()); for (const auto &fieldInfo : fieldInfos) { fieldNames.push_back(fieldInfo.GetFieldName()); } @@ -559,6 +560,12 @@ int RelationalSyncAbleStorage::LocalDataChanged(int notifyEvent, std::vector &entries, const std::string &sourceID, + const std::string &targetID) const +{ + return E_OK; +} + int RelationalSyncAbleStorage::CreateDistributedDeviceTable(const std::string &device, const RelationalSyncStrategy &syncStrategy) { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp index cef020b87cc..1ba83e69afc 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp @@ -38,7 +38,7 @@ QueryObject::QueryObject() { } -void QueryObject::GetAttrFromQueryObjNodes() +void QueryObject::SetAttrWithQueryObjNodes() { for (const auto &iter : queryObjNodes_) { SymbolType symbolType = SqliteQueryHelper::GetSymbolType(iter.operFlag); @@ -70,7 +70,7 @@ QueryObject::QueryObject(const Query &query) { QueryExpression queryExpressions = GetQueryInfo::GetQueryExpression(query); queryObjNodes_ = queryExpressions.GetQueryExpression(); - GetAttrFromQueryObjNodes(); + SetAttrWithQueryObjNodes(); isValid_ = queryExpressions.GetErrFlag(); prefixKey_ = queryExpressions.GetPreFixKey(); suggestIndex_ = queryExpressions.GetSuggestIndex(); @@ -95,7 +95,7 @@ QueryObject::QueryObject(const std::list &queryObjNodes, const std hasInKeys_(false), orderByCounts_(0) { - GetAttrFromQueryObjNodes(); + SetAttrWithQueryObjNodes(); } QueryObject::~QueryObject() diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h index b62b2211361..dc6209fe8e6 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h @@ -106,7 +106,7 @@ private: int CheckLimitFormat(const std::list::iterator &iter) const; int CheckLinkerBefore(const std::list::iterator &iter) const; void ClearNodesFlag(); - void GetAttrFromQueryObjNodes(); + void SetAttrWithQueryObjNodes(); int CheckInKeys() const; SchemaObject schema_; // used to check and parse schema filed diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.h index 3d5190e4458..65a5c859a52 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.h @@ -29,7 +29,6 @@ public: // used for transferring db file to new dir while classifycation feature in SOFTWARE_VERSION_RELEASE_3_0 static int TransferDatabasePath(const std::string &parentDir, const OpenDbProperties &option); - static int CreateDbDir(); void SetMetaUpgrade(const SecurityOption ¤tOpt, const SecurityOption &expectOpt, const std::string &subDir); void SetSubdir(const std::string &subDir); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp index eb53ab43888..5639f3b9f16 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp @@ -322,7 +322,7 @@ std::map GetChangedIndexes(const TableInfo &oldTab return indexes; } -int Upgradeindexes(sqlite3 *db, const std::vector &tables, +int UpgradeIndexes(sqlite3 *db, const std::vector &tables, const std::map &indexes) { if (db == nullptr) { @@ -385,7 +385,7 @@ int SQLiteSingleVerRelationalStorageExecutor::AlterAuxTableForUpgrade(const Tabl return errCode; } - errCode = Upgradeindexes(dbHandle_, deviceTables, upgradeIndexces); + errCode = UpgradeIndexes(dbHandle_, deviceTables, upgradeIndexces); if (errCode != E_OK) { LOGE("upgrade indexes failed. %d", errCode); } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h index 03e22e9ce82..647b1c02f04 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h @@ -60,8 +60,6 @@ public: int SaveSyncItems(const QueryObject &object, std::vector &dataItems, const std::string &deviceName, const TableInfo &table, bool useTrans = true); - int AnalysisRelationalSchema(const std::string &tableName, TableInfo &tableInfo); - int CheckDBModeForRelational(); int DeleteDistributedDeviceTable(const std::string &device, const std::string &tableName); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp index 6f77bb141c0..e00d62cf2aa 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.cpp @@ -39,12 +39,12 @@ SQLiteSingleVerResultSet::~SQLiteSingleVerResultSet() { isOpen_ = false; count_ = 0; - position_ = INIT_POSTION; + position_ = INIT_POSITION; kvDB_ = nullptr; window_ = nullptr; rawCursor_ = nullptr; handle_ = nullptr; - cacheStartPosition_ = INIT_POSTION; + cacheStartPosition_ = INIT_POSITION; } // The user get KvStoreResultSet after Open function called, so no need mutex during open procedure @@ -121,7 +121,7 @@ int SQLiteSingleVerResultSet::OpenForCacheEntryIdMode() cachedRowIds_.clear(); return errCode; } - // If no result, then nothing is cached, so the cacheStartPosition_ is still INIT_POSTION + // If no result, then nothing is cached, so the cacheStartPosition_ is still INIT_POSITION if (count_ != 0) { cacheStartPosition_ = 0; } @@ -150,12 +150,12 @@ int SQLiteSingleVerResultSet::MoveTo(int position) const return -E_RESULT_SET_STATUS_INVALID; } if (count_ == 0) { - position_ = (position >= 0) ? 0 : INIT_POSTION; + position_ = (position >= 0) ? 0 : INIT_POSITION; LOGW("[SqlSinResSet][MoveTo] Empty ResultSet."); return -E_RESULT_SET_EMPTY; } if (position < 0) { - position_ = INIT_POSTION; + position_ = INIT_POSITION; LOGW("[SqlSinResSet][MoveTo] Target Position=%d invalid.", position); return -E_INVALID_ARGS; } @@ -180,7 +180,7 @@ int SQLiteSingleVerResultSet::MoveToForCacheFullEntryMode(int position) const position_ = position; return E_OK; } - position_ = INIT_POSTION; + position_ = INIT_POSITION; LOGE("[SqlSinResSet][MoveForEntry] Move to position=%d fail.", position); return -E_UNEXPECTED_DATA; } @@ -223,8 +223,8 @@ int SQLiteSingleVerResultSet::MoveToForCacheEntryIdMode(int position) const LOGE("[SqlSinResSet][MoveForRowid] Move to position=%d, Reload fail, errCode=%d.", position, errCode); // What else shall we do if error happened ? cachedRowIds_.clear(); - cacheStartPosition_ = INIT_POSTION; - position_ = INIT_POSTION; // Reset Position As MoveForEntry Do + cacheStartPosition_ = INIT_POSITION; + position_ = INIT_POSITION; // Reset Position As MoveForEntry Do return -E_UNEXPECTED_DATA; } LOGD("[SqlSinResSet][MoveForRowid] Reload: position=%d, cacheStartPos=%d, cached=%zu, count=%d.", @@ -241,7 +241,7 @@ int SQLiteSingleVerResultSet::GetEntry(Entry &entry) const if (!isOpen_ || count_ == 0) { return -E_NO_SUCH_ENTRY; } - if (position_ > INIT_POSTION && position_ < count_) { + if (position_ > INIT_POSITION && position_ < count_) { // If position_ in the valid range, it can be guaranteed that everything is ok without errors if (option_.cacheMode == ResultSetCacheMode::CACHE_FULL_ENTRY) { return window_->GetEntry(entry); @@ -278,7 +278,7 @@ void SQLiteSingleVerResultSet::Close() } isOpen_ = false; count_ = 0; - position_ = INIT_POSTION; + position_ = INIT_POSITION; LOGD("[SqlSinResSet][Close] Done, Type=%d, Mode=%d.", static_cast(type_), static_cast(option_.cacheMode)); } @@ -295,7 +295,7 @@ void SQLiteSingleVerResultSet::CloseForCacheFullEntryMode() void SQLiteSingleVerResultSet::CloseForCacheEntryIdMode() { - cacheStartPosition_ = INIT_POSTION; + cacheStartPosition_ = INIT_POSITION; cachedRowIds_.clear(); // In Fact : handle_ and kvDB_ is guaranteed to be not nullptr if (handle_ != nullptr) { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.h index d4c538304c5..a249e801b56 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_result_set.h @@ -24,7 +24,7 @@ #include "query_object.h" namespace DistributedDB { -constexpr int INIT_POSTION = -1; +constexpr int INIT_POSITION = -1; constexpr int DEFAULT_RESULT_SET_CACHE_MAX_SIZE = 1; // Unit MB, default 1 MB constexpr int RESULT_SET_CACHE_MAX_SIZE_MIN = 1; constexpr int RESULT_SET_CACHE_MAX_SIZE_MAX = 16; @@ -84,7 +84,7 @@ private: // Common Part Of Two ResultSet Mode. bool isOpen_ = false; int count_ = 0; - mutable int position_ = INIT_POSTION; // The position in the overall result + mutable int position_ = INIT_POSITION; // The position in the overall result mutable std::mutex mutex_; // For KeyPrefix Type Or Query Type. @@ -101,7 +101,7 @@ private: // Cache EntryId Mode Using StorageExecutor, Own It, Responsible To Release It. SQLiteSingleVerStorageExecutor *handle_ = nullptr; mutable std::vector cachedRowIds_; - mutable int cacheStartPosition_ = INIT_POSTION; // The offset of the first cached rowid in all result rowids + mutable int cacheStartPosition_ = INIT_POSITION; // The offset of the first cached rowid in all result rowids }; } // namespace DistributedDB diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp index 157b23c5e6a..35e6c08c1f1 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp @@ -1034,7 +1034,6 @@ void SQLiteSingleVerStorageEngine::CommitAndReleaseNotifyData(SingleVerNaturalSt } commitNotifyFunc_(eventType, static_cast(committedData)); committedData = nullptr; - return; } void SQLiteSingleVerStorageEngine::InitConflictNotifiedFlag(SingleVerNaturalStoreCommitNotifyData *&committedData) const @@ -1080,7 +1079,6 @@ void SQLiteSingleVerStorageEngine::SetMaxTimestamp(Timestamp maxTimestamp) const auto kvStore = static_cast(kvdb); kvStore->SetMaxTimestamp(maxTimestamp); RefObject::DecObjRef(kvdb); - return; } void SQLiteSingleVerStorageEngine::CommitNotifyForMigrateCache(NotifyMigrateSyncData &syncData) const @@ -1129,7 +1127,6 @@ void SQLiteSingleVerStorageEngine::CommitNotifyForMigrateCache(NotifyMigrateSync if (committedData != nullptr) { CommitAndReleaseNotifyData(committedData, SQLITE_GENERAL_NS_SYNC_EVENT); } - return; } // Cache subscribe when engine state is CACHE mode, and its will be applied at the beginning of migrate. diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp index 96905deef4d..447339760e7 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp @@ -815,7 +815,7 @@ int SetFieldInfo(sqlite3_stmt *statement, TableInfo &table) field.SetDefaultValue(tmpString); } - int keyIndex = sqlite3_column_int64(statement, 5); // 5 means primary key index + int keyIndex = sqlite3_column_int(statement, 5); // 5 means primary key index if (keyIndex != 0) { // not 0 means is a primary key table.SetPrimaryKey(field.GetFieldName(), keyIndex); } diff --git a/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp b/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp index f0facc99739..172887be6f0 100644 --- a/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp +++ b/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp @@ -96,7 +96,7 @@ void SubscribeManager::DeleteRemoteSubscribeQuery(const std::string &device, con DeleteSubscribeQuery(device, queryId, remoteSubscribedMap_, remoteSubscribedTotalMap_); } -void SubscribeManager::PutLocalUnFiniedSubQueries(const std::string &device, +void SubscribeManager::PutLocalUnFinishedSubQueries(const std::string &device, std::vector &subscribeQueries) { LOGI("[SubscribeManager] put local unfinished subscribe queries, nums=%zu", subscribeQueries.size()); diff --git a/frameworks/libs/distributeddb/syncer/src/subscribe_manager.h b/frameworks/libs/distributeddb/syncer/src/subscribe_manager.h index 42ca070c54b..88af8fa026a 100644 --- a/frameworks/libs/distributeddb/syncer/src/subscribe_manager.h +++ b/frameworks/libs/distributeddb/syncer/src/subscribe_manager.h @@ -63,7 +63,7 @@ public: void DeleteRemoteSubscribeQuery(const std::string &device, const QuerySyncObject &query); // put subscribe queries into unfinished map when remote db online - void PutLocalUnFiniedSubQueries(const std::string &device, std::vector &subscribeQueries); + void PutLocalUnFinishedSubQueries(const std::string &device, std::vector &subscribeQueries); // get all device unFinished subscribe queries which triggered by auto subscribe and need retry subscribe void GetAllUnFinishSubQueries(std::map> &allSyncQueries) const; diff --git a/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp b/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp index 221dcbca9c5..25ce3bf2869 100644 --- a/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp +++ b/frameworks/libs/distributeddb/syncer/src/sync_engine.cpp @@ -837,7 +837,7 @@ void SyncEngine::GetRemoteSubscribeQueries(const std::string &device, std::vecto void SyncEngine::PutUnfiniedSubQueries(const std::string &device, std::vector &subscribeQueries) { - subManager_->PutLocalUnFiniedSubQueries(device, subscribeQueries); + subManager_->PutLocalUnFinishedSubQueries(device, subscribeQueries); } void SyncEngine::GetAllUnFinishSubQueries(std::map> &allSyncQueries) diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subsribe_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subsribe_sync_test.cpp index a7ce0829ad3..761da484a29 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subsribe_sync_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_p2p_subsribe_sync_test.cpp @@ -596,11 +596,11 @@ HWTEST_F(DistributedDBSingleVerP2PSubscribeSyncTest, subscribeManager005, TestSi LOGI("============step 2============"); subManager.GetLocalSubscribeQueries(DEVICE_A, subscribeQueries); ASSERT_TRUE(subscribeQueries.size() == 4); - subManager.PutLocalUnFiniedSubQueries(DEVICE_A, subscribeQueries); + subManager.PutLocalUnFinishedSubQueries(DEVICE_A, subscribeQueries); subscribeQueries.clear(); subManager.GetLocalSubscribeQueries(DEVICE_B, subscribeQueries); ASSERT_TRUE(subscribeQueries.size() == 2); - subManager.PutLocalUnFiniedSubQueries(DEVICE_B, subscribeQueries); + subManager.PutLocalUnFinishedSubQueries(DEVICE_B, subscribeQueries); subscribeQueries.clear(); /** * @tc.steps: step3. get all device unFinished subscribe queries and check -- Gitee From a5b62c08a5679730ff0d20d6be9894bef4e0ceb6 Mon Sep 17 00:00:00 2001 From: lianhuix Date: Fri, 28 Oct 2022 17:54:47 +0800 Subject: [PATCH 3/5] Fix review issues Signed-off-by: lianhuix --- .../src/kv_store_delegate_manager.cpp | 2 +- .../relational/relational_sync_able_storage.h | 5 ---- .../storage/include/ikvdb_sync_interface.h | 1 - .../storage/include/kvdb_properties.h | 3 -- .../include/relational_db_sync_interface.h | 5 ---- .../include/relational_store_connection.h | 1 - .../storage/include/relationaldb_properties.h | 3 -- .../include/single_ver_kvdb_sync_interface.h | 2 -- .../storage/src/kvdb_properties.cpp | 5 ---- .../src/relational_sync_able_storage.cpp | 14 ++-------- .../storage/src/relationaldb_properties.cpp | 5 ---- .../storage/src/sqlite/query_object.cpp | 26 +++++++++++++++++ .../storage/src/sqlite/query_object.h | 26 ++++------------- .../storage/src/sqlite/query_sync_object.cpp | 9 ++++-- .../storage/src/sqlite/query_sync_object.h | 2 ++ .../sqlite_relational_store_connection.cpp | 5 ---- .../sqlite_relational_store_connection.h | 1 - ...qlite_single_relational_storage_engine.cpp | 15 +++++++++- .../sqlite_single_relational_storage_engine.h | 2 ++ .../sqlite_single_ver_natural_store.cpp | 12 ++++---- .../storage/src/sqlite/sqlite_utils.cpp | 28 ++----------------- .../storage/src/sqlite/sqlite_utils.h | 1 - .../syncer/src/single_ver_data_sync.cpp | 4 +-- .../syncer/src/single_ver_data_sync.h | 2 +- ...rtual_relational_ver_sync_db_interface.cpp | 28 ------------------- ...virtual_relational_ver_sync_db_interface.h | 4 --- 26 files changed, 69 insertions(+), 142 deletions(-) diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp index ebf55f74b13..311c51c5598 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp @@ -536,7 +536,7 @@ DBStatus KvStoreDelegateManager::EnableKvStoreAutoLaunch(const std::string &user return DB_ERROR; } AutoLaunchParam param{ userId, appId, storeId, option, notifier, {}}; - std::shared_ptr ptr = std::make_shared(); + std::shared_ptr ptr; int errCode = AutoLaunch::GetAutoLaunchProperties(param, DBType::DB_KV, true, ptr); if (errCode != E_OK) { LOGE("[KvStoreManager] Enable auto launch failed:%d", errCode); diff --git a/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h b/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h index 0ef33e4f664..96f81b436a8 100644 --- a/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h +++ b/frameworks/libs/distributeddb/interfaces/src/relational/relational_sync_able_storage.h @@ -89,11 +89,6 @@ public: // Get the timestamp when database created or imported int GetDatabaseCreateTimestamp(Timestamp &outTime) const override; - // Get batch meta data associated with the given key. - int GetBatchMetaData(const std::vector &keys, std::vector &entries) const override; - // Put batch meta data as a key-value entry vector - int PutBatchMetaData(std::vector &entries) override; - std::vector GetTablesQuery() override; int LocalDataChanged(int notifyEvent, std::vector &queryObj) override; diff --git a/frameworks/libs/distributeddb/storage/include/ikvdb_sync_interface.h b/frameworks/libs/distributeddb/storage/include/ikvdb_sync_interface.h index 572add415c3..b44226dc959 100644 --- a/frameworks/libs/distributeddb/storage/include/ikvdb_sync_interface.h +++ b/frameworks/libs/distributeddb/storage/include/ikvdb_sync_interface.h @@ -25,7 +25,6 @@ namespace DistributedDB { class IKvDBSyncInterface : public SyncGenericInterface { public: - // Constructor/Destructor. IKvDBSyncInterface() = default; ~IKvDBSyncInterface() override = default; diff --git a/frameworks/libs/distributeddb/storage/include/kvdb_properties.h b/frameworks/libs/distributeddb/storage/include/kvdb_properties.h index c985b0d8321..6b668a791ee 100644 --- a/frameworks/libs/distributeddb/storage/include/kvdb_properties.h +++ b/frameworks/libs/distributeddb/storage/include/kvdb_properties.h @@ -38,9 +38,6 @@ public: // Set the password void SetPassword(CipherType type, const CipherPassword &password); - // is schema exist - bool IsSchemaExist() const; - // set schema void SetSchema(const SchemaObject &schema); diff --git a/frameworks/libs/distributeddb/storage/include/relational_db_sync_interface.h b/frameworks/libs/distributeddb/storage/include/relational_db_sync_interface.h index 5cf833aa110..01ef9a64f09 100644 --- a/frameworks/libs/distributeddb/storage/include/relational_db_sync_interface.h +++ b/frameworks/libs/distributeddb/storage/include/relational_db_sync_interface.h @@ -33,11 +33,6 @@ public: virtual RelationalSchemaObject GetSchemaInfo() const = 0; - // Get batch meta data associated with the given key. - virtual int GetBatchMetaData(const std::vector &keys, std::vector &entries) const = 0; - // Put batch meta data as a key-value entry vector - virtual int PutBatchMetaData(std::vector &entries) = 0; - virtual std::vector GetTablesQuery() = 0; virtual int LocalDataChanged(int notifyEvent, std::vector &queryObj) = 0; diff --git a/frameworks/libs/distributeddb/storage/include/relational_store_connection.h b/frameworks/libs/distributeddb/storage/include/relational_store_connection.h index 5f1b230a116..04d4a7ad7db 100644 --- a/frameworks/libs/distributeddb/storage/include/relational_store_connection.h +++ b/frameworks/libs/distributeddb/storage/include/relational_store_connection.h @@ -48,7 +48,6 @@ public: // Close and release the connection. virtual int Close() = 0; - virtual int TriggerAutoSync() = 0; virtual int SyncToDevice(SyncInfo &info) = 0; virtual std::string GetIdentifier() = 0; virtual int CreateDistributedTable(const std::string &tableName) = 0; diff --git a/frameworks/libs/distributeddb/storage/include/relationaldb_properties.h b/frameworks/libs/distributeddb/storage/include/relationaldb_properties.h index d29f1a16a9e..a9dc4660d28 100644 --- a/frameworks/libs/distributeddb/storage/include/relationaldb_properties.h +++ b/frameworks/libs/distributeddb/storage/include/relationaldb_properties.h @@ -28,9 +28,6 @@ public: RelationalDBProperties(); ~RelationalDBProperties() override; - // is schema exist - bool IsSchemaExist() const; - // set schema void SetSchema(const RelationalSchemaObject &schema); diff --git a/frameworks/libs/distributeddb/storage/include/single_ver_kvdb_sync_interface.h b/frameworks/libs/distributeddb/storage/include/single_ver_kvdb_sync_interface.h index dc9cdf29894..17da22c3edf 100644 --- a/frameworks/libs/distributeddb/storage/include/single_ver_kvdb_sync_interface.h +++ b/frameworks/libs/distributeddb/storage/include/single_ver_kvdb_sync_interface.h @@ -24,8 +24,6 @@ namespace DistributedDB { using MulDevTimeRanges = std::map>; -using MulDevSinVerKvEntry = std::map>; -using MulDevDataItems = std::map>; class SingleVerKvDBSyncInterface : public IKvDBSyncInterface { public: diff --git a/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp b/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp index c10569d8213..72885909301 100644 --- a/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp +++ b/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp @@ -63,11 +63,6 @@ void KvDBProperties::SetPassword(CipherType type, const CipherPassword &password password_ = password; } -bool KvDBProperties::IsSchemaExist() const -{ - return schema_.IsSchemaValid(); -} - void KvDBProperties::SetSchema(const SchemaObject &schema) { schema_ = schema; diff --git a/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp b/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp index 493e03ef658..324cfef58e7 100644 --- a/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp +++ b/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp @@ -195,6 +195,7 @@ int RelationalSyncAbleStorage::PutMetaData(const Key &key, const Value &value) // Delete multiple meta data records in a transaction. int RelationalSyncAbleStorage::DeleteMetaData(const std::vector &keys) { + CHECK_STORAGE_ENGINE; for (const auto &key : keys) { if (key.empty() || key.size() > DBConstant::MAX_KEY_SIZE) { return -E_INVALID_ARGS; @@ -222,6 +223,7 @@ int RelationalSyncAbleStorage::DeleteMetaData(const std::vector &keys) // Delete multiple meta data records with key prefix in a transaction. int RelationalSyncAbleStorage::DeleteMetaDataByPrefixKey(const Key &keyPrefix) const { + CHECK_STORAGE_ENGINE; if (keyPrefix.empty() || keyPrefix.size() > DBConstant::MAX_KEY_SIZE) { return -E_INVALID_ARGS; } @@ -537,18 +539,6 @@ int RelationalSyncAbleStorage::GetDatabaseCreateTimestamp(Timestamp &outTime) co return OS::GetCurrentSysTimeInMicrosecond(outTime); } -// Get batch meta data associated with the given key. -int RelationalSyncAbleStorage::GetBatchMetaData(const std::vector &keys, std::vector &entries) const -{ - return -E_NOT_SUPPORT; -} - -// Put batch meta data as a key-value entry vector -int RelationalSyncAbleStorage::PutBatchMetaData(std::vector &entries) -{ - return -E_NOT_SUPPORT; -} - std::vector RelationalSyncAbleStorage::GetTablesQuery() { return {}; diff --git a/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp b/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp index 6dc2ea91a21..ee0333bd53a 100644 --- a/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp +++ b/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp @@ -29,11 +29,6 @@ RelationalDBProperties::RelationalDBProperties() RelationalDBProperties::~RelationalDBProperties() {} -bool RelationalDBProperties::IsSchemaExist() const -{ - return schema_.IsSchemaValid(); -} - void RelationalDBProperties::SetSchema(const RelationalSchemaObject &schema) { schema_ = schema; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp index 1ba83e69afc..17b09c16307 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.cpp @@ -452,5 +452,31 @@ int QueryObject::SetSchema(const RelationalSchemaObject &schemaObj) return E_OK; } #endif + +void QueryObject::SetTableName(const std::string &tableName) +{ + tableName_ = tableName; + isTableNameSpecified_ = true; +} + +const std::string &QueryObject::GetTableName() const +{ + return tableName_; +} + +bool QueryObject::HasInKeys() const +{ + return hasInKeys_; +} + +void QueryObject::SetSortType(SortType sortType) +{ + sortType_ = sortType; +} + +SortType QueryObject::GetSortType() const +{ + return sortType_; +} } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h index dc6209fe8e6..ec0c648304f 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_object.h @@ -47,16 +47,9 @@ public: bool IsQueryOnlyByKey() const; bool IsQueryForRelationalDB() const; - void SetTableName(const std::string &tableName) - { - tableName_ = tableName; - isTableNameSpecified_ = true; - } + void SetTableName(const std::string &tableName); - const std::string &GetTableName() const - { - return tableName_; - } + const std::string &GetTableName() const; bool HasOrderBy() const; @@ -64,20 +57,11 @@ public: bool Empty() const; - bool HasInKeys() const - { - return hasInKeys_; - } + bool HasInKeys() const; - void SetSortType(SortType sortType) - { - sortType_ = sortType; - } + void SetSortType(SortType sortType); - SortType GetSortType() const - { - return sortType_; - } + SortType GetSortType() const; #ifdef RELATIONAL_STORE int SetSchema(const RelationalSchemaObject &schemaObj); // The interface can only be used in relational query. 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 50b4b9d0ca8..7e009ade5db 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp @@ -15,9 +15,9 @@ #include "query_sync_object.h" +#include "db_common.h" #include "db_errno.h" #include "log_print.h" -#include "db_common.h" #include "version.h" namespace DistributedDB { @@ -124,6 +124,9 @@ std::string QuerySyncObject::GetIdentify() const if (!isValid_) { return std::string(); } + if (!identify_.empty()) { + return identify_; + } // suggestionIndex is local attribute, do not need to be propagated to remote uint64_t len = Parcel::GetVectorCharLen(prefixKey_); for (const QueryObjNode &node : queryObjNodes_) { @@ -175,8 +178,8 @@ std::string QuerySyncObject::GetIdentify() const if (parcel.IsError() || DBCommon::CalcValueHash(buff, hashBuff) != E_OK) { return std::string(); } - - return DBCommon::VectorToHexString(hashBuff); + identify_ = DBCommon::VectorToHexString(hashBuff); + return identify_; } uint32_t QuerySyncObject::CalculateParcelLen(uint32_t softWareVersion) const 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 7d8ca7630c1..dae2ef40fe8 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h @@ -55,6 +55,8 @@ private: uint32_t CalculateLen() const; int GetObjContext(ObjContext &objContext) const; uint32_t GetVersion() const; + + mutable std::string identify_; }; } #endif \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp index ba36b9a465a..991132b8916 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp @@ -180,11 +180,6 @@ int SQLiteRelationalStoreConnection::Pragma(int cmd, void *parameter) // reserve return E_OK; } -int SQLiteRelationalStoreConnection::TriggerAutoSync() -{ - return E_OK; -} - int SQLiteRelationalStoreConnection::SyncToDevice(SyncInfo &info) { auto *store = GetDB(); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.h b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.h index ec798d2857b..3c51d21de0b 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.h @@ -34,7 +34,6 @@ public: // Close and release the connection. int Close() override; - int TriggerAutoSync() override; int SyncToDevice(SyncInfo &info) override; std::string GetIdentifier() override; int CreateDistributedTable(const std::string &tableName) override; 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 d02485d5319..ac163cb83be 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 @@ -40,7 +40,7 @@ StorageExecutor *SQLiteSingleRelationalStorageEngine::NewSQLiteStorageExecutor(s int SQLiteSingleRelationalStorageEngine::Upgrade(sqlite3 *db) { - int errCode = SQLiteUtils::CreateRelationalMetaTable(db); + int errCode = CreateRelationalMetaTable(db); if (errCode != E_OK) { LOGE("Create relational store meta table failed. err=%d", errCode); return errCode; @@ -290,5 +290,18 @@ void SQLiteSingleRelationalStorageEngine::SetProperties(const RelationalDBProper { properties_ = properties; } + +int SQLiteSingleRelationalStorageEngine::CreateRelationalMetaTable(sqlite3 *db) +{ + std::string sql = + "CREATE TABLE IF NOT EXISTS " + DBConstant::RELATIONAL_PREFIX + "metadata(" \ + "key BLOB PRIMARY KEY NOT NULL," \ + "value BLOB);"; + int errCode = SQLiteUtils::ExecuteRawSQL(db, sql); + if (errCode != E_OK) { + LOGE("[SQLite] execute create table sql failed, err=%d", errCode); + } + return errCode; +} } #endif \ No newline at end of file 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 3b3370c6867..54ea19c1c2c 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 @@ -57,6 +57,8 @@ private: int CreateDistributedTable(const std::string &tableName, bool isUpgraded, const std::string &identity, bool &schemaChanged, RelationalSchemaObject &tmpSchema); + int CreateRelationalMetaTable(sqlite3 *db); + RelationalSchemaObject schema_; mutable std::mutex schemaMutex_; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp index 1d11a549799..01359209663 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp @@ -182,17 +182,15 @@ SQLiteSingleVerNaturalStore::~SQLiteSingleVerNaturalStore() std::string SQLiteSingleVerNaturalStore::GetDatabasePath(const KvDBProperties &kvDBProp) { - std::string filePath = GetSubDirPath(kvDBProp) + "/" + - DBConstant::MAINDB_DIR + "/" + DBConstant::SINGLE_VER_DATA_STORE + DBConstant::SQLITE_DB_EXTENSION; - return filePath; + return GetSubDirPath(kvDBProp) + "/" + DBConstant::MAINDB_DIR + "/" + DBConstant::SINGLE_VER_DATA_STORE + + DBConstant::SQLITE_DB_EXTENSION; } std::string SQLiteSingleVerNaturalStore::GetSubDirPath(const KvDBProperties &kvDBProp) { std::string dataDir = kvDBProp.GetStringProp(KvDBProperties::DATA_DIR, ""); std::string identifierDir = kvDBProp.GetStringProp(KvDBProperties::IDENTIFIER_DIR, ""); - std::string dirPath = dataDir + "/" + identifierDir + "/" + DBConstant::SINGLE_SUB_DIR; - return dirPath; + return dataDir + "/" + identifierDir + "/" + DBConstant::SINGLE_SUB_DIR; } int SQLiteSingleVerNaturalStore::SetUserVer(const KvDBProperties &kvDBProp, int version) @@ -298,8 +296,8 @@ inline bool AmendValueShouldBeUse(int errCode) inline bool IsValueMismatched(int errCode) { return (errCode == -E_VALUE_MISMATCH_FEILD_COUNT || - errCode == -E_VALUE_MISMATCH_FEILD_TYPE || - errCode == -E_VALUE_MISMATCH_CONSTRAINT); + errCode == -E_VALUE_MISMATCH_FEILD_TYPE || + errCode == -E_VALUE_MISMATCH_CONSTRAINT); } } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp index 447339760e7..37c94a69860 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp @@ -1273,12 +1273,8 @@ int SQLiteUtils::IncreaseIndex(sqlite3 *db, const IndexName &name, const IndexIn LOGE("[IncreaseIndex] Sqlite DB not exists."); return -E_INVALID_DB; } - if (name.empty()) { - LOGE("[IncreaseIndex] Name can not be empty."); - return -E_NOT_PERMIT; - } - if (info.empty()) { - LOGE("[IncreaseIndex] Info can not be empty."); + if (name.empty() || info.empty()) { + LOGE("[IncreaseIndex] Name or info can not be empty."); return -E_NOT_PERMIT; } std::string indexName = SchemaUtils::FieldPathString(name); @@ -1392,19 +1388,6 @@ int SQLiteUtils::RegisterGetSysTime(sqlite3 *db) return SQLiteUtils::RegisterFunction(db, "get_sys_time", 1, nullptr, func); } -int SQLiteUtils::CreateRelationalMetaTable(sqlite3 *db) -{ - std::string sql = - "CREATE TABLE IF NOT EXISTS " + DBConstant::RELATIONAL_PREFIX + "metadata(" \ - "key BLOB PRIMARY KEY NOT NULL," \ - "value BLOB);"; - int errCode = SQLiteUtils::ExecuteRawSQL(db, sql); - if (errCode != E_OK) { - LOGE("[SQLite] execute create table sql failed, err=%d", errCode); - } - return errCode; -} - int SQLiteUtils::CreateSameStuTable(sqlite3 *db, const TableInfo &baseTbl, const std::string &newTableName) { std::string sql = "CREATE TABLE IF NOT EXISTS " + newTableName + "("; @@ -2089,7 +2072,6 @@ int SQLiteUtils::SetCipherSettings(sqlite3 *db, CipherType type, uint32_t iterTi errCode = SQLiteUtils::ExecuteRawSQL(db, KDF_ITER_CONFIG_SQL + std::to_string(iterTimes)); if (errCode != E_OK) { LOGE("[SQLiteUtils][SetCipherSettings] config iter failed:%d", errCode); - return errCode; } return errCode; } @@ -2153,11 +2135,7 @@ int SQLiteUtils::CheckTableEmpty(sqlite3 *db, const std::string &tableName, bool errCode = SQLiteUtils::StepWithRetry(stmt, false); if (errCode == SQLiteUtils::MapSQLiteErrno(SQLITE_ROW)) { - if (sqlite3_column_type(stmt, 0) == SQLITE_NULL) { - isEmpty = true; - } else { - isEmpty = false; - } + isEmpty = (sqlite3_column_type(stmt, 0) == SQLITE_NULL); errCode = E_OK; } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.h index 3b59e575fed..c759bc78fcf 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.h @@ -168,7 +168,6 @@ public: static int RegisterGetSysTime(sqlite3 *db); static int CreateRelationalLogTable(sqlite3 *db, const std::string &oriTableName); - static int CreateRelationalMetaTable(sqlite3 *db); static int AddRelationalLogTableTrigger(sqlite3 *db, const std::string &identity, const TableInfo &table); static int AnalysisSchema(sqlite3 *db, const std::string &tableName, TableInfo &table); diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp index 291518d1f41..d3a430cb83b 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.cpp @@ -248,7 +248,7 @@ int SingleVerDataSync::Send(SingleVerSyncTaskContext *context, const Message *me return errCode; } -int SingleVerDataSync::GetData(SingleVerSyncTaskContext *context, std::vector &outData, size_t packetSize) +int SingleVerDataSync::GetData(SingleVerSyncTaskContext *context, size_t packetSize, std::vector &outData) { int errCode; UpdateMtuSize(); @@ -290,7 +290,7 @@ int SingleVerDataSync::GetDataWithPerformanceRecord(SingleVerSyncTaskContext *co performance->StepTimeRecordStart(PT_TEST_RECORDS::RECORD_READ_DATA); } context->StartFeedDogForGetData(context->GetResponseSessionId()); - int errCode = GetData(context, syncOutData.entries, packetSize); + int errCode = GetData(context, packetSize, syncOutData.entries); context->StopFeedDogForGetData(); if (performance != nullptr) { performance->StepTimeRecordEnd(PT_TEST_RECORDS::RECORD_READ_DATA); diff --git a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.h b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.h index 4e9343aece3..3d6aba3766d 100644 --- a/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.h +++ b/frameworks/libs/distributeddb/syncer/src/single_ver_data_sync.h @@ -146,7 +146,7 @@ protected: SyncTimeRange GetSyncDataTimeRange(SyncType syncType, SingleVerSyncTaskContext *context, const std::vector &inData, UpdateWaterMark &isUpdate); - int GetData(SingleVerSyncTaskContext *context, std::vector &outData, size_t packetSize); + int GetData(SingleVerSyncTaskContext *context, size_t packetSize, std::vector &outData); int GetDataWithPerformanceRecord(SingleVerSyncTaskContext *context, SyncEntry &syncOutData); diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.cpp index afda4562fed..04e44c4bcd8 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.cpp @@ -166,34 +166,6 @@ int VirtualRelationalVerSyncDBInterface::GetDatabaseCreateTimestamp(Timestamp &o return E_OK; } -int VirtualRelationalVerSyncDBInterface::GetBatchMetaData(const std::vector &keys, - std::vector &entries) const -{ - int errCode = E_OK; - for (const auto &key : keys) { - Entry entry; - entry.key = key; - errCode = GetMetaData(key, entry.value); - if (errCode != E_OK) { - return errCode; - } - entries.push_back(entry); - } - return errCode; -} - -int VirtualRelationalVerSyncDBInterface::PutBatchMetaData(std::vector &entries) -{ - int errCode = E_OK; - for (const auto &entry : entries) { - errCode = PutMetaData(entry.key, entry.value); - if (errCode != E_OK) { - return errCode; - } - } - return errCode; -} - std::vector VirtualRelationalVerSyncDBInterface::GetTablesQuery() { return {}; diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.h b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.h index e42cba6be4f..e44f57b4eb3 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.h +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/virtual_relational_ver_sync_db_interface.h @@ -50,10 +50,6 @@ public: int GetDatabaseCreateTimestamp(Timestamp &outTime) const override; - int GetBatchMetaData(const std::vector &keys, std::vector &entries) const override; - - int PutBatchMetaData(std::vector &entries) override; - std::vector GetTablesQuery() override; int LocalDataChanged(int notifyEvent, std::vector &queryObj) override; -- Gitee From 99a22c14a0dad4fbc871e1303dd8051f71ce12ce Mon Sep 17 00:00:00 2001 From: lianhuix Date: Fri, 28 Oct 2022 21:47:07 +0800 Subject: [PATCH 4/5] Fix review issues Signed-off-by: lianhuix --- frameworks/libs/distributeddb/include/query.h | 4 ++-- frameworks/libs/distributeddb/include/query_expression.h | 4 ++-- .../libs/distributeddb/interfaces/include/kv_store_errno.h | 4 ++-- .../storage/src/generic_single_ver_kv_entry.cpp | 2 +- frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp | 7 ++----- .../storage/src/operation/single_ver_database_oper.cpp | 2 +- .../src/sqlite/relational/sqlite_relational_store.cpp | 3 +-- .../storage/src/sqlite/sqlite_single_ver_natural_store.cpp | 7 +++---- .../storage/src/sqlite/sqlite_single_ver_natural_store.h | 2 +- .../sqlite/sqlite_single_ver_storage_executor_cache.cpp | 3 +-- .../distributeddb/storage/src/storage_engine_manager.cpp | 4 ---- 11 files changed, 16 insertions(+), 26 deletions(-) diff --git a/frameworks/libs/distributeddb/include/query.h b/frameworks/libs/distributeddb/include/query.h index e5e409ebfb4..657e93df3ee 100644 --- a/frameworks/libs/distributeddb/include/query.h +++ b/frameworks/libs/distributeddb/include/query.h @@ -16,10 +16,10 @@ #ifndef DISTRIBUTEDDB_QUERY_H #define DISTRIBUTEDDB_QUERY_H -#include -#include #include #include +#include +#include #include "query_expression.h" #include "types_export.h" diff --git a/frameworks/libs/distributeddb/include/query_expression.h b/frameworks/libs/distributeddb/include/query_expression.h index 968d4de0136..fa4ccdaa27d 100644 --- a/frameworks/libs/distributeddb/include/query_expression.h +++ b/frameworks/libs/distributeddb/include/query_expression.h @@ -192,5 +192,5 @@ public: return QueryValueType::VALUE_TYPE_STRING; } }; -} -#endif \ No newline at end of file +} // DistributedDB +#endif // DISTRIBUTEDDB_QUERY_EXPRESSION_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/interfaces/include/kv_store_errno.h b/frameworks/libs/distributeddb/interfaces/include/kv_store_errno.h index 4cb150f59a0..ba0835389b8 100644 --- a/frameworks/libs/distributeddb/interfaces/include/kv_store_errno.h +++ b/frameworks/libs/distributeddb/interfaces/include/kv_store_errno.h @@ -21,5 +21,5 @@ namespace DistributedDB { // Transfer the db error code to the DBStatus. DBStatus TransferDBErrno(int err); -}; -#endif \ No newline at end of file +} // DistributedDB +#endif // KV_STORE_ERRNO_H \ No newline at end of file diff --git a/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp b/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp index 48ec008934e..d1f6f10f633 100644 --- a/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp +++ b/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp @@ -124,7 +124,7 @@ int GenericSingleVerKvEntry::SerializeData(Parcel &parcel, uint32_t targetVersio int GenericSingleVerKvEntry::SerializeDatas(const std::vector &kvEntries, Parcel &parcel, uint32_t targetVersion) { - uint32_t size = kvEntries.size(); + uint32_t size = static_cast(kvEntries.size()); int errCode = parcel.WriteUInt32(size); if (errCode != E_OK) { LOGE("[SerializeDatas] write entries size failed, errCode=%d.", errCode); diff --git a/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp b/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp index 4c7c46867f0..d7c62dfbe4b 100644 --- a/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp +++ b/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp @@ -655,7 +655,7 @@ IKvDB *KvDBManager::SaveKvDBToCache(IKvDB *kvDB) // Save to IKvDB to the global map void KvDBManager::RemoveKvDBFromCache(const IKvDB *kvDB) { - KvDBProperties properties = kvDB->GetMyProperties(); + const KvDBProperties &properties = kvDB->GetMyProperties(); std::string identifier = GenerateKvDBIdentifier(properties); int databaseType = properties.GetIntProp(KvDBProperties::DATABASE_TYPE, KvDBProperties::LOCAL_TYPE); std::lock_guard lockGuard(kvDBLock_); @@ -836,10 +836,7 @@ bool KvDBManager::CompareSchemaObject(const SchemaObject &newSchema, const Schem return false; } int errCode = oldSchema.CompareAgainstSchemaObject(newSchema); - if (errCode == -E_SCHEMA_EQUAL_EXACTLY) { - return true; - } - return false; + return (errCode == -E_SCHEMA_EQUAL_EXACTLY); } int KvDBManager::CheckSchema(const IKvDB *kvDB, const KvDBProperties &properties) diff --git a/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp b/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp index 6863a736ce6..c47b082c6dd 100644 --- a/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp +++ b/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp @@ -165,7 +165,7 @@ int SingleVerDatabaseOper::RekeyPostHandle(const CipherPassword &passwd) singleVerNaturalStore_->GetDbPropertyForUpdate().GetPassword(cipherType, oldPasswd); singleVerNaturalStore_->GetDbPropertyForUpdate().SetPassword(cipherType, passwd); singleVerNaturalStore_->GetDbPropertyForUpdate().SetBoolProp( - KvDBProperties::ENCRYPTED_MODE, (passwd.GetSize() == 0) ? false : true); + KvDBProperties::ENCRYPTED_MODE, (passwd.GetSize() != 0)); return InitStorageEngine(); } 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 5ce33573053..f14bd218af6 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 @@ -216,8 +216,7 @@ int SQLiteRelationalStore::SaveTableModeToMeta(DistributedTableMode mode) int SQLiteRelationalStore::SaveLogTableVersionToMeta() { - LOGD("save log table version to meta table, key: %s, val: %s", DBConstant::LOG_TABLE_VERSION_KEY.c_str(), - DBConstant::LOG_TABLE_VERSION_CURRENT.c_str()); + LOGD("save log table version to meta table, version: %s", DBConstant::LOG_TABLE_VERSION_CURRENT.c_str()); const Key logVersionKey(DBConstant::LOG_TABLE_VERSION_KEY.begin(), DBConstant::LOG_TABLE_VERSION_KEY.end()); Value logVersionVal(DBConstant::LOG_TABLE_VERSION_CURRENT.begin(), DBConstant::LOG_TABLE_VERSION_CURRENT.end()); int errCode = storageEngine_->PutMetaData(logVersionKey, logVersionVal); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp index 01359209663..95dd5c67b2d 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp @@ -923,13 +923,12 @@ void SQLiteSingleVerNaturalStore::GetMaxTimestamp(Timestamp &stamp) const stamp = currentMaxTimestamp_; } -int SQLiteSingleVerNaturalStore::SetMaxTimestamp(Timestamp timestamp) +void SQLiteSingleVerNaturalStore::SetMaxTimestamp(Timestamp timestamp) { std::lock_guard lock(maxTimestampMutex_); if (timestamp > currentMaxTimestamp_) { currentMaxTimestamp_ = timestamp; } - return E_OK; } // In sync procedure, call this function @@ -1256,7 +1255,7 @@ int SQLiteSingleVerNaturalStore::SaveSyncDataToMain(const QueryObject &query, st int errCode = SaveSyncItems(query, dataItems, deviceInfo, maxTimestamp, committedData); if (errCode == E_OK) { isNeedCommit = true; - (void)SetMaxTimestamp(maxTimestamp); + SetMaxTimestamp(maxTimestamp); } CommitAndReleaseNotifyData(committedData, isNeedCommit, SQLITE_GENERAL_NS_SYNC_EVENT); @@ -1333,7 +1332,7 @@ int SQLiteSingleVerNaturalStore::SaveSyncDataToCacheDB(const QueryObject &query, if (errCode != E_OK) { LOGE("[SingleVerNStore] Failed to save sync data in cache mode, err : %d", errCode); } else { - (void)SetMaxTimestamp(maxTimestamp); + SetMaxTimestamp(maxTimestamp); } DBDfxAdapter::FinishTraceSQL(); ReleaseHandle(handle); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h index 9debf4ef01d..2f2fcead31b 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h @@ -95,7 +95,7 @@ public: void GetMaxTimestamp(Timestamp &stamp) const override; - int SetMaxTimestamp(Timestamp timestamp); + void SetMaxTimestamp(Timestamp timestamp); int Rekey(const CipherPassword &passwd) override; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp index 0e766e47675..609f0ceda5e 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp @@ -140,7 +140,7 @@ int SQLiteSingleVerStorageExecutor::GetMinVersionCacheData( int errCode = SQLiteUtils::GetStatement(dbHandle_, sql, statement); if (errCode != E_OK) { LOGE("GetStatement fail when get min version cache data! errCode = [%d]", errCode); - goto END; + return CheckCorruptedStatus(errCode); } errCode = GetAllDataItems(statement, dataItems, minVerIncurCacheDb, true); @@ -148,7 +148,6 @@ int SQLiteSingleVerStorageExecutor::GetMinVersionCacheData( LOGE("Failed to get all the data items by the min version:[%d]", errCode); } -END: SQLiteUtils::ResetStatement(statement, true, errCode); return CheckCorruptedStatus(errCode); } diff --git a/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp b/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp index 8657a4e9a67..1d8b15bd5db 100644 --- a/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp +++ b/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp @@ -263,10 +263,7 @@ void StorageEngineManager::ReleaseResources(const std::string &identifier) if (storageEngine != nullptr) { LOGI("[StorageEngineManager] Release storage engine"); delete storageEngine; - storageEngine = nullptr; } - - return; } int StorageEngineManager::ReleaseEngine(StorageEngine *releaseEngine) @@ -293,7 +290,6 @@ int StorageEngineManager::ReleaseEngine(StorageEngine *releaseEngine) } delete releaseEngine; - releaseEngine = nullptr; return E_OK; } -- Gitee From 51bd764ef32f74b3cf66c83bf413fce17149e628 Mon Sep 17 00:00:00 2001 From: lianhuix Date: Sat, 29 Oct 2022 15:59:52 +0800 Subject: [PATCH 5/5] Fix review issues Signed-off-by: lianhuix --- .../common/include/macro_utils.h | 2 +- .../distributeddb/common/src/db_common.cpp | 2 -- .../common/src/param_check_utils.cpp | 5 +---- .../relational/relational_row_data_set.cpp | 2 +- .../include/iprocess_system_api_adapter.h | 3 ++- .../interfaces/include/kv_store_delegate.h | 4 ++-- .../interfaces/include/kv_store_nb_delegate.h | 12 ++++++------ .../relational/relational_store_manager.h | 3 ++- .../interfaces/src/intercepted_data_impl.cpp | 2 +- .../interfaces/src/kv_store_delegate_impl.cpp | 13 ++++++------- .../src/kv_store_nb_delegate_impl.cpp | 4 ++-- .../src/kv_store_snapshot_delegate_impl.cpp | 2 +- .../storage/src/generic_kvdb.cpp | 8 ++++---- .../storage/src/kvdb_manager.cpp | 3 +-- .../src/relational_sync_able_storage.cpp | 2 +- .../storage/src/sqlite/query_sync_object.h | 2 +- .../storage/src/sqlite/sqlite_local_kvdb.h | 2 +- ...te_single_ver_natural_store_connection.cpp | 9 ++++----- ...e_single_ver_relational_storage_executor.h | 6 +++--- .../sqlite_single_ver_storage_engine.cpp | 2 +- ..._single_ver_storage_executor_subscribe.cpp | 4 ++-- .../src/sqlite/sqlite_storage_engine.cpp | 5 ----- .../src/sqlite/sqlite_storage_engine.h | 2 -- .../storage/src/sqlite/sqlite_utils.cpp | 19 ------------------- .../storage/src/sqlite/sqlite_utils.h | 2 -- 25 files changed, 43 insertions(+), 77 deletions(-) diff --git a/frameworks/libs/distributeddb/common/include/macro_utils.h b/frameworks/libs/distributeddb/common/include/macro_utils.h index ec2ccd61cb4..bc73f17f5e8 100644 --- a/frameworks/libs/distributeddb/common/include/macro_utils.h +++ b/frameworks/libs/distributeddb/common/include/macro_utils.h @@ -35,7 +35,7 @@ namespace DistributedDB { #define BYTE_8_ALIGN(x) (((x) + (8 - 1)) & ~(8 - 1)) -#define BITX(x) (1 << (x)) +#define BITX(x) (1U << (x)) #define ULL(x) (static_cast(x)) diff --git a/frameworks/libs/distributeddb/common/src/db_common.cpp b/frameworks/libs/distributeddb/common/src/db_common.cpp index 1243b2aca7f..384e9aca5ef 100644 --- a/frameworks/libs/distributeddb/common/src/db_common.cpp +++ b/frameworks/libs/distributeddb/common/src/db_common.cpp @@ -247,11 +247,9 @@ int DBCommon::CopyFile(const std::string &srcFile, const std::string &dstFile) END: if (fileIn != nullptr) { (void)fclose(fileIn); - fileIn = nullptr; } if (fileOut != nullptr) { (void)fclose(fileOut); - fileOut = nullptr; } return errCode; } diff --git a/frameworks/libs/distributeddb/common/src/param_check_utils.cpp b/frameworks/libs/distributeddb/common/src/param_check_utils.cpp index 2a1fe4d232a..b2847e694cd 100644 --- a/frameworks/libs/distributeddb/common/src/param_check_utils.cpp +++ b/frameworks/libs/distributeddb/common/src/param_check_utils.cpp @@ -28,12 +28,9 @@ bool ParamCheckUtils::CheckDataDir(const std::string &dataDir, std::string &cano return false; } - if (OS::GetRealPath(dataDir, canonicalDir) != E_OK) { - return false; - } // After normalizing the path, determine whether the path is a legal path considered by the program. // There has been guaranteed by the upper layer, So there is no need trustlist set here. - return true; + return (OS::GetRealPath(dataDir, canonicalDir) == E_OK); } bool ParamCheckUtils::IsStoreIdSafe(const std::string &storeId) diff --git a/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp b/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp index 629ed080869..ef949515a61 100644 --- a/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp +++ b/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp @@ -77,7 +77,7 @@ int RelationalRowDataSet::Serialize(Parcel &parcel) const (void)parcel.WriteUInt32(data_.size()); for (const auto &rowData : data_) { rowData->Serialize(parcel); - }; + } (void)parcel.EightByteAlign(); if (parcel.IsError()) { diff --git a/frameworks/libs/distributeddb/interfaces/include/iprocess_system_api_adapter.h b/frameworks/libs/distributeddb/interfaces/include/iprocess_system_api_adapter.h index 3a3b14de6dc..6aecd7e6c76 100644 --- a/frameworks/libs/distributeddb/interfaces/include/iprocess_system_api_adapter.h +++ b/frameworks/libs/distributeddb/interfaces/include/iprocess_system_api_adapter.h @@ -16,8 +16,9 @@ #ifndef IPROCESS_SYSTEM_API_ADAPTER_H #define IPROCESS_SYSTEM_API_ADAPTER_H -#include #include +#include + #include "store_types.h" namespace DistributedDB { diff --git a/frameworks/libs/distributeddb/interfaces/include/kv_store_delegate.h b/frameworks/libs/distributeddb/interfaces/include/kv_store_delegate.h index 5194ac455d4..cd5f820905f 100644 --- a/frameworks/libs/distributeddb/interfaces/include/kv_store_delegate.h +++ b/frameworks/libs/distributeddb/interfaces/include/kv_store_delegate.h @@ -16,12 +16,12 @@ #ifndef KV_STORE_DELEGATE_H #define KV_STORE_DELEGATE_H -#include #include +#include -#include "store_types.h" #include "kv_store_observer.h" #include "kv_store_snapshot_delegate.h" +#include "store_types.h" namespace DistributedDB { class KvStoreDelegate { diff --git a/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h b/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h index b9218a75ad2..4a27d2eb5c7 100644 --- a/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h +++ b/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h @@ -16,17 +16,17 @@ #ifndef KV_STORE_NB_DELEGATE_H #define KV_STORE_NB_DELEGATE_H -#include -#include #include +#include +#include -#include "store_types.h" -#include "kv_store_observer.h" +#include "intercepted_data.h" +#include "iprocess_system_api_adapter.h" #include "kv_store_nb_conflict_data.h" +#include "kv_store_observer.h" #include "kv_store_result_set.h" #include "query.h" -#include "iprocess_system_api_adapter.h" -#include "intercepted_data.h" +#include "store_types.h" namespace DistributedDB { using KvStoreNbPublishOnConflict = std::function; diff --git a/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_manager.h b/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_manager.h index 160b0da71fb..66276e8d2c7 100644 --- a/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_manager.h +++ b/frameworks/libs/distributeddb/interfaces/include/relational/relational_store_manager.h @@ -14,9 +14,10 @@ */ #ifndef RELATIONAL_STORE_MANAGER_H #define RELATIONAL_STORE_MANAGER_H -#include + #include #include +#include #include "auto_launch_export.h" #include "relational_store_delegate.h" diff --git a/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp index 97042fd5bf9..9dafce35271 100644 --- a/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/intercepted_data_impl.cpp @@ -76,7 +76,7 @@ InterceptedDataImpl::InterceptedDataImpl(std::vector dataIte // New packet cannot exceed both twice the MTU and twice the original size. // Besides, it cannot exceed 30 MB. maxPacketSize_ = std::min(DBConstant::MAX_SYNC_BLOCK_SIZE, - std::max(totalLength_, static_cast(DBConstant::MAX_MTU_SIZE)) * 2); + std::max(totalLength_, static_cast(DBConstant::MAX_MTU_SIZE)) * 2); } InterceptedDataImpl::~InterceptedDataImpl() diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp index badcf0c2195..41c087c90e0 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp @@ -19,18 +19,17 @@ #include #include -#include "platform_specific.h" -#include "log_print.h" -#include "param_check_utils.h" -#include "db_constant.h" #include "db_errno.h" #include "db_types.h" +#include "kv_store_changed_data_impl.h" #include "kv_store_errno.h" -#include "kvdb_pragma.h" #include "kv_store_observer.h" -#include "kvdb_manager.h" #include "kv_store_snapshot_delegate_impl.h" -#include "kv_store_changed_data_impl.h" +#include "kvdb_manager.h" +#include "kvdb_pragma.h" +#include "log_print.h" +#include "param_check_utils.h" +#include "platform_specific.h" namespace DistributedDB { namespace { diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp index 488ace66522..12a9f6956c7 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp @@ -932,7 +932,7 @@ DBStatus KvStoreNbDelegateImpl::UnSubscribeRemoteQuery(const std::vector &keys) const { if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } IOption option; diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp index 17ce4a8f9f1..6fbe5e3f240 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp @@ -16,8 +16,8 @@ #ifndef OMIT_MULTI_VER #include "kv_store_snapshot_delegate_impl.h" -#include "kv_store_errno.h" #include "db_errno.h" +#include "kv_store_errno.h" #include "log_print.h" namespace DistributedDB { diff --git a/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp b/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp index c1e681e5675..2ba26ab57aa 100644 --- a/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp +++ b/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp @@ -14,15 +14,15 @@ */ #include "generic_kvdb.h" -#include "platform_specific.h" -#include "log_print.h" + #include "db_common.h" #include "db_constant.h" #include "db_errno.h" +#include "kvdb_commit_notify_filterable_data.h" +#include "kvdb_utils.h" +#include "log_print.h" #include "package_file.h" #include "runtime_context.h" -#include "kvdb_utils.h" -#include "kvdb_commit_notify_filterable_data.h" namespace DistributedDB { DEFINE_OBJECT_TAG_FACILITIES(GenericKvDB); diff --git a/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp b/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp index d7c62dfbe4b..4d1b45ff0ca 100644 --- a/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp +++ b/frameworks/libs/distributeddb/storage/src/kvdb_manager.cpp @@ -835,8 +835,7 @@ bool KvDBManager::CompareSchemaObject(const SchemaObject &newSchema, const Schem if (!newSchema.IsSchemaValid() || !oldSchema.IsSchemaValid()) { return false; } - int errCode = oldSchema.CompareAgainstSchemaObject(newSchema); - return (errCode == -E_SCHEMA_EQUAL_EXACTLY); + return (oldSchema.CompareAgainstSchemaObject(newSchema) == -E_SCHEMA_EQUAL_EXACTLY); } int KvDBManager::CheckSchema(const IKvDB *kvDB, const KvDBProperties &properties) diff --git a/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp b/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp index 324cfef58e7..81c15feb8d4 100644 --- a/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp +++ b/frameworks/libs/distributeddb/storage/src/relational_sync_able_storage.cpp @@ -393,7 +393,7 @@ int RelationalSyncAbleStorage::GetSyncDataNext(std::vector & } const auto fieldInfos = storageEngine_->GetSchemaRef().GetTable(token->GetQuery().GetTableName()).GetFieldInfos(); std::vector fieldNames; - fieldNames.resize(fieldInfos.size()); + fieldNames.reserve(fieldInfos.size()); for (const auto &fieldInfo : fieldInfos) { fieldNames.push_back(fieldInfo.GetFieldName()); } 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 dae2ef40fe8..d6193c9e25e 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.h @@ -18,8 +18,8 @@ #include -#include "query_object.h" #include "parcel.h" +#include "query_object.h" namespace DistributedDB { const uint32_t QUERY_SYNC_OBJECT_VERSION_0 = 0; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.h index 631497a23c4..05db1314142 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.h @@ -16,8 +16,8 @@ #ifndef SQLITE_LOCAL_KV_DB_H #define SQLITE_LOCAL_KV_DB_H -#include #include +#include #include "local_kvdb.h" #include "sqlite_local_storage_executor.h" diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp index 9d5e0f220a9..c03b347ace6 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp @@ -15,17 +15,16 @@ #include "sqlite_single_ver_natural_store_connection.h" +#include "db_common.h" #include "db_constant.h" #include "db_dfx_adapter.h" #include "db_errno.h" -#include "log_print.h" +#include "kvdb_observer_handle.h" #include "kvdb_pragma.h" +#include "log_print.h" #include "sqlite_single_ver_natural_store.h" -#include "kvdb_observer_handle.h" -#include "store_types.h" -#include "db_common.h" #include "sqlite_single_ver_result_set.h" -#include "sqlite_single_ver_forward_cursor.h" +#include "store_types.h" namespace DistributedDB { namespace { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h index 647b1c02f04..88c55535ac0 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.h @@ -19,11 +19,11 @@ #include "data_transformer.h" #include "db_types.h" #include "macro_utils.h" -#include "sqlite_utils.h" -#include "sqlite_storage_executor.h" +#include "query_object.h" #include "relational_row_data.h" #include "relational_store_delegate.h" -#include "query_object.h" +#include "sqlite_storage_executor.h" +#include "sqlite_utils.h" namespace DistributedDB { class SQLiteSingleVerRelationalStorageExecutor : public SQLiteStorageExecutor { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp index 35e6c08c1f1..146b929819d 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_engine.cpp @@ -171,7 +171,7 @@ int SQLiteSingleVerStorageEngine::MigrateSyncDataByVersion(SQLiteSingleVerStorag SetMaxTimestamp(timestamp); } - errCode = ReleaseHandleTransiently(handle, 2ull); // temporary release handle 2ms + errCode = ReleaseHandleTransiently(handle, 2ULL); // temporary release handle 2ms if (errCode != E_OK) { return errCode; } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp index 061d9b89ffa..66165c85494 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp @@ -172,14 +172,14 @@ int SQLiteSingleVerStorageExecutor::AddSubscribeTrigger(QueryObject &query, cons std::string subscribeCondition; errCode = helper.GetSubscribeSql(subscribeId, mode, subscribeCondition); if (errCode != E_OK) { - LOGE("Get subscribe trigger create sql failed. mode: %u, errCode: %d", static_cast(mode), + LOGE("Get subscribe trigger create sql failed. mode: %d, errCode: %d", static_cast(mode), errCode); return errCode; } std::string sql = FormatSubscribeTriggerSql(subscribeId, subscribeCondition, mode); errCode = SQLiteUtils::ExecuteRawSQL(dbHandle_, sql); if (errCode != E_OK) { - LOGE("Add subscribe trigger failed. mode: %u, errCode: %d", static_cast(mode), errCode); + LOGE("Add subscribe trigger failed. mode: %d, errCode: %d", static_cast(mode), errCode); return errCode; } } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp index 4d004150816..5fc2fafcc55 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.cpp @@ -123,11 +123,6 @@ void SQLiteStorageEngine::SetEngineState(EngineState state) engineState_ = state; // Current usage logically can guarantee no concurrency } -const OpenDbProperties &SQLiteStorageEngine::GetOpenOption() const -{ - return option_; -} - bool SQLiteStorageEngine::IsNeedMigrate() const { return false; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.h index bed31646634..b8aecd9f2ed 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_engine.h @@ -44,8 +44,6 @@ public: void SetEngineState(EngineState state) override; - const OpenDbProperties &GetOpenOption() const; - virtual void IncreaseCacheRecordVersion(); virtual uint64_t GetCacheRecordVersion() const; virtual uint64_t GetAndIncreaseCacheRecordVersion(); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp index 37c94a69860..05b5fb4dcbd 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.cpp @@ -48,7 +48,6 @@ namespace { const int USING_STR_LEN = -1; const std::string WAL_MODE_SQL = "PRAGMA journal_mode=WAL;"; const std::string SYNC_MODE_FULL_SQL = "PRAGMA synchronous=FULL;"; - const std::string SYNC_MODE_NORMAL_SQL = "PRAGMA synchronous=NORMAL;"; const std::string USER_VERSION_SQL = "PRAGMA user_version;"; const std::string BEGIN_SQL = "BEGIN TRANSACTION"; const std::string BEGIN_IMMEDIATE_SQL = "BEGIN IMMEDIATE TRANSACTION"; @@ -1144,24 +1143,6 @@ int SQLiteUtils::ExportDatabase(const std::string &srcFile, CipherType type, con } #endif -int SQLiteUtils::SaveSchema(const OpenDbProperties &properties) -{ - if (properties.uri.empty()) { - return -E_INVALID_ARGS; - } - - sqlite3 *db = nullptr; - int errCode = OpenDatabase(properties, db); - if (errCode != E_OK) { - return errCode; - } - - errCode = SaveSchema(db, properties.schema); - (void)sqlite3_close_v2(db); - db = nullptr; - return errCode; -} - int SQLiteUtils::SaveSchema(sqlite3 *db, const std::string &strSchema) { if (db == nullptr) { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.h index c759bc78fcf..d2fef37a3ef 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_utils.h @@ -127,8 +127,6 @@ public: static int MapSQLiteErrno(int errCode); - static int SaveSchema(const OpenDbProperties &properties); - static int SaveSchema(sqlite3 *db, const std::string &strSchema); static int GetSchema(const OpenDbProperties &properties, std::string &strSchema); -- Gitee