diff --git a/frameworks/libs/distributeddb/common/include/json_object.h b/frameworks/libs/distributeddb/common/include/json_object.h index 3d79c31acb5c8fa1b80cce393e44eb69c0bb329f..aa2b0a3789977be0113e80cfa1e48aeb17ee336a 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/macro_utils.h b/frameworks/libs/distributeddb/common/include/macro_utils.h index ec2ccd61cb4d90ce479cd0c2b9dd06203568b9b7..bc73f17f5e8e51f7a3379a5c00e95fadb5d06246 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/include/relational/prepared_stmt.h b/frameworks/libs/distributeddb/common/include/relational/prepared_stmt.h index 38eb2fe7cc12c5491176027a1ef729c90d8f3a08..ddcdd9df5ea31fd527d376940c69e709178ca085 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 995a72292818d2b7023852695aeda9e661846538..dd1dc0f2dc073241cc88c518999c870b22b59f42 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 7cb622ff622c669fc76e296f8642a5a2c3cc4324..270b622087220daed12ba28a2961800529f23808 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 9b51158ddca8d18a7a384cf5d725d05afb549883..384e9aca5ef081edbf8abbb2191a2afccdf1660b 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); } @@ -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; } @@ -272,7 +270,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/evloop/src/event_impl.cpp b/frameworks/libs/distributeddb/common/src/evloop/src/event_impl.cpp index 4a70a3aeb61d910483ebcec502664dad5e118647..0f29cc09ce6c08c5aafb3d35f4a00503458c0435 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 48964b5585161d970ec98bacbbd29ce326d2fe11..df9caae0df5060ea8b303f60e7b4e2ef9b00d432 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/param_check_utils.cpp b/frameworks/libs/distributeddb/common/src/param_check_utils.cpp index 2a1fe4d232a5d74ea21f450c9233b32fbfadad27..b2847e694cd4df6dea3ae2b96a93fae2dd7e775d 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/parcel.cpp b/frameworks/libs/distributeddb/common/src/parcel.cpp index 815597416fac4d7b0f33071646184778e6420739..2a30404e31cecc085e01b0e7833f47f143e11159 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_row_data_set.cpp b/frameworks/libs/distributeddb/common/src/relational/relational_row_data_set.cpp index e602066006e94fc46ab81d3456c4bf6e042e9b2d..ef949515a615166b1cb8492ca51cd34e55381468 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()) { @@ -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/relational/relational_schema_object.cpp b/frameworks/libs/distributeddb/common/src/relational/relational_schema_object.cpp index fa8936ca51627ad6b8e70de4efb111a87767b120..6fa207c68c13421a6ec198ca9f04ebf30e82af87 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/common/src/schema_negotiate.cpp b/frameworks/libs/distributeddb/common/src/schema_negotiate.cpp index e1669b7f7487619e5a464d8aeb4cbe2430ed7fbe..3167c58e55a466e022b1a95ced56c7f537d98af8 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 b3ecf81e66a6c39b7f922b220ddffc4962efd0c1..8157e0953c343f0cba1bef534040fac762cc685f 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/include/query.h b/frameworks/libs/distributeddb/include/query.h index e5e409ebfb4b6d7313c021ef4865ead861872cf5..657e93df3eef3fa1a309822bddcece3649fb9ec0 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 5c931d45035c94531737b748f026903a755734d6..fa4ccdaa27daa734c3a02e18f0ba3535b46dd601 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; } }; @@ -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/iprocess_system_api_adapter.h b/frameworks/libs/distributeddb/interfaces/include/iprocess_system_api_adapter.h index 3a3b14de6dcdac3e5f8082f7fbd28d4c9905f366..6aecd7e6c760a56a5dc92f1adfb28c95c28e8659 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 5194ac455d4004c67a6e84e0ff8a00922e428934..cd5f820905f55f37efb9cccb7cd8050ff00bb1d9 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_errno.h b/frameworks/libs/distributeddb/interfaces/include/kv_store_errno.h index 4cb150f59a06d3cdc8f5a3c01df5e249c1ed948c..ba0835389b851e7a484b6a34bdaa2e52ae63c10a 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/interfaces/include/kv_store_nb_delegate.h b/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h index b9218a75ad219b7317c096b5de44a27139b9dd32..4a27d2eb5c7a389cf83d18988c096c5395766293 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 160b0da71fb29af8fb8696d1203b79cf6c05f908..66276e8d2c710acf2bd89f1bb15d61dd1df9d02c 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 97042fd5bf92eabca29e70a36cc9561aa8473e89..9dafce35271ef9aab01a31c8b63898aaec87ef31 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 d1a0be4449550aee11b767ec1df405e40c18e60a..41c087c90e0ae31d3c1eeb373d07874126bb4b92 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_impl.cpp @@ -19,22 +19,21 @@ #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 { - 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 +65,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 +82,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 +99,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 +116,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 +133,7 @@ DBStatus KvStoreDelegateImpl::Clear() return TransferDBErrno(errCode); } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -177,7 +176,7 @@ void KvStoreDelegateImpl::GetKvStoreSnapshot(KvStoreObserver *observer, } } - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); callback(DB_ERROR, nullptr); } @@ -210,7 +209,7 @@ DBStatus KvStoreDelegateImpl::RegisterObserver(KvStoreObserver *observer) } if (conn_ == nullptr) { - LOGE("%s", INVALID_CONNECTION.c_str()); + LOGE("%s", INVALID_CONNECTION); return DB_ERROR; } @@ -248,7 +247,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 +271,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 +286,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 +301,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 +339,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 +373,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 +403,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 +430,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_delegate_manager.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp index ebf55f74b134f811feb276b7282125c6fce96058..311c51c559877097278e0134b38aada8c0dac160 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/kv_store_nb_conflict_data_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_conflict_data_impl.cpp index 36e8b0bdca26840f9fa92d7783a018e844a65798..ceb254a552cfcc3a003af00d3f31b817b6d3f22e 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 4d0cb7cccdb198da830cf9f6091c470476d85878..12a9f6956c7999f991083710316126c8d5d2e387 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 &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_nb_delegate_impl.h b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h index e791be26aeafbaee56f5cca93251831b31543edb..2693de932958bf0ee59a3585d63dfd0b5e42e252 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h @@ -16,13 +16,13 @@ #ifndef KV_STORE_NB_DELEGATE_IMPL_H #define KV_STORE_NB_DELEGATE_IMPL_H -#include #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 11c3e61929c4845e06671adc3103fc1ff0ea5e24..0e4d114148768e4e3915e4e47b70c64821d9a7f0 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 6092dcb64fc20d3d0cb045520d427330eb1b9430..45082535d68b11e83f89f031f37b2411a12d15f0 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/kv_store_snapshot_delegate_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_snapshot_delegate_impl.cpp index 17ce4a8f9f1b7277723bc5691787a29231d738c4..6fbe5e3f240e9670caf203315aa4a9331690d6da 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/interfaces/src/relational/relational_store_changed_data_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/relational/relational_store_changed_data_impl.cpp index 4afb818b65682b691c7c5cfaa9f48ce5a2d3ba42..45638fa122d6a55e9a42441fab67ccbfd8117c43 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 c2be0738cf05411be57a09f0d5782ec15803c8f8..ac94a227a231a0c121fcba750471213d08e1c8d8 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 96f44a8f9a668986f9401dd84923128af013cbe8..4646d97e1211a80eee2db23785798c2c8b83c5ba 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 82968e5e3c4635ef5d7e8dffbde75a19d0b1e5c4..96f81b436a89fc9e9a4f8ea3f4976b4ce78455a9 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" @@ -90,20 +89,12 @@ 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; 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/include/ikvdb_sync_interface.h b/frameworks/libs/distributeddb/storage/include/ikvdb_sync_interface.h index 572add415c36ac39eb9a88cfba2c2d1135eda082..b44226dc9593bd7c4175e13b8c6e0ab0572adcf2 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 c985b0d832154b80f63d72c7d10f5298b3c4917f..6b668a791ee71433c3b69a179eae8827de5fa4e9 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 5cf833aa1102805151c028cb925fe37c4080fff7..01ef9a64f09aad564f2560d9073569ebcea5bec2 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 5f1b230a1166d08ef7442c716be126e14ac8e84b..04d4a7ad7dbbc479de0639b1431d0e3767847fbb 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 d29f1a16a9e169a77f36cf751fa3671641a5ff9c..a9dc4660d285cabca6d4aa4fb88d9046fff06152 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 dc9cdf29894a96c0a8c05bb66455b7df3518b1f2..17da22c3edfbfebd87149833a8c6251a96c9b51b 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/generic_kvdb.cpp b/frameworks/libs/distributeddb/storage/src/generic_kvdb.cpp index c1e681e5675ee51fe3ace9d40f034df0382dbe29..2ba26ab57aa86a83a95a8442999903650bc426a3 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/generic_single_ver_kv_entry.cpp b/frameworks/libs/distributeddb/storage/src/generic_single_ver_kv_entry.cpp index 48ec008934e0b6a9a5f4e67b87ccf0817d1bd0e7..d1f6f10f6336241d192e9cbfb9fa10b22f36e705 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 4c7c46867f02d20d86008471a3726ae89ff4eb67..4d1b45ff0ca9ed08fd4d422b635bf06a6a879989 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_); @@ -835,11 +835,7 @@ bool KvDBManager::CompareSchemaObject(const SchemaObject &newSchema, const Schem if (!newSchema.IsSchemaValid() || !oldSchema.IsSchemaValid()) { return false; } - int errCode = oldSchema.CompareAgainstSchemaObject(newSchema); - if (errCode == -E_SCHEMA_EQUAL_EXACTLY) { - return true; - } - return false; + 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/kvdb_properties.cpp b/frameworks/libs/distributeddb/storage/src/kvdb_properties.cpp index c10569d8213c9230958c4ff4719f5b1e9531942e..72885909301823820d8d04ebc45acb5044151f95 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/operation/single_ver_database_oper.cpp b/frameworks/libs/distributeddb/storage/src/operation/single_ver_database_oper.cpp index 6863a736ce625195dcffde98c90d1e4fb607d769..c47b082c6ddb00cb98b19bfc378d17b761e2beb4 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/relational_store_instance.cpp b/frameworks/libs/distributeddb/storage/src/relational_store_instance.cpp index 363b308908db13b5963a091ba68bab1152e74d85..cb1fc43a3b9002444172a403431a58280c7c1c97 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 c9b5f3eb1844387508c9433e3f40f13751ab2b5c..81c15feb8d4cbe9f66b62da3357ae62234409670 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; } @@ -391,6 +393,7 @@ int RelationalSyncAbleStorage::GetSyncDataNext(std::vector & } const auto fieldInfos = storageEngine_->GetSchemaRef().GetTable(token->GetQuery().GetTableName()).GetFieldInfos(); std::vector fieldNames; + fieldNames.reserve(fieldInfos.size()); for (const auto &fieldInfo : fieldInfos) { fieldNames.push_back(fieldInfo.GetFieldName()); } @@ -536,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 {}; @@ -559,6 +550,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/relationaldb_properties.cpp b/frameworks/libs/distributeddb/storage/src/relationaldb_properties.cpp index 6dc2ea91a21493dcabb46fc9f8d2fcb5a5c9c9dd..ee0333bd53abca8d8db12c06fa4cf7e18398d6f9 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 da9b9a479fa562ed814e47ce48403301d55d4783..17b09c163071962cb484e176c1a97810f087d8e2 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" @@ -37,7 +38,7 @@ QueryObject::QueryObject() { } -void QueryObject::GetAttrFromQueryObjNodes() +void QueryObject::SetAttrWithQueryObjNodes() { for (const auto &iter : queryObjNodes_) { SymbolType symbolType = SqliteQueryHelper::GetSymbolType(iter.operFlag); @@ -69,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(); @@ -94,7 +95,7 @@ QueryObject::QueryObject(const std::list &queryObjNodes, const std hasInKeys_(false), orderByCounts_(0) { - GetAttrFromQueryObjNodes(); + SetAttrWithQueryObjNodes(); } QueryObject::~QueryObject() @@ -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()) { @@ -457,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 4f71e0e8b3ead951474d606b1c2ff3764a259289..ec0c648304f59e1e66d6043c57197dc3b5f6ec05 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. @@ -106,9 +90,8 @@ 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; - 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 c42d8c42218b9cd2929a30d0adee372cba9b03d5..7e009ade5db51ca4d9376a5c7c3fc11baae7da5a 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/query_sync_object.cpp @@ -15,14 +15,16 @@ #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 { 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; } @@ -122,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_) { @@ -173,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 7d8ca7630c1a2ea98a03dc2229c43e871ce39c2f..d6193c9e25eaf0ecdd6a7a427a6d6a91cef5c371 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; @@ -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.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store.cpp index 5ce33573053937ae44f0bd4974863ac51a84aa2f..f14bd218af6d130eed9fe9dcf88e856da28513eb 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/relational/sqlite_relational_store_connection.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/relational/sqlite_relational_store_connection.cpp index ba36b9a465a0b9d19ce3c3349052468f55b2d39b..991132b89165c7847f5fa0fc105987c907218c11 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 ec798d2857bdbe9f2a0f49999b900dbb1852baea..3c51d21de0b4b2eb3edd81cc23922c9514c67181 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 d02485d53197f5eaceb8c5232eed792e8008d425..ac163cb83be60848c307c835357041a12ce17fdf 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 3b3370c68675b6c1c7e29e7cef96d1d6ba032600..54ea19c1c2ca8fbb791b09f8bd41c75722bacb8c 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/split_device_log_table_manager.h b/frameworks/libs/distributeddb/storage/src/sqlite/split_device_log_table_manager.h index 63a7612af1eb3c6b6de305ac8fcbf17c96018f9f..7e442ddf6553bc0e133568d506f44b8505665a2a 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_kvdb.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_kvdb.h index 631497a23c45ca77e6b9e9dc8408ac79410383d6..05db13141425da1653fa1dea2e74e4844c5102a2 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_local_storage_executor.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_local_storage_executor.h index a1e6b5d294732e49fcd0b5e48070a5fa910a028e..7726edf3be4540eca2386349a7fc81b9051529a1 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 b1f04273611cbaef556d64d3f16683ff9fd45a94..42810d42bbbd4cb7a36ba5181159480c83a96b19 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_database_upgrader.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_database_upgrader.h index 3d5190e4458590a7654ca821f24497ef6790bb76..65a5c859a52843ccbcc97a32ac65f021e17a3c73 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_natural_store.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.cpp index 871f853adce510dddf77509111a5d6641c959697..95dd5c67b2dcc5568ee7b0ab5ad22b3659d3e63a 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); } } @@ -925,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 @@ -1258,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); @@ -1335,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); @@ -2051,7 +2048,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 dd81bc7b0fb6fc1ebae237394c4abad470b3af1c..2f2fcead31b5768ca6ae512248d7d72ad42ef6b4 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 { @@ -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; @@ -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 25dbf5de5837c7f8f94d9e5c96ed777dac925947..c03b347ace6b1a37c04d1b483218cadcdf211f2d 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 { @@ -62,7 +61,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 +405,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 +1556,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_relational_storage_executor.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_relational_storage_executor.cpp index eb53ab438888ae7dacbc1f791404b1860fc5011a..5639f3b9f165bcef1a25df66d0e270dd36a9b005 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 03e22e9ce82543e2ef2b7595d283f32cec953fd0..88c55535ac04e80cefc28494a1eb35c3d0f150df 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 { @@ -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 6f77bb141c010c39ace6382f3c3eb7564d44d935..e00d62cf2aa9c96aaa9fb6406de6409750ead6e3 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 d4c538304c52fe0d981c1edc79f01ffad129298a..a249e801b560186a554e327e45ebfc5d6cb46ee7 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_schema_database_upgrader.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_schema_database_upgrader.cpp index 4aaaf25ce0b56ede0fb3474cfbbd0047dd8c2611..70cf68ecb843d10182aef25a11e827a4d335618e 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 a5b63634d2c250d8757de4e4b9c7d7718a47058d..146b929819db447f0c45c1f1807bfde77f839c14 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 { @@ -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; } @@ -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_single_ver_storage_executor_cache.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_cache.cpp index 0e766e47675cc34b6df5caea1a9a786bcebf42e9..609f0ceda5e0ff3cd3b91677666b82fce86f219a 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/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_storage_executor_subscribe.cpp index 061d9b89ffacf9ea8cc459e958fd622fc3da60df..66165c854945da3c5d44e1cf63cb591bac9c5c9d 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 4d004150816a77f5a1a4e1ee0f1bb35026b8af84..5fc2fafcc554a4ea4c848bf9117a4735cae87b0e 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 bed316466340fc8bb9fcbbe3c233ea897b66f86d..b8aecd9f2ed4e4c7c1b5036c96d3fa039b774807 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_storage_executor.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_storage_executor.h index 10abd5db26d79a3398cc4349b24ad6cb9bd05103..1730cfe86e48ebfa2aebdc2d954aedcf2881c256 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 08c1d8a77141b004f955b180b585aece026b6c43..05b5fb4dcbde61dd3698ce60ce2590c4f424d1d5 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"; @@ -815,7 +814,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); } @@ -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) { @@ -1273,12 +1254,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 +1369,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 + "("; @@ -1772,7 +1736,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 @@ -2089,7 +2053,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 +2116,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 3b59e575fedd380c412af1940993033d9c6de941..d2fef37a3ef19c8989baf83d4877d4610986cf9c 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); @@ -168,7 +166,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/storage/src/storage_engine_manager.cpp b/frameworks/libs/distributeddb/storage/src/storage_engine_manager.cpp index 8657a4e9a67002d07333e8928a5295a804530321..1d8b15bd5dbea295b2fb636b4e949e175aeb15b7 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; } 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 291518d1f412107711b7293b604f5191234c253a..d3a430cb83bab063c3bfe348a020eb3db70aea9b 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 4e9343aece32f3d8adf78156db81dabb8398b361..3d6aba3766d6ef7230a6d4397e5edf19234d8d76 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/syncer/src/subscribe_manager.cpp b/frameworks/libs/distributeddb/syncer/src/subscribe_manager.cpp index f0facc99739be521fef358a6589ad2432946009b..172887be6f0c0181d5e0004fff0cfe9d28c14135 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 42ca070c54b65850421b2d62c5ce5bc16d6283c4..88af8fa026ae06576cfe01e8f645c45d533d7027 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 221dcbca9c5b0f10a7414b4bb26985f33de5643c..25ce3bf2869ea7426a56790b0146f86ec3b5d764 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 a7ce0829ad300c9a5c505b8655aa42fa20fb74b8..761da484a297e041f1a1da2d38b752e7e27865a2 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 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 afda4562fedb4ec727905a5487b2df2244db2af5..04e44c4bcd8b1ab830194cd64c016194d7117231 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 e42cba6be4faa482cd9010aea750c69a917cca4c..e44f57b4eb312327edf0d20068476bb4b921c21b 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;