mirror of
https://gitee.com/openharmony/distributeddatamgr_relational_store
synced 2024-11-27 01:01:02 +00:00
BatchInsert
Signed-off-by: zhangdi <zhangdi126@huawei.com>
This commit is contained in:
parent
854db108fc
commit
8ee8845170
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "napi_async_call.h"
|
#include "napi_async_call.h"
|
||||||
#include "napi_rdb_predicates.h"
|
#include "napi_rdb_predicates.h"
|
||||||
|
#include "values_buckets.h"
|
||||||
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace RelationalStoreJsKit {
|
namespace RelationalStoreJsKit {
|
||||||
@ -37,6 +38,7 @@ struct RdbStoreContext : public RdbStoreContextBase {
|
|||||||
std::vector<std::string> columns;
|
std::vector<std::string> columns;
|
||||||
ValuesBucket valuesBucket;
|
ValuesBucket valuesBucket;
|
||||||
std::vector<ValuesBucket> valuesBuckets;
|
std::vector<ValuesBucket> valuesBuckets;
|
||||||
|
ValuesBuckets sharedValuesBuckets;
|
||||||
std::map<std::string, ValueObject> numberMaps;
|
std::map<std::string, ValueObject> numberMaps;
|
||||||
std::vector<ValueObject> bindArgs;
|
std::vector<ValueObject> bindArgs;
|
||||||
int64_t int64Output;
|
int64_t int64Output;
|
||||||
@ -75,4 +77,4 @@ struct RdbStoreContext : public RdbStoreContextBase {
|
|||||||
};
|
};
|
||||||
} // namespace RelationalStoreJsKit
|
} // namespace RelationalStoreJsKit
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
#endif // NAPI_RDB_CONTEXT_H
|
#endif // NAPI_RDB_CONTEXT_H
|
||||||
|
@ -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<std::string> columns;
|
||||||
|
ValuesBucket valuesBucket;
|
||||||
|
std::vector<ValuesBucket> valuesBuckets;
|
||||||
|
+ ValuesBuckets sharedValuesBuckets;
|
||||||
|
std::map<std::string, ValueObject> numberMaps;
|
||||||
|
std::vector<ValueObject> 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
|
@ -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<InnerError>("napi_get_element failed."));
|
CHECK_RETURN_SET(status == napi_ok, std::make_shared<InnerError>("napi_get_element failed."));
|
||||||
|
|
||||||
CHECK_RETURN_ERR(ParseValuesBucket(env, obj, context) == OK);
|
CHECK_RETURN_ERR(ParseValuesBucket(env, obj, context) == OK);
|
||||||
context->valuesBuckets.push_back(std::move(context->valuesBucket));
|
context->sharedValuesBuckets.Put(context->valuesBucket);
|
||||||
context->valuesBucket.Clear();
|
context->valuesBucket.Clear();
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
@ -661,7 +661,9 @@ napi_value RdbStoreProxy::BatchInsert(napi_env env, napi_callback_info info)
|
|||||||
auto exec = [context]() -> int {
|
auto exec = [context]() -> int {
|
||||||
CHECK_RETURN_ERR(context->rdbStore != nullptr);
|
CHECK_RETURN_ERR(context->rdbStore != nullptr);
|
||||||
auto rdbStore = std::move(context->rdbStore);
|
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) {
|
auto output = [context](napi_env env, napi_value &result) {
|
||||||
napi_status status = napi_create_int64(env, context->int64Output, &result);
|
napi_status status = napi_create_int64(env, context->int64Output, &result);
|
||||||
|
@ -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<InnerError>("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);
|
@ -39,6 +39,7 @@ public:
|
|||||||
int32_t Step() override;
|
int32_t Step() override;
|
||||||
int32_t Reset() override;
|
int32_t Reset() override;
|
||||||
int32_t Execute(const std::vector<ValueObject>& args) override;
|
int32_t Execute(const std::vector<ValueObject>& args) override;
|
||||||
|
int32_t Execute(const std::vector<std::reference_wrapper<ValueObject>>& args) override;
|
||||||
std::pair<int, ValueObject> ExecuteForValue(const std::vector<ValueObject>& args) override;
|
std::pair<int, ValueObject> ExecuteForValue(const std::vector<ValueObject>& args) override;
|
||||||
int32_t Changes() const override;
|
int32_t Changes() const override;
|
||||||
int64_t LastInsertRowId() const override;
|
int64_t LastInsertRowId() const override;
|
||||||
@ -55,6 +56,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
friend class RdConnection;
|
friend class RdConnection;
|
||||||
int Prepare(GRD_DB *db, const std::string &sql);
|
int Prepare(GRD_DB *db, const std::string &sql);
|
||||||
|
int32_t Bind(const std::vector<std::reference_wrapper<ValueObject>>& args);
|
||||||
int InnerBindBlobTypeArgs(const ValueObject &bindArg, uint32_t index) const;
|
int InnerBindBlobTypeArgs(const ValueObject &bindArg, uint32_t index) const;
|
||||||
int IsValid(int index) const;
|
int IsValid(int index) const;
|
||||||
|
|
||||||
@ -73,4 +75,4 @@ private:
|
|||||||
};
|
};
|
||||||
} // namespace NativeRdb
|
} // namespace NativeRdb
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
#endif // NATIVE_RDB_RD_STATEMENT_H
|
#endif // NATIVE_RDB_RD_STATEMENT_H
|
||||||
|
24
frameworks/native/rdb/include/rd_statement.h.rej
Normal file
24
frameworks/native/rdb/include/rd_statement.h.rej
Normal file
@ -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<ValueObject>& args) override;
|
||||||
|
+ int32_t Execute(const std::vector<std::reference_wrapper<ValueObject>>& args) override;
|
||||||
|
std::pair<int, ValueObject> ExecuteForValue(const std::vector<ValueObject>& 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<std::reference_wrapper<ValueObject>>& 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
|
@ -82,6 +82,7 @@ public:
|
|||||||
const RdbStoreConfig &GetConfig();
|
const RdbStoreConfig &GetConfig();
|
||||||
int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &values) override;
|
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<ValuesBucket>& values) override;
|
int BatchInsert(int64_t& outInsertNum, const std::string& table, const std::vector<ValuesBucket>& values) override;
|
||||||
|
std::pair<int, int64_t> BatchInsert(const std::string& table, const ValuesBuckets& values) override;
|
||||||
int Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) 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,
|
int InsertWithConflictResolution(int64_t &outRowId, const std::string &table, const ValuesBucket &values,
|
||||||
ConflictResolution conflictResolution) override;
|
ConflictResolution conflictResolution) override;
|
||||||
@ -198,6 +199,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
using ExecuteSqls = std::vector<std::pair<std::string, std::vector<std::vector<ValueObject>>>>;
|
using ExecuteSqls = std::vector<std::pair<std::string, std::vector<std::vector<ValueObject>>>>;
|
||||||
|
using ExecuteSqlsRef =
|
||||||
|
std::vector<std::pair<std::string, std::vector<std::vector<std::reference_wrapper<ValueObject>>>>>;
|
||||||
using Stmt = std::shared_ptr<Statement>;
|
using Stmt = std::shared_ptr<Statement>;
|
||||||
using RdbParam = DistributedRdb::RdbSyncerParam;
|
using RdbParam = DistributedRdb::RdbSyncerParam;
|
||||||
|
|
||||||
@ -211,6 +214,7 @@ private:
|
|||||||
int CheckAttach(const std::string &sql);
|
int CheckAttach(const std::string &sql);
|
||||||
std::pair<int32_t, Stmt> BeginExecuteSql(const std::string &sql);
|
std::pair<int32_t, Stmt> BeginExecuteSql(const std::string &sql);
|
||||||
ExecuteSqls GenerateSql(const std::string& table, const std::vector<ValuesBucket>& buckets, int limit);
|
ExecuteSqls GenerateSql(const std::string& table, const std::vector<ValuesBucket>& buckets, int limit);
|
||||||
|
ExecuteSqlsRef GenerateSql(const std::string& table, const ValuesBuckets& buckets, int limit);
|
||||||
int GetDataBasePath(const std::string &databasePath, std::string &backupFilePath);
|
int GetDataBasePath(const std::string &databasePath, std::string &backupFilePath);
|
||||||
void SetAssetStatus(const ValueObject &val, int32_t status);
|
void SetAssetStatus(const ValueObject &val, int32_t status);
|
||||||
void DoCloudSync(const std::string &table);
|
void DoCloudSync(const std::string &table);
|
||||||
@ -244,7 +248,8 @@ private:
|
|||||||
int UpdateWithConflictResolutionEntry(int &changedRows, const std::string &table, const ValuesBucket &values,
|
int UpdateWithConflictResolutionEntry(int &changedRows, const std::string &table, const ValuesBucket &values,
|
||||||
const std::string &whereClause, const std::vector<ValueObject> &bindArgs,
|
const std::string &whereClause, const std::vector<ValueObject> &bindArgs,
|
||||||
ConflictResolution conflictResolution);
|
ConflictResolution conflictResolution);
|
||||||
int BatchInsertEntry(int64_t& outInsertNum, const std::string& table, const std::vector<ValuesBucket>& values);
|
template<typename T>
|
||||||
|
int BatchInsertEntry(const std::string& table, const T& values, size_t rowSize, int64_t& outInsertNum);
|
||||||
int ExecuteSqlEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs);
|
int ExecuteSqlEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs);
|
||||||
std::pair<int32_t, ValueObject> ExecuteEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs,
|
std::pair<int32_t, ValueObject> ExecuteEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs,
|
||||||
int64_t trxId);
|
int64_t trxId);
|
||||||
|
36
frameworks/native/rdb/include/rdb_store_impl.h.rej
Normal file
36
frameworks/native/rdb/include/rdb_store_impl.h.rej
Normal file
@ -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<ValuesBucket>& values) override;
|
||||||
|
+ std::pair<int, int64_t> 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<std::pair<std::string, std::vector<std::vector<ValueObject>>>>;
|
||||||
|
+ using ExecuteSqlsRef =
|
||||||
|
+ std::vector<std::pair<std::string, std::vector<std::vector<std::reference_wrapper<ValueObject>>>>>;
|
||||||
|
using Stmt = std::shared_ptr<Statement>;
|
||||||
|
using RdbParam = DistributedRdb::RdbSyncerParam;
|
||||||
|
|
||||||
|
@@ -211,6 +214,7 @@ private:
|
||||||
|
int CheckAttach(const std::string &sql);
|
||||||
|
std::pair<int32_t, Stmt> BeginExecuteSql(const std::string &sql);
|
||||||
|
ExecuteSqls GenerateSql(const std::string& table, const std::vector<ValuesBucket>& 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<ValueObject> &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<ValueObject> &bindArgs,
|
||||||
|
ConflictResolution conflictResolution);
|
||||||
|
- int BatchInsertEntry(int64_t& outInsertNum, const std::string& table, const std::vector<ValuesBucket>& values);
|
||||||
|
+ template<typename T>
|
||||||
|
+ int BatchInsertEntry(const std::string& table, const T& values, size_t rowSize, int64_t& outInsertNum);
|
||||||
|
int ExecuteSqlEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs);
|
||||||
|
std::pair<int32_t, ValueObject> ExecuteEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs,
|
||||||
|
int64_t trxId);
|
@ -48,8 +48,9 @@ public:
|
|||||||
const AbsRdbPredicates &predicates, const std::vector<std::string> &columns, const std::string &logTable);
|
const AbsRdbPredicates &predicates, const std::vector<std::string> &columns, const std::string &logTable);
|
||||||
static std::string GetSqlArgs(size_t size);
|
static std::string GetSqlArgs(size_t size);
|
||||||
|
|
||||||
static ExecuteSqls MakeExecuteSqls(
|
template<typename T>
|
||||||
const std::string &sql, std::vector<ValueObject> &&args, int fieldSize, int limit);
|
static std::vector<std::pair<std::string, std::vector<std::vector<T>>>> MakeExecuteSqls(
|
||||||
|
const std::string &sql, const std::vector<T> &args, int fieldSize, int limit);
|
||||||
private:
|
private:
|
||||||
static void AppendClause(std::string &builder, const std::string &name,
|
static void AppendClause(std::string &builder, const std::string &name,
|
||||||
const std::string &clause, const std::string &table = "");
|
const std::string &clause, const std::string &table = "");
|
||||||
|
22
frameworks/native/rdb/include/sqlite_sql_builder.h.rej
Normal file
22
frameworks/native/rdb/include/sqlite_sql_builder.h.rej
Normal file
@ -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<std::pair<std::string, std::vector<std::vector<ValueObject>>>>;
|
||||||
|
+ using ExecuteSqlsRef =
|
||||||
|
+ std::vector<std::pair<std::string, std::vector<std::vector<std::reference_wrapper<ValueObject>>>>>;
|
||||||
|
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<std::string> &columns, const std::string &logTable);
|
||||||
|
static std::string GetSqlArgs(size_t size);
|
||||||
|
|
||||||
|
- static ExecuteSqls MakeExecuteSqls(
|
||||||
|
- const std::string &sql, std::vector<ValueObject> &&args, int fieldSize, int limit);
|
||||||
|
+ template<typename T>
|
||||||
|
+ static std::vector<std::pair<std::string, std::vector<std::vector<T>>>> MakeExecuteSqls(
|
||||||
|
+ const std::string &sql, const std::vector<T> &args, int fieldSize, int limit);
|
||||||
|
private:
|
||||||
|
static void AppendClause(std::string &builder, const std::string &name,
|
||||||
|
const std::string &clause, const std::string &table = "");
|
@ -44,6 +44,7 @@ public:
|
|||||||
int Reset() override;
|
int Reset() override;
|
||||||
int Finalize() override;
|
int Finalize() override;
|
||||||
int Execute(const std::vector<ValueObject> &args) override;
|
int Execute(const std::vector<ValueObject> &args) override;
|
||||||
|
int32_t Execute(const std::vector<std::reference_wrapper<ValueObject>> &args) override;
|
||||||
std::pair<int, ValueObject> ExecuteForValue(const std::vector<ValueObject> &args) override;
|
std::pair<int, ValueObject> ExecuteForValue(const std::vector<ValueObject> &args) override;
|
||||||
int Changes() const override;
|
int Changes() const override;
|
||||||
int64_t LastInsertRowId() const override;
|
int64_t LastInsertRowId() const override;
|
||||||
@ -82,6 +83,7 @@ private:
|
|||||||
|
|
||||||
int Prepare(sqlite3 *dbHandle, const std::string &sql);
|
int Prepare(sqlite3 *dbHandle, const std::string &sql);
|
||||||
int BindArgs(const std::vector<ValueObject> &bindArgs);
|
int BindArgs(const std::vector<ValueObject> &bindArgs);
|
||||||
|
int BindArgs(const std::vector<std::reference_wrapper<ValueObject>> &bindArgs);
|
||||||
int IsValid(int index) const;
|
int IsValid(int index) const;
|
||||||
int InnerStep();
|
int InnerStep();
|
||||||
int InnerFinalize();
|
int InnerFinalize();
|
||||||
@ -109,4 +111,4 @@ private:
|
|||||||
};
|
};
|
||||||
} // namespace NativeRdb
|
} // namespace NativeRdb
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
#endif
|
#endif
|
||||||
|
24
frameworks/native/rdb/include/sqlite_statement.h.rej
Normal file
24
frameworks/native/rdb/include/sqlite_statement.h.rej
Normal file
@ -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<ValueObject> &args) override;
|
||||||
|
+ int32_t Execute(const std::vector<std::reference_wrapper<ValueObject>> &args) override;
|
||||||
|
std::pair<int, ValueObject> ExecuteForValue(const std::vector<ValueObject> &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<ValueObject> &bindArgs);
|
||||||
|
+ int BindArgs(const std::vector<std::reference_wrapper<ValueObject>> &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
|
@ -39,6 +39,7 @@ public:
|
|||||||
virtual int32_t Reset() = 0;
|
virtual int32_t Reset() = 0;
|
||||||
virtual int32_t Finalize() = 0;
|
virtual int32_t Finalize() = 0;
|
||||||
virtual int32_t Execute(const std::vector<ValueObject> &args = {}) = 0;
|
virtual int32_t Execute(const std::vector<ValueObject> &args = {}) = 0;
|
||||||
|
virtual int32_t Execute(const std::vector<std::reference_wrapper<ValueObject>> &args) = 0;
|
||||||
|
|
||||||
virtual std::pair<int, ValueObject> ExecuteForValue(const std::vector<ValueObject> &args = {}) = 0;
|
virtual std::pair<int, ValueObject> ExecuteForValue(const std::vector<ValueObject> &args = {}) = 0;
|
||||||
virtual int32_t Changes() const = 0;
|
virtual int32_t Changes() const = 0;
|
||||||
|
9
frameworks/native/rdb/include/statement.h.rej
Normal file
9
frameworks/native/rdb/include/statement.h.rej
Normal file
@ -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<ValueObject> &args = {}) = 0;
|
||||||
|
+ virtual int32_t Execute(const std::vector<std::reference_wrapper<ValueObject>> &args) = 0;
|
||||||
|
|
||||||
|
virtual std::pair<int, ValueObject> ExecuteForValue(const std::vector<ValueObject> &args = {}) = 0;
|
||||||
|
virtual int32_t Changes() const = 0;
|
@ -38,8 +38,8 @@ public:
|
|||||||
~RdbStoreImpl() override;
|
~RdbStoreImpl() override;
|
||||||
const RdbStoreConfig &GetConfig();
|
const RdbStoreConfig &GetConfig();
|
||||||
int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &values) override;
|
int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &values) override;
|
||||||
int BatchInsert(
|
int BatchInsert(int64_t& outInsertNum, const std::string& table, const std::vector<ValuesBucket>& values) override;
|
||||||
int64_t& outInsertNum, const std::string& table, const std::vector<ValuesBucket>& values) override;
|
std::pair<int, int64_t> BatchInsert(const std::string& table, const ValuesBuckets& values) override;
|
||||||
int Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) 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,
|
int InsertWithConflictResolution(int64_t &outRowId, const std::string &table, const ValuesBucket &values,
|
||||||
ConflictResolution conflictResolution) override;
|
ConflictResolution conflictResolution) override;
|
||||||
@ -108,6 +108,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
using ExecuteSqls = std::vector<std::pair<std::string, std::vector<std::vector<ValueObject>>>>;
|
using ExecuteSqls = std::vector<std::pair<std::string, std::vector<std::vector<ValueObject>>>>;
|
||||||
|
using ExecuteSqlsRef =
|
||||||
|
std::vector<std::pair<std::string, std::vector<std::vector<std::reference_wrapper<ValueObject>>>>>;
|
||||||
using Stmt = std::shared_ptr<Statement>;
|
using Stmt = std::shared_ptr<Statement>;
|
||||||
using RdbParam = DistributedRdb::RdbSyncerParam;
|
using RdbParam = DistributedRdb::RdbSyncerParam;
|
||||||
|
|
||||||
@ -120,6 +122,7 @@ private:
|
|||||||
int CheckAttach(const std::string &sql);
|
int CheckAttach(const std::string &sql);
|
||||||
std::pair<int32_t, Stmt> BeginExecuteSql(const std::string &sql);
|
std::pair<int32_t, Stmt> BeginExecuteSql(const std::string &sql);
|
||||||
ExecuteSqls GenerateSql(const std::string& table, const std::vector<ValuesBucket>& buckets, int limit);
|
ExecuteSqls GenerateSql(const std::string& table, const std::vector<ValuesBucket>& buckets, int limit);
|
||||||
|
ExecuteSqlsRef GenerateSql(const std::string& table, const ValuesBuckets& buckets, int limit);
|
||||||
int GetDataBasePath(const std::string &databasePath, std::string &backupFilePath);
|
int GetDataBasePath(const std::string &databasePath, std::string &backupFilePath);
|
||||||
int ExecuteSqlInner(const std::string &sql, const std::vector<ValueObject> &bindArgs);
|
int ExecuteSqlInner(const std::string &sql, const std::vector<ValueObject> &bindArgs);
|
||||||
void SetAssetStatus(const ValueObject &val, int32_t status);
|
void SetAssetStatus(const ValueObject &val, int32_t status);
|
||||||
@ -136,7 +139,8 @@ private:
|
|||||||
int UpdateWithConflictResolutionEntry(int &changedRows, const std::string &table, const ValuesBucket &values,
|
int UpdateWithConflictResolutionEntry(int &changedRows, const std::string &table, const ValuesBucket &values,
|
||||||
const std::string &whereClause, const std::vector<ValueObject> &bindArgs,
|
const std::string &whereClause, const std::vector<ValueObject> &bindArgs,
|
||||||
ConflictResolution conflictResolution);
|
ConflictResolution conflictResolution);
|
||||||
int BatchInsertEntry(int64_t& outInsertNum, const std::string& table, const std::vector<ValuesBucket>& values);
|
template<typename T>
|
||||||
|
int BatchInsertEntry(const std::string& table, const T& values, size_t rowSize, int64_t& outInsertNum);
|
||||||
int ExecuteSqlEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs);
|
int ExecuteSqlEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs);
|
||||||
std::pair<int32_t, ValueObject> ExecuteEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs,
|
std::pair<int32_t, ValueObject> ExecuteEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs,
|
||||||
int64_t trxId);
|
int64_t trxId);
|
||||||
|
39
frameworks/native/rdb/mock/include/rdb_store_impl.h.rej
Normal file
39
frameworks/native/rdb/mock/include/rdb_store_impl.h.rej
Normal file
@ -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<ValuesBucket>& values) override;
|
||||||
|
+ int BatchInsert(int64_t& outInsertNum, const std::string& table, const std::vector<ValuesBucket>& values) override;
|
||||||
|
+ std::pair<int, int64_t> 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<std::pair<std::string, std::vector<std::vector<ValueObject>>>>;
|
||||||
|
+ using ExecuteSqlsRef =
|
||||||
|
+ std::vector<std::pair<std::string, std::vector<std::vector<std::reference_wrapper<ValueObject>>>>>;
|
||||||
|
using Stmt = std::shared_ptr<Statement>;
|
||||||
|
using RdbParam = DistributedRdb::RdbSyncerParam;
|
||||||
|
|
||||||
|
@@ -120,6 +122,7 @@ private:
|
||||||
|
int CheckAttach(const std::string &sql);
|
||||||
|
std::pair<int32_t, Stmt> BeginExecuteSql(const std::string &sql);
|
||||||
|
ExecuteSqls GenerateSql(const std::string& table, const std::vector<ValuesBucket>& 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<ValueObject> &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<ValueObject> &bindArgs,
|
||||||
|
ConflictResolution conflictResolution);
|
||||||
|
- int BatchInsertEntry(int64_t& outInsertNum, const std::string& table, const std::vector<ValuesBucket>& values);
|
||||||
|
+ template<typename T>
|
||||||
|
+ int BatchInsertEntry(const std::string& table, const T& values, size_t rowSize, int64_t& outInsertNum);
|
||||||
|
int ExecuteSqlEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs);
|
||||||
|
std::pair<int32_t, ValueObject> ExecuteEntry(const std::string& sql, const std::vector<ValueObject>& bindArgs,
|
||||||
|
int64_t trxId);
|
@ -69,6 +69,11 @@ bool BigInteger::operator==(const BigInteger& other)
|
|||||||
return value_ == other.value_;
|
return value_ == other.value_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BigInteger::operator<(const BigInteger &rhs)
|
||||||
|
{
|
||||||
|
return value_ < rhs.value_;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t BigInteger::Sign() const
|
int32_t BigInteger::Sign() const
|
||||||
{
|
{
|
||||||
return sign_;
|
return sign_;
|
||||||
@ -88,4 +93,4 @@ std::vector<uint64_t> BigInteger::Value() const
|
|||||||
{
|
{
|
||||||
return value_;
|
return value_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
frameworks/native/rdb/src/big_integer.cpp.rej
Normal file
20
frameworks/native/rdb/src/big_integer.cpp.rej
Normal file
@ -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<uint64_t> BigInteger::Value() const
|
||||||
|
{
|
||||||
|
return value_;
|
||||||
|
}
|
||||||
|
-}
|
||||||
|
\ No newline at end of file
|
||||||
|
+}
|
@ -116,7 +116,7 @@ int RdStatement::Prepare(GRD_DB *db, const std::string &newSql)
|
|||||||
(!EndWithNull(newSql, curIdx) && !TryEatSymbol(newSql, ';', curIdx))) {
|
(!EndWithNull(newSql, curIdx) && !TryEatSymbol(newSql, ';', curIdx))) {
|
||||||
return E_INCORRECT_SQL;
|
return E_INCORRECT_SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
readOnly_ = false;
|
readOnly_ = false;
|
||||||
sql_ = newSql;
|
sql_ = newSql;
|
||||||
return setPragmas_["user_version"](version);
|
return setPragmas_["user_version"](version);
|
||||||
@ -245,24 +245,33 @@ int32_t RdStatement::Prepare(const std::string& sql)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t RdStatement::Bind(const std::vector<ValueObject>& args)
|
int32_t RdStatement::Bind(const std::vector<ValueObject>& args)
|
||||||
|
{
|
||||||
|
std::vector<std::reference_wrapper<ValueObject>> refArgs;
|
||||||
|
for (auto &object : args) {
|
||||||
|
refArgs.emplace_back(std::ref(const_cast<ValueObject&>(object)));
|
||||||
|
}
|
||||||
|
return Bind(refArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t RdStatement::Bind(const std::vector<std::reference_wrapper<ValueObject>>& args)
|
||||||
{
|
{
|
||||||
uint32_t index = 1;
|
uint32_t index = 1;
|
||||||
int ret = E_OK;
|
int ret = E_OK;
|
||||||
for (auto &arg : args) {
|
for (auto &arg : args) {
|
||||||
switch (arg.GetType()) {
|
switch (arg.get().GetType()) {
|
||||||
case ValueObjectType::TYPE_NULL: {
|
case ValueObjectType::TYPE_NULL: {
|
||||||
ret = RdUtils::RdSqlBindNull(stmtHandle_, index);
|
ret = RdUtils::RdSqlBindNull(stmtHandle_, index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ValueObjectType::TYPE_INT: {
|
case ValueObjectType::TYPE_INT: {
|
||||||
int64_t value = 0;
|
int64_t value = 0;
|
||||||
arg.GetLong(value);
|
arg.get().GetLong(value);
|
||||||
ret = RdUtils::RdSqlBindInt64(stmtHandle_, index, value);
|
ret = RdUtils::RdSqlBindInt64(stmtHandle_, index, value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ValueObjectType::TYPE_DOUBLE: {
|
case ValueObjectType::TYPE_DOUBLE: {
|
||||||
double doubleVal = 0;
|
double doubleVal = 0;
|
||||||
arg.GetDouble(doubleVal);
|
arg.get().GetDouble(doubleVal);
|
||||||
ret = RdUtils::RdSqlBindDouble(stmtHandle_, index, doubleVal);
|
ret = RdUtils::RdSqlBindDouble(stmtHandle_, index, doubleVal);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -313,6 +322,15 @@ int32_t RdStatement::Reset()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t RdStatement::Execute(const std::vector<ValueObject>& args)
|
int32_t RdStatement::Execute(const std::vector<ValueObject>& args)
|
||||||
|
{
|
||||||
|
std::vector<std::reference_wrapper<ValueObject>> refArgs;
|
||||||
|
for (auto &object : args) {
|
||||||
|
refArgs.emplace_back(std::ref(const_cast<ValueObject&>(object)));
|
||||||
|
}
|
||||||
|
return Execute(refArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t RdStatement::Execute(const std::vector<std::reference_wrapper<ValueObject>>& args)
|
||||||
{
|
{
|
||||||
if (!readOnly_ && strcmp(sql_.c_str(), GlobalExpr::PRAGMA_VERSION) == 0) {
|
if (!readOnly_ && strcmp(sql_.c_str(), GlobalExpr::PRAGMA_VERSION) == 0) {
|
||||||
// It has already set version in prepare procedure
|
// It has already set version in prepare procedure
|
||||||
|
63
frameworks/native/rdb/src/rd_statement.cpp.rej
Normal file
63
frameworks/native/rdb/src/rd_statement.cpp.rej
Normal file
@ -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<ValueObject>& args)
|
||||||
|
+{
|
||||||
|
+ std::vector<std::reference_wrapper<ValueObject>> refArgs;
|
||||||
|
+ for (auto &object : args) {
|
||||||
|
+ refArgs.emplace_back(std::ref(const_cast<ValueObject&>(object)));
|
||||||
|
+ }
|
||||||
|
+ return Bind(refArgs);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int32_t RdStatement::Bind(const std::vector<std::reference_wrapper<ValueObject>>& 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<ValueObject>& args)
|
||||||
|
+{
|
||||||
|
+ std::vector<std::reference_wrapper<ValueObject>> refArgs;
|
||||||
|
+ for (auto &object : args) {
|
||||||
|
+ refArgs.emplace_back(std::ref(const_cast<ValueObject&>(object)));
|
||||||
|
+ }
|
||||||
|
+ return Execute(refArgs);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int32_t RdStatement::Execute(const std::vector<std::reference_wrapper<ValueObject>>& args)
|
||||||
|
{
|
||||||
|
if (!readOnly_ && strcmp(sql_.c_str(), GlobalExpr::PRAGMA_VERSION) == 0) {
|
||||||
|
// It has already set version in prepare procedure
|
@ -42,6 +42,7 @@
|
|||||||
#include "sqlite_statement.h"
|
#include "sqlite_statement.h"
|
||||||
#include "sqlite_utils.h"
|
#include "sqlite_utils.h"
|
||||||
#include "step_result_set.h"
|
#include "step_result_set.h"
|
||||||
|
#include "values_buckets.h"
|
||||||
#include "task_executor.h"
|
#include "task_executor.h"
|
||||||
#include "traits.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<ValuesBucket> &values)
|
int RdbStoreImpl::BatchInsert(int64_t &outInsertNum, const std::string &table, const std::vector<ValuesBucket> &values)
|
||||||
{
|
{
|
||||||
SqlStatistic sqlStatistic("", SqlStatistic::Step::STEP_TOTAL);
|
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,
|
std::pair<int, int64_t> RdbStoreImpl::BatchInsert(const std::string &table, const ValuesBuckets &values)
|
||||||
const std::vector<ValuesBucket> &values)
|
{
|
||||||
|
SqlStatistic sqlStatistic("", SqlStatistic::Step::STEP_TOTAL);
|
||||||
|
int64_t rowSize = 0;
|
||||||
|
auto ret = BatchInsertEntry(table, values, values.RowSize(), rowSize);
|
||||||
|
return { ret, rowSize };
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
int RdbStoreImpl::BatchInsertEntry(const std::string &table, const T &values, size_t rowSize, int64_t &outInsertNum)
|
||||||
{
|
{
|
||||||
if (isReadOnly_ || (config_.GetDBType() == DB_VECTOR)) {
|
if (isReadOnly_ || (config_.GetDBType() == DB_VECTOR)) {
|
||||||
return E_NOT_SUPPORT;
|
return E_NOT_SUPPORT;
|
||||||
}
|
}
|
||||||
if (values.empty()) {
|
if (rowSize == 0) {
|
||||||
outInsertNum = 0;
|
outInsertNum = 0;
|
||||||
return E_OK;
|
return E_OK;
|
||||||
}
|
}
|
||||||
@ -374,7 +383,7 @@ int RdbStoreImpl::BatchInsertEntry(int64_t &outInsertNum, const std::string &tab
|
|||||||
auto executeSqlArgs = GenerateSql(table, values, connection->GetMaxVariable());
|
auto executeSqlArgs = GenerateSql(table, values, connection->GetMaxVariable());
|
||||||
if (executeSqlArgs.empty()) {
|
if (executeSqlArgs.empty()) {
|
||||||
LOG_ERROR("empty, table=%{public}s, values:%{public}zu, max number:%{public}d.", table.c_str(),
|
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;
|
return E_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
|
#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;
|
connection = nullptr;
|
||||||
outInsertNum = static_cast<int64_t>(values.size());
|
outInsertNum = static_cast<int64_t>(rowSize);
|
||||||
DoCloudSync(table);
|
DoCloudSync(table);
|
||||||
return E_OK;
|
return E_OK;
|
||||||
}
|
}
|
||||||
@ -442,7 +451,37 @@ RdbStoreImpl::ExecuteSqls RdbStoreImpl::GenerateSql(const std::string& table, co
|
|||||||
}
|
}
|
||||||
sql.pop_back();
|
sql.pop_back();
|
||||||
sql.append(") VALUES ");
|
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<ValueObject> emptyRef(object);
|
||||||
|
std::vector<std::reference_wrapper<ValueObject>> 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)
|
int RdbStoreImpl::Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &values)
|
||||||
|
104
frameworks/native/rdb/src/rdb_store_impl.cpp.rej
Normal file
104
frameworks/native/rdb/src/rdb_store_impl.cpp.rej
Normal file
@ -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<ValuesBucket> &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<ValuesBucket> &values)
|
||||||
|
+std::pair<int, int64_t> 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<typename T>
|
||||||
|
+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<int64_t>(values.size());
|
||||||
|
+ outInsertNum = static_cast<int64_t>(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<ValueObject> emptyRef(object);
|
||||||
|
+ std::vector<std::reference_wrapper<ValueObject>> 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;
|
@ -321,14 +321,14 @@ SqliteSqlBuilder::ExecuteSqls SqliteSqlBuilder::MakeExecuteSqls(
|
|||||||
return sqlStr;
|
return sqlStr;
|
||||||
};
|
};
|
||||||
std::string executeSql;
|
std::string executeSql;
|
||||||
ExecuteSqls executeSqls;
|
std::vector<std::pair<std::string, std::vector<std::vector<T>>>> executeSqls;
|
||||||
auto start = args.begin();
|
auto start = args.begin();
|
||||||
if (executeTimes != 0) {
|
if (executeTimes != 0) {
|
||||||
executeSql = appendAgsSql(maxRowNumbersOneTimes);
|
executeSql = appendAgsSql(maxRowNumbersOneTimes);
|
||||||
std::vector<std::vector<ValueObject>> sqlArgs;
|
std::vector<std::vector<T>> sqlArgs;
|
||||||
size_t maxVariableNumbers = maxRowNumbersOneTimes * static_cast<size_t>(fieldSize);
|
size_t maxVariableNumbers = maxRowNumbersOneTimes * static_cast<size_t>(fieldSize);
|
||||||
for (size_t i = 0; i < executeTimes; ++i) {
|
for (size_t i = 0; i < executeTimes; ++i) {
|
||||||
std::vector<ValueObject> bindValueArgs(start, start + maxVariableNumbers);
|
std::vector<T> bindValueArgs(start, start + maxVariableNumbers);
|
||||||
sqlArgs.emplace_back(std::move(bindValueArgs));
|
sqlArgs.emplace_back(std::move(bindValueArgs));
|
||||||
start += maxVariableNumbers;
|
start += maxVariableNumbers;
|
||||||
}
|
}
|
||||||
|
64
frameworks/native/rdb/src/sqlite_sql_builder.cpp.rej
Normal file
64
frameworks/native/rdb/src/sqlite_sql_builder.cpp.rej
Normal file
@ -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<ValueObject> &&args, int fieldSize, int limit)
|
||||||
|
+template<typename T>
|
||||||
|
+std::vector<std::pair<std::string, std::vector<std::vector<T>>>> SqliteSqlBuilder::MakeExecuteSqls(
|
||||||
|
+ const std::string &sql, const std::vector<T> &args, int fieldSize, int limit)
|
||||||
|
{
|
||||||
|
if (fieldSize == 0) {
|
||||||
|
- return ExecuteSqls();
|
||||||
|
+ return {};
|
||||||
|
}
|
||||||
|
size_t rowNumbers = args.size() / static_cast<size_t>(fieldSize);
|
||||||
|
size_t maxRowNumbersOneTimes = static_cast<size_t>(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<std::pair<std::string, std::vector<std::vector<T>>>> executeSqls;
|
||||||
|
auto start = args.begin();
|
||||||
|
if (executeTimes != 0) {
|
||||||
|
executeSql = appendAgsSql(maxRowNumbersOneTimes);
|
||||||
|
- std::vector<std::vector<ValueObject>> sqlArgs;
|
||||||
|
+ std::vector<std::vector<T>> sqlArgs;
|
||||||
|
size_t maxVariableNumbers = maxRowNumbersOneTimes * static_cast<size_t>(fieldSize);
|
||||||
|
for (size_t i = 0; i < executeTimes; ++i) {
|
||||||
|
- std::vector<ValueObject> bindValueArgs(start, start + maxVariableNumbers);
|
||||||
|
+ std::vector<T> 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<std::vector<ValueObject>> sqlArgs(1, std::vector<ValueObject>(start, args.end()));
|
||||||
|
+ std::vector<std::vector<T>> sqlArgs(1, std::vector<T>(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<ValueObject> &args, int fieldSize, int limit);
|
||||||
|
+template SqliteSqlBuilder::ExecuteSqlsRef SqliteSqlBuilder::MakeExecuteSqls(
|
||||||
|
+ const std::string &sql, const std::vector<std::reference_wrapper<ValueObject>> &args, int fieldSize, int limit);
|
||||||
|
} // namespace NativeRdb
|
||||||
|
} // namespace OHOS
|
@ -138,6 +138,15 @@ void SqliteStatement::ReadFile2Buffer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int SqliteStatement::BindArgs(const std::vector<ValueObject> &bindArgs)
|
int SqliteStatement::BindArgs(const std::vector<ValueObject> &bindArgs)
|
||||||
|
{
|
||||||
|
std::vector<std::reference_wrapper<ValueObject>> refBindArgs;
|
||||||
|
for (auto &object : bindArgs) {
|
||||||
|
refBindArgs.emplace_back(std::ref(const_cast<ValueObject&>(object)));
|
||||||
|
}
|
||||||
|
return BindArgs(refBindArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteStatement::BindArgs(const std::vector<std::reference_wrapper<ValueObject>> &bindArgs)
|
||||||
{
|
{
|
||||||
SqlStatistic sqlStatistic("", SqlStatistic::Step::STEP_PREPARE, seqId_);
|
SqlStatistic sqlStatistic("", SqlStatistic::Step::STEP_PREPARE, seqId_);
|
||||||
if (bound_) {
|
if (bound_) {
|
||||||
@ -147,12 +156,12 @@ int SqliteStatement::BindArgs(const std::vector<ValueObject> &bindArgs)
|
|||||||
bound_ = true;
|
bound_ = true;
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for (auto &arg : bindArgs) {
|
for (auto &arg : bindArgs) {
|
||||||
auto action = ACTIONS[arg.value.index()];
|
auto action = ACTIONS[arg.get().value.index()];
|
||||||
if (action == nullptr) {
|
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;
|
return E_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
auto errCode = action(stmt_, index, arg.value);
|
auto errCode = action(stmt_, index, arg.get().value);
|
||||||
if (errCode != SQLITE_OK) {
|
if (errCode != SQLITE_OK) {
|
||||||
LOG_ERROR("Bind has error: %{public}d, sql: %{public}s, errno %{public}d", errCode, sql_.c_str(), errno);
|
LOG_ERROR("Bind has error: %{public}d, sql: %{public}s, errno %{public}d", errCode, sql_.c_str(), errno);
|
||||||
return SQLiteError::ErrNo(errCode);
|
return SQLiteError::ErrNo(errCode);
|
||||||
@ -327,6 +336,15 @@ int SqliteStatement::Finalize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int SqliteStatement::Execute(const std::vector<ValueObject> &args)
|
int SqliteStatement::Execute(const std::vector<ValueObject> &args)
|
||||||
|
{
|
||||||
|
std::vector<std::reference_wrapper<ValueObject>> refArgs;
|
||||||
|
for (auto &object : args) {
|
||||||
|
refArgs.emplace_back(std::ref(const_cast<ValueObject&>(object)));
|
||||||
|
}
|
||||||
|
return Execute(refArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t SqliteStatement::Execute(const std::vector<std::reference_wrapper<ValueObject>> &args)
|
||||||
{
|
{
|
||||||
int count = static_cast<int>(args.size());
|
int count = static_cast<int>(args.size());
|
||||||
if (count != numParameters_) {
|
if (count != numParameters_) {
|
||||||
|
49
frameworks/native/rdb/src/sqlite_statement.cpp.rej
Normal file
49
frameworks/native/rdb/src/sqlite_statement.cpp.rej
Normal file
@ -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<ValueObject> &bindArgs)
|
||||||
|
+{
|
||||||
|
+ std::vector<std::reference_wrapper<ValueObject>> refBindArgs;
|
||||||
|
+ for (auto &object : bindArgs) {
|
||||||
|
+ refBindArgs.emplace_back(std::ref(const_cast<ValueObject&>(object)));
|
||||||
|
+ }
|
||||||
|
+ return BindArgs(refBindArgs);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int SqliteStatement::BindArgs(const std::vector<std::reference_wrapper<ValueObject>> &bindArgs)
|
||||||
|
{
|
||||||
|
SqlStatistic sqlStatistic("", SqlStatistic::Step::STEP_PREPARE, seqId_);
|
||||||
|
if (bound_) {
|
||||||
|
@@ -146,12 +155,12 @@ int SqliteStatement::BindArgs(const std::vector<ValueObject> &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<ValueObject> &args)
|
||||||
|
+{
|
||||||
|
+ std::vector<std::reference_wrapper<ValueObject>> refArgs;
|
||||||
|
+ for (auto &object : args) {
|
||||||
|
+ refArgs.emplace_back(std::ref(const_cast<ValueObject&>(object)));
|
||||||
|
+ }
|
||||||
|
+ return Execute(refArgs);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int32_t SqliteStatement::Execute(const std::vector<std::reference_wrapper<ValueObject>> &args)
|
||||||
|
{
|
||||||
|
int count = static_cast<int>(args.size());
|
||||||
|
if (count != numParameters_) {
|
@ -341,5 +341,40 @@ int ValueObject::Get(T &output) const
|
|||||||
output = static_cast<T>(*v);
|
output = static_cast<T>(*v);
|
||||||
return E_OK;
|
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 NativeRdb
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
|
42
frameworks/native/rdb/src/value_object.cpp.rej
Normal file
42
frameworks/native/rdb/src/value_object.cpp.rej
Normal file
@ -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<T>(*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
|
66
frameworks/native/rdb/src/values_buckets.cpp
Normal file
66
frameworks/native/rdb/src/values_buckets.cpp
Normal file
@ -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<std::set<std::string>>();
|
||||||
|
values_ = std::make_shared<std::set<ValueObject>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ValuesBuckets::RowSize() const
|
||||||
|
{
|
||||||
|
return buckets_.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<ValuesBuckets::FieldsType, ValuesBuckets::ValuesType> 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<std::string &>(*fieldResult.first)),
|
||||||
|
std::ref(const_cast<ValueObject &>(*valueResult.first))));
|
||||||
|
}
|
||||||
|
buckets_.push_back(std::move(row));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<int, ValuesBuckets::ValueType> 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 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -41,6 +41,7 @@ base_sources = [
|
|||||||
"${relational_store_native_path}/rdb/src/string_utils.cpp",
|
"${relational_store_native_path}/rdb/src/string_utils.cpp",
|
||||||
"${relational_store_native_path}/rdb/src/value_object.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_bucket.cpp",
|
||||||
|
"${relational_store_native_path}/rdb/src/values_buckets.cpp",
|
||||||
]
|
]
|
||||||
|
|
||||||
if (!is_ohos) {
|
if (!is_ohos) {
|
||||||
|
9
interfaces/inner_api/rdb/BUILD.gn.rej
Normal file
9
interfaces/inner_api/rdb/BUILD.gn.rej
Normal file
@ -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) {
|
@ -33,6 +33,7 @@ public:
|
|||||||
BigInteger &operator=(const BigInteger &other);
|
BigInteger &operator=(const BigInteger &other);
|
||||||
BigInteger &operator=(BigInteger &&other);
|
BigInteger &operator=(BigInteger &&other);
|
||||||
bool operator==(const BigInteger &other);
|
bool operator==(const BigInteger &other);
|
||||||
|
bool operator<(const BigInteger &rhs);
|
||||||
|
|
||||||
int32_t Sign() const;
|
int32_t Sign() const;
|
||||||
size_t Size() const;
|
size_t Size() const;
|
||||||
|
9
interfaces/inner_api/rdb/include/big_integer.h.rej
Normal file
9
interfaces/inner_api/rdb/include/big_integer.h.rej
Normal file
@ -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;
|
@ -26,6 +26,7 @@
|
|||||||
#include "result_set.h"
|
#include "result_set.h"
|
||||||
#include "value_object.h"
|
#include "value_object.h"
|
||||||
#include "values_bucket.h"
|
#include "values_bucket.h"
|
||||||
|
#include "values_buckets.h"
|
||||||
#include "rdb_types.h"
|
#include "rdb_types.h"
|
||||||
#include "rdb_common.h"
|
#include "rdb_common.h"
|
||||||
#include "rdb_errno.h"
|
#include "rdb_errno.h"
|
||||||
@ -104,6 +105,17 @@ public:
|
|||||||
virtual int BatchInsert(
|
virtual int BatchInsert(
|
||||||
int64_t &outInsertNum, const std::string &table, const std::vector<ValuesBucket> &values) = 0;
|
int64_t &outInsertNum, const std::string &table, const std::vector<ValuesBucket> &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<int, int64_t> BatchInsert(const std::string &table, const ValuesBuckets &values)
|
||||||
|
{
|
||||||
|
return { E_NOT_SUPPORT, 0 };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Replaces a row of data into the target table.
|
* @brief Replaces a row of data into the target table.
|
||||||
*
|
*
|
||||||
|
27
interfaces/inner_api/rdb/include/rdb_store.h.rej
Normal file
27
interfaces/inner_api/rdb/include/rdb_store.h.rej
Normal file
@ -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<ValuesBucket> &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<int, int64_t> BatchInsert(const std::string &table, const ValuesBuckets &values)
|
||||||
|
+ {
|
||||||
|
+ return { E_NOT_SUPPORT, 0 };
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
/**
|
||||||
|
* @brief Replaces a row of data into the target table.
|
||||||
|
*
|
@ -230,7 +230,7 @@ public:
|
|||||||
* @param val Indicates an Assets input parameter.
|
* @param val Indicates an Assets input parameter.
|
||||||
*/
|
*/
|
||||||
API_EXPORT ValueObject(BigInt val);
|
API_EXPORT ValueObject(BigInt val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructor.
|
* @brief Constructor.
|
||||||
* This constructor is used to convert the FloatVector input parameter to a value of type ValueObject.
|
* This constructor is used to convert the FloatVector input parameter to a value of type ValueObject.
|
||||||
@ -379,6 +379,8 @@ public:
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator<(const ValueObject &rhs) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<class T>
|
template<class T>
|
||||||
int Get(T &output) const;
|
int Get(T &output) const;
|
||||||
|
19
interfaces/inner_api/rdb/include/value_object.h.rej
Normal file
19
interfaces/inner_api/rdb/include/value_object.h.rej
Normal file
@ -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<class T>
|
||||||
|
int Get(T &output) const;
|
52
interfaces/inner_api/rdb/include/values_buckets.h
Normal file
52
interfaces/inner_api/rdb/include/values_buckets.h
Normal file
@ -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 <map>
|
||||||
|
#include <set>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "value_object.h"
|
||||||
|
#include "values_bucket.h"
|
||||||
|
|
||||||
|
namespace OHOS {
|
||||||
|
namespace NativeRdb {
|
||||||
|
class API_EXPORT ValuesBuckets {
|
||||||
|
public:
|
||||||
|
using FieldsType = std::shared_ptr<std::set<std::string>>;
|
||||||
|
using ValuesType = std::shared_ptr<std::set<ValueObject>>;
|
||||||
|
using FieldType = std::reference_wrapper<const std::string>;
|
||||||
|
using ValueType = std::reference_wrapper<ValueObject>;
|
||||||
|
using BucketType = std::map<FieldType, ValueType, std::less<std::string>>;
|
||||||
|
|
||||||
|
API_EXPORT ValuesBuckets();
|
||||||
|
|
||||||
|
API_EXPORT size_t RowSize() const;
|
||||||
|
API_EXPORT std::pair<FieldsType, ValuesType> GetFieldsAndValues() const;
|
||||||
|
|
||||||
|
API_EXPORT void Put(const ValuesBucket &bucket);
|
||||||
|
API_EXPORT std::pair<int, ValueType> Get(size_t row, const FieldType &field) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FieldsType fields_;
|
||||||
|
ValuesType values_;
|
||||||
|
std::vector<BucketType> buckets_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace NativeRdb
|
||||||
|
} // namespace OHOS
|
||||||
|
#endif
|
@ -32,6 +32,7 @@ public:
|
|||||||
BigInteger &operator=(const BigInteger &other);
|
BigInteger &operator=(const BigInteger &other);
|
||||||
BigInteger &operator=(BigInteger &&other);
|
BigInteger &operator=(BigInteger &&other);
|
||||||
bool operator==(const BigInteger &other);
|
bool operator==(const BigInteger &other);
|
||||||
|
bool operator<(const BigInteger &rhs);
|
||||||
|
|
||||||
int32_t Sign() const;
|
int32_t Sign() const;
|
||||||
size_t Size() const;
|
size_t Size() const;
|
||||||
|
9
interfaces/inner_api/rdb/mock/include/big_integer.h.rej
Normal file
9
interfaces/inner_api/rdb/mock/include/big_integer.h.rej
Normal file
@ -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;
|
@ -28,6 +28,8 @@
|
|||||||
#include "result_set.h"
|
#include "result_set.h"
|
||||||
#include "value_object.h"
|
#include "value_object.h"
|
||||||
#include "values_bucket.h"
|
#include "values_bucket.h"
|
||||||
|
#include "values_buckets.h"
|
||||||
|
|
||||||
namespace OHOS::NativeRdb {
|
namespace OHOS::NativeRdb {
|
||||||
class RdbStore {
|
class RdbStore {
|
||||||
public:
|
public:
|
||||||
@ -39,6 +41,10 @@ public:
|
|||||||
virtual int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &values) = 0;
|
virtual int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &values) = 0;
|
||||||
virtual int BatchInsert(int64_t &outInsertNum, const std::string &table,
|
virtual int BatchInsert(int64_t &outInsertNum, const std::string &table,
|
||||||
const std::vector<ValuesBucket> &values) = 0;
|
const std::vector<ValuesBucket> &values) = 0;
|
||||||
|
virtual std::pair<int, int64_t> 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 Replace(int64_t &outRowId, const std::string &table, const ValuesBucket &values) = 0;
|
||||||
virtual int InsertWithConflictResolution(
|
virtual int InsertWithConflictResolution(
|
||||||
int64_t &outRowId, const std::string &table, const ValuesBucket &values,
|
int64_t &outRowId, const std::string &table, const ValuesBucket &values,
|
||||||
|
21
interfaces/inner_api/rdb/mock/include/rdb_store.h.rej
Normal file
21
interfaces/inner_api/rdb/mock/include/rdb_store.h.rej
Normal file
@ -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<ValuesBucket> &values) = 0;
|
||||||
|
+ virtual std::pair<int, int64_t> 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,
|
@ -325,6 +325,8 @@ public:
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator<(const ValueObject &rhs) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<class T>
|
template<class T>
|
||||||
int Get(T &output) const;
|
int Get(T &output) const;
|
||||||
|
10
interfaces/inner_api/rdb/mock/include/value_object.h.rej
Normal file
10
interfaces/inner_api/rdb/mock/include/value_object.h.rej
Normal file
@ -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<class T>
|
||||||
|
int Get(T &output) const;
|
51
interfaces/inner_api/rdb/mock/include/values_buckets.h
Normal file
51
interfaces/inner_api/rdb/mock/include/values_buckets.h
Normal file
@ -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 <map>
|
||||||
|
#include <set>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "value_object.h"
|
||||||
|
#include "values_bucket.h"
|
||||||
|
|
||||||
|
namespace OHOS {
|
||||||
|
namespace NativeRdb {
|
||||||
|
class ValuesBuckets {
|
||||||
|
public:
|
||||||
|
using FieldsType = std::shared_ptr<std::set<std::string>>;
|
||||||
|
using ValuesType = std::shared_ptr<std::set<ValueObject>>;
|
||||||
|
using FieldType = std::reference_wrapper<const std::string>;
|
||||||
|
using ValueType = std::reference_wrapper<ValueObject>;
|
||||||
|
using BucketType = std::map<FieldType, ValueType, std::less<std::string>>;
|
||||||
|
|
||||||
|
ValuesBuckets();
|
||||||
|
|
||||||
|
size_t RowSize() const;
|
||||||
|
std::pair<FieldsType, ValuesType> GetFieldsAndValues() const;
|
||||||
|
|
||||||
|
void Put(const ValuesBucket &bucket);
|
||||||
|
std::pair<int, ValueType> Get(size_t row, const FieldType &field) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FieldsType fields_;
|
||||||
|
ValuesType values_;
|
||||||
|
std::vector<BucketType> buckets_;
|
||||||
|
};
|
||||||
|
} // namespace NativeRdb
|
||||||
|
} // namespace OHOS
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user