From 8ee8845170b778abcf83ed53d17c67ae36cf0b78 Mon Sep 17 00:00:00 2001 From: zhangdi Date: Sat, 28 Sep 2024 10:16:25 +0800 Subject: [PATCH] BatchInsert Signed-off-by: zhangdi --- .../include/napi_rdb_context.h | 4 +- .../include/napi_rdb_context.h.rej | 24 ++++ .../relationalstore/src/napi_rdb_store.cpp | 6 +- .../src/napi_rdb_store.cpp.rej | 21 ++++ frameworks/native/rdb/include/rd_statement.h | 4 +- .../native/rdb/include/rd_statement.h.rej | 24 ++++ .../native/rdb/include/rdb_store_impl.h | 7 +- .../native/rdb/include/rdb_store_impl.h.rej | 36 ++++++ .../native/rdb/include/sqlite_sql_builder.h | 5 +- .../rdb/include/sqlite_sql_builder.h.rej | 22 ++++ .../native/rdb/include/sqlite_statement.h | 4 +- .../native/rdb/include/sqlite_statement.h.rej | 24 ++++ frameworks/native/rdb/include/statement.h | 1 + frameworks/native/rdb/include/statement.h.rej | 9 ++ .../native/rdb/mock/include/rdb_store_impl.h | 10 +- .../rdb/mock/include/rdb_store_impl.h.rej | 39 +++++++ frameworks/native/rdb/src/big_integer.cpp | 7 +- frameworks/native/rdb/src/big_integer.cpp.rej | 20 ++++ frameworks/native/rdb/src/rd_statement.cpp | 26 ++++- .../native/rdb/src/rd_statement.cpp.rej | 63 +++++++++++ frameworks/native/rdb/src/rdb_store_impl.cpp | 53 +++++++-- .../native/rdb/src/rdb_store_impl.cpp.rej | 104 ++++++++++++++++++ .../native/rdb/src/sqlite_sql_builder.cpp | 6 +- .../native/rdb/src/sqlite_sql_builder.cpp.rej | 64 +++++++++++ .../native/rdb/src/sqlite_statement.cpp | 24 +++- .../native/rdb/src/sqlite_statement.cpp.rej | 49 +++++++++ frameworks/native/rdb/src/value_object.cpp | 35 ++++++ .../native/rdb/src/value_object.cpp.rej | 42 +++++++ frameworks/native/rdb/src/values_buckets.cpp | 66 +++++++++++ interfaces/inner_api/rdb/BUILD.gn | 1 + interfaces/inner_api/rdb/BUILD.gn.rej | 9 ++ .../inner_api/rdb/include/big_integer.h | 1 + .../inner_api/rdb/include/big_integer.h.rej | 9 ++ interfaces/inner_api/rdb/include/rdb_store.h | 12 ++ .../inner_api/rdb/include/rdb_store.h.rej | 27 +++++ .../inner_api/rdb/include/value_object.h | 4 +- .../inner_api/rdb/include/value_object.h.rej | 19 ++++ .../inner_api/rdb/include/values_buckets.h | 52 +++++++++ .../inner_api/rdb/mock/include/big_integer.h | 1 + .../rdb/mock/include/big_integer.h.rej | 9 ++ .../inner_api/rdb/mock/include/rdb_store.h | 6 + .../rdb/mock/include/rdb_store.h.rej | 21 ++++ .../inner_api/rdb/mock/include/value_object.h | 2 + .../rdb/mock/include/value_object.h.rej | 10 ++ .../rdb/mock/include/values_buckets.h | 51 +++++++++ 45 files changed, 1003 insertions(+), 30 deletions(-) create mode 100644 frameworks/js/napi/relationalstore/include/napi_rdb_context.h.rej create mode 100644 frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp.rej create mode 100644 frameworks/native/rdb/include/rd_statement.h.rej create mode 100644 frameworks/native/rdb/include/rdb_store_impl.h.rej create mode 100644 frameworks/native/rdb/include/sqlite_sql_builder.h.rej create mode 100644 frameworks/native/rdb/include/sqlite_statement.h.rej create mode 100644 frameworks/native/rdb/include/statement.h.rej create mode 100644 frameworks/native/rdb/mock/include/rdb_store_impl.h.rej create mode 100644 frameworks/native/rdb/src/big_integer.cpp.rej create mode 100644 frameworks/native/rdb/src/rd_statement.cpp.rej create mode 100644 frameworks/native/rdb/src/rdb_store_impl.cpp.rej create mode 100644 frameworks/native/rdb/src/sqlite_sql_builder.cpp.rej create mode 100644 frameworks/native/rdb/src/sqlite_statement.cpp.rej create mode 100644 frameworks/native/rdb/src/value_object.cpp.rej create mode 100644 frameworks/native/rdb/src/values_buckets.cpp create mode 100644 interfaces/inner_api/rdb/BUILD.gn.rej create mode 100644 interfaces/inner_api/rdb/include/big_integer.h.rej create mode 100644 interfaces/inner_api/rdb/include/rdb_store.h.rej create mode 100644 interfaces/inner_api/rdb/include/value_object.h.rej create mode 100644 interfaces/inner_api/rdb/include/values_buckets.h create mode 100644 interfaces/inner_api/rdb/mock/include/big_integer.h.rej create mode 100644 interfaces/inner_api/rdb/mock/include/rdb_store.h.rej create mode 100644 interfaces/inner_api/rdb/mock/include/value_object.h.rej create mode 100644 interfaces/inner_api/rdb/mock/include/values_buckets.h diff --git a/frameworks/js/napi/relationalstore/include/napi_rdb_context.h b/frameworks/js/napi/relationalstore/include/napi_rdb_context.h index 2a89fe25c..4df2e99e6 100644 --- a/frameworks/js/napi/relationalstore/include/napi_rdb_context.h +++ b/frameworks/js/napi/relationalstore/include/napi_rdb_context.h @@ -18,6 +18,7 @@ #include "napi_async_call.h" #include "napi_rdb_predicates.h" +#include "values_buckets.h" namespace OHOS { namespace RelationalStoreJsKit { @@ -37,6 +38,7 @@ struct RdbStoreContext : public RdbStoreContextBase { std::vector columns; ValuesBucket valuesBucket; std::vector valuesBuckets; + ValuesBuckets sharedValuesBuckets; std::map numberMaps; std::vector bindArgs; int64_t int64Output; @@ -75,4 +77,4 @@ struct RdbStoreContext : public RdbStoreContextBase { }; } // namespace RelationalStoreJsKit } // namespace OHOS -#endif // NAPI_RDB_CONTEXT_H \ No newline at end of file +#endif // NAPI_RDB_CONTEXT_H diff --git a/frameworks/js/napi/relationalstore/include/napi_rdb_context.h.rej b/frameworks/js/napi/relationalstore/include/napi_rdb_context.h.rej new file mode 100644 index 000000000..f6ceb75ef --- /dev/null +++ b/frameworks/js/napi/relationalstore/include/napi_rdb_context.h.rej @@ -0,0 +1,24 @@ +diff a/frameworks/js/napi/relationalstore/include/napi_rdb_context.h b/frameworks/js/napi/relationalstore/include/napi_rdb_context.h (rejected hunks) +@@ -18,6 +18,7 @@ + + #include "napi_async_call.h" + #include "napi_rdb_predicates.h" ++#include "values_buckets.h" + + namespace OHOS { + namespace RelationalStoreJsKit { +@@ -37,6 +38,7 @@ struct RdbStoreContext : public RdbStoreContextBase { + std::vector columns; + ValuesBucket valuesBucket; + std::vector valuesBuckets; ++ ValuesBuckets sharedValuesBuckets; + std::map numberMaps; + std::vector bindArgs; + int64_t int64Output; +@@ -75,4 +77,4 @@ struct RdbStoreContext : public RdbStoreContextBase { + }; + } // namespace RelationalStoreJsKit + } // namespace OHOS +-#endif // NAPI_RDB_CONTEXT_H +\ No newline at end of file ++#endif // NAPI_RDB_CONTEXT_H diff --git a/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp b/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp index 62c151f2e..7e7b3d522 100644 --- a/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp +++ b/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp @@ -599,7 +599,7 @@ int ParseValuesBuckets(const napi_env env, const napi_value arg, std::shared_ptr CHECK_RETURN_SET(status == napi_ok, std::make_shared("napi_get_element failed.")); CHECK_RETURN_ERR(ParseValuesBucket(env, obj, context) == OK); - context->valuesBuckets.push_back(std::move(context->valuesBucket)); + context->sharedValuesBuckets.Put(context->valuesBucket); context->valuesBucket.Clear(); } return OK; @@ -661,7 +661,9 @@ napi_value RdbStoreProxy::BatchInsert(napi_env env, napi_callback_info info) auto exec = [context]() -> int { CHECK_RETURN_ERR(context->rdbStore != nullptr); auto rdbStore = std::move(context->rdbStore); - return rdbStore->BatchInsert(context->int64Output, context->tableName, context->valuesBuckets); + auto [ret, output] = rdbStore->BatchInsert(context->tableName, context->sharedValuesBuckets); + context->int64Output = output; + return ret; }; auto output = [context](napi_env env, napi_value &result) { napi_status status = napi_create_int64(env, context->int64Output, &result); diff --git a/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp.rej b/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp.rej new file mode 100644 index 000000000..6703a3bdd --- /dev/null +++ b/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp.rej @@ -0,0 +1,21 @@ +diff a/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp b/frameworks/js/napi/relationalstore/src/napi_rdb_store.cpp (rejected hunks) +@@ -597,7 +597,7 @@ int ParseValuesBuckets(const napi_env env, const napi_value arg, std::shared_ptr + CHECK_RETURN_SET(status == napi_ok, std::make_shared("napi_get_element failed.")); + + CHECK_RETURN_ERR(ParseValuesBucket(env, obj, context) == OK); +- context->valuesBuckets.push_back(std::move(context->valuesBucket)); ++ context->sharedValuesBuckets.Put(context->valuesBucket); + context->valuesBucket.Clear(); + } + return OK; +@@ -659,7 +659,9 @@ napi_value RdbStoreProxy::BatchInsert(napi_env env, napi_callback_info info) + auto exec = [context]() -> int { + CHECK_RETURN_ERR(context->rdbStore != nullptr); + auto rdbStore = std::move(context->rdbStore); +- return rdbStore->BatchInsert(context->int64Output, context->tableName, context->valuesBuckets); ++ auto [ret, output] = rdbStore->BatchInsert(context->tableName, context->sharedValuesBuckets); ++ context->int64Output = output; ++ return ret; + }; + auto output = [context](napi_env env, napi_value &result) { + napi_status status = napi_create_int64(env, context->int64Output, &result); diff --git a/frameworks/native/rdb/include/rd_statement.h b/frameworks/native/rdb/include/rd_statement.h index c570d5125..a1271fddf 100644 --- a/frameworks/native/rdb/include/rd_statement.h +++ b/frameworks/native/rdb/include/rd_statement.h @@ -39,6 +39,7 @@ public: int32_t Step() override; int32_t Reset() override; int32_t Execute(const std::vector& args) override; + int32_t Execute(const std::vector>& args) override; std::pair ExecuteForValue(const std::vector& args) override; int32_t Changes() const override; int64_t LastInsertRowId() const override; @@ -55,6 +56,7 @@ public: private: friend class RdConnection; int Prepare(GRD_DB *db, const std::string &sql); + int32_t Bind(const std::vector>& args); int InnerBindBlobTypeArgs(const ValueObject &bindArg, uint32_t index) const; int IsValid(int index) const; @@ -73,4 +75,4 @@ private: }; } // namespace NativeRdb } // namespace OHOS -#endif // NATIVE_RDB_RD_STATEMENT_H \ No newline at end of file +#endif // NATIVE_RDB_RD_STATEMENT_H diff --git a/frameworks/native/rdb/include/rd_statement.h.rej b/frameworks/native/rdb/include/rd_statement.h.rej new file mode 100644 index 000000000..94f49bb17 --- /dev/null +++ b/frameworks/native/rdb/include/rd_statement.h.rej @@ -0,0 +1,24 @@ +diff a/frameworks/native/rdb/include/rd_statement.h b/frameworks/native/rdb/include/rd_statement.h (rejected hunks) +@@ -39,6 +39,7 @@ public: + int32_t Step() override; + int32_t Reset() override; + int32_t Execute(const std::vector& args) override; ++ int32_t Execute(const std::vector>& args) override; + std::pair ExecuteForValue(const std::vector& args) override; + int32_t Changes() const override; + int64_t LastInsertRowId() const override; +@@ -55,6 +56,7 @@ public: + private: + friend class RdConnection; + int Prepare(GRD_DB *db, const std::string &sql); ++ int32_t Bind(const std::vector>& args); + int InnerBindBlobTypeArgs(const ValueObject &bindArg, uint32_t index) const; + int IsValid(int index) const; + +@@ -73,4 +75,4 @@ private: + }; + } // namespace NativeRdb + } // namespace OHOS +-#endif // NATIVE_RDB_RD_STATEMENT_H +\ No newline at end of file ++#endif // NATIVE_RDB_RD_STATEMENT_H diff --git a/frameworks/native/rdb/include/rdb_store_impl.h b/frameworks/native/rdb/include/rdb_store_impl.h index a0415cffc..17a5441e5 100644 --- a/frameworks/native/rdb/include/rdb_store_impl.h +++ b/frameworks/native/rdb/include/rdb_store_impl.h @@ -82,6 +82,7 @@ public: const RdbStoreConfig &GetConfig(); int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &values) override; int BatchInsert(int64_t& outInsertNum, const std::string& table, const std::vector& values) override; + std::pair BatchInsert(const std::string& table, const ValuesBuckets& values) override; int Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) override; int InsertWithConflictResolution(int64_t &outRowId, const std::string &table, const ValuesBucket &values, ConflictResolution conflictResolution) override; @@ -198,6 +199,8 @@ public: private: using ExecuteSqls = std::vector>>>; + using ExecuteSqlsRef = + std::vector>>>>; using Stmt = std::shared_ptr; using RdbParam = DistributedRdb::RdbSyncerParam; @@ -211,6 +214,7 @@ private: int CheckAttach(const std::string &sql); std::pair BeginExecuteSql(const std::string &sql); ExecuteSqls GenerateSql(const std::string& table, const std::vector& buckets, int limit); + ExecuteSqlsRef GenerateSql(const std::string& table, const ValuesBuckets& buckets, int limit); int GetDataBasePath(const std::string &databasePath, std::string &backupFilePath); void SetAssetStatus(const ValueObject &val, int32_t status); void DoCloudSync(const std::string &table); @@ -244,7 +248,8 @@ private: int UpdateWithConflictResolutionEntry(int &changedRows, const std::string &table, const ValuesBucket &values, const std::string &whereClause, const std::vector &bindArgs, ConflictResolution conflictResolution); - int BatchInsertEntry(int64_t& outInsertNum, const std::string& table, const std::vector& values); + template + int BatchInsertEntry(const std::string& table, const T& values, size_t rowSize, int64_t& outInsertNum); int ExecuteSqlEntry(const std::string& sql, const std::vector& bindArgs); std::pair ExecuteEntry(const std::string& sql, const std::vector& bindArgs, int64_t trxId); diff --git a/frameworks/native/rdb/include/rdb_store_impl.h.rej b/frameworks/native/rdb/include/rdb_store_impl.h.rej new file mode 100644 index 000000000..92573ec87 --- /dev/null +++ b/frameworks/native/rdb/include/rdb_store_impl.h.rej @@ -0,0 +1,36 @@ +diff a/frameworks/native/rdb/include/rdb_store_impl.h b/frameworks/native/rdb/include/rdb_store_impl.h (rejected hunks) +@@ -82,6 +82,7 @@ public: + const RdbStoreConfig &GetConfig(); + int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &values) override; + int BatchInsert(int64_t& outInsertNum, const std::string& table, const std::vector& values) override; ++ std::pair BatchInsert(const std::string& table, const ValuesBuckets& values) override; + int Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) override; + int InsertWithConflictResolution(int64_t &outRowId, const std::string &table, const ValuesBucket &values, + ConflictResolution conflictResolution) override; +@@ -198,6 +199,8 @@ public: + + private: + using ExecuteSqls = std::vector>>>; ++ using ExecuteSqlsRef = ++ std::vector>>>>; + using Stmt = std::shared_ptr; + using RdbParam = DistributedRdb::RdbSyncerParam; + +@@ -211,6 +214,7 @@ private: + int CheckAttach(const std::string &sql); + std::pair BeginExecuteSql(const std::string &sql); + ExecuteSqls GenerateSql(const std::string& table, const std::vector& buckets, int limit); ++ ExecuteSqlsRef GenerateSql(const std::string& table, const ValuesBuckets& buckets, int limit); + int GetDataBasePath(const std::string &databasePath, std::string &backupFilePath); + int ExecuteSqlInner(const std::string &sql, const std::vector &bindArgs); + void SetAssetStatus(const ValueObject &val, int32_t status); +@@ -245,7 +249,8 @@ private: + int UpdateWithConflictResolutionEntry(int &changedRows, const std::string &table, const ValuesBucket &values, + const std::string &whereClause, const std::vector &bindArgs, + ConflictResolution conflictResolution); +- int BatchInsertEntry(int64_t& outInsertNum, const std::string& table, const std::vector& values); ++ template ++ int BatchInsertEntry(const std::string& table, const T& values, size_t rowSize, int64_t& outInsertNum); + int ExecuteSqlEntry(const std::string& sql, const std::vector& bindArgs); + std::pair ExecuteEntry(const std::string& sql, const std::vector& bindArgs, + int64_t trxId); diff --git a/frameworks/native/rdb/include/sqlite_sql_builder.h b/frameworks/native/rdb/include/sqlite_sql_builder.h index 537a08427..46d38e3db 100644 --- a/frameworks/native/rdb/include/sqlite_sql_builder.h +++ b/frameworks/native/rdb/include/sqlite_sql_builder.h @@ -48,8 +48,9 @@ public: const AbsRdbPredicates &predicates, const std::vector &columns, const std::string &logTable); static std::string GetSqlArgs(size_t size); - static ExecuteSqls MakeExecuteSqls( - const std::string &sql, std::vector &&args, int fieldSize, int limit); + template + static std::vector>>> MakeExecuteSqls( + const std::string &sql, const std::vector &args, int fieldSize, int limit); private: static void AppendClause(std::string &builder, const std::string &name, const std::string &clause, const std::string &table = ""); diff --git a/frameworks/native/rdb/include/sqlite_sql_builder.h.rej b/frameworks/native/rdb/include/sqlite_sql_builder.h.rej new file mode 100644 index 000000000..9baca5f38 --- /dev/null +++ b/frameworks/native/rdb/include/sqlite_sql_builder.h.rej @@ -0,0 +1,22 @@ +diff a/frameworks/native/rdb/include/sqlite_sql_builder.h b/frameworks/native/rdb/include/sqlite_sql_builder.h (rejected hunks) +@@ -27,6 +27,8 @@ namespace NativeRdb { + class SqliteSqlBuilder { + public: + using ExecuteSqls = std::vector>>>; ++ using ExecuteSqlsRef = ++ std::vector>>>>; + SqliteSqlBuilder(); + ~SqliteSqlBuilder(); + static std::string BuildDeleteString(const std::string &tableName, const std::string &index, +@@ -54,8 +56,9 @@ public: + const AbsRdbPredicates &predicates, const std::vector &columns, const std::string &logTable); + static std::string GetSqlArgs(size_t size); + +- static ExecuteSqls MakeExecuteSqls( +- const std::string &sql, std::vector &&args, int fieldSize, int limit); ++ template ++ static std::vector>>> MakeExecuteSqls( ++ const std::string &sql, const std::vector &args, int fieldSize, int limit); + private: + static void AppendClause(std::string &builder, const std::string &name, + const std::string &clause, const std::string &table = ""); diff --git a/frameworks/native/rdb/include/sqlite_statement.h b/frameworks/native/rdb/include/sqlite_statement.h index c7ddb2738..fdf509203 100644 --- a/frameworks/native/rdb/include/sqlite_statement.h +++ b/frameworks/native/rdb/include/sqlite_statement.h @@ -44,6 +44,7 @@ public: int Reset() override; int Finalize() override; int Execute(const std::vector &args) override; + int32_t Execute(const std::vector> &args) override; std::pair ExecuteForValue(const std::vector &args) override; int Changes() const override; int64_t LastInsertRowId() const override; @@ -82,6 +83,7 @@ private: int Prepare(sqlite3 *dbHandle, const std::string &sql); int BindArgs(const std::vector &bindArgs); + int BindArgs(const std::vector> &bindArgs); int IsValid(int index) const; int InnerStep(); int InnerFinalize(); @@ -109,4 +111,4 @@ private: }; } // namespace NativeRdb } // namespace OHOS -#endif \ No newline at end of file +#endif diff --git a/frameworks/native/rdb/include/sqlite_statement.h.rej b/frameworks/native/rdb/include/sqlite_statement.h.rej new file mode 100644 index 000000000..63c4d65ce --- /dev/null +++ b/frameworks/native/rdb/include/sqlite_statement.h.rej @@ -0,0 +1,24 @@ +diff a/frameworks/native/rdb/include/sqlite_statement.h b/frameworks/native/rdb/include/sqlite_statement.h (rejected hunks) +@@ -44,6 +44,7 @@ public: + int Reset() override; + int Finalize() override; + int Execute(const std::vector &args) override; ++ int32_t Execute(const std::vector> &args) override; + std::pair ExecuteForValue(const std::vector &args) override; + int Changes() const override; + int64_t LastInsertRowId() const override; +@@ -82,6 +83,7 @@ private: + + int Prepare(sqlite3 *dbHandle, const std::string &sql); + int BindArgs(const std::vector &bindArgs); ++ int BindArgs(const std::vector> &bindArgs); + int IsValid(int index) const; + int InnerStep(); + int InnerFinalize(); +@@ -109,4 +111,4 @@ private: + }; + } // namespace NativeRdb + } // namespace OHOS +-#endif +\ No newline at end of file ++#endif diff --git a/frameworks/native/rdb/include/statement.h b/frameworks/native/rdb/include/statement.h index 400bcff86..d5d256536 100644 --- a/frameworks/native/rdb/include/statement.h +++ b/frameworks/native/rdb/include/statement.h @@ -39,6 +39,7 @@ public: virtual int32_t Reset() = 0; virtual int32_t Finalize() = 0; virtual int32_t Execute(const std::vector &args = {}) = 0; + virtual int32_t Execute(const std::vector> &args) = 0; virtual std::pair ExecuteForValue(const std::vector &args = {}) = 0; virtual int32_t Changes() const = 0; diff --git a/frameworks/native/rdb/include/statement.h.rej b/frameworks/native/rdb/include/statement.h.rej new file mode 100644 index 000000000..d7d344a63 --- /dev/null +++ b/frameworks/native/rdb/include/statement.h.rej @@ -0,0 +1,9 @@ +diff a/frameworks/native/rdb/include/statement.h b/frameworks/native/rdb/include/statement.h (rejected hunks) +@@ -39,6 +39,7 @@ public: + virtual int32_t Reset() = 0; + virtual int32_t Finalize() = 0; + virtual int32_t Execute(const std::vector &args = {}) = 0; ++ virtual int32_t Execute(const std::vector> &args) = 0; + + virtual std::pair ExecuteForValue(const std::vector &args = {}) = 0; + virtual int32_t Changes() const = 0; diff --git a/frameworks/native/rdb/mock/include/rdb_store_impl.h b/frameworks/native/rdb/mock/include/rdb_store_impl.h index 67056e277..123cf9287 100644 --- a/frameworks/native/rdb/mock/include/rdb_store_impl.h +++ b/frameworks/native/rdb/mock/include/rdb_store_impl.h @@ -38,8 +38,8 @@ public: ~RdbStoreImpl() override; const RdbStoreConfig &GetConfig(); int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &values) override; - int BatchInsert( - int64_t& outInsertNum, const std::string& table, const std::vector& values) override; + int BatchInsert(int64_t& outInsertNum, const std::string& table, const std::vector& values) override; + std::pair BatchInsert(const std::string& table, const ValuesBuckets& values) override; int Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) override; int InsertWithConflictResolution(int64_t &outRowId, const std::string &table, const ValuesBucket &values, ConflictResolution conflictResolution) override; @@ -108,6 +108,8 @@ public: private: using ExecuteSqls = std::vector>>>; + using ExecuteSqlsRef = + std::vector>>>>; using Stmt = std::shared_ptr; using RdbParam = DistributedRdb::RdbSyncerParam; @@ -120,6 +122,7 @@ private: int CheckAttach(const std::string &sql); std::pair BeginExecuteSql(const std::string &sql); ExecuteSqls GenerateSql(const std::string& table, const std::vector& buckets, int limit); + ExecuteSqlsRef GenerateSql(const std::string& table, const ValuesBuckets& buckets, int limit); int GetDataBasePath(const std::string &databasePath, std::string &backupFilePath); int ExecuteSqlInner(const std::string &sql, const std::vector &bindArgs); void SetAssetStatus(const ValueObject &val, int32_t status); @@ -136,7 +139,8 @@ private: int UpdateWithConflictResolutionEntry(int &changedRows, const std::string &table, const ValuesBucket &values, const std::string &whereClause, const std::vector &bindArgs, ConflictResolution conflictResolution); - int BatchInsertEntry(int64_t& outInsertNum, const std::string& table, const std::vector& values); + template + int BatchInsertEntry(const std::string& table, const T& values, size_t rowSize, int64_t& outInsertNum); int ExecuteSqlEntry(const std::string& sql, const std::vector& bindArgs); std::pair ExecuteEntry(const std::string& sql, const std::vector& bindArgs, int64_t trxId); diff --git a/frameworks/native/rdb/mock/include/rdb_store_impl.h.rej b/frameworks/native/rdb/mock/include/rdb_store_impl.h.rej new file mode 100644 index 000000000..164a8a892 --- /dev/null +++ b/frameworks/native/rdb/mock/include/rdb_store_impl.h.rej @@ -0,0 +1,39 @@ +diff a/frameworks/native/rdb/mock/include/rdb_store_impl.h b/frameworks/native/rdb/mock/include/rdb_store_impl.h (rejected hunks) +@@ -38,8 +38,8 @@ public: + ~RdbStoreImpl() override; + const RdbStoreConfig &GetConfig(); + int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &values) override; +- int BatchInsert( +- int64_t& outInsertNum, const std::string& table, const std::vector& values) override; ++ int BatchInsert(int64_t& outInsertNum, const std::string& table, const std::vector& values) override; ++ std::pair BatchInsert(const std::string& table, const ValuesBuckets& values) override; + int Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) override; + int InsertWithConflictResolution(int64_t &outRowId, const std::string &table, const ValuesBucket &values, + ConflictResolution conflictResolution) override; +@@ -108,6 +108,8 @@ public: + + private: + using ExecuteSqls = std::vector>>>; ++ using ExecuteSqlsRef = ++ std::vector>>>>; + using Stmt = std::shared_ptr; + using RdbParam = DistributedRdb::RdbSyncerParam; + +@@ -120,6 +122,7 @@ private: + int CheckAttach(const std::string &sql); + std::pair BeginExecuteSql(const std::string &sql); + ExecuteSqls GenerateSql(const std::string& table, const std::vector& buckets, int limit); ++ ExecuteSqlsRef GenerateSql(const std::string& table, const ValuesBuckets& buckets, int limit); + int GetDataBasePath(const std::string &databasePath, std::string &backupFilePath); + int ExecuteSqlInner(const std::string &sql, const std::vector &bindArgs); + void SetAssetStatus(const ValueObject &val, int32_t status); +@@ -136,7 +139,8 @@ private: + int UpdateWithConflictResolutionEntry(int &changedRows, const std::string &table, const ValuesBucket &values, + const std::string &whereClause, const std::vector &bindArgs, + ConflictResolution conflictResolution); +- int BatchInsertEntry(int64_t& outInsertNum, const std::string& table, const std::vector& values); ++ template ++ int BatchInsertEntry(const std::string& table, const T& values, size_t rowSize, int64_t& outInsertNum); + int ExecuteSqlEntry(const std::string& sql, const std::vector& bindArgs); + std::pair ExecuteEntry(const std::string& sql, const std::vector& bindArgs, + int64_t trxId); diff --git a/frameworks/native/rdb/src/big_integer.cpp b/frameworks/native/rdb/src/big_integer.cpp index 89f388e4c..f200f5cfd 100644 --- a/frameworks/native/rdb/src/big_integer.cpp +++ b/frameworks/native/rdb/src/big_integer.cpp @@ -69,6 +69,11 @@ bool BigInteger::operator==(const BigInteger& other) return value_ == other.value_; } +bool BigInteger::operator<(const BigInteger &rhs) +{ + return value_ < rhs.value_; +} + int32_t BigInteger::Sign() const { return sign_; @@ -88,4 +93,4 @@ std::vector BigInteger::Value() const { return value_; } -} \ No newline at end of file +} diff --git a/frameworks/native/rdb/src/big_integer.cpp.rej b/frameworks/native/rdb/src/big_integer.cpp.rej new file mode 100644 index 000000000..b93ed16c4 --- /dev/null +++ b/frameworks/native/rdb/src/big_integer.cpp.rej @@ -0,0 +1,20 @@ +diff a/frameworks/native/rdb/src/big_integer.cpp b/frameworks/native/rdb/src/big_integer.cpp (rejected hunks) +@@ -69,6 +69,11 @@ bool BigInteger::operator==(const BigInteger& other) + return value_ == other.value_; + } + ++bool BigInteger::operator<(const BigInteger &rhs) ++{ ++ return value_ < rhs.value_; ++} ++ + int32_t BigInteger::Sign() const + { + return sign_; +@@ -88,4 +93,4 @@ std::vector BigInteger::Value() const + { + return value_; + } +-} +\ No newline at end of file ++} diff --git a/frameworks/native/rdb/src/rd_statement.cpp b/frameworks/native/rdb/src/rd_statement.cpp index f15baba6e..6b0efb56b 100644 --- a/frameworks/native/rdb/src/rd_statement.cpp +++ b/frameworks/native/rdb/src/rd_statement.cpp @@ -116,7 +116,7 @@ int RdStatement::Prepare(GRD_DB *db, const std::string &newSql) (!EndWithNull(newSql, curIdx) && !TryEatSymbol(newSql, ';', curIdx))) { return E_INCORRECT_SQL; } - + readOnly_ = false; sql_ = newSql; return setPragmas_["user_version"](version); @@ -245,24 +245,33 @@ int32_t RdStatement::Prepare(const std::string& sql) } int32_t RdStatement::Bind(const std::vector& args) +{ + std::vector> refArgs; + for (auto &object : args) { + refArgs.emplace_back(std::ref(const_cast(object))); + } + return Bind(refArgs); +} + +int32_t RdStatement::Bind(const std::vector>& args) { uint32_t index = 1; int ret = E_OK; for (auto &arg : args) { - switch (arg.GetType()) { + switch (arg.get().GetType()) { case ValueObjectType::TYPE_NULL: { ret = RdUtils::RdSqlBindNull(stmtHandle_, index); break; } case ValueObjectType::TYPE_INT: { int64_t value = 0; - arg.GetLong(value); + arg.get().GetLong(value); ret = RdUtils::RdSqlBindInt64(stmtHandle_, index, value); break; } case ValueObjectType::TYPE_DOUBLE: { double doubleVal = 0; - arg.GetDouble(doubleVal); + arg.get().GetDouble(doubleVal); ret = RdUtils::RdSqlBindDouble(stmtHandle_, index, doubleVal); break; } @@ -313,6 +322,15 @@ int32_t RdStatement::Reset() } int32_t RdStatement::Execute(const std::vector& args) +{ + std::vector> refArgs; + for (auto &object : args) { + refArgs.emplace_back(std::ref(const_cast(object))); + } + return Execute(refArgs); +} + +int32_t RdStatement::Execute(const std::vector>& args) { if (!readOnly_ && strcmp(sql_.c_str(), GlobalExpr::PRAGMA_VERSION) == 0) { // It has already set version in prepare procedure diff --git a/frameworks/native/rdb/src/rd_statement.cpp.rej b/frameworks/native/rdb/src/rd_statement.cpp.rej new file mode 100644 index 000000000..6321b1aa3 --- /dev/null +++ b/frameworks/native/rdb/src/rd_statement.cpp.rej @@ -0,0 +1,63 @@ +diff a/frameworks/native/rdb/src/rd_statement.cpp b/frameworks/native/rdb/src/rd_statement.cpp (rejected hunks) +@@ -116,7 +116,7 @@ int RdStatement::Prepare(GRD_DB *db, const std::string &newSql) + (!EndWithNull(newSql, curIdx) && !TryEatSymbol(newSql, ';', curIdx))) { + return E_INCORRECT_SQL; + } +- ++ + readOnly_ = false; + sql_ = newSql; + return setPragmas_["user_version"](version); +@@ -245,24 +245,33 @@ int32_t RdStatement::Prepare(const std::string& sql) + } + + int32_t RdStatement::Bind(const std::vector& args) ++{ ++ std::vector> refArgs; ++ for (auto &object : args) { ++ refArgs.emplace_back(std::ref(const_cast(object))); ++ } ++ return Bind(refArgs); ++} ++ ++int32_t RdStatement::Bind(const std::vector>& args) + { + uint32_t index = 1; + int ret = E_OK; + for (auto &arg : args) { +- switch (arg.GetType()) { ++ switch (arg.get().GetType()) { + case ValueObjectType::TYPE_NULL: { + ret = RdUtils::RdSqlBindNull(stmtHandle_, index); + break; + } + case ValueObjectType::TYPE_INT: { + int64_t value = 0; +- arg.GetLong(value); ++ arg.get().GetLong(value); + ret = RdUtils::RdSqlBindInt64(stmtHandle_, index, value); + break; + } + case ValueObjectType::TYPE_DOUBLE: { + double doubleVal = 0; +- arg.GetDouble(doubleVal); ++ arg.get().GetDouble(doubleVal); + ret = RdUtils::RdSqlBindDouble(stmtHandle_, index, doubleVal); + break; + } +@@ -313,6 +322,15 @@ int32_t RdStatement::Reset() + } + + int32_t RdStatement::Execute(const std::vector& args) ++{ ++ std::vector> refArgs; ++ for (auto &object : args) { ++ refArgs.emplace_back(std::ref(const_cast(object))); ++ } ++ return Execute(refArgs); ++} ++ ++int32_t RdStatement::Execute(const std::vector>& args) + { + if (!readOnly_ && strcmp(sql_.c_str(), GlobalExpr::PRAGMA_VERSION) == 0) { + // It has already set version in prepare procedure diff --git a/frameworks/native/rdb/src/rdb_store_impl.cpp b/frameworks/native/rdb/src/rdb_store_impl.cpp index d7e8b27e9..374ae482f 100644 --- a/frameworks/native/rdb/src/rdb_store_impl.cpp +++ b/frameworks/native/rdb/src/rdb_store_impl.cpp @@ -42,6 +42,7 @@ #include "sqlite_statement.h" #include "sqlite_utils.h" #include "step_result_set.h" +#include "values_buckets.h" #include "task_executor.h" #include "traits.h" @@ -354,16 +355,24 @@ int RdbStoreImpl::Insert(int64_t &outRowId, const std::string &table, const Valu int RdbStoreImpl::BatchInsert(int64_t &outInsertNum, const std::string &table, const std::vector &values) { SqlStatistic sqlStatistic("", SqlStatistic::Step::STEP_TOTAL); - return BatchInsertEntry(outInsertNum, table, values); + return BatchInsertEntry(table, values, values.size(), outInsertNum); } -int RdbStoreImpl::BatchInsertEntry(int64_t &outInsertNum, const std::string &table, - const std::vector &values) +std::pair RdbStoreImpl::BatchInsert(const std::string &table, const ValuesBuckets &values) +{ + SqlStatistic sqlStatistic("", SqlStatistic::Step::STEP_TOTAL); + int64_t rowSize = 0; + auto ret = BatchInsertEntry(table, values, values.RowSize(), rowSize); + return { ret, rowSize }; +} + +template +int RdbStoreImpl::BatchInsertEntry(const std::string &table, const T &values, size_t rowSize, int64_t &outInsertNum) { if (isReadOnly_ || (config_.GetDBType() == DB_VECTOR)) { return E_NOT_SUPPORT; } - if (values.empty()) { + if (rowSize == 0) { outInsertNum = 0; return E_OK; } @@ -374,7 +383,7 @@ int RdbStoreImpl::BatchInsertEntry(int64_t &outInsertNum, const std::string &tab auto executeSqlArgs = GenerateSql(table, values, connection->GetMaxVariable()); if (executeSqlArgs.empty()) { LOG_ERROR("empty, table=%{public}s, values:%{public}zu, max number:%{public}d.", table.c_str(), - values.size(), connection->GetMaxVariable()); + rowSize, connection->GetMaxVariable()); return E_INVALID_ARGS; } #if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) @@ -396,7 +405,7 @@ int RdbStoreImpl::BatchInsertEntry(int64_t &outInsertNum, const std::string &tab } } connection = nullptr; - outInsertNum = static_cast(values.size()); + outInsertNum = static_cast(rowSize); DoCloudSync(table); return E_OK; } @@ -442,7 +451,37 @@ RdbStoreImpl::ExecuteSqls RdbStoreImpl::GenerateSql(const std::string& table, co } sql.pop_back(); sql.append(") VALUES "); - return SqliteSqlBuilder::MakeExecuteSqls(sql, std::move(args), fields.size(), limit); + return SqliteSqlBuilder::MakeExecuteSqls(sql, args, fields.size(), limit); +} + +RdbStoreImpl::ExecuteSqlsRef RdbStoreImpl::GenerateSql( + const std::string& table, const ValuesBuckets& buckets, int limit) +{ + auto [fields, values] = buckets.GetFieldsAndValues(); + auto columnSize = fields->size(); + auto rowSize = buckets.RowSize(); + LOG_INFO("columnSize=%{public}zu, rowSize=%{public}zu", columnSize, rowSize); + + ValueObject object; + std::reference_wrapper emptyRef(object); + std::vector> args(columnSize * rowSize, emptyRef); + std::string sql = "INSERT OR REPLACE INTO " + table + " ("; + size_t columnIndex = 0; + for (auto &field : *fields) { + for (size_t row = 0; row < rowSize; ++row) { + auto [errorCode, value] = buckets.Get(row, std::ref(field)); + if (errorCode != E_OK) { + LOG_ERROR("not found %{public}s in row=%{public}zu", field.c_str(), row); + return ExecuteSqlsRef(); + } + args[columnIndex + row * columnSize] = value; + } + columnIndex++; + sql.append(field).append(","); + } + sql.pop_back(); + sql.append(") VALUES "); + return SqliteSqlBuilder::MakeExecuteSqls(sql, args, columnSize, limit); } int RdbStoreImpl::Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &values) diff --git a/frameworks/native/rdb/src/rdb_store_impl.cpp.rej b/frameworks/native/rdb/src/rdb_store_impl.cpp.rej new file mode 100644 index 000000000..662644c2b --- /dev/null +++ b/frameworks/native/rdb/src/rdb_store_impl.cpp.rej @@ -0,0 +1,104 @@ +diff a/frameworks/native/rdb/src/rdb_store_impl.cpp b/frameworks/native/rdb/src/rdb_store_impl.cpp (rejected hunks) +@@ -42,6 +42,7 @@ + #include "sqlite_statement.h" + #include "sqlite_utils.h" + #include "step_result_set.h" ++#include "values_buckets.h" + #include "task_executor.h" + #include "traits.h" + +@@ -353,16 +354,24 @@ int RdbStoreImpl::Insert(int64_t &outRowId, const std::string &table, const Valu + int RdbStoreImpl::BatchInsert(int64_t &outInsertNum, const std::string &table, const std::vector &values) + { + SqlStatistic sqlStatistic("", SqlStatistic::Step::STEP_TOTAL); +- return BatchInsertEntry(outInsertNum, table, values); ++ return BatchInsertEntry(table, values, values.size(), outInsertNum); + } + +-int RdbStoreImpl::BatchInsertEntry(int64_t &outInsertNum, const std::string &table, +- const std::vector &values) ++std::pair RdbStoreImpl::BatchInsert(const std::string &table, const ValuesBuckets &values) ++{ ++ SqlStatistic sqlStatistic("", SqlStatistic::Step::STEP_TOTAL); ++ int64_t rowSize = 0; ++ auto ret = BatchInsertEntry(table, values, values.RowSize(), rowSize); ++ return { ret, rowSize }; ++} ++ ++template ++int RdbStoreImpl::BatchInsertEntry(const std::string &table, const T &values, size_t rowSize, int64_t &outInsertNum) + { + if (isReadOnly_ || (config_.GetDBType() == DB_VECTOR)) { + return E_NOT_SUPPORT; + } +- if (values.empty()) { ++ if (rowSize == 0) { + outInsertNum = 0; + return E_OK; + } +@@ -373,7 +382,7 @@ int RdbStoreImpl::BatchInsertEntry(int64_t &outInsertNum, const std::string &tab + auto executeSqlArgs = GenerateSql(table, values, connection->GetMaxVariable()); + if (executeSqlArgs.empty()) { + LOG_ERROR("empty, table=%{public}s, values:%{public}zu, max number:%{public}d.", table.c_str(), +- values.size(), connection->GetMaxVariable()); ++ rowSize, connection->GetMaxVariable()); + return E_INVALID_ARGS; + } + #if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) +@@ -395,7 +404,7 @@ int RdbStoreImpl::BatchInsertEntry(int64_t &outInsertNum, const std::string &tab + } + } + connection = nullptr; +- outInsertNum = static_cast(values.size()); ++ outInsertNum = static_cast(rowSize); + DoCloudSync(table); + return E_OK; + } +@@ -441,7 +450,37 @@ RdbStoreImpl::ExecuteSqls RdbStoreImpl::GenerateSql(const std::string& table, co + } + sql.pop_back(); + sql.append(") VALUES "); +- return SqliteSqlBuilder::MakeExecuteSqls(sql, std::move(args), fields.size(), limit); ++ return SqliteSqlBuilder::MakeExecuteSqls(sql, args, fields.size(), limit); ++} ++ ++RdbStoreImpl::ExecuteSqlsRef RdbStoreImpl::GenerateSql( ++ const std::string& table, const ValuesBuckets& buckets, int limit) ++{ ++ auto [fields, values] = buckets.GetFieldsAndValues(); ++ auto columnSize = fields->size(); ++ auto rowSize = buckets.RowSize(); ++ LOG_INFO("columnSize=%{public}zu, rowSize=%{public}zu", columnSize, rowSize); ++ ++ ValueObject object; ++ std::reference_wrapper emptyRef(object); ++ std::vector> args(columnSize * rowSize, emptyRef); ++ std::string sql = "INSERT OR REPLACE INTO " + table + " ("; ++ size_t columnIndex = 0; ++ for (auto &field : *fields) { ++ for (size_t row = 0; row < rowSize; ++row) { ++ auto [errorCode, value] = buckets.Get(row, std::ref(field)); ++ if (errorCode != E_OK) { ++ LOG_ERROR("not found %{public}s in row=%{public}zu", field.c_str(), row); ++ return ExecuteSqlsRef(); ++ } ++ args[columnIndex + row * columnSize] = value; ++ } ++ columnIndex++; ++ sql.append(field).append(","); ++ } ++ sql.pop_back(); ++ sql.append(") VALUES "); ++ return SqliteSqlBuilder::MakeExecuteSqls(sql, args, columnSize, limit); + } + + int RdbStoreImpl::Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &values) +@@ -1748,7 +1787,7 @@ int RdbStoreImpl::GetDestPath(const std::string &backupPath, std::string &destPa + return E_ERROR; + } + } +- ++ + if (access(destPath.c_str(), F_OK) != E_OK) { + LOG_ERROR("The backupFilePath does not exists."); + return E_INVALID_FILE_PATH; diff --git a/frameworks/native/rdb/src/sqlite_sql_builder.cpp b/frameworks/native/rdb/src/sqlite_sql_builder.cpp index f48071820..8e7c02be7 100644 --- a/frameworks/native/rdb/src/sqlite_sql_builder.cpp +++ b/frameworks/native/rdb/src/sqlite_sql_builder.cpp @@ -321,14 +321,14 @@ SqliteSqlBuilder::ExecuteSqls SqliteSqlBuilder::MakeExecuteSqls( return sqlStr; }; std::string executeSql; - ExecuteSqls executeSqls; + std::vector>>> executeSqls; auto start = args.begin(); if (executeTimes != 0) { executeSql = appendAgsSql(maxRowNumbersOneTimes); - std::vector> sqlArgs; + std::vector> sqlArgs; size_t maxVariableNumbers = maxRowNumbersOneTimes * static_cast(fieldSize); for (size_t i = 0; i < executeTimes; ++i) { - std::vector bindValueArgs(start, start + maxVariableNumbers); + std::vector bindValueArgs(start, start + maxVariableNumbers); sqlArgs.emplace_back(std::move(bindValueArgs)); start += maxVariableNumbers; } diff --git a/frameworks/native/rdb/src/sqlite_sql_builder.cpp.rej b/frameworks/native/rdb/src/sqlite_sql_builder.cpp.rej new file mode 100644 index 000000000..1149e79be --- /dev/null +++ b/frameworks/native/rdb/src/sqlite_sql_builder.cpp.rej @@ -0,0 +1,64 @@ +diff a/frameworks/native/rdb/src/sqlite_sql_builder.cpp b/frameworks/native/rdb/src/sqlite_sql_builder.cpp (rejected hunks) +@@ -334,22 +334,20 @@ std::string SqliteSqlBuilder::GetSqlArgs(size_t size) + return args; + } + +-SqliteSqlBuilder::ExecuteSqls SqliteSqlBuilder::MakeExecuteSqls( +- const std::string &sql, std::vector &&args, int fieldSize, int limit) ++template ++std::vector>>> SqliteSqlBuilder::MakeExecuteSqls( ++ const std::string &sql, const std::vector &args, int fieldSize, int limit) + { + if (fieldSize == 0) { +- return ExecuteSqls(); ++ return {}; + } + size_t rowNumbers = args.size() / static_cast(fieldSize); + size_t maxRowNumbersOneTimes = static_cast(limit / fieldSize); + if (maxRowNumbersOneTimes == 0) { +- return ExecuteSqls(); ++ return {}; + } + size_t executeTimes = rowNumbers / maxRowNumbersOneTimes; + size_t remainingRows = rowNumbers % maxRowNumbersOneTimes; +- LOG_DEBUG("rowNumbers %{public}zu, maxRowNumbersOneTimes %{public}zu, executeTimes %{public}zu," +- "remainingRows %{public}zu, fieldSize %{public}d, limit %{public}d", +- rowNumbers, maxRowNumbersOneTimes, executeTimes, remainingRows, fieldSize, limit); + std::string singleRowSqlArgs = "(" + SqliteSqlBuilder::GetSqlArgs(fieldSize) + ")"; + auto appendAgsSql = [&singleRowSqlArgs, &sql] (size_t rowNumber) { + std::string sqlStr = sql; +@@ -360,14 +358,14 @@ SqliteSqlBuilder::ExecuteSqls SqliteSqlBuilder::MakeExecuteSqls( + return sqlStr; + }; + std::string executeSql; +- ExecuteSqls executeSqls; ++ std::vector>>> executeSqls; + auto start = args.begin(); + if (executeTimes != 0) { + executeSql = appendAgsSql(maxRowNumbersOneTimes); +- std::vector> sqlArgs; ++ std::vector> sqlArgs; + size_t maxVariableNumbers = maxRowNumbersOneTimes * static_cast(fieldSize); + for (size_t i = 0; i < executeTimes; ++i) { +- std::vector bindValueArgs(start, start + maxVariableNumbers); ++ std::vector bindValueArgs(start, start + maxVariableNumbers); + sqlArgs.emplace_back(std::move(bindValueArgs)); + start += maxVariableNumbers; + } +@@ -376,10 +374,15 @@ SqliteSqlBuilder::ExecuteSqls SqliteSqlBuilder::MakeExecuteSqls( + + if (remainingRows != 0) { + executeSql = appendAgsSql(remainingRows); +- std::vector> sqlArgs(1, std::vector(start, args.end())); ++ std::vector> sqlArgs(1, std::vector(start, args.end())); + executeSqls.emplace_back(std::make_pair(executeSql, std::move(sqlArgs))); + } + return executeSqls; + } ++ ++template SqliteSqlBuilder::ExecuteSqls SqliteSqlBuilder::MakeExecuteSqls( ++ const std::string &sql, const std::vector &args, int fieldSize, int limit); ++template SqliteSqlBuilder::ExecuteSqlsRef SqliteSqlBuilder::MakeExecuteSqls( ++ const std::string &sql, const std::vector> &args, int fieldSize, int limit); + } // namespace NativeRdb + } // namespace OHOS diff --git a/frameworks/native/rdb/src/sqlite_statement.cpp b/frameworks/native/rdb/src/sqlite_statement.cpp index 8bab59ec1..78e64f662 100644 --- a/frameworks/native/rdb/src/sqlite_statement.cpp +++ b/frameworks/native/rdb/src/sqlite_statement.cpp @@ -138,6 +138,15 @@ void SqliteStatement::ReadFile2Buffer() } int SqliteStatement::BindArgs(const std::vector &bindArgs) +{ + std::vector> refBindArgs; + for (auto &object : bindArgs) { + refBindArgs.emplace_back(std::ref(const_cast(object))); + } + return BindArgs(refBindArgs); +} + +int SqliteStatement::BindArgs(const std::vector> &bindArgs) { SqlStatistic sqlStatistic("", SqlStatistic::Step::STEP_PREPARE, seqId_); if (bound_) { @@ -147,12 +156,12 @@ int SqliteStatement::BindArgs(const std::vector &bindArgs) bound_ = true; int index = 1; for (auto &arg : bindArgs) { - auto action = ACTIONS[arg.value.index()]; + auto action = ACTIONS[arg.get().value.index()]; if (action == nullptr) { - LOG_ERROR("not support the type %{public}zu", arg.value.index()); + LOG_ERROR("not support the type %{public}zu", arg.get().value.index()); return E_INVALID_ARGS; } - auto errCode = action(stmt_, index, arg.value); + auto errCode = action(stmt_, index, arg.get().value); if (errCode != SQLITE_OK) { LOG_ERROR("Bind has error: %{public}d, sql: %{public}s, errno %{public}d", errCode, sql_.c_str(), errno); return SQLiteError::ErrNo(errCode); @@ -327,6 +336,15 @@ int SqliteStatement::Finalize() } int SqliteStatement::Execute(const std::vector &args) +{ + std::vector> refArgs; + for (auto &object : args) { + refArgs.emplace_back(std::ref(const_cast(object))); + } + return Execute(refArgs); +} + +int32_t SqliteStatement::Execute(const std::vector> &args) { int count = static_cast(args.size()); if (count != numParameters_) { diff --git a/frameworks/native/rdb/src/sqlite_statement.cpp.rej b/frameworks/native/rdb/src/sqlite_statement.cpp.rej new file mode 100644 index 000000000..aad90abaf --- /dev/null +++ b/frameworks/native/rdb/src/sqlite_statement.cpp.rej @@ -0,0 +1,49 @@ +diff a/frameworks/native/rdb/src/sqlite_statement.cpp b/frameworks/native/rdb/src/sqlite_statement.cpp (rejected hunks) +@@ -137,6 +137,15 @@ void SqliteStatement::ReadFile2Buffer() + } + + int SqliteStatement::BindArgs(const std::vector &bindArgs) ++{ ++ std::vector> refBindArgs; ++ for (auto &object : bindArgs) { ++ refBindArgs.emplace_back(std::ref(const_cast(object))); ++ } ++ return BindArgs(refBindArgs); ++} ++ ++int SqliteStatement::BindArgs(const std::vector> &bindArgs) + { + SqlStatistic sqlStatistic("", SqlStatistic::Step::STEP_PREPARE, seqId_); + if (bound_) { +@@ -146,12 +155,12 @@ int SqliteStatement::BindArgs(const std::vector &bindArgs) + bound_ = true; + int index = 1; + for (auto &arg : bindArgs) { +- auto action = ACTIONS[arg.value.index()]; ++ auto action = ACTIONS[arg.get().value.index()]; + if (action == nullptr) { +- LOG_ERROR("not support the type %{public}zu", arg.value.index()); ++ LOG_ERROR("not support the type %{public}zu", arg.get().value.index()); + return E_INVALID_ARGS; + } +- auto errCode = action(stmt_, index, arg.value); ++ auto errCode = action(stmt_, index, arg.get().value); + if (errCode != SQLITE_OK) { + LOG_ERROR("Bind has error: %{public}d, sql: %{public}s, errno %{public}d", errCode, sql_.c_str(), errno); + return SQLiteError::ErrNo(errCode); +@@ -325,6 +334,15 @@ int SqliteStatement::Finalize() + } + + int SqliteStatement::Execute(const std::vector &args) ++{ ++ std::vector> refArgs; ++ for (auto &object : args) { ++ refArgs.emplace_back(std::ref(const_cast(object))); ++ } ++ return Execute(refArgs); ++} ++ ++int32_t SqliteStatement::Execute(const std::vector> &args) + { + int count = static_cast(args.size()); + if (count != numParameters_) { diff --git a/frameworks/native/rdb/src/value_object.cpp b/frameworks/native/rdb/src/value_object.cpp index c950e6f40..5efa25f34 100644 --- a/frameworks/native/rdb/src/value_object.cpp +++ b/frameworks/native/rdb/src/value_object.cpp @@ -341,5 +341,40 @@ int ValueObject::Get(T &output) const output = static_cast(*v); return E_OK; } + +bool ValueObject::operator<(const ValueObject &rhs) const +{ + if (GetType() != rhs.GetType()) { + return GetType() < rhs.GetType(); + } + + bool result = true; + switch (GetType()) { + case TYPE_INT: + result = int64_t(*this) < int64_t(rhs); + break; + case TYPE_DOUBLE: + result = double(*this) < double(rhs); + break; + case TYPE_STRING: + result = std::string(*this) < std::string(rhs); + break; + case TYPE_BOOL: + result = bool(*this) < bool(rhs); + break; + case TYPE_BLOB: + result = Blob(*this) < Blob(rhs); + break; + case TYPE_VECS: + result = FloatVector(*this) < FloatVector(rhs); + break; + case TYPE_BIGINT: + result = BigInt(*this) < BigInt(rhs); + break; + default: + break; + } + return result; +} } // namespace NativeRdb } // namespace OHOS diff --git a/frameworks/native/rdb/src/value_object.cpp.rej b/frameworks/native/rdb/src/value_object.cpp.rej new file mode 100644 index 000000000..b9e094407 --- /dev/null +++ b/frameworks/native/rdb/src/value_object.cpp.rej @@ -0,0 +1,42 @@ +diff a/frameworks/native/rdb/src/value_object.cpp b/frameworks/native/rdb/src/value_object.cpp (rejected hunks) +@@ -341,5 +341,40 @@ int ValueObject::Get(T &output) const + output = static_cast(*v); + return E_OK; + } ++ ++bool ValueObject::operator<(const ValueObject &rhs) const ++{ ++ if (GetType() != rhs.GetType()) { ++ return GetType() < rhs.GetType(); ++ } ++ ++ bool result = true; ++ switch (GetType()) { ++ case TYPE_INT: ++ result = int64_t(*this) < int64_t(rhs); ++ break; ++ case TYPE_DOUBLE: ++ result = double(*this) < double(rhs); ++ break; ++ case TYPE_STRING: ++ result = std::string(*this) < std::string(rhs); ++ break; ++ case TYPE_BOOL: ++ result = bool(*this) < bool(rhs); ++ break; ++ case TYPE_BLOB: ++ result = Blob(*this) < Blob(rhs); ++ break; ++ case TYPE_VECS: ++ result = FloatVector(*this) < FloatVector(rhs); ++ break; ++ case TYPE_BIGINT: ++ result = BigInt(*this) < BigInt(rhs); ++ break; ++ default: ++ break; ++ } ++ return result; ++} + } // namespace NativeRdb + } // namespace OHOS diff --git a/frameworks/native/rdb/src/values_buckets.cpp b/frameworks/native/rdb/src/values_buckets.cpp new file mode 100644 index 000000000..540a6c373 --- /dev/null +++ b/frameworks/native/rdb/src/values_buckets.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "values_buckets.h" +#include "rdb_errno.h" + +namespace OHOS { +namespace NativeRdb { +ValuesBuckets::ValuesBuckets() +{ + fields_ = std::make_shared>(); + values_ = std::make_shared>(); +} + +size_t ValuesBuckets::RowSize() const +{ + return buckets_.size(); +} + +std::pair ValuesBuckets::GetFieldsAndValues() const +{ + return { fields_, values_ }; +} + +void ValuesBuckets::Put(const ValuesBucket &bucket) +{ + BucketType row; + for (const auto &[field, value] : bucket.values_) { + auto fieldResult = fields_->insert(field); + auto valueResult = values_->insert(value); + row.insert(std::make_pair(std::ref(const_cast(*fieldResult.first)), + std::ref(const_cast(*valueResult.first)))); + } + buckets_.push_back(std::move(row)); +} + +std::pair ValuesBuckets::Get(size_t row, const FieldType &field) const +{ + ValueObject emptyObject; + ValueType emptyRef(emptyObject); + + if (row >= buckets_.size()) { + return { E_INVALID_ARGS, emptyRef }; + } + + auto &bucket = buckets_[row]; + auto it = bucket.find(field); + if (it == bucket.end()) { + return { E_INVALID_ARGS, emptyRef }; + } + + return { E_OK, it->second }; +} +} +} diff --git a/interfaces/inner_api/rdb/BUILD.gn b/interfaces/inner_api/rdb/BUILD.gn index 63e0aad49..1b28593b3 100644 --- a/interfaces/inner_api/rdb/BUILD.gn +++ b/interfaces/inner_api/rdb/BUILD.gn @@ -41,6 +41,7 @@ base_sources = [ "${relational_store_native_path}/rdb/src/string_utils.cpp", "${relational_store_native_path}/rdb/src/value_object.cpp", "${relational_store_native_path}/rdb/src/values_bucket.cpp", + "${relational_store_native_path}/rdb/src/values_buckets.cpp", ] if (!is_ohos) { diff --git a/interfaces/inner_api/rdb/BUILD.gn.rej b/interfaces/inner_api/rdb/BUILD.gn.rej new file mode 100644 index 000000000..419017848 --- /dev/null +++ b/interfaces/inner_api/rdb/BUILD.gn.rej @@ -0,0 +1,9 @@ +diff a/interfaces/inner_api/rdb/BUILD.gn b/interfaces/inner_api/rdb/BUILD.gn (rejected hunks) +@@ -41,6 +41,7 @@ base_sources = [ + "${relational_store_native_path}/rdb/src/string_utils.cpp", + "${relational_store_native_path}/rdb/src/value_object.cpp", + "${relational_store_native_path}/rdb/src/values_bucket.cpp", ++ "${relational_store_native_path}/rdb/src/values_buckets.cpp", + ] + + if (!is_ohos) { diff --git a/interfaces/inner_api/rdb/include/big_integer.h b/interfaces/inner_api/rdb/include/big_integer.h index 41071f31d..dc713d664 100644 --- a/interfaces/inner_api/rdb/include/big_integer.h +++ b/interfaces/inner_api/rdb/include/big_integer.h @@ -33,6 +33,7 @@ public: BigInteger &operator=(const BigInteger &other); BigInteger &operator=(BigInteger &&other); bool operator==(const BigInteger &other); + bool operator<(const BigInteger &rhs); int32_t Sign() const; size_t Size() const; diff --git a/interfaces/inner_api/rdb/include/big_integer.h.rej b/interfaces/inner_api/rdb/include/big_integer.h.rej new file mode 100644 index 000000000..e0f1be497 --- /dev/null +++ b/interfaces/inner_api/rdb/include/big_integer.h.rej @@ -0,0 +1,9 @@ +diff a/interfaces/inner_api/rdb/include/big_integer.h b/interfaces/inner_api/rdb/include/big_integer.h (rejected hunks) +@@ -33,6 +33,7 @@ public: + BigInteger &operator=(const BigInteger &other); + BigInteger &operator=(BigInteger &&other); + bool operator==(const BigInteger &other); ++ bool operator<(const BigInteger &rhs); + + int32_t Sign() const; + size_t Size() const; diff --git a/interfaces/inner_api/rdb/include/rdb_store.h b/interfaces/inner_api/rdb/include/rdb_store.h index 8f1b9c5a9..6806f08aa 100644 --- a/interfaces/inner_api/rdb/include/rdb_store.h +++ b/interfaces/inner_api/rdb/include/rdb_store.h @@ -26,6 +26,7 @@ #include "result_set.h" #include "value_object.h" #include "values_bucket.h" +#include "values_buckets.h" #include "rdb_types.h" #include "rdb_common.h" #include "rdb_errno.h" @@ -104,6 +105,17 @@ public: virtual int BatchInsert( int64_t &outInsertNum, const std::string &table, const std::vector &values) = 0; + /** + * @brief Inserts a batch of data into the target table. + * + * @param table Indicates the target table. + * @param values Indicates the rows of data {@link ValuesBuckets} to be inserted into the table. + */ + virtual std::pair BatchInsert(const std::string &table, const ValuesBuckets &values) + { + return { E_NOT_SUPPORT, 0 }; + } + /** * @brief Replaces a row of data into the target table. * diff --git a/interfaces/inner_api/rdb/include/rdb_store.h.rej b/interfaces/inner_api/rdb/include/rdb_store.h.rej new file mode 100644 index 000000000..dfdb8555e --- /dev/null +++ b/interfaces/inner_api/rdb/include/rdb_store.h.rej @@ -0,0 +1,27 @@ +diff a/interfaces/inner_api/rdb/include/rdb_store.h b/interfaces/inner_api/rdb/include/rdb_store.h (rejected hunks) +@@ -26,6 +26,7 @@ + #include "result_set.h" + #include "value_object.h" + #include "values_bucket.h" ++#include "values_buckets.h" + #include "rdb_types.h" + #include "rdb_common.h" + #include "rdb_errno.h" +@@ -104,6 +105,17 @@ public: + virtual int BatchInsert( + int64_t &outInsertNum, const std::string &table, const std::vector &values) = 0; + ++ /** ++ * @brief Inserts a batch of data into the target table. ++ * ++ * @param table Indicates the target table. ++ * @param values Indicates the rows of data {@link ValuesBuckets} to be inserted into the table. ++ */ ++ virtual std::pair BatchInsert(const std::string &table, const ValuesBuckets &values) ++ { ++ return { E_NOT_SUPPORT, 0 }; ++ } ++ + /** + * @brief Replaces a row of data into the target table. + * diff --git a/interfaces/inner_api/rdb/include/value_object.h b/interfaces/inner_api/rdb/include/value_object.h index 91d93fcff..d893a0cdf 100644 --- a/interfaces/inner_api/rdb/include/value_object.h +++ b/interfaces/inner_api/rdb/include/value_object.h @@ -230,7 +230,7 @@ public: * @param val Indicates an Assets input parameter. */ API_EXPORT ValueObject(BigInt val); - + /** * @brief Constructor. * This constructor is used to convert the FloatVector input parameter to a value of type ValueObject. @@ -379,6 +379,8 @@ public: return value; } + bool operator<(const ValueObject &rhs) const; + private: template int Get(T &output) const; diff --git a/interfaces/inner_api/rdb/include/value_object.h.rej b/interfaces/inner_api/rdb/include/value_object.h.rej new file mode 100644 index 000000000..deda12a2d --- /dev/null +++ b/interfaces/inner_api/rdb/include/value_object.h.rej @@ -0,0 +1,19 @@ +diff a/interfaces/inner_api/rdb/include/value_object.h b/interfaces/inner_api/rdb/include/value_object.h (rejected hunks) +@@ -225,7 +225,7 @@ public: + * @param val Indicates an Assets input parameter. + */ + API_EXPORT ValueObject(BigInt val); +- ++ + /** + * @brief Constructor. + * This constructor is used to convert the FloatVector input parameter to a value of type ValueObject. +@@ -374,6 +374,8 @@ public: + return value; + } + ++ bool operator<(const ValueObject &rhs) const; ++ + private: + template + int Get(T &output) const; diff --git a/interfaces/inner_api/rdb/include/values_buckets.h b/interfaces/inner_api/rdb/include/values_buckets.h new file mode 100644 index 000000000..5f99d6db7 --- /dev/null +++ b/interfaces/inner_api/rdb/include/values_buckets.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NATIVE_RDB_VALUES_BUCKETS_H +#define NATIVE_RDB_VALUES_BUCKETS_H + +#include +#include +#include + +#include "value_object.h" +#include "values_bucket.h" + +namespace OHOS { +namespace NativeRdb { +class API_EXPORT ValuesBuckets { +public: + using FieldsType = std::shared_ptr>; + using ValuesType = std::shared_ptr>; + using FieldType = std::reference_wrapper; + using ValueType = std::reference_wrapper; + using BucketType = std::map>; + + API_EXPORT ValuesBuckets(); + + API_EXPORT size_t RowSize() const; + API_EXPORT std::pair GetFieldsAndValues() const; + + API_EXPORT void Put(const ValuesBucket &bucket); + API_EXPORT std::pair Get(size_t row, const FieldType &field) const; + +private: + FieldsType fields_; + ValuesType values_; + std::vector buckets_; +}; + +} // namespace NativeRdb +} // namespace OHOS +#endif diff --git a/interfaces/inner_api/rdb/mock/include/big_integer.h b/interfaces/inner_api/rdb/mock/include/big_integer.h index fd97853b1..193901ca0 100644 --- a/interfaces/inner_api/rdb/mock/include/big_integer.h +++ b/interfaces/inner_api/rdb/mock/include/big_integer.h @@ -32,6 +32,7 @@ public: BigInteger &operator=(const BigInteger &other); BigInteger &operator=(BigInteger &&other); bool operator==(const BigInteger &other); + bool operator<(const BigInteger &rhs); int32_t Sign() const; size_t Size() const; diff --git a/interfaces/inner_api/rdb/mock/include/big_integer.h.rej b/interfaces/inner_api/rdb/mock/include/big_integer.h.rej new file mode 100644 index 000000000..de2d77003 --- /dev/null +++ b/interfaces/inner_api/rdb/mock/include/big_integer.h.rej @@ -0,0 +1,9 @@ +diff a/interfaces/inner_api/rdb/mock/include/big_integer.h b/interfaces/inner_api/rdb/mock/include/big_integer.h (rejected hunks) +@@ -32,6 +32,7 @@ public: + BigInteger &operator=(const BigInteger &other); + BigInteger &operator=(BigInteger &&other); + bool operator==(const BigInteger &other); ++ bool operator<(const BigInteger &rhs); + + int32_t Sign() const; + size_t Size() const; diff --git a/interfaces/inner_api/rdb/mock/include/rdb_store.h b/interfaces/inner_api/rdb/mock/include/rdb_store.h index 9b2e021c5..3fb28682a 100644 --- a/interfaces/inner_api/rdb/mock/include/rdb_store.h +++ b/interfaces/inner_api/rdb/mock/include/rdb_store.h @@ -28,6 +28,8 @@ #include "result_set.h" #include "value_object.h" #include "values_bucket.h" +#include "values_buckets.h" + namespace OHOS::NativeRdb { class RdbStore { public: @@ -39,6 +41,10 @@ public: virtual int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &values) = 0; virtual int BatchInsert(int64_t &outInsertNum, const std::string &table, const std::vector &values) = 0; + virtual std::pair BatchInsert(const std::string &table, const ValuesBuckets &values) + { + return { E_NOT_SUPPORT, 0 }; + } virtual int Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &values) = 0; virtual int InsertWithConflictResolution( int64_t &outRowId, const std::string &table, const ValuesBucket &values, diff --git a/interfaces/inner_api/rdb/mock/include/rdb_store.h.rej b/interfaces/inner_api/rdb/mock/include/rdb_store.h.rej new file mode 100644 index 000000000..8243a3994 --- /dev/null +++ b/interfaces/inner_api/rdb/mock/include/rdb_store.h.rej @@ -0,0 +1,21 @@ +diff a/interfaces/inner_api/rdb/mock/include/rdb_store.h b/interfaces/inner_api/rdb/mock/include/rdb_store.h (rejected hunks) +@@ -28,6 +28,8 @@ + #include "result_set.h" + #include "value_object.h" + #include "values_bucket.h" ++#include "values_buckets.h" ++ + namespace OHOS::NativeRdb { + class RdbStore { + public: +@@ -39,6 +41,10 @@ public: + virtual int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &values) = 0; + virtual int BatchInsert(int64_t &outInsertNum, const std::string &table, + const std::vector &values) = 0; ++ virtual std::pair BatchInsert(const std::string &table, const ValuesBuckets &values) ++ { ++ return { E_NOT_SUPPORT, 0 }; ++ } + virtual int Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &values) = 0; + virtual int InsertWithConflictResolution( + int64_t &outRowId, const std::string &table, const ValuesBucket &values, diff --git a/interfaces/inner_api/rdb/mock/include/value_object.h b/interfaces/inner_api/rdb/mock/include/value_object.h index cddf8464f..348357fe3 100644 --- a/interfaces/inner_api/rdb/mock/include/value_object.h +++ b/interfaces/inner_api/rdb/mock/include/value_object.h @@ -325,6 +325,8 @@ public: return value; } + bool operator<(const ValueObject &rhs) const; + private: template int Get(T &output) const; diff --git a/interfaces/inner_api/rdb/mock/include/value_object.h.rej b/interfaces/inner_api/rdb/mock/include/value_object.h.rej new file mode 100644 index 000000000..b89a24f1f --- /dev/null +++ b/interfaces/inner_api/rdb/mock/include/value_object.h.rej @@ -0,0 +1,10 @@ +diff a/interfaces/inner_api/rdb/mock/include/value_object.h b/interfaces/inner_api/rdb/mock/include/value_object.h (rejected hunks) +@@ -325,6 +325,8 @@ public: + return value; + } + ++ bool operator<(const ValueObject &rhs) const; ++ + private: + template + int Get(T &output) const; diff --git a/interfaces/inner_api/rdb/mock/include/values_buckets.h b/interfaces/inner_api/rdb/mock/include/values_buckets.h new file mode 100644 index 000000000..ca8534b10 --- /dev/null +++ b/interfaces/inner_api/rdb/mock/include/values_buckets.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NATIVE_RDB_VALUES_BUCKETS_H +#define NATIVE_RDB_VALUES_BUCKETS_H + +#include +#include +#include + +#include "value_object.h" +#include "values_bucket.h" + +namespace OHOS { +namespace NativeRdb { +class ValuesBuckets { +public: + using FieldsType = std::shared_ptr>; + using ValuesType = std::shared_ptr>; + using FieldType = std::reference_wrapper; + using ValueType = std::reference_wrapper; + using BucketType = std::map>; + + ValuesBuckets(); + + size_t RowSize() const; + std::pair GetFieldsAndValues() const; + + void Put(const ValuesBucket &bucket); + std::pair Get(size_t row, const FieldType &field) const; + +private: + FieldsType fields_; + ValuesType values_; + std::vector buckets_; +}; +} // namespace NativeRdb +} // namespace OHOS +#endif