mirror of
https://gitee.com/openharmony/distributeddatamgr_relational_store
synced 2024-11-27 01:01:02 +00:00
commit
ebea3c91da
@ -13,13 +13,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "napi/native_api.h"
|
||||
#include "napi_rdb_const_properties.h"
|
||||
#include "napi_rdb_predicates.h"
|
||||
#include "napi_rdb_store.h"
|
||||
#include "napi_rdb_store_helper.h"
|
||||
#include "napi_rdb_const_properties.h"
|
||||
#include "napi_result_set.h"
|
||||
#include "napi_transaction.h"
|
||||
#include "napi/native_api.h"
|
||||
|
||||
using namespace OHOS::RelationalStoreJsKit;
|
||||
|
||||
|
@ -155,8 +155,8 @@ napi_value AsyncCall::Async(napi_env env, std::shared_ptr<ContextBase> context)
|
||||
}
|
||||
auto report = (record_.total_.times_.load() - record_.completed_.times_.load()) / EXCEPT_DELTA;
|
||||
if (report > record_.reportTimes_ && record_.executed_ != nullptr) {
|
||||
LOG_WARN("Warning:Times:(C:%{public}" PRId64 ", E:%{public}" PRId64 ", F:%{public}" PRId64") Last time("
|
||||
"C:%{public}" PRId64 ", E:%{public}" PRId64 ", F:%{public}" PRId64")",
|
||||
LOG_WARN("Warning:Times:(C:%{public}" PRId64 ", E:%{public}" PRId64 ", F:%{public}" PRId64 ") Last time("
|
||||
"C:%{public}" PRId64 ", E:%{public}" PRId64 ", F:%{public}" PRId64 ")",
|
||||
record_.total_.times_.load(), record_.executed_->times_.load(), record_.completed_.times_.load(),
|
||||
record_.total_.lastTime_, record_.executed_->lastTime_, record_.completed_.lastTime_);
|
||||
}
|
||||
|
@ -14,23 +14,24 @@
|
||||
*/
|
||||
|
||||
#include "napi_rdb_const_properties.h"
|
||||
|
||||
#include "js_utils.h"
|
||||
#include "rdb_common.h"
|
||||
#include "rdb_store.h"
|
||||
#include "js_utils.h"
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
#include "rdb_store_config.h"
|
||||
#include "rdb_types.h"
|
||||
|
||||
using OHOS::DistributedRdb::SyncMode;
|
||||
using OHOS::DistributedRdb::SubscribeMode;
|
||||
using OHOS::DistributedRdb::SyncMode;
|
||||
|
||||
#endif
|
||||
using OHOS::NativeRdb::SecurityLevel;
|
||||
using OHOS::NativeRdb::ConflictResolution;
|
||||
using OHOS::DistributedRdb::ProgressCode;
|
||||
using OHOS::DistributedRdb::DistributedTableType;
|
||||
using OHOS::DistributedRdb::ProgressCode;
|
||||
using OHOS::NativeRdb::ConflictResolution;
|
||||
using OHOS::NativeRdb::SecurityLevel;
|
||||
|
||||
#define SET_NAPI_PROPERTY(object, prop, value) \
|
||||
#define SET_NAPI_PROPERTY(object, prop, value) \
|
||||
napi_set_named_property((env), (object), (prop), AppDataMgrJsKit::JSUtils::Convert2JSValue((env), (value)))
|
||||
|
||||
namespace OHOS::RelationalStoreJsKit {
|
||||
|
@ -34,7 +34,7 @@ static constexpr JsErrorCode JS_ERROR_CODE_MSGS[] = {
|
||||
{ NativeRdb::E_GET_DATAOBSMGRCLIENT_FAIL, 14801050, "Failed to get DataObsMgrClient." },
|
||||
{ NativeRdb::E_TYPE_MISMATCH, 14800051, "The type of the distributed table does not match." },
|
||||
{ NativeRdb::E_SQLITE_FULL, 14800029, "SQLite: The database is full." },
|
||||
{ NativeRdb::E_NOT_SUPPORT_THE_SQL, 14800021, "SQLite: Generic error."},
|
||||
{ NativeRdb::E_NOT_SUPPORT_THE_SQL, 14800021, "SQLite: Generic error." },
|
||||
{ NativeRdb::E_ATTACHED_DATABASE_EXIST, 14800016, "The database alias already exists." },
|
||||
{ NativeRdb::E_SQLITE_ERROR, 14800021, "SQLite: Generic error." },
|
||||
{ NativeRdb::E_SQLITE_CORRUPT, 14800011, "Database corrupted." },
|
||||
|
@ -333,7 +333,7 @@ int32_t Convert2Value(napi_env env, napi_value input, CryptoParam &cryptoParam)
|
||||
NAPI_CALL_RETURN_ERR(GetNamedProperty(env, input, "kdfAlgo", cryptoParam.kdfAlgo, true), napi_invalid_arg);
|
||||
NAPI_CALL_RETURN_ERR(
|
||||
GetNamedProperty(env, input, "cryptoPageSize", cryptoParam.cryptoPageSize, true), napi_invalid_arg);
|
||||
|
||||
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
@ -375,7 +375,7 @@ int32_t Convert2Value(napi_env env, napi_value jsValue, RdbConfig &rdbConfig)
|
||||
|
||||
GetNamedProperty(env, jsValue, "pluginLibs", rdbConfig.pluginLibs, true);
|
||||
ASSERT(OK == status, "get pluginLibs failed.", napi_invalid_arg);
|
||||
|
||||
|
||||
status = GetNamedProperty(env, jsValue, "haMode", rdbConfig.haMode, true);
|
||||
ASSERT(OK == status, "get haMode failed.", napi_invalid_arg);
|
||||
|
||||
|
@ -15,11 +15,11 @@
|
||||
#define LOG_TAG "NapiRdbPredicates"
|
||||
#include "napi_rdb_predicates.h"
|
||||
|
||||
#include "js_df_manager.h"
|
||||
#include "js_utils.h"
|
||||
#include "logger.h"
|
||||
#include "napi_rdb_error.h"
|
||||
#include "napi_rdb_trace.h"
|
||||
#include "js_df_manager.h"
|
||||
|
||||
using namespace OHOS::Rdb;
|
||||
using namespace OHOS::NativeRdb;
|
||||
@ -483,7 +483,6 @@ napi_value RdbPredicatesProxy::NotLike(napi_env env, napi_callback_info info)
|
||||
return thiz;
|
||||
}
|
||||
|
||||
|
||||
napi_value RdbPredicatesProxy::Glob(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz = nullptr;
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "js_df_manager.h"
|
||||
#include "js_native_api.h"
|
||||
#include "js_native_api_types.h"
|
||||
#include "js_utils.h"
|
||||
@ -35,7 +36,6 @@
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_sql_statistic.h"
|
||||
#include "securec.h"
|
||||
#include "js_df_manager.h"
|
||||
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
|
||||
#include "rdb_utils.h"
|
||||
@ -621,7 +621,7 @@ napi_value RdbStoreProxy::Insert(napi_env env, napi_callback_info info)
|
||||
CHECK_RETURN(OK == ParseTableName(env, argv[0], context));
|
||||
CHECK_RETURN(OK == ParseValuesBucket(env, argv[1], context));
|
||||
CHECK_RETURN_SET_E(!HasDuplicateAssets(context->valuesBucket), std::make_shared<ParamError>("Duplicate assets "
|
||||
"are not allowed"));
|
||||
"are not allowed"));
|
||||
if (argc == 3) {
|
||||
CHECK_RETURN(OK == ParseConflictResolution(env, argv[2], context));
|
||||
}
|
||||
@ -662,7 +662,7 @@ napi_value RdbStoreProxy::BatchInsert(napi_env env, napi_callback_info info)
|
||||
CHECK_RETURN(OK == ParseTableName(env, argv[0], context));
|
||||
CHECK_RETURN(OK == ParseValuesBuckets(env, argv[1], context));
|
||||
CHECK_RETURN_SET_E(!HasDuplicateAssets(context->sharedValuesBuckets),
|
||||
std::make_shared<ParamError>("Duplicate assets are not allowed"));
|
||||
std::make_shared<ParamError>("Duplicate assets are not allowed"));
|
||||
};
|
||||
auto exec = [context]() -> int {
|
||||
CHECK_RETURN_ERR(context->rdbStore != nullptr);
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "logger.h"
|
||||
#include "napi_async_call.h"
|
||||
#include "napi_rdb_error.h"
|
||||
|
@ -103,7 +103,6 @@ void NapiRdbStoreObserver::OnChange()
|
||||
[](napi_env env, int &argc, napi_value *argv) {});
|
||||
}
|
||||
|
||||
|
||||
NapiRdbStoreObserver::JSChangeInfo::JSChangeInfo(const Origin &origin, ChangeInfo::iterator info)
|
||||
{
|
||||
table = info->first;
|
||||
|
@ -17,13 +17,13 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "js_df_manager.h"
|
||||
#include "js_utils.h"
|
||||
#include "logger.h"
|
||||
#include "napi_rdb_error.h"
|
||||
#include "napi_rdb_js_utils.h"
|
||||
#include "napi_rdb_sendable_utils.h"
|
||||
#include "napi_rdb_trace.h"
|
||||
#include "js_df_manager.h"
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
|
||||
#include "rdb_result_set_bridge.h"
|
||||
#include "string_ex.h"
|
||||
@ -92,8 +92,8 @@ napi_value ResultSetProxy::Initialize(napi_env env, napi_callback_info info)
|
||||
LOG_ERROR("(T:%{public}d) freed! data:0x%016" PRIXPTR, tid, uintptr_t(data) & LOWER_24_BITS_MASK);
|
||||
}
|
||||
if (data != hint) {
|
||||
LOG_ERROR("RdbStoreProxy memory corrupted! data:0x%016" PRIXPTR "hint:0x%016" PRIXPTR,
|
||||
uintptr_t(data), uintptr_t(hint));
|
||||
LOG_ERROR("RdbStoreProxy memory corrupted! data:0x%016" PRIXPTR "hint:0x%016" PRIXPTR, uintptr_t(data),
|
||||
uintptr_t(hint));
|
||||
return;
|
||||
}
|
||||
ResultSetProxy *proxy = reinterpret_cast<ResultSetProxy *>(data);
|
||||
|
@ -260,8 +260,7 @@ napi_value TransactionProxy::Initialize(napi_env env, napi_callback_info info)
|
||||
LOG_ERROR("(T:%{public}d) freed! data:0x%016" PRIXPTR, tid, uintptr_t(data) & LOWER_24_BITS_MASK);
|
||||
}
|
||||
if (data != hint) {
|
||||
LOG_ERROR("memory corrupted! data:0x%016" PRIXPTR "hint:0x%016" PRIXPTR, uintptr_t(data),
|
||||
uintptr_t(hint));
|
||||
LOG_ERROR("memory corrupted! data:0x%016" PRIXPTR "hint:0x%016" PRIXPTR, uintptr_t(data), uintptr_t(hint));
|
||||
return;
|
||||
}
|
||||
TransactionProxy *proxy = reinterpret_cast<TransactionProxy *>(data);
|
||||
@ -282,8 +281,7 @@ struct CommitContext : public TransactionContext {
|
||||
int32_t Parse(napi_env env, size_t argc, napi_value *argv, napi_value self)
|
||||
{
|
||||
GetInstance(self);
|
||||
ASSERT_RETURN_SET_ERROR(
|
||||
transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
ASSERT_RETURN_SET_ERROR(transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
return OK;
|
||||
}
|
||||
};
|
||||
@ -316,8 +314,7 @@ struct RollbackContext : public TransactionContext {
|
||||
int32_t Parse(napi_env env, size_t argc, napi_value *argv, napi_value self)
|
||||
{
|
||||
GetInstance(self);
|
||||
ASSERT_RETURN_SET_ERROR(
|
||||
transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
ASSERT_RETURN_SET_ERROR(transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
return OK;
|
||||
}
|
||||
};
|
||||
@ -352,8 +349,7 @@ struct DeleteContext : public TransactionContext {
|
||||
{
|
||||
ASSERT_RETURN_SET_ERROR(argc == 1, std::make_shared<ParamNumError>("1"));
|
||||
GetInstance(self);
|
||||
ASSERT_RETURN_SET_ERROR(
|
||||
transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
ASSERT_RETURN_SET_ERROR(transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
CHECK_RETURN_ERR(ParseRdbPredicatesProxy(env, argv[0], rdbPredicates) == OK);
|
||||
return OK;
|
||||
}
|
||||
@ -394,8 +390,7 @@ struct UpdateContext : public TransactionContext {
|
||||
{
|
||||
ASSERT_RETURN_SET_ERROR(argc == 2 || argc == 3, std::make_shared<ParamNumError>("2 to 3"));
|
||||
GetInstance(self);
|
||||
ASSERT_RETURN_SET_ERROR(
|
||||
transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
ASSERT_RETURN_SET_ERROR(transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
CHECK_RETURN_ERR(ParseValuesBucket(env, argv[0], valuesBucket) == OK);
|
||||
CHECK_RETURN_ERR(ParseRdbPredicatesProxy(env, argv[1], rdbPredicates) == OK);
|
||||
// 'argv[2]' is an optional parameter
|
||||
@ -445,8 +440,7 @@ struct InsertContext : public TransactionContext {
|
||||
{
|
||||
ASSERT_RETURN_SET_ERROR(argc == 2 || argc == 3, std::make_shared<ParamNumError>("2 to 3"));
|
||||
GetInstance(self);
|
||||
ASSERT_RETURN_SET_ERROR(
|
||||
transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
ASSERT_RETURN_SET_ERROR(transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
CHECK_RETURN_ERR(JSUtils::Convert2Value(env, argv[0], tableName) == OK);
|
||||
CHECK_RETURN_ERR(ParseValuesBucket(env, argv[1], valuesBucket) == OK);
|
||||
// 'argv[2]' is an optional parameter
|
||||
@ -496,8 +490,7 @@ struct BatchInsertContext : public TransactionContext {
|
||||
{
|
||||
ASSERT_RETURN_SET_ERROR(argc == 2, std::make_shared<ParamNumError>("2"));
|
||||
GetInstance(self);
|
||||
ASSERT_RETURN_SET_ERROR(
|
||||
transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
ASSERT_RETURN_SET_ERROR(transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
ASSERT_RETURN_SET_ERROR(
|
||||
JSUtils::Convert2Value(env, argv[0], tableName) == OK, std::make_shared<ParamError>("table", "a string."));
|
||||
CHECK_RETURN_ERR(ParseValuesBuckets(env, argv[1], valuesBuckets) == OK);
|
||||
@ -541,8 +534,7 @@ struct QueryContext : public TransactionContext {
|
||||
{
|
||||
ASSERT_RETURN_SET_ERROR(argc == 1 || argc == 2, std::make_shared<ParamNumError>("1 to 2"));
|
||||
GetInstance(self);
|
||||
ASSERT_RETURN_SET_ERROR(
|
||||
transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
ASSERT_RETURN_SET_ERROR(transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
CHECK_RETURN_ERR(ParseRdbPredicatesProxy(env, argv[0], rdbPredicates) == OK);
|
||||
if (argc > 1 && !JSUtils::IsNull(env, argv[1])) {
|
||||
ASSERT_RETURN_SET_ERROR(JSUtils::Convert2Value(env, argv[1], columns) == OK,
|
||||
@ -587,8 +579,7 @@ struct QuerySqlContext : public TransactionContext {
|
||||
{
|
||||
ASSERT_RETURN_SET_ERROR(argc == 1 || argc == 2, std::make_shared<ParamNumError>("1 to 2"));
|
||||
GetInstance(self);
|
||||
ASSERT_RETURN_SET_ERROR(
|
||||
transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
ASSERT_RETURN_SET_ERROR(transaction_ != nullptr, std::make_shared<ParamError>("transaction", "a transaction."));
|
||||
ASSERT_RETURN_SET_ERROR(
|
||||
JSUtils::Convert2Value(env, argv[0], sql) == OK, std::make_shared<ParamError>("sql", "a string."));
|
||||
if (argc > 1 && !JSUtils::IsNull(env, argv[1])) {
|
||||
|
@ -21,8 +21,7 @@
|
||||
namespace OHOS::RelationalStoreJsKit {
|
||||
using namespace OHOS::Rdb;
|
||||
|
||||
NapiUvQueue::NapiUvQueue(napi_env env, napi_value callback)
|
||||
: env_(env)
|
||||
NapiUvQueue::NapiUvQueue(napi_env env, napi_value callback) : env_(env)
|
||||
{
|
||||
napi_create_reference(env, callback, 1, &callback_);
|
||||
napi_get_uv_event_loop(env, &loop_);
|
||||
@ -45,7 +44,7 @@ bool NapiUvQueue::operator==(napi_value value)
|
||||
|
||||
void NapiUvQueue::CallFunction(NapiArgsGenerator genArgs)
|
||||
{
|
||||
uv_work_t* work = new (std::nothrow) uv_work_t;
|
||||
uv_work_t *work = new (std::nothrow) uv_work_t;
|
||||
if (work == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
static constexpr const char* FLAG[AbsPredicates::Origin::BUTT] = { "0x02", "0x0", "0x0" };
|
||||
static constexpr const char *FLAG[AbsPredicates::Origin::BUTT] = { "0x02", "0x0", "0x0" };
|
||||
AbsPredicates::AbsPredicates()
|
||||
{
|
||||
Initial();
|
||||
@ -563,7 +563,7 @@ void AbsPredicates::AppendWhereClauseWithInOrNotIn(
|
||||
whereClause += field + StringUtils::SurroundWithFunction(methodName, ",", replaceValues);
|
||||
}
|
||||
|
||||
std::string AbsPredicates::GetStatement() const
|
||||
std::string AbsPredicates::GetStatement() const
|
||||
{
|
||||
return SqliteSqlBuilder::BuildSqlStringFromPredicates(*this);
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ std::string AbsRdbPredicates::GetTableName() const
|
||||
std::string AbsRdbPredicates::ToString() const
|
||||
{
|
||||
std::string args;
|
||||
for (const auto& item : GetWhereArgs()) {
|
||||
for (const auto &item : GetWhereArgs()) {
|
||||
args += item + ", ";
|
||||
}
|
||||
return "TableName = " + GetTableName() + ", {WhereClause:" + GetWhereClause() + ", bindArgs:{" + args + "}"
|
||||
@ -150,29 +150,29 @@ std::string AbsRdbPredicates::ToString() const
|
||||
+ ", isSorted:" + std::to_string(IsSorted()) + "}";
|
||||
}
|
||||
|
||||
AbsRdbPredicates* AbsRdbPredicates::InDevices(std::vector<std::string> &devices)
|
||||
AbsRdbPredicates *AbsRdbPredicates::InDevices(std::vector<std::string> &devices)
|
||||
{
|
||||
predicates_.devices_ = devices;
|
||||
return this;
|
||||
}
|
||||
|
||||
AbsRdbPredicates* AbsRdbPredicates::InAllDevices()
|
||||
AbsRdbPredicates *AbsRdbPredicates::InAllDevices()
|
||||
{
|
||||
predicates_.devices_.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
const DistributedRdb::PredicatesMemo& AbsRdbPredicates::GetDistributedPredicates() const
|
||||
const DistributedRdb::PredicatesMemo &AbsRdbPredicates::GetDistributedPredicates() const
|
||||
{
|
||||
int limit = GetLimit();
|
||||
if (limit >= 0) {
|
||||
predicates_.AddOperation(DistributedRdb::RdbPredicateOperator::LIMIT,
|
||||
std::to_string(limit), std::to_string(GetOffset()));
|
||||
predicates_.AddOperation(
|
||||
DistributedRdb::RdbPredicateOperator::LIMIT, std::to_string(limit), std::to_string(GetOffset()));
|
||||
}
|
||||
return predicates_;
|
||||
}
|
||||
|
||||
AbsRdbPredicates* AbsRdbPredicates::EqualTo(const std::string &field, const ValueObject &value)
|
||||
AbsRdbPredicates *AbsRdbPredicates::EqualTo(const std::string &field, const ValueObject &value)
|
||||
{
|
||||
if (auto pval = std::get_if<std::string>(&value.value)) {
|
||||
predicates_.AddOperation(DistributedRdb::EQUAL_TO, field, *pval);
|
||||
@ -180,7 +180,7 @@ AbsRdbPredicates* AbsRdbPredicates::EqualTo(const std::string &field, const Valu
|
||||
return (AbsRdbPredicates *)AbsPredicates::EqualTo(field, value);
|
||||
}
|
||||
|
||||
AbsRdbPredicates* AbsRdbPredicates::NotEqualTo(const std::string &field, const ValueObject &value)
|
||||
AbsRdbPredicates *AbsRdbPredicates::NotEqualTo(const std::string &field, const ValueObject &value)
|
||||
{
|
||||
if (auto pval = std::get_if<std::string>(&value.value)) {
|
||||
predicates_.AddOperation(DistributedRdb::NOT_EQUAL_TO, field, *pval);
|
||||
@ -188,26 +188,26 @@ AbsRdbPredicates* AbsRdbPredicates::NotEqualTo(const std::string &field, const V
|
||||
return (AbsRdbPredicates *)AbsPredicates::NotEqualTo(field, value);
|
||||
}
|
||||
|
||||
AbsRdbPredicates* AbsRdbPredicates::And()
|
||||
AbsRdbPredicates *AbsRdbPredicates::And()
|
||||
{
|
||||
predicates_.AddOperation(DistributedRdb::AND, "", "");
|
||||
return (AbsRdbPredicates *)AbsPredicates::And();
|
||||
}
|
||||
|
||||
AbsRdbPredicates* AbsRdbPredicates::Or()
|
||||
AbsRdbPredicates *AbsRdbPredicates::Or()
|
||||
{
|
||||
predicates_.AddOperation(DistributedRdb::OR, "", "");
|
||||
return (AbsRdbPredicates *)AbsPredicates::Or();
|
||||
}
|
||||
|
||||
AbsRdbPredicates* AbsRdbPredicates::OrderByAsc(const std::string &field)
|
||||
AbsRdbPredicates *AbsRdbPredicates::OrderByAsc(const std::string &field)
|
||||
{
|
||||
std::string isAsc = "true";
|
||||
predicates_.AddOperation(DistributedRdb::ORDER_BY, field, isAsc);
|
||||
return (AbsRdbPredicates *)AbsPredicates::OrderByAsc(field);
|
||||
}
|
||||
|
||||
AbsRdbPredicates* AbsRdbPredicates::OrderByDesc(const std::string &field)
|
||||
AbsRdbPredicates *AbsRdbPredicates::OrderByDesc(const std::string &field)
|
||||
{
|
||||
std::string isAsc = "false";
|
||||
predicates_.AddOperation(DistributedRdb::ORDER_BY, field, isAsc);
|
||||
|
@ -29,10 +29,10 @@
|
||||
namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
void RowEntity::Put(const std::string& name, int32_t index, ValueObject&& value)
|
||||
void RowEntity::Put(const std::string &name, int32_t index, ValueObject &&value)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(indexs_.size())) {
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
auto it = values_.emplace(name, std::move(value));
|
||||
indexs_[index] = it.first;
|
||||
@ -144,13 +144,13 @@ int AbsResultSet::InitColumnNames()
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < names.size(); ++i) {
|
||||
columnMap_.insert(std::pair{names[i], i});
|
||||
columnMap_.insert(std::pair{ names[i], i });
|
||||
}
|
||||
columnCount_ = static_cast<int>(names.size());
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int AbsResultSet::GetBlob(int columnIndex, std::vector<uint8_t>& blob)
|
||||
int AbsResultSet::GetBlob(int columnIndex, std::vector<uint8_t> &blob)
|
||||
{
|
||||
ValueObject object;
|
||||
int errorCode = Get(columnIndex, object);
|
||||
@ -196,7 +196,7 @@ int AbsResultSet::GetInt(int columnIndex, int &value)
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int AbsResultSet::GetLong(int columnIndex, int64_t& value)
|
||||
int AbsResultSet::GetLong(int columnIndex, int64_t &value)
|
||||
{
|
||||
ValueObject object;
|
||||
int errorCode = Get(columnIndex, object);
|
||||
@ -213,7 +213,7 @@ int AbsResultSet::GetLong(int columnIndex, int64_t& value)
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int AbsResultSet::GetDouble(int columnIndex, double& value)
|
||||
int AbsResultSet::GetDouble(int columnIndex, double &value)
|
||||
{
|
||||
ValueObject object;
|
||||
int errorCode = Get(columnIndex, object);
|
||||
@ -399,7 +399,7 @@ int AbsResultSet::GetColumnIndex(const std::string &columnName, int &columnIndex
|
||||
lowerName = lowerName.substr(periodIndex + 1);
|
||||
}
|
||||
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
|
||||
for (const auto& [name, index] : columnMap_) {
|
||||
for (const auto &[name, index] : columnMap_) {
|
||||
std::string temp = name;
|
||||
std::transform(name.begin(), name.end(), temp.begin(), ::tolower);
|
||||
if (lowerName == temp) {
|
||||
@ -425,7 +425,7 @@ int AbsResultSet::GetColumnName(int columnIndex, std::string &columnName)
|
||||
return E_COLUMN_OUT_RANGE;
|
||||
}
|
||||
|
||||
for (const auto& [name, index] : columnMap_) {
|
||||
for (const auto &[name, index] : columnMap_) {
|
||||
if (index == columnIndex) {
|
||||
columnName = name;
|
||||
return E_OK;
|
||||
|
@ -82,7 +82,7 @@ int AbsSharedResultSet::GetColumnType(int columnIndex, ColumnType &columnType)
|
||||
if (errorCode != E_OK) {
|
||||
return errorCode;
|
||||
}
|
||||
SharedBlock::CellUnit* cellUnit = block->GetCellUnit(block->GetBlockPos(), (uint32_t)columnIndex);
|
||||
SharedBlock::CellUnit *cellUnit = block->GetCellUnit(block->GetBlockPos(), (uint32_t)columnIndex);
|
||||
if (!cellUnit) {
|
||||
LOG_ERROR("AbsSharedResultSet::GetColumnType cellUnit is null!");
|
||||
return E_ERROR;
|
||||
@ -140,7 +140,7 @@ int AbsSharedResultSet::GetString(int columnIndex, std::string &value)
|
||||
return AbsResultSet::GetString(columnIndex, value);
|
||||
}
|
||||
|
||||
int AbsSharedResultSet::Get(int32_t col, ValueObject& value)
|
||||
int AbsSharedResultSet::Get(int32_t col, ValueObject &value)
|
||||
{
|
||||
auto block = GetBlock();
|
||||
int errorCode = CheckState(col);
|
||||
@ -251,7 +251,7 @@ void AbsSharedResultSet::Finalize()
|
||||
Close();
|
||||
}
|
||||
|
||||
int AbsSharedResultSet::GetCustomerValue(int index, ValueObject& value, SharedBlock *block)
|
||||
int AbsSharedResultSet::GetCustomerValue(int index, ValueObject &value, SharedBlock *block)
|
||||
{
|
||||
auto *cellUnit = block->GetCellUnit(block->GetBlockPos(), index);
|
||||
if (cellUnit == nullptr) {
|
||||
@ -310,7 +310,7 @@ int AbsSharedResultSet::CheckState(int columnIndex)
|
||||
if (rowPos_ < 0 || rowPos_ >= count) {
|
||||
return E_ROW_OUT_RANGE;
|
||||
}
|
||||
|
||||
|
||||
GetColumnCount(count);
|
||||
if (columnIndex >= count || columnIndex < 0) {
|
||||
return E_COLUMN_OUT_RANGE;
|
||||
|
@ -30,17 +30,17 @@ BigInteger::BigInteger(int32_t sign, std::vector<uint64_t>&& trueForm)
|
||||
{
|
||||
}
|
||||
|
||||
BigInteger::BigInteger(const BigInteger& other)
|
||||
BigInteger::BigInteger(const BigInteger &other)
|
||||
{
|
||||
operator=(other);
|
||||
}
|
||||
|
||||
BigInteger::BigInteger(BigInteger&& other)
|
||||
BigInteger::BigInteger(BigInteger &&other)
|
||||
{
|
||||
operator=(std::move(other));
|
||||
}
|
||||
|
||||
BigInteger& BigInteger::operator=(const BigInteger& other)
|
||||
BigInteger &BigInteger::operator=(const BigInteger &other)
|
||||
{
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
@ -50,7 +50,7 @@ BigInteger& BigInteger::operator=(const BigInteger& other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
BigInteger& BigInteger::operator=(BigInteger&& other)
|
||||
BigInteger &BigInteger::operator=(BigInteger &&other)
|
||||
{
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
@ -61,7 +61,7 @@ BigInteger& BigInteger::operator=(BigInteger&& other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool BigInteger::operator==(const BigInteger& other)
|
||||
bool BigInteger::operator==(const BigInteger &other)
|
||||
{
|
||||
if (sign_ != other.sign_) {
|
||||
return false;
|
||||
@ -84,7 +84,7 @@ size_t BigInteger::Size() const
|
||||
return value_.size();
|
||||
}
|
||||
|
||||
const uint64_t* BigInteger::TrueForm() const
|
||||
const uint64_t *BigInteger::TrueForm() const
|
||||
{
|
||||
return value_.data();
|
||||
}
|
||||
@ -93,4 +93,4 @@ std::vector<uint64_t> BigInteger::Value() const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::NativeRdb
|
||||
|
@ -330,5 +330,5 @@ int CacheResultSet::GetSize(int columnIndex, size_t &size)
|
||||
{
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
}
|
||||
} // namespace NativeRdb
|
||||
} // namespace OHOS
|
@ -106,7 +106,7 @@ int32_t Connection::RegisterCreator(int32_t dbType, Creator creator)
|
||||
if (g_creators[dbType] != nullptr) {
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
|
||||
g_creators[dbType] = creator;
|
||||
return E_OK;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
#define LOG_TAG "DelayNotify"
|
||||
#include "delay_notify.h"
|
||||
|
||||
#include "logger.h"
|
||||
namespace OHOS::NativeRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
@ -45,7 +46,7 @@ void DelayNotify::UpdateNotify(const DistributedRdb::RdbChangedData &changedData
|
||||
LOG_DEBUG("Update changed data.");
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
for (auto& [k, v] : changedData.tableData) {
|
||||
for (auto &[k, v] : changedData.tableData) {
|
||||
if (!v.isTrackedDataChange) {
|
||||
continue;
|
||||
}
|
||||
@ -148,7 +149,7 @@ void DelayNotify::ExecuteTask()
|
||||
if (errCode != 0) {
|
||||
LOG_ERROR("NotifyDataChange is failed, err is %{public}d.", errCode);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
for (auto& [k, v] : changedData.tableData) {
|
||||
for (auto &[k, v] : changedData.tableData) {
|
||||
changedData_.tableData.insert_or_assign(k, v);
|
||||
}
|
||||
return;
|
||||
@ -194,4 +195,4 @@ PauseDelayNotify::~PauseDelayNotify()
|
||||
delayNotifier_->Resume();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::NativeRdb
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
#define LOG_TAG "GRD_API_MANAGER"
|
||||
#include "grd_api_manager.h"
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
@ -92,4 +93,3 @@ GRD_APIInfo GetApiInfoInstance()
|
||||
|
||||
} // namespace NativeRdb
|
||||
} // namespace OHOS
|
||||
|
||||
|
@ -63,8 +63,8 @@ size_t RawDataParser::ParserRawData(const uint8_t *data, size_t length, Assets &
|
||||
return 0;
|
||||
}
|
||||
std::vector<uint8_t> alignData;
|
||||
alignData.assign(data, data + sizeof (ASSETS_MAGIC));
|
||||
used += sizeof (ASSETS_MAGIC);
|
||||
alignData.assign(data, data + sizeof(ASSETS_MAGIC));
|
||||
used += sizeof(ASSETS_MAGIC);
|
||||
auto hostMagicWord = Endian::LeToH(*(reinterpret_cast<decltype(&ASSETS_MAGIC)>(alignData.data())));
|
||||
if (hostMagicWord != ASSETS_MAGIC) {
|
||||
return 0;
|
||||
@ -99,8 +99,8 @@ std::vector<uint8_t> RawDataParser::PackageRawData(const Asset &asset)
|
||||
auto leMagic = Endian::HToLe(ASSET_MAGIC);
|
||||
auto magicU8 = reinterpret_cast<uint8_t *>(const_cast<uint32_t *>(&leMagic));
|
||||
rawData.insert(rawData.end(), magicU8, magicU8 + sizeof(ASSET_MAGIC));
|
||||
rawData.insert(rawData.end(), reinterpret_cast<uint8_t *>(&size),
|
||||
reinterpret_cast<uint8_t *>(&size) + sizeof(size));
|
||||
rawData.insert(
|
||||
rawData.end(), reinterpret_cast<uint8_t *>(&size), reinterpret_cast<uint8_t *>(&size) + sizeof(size));
|
||||
rawData.insert(rawData.end(), data.begin(), data.end());
|
||||
return rawData;
|
||||
}
|
||||
@ -132,7 +132,7 @@ size_t RawDataParser::ParserRawData(const uint8_t *data, size_t length, std::map
|
||||
return used;
|
||||
}
|
||||
|
||||
size_t RawDataParser::ParserRawData(const uint8_t* data, size_t length, BigInteger& bigint)
|
||||
size_t RawDataParser::ParserRawData(const uint8_t *data, size_t length, BigInteger &bigint)
|
||||
{
|
||||
size_t used = 0;
|
||||
if (sizeof(BIG_INT) > length - used) {
|
||||
@ -176,7 +176,7 @@ size_t RawDataParser::ParserRawData(const uint8_t* data, size_t length, BigInteg
|
||||
return used;
|
||||
}
|
||||
|
||||
size_t RawDataParser::ParserRawData(const uint8_t* data, size_t length, RawDataParser::Floats& floats)
|
||||
size_t RawDataParser::ParserRawData(const uint8_t *data, size_t length, RawDataParser::Floats &floats)
|
||||
{
|
||||
size_t used = 0;
|
||||
if (sizeof(FLOUT32_ARRAY) > length - used) {
|
||||
@ -219,12 +219,12 @@ std::vector<uint8_t> RawDataParser::PackageRawData(const std::map<std::string, A
|
||||
return PackageRawData(res);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> RawDataParser::PackageRawData(const BigInteger& bigint)
|
||||
std::vector<uint8_t> RawDataParser::PackageRawData(const BigInteger &bigint)
|
||||
{
|
||||
size_t offset = 0;
|
||||
auto size = sizeof(BIG_INT) + sizeof(uint32_t) + sizeof(uint64_t) * (bigint.Size() + 1);
|
||||
std::vector<uint8_t> rawData(size, 0);
|
||||
uint8_t* data = rawData.data();
|
||||
uint8_t *data = rawData.data();
|
||||
*(reinterpret_cast<uint32_t *>(&data[offset])) = Endian::HToLe(BIG_INT);
|
||||
offset += sizeof(BIG_INT);
|
||||
*(reinterpret_cast<uint32_t *>(&data[offset])) = Endian::HToLe(uint32_t(bigint.Sign()));
|
||||
@ -242,12 +242,12 @@ std::vector<uint8_t> RawDataParser::PackageRawData(const BigInteger& bigint)
|
||||
return rawData;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> RawDataParser::PackageRawData(const RawDataParser::Floats& floats)
|
||||
std::vector<uint8_t> RawDataParser::PackageRawData(const RawDataParser::Floats &floats)
|
||||
{
|
||||
size_t offset = 0;
|
||||
auto size = sizeof(FLOUT32_ARRAY) + sizeof(uint32_t) + sizeof(float) * floats.size();
|
||||
std::vector<uint8_t> rawData(size, 0);
|
||||
uint8_t* data = rawData.data();
|
||||
uint8_t *data = rawData.data();
|
||||
*(reinterpret_cast<uint32_t *>(&data[offset])) = Endian::HToLe(FLOUT32_ARRAY);
|
||||
offset += sizeof(FLOUT32_ARRAY);
|
||||
*(reinterpret_cast<uint32_t *>(&data[offset])) = Endian::HToLe(uint32_t(floats.size()));
|
||||
|
@ -16,10 +16,11 @@
|
||||
#include "rd_connection.h"
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "logger.h"
|
||||
#include "grd_api_manager.h"
|
||||
#include "logger.h"
|
||||
#include "rd_statement.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_security_manager.h"
|
||||
@ -36,14 +37,14 @@ const int32_t RdConnection::regRepairer_ = Connection::RegisterRepairer(DB_VECTO
|
||||
__attribute__((used))
|
||||
const int32_t RdConnection::regDeleter_ = Connection::RegisterDeleter(DB_VECTOR, RdConnection::Delete);
|
||||
|
||||
std::pair<int32_t, std::shared_ptr<Connection>> RdConnection::Create(const RdbStoreConfig& config, bool isWrite)
|
||||
std::pair<int32_t, std::shared_ptr<Connection>> RdConnection::Create(const RdbStoreConfig &config, bool isWrite)
|
||||
{
|
||||
std::pair<int32_t, std::shared_ptr<Connection>> result = { E_ERROR, nullptr };
|
||||
if (!IsUsingArkData() || config.GetStorageMode() == StorageMode::MODE_MEMORY) {
|
||||
result.first = E_NOT_SUPPORT;
|
||||
return result;
|
||||
}
|
||||
auto& [errCode, conn] = result;
|
||||
auto &[errCode, conn] = result;
|
||||
for (size_t i = 0; i < ITERS_COUNT; i++) {
|
||||
std::shared_ptr<RdConnection> connection = std::make_shared<RdConnection>(config, isWrite);
|
||||
if (connection == nullptr) {
|
||||
@ -59,7 +60,7 @@ std::pair<int32_t, std::shared_ptr<Connection>> RdConnection::Create(const RdbSt
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t RdConnection::Repair(const RdbStoreConfig& config)
|
||||
int32_t RdConnection::Repair(const RdbStoreConfig &config)
|
||||
{
|
||||
std::string dbPath = "";
|
||||
auto errCode = SqliteGlobalConfig::GetDbPath(config, dbPath);
|
||||
@ -131,7 +132,6 @@ std::string RdConnection::GetConfigStr(const std::vector<uint8_t> &keys, bool is
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
int RdConnection::InnerOpen(const RdbStoreConfig &config)
|
||||
{
|
||||
std::string dbPath = "";
|
||||
@ -177,7 +177,7 @@ int32_t RdConnection::OnInitialize()
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
std::pair<int32_t, RdConnection::Stmt> RdConnection::CreateStatement(const std::string& sql, Connection::SConn conn)
|
||||
std::pair<int32_t, RdConnection::Stmt> RdConnection::CreateStatement(const std::string &sql, Connection::SConn conn)
|
||||
{
|
||||
auto stmt = std::make_shared<RdStatement>();
|
||||
stmt->conn_ = conn;
|
||||
@ -205,7 +205,7 @@ bool RdConnection::IsWriter() const
|
||||
return isWriter_;
|
||||
}
|
||||
|
||||
int32_t RdConnection::ReSetKey(const RdbStoreConfig& config)
|
||||
int32_t RdConnection::ReSetKey(const RdbStoreConfig &config)
|
||||
{
|
||||
if (!IsWriter()) {
|
||||
return E_OK;
|
||||
@ -243,17 +243,17 @@ int32_t RdConnection::LimitWalSize()
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t RdConnection::ConfigLocale(const std::string& localeStr)
|
||||
int32_t RdConnection::ConfigLocale(const std::string &localeStr)
|
||||
{
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t RdConnection::CleanDirtyData(const std::string& table, uint64_t cursor)
|
||||
int32_t RdConnection::CleanDirtyData(const std::string &table, uint64_t cursor)
|
||||
{
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t RdConnection::SubscribeTableChanges(const Connection::Notifier& notifier)
|
||||
int32_t RdConnection::SubscribeTableChanges(const Connection::Notifier ¬ifier)
|
||||
{
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
@ -273,20 +273,20 @@ int32_t RdConnection::ClearCache()
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t RdConnection::Subscribe(const std::string& event,
|
||||
const std::shared_ptr<DistributedRdb::RdbStoreObserver>& observer)
|
||||
int32_t RdConnection::Subscribe(
|
||||
const std::string &event, const std::shared_ptr<DistributedRdb::RdbStoreObserver> &observer)
|
||||
{
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t RdConnection::Unsubscribe(const std::string& event,
|
||||
const std::shared_ptr<DistributedRdb::RdbStoreObserver>& observer)
|
||||
int32_t RdConnection::Unsubscribe(
|
||||
const std::string &event, const std::shared_ptr<DistributedRdb::RdbStoreObserver> &observer)
|
||||
{
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t RdConnection::Backup(const std::string &databasePath, const std::vector<uint8_t> &destEncryptKey,
|
||||
bool isAsync, SlaveStatus &slaveStatus)
|
||||
int32_t RdConnection::Backup(const std::string &databasePath, const std::vector<uint8_t> &destEncryptKey, bool isAsync,
|
||||
SlaveStatus &slaveStatus)
|
||||
{
|
||||
if (!destEncryptKey.empty() && !config_.IsEncrypt()) {
|
||||
return RdUtils::RdDbBackup(dbHandle_, databasePath.c_str(), destEncryptKey);
|
||||
@ -300,8 +300,8 @@ int32_t RdConnection::Backup(const std::string &databasePath, const std::vector<
|
||||
return RdUtils::RdDbBackup(dbHandle_, databasePath.c_str(), {});
|
||||
}
|
||||
|
||||
int32_t RdConnection::Restore(const std::string &databasePath, const std::vector<uint8_t> &destEncryptKey,
|
||||
SlaveStatus &slaveStatus)
|
||||
int32_t RdConnection::Restore(
|
||||
const std::string &databasePath, const std::vector<uint8_t> &destEncryptKey, SlaveStatus &slaveStatus)
|
||||
{
|
||||
auto ret = RdUtils::RdDbClose(dbHandle_, 0);
|
||||
if (ret != E_OK) {
|
||||
|
@ -15,19 +15,19 @@
|
||||
#define LOG_TAG "RdStatement"
|
||||
#include "rd_statement.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
#include "logger.h"
|
||||
#include "raw_data_parser.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rd_connection.h"
|
||||
#include "rd_utils.h"
|
||||
#include "sqlite_global_config.h"
|
||||
#include "sqlite_utils.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_fault_hiview_reporter.h"
|
||||
#include "sqlite_global_config.h"
|
||||
#include "sqlite_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
@ -181,8 +181,8 @@ int RdStatement::InnerBindBlobTypeArgs(const ValueObject &arg, uint32_t index) c
|
||||
case ValueObjectType::TYPE_BLOB: {
|
||||
std::vector<uint8_t> blob;
|
||||
arg.GetBlob(blob);
|
||||
ret = RdUtils::RdSqlBindBlob(stmtHandle_, index, static_cast<const void *>(blob.data()), blob.size(),
|
||||
nullptr);
|
||||
ret = RdUtils::RdSqlBindBlob(
|
||||
stmtHandle_, index, static_cast<const void *>(blob.data()), blob.size(), nullptr);
|
||||
break;
|
||||
}
|
||||
case ValueObjectType::TYPE_BOOL: {
|
||||
@ -195,23 +195,23 @@ int RdStatement::InnerBindBlobTypeArgs(const ValueObject &arg, uint32_t index) c
|
||||
ValueObject::Asset asset;
|
||||
arg.GetAsset(asset);
|
||||
auto rawData = RawDataParser::PackageRawData(asset);
|
||||
ret = RdUtils::RdSqlBindBlob(stmtHandle_, index, static_cast<const void *>(rawData.data()),
|
||||
rawData.size(), nullptr);
|
||||
ret = RdUtils::RdSqlBindBlob(
|
||||
stmtHandle_, index, static_cast<const void *>(rawData.data()), rawData.size(), nullptr);
|
||||
break;
|
||||
}
|
||||
case ValueObjectType::TYPE_ASSETS: {
|
||||
ValueObject::Assets assets;
|
||||
arg.GetAssets(assets);
|
||||
auto rawData = RawDataParser::PackageRawData(assets);
|
||||
ret = RdUtils::RdSqlBindBlob(stmtHandle_, index, static_cast<const void *>(rawData.data()),
|
||||
rawData.size(), nullptr);
|
||||
ret = RdUtils::RdSqlBindBlob(
|
||||
stmtHandle_, index, static_cast<const void *>(rawData.data()), rawData.size(), nullptr);
|
||||
break;
|
||||
}
|
||||
case ValueObjectType::TYPE_VECS: {
|
||||
ValueObject::FloatVector vectors;
|
||||
arg.GetVecs(vectors);
|
||||
ret = RdUtils::RdSqlBindFloatVector(stmtHandle_, index,
|
||||
static_cast<float *>(vectors.data()), vectors.size(), nullptr);
|
||||
ret = RdUtils::RdSqlBindFloatVector(
|
||||
stmtHandle_, index, static_cast<float *>(vectors.data()), vectors.size(), nullptr);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -237,7 +237,7 @@ int RdStatement::IsValid(int index) const
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t RdStatement::Prepare(const std::string& sql)
|
||||
int32_t RdStatement::Prepare(const std::string &sql)
|
||||
{
|
||||
if (dbHandle_ == nullptr) {
|
||||
return E_ERROR;
|
||||
@ -245,16 +245,16 @@ int32_t RdStatement::Prepare(const std::string& sql)
|
||||
return Prepare(dbHandle_, 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)));
|
||||
refArgs.emplace_back(std::ref(const_cast<ValueObject &>(object)));
|
||||
}
|
||||
return Bind(refArgs);
|
||||
}
|
||||
|
||||
int32_t RdStatement::Bind(const std::vector<std::reference_wrapper<ValueObject>>& args)
|
||||
int32_t RdStatement::Bind(const std::vector<std::reference_wrapper<ValueObject>> &args)
|
||||
{
|
||||
uint32_t index = 1;
|
||||
int ret = E_OK;
|
||||
@ -322,16 +322,16 @@ int32_t RdStatement::Reset()
|
||||
return RdUtils::RdSqlReset(stmtHandle_);
|
||||
}
|
||||
|
||||
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)));
|
||||
refArgs.emplace_back(std::ref(const_cast<ValueObject &>(object)));
|
||||
}
|
||||
return Execute(refArgs);
|
||||
}
|
||||
|
||||
int32_t RdStatement::Execute(const std::vector<std::reference_wrapper<ValueObject>>& args)
|
||||
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
|
||||
@ -351,7 +351,7 @@ int32_t RdStatement::Execute(const std::vector<std::reference_wrapper<ValueObjec
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::pair<int, ValueObject> RdStatement::ExecuteForValue(const std::vector<ValueObject>& args)
|
||||
std::pair<int, ValueObject> RdStatement::ExecuteForValue(const std::vector<ValueObject> &args)
|
||||
{
|
||||
int ret = E_OK;
|
||||
if (readOnly_ && strcmp(sql_.c_str(), GlobalExpr::PRAGMA_VERSION) == 0) {
|
||||
@ -397,7 +397,7 @@ std::pair<int32_t, std::string> RdStatement::GetColumnName(int32_t index) const
|
||||
if (ret != E_OK) {
|
||||
return { ret, "" };
|
||||
}
|
||||
const char* name = RdUtils::RdSqlColName(stmtHandle_, index);
|
||||
const char *name = RdUtils::RdSqlColName(stmtHandle_, index);
|
||||
if (name == nullptr) {
|
||||
LOG_ERROR("column_name is null.");
|
||||
return { E_ERROR, "" };
|
||||
@ -464,8 +464,7 @@ std::pair<int32_t, ValueObject> RdStatement::GetColumn(int32_t index) const
|
||||
break;
|
||||
case ColumnType::TYPE_FLOAT32_ARRAY: {
|
||||
uint32_t dim = 0;
|
||||
auto vectors =
|
||||
reinterpret_cast<const float *>(RdUtils::RdSqlColumnFloatVector(stmtHandle_, index, &dim));
|
||||
auto vectors = reinterpret_cast<const float *>(RdUtils::RdSqlColumnFloatVector(stmtHandle_, index, &dim));
|
||||
std::vector<float> vecData;
|
||||
if (dim > 0 || vectors != nullptr) {
|
||||
vecData.resize(dim);
|
||||
@ -501,7 +500,7 @@ bool RdStatement::SupportBlockInfo() const
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t RdStatement::FillBlockInfo(SharedBlockInfo* info) const
|
||||
int32_t RdStatement::FillBlockInfo(SharedBlockInfo *info) const
|
||||
{
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
@ -16,14 +16,15 @@
|
||||
#define LOG_TAG "RdUtils"
|
||||
#include "rd_utils.h"
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <securec.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "grd_error.h"
|
||||
#include "grd_api_manager.h"
|
||||
#include "grd_error.h"
|
||||
#include "logger.h"
|
||||
#include "remote_result_set.h"
|
||||
|
||||
@ -40,13 +41,13 @@ struct GrdErrnoPair {
|
||||
|
||||
const GrdErrnoPair GRD_ERRNO_MAP[] = {
|
||||
{ GRD_OK, E_OK },
|
||||
{ GRD_REBUILD_DATABASE, E_OK},
|
||||
{ GRD_REBUILD_DATABASE, E_OK },
|
||||
{ GRD_NO_DATA, E_NO_MORE_ROWS },
|
||||
{ GRD_DATA_CORRUPTED, E_SQLITE_CORRUPT },
|
||||
{ GRD_INVALID_FILE_FORMAT, E_SQLITE_CORRUPT },
|
||||
{ GRD_PRIMARY_KEY_VIOLATION, E_SQLITE_CONSTRAINT},
|
||||
{ GRD_RESTRICT_VIOLATION, E_SQLITE_CONSTRAINT},
|
||||
{ GRD_CONSTRAINT_CHECK_VIOLATION, E_SQLITE_CONSTRAINT},
|
||||
{ GRD_INVALID_FILE_FORMAT, E_SQLITE_CORRUPT },
|
||||
{ GRD_PRIMARY_KEY_VIOLATION, E_SQLITE_CONSTRAINT },
|
||||
{ GRD_RESTRICT_VIOLATION, E_SQLITE_CONSTRAINT },
|
||||
{ GRD_CONSTRAINT_CHECK_VIOLATION, E_SQLITE_CONSTRAINT },
|
||||
{ GRD_NOT_SUPPORT, E_NOT_SUPPORT },
|
||||
{ GRD_OVER_LIMIT, E_SQLITE_CONSTRAINT },
|
||||
{ GRD_INVALID_ARGS, E_INVALID_ARGS },
|
||||
@ -62,12 +63,12 @@ const GrdErrnoPair GRD_ERRNO_MAP[] = {
|
||||
{ GRD_PASSWORD_UNMATCHED, E_SQLITE_CANTOPEN },
|
||||
{ GRD_PASSWORD_NEED_REKEY, E_CHANGE_UNENCRYPTED_TO_ENCRYPTED },
|
||||
|
||||
{ GRD_NAME_TOO_LONG, E_SQLITE_CONSTRAINT},
|
||||
{ GRD_INVALID_TABLE_DEFINITION, E_SQLITE_SCHEMA},
|
||||
{ GRD_SEMANTIC_ERROR, E_NOT_SUPPORT_THE_SQL},
|
||||
{ GRD_SYNTAX_ERROR, E_NOT_SUPPORT_THE_SQL},
|
||||
{ GRD_DATA_MISMATCH, E_SQLITE_MISMATCH},
|
||||
{ GRD_WRONG_STMT_OBJECT, E_INVALID_OBJECT_TYPE},
|
||||
{ GRD_NAME_TOO_LONG, E_SQLITE_CONSTRAINT },
|
||||
{ GRD_INVALID_TABLE_DEFINITION, E_SQLITE_SCHEMA },
|
||||
{ GRD_SEMANTIC_ERROR, E_NOT_SUPPORT_THE_SQL },
|
||||
{ GRD_SYNTAX_ERROR, E_NOT_SUPPORT_THE_SQL },
|
||||
{ GRD_DATA_MISMATCH, E_SQLITE_MISMATCH },
|
||||
{ GRD_WRONG_STMT_OBJECT, E_INVALID_OBJECT_TYPE },
|
||||
{ GRD_DATA_CONFLICT, E_INVALID_CONFLICT_FLAG },
|
||||
|
||||
{ GRD_INNER_ERR, E_ERROR },
|
||||
@ -292,8 +293,7 @@ void RdSqlFreeFloatArr(void *floatElement)
|
||||
delete[] ((float *)floatElement);
|
||||
}
|
||||
|
||||
int RdUtils::RdSqlBindFloatVector(GRD_SqlStmt *stmt, uint32_t idx, float *val,
|
||||
uint32_t dim, void (*freeFunc)(void *))
|
||||
int RdUtils::RdSqlBindFloatVector(GRD_SqlStmt *stmt, uint32_t idx, float *val, uint32_t dim, void (*freeFunc)(void *))
|
||||
{
|
||||
if (GRD_KVApiInfo.DBSqlBindFloatVector == nullptr) {
|
||||
GRD_KVApiInfo = GetApiInfoInstance();
|
||||
@ -536,7 +536,6 @@ int RdUtils::RdDbRekey(const char *dbFile, const char *configStr, const std::vec
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int RdUtils::RdDbGetVersion(GRD_DB *db, GRD_ConfigTypeE type, int &version)
|
||||
{
|
||||
if (GRD_KVApiInfo.DBGetConfigApi == nullptr) {
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
namespace OHOS::DistributedRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
using RdbServiceProxy = DistributedRdb::RdbServiceProxy;
|
||||
using RdbServiceProxy = DistributedRdb::RdbServiceProxy;
|
||||
using namespace OHOS::NativeRdb;
|
||||
using namespace OHOS::DistributedRdb::RelationalStore;
|
||||
|
||||
@ -36,8 +36,7 @@ class DeathStub : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedRdb.DeathStub");
|
||||
};
|
||||
class DeathStubImpl : public IRemoteStub<DeathStub> {
|
||||
};
|
||||
class DeathStubImpl : public IRemoteStub<DeathStub> {};
|
||||
std::shared_ptr<RdbStoreDataServiceProxy> RdbManagerImpl::GetDistributedDataManager(const std::string &bundleName)
|
||||
{
|
||||
auto manager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
@ -61,11 +60,11 @@ std::shared_ptr<RdbStoreDataServiceProxy> RdbManagerImpl::GetDistributedDataMana
|
||||
return std::shared_ptr<RdbStoreDataServiceProxy>(dataService.GetRefPtr(), [dataService, observer](const auto *) {});
|
||||
}
|
||||
|
||||
static void LinkToDeath(const sptr<IRemoteObject>& remote)
|
||||
static void LinkToDeath(const sptr<IRemoteObject> &remote)
|
||||
{
|
||||
auto& manager = RdbManagerImpl::GetInstance();
|
||||
sptr<RdbManagerImpl::ServiceDeathRecipient> deathRecipient =
|
||||
new(std::nothrow) RdbManagerImpl::ServiceDeathRecipient(&manager);
|
||||
auto &manager = RdbManagerImpl::GetInstance();
|
||||
sptr<RdbManagerImpl::ServiceDeathRecipient> deathRecipient = new (std::nothrow)
|
||||
RdbManagerImpl::ServiceDeathRecipient(&manager);
|
||||
if (deathRecipient == nullptr) {
|
||||
LOG_ERROR("new ServiceDeathRecipient failed.");
|
||||
return;
|
||||
@ -84,7 +83,7 @@ RdbManagerImpl::~RdbManagerImpl()
|
||||
LOG_INFO("destroy.");
|
||||
}
|
||||
|
||||
RdbManagerImpl& RdbManagerImpl::GetInstance()
|
||||
RdbManagerImpl &RdbManagerImpl::GetInstance()
|
||||
{
|
||||
static RdbManagerImpl manager;
|
||||
return manager;
|
||||
@ -187,9 +186,9 @@ sptr<IRemoteObject> RdbStoreDataServiceProxy::GetFeatureInterface(const std::str
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption mo { MessageOption::TF_SYNC };
|
||||
int32_t error = Remote()->SendRequest(
|
||||
static_cast<uint32_t>(KvStoreInterfaceCode::GET_FEATURE_INTERFACE), data, reply, mo);
|
||||
MessageOption mo{ MessageOption::TF_SYNC };
|
||||
int32_t error =
|
||||
Remote()->SendRequest(static_cast<uint32_t>(KvStoreInterfaceCode::GET_FEATURE_INTERFACE), data, reply, mo);
|
||||
if (error != 0) {
|
||||
LOG_ERROR("SendRequest returned %{public}d", error);
|
||||
return nullptr;
|
||||
@ -217,9 +216,9 @@ int32_t RdbStoreDataServiceProxy::RegisterDeathObserver(const std::string &bundl
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption mo { MessageOption::TF_SYNC };
|
||||
int32_t error = Remote()->SendRequest(
|
||||
static_cast<uint32_t>(KvStoreInterfaceCode::REGISTER_DEATH_OBSERVER), data, reply, mo);
|
||||
MessageOption mo{ MessageOption::TF_SYNC };
|
||||
int32_t error =
|
||||
Remote()->SendRequest(static_cast<uint32_t>(KvStoreInterfaceCode::REGISTER_DEATH_OBSERVER), data, reply, mo);
|
||||
if (error != 0) {
|
||||
LOG_ERROR("SendRequest returned %{public}d", error);
|
||||
return E_ERROR;
|
||||
|
@ -34,7 +34,7 @@ RdbNotifierStub::~RdbNotifierStub() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
bool RdbNotifierStub::CheckInterfaceToken(MessageParcel& data)
|
||||
bool RdbNotifierStub::CheckInterfaceToken(MessageParcel &data)
|
||||
{
|
||||
auto localDescriptor = GetDescriptor();
|
||||
auto remoteDescriptor = data.ReadInterfaceToken();
|
||||
@ -45,8 +45,7 @@ bool RdbNotifierStub::CheckInterfaceToken(MessageParcel& data)
|
||||
return true;
|
||||
}
|
||||
|
||||
int RdbNotifierStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
int RdbNotifierStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
LOG_DEBUG("code:%{public}u, callingPid:%{public}d", code, IPCSkeleton::GetCallingPid());
|
||||
if (!CheckInterfaceToken(data)) {
|
||||
|
@ -17,11 +17,12 @@
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <securec.h>
|
||||
#include <string>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "directory_ex.h"
|
||||
#include "file_ex.h"
|
||||
#include "hks_api.h"
|
||||
@ -106,7 +107,7 @@ int32_t RdbSecurityManager::HksLoopUpdate(const struct HksBlob *handle, const st
|
||||
return HKS_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
struct HksBlob input = {MAX_UPDATE_SIZE, inData->data};
|
||||
struct HksBlob input = { MAX_UPDATE_SIZE, inData->data };
|
||||
uint8_t *end = inData->data + inData->size - 1;
|
||||
outData->size = 0;
|
||||
struct HksBlob output = { MAX_OUTDATA_SIZE, outData->data };
|
||||
@ -162,7 +163,7 @@ int32_t RdbSecurityManager::HksDecryptThreeStage(const struct HksBlob *keyAlias,
|
||||
|
||||
RdbSecurityManager::RdbSecurityManager()
|
||||
: nonce_(RDB_HKS_BLOB_TYPE_NONCE, RDB_HKS_BLOB_TYPE_NONCE + strlen(RDB_HKS_BLOB_TYPE_NONCE)),
|
||||
aad_(RDB_HKS_BLOB_TYPE_AAD, RDB_HKS_BLOB_TYPE_AAD + strlen(RDB_HKS_BLOB_TYPE_AAD)){};
|
||||
aad_(RDB_HKS_BLOB_TYPE_AAD, RDB_HKS_BLOB_TYPE_AAD + strlen(RDB_HKS_BLOB_TYPE_AAD)) {};
|
||||
|
||||
RdbSecurityManager::~RdbSecurityManager() = default;
|
||||
|
||||
|
@ -17,8 +17,8 @@
|
||||
|
||||
#include "itypes_util.h"
|
||||
#include "logger.h"
|
||||
#include "sqlite_utils.h"
|
||||
#include "result_set_proxy.h"
|
||||
#include "sqlite_utils.h"
|
||||
|
||||
namespace OHOS::DistributedRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
@ -90,8 +90,8 @@ int32_t RdbServiceProxy::InitNotifier(const RdbSyncerParam ¶m)
|
||||
int32_t RdbServiceProxy::InitNotifier(const RdbSyncerParam ¶m, sptr<IRemoteObject> notifier)
|
||||
{
|
||||
MessageParcel reply;
|
||||
int32_t status = IPC_SEND(
|
||||
static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_INIT_NOTIFIER), reply, param, notifier);
|
||||
int32_t status =
|
||||
IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_INIT_NOTIFIER), reply, param, notifier);
|
||||
if (status != RDB_OK) {
|
||||
LOG_ERROR("status:%{public}d, bundleName:%{public}s", status, param.bundleName_.c_str());
|
||||
}
|
||||
@ -107,16 +107,16 @@ uint32_t RdbServiceProxy::GetSeqNum()
|
||||
return value;
|
||||
}
|
||||
|
||||
std::pair<int32_t, Details> RdbServiceProxy::DoSync(const RdbSyncerParam& param, const Option &option,
|
||||
const PredicatesMemo &predicates)
|
||||
std::pair<int32_t, Details> RdbServiceProxy::DoSync(
|
||||
const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates)
|
||||
{
|
||||
std::pair<int32_t, Details> result{RDB_ERROR, {}};
|
||||
std::pair<int32_t, Details> result{ RDB_ERROR, {} };
|
||||
MessageParcel reply;
|
||||
auto &[status, details] = result;
|
||||
status = IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_SYNC), reply, param, option, predicates);
|
||||
if (status != RDB_OK) {
|
||||
LOG_ERROR("status:%{public}d, bundleName:%{public}s, storeName:%{public}s",
|
||||
status, param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str());
|
||||
LOG_ERROR("status:%{public}d, bundleName:%{public}s, storeName:%{public}s", status, param.bundleName_.c_str(),
|
||||
SqliteUtils::Anonymous(param.storeName_).c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -128,8 +128,8 @@ std::pair<int32_t, Details> RdbServiceProxy::DoSync(const RdbSyncerParam& param,
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t RdbServiceProxy::DoSync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates,
|
||||
const AsyncDetail &async)
|
||||
int32_t RdbServiceProxy::DoSync(
|
||||
const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates, const AsyncDetail &async)
|
||||
{
|
||||
auto [status, details] = DoSync(param, option, predicates);
|
||||
if (status != RDB_OK) {
|
||||
@ -146,8 +146,8 @@ int32_t RdbServiceProxy::DoSync(const RdbSyncerParam ¶m, const Option &optio
|
||||
int32_t RdbServiceProxy::DoAsync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates)
|
||||
{
|
||||
MessageParcel reply;
|
||||
int32_t status = IPC_SEND(
|
||||
static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_ASYNC), reply, param, option, predicates);
|
||||
int32_t status =
|
||||
IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_ASYNC), reply, param, option, predicates);
|
||||
if (status != RDB_OK) {
|
||||
LOG_ERROR("status:%{public}d, bundleName:%{public}s, storeName:%{public}s, seqNum:%{public}u", status,
|
||||
param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str(), option.seqNum);
|
||||
@ -155,8 +155,8 @@ int32_t RdbServiceProxy::DoAsync(const RdbSyncerParam ¶m, const Option &opti
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t RdbServiceProxy::DoAsync(const RdbSyncerParam& param, const Option &option,
|
||||
const PredicatesMemo &predicates, const AsyncDetail & callback)
|
||||
int32_t RdbServiceProxy::DoAsync(
|
||||
const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates, const AsyncDetail &callback)
|
||||
{
|
||||
Option asyncOption = option;
|
||||
if (callback != nullptr) {
|
||||
@ -176,22 +176,21 @@ int32_t RdbServiceProxy::DoAsync(const RdbSyncerParam& param, const Option &opti
|
||||
return RDB_OK;
|
||||
}
|
||||
|
||||
int32_t RdbServiceProxy::SetDistributedTables(const RdbSyncerParam& param, const std::vector<std::string> &tables,
|
||||
int32_t RdbServiceProxy::SetDistributedTables(const RdbSyncerParam ¶m, const std::vector<std::string> &tables,
|
||||
const std::vector<Reference> &references, bool isRebuild, int32_t type)
|
||||
{
|
||||
MessageParcel reply;
|
||||
int32_t status = IPC_SEND(
|
||||
static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_SET_DIST_TABLE), reply, param, tables, references,
|
||||
type, isRebuild);
|
||||
int32_t status = IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_SET_DIST_TABLE), reply, param,
|
||||
tables, references, type, isRebuild);
|
||||
if (status != RDB_OK) {
|
||||
LOG_ERROR("status:%{public}d, bundleName:%{public}s, storeName:%{public}s, type:%{public}d",
|
||||
status, param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str(), type);
|
||||
LOG_ERROR("status:%{public}d, bundleName:%{public}s, storeName:%{public}s, type:%{public}d", status,
|
||||
param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str(), type);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t RdbServiceProxy::Sync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates,
|
||||
const AsyncDetail &async)
|
||||
int32_t RdbServiceProxy::Sync(
|
||||
const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates, const AsyncDetail &async)
|
||||
{
|
||||
if (option.isAsync) {
|
||||
return DoAsync(param, option, predicates, async);
|
||||
@ -199,7 +198,7 @@ int32_t RdbServiceProxy::Sync(const RdbSyncerParam ¶m, const Option &option,
|
||||
return DoSync(param, option, predicates, async);
|
||||
}
|
||||
|
||||
std::string RdbServiceProxy::RemoveSuffix(const std::string& name)
|
||||
std::string RdbServiceProxy::RemoveSuffix(const std::string &name)
|
||||
{
|
||||
std::string suffix(".db");
|
||||
auto pos = name.rfind(suffix);
|
||||
@ -209,8 +208,8 @@ std::string RdbServiceProxy::RemoveSuffix(const std::string& name)
|
||||
return { name, 0, pos };
|
||||
}
|
||||
|
||||
int32_t RdbServiceProxy::Subscribe(const RdbSyncerParam ¶m, const SubscribeOption &option,
|
||||
RdbStoreObserver *observer)
|
||||
int32_t RdbServiceProxy::Subscribe(
|
||||
const RdbSyncerParam ¶m, const SubscribeOption &option, RdbStoreObserver *observer)
|
||||
{
|
||||
if (observer == nullptr) {
|
||||
return RDB_ERROR;
|
||||
@ -239,17 +238,16 @@ int32_t RdbServiceProxy::Subscribe(const RdbSyncerParam ¶m, const SubscribeO
|
||||
int32_t RdbServiceProxy::DoSubscribe(const RdbSyncerParam ¶m, const SubscribeOption &option)
|
||||
{
|
||||
MessageParcel reply;
|
||||
int32_t status = IPC_SEND(
|
||||
static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_SUBSCRIBE), reply, param, option);
|
||||
int32_t status = IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_SUBSCRIBE), reply, param, option);
|
||||
if (status != RDB_OK) {
|
||||
LOG_ERROR("status:%{public}d, bundleName:%{public}s, storeName:%{public}s",
|
||||
status, param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str());
|
||||
LOG_ERROR("status:%{public}d, bundleName:%{public}s, storeName:%{public}s", status, param.bundleName_.c_str(),
|
||||
SqliteUtils::Anonymous(param.storeName_).c_str());
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t RdbServiceProxy::UnSubscribe(const RdbSyncerParam ¶m, const SubscribeOption &option,
|
||||
RdbStoreObserver *observer)
|
||||
int32_t RdbServiceProxy::UnSubscribe(
|
||||
const RdbSyncerParam ¶m, const SubscribeOption &option, RdbStoreObserver *observer)
|
||||
{
|
||||
if (observer == nullptr) {
|
||||
LOG_ERROR("observer is null.");
|
||||
@ -261,9 +259,7 @@ int32_t RdbServiceProxy::UnSubscribe(const RdbSyncerParam ¶m, const Subscrib
|
||||
auto name = RemoveSuffix(param.storeName_);
|
||||
observers_.ComputeIfPresent(name, [observer](const auto &key, std::list<ObserverParam> &value) {
|
||||
LOG_INFO("before remove size=%{public}d", static_cast<int>(value.size()));
|
||||
value.remove_if([observer](const ObserverParam ¶m) {
|
||||
return param.observer == observer;
|
||||
});
|
||||
value.remove_if([observer](const ObserverParam ¶m) { return param.observer == observer; });
|
||||
LOG_INFO("after remove size=%{public}d", static_cast<int>(value.size()));
|
||||
return !(value.empty());
|
||||
});
|
||||
@ -460,11 +456,11 @@ void RdbServiceProxy::OnDataChange(
|
||||
{
|
||||
LOG_DEBUG("store:%{public}s data change from :%{public}s, dataType:%{public}d, origin:%{public}d.",
|
||||
SqliteUtils::Anonymous(origin.store).c_str(),
|
||||
origin.id.empty() ? "empty" : SqliteUtils::Anonymous(*origin.id.begin()).c_str(),
|
||||
origin.dataType, origin.origin);
|
||||
origin.id.empty() ? "empty" : SqliteUtils::Anonymous(*origin.id.begin()).c_str(), origin.dataType,
|
||||
origin.origin);
|
||||
auto name = RdbServiceProxy::RemoveSuffix(origin.store);
|
||||
observers_.ComputeIfPresent(name, [&origin, &primaries, info = std::move(changeInfo)](
|
||||
const auto &key, const std::list<ObserverParam> &value) mutable {
|
||||
const auto &key, const std::list<ObserverParam> &value) mutable {
|
||||
auto size = value.size();
|
||||
for (const auto ¶ms : value) {
|
||||
params.observer->OnChange(origin, primaries, --size > 0 ? ChangeInfo(info) : std::move(info));
|
||||
@ -475,10 +471,10 @@ void RdbServiceProxy::OnDataChange(
|
||||
|
||||
void RdbServiceProxy::OnSyncComplete(uint32_t seqNum, Details &&result)
|
||||
{
|
||||
syncCallbacks_.ComputeIfPresent(seqNum, [&result] (const auto& key, const AsyncDetail& callback) {
|
||||
syncCallbacks_.ComputeIfPresent(seqNum, [&result](const auto &key, const AsyncDetail &callback) {
|
||||
auto finished = result.empty() || (result.begin()->second.progress == SYNC_FINISH);
|
||||
LOG_DEBUG("Sync complete, seqNum%{public}d, result size:%{public}zu", key, result.size());
|
||||
if (callback!=nullptr) {
|
||||
if (callback != nullptr) {
|
||||
callback(std::move(result));
|
||||
}
|
||||
return !finished;
|
||||
@ -499,11 +495,11 @@ void RdbServiceProxy::OnSyncComplete(const std::string &storeName, Details &&res
|
||||
});
|
||||
}
|
||||
|
||||
int32_t RdbServiceProxy::SetSearchable(const RdbSyncerParam& param, bool isSearchable)
|
||||
int32_t RdbServiceProxy::SetSearchable(const RdbSyncerParam ¶m, bool isSearchable)
|
||||
{
|
||||
MessageParcel reply;
|
||||
int32_t status = IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_SET_SEARCHABLE),
|
||||
reply, param, isSearchable);
|
||||
int32_t status =
|
||||
IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_SET_SEARCHABLE), reply, param, isSearchable);
|
||||
if (status != RDB_OK) {
|
||||
LOG_ERROR("RdbServiceProxy SetSearchable fail, status:%{public}d, "
|
||||
"bundleName:%{public}s, storeName:%{public}s",
|
||||
@ -512,12 +508,12 @@ int32_t RdbServiceProxy::SetSearchable(const RdbSyncerParam& param, bool isSearc
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t RdbServiceProxy::NotifyDataChange(const RdbSyncerParam ¶m, const RdbChangedData &rdbChangedData,
|
||||
const RdbNotifyConfig &rdbNotifyConfig)
|
||||
int32_t RdbServiceProxy::NotifyDataChange(
|
||||
const RdbSyncerParam ¶m, const RdbChangedData &rdbChangedData, const RdbNotifyConfig &rdbNotifyConfig)
|
||||
{
|
||||
MessageParcel reply;
|
||||
int32_t status = IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_NOTIFY_DATA_CHANGE),
|
||||
reply, param, rdbChangedData, rdbNotifyConfig);
|
||||
int32_t status = IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_NOTIFY_DATA_CHANGE), reply, param,
|
||||
rdbChangedData, rdbNotifyConfig);
|
||||
if (status != RDB_OK) {
|
||||
LOG_ERROR("RdbServiceProxy NotifyDataChange fail, status:%{public}d, "
|
||||
"bundleName:%{public}s, storeName:%{public}s",
|
||||
@ -526,7 +522,7 @@ int32_t RdbServiceProxy::NotifyDataChange(const RdbSyncerParam ¶m, const Rdb
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t RdbServiceProxy::Disable(const RdbSyncerParam& param)
|
||||
int32_t RdbServiceProxy::Disable(const RdbSyncerParam ¶m)
|
||||
{
|
||||
MessageParcel reply;
|
||||
int32_t status = IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_DISABLE), reply, param);
|
||||
@ -537,7 +533,7 @@ int32_t RdbServiceProxy::Disable(const RdbSyncerParam& param)
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t RdbServiceProxy::Enable(const RdbSyncerParam& param)
|
||||
int32_t RdbServiceProxy::Enable(const RdbSyncerParam ¶m)
|
||||
{
|
||||
MessageParcel reply;
|
||||
int32_t status = IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_ENABLE), reply, param);
|
||||
@ -564,12 +560,12 @@ int32_t RdbServiceProxy::GetPassword(const RdbSyncerParam ¶m, std::vector<ui
|
||||
return status;
|
||||
}
|
||||
|
||||
std::pair<int32_t, uint32_t> RdbServiceProxy::LockCloudContainer(const RdbSyncerParam& param)
|
||||
std::pair<int32_t, uint32_t> RdbServiceProxy::LockCloudContainer(const RdbSyncerParam ¶m)
|
||||
{
|
||||
MessageParcel reply;
|
||||
uint32_t expiredTime = 0;
|
||||
int32_t status = IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_LOCK_CLOUD_CONTAINER), reply,
|
||||
param, expiredTime);
|
||||
int32_t status = IPC_SEND(
|
||||
static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_LOCK_CLOUD_CONTAINER), reply, param, expiredTime);
|
||||
if (status != RDB_OK) {
|
||||
LOG_ERROR("fail, status:%{public}d, bundleName:%{public}s, storeName:%{public}s", status,
|
||||
param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str());
|
||||
@ -582,11 +578,11 @@ std::pair<int32_t, uint32_t> RdbServiceProxy::LockCloudContainer(const RdbSyncer
|
||||
return { status, expiredTime };
|
||||
}
|
||||
|
||||
int32_t RdbServiceProxy::UnlockCloudContainer(const RdbSyncerParam& param)
|
||||
int32_t RdbServiceProxy::UnlockCloudContainer(const RdbSyncerParam ¶m)
|
||||
{
|
||||
MessageParcel reply;
|
||||
int32_t status = IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_UNLOCK_CLOUD_CONTAINER),
|
||||
reply, param);
|
||||
int32_t status =
|
||||
IPC_SEND(static_cast<uint32_t>(RdbServiceCode::RDB_SERVICE_CMD_UNLOCK_CLOUD_CONTAINER), reply, param);
|
||||
if (status != RDB_OK) {
|
||||
LOG_ERROR("fail, status:%{public}d, bundleName:%{public}s, storeName:%{public}s", status,
|
||||
param.bundleName_.c_str(), SqliteUtils::Anonymous(param.storeName_).c_str());
|
||||
|
@ -48,7 +48,7 @@ int RdbSqlUtils::CreateDirectory(const std::string &databaseDir)
|
||||
directories.push_back(tempDirectory);
|
||||
|
||||
std::string databaseDirectory;
|
||||
for (const std::string& directory : directories) {
|
||||
for (const std::string &directory : directories) {
|
||||
databaseDirectory = databaseDirectory + "/" + directory;
|
||||
if (access(databaseDirectory.c_str(), F_OK) != 0) {
|
||||
if (MkDir(databaseDirectory)) {
|
||||
@ -69,8 +69,8 @@ int RdbSqlUtils::CreateDirectory(const std::string &databaseDir)
|
||||
/**
|
||||
* @brief get custom data base path.
|
||||
*/
|
||||
std::pair<std::string, int> RdbSqlUtils::GetDefaultDatabasePath(const std::string &baseDir, const std::string &name,
|
||||
const std::string &customDir)
|
||||
std::pair<std::string, int> RdbSqlUtils::GetDefaultDatabasePath(
|
||||
const std::string &baseDir, const std::string &name, const std::string &customDir)
|
||||
{
|
||||
int errorCode = E_OK;
|
||||
if (customDir.empty()) {
|
||||
|
@ -18,8 +18,8 @@
|
||||
#include "sqlite_utils.h"
|
||||
#include "traits.h"
|
||||
namespace OHOS::NativeRdb {
|
||||
RdbStore::ModifyTime::ModifyTime(std::shared_ptr<ResultSet> result, std::map<std::vector<uint8_t>, PRIKey> hashKeys,
|
||||
bool isFromRowId)
|
||||
RdbStore::ModifyTime::ModifyTime(
|
||||
std::shared_ptr<ResultSet> result, std::map<std::vector<uint8_t>, PRIKey> hashKeys, bool isFromRowId)
|
||||
: result_(std::move(result)), hash_(std::move(hashKeys)), isFromRowId_(isFromRowId)
|
||||
{
|
||||
for (auto &[_, priKey] : hash_) {
|
||||
@ -119,8 +119,8 @@ int RdbStore::Insert(int64_t &outRowId, const std::string &table, const Row &row
|
||||
return errCode;
|
||||
}
|
||||
|
||||
int RdbStore::InsertWithConflictResolution(int64_t &outRowId, const std::string &table, const Row &row,
|
||||
Resolution resolution)
|
||||
int RdbStore::InsertWithConflictResolution(
|
||||
int64_t &outRowId, const std::string &table, const Row &row, Resolution resolution)
|
||||
{
|
||||
auto [errCode, rowid] = Insert(table, row, resolution);
|
||||
if (errCode == E_OK) {
|
||||
@ -156,8 +156,8 @@ std::pair<int, int64_t> RdbStore::BatchInsert(const std::string &table, const Re
|
||||
return { E_NOT_SUPPORT, -1 };
|
||||
}
|
||||
|
||||
std::pair<int, int> RdbStore::Update(const std::string &table, const Row &row, const std::string &where,
|
||||
const Values &args, Resolution resolution)
|
||||
std::pair<int, int> RdbStore::Update(
|
||||
const std::string &table, const Row &row, const std::string &where, const Values &args, Resolution resolution)
|
||||
{
|
||||
(void)table;
|
||||
(void)row;
|
||||
@ -167,8 +167,8 @@ std::pair<int, int> RdbStore::Update(const std::string &table, const Row &row, c
|
||||
return { E_NOT_SUPPORT, 0 };
|
||||
}
|
||||
|
||||
int RdbStore::Update(int &changedRows, const std::string &table, const Row &row, const std::string &whereClause,
|
||||
const Values &args)
|
||||
int RdbStore::Update(
|
||||
int &changedRows, const std::string &table, const Row &row, const std::string &whereClause, const Values &args)
|
||||
{
|
||||
auto [errCode, changes] = Update(table, row, whereClause, args, NO_ACTION);
|
||||
if (errCode == E_OK) {
|
||||
@ -182,8 +182,8 @@ int RdbStore::Update(int &changedRows, const Row &row, const AbsRdbPredicates &p
|
||||
return Update(changedRows, predicates.GetTableName(), row, predicates.GetWhereClause(), predicates.GetBindArgs());
|
||||
}
|
||||
|
||||
int RdbStore::Update(int &changedRows, const std::string &table, const Row &row, const std::string &whereClause,
|
||||
const Olds &args)
|
||||
int RdbStore::Update(
|
||||
int &changedRows, const std::string &table, const Row &row, const std::string &whereClause, const Olds &args)
|
||||
{
|
||||
return Update(changedRows, table, row, whereClause, ToValues(args));
|
||||
};
|
||||
@ -223,8 +223,8 @@ std::shared_ptr<AbsSharedResultSet> RdbStore::Query(int &errCode, bool distinct,
|
||||
const std::string &indexName, const std::string &orderBy, const int &limit, const int &offset)
|
||||
{
|
||||
std::string sql;
|
||||
errCode = SqliteSqlBuilder::BuildQueryString(distinct, table, "", columns, whereClause, groupBy, indexName,
|
||||
orderBy, limit, offset, sql);
|
||||
errCode = SqliteSqlBuilder::BuildQueryString(
|
||||
distinct, table, "", columns, whereClause, groupBy, indexName, orderBy, limit, offset, sql);
|
||||
if (errCode != E_OK) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -268,8 +268,8 @@ std::shared_ptr<ResultSet> RdbStore::QueryByStep(const AbsRdbPredicates &predica
|
||||
return QueryByStep(sql, predicates.GetBindArgs());
|
||||
}
|
||||
|
||||
std::shared_ptr<ResultSet> RdbStore::RemoteQuery(const std::string &device, const AbsRdbPredicates &predicates,
|
||||
const Fields &columns, int &errCode)
|
||||
std::shared_ptr<ResultSet> RdbStore::RemoteQuery(
|
||||
const std::string &device, const AbsRdbPredicates &predicates, const Fields &columns, int &errCode)
|
||||
{
|
||||
(void)device;
|
||||
(void)predicates;
|
||||
@ -278,8 +278,8 @@ std::shared_ptr<ResultSet> RdbStore::RemoteQuery(const std::string &device, cons
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::pair<int32_t, std::shared_ptr<ResultSet>> RdbStore::QuerySharingResource(const AbsRdbPredicates &predicates,
|
||||
const Fields &columns)
|
||||
std::pair<int32_t, std::shared_ptr<ResultSet>> RdbStore::QuerySharingResource(
|
||||
const AbsRdbPredicates &predicates, const Fields &columns)
|
||||
{
|
||||
(void)predicates;
|
||||
(void)columns;
|
||||
@ -430,8 +430,8 @@ int RdbStore::Restore(const std::string &backupPath, const std::vector<uint8_t>
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int RdbStore::SetDistributedTables(const std::vector<std::string> &tables, int32_t type,
|
||||
const DistributedRdb::DistributedConfig &distributedConfig)
|
||||
int RdbStore::SetDistributedTables(
|
||||
const std::vector<std::string> &tables, int32_t type, const DistributedRdb::DistributedConfig &distributedConfig)
|
||||
{
|
||||
(void)tables;
|
||||
(void)type;
|
||||
@ -469,28 +469,28 @@ int RdbStore::Sync(const SyncOption &option, const AbsRdbPredicates &predicate,
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int RdbStore::Subscribe(const SubscribeOption& option, RdbStoreObserver *observer)
|
||||
int RdbStore::Subscribe(const SubscribeOption &option, RdbStoreObserver *observer)
|
||||
{
|
||||
(void)option;
|
||||
(void)observer;
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int RdbStore::UnSubscribe(const SubscribeOption& option, RdbStoreObserver *observer)
|
||||
int RdbStore::UnSubscribe(const SubscribeOption &option, RdbStoreObserver *observer)
|
||||
{
|
||||
(void)option;
|
||||
(void)observer;
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int RdbStore::SubscribeObserver(const SubscribeOption& option, const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
int RdbStore::SubscribeObserver(const SubscribeOption &option, const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
{
|
||||
(void)option;
|
||||
(void)observer;
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int RdbStore::UnsubscribeObserver(const SubscribeOption& option, const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
int RdbStore::UnsubscribeObserver(const SubscribeOption &option, const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
{
|
||||
(void)option;
|
||||
(void)observer;
|
||||
@ -545,8 +545,8 @@ int32_t RdbStore::GetBackupStatus() const
|
||||
return SlaveStatus::UNDEFINED;
|
||||
}
|
||||
|
||||
RdbStore::ModifyTime RdbStore::GetModifyTime(const std::string &table, const std::string &column,
|
||||
std::vector<PRIKey> &keys)
|
||||
RdbStore::ModifyTime RdbStore::GetModifyTime(
|
||||
const std::string &table, const std::string &column, std::vector<PRIKey> &keys)
|
||||
{
|
||||
(void)table;
|
||||
(void)column;
|
||||
@ -567,8 +567,8 @@ int RdbStore::GetRebuilt(RebuiltType &rebuilt)
|
||||
return E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
std::pair<int32_t, int32_t> RdbStore::Attach(const RdbStoreConfig &config, const std::string &attachName,
|
||||
int32_t waitTime)
|
||||
std::pair<int32_t, int32_t> RdbStore::Attach(
|
||||
const RdbStoreConfig &config, const std::string &attachName, int32_t waitTime)
|
||||
{
|
||||
(void)config;
|
||||
(void)attachName;
|
||||
@ -600,4 +600,4 @@ std::string RdbStore::GetLogTableName(const std::string &tableName)
|
||||
{
|
||||
return "naturalbase_rdb_aux_" + tableName + "_log";
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::NativeRdb
|
@ -249,7 +249,7 @@ std::string RdbStoreConfig::GetJournalModeValue(JournalMode journalMode)
|
||||
case JournalMode::MODE_TRUNCATE:
|
||||
return "TRUNCATE";
|
||||
case JournalMode::MODE_PERSIST:
|
||||
return "PERSIST";
|
||||
return "PERSIST";
|
||||
case JournalMode::MODE_MEMORY:
|
||||
return "MEMORY";
|
||||
case JournalMode::MODE_WAL:
|
||||
@ -335,7 +335,7 @@ int RdbStoreConfig::GetReadConSize() const
|
||||
|
||||
void RdbStoreConfig::SetReadConSize(int readConSize)
|
||||
{
|
||||
readConSize_= readConSize;
|
||||
readConSize_ = readConSize;
|
||||
}
|
||||
|
||||
void RdbStoreConfig::SetEncryptKey(const std::vector<uint8_t> &encryptKey)
|
||||
|
@ -15,6 +15,8 @@
|
||||
#define LOG_TAG "RdbStoreImpl"
|
||||
#include "rdb_store_impl.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
@ -23,7 +25,6 @@
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "cache_result_set.h"
|
||||
#include "directory_ex.h"
|
||||
@ -43,10 +44,10 @@
|
||||
#include "sqlite_statement.h"
|
||||
#include "sqlite_utils.h"
|
||||
#include "step_result_set.h"
|
||||
#include "values_buckets.h"
|
||||
#include "task_executor.h"
|
||||
#include "traits.h"
|
||||
#include "transaction.h"
|
||||
#include "values_buckets.h"
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
|
||||
#include "delay_notify.h"
|
||||
#include "raw_data_parser.h"
|
||||
@ -146,8 +147,8 @@ void RdbStoreImpl::AfterOpen(const RdbParam ¶m, int32_t retry)
|
||||
}
|
||||
}
|
||||
|
||||
RdbStore::ModifyTime RdbStoreImpl::GetModifyTime(const std::string &table, const std::string &columnName,
|
||||
std::vector<PRIKey> &keys)
|
||||
RdbStore::ModifyTime RdbStoreImpl::GetModifyTime(
|
||||
const std::string &table, const std::string &columnName, std::vector<PRIKey> &keys)
|
||||
{
|
||||
if (table.empty() || columnName.empty() || keys.empty()) {
|
||||
LOG_ERROR("invalid para.");
|
||||
@ -235,8 +236,8 @@ std::string RdbStoreImpl::GetLogTableName(const std::string &tableName)
|
||||
return DistributedDB::RelationalStoreManager::GetDistributedLogTableName(tableName);
|
||||
}
|
||||
|
||||
std::pair<int32_t, std::shared_ptr<ResultSet>> RdbStoreImpl::QuerySharingResource(const AbsRdbPredicates &predicates,
|
||||
const Fields &columns)
|
||||
std::pair<int32_t, std::shared_ptr<ResultSet>> RdbStoreImpl::QuerySharingResource(
|
||||
const AbsRdbPredicates &predicates, const Fields &columns)
|
||||
{
|
||||
if (config_.GetDBType() == DB_VECTOR) {
|
||||
return { E_NOT_SUPPORT, nullptr };
|
||||
@ -253,8 +254,8 @@ std::pair<int32_t, std::shared_ptr<ResultSet>> RdbStoreImpl::QuerySharingResourc
|
||||
return { status, resultSet };
|
||||
}
|
||||
|
||||
std::shared_ptr<ResultSet> RdbStoreImpl::RemoteQuery(const std::string &device, const AbsRdbPredicates &predicates,
|
||||
const Fields &columns, int &errCode)
|
||||
std::shared_ptr<ResultSet> RdbStoreImpl::RemoteQuery(
|
||||
const std::string &device, const AbsRdbPredicates &predicates, const Fields &columns, int &errCode)
|
||||
{
|
||||
DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__));
|
||||
if (config_.GetDBType() == DB_VECTOR) {
|
||||
@ -289,8 +290,8 @@ void RdbStoreImpl::NotifyDataChange()
|
||||
}
|
||||
}
|
||||
|
||||
int RdbStoreImpl::SetDistributedTables(const std::vector<std::string> &tables, int32_t type,
|
||||
const DistributedRdb::DistributedConfig &distributedConfig)
|
||||
int RdbStoreImpl::SetDistributedTables(
|
||||
const std::vector<std::string> &tables, int32_t type, const DistributedRdb::DistributedConfig &distributedConfig)
|
||||
{
|
||||
DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__));
|
||||
if (config_.GetDBType() == DB_VECTOR || isReadOnly_) {
|
||||
@ -304,8 +305,8 @@ int RdbStoreImpl::SetDistributedTables(const std::vector<std::string> &tables, i
|
||||
if (errCode != E_OK) {
|
||||
return errCode;
|
||||
}
|
||||
int32_t errorCode = service->SetDistributedTables(syncerParam_, tables, distributedConfig.references,
|
||||
distributedConfig.isRebuild, type);
|
||||
int32_t errorCode = service->SetDistributedTables(
|
||||
syncerParam_, tables, distributedConfig.references, distributedConfig.isRebuild, type);
|
||||
if (errorCode != E_OK) {
|
||||
LOG_ERROR("Fail to set distributed tables, error=%{public}d", errorCode);
|
||||
return errorCode;
|
||||
@ -392,8 +393,8 @@ int RdbStoreImpl::Sync(const SyncOption &option, const AbsRdbPredicates &predica
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RdbStoreImpl::InnerSync(const RdbParam ¶m, const Options &option, const Memo &predicates,
|
||||
const AsyncDetail &async)
|
||||
int RdbStoreImpl::InnerSync(
|
||||
const RdbParam ¶m, const Options &option, const Memo &predicates, const AsyncDetail &async)
|
||||
{
|
||||
auto [errCode, service] = RdbMgr::GetInstance().GetRdbService(param);
|
||||
if (errCode == E_NOT_SUPPORT) {
|
||||
@ -423,7 +424,7 @@ Uri RdbStoreImpl::GetUri(const std::string &event)
|
||||
return Uri(rdbUri);
|
||||
}
|
||||
|
||||
int RdbStoreImpl::SubscribeLocal(const SubscribeOption& option, RdbStoreObserver *observer)
|
||||
int RdbStoreImpl::SubscribeLocal(const SubscribeOption &option, RdbStoreObserver *observer)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
localObservers_.try_emplace(option.event);
|
||||
@ -439,7 +440,7 @@ int RdbStoreImpl::SubscribeLocal(const SubscribeOption& option, RdbStoreObserver
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int RdbStoreImpl::SubscribeLocalShared(const SubscribeOption& option, RdbStoreObserver *observer)
|
||||
int RdbStoreImpl::SubscribeLocalShared(const SubscribeOption &option, RdbStoreObserver *observer)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
localSharedObservers_.try_emplace(option.event);
|
||||
@ -466,8 +467,8 @@ int RdbStoreImpl::SubscribeLocalShared(const SubscribeOption& option, RdbStoreOb
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t RdbStoreImpl::SubscribeLocalDetail(const SubscribeOption &option,
|
||||
const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
int32_t RdbStoreImpl::SubscribeLocalDetail(
|
||||
const SubscribeOption &option, const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
{
|
||||
auto connection = connectionPool_->AcquireConnection(false);
|
||||
if (connection == nullptr) {
|
||||
@ -481,7 +482,7 @@ int32_t RdbStoreImpl::SubscribeLocalDetail(const SubscribeOption &option,
|
||||
return errCode;
|
||||
}
|
||||
|
||||
int RdbStoreImpl::SubscribeRemote(const SubscribeOption& option, RdbStoreObserver *observer)
|
||||
int RdbStoreImpl::SubscribeRemote(const SubscribeOption &option, RdbStoreObserver *observer)
|
||||
{
|
||||
auto [errCode, service] = RdbMgr::GetInstance().GetRdbService(syncerParam_);
|
||||
if (errCode != E_OK) {
|
||||
@ -504,7 +505,7 @@ int RdbStoreImpl::Subscribe(const SubscribeOption &option, RdbStoreObserver *obs
|
||||
return SubscribeRemote(option, observer);
|
||||
}
|
||||
|
||||
int RdbStoreImpl::UnSubscribeLocal(const SubscribeOption& option, RdbStoreObserver *observer)
|
||||
int RdbStoreImpl::UnSubscribeLocal(const SubscribeOption &option, RdbStoreObserver *observer)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto obs = localObservers_.find(option.event);
|
||||
@ -526,7 +527,7 @@ int RdbStoreImpl::UnSubscribeLocal(const SubscribeOption& option, RdbStoreObserv
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int RdbStoreImpl::UnSubscribeLocalAll(const SubscribeOption& option)
|
||||
int RdbStoreImpl::UnSubscribeLocalAll(const SubscribeOption &option)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto obs = localObservers_.find(option.event);
|
||||
@ -538,7 +539,7 @@ int RdbStoreImpl::UnSubscribeLocalAll(const SubscribeOption& option)
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int RdbStoreImpl::UnSubscribeLocalShared(const SubscribeOption& option, RdbStoreObserver *observer)
|
||||
int RdbStoreImpl::UnSubscribeLocalShared(const SubscribeOption &option, RdbStoreObserver *observer)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto obs = localSharedObservers_.find(option.event);
|
||||
@ -570,7 +571,7 @@ int RdbStoreImpl::UnSubscribeLocalShared(const SubscribeOption& option, RdbStore
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int RdbStoreImpl::UnSubscribeLocalSharedAll(const SubscribeOption& option)
|
||||
int RdbStoreImpl::UnSubscribeLocalSharedAll(const SubscribeOption &option)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto obs = localSharedObservers_.find(option.event);
|
||||
@ -599,8 +600,8 @@ int RdbStoreImpl::UnSubscribeLocalSharedAll(const SubscribeOption& option)
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t RdbStoreImpl::UnsubscribeLocalDetail(const SubscribeOption& option,
|
||||
const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
int32_t RdbStoreImpl::UnsubscribeLocalDetail(
|
||||
const SubscribeOption &option, const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
{
|
||||
auto connection = connectionPool_->AcquireConnection(false);
|
||||
if (connection == nullptr) {
|
||||
@ -614,7 +615,7 @@ int32_t RdbStoreImpl::UnsubscribeLocalDetail(const SubscribeOption& option,
|
||||
return errCode;
|
||||
}
|
||||
|
||||
int RdbStoreImpl::UnSubscribeRemote(const SubscribeOption& option, RdbStoreObserver *observer)
|
||||
int RdbStoreImpl::UnSubscribeRemote(const SubscribeOption &option, RdbStoreObserver *observer)
|
||||
{
|
||||
auto [errCode, service] = RdbMgr::GetInstance().GetRdbService(syncerParam_);
|
||||
if (errCode != E_OK) {
|
||||
@ -640,7 +641,7 @@ int RdbStoreImpl::UnSubscribe(const SubscribeOption &option, RdbStoreObserver *o
|
||||
return UnSubscribeRemote(option, observer);
|
||||
}
|
||||
|
||||
int RdbStoreImpl::SubscribeObserver(const SubscribeOption& option, const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
int RdbStoreImpl::SubscribeObserver(const SubscribeOption &option, const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
{
|
||||
if (config_.GetDBType() == DB_VECTOR) {
|
||||
return E_NOT_SUPPORT;
|
||||
@ -648,7 +649,7 @@ int RdbStoreImpl::SubscribeObserver(const SubscribeOption& option, const std::sh
|
||||
return SubscribeLocalDetail(option, observer);
|
||||
}
|
||||
|
||||
int RdbStoreImpl::UnsubscribeObserver(const SubscribeOption& option, const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
int RdbStoreImpl::UnsubscribeObserver(const SubscribeOption &option, const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
{
|
||||
if (config_.GetDBType() == DB_VECTOR) {
|
||||
return E_NOT_SUPPORT;
|
||||
@ -727,8 +728,8 @@ void RdbStoreImpl::InitDelayNotifier()
|
||||
return;
|
||||
}
|
||||
delayNotifier_->SetExecutorPool(TaskExecutor::GetInstance().GetExecutor());
|
||||
delayNotifier_->SetTask([param = syncerParam_]
|
||||
(const DistributedRdb::RdbChangedData& rdbChangedData, const RdbNotifyConfig& rdbNotifyConfig) -> int {
|
||||
delayNotifier_->SetTask([param = syncerParam_](const DistributedRdb::RdbChangedData &rdbChangedData,
|
||||
const RdbNotifyConfig &rdbNotifyConfig) -> int {
|
||||
auto [errCode, service] = RdbMgr::GetInstance().GetRdbService(param);
|
||||
if (errCode == E_NOT_SUPPORT) {
|
||||
return errCode;
|
||||
@ -753,7 +754,7 @@ int RdbStoreImpl::RegisterDataChangeCallback()
|
||||
InitDelayNotifier();
|
||||
auto callBack = [delayNotifier = delayNotifier_](const std::set<std::string> &tables) {
|
||||
DistributedRdb::RdbChangedData rdbChangedData;
|
||||
for (const auto& table : tables) {
|
||||
for (const auto &table : tables) {
|
||||
rdbChangedData.tableData[table].isTrackedDataChange = true;
|
||||
}
|
||||
if (delayNotifier != nullptr) {
|
||||
@ -1045,8 +1046,8 @@ std::pair<int, int64_t> RdbStoreImpl::BatchInsert(const std::string &table, cons
|
||||
return { E_OK, int64_t(rows.RowSize()) };
|
||||
}
|
||||
|
||||
std::pair<int, int> RdbStoreImpl::Update(const std::string &table, const Row &row, const std::string &where,
|
||||
const Values &args, Resolution resolution)
|
||||
std::pair<int, int> RdbStoreImpl::Update(
|
||||
const std::string &table, const Row &row, const std::string &where, const Values &args, Resolution resolution)
|
||||
{
|
||||
DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__));
|
||||
if (isReadOnly_ || (config_.GetDBType() == DB_VECTOR)) {
|
||||
@ -1245,8 +1246,8 @@ std::pair<int32_t, ValueObject> RdbStoreImpl::Execute(const std::string &sql, co
|
||||
return HandleDifferentSqlTypes(statement, sql, object, sqlType);
|
||||
}
|
||||
|
||||
std::pair<int32_t, ValueObject> RdbStoreImpl::HandleDifferentSqlTypes(std::shared_ptr<Statement> statement,
|
||||
const std::string &sql, const ValueObject &object, int sqlType)
|
||||
std::pair<int32_t, ValueObject> RdbStoreImpl::HandleDifferentSqlTypes(
|
||||
std::shared_ptr<Statement> statement, const std::string &sql, const ValueObject &object, int sqlType)
|
||||
{
|
||||
int32_t errCode = E_OK;
|
||||
if (sqlType == SqliteUtils::STATEMENT_INSERT) {
|
||||
@ -1343,10 +1344,8 @@ int RdbStoreImpl::ExecuteForLastInsertedRowId(int64_t &outValue, const std::stri
|
||||
auto allEnd = std::chrono::steady_clock::now();
|
||||
int64_t totalCostTime = std::chrono::duration_cast<std::chrono::milliseconds>(begin - allEnd).count();
|
||||
if (totalCostTime >= TIME_OUT) {
|
||||
int64_t prepareCost =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(beginExec - begin).count();
|
||||
int64_t execCost =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(beginExec - beginResult).count();
|
||||
int64_t prepareCost = std::chrono::duration_cast<std::chrono::milliseconds>(beginExec - begin).count();
|
||||
int64_t execCost = std::chrono::duration_cast<std::chrono::milliseconds>(beginExec - beginResult).count();
|
||||
int64_t resultCost = std::chrono::duration_cast<std::chrono::milliseconds>(allEnd - beginResult).count();
|
||||
LOG_WARN("total[%{public}" PRId64 "] stmt[%{public}" PRId64 "] exec[%{public}" PRId64
|
||||
"] result[%{public}" PRId64 "] "
|
||||
@ -1475,8 +1474,8 @@ int RdbStoreImpl::Backup(const std::string &databasePath, const std::vector<uint
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<ValueObject> RdbStoreImpl::CreateBackupBindArgs(const std::string &databasePath,
|
||||
const std::vector<uint8_t> &destEncryptKey)
|
||||
std::vector<ValueObject> RdbStoreImpl::CreateBackupBindArgs(
|
||||
const std::string &databasePath, const std::vector<uint8_t> &destEncryptKey)
|
||||
{
|
||||
std::vector<ValueObject> bindArgs;
|
||||
bindArgs.emplace_back(databasePath);
|
||||
@ -1545,7 +1544,7 @@ int RdbStoreImpl::InnerBackup(const std::string &databasePath, const std::vector
|
||||
return (res == E_OK) ? ret : res;
|
||||
}
|
||||
|
||||
std::pair<int32_t, RdbStoreImpl::Stmt> RdbStoreImpl::BeginExecuteSql(const std::string& sql)
|
||||
std::pair<int32_t, RdbStoreImpl::Stmt> RdbStoreImpl::BeginExecuteSql(const std::string &sql)
|
||||
{
|
||||
int type = SqliteUtils::GetSqlStatementType(sql);
|
||||
if (SqliteUtils::IsSpecial(type)) {
|
||||
@ -1643,7 +1642,7 @@ int RdbStoreImpl::SetDefaultEncryptAlgo(const ConnectionPool::SharedConn &conn,
|
||||
}
|
||||
|
||||
sql = std::string(GlobalExpr::CIPHER_DEFAULT_ATTACH_PAGE_SIZE_PREFIX) +
|
||||
std::to_string(config.GetCryptoParam().cryptoPageSize);
|
||||
std::to_string(config.GetCryptoParam().cryptoPageSize);
|
||||
return SetDefaultEncryptSql(statement, sql, config);
|
||||
}
|
||||
|
||||
@ -1835,16 +1834,16 @@ int RdbStoreImpl::BeginTransaction()
|
||||
if (errCode == E_SQLITE_LOCKED || errCode == E_SQLITE_BUSY) {
|
||||
connectionPool_->Dump(true, "BEGIN");
|
||||
}
|
||||
LOG_ERROR("transaction id: %{public}zu, storeName: %{public}s, errCode: %{public}d",
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
LOG_ERROR("transaction id: %{public}zu, storeName: %{public}s, errCode: %{public}d", transactionId,
|
||||
SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
return errCode;
|
||||
}
|
||||
connectionPool_->SetInTransaction(true);
|
||||
connectionPool_->GetTransactionStack().push(transaction);
|
||||
// 1 means the number of transactions in process
|
||||
if (transactionId > 1) {
|
||||
LOG_WARN("transaction id: %{public}zu, storeName: %{public}s, errCode: %{public}d",
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
LOG_WARN("transaction id: %{public}zu, storeName: %{public}s, errCode: %{public}d", transactionId,
|
||||
SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
}
|
||||
|
||||
return E_OK;
|
||||
@ -1854,7 +1853,7 @@ std::pair<int, int64_t> RdbStoreImpl::BeginTrans()
|
||||
{
|
||||
DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__));
|
||||
if (!config_.IsVector() || isReadOnly_) {
|
||||
return {E_NOT_SUPPORT, 0};
|
||||
return { E_NOT_SUPPORT, 0 };
|
||||
}
|
||||
|
||||
int64_t tmpTrxId = 0;
|
||||
@ -1862,7 +1861,7 @@ std::pair<int, int64_t> RdbStoreImpl::BeginTrans()
|
||||
if (connection == nullptr) {
|
||||
LOG_ERROR("Get null connection, storeName: %{public}s errCode:0x%{public}x.",
|
||||
SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
return {errCode, 0};
|
||||
return { errCode, 0 };
|
||||
}
|
||||
tmpTrxId = newTrxId_.fetch_add(1);
|
||||
trxConnMap_.Insert(tmpTrxId, connection);
|
||||
@ -1870,7 +1869,7 @@ std::pair<int, int64_t> RdbStoreImpl::BeginTrans()
|
||||
if (errCode != E_OK) {
|
||||
trxConnMap_.Erase(tmpTrxId);
|
||||
}
|
||||
return {errCode, tmpTrxId};
|
||||
return { errCode, tmpTrxId };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1910,8 +1909,8 @@ int RdbStoreImpl::RollBack()
|
||||
if (errCode == E_SQLITE_BUSY || errCode == E_SQLITE_LOCKED) {
|
||||
Reportor::Report(Reportor::Create(config_, errCode, "ErrorType: RollBusy"));
|
||||
}
|
||||
LOG_ERROR("failed, id: %{public}zu, storeName: %{public}s, errCode: %{public}d",
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
LOG_ERROR("failed, id: %{public}zu, storeName: %{public}s, errCode: %{public}d", transactionId,
|
||||
SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
return errCode;
|
||||
}
|
||||
if (connectionPool_->GetTransactionStack().empty()) {
|
||||
@ -1919,14 +1918,14 @@ int RdbStoreImpl::RollBack()
|
||||
}
|
||||
// 1 means the number of transactions in process
|
||||
if (transactionId > 1) {
|
||||
LOG_WARN("transaction id: %{public}zu, storeName: %{public}s, errCode: %{public}d",
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
LOG_WARN("transaction id: %{public}zu, storeName: %{public}s, errCode: %{public}d", transactionId,
|
||||
SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int RdbStoreImpl::ExecuteByTrxId(const std::string &sql, int64_t trxId, bool closeConnAfterExecute,
|
||||
const std::vector<ValueObject> &bindArgs)
|
||||
int RdbStoreImpl::ExecuteByTrxId(
|
||||
const std::string &sql, int64_t trxId, bool closeConnAfterExecute, const std::vector<ValueObject> &bindArgs)
|
||||
{
|
||||
if ((!config_.IsVector()) || isReadOnly_) {
|
||||
return E_NOT_SUPPORT;
|
||||
@ -1988,8 +1987,8 @@ int RdbStoreImpl::Commit()
|
||||
BaseTransaction transaction = connectionPool_->GetTransactionStack().top();
|
||||
std::string sqlStr = transaction.GetCommitStr();
|
||||
if (sqlStr.size() <= 1) {
|
||||
LOG_WARN("id: %{public}zu, storeName: %{public}s, sql: %{public}s",
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), sqlStr.c_str());
|
||||
LOG_WARN("id: %{public}zu, storeName: %{public}s, sql: %{public}s", transactionId,
|
||||
SqliteUtils::Anonymous(name_).c_str(), sqlStr.c_str());
|
||||
connectionPool_->GetTransactionStack().pop();
|
||||
return E_OK;
|
||||
}
|
||||
@ -2007,8 +2006,8 @@ int RdbStoreImpl::Commit()
|
||||
if (errCode == E_SQLITE_BUSY || errCode == E_SQLITE_LOCKED) {
|
||||
Reportor::Report(Reportor::Create(config_, errCode, "ErrorType: CommitBusy"));
|
||||
}
|
||||
LOG_ERROR("failed, id: %{public}zu, storeName: %{public}s, errCode: %{public}d",
|
||||
transactionId, SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
LOG_ERROR("failed, id: %{public}zu, storeName: %{public}s, errCode: %{public}d", transactionId,
|
||||
SqliteUtils::Anonymous(name_).c_str(), errCode);
|
||||
return errCode;
|
||||
}
|
||||
connectionPool_->SetInTransaction(false);
|
||||
@ -2115,7 +2114,7 @@ void RdbStoreImpl::DoCloudSync(const std::string &table)
|
||||
pool->Schedule(interval, [cloudInfo = std::weak_ptr<CloudTables>(cloudInfo_), param = syncerParam_]() {
|
||||
auto changeInfo = cloudInfo.lock();
|
||||
if (changeInfo == nullptr) {
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
auto tables = changeInfo->Steal();
|
||||
if (tables.empty()) {
|
||||
@ -2227,7 +2226,7 @@ int RdbStoreImpl::Restore(const std::string &backupPath, const std::vector<uint8
|
||||
|
||||
std::pair<int32_t, std::shared_ptr<Connection>> RdbStoreImpl::CreateWritableConn()
|
||||
{
|
||||
auto config = config_;
|
||||
auto config = config_;
|
||||
config.SetHaMode(HAMode::SINGLE);
|
||||
config.SetCreateNecessary(false);
|
||||
auto [result, conn] = Connection::Create(config, true);
|
||||
@ -2247,7 +2246,7 @@ std::pair<int32_t, std::shared_ptr<Statement>> RdbStoreImpl::GetStatement(
|
||||
return conn->CreateStatement(sql, conn);
|
||||
}
|
||||
|
||||
std::pair<int32_t, std::shared_ptr<Statement>> RdbStoreImpl::GetStatement(const std::string& sql, bool read) const
|
||||
std::pair<int32_t, std::shared_ptr<Statement>> RdbStoreImpl::GetStatement(const std::string &sql, bool read) const
|
||||
{
|
||||
auto conn = connectionPool_->AcquireConnection(read);
|
||||
if (conn == nullptr) {
|
||||
@ -2338,7 +2337,7 @@ int32_t RdbStoreImpl::GetDbType() const
|
||||
std::pair<int32_t, std::shared_ptr<Transaction>> RdbStoreImpl::CreateTransaction(int32_t type)
|
||||
{
|
||||
if (isReadOnly_) {
|
||||
return { E_NOT_SUPPORT, nullptr};
|
||||
return { E_NOT_SUPPORT, nullptr };
|
||||
}
|
||||
|
||||
auto [errCode, conn] = connectionPool_->CreateTransConn();
|
||||
|
@ -20,11 +20,11 @@
|
||||
|
||||
#include "logger.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_radar_reporter.h"
|
||||
#include "rdb_store_impl.h"
|
||||
#include "rdb_trace.h"
|
||||
#include "sqlite_global_config.h"
|
||||
#include "task_executor.h"
|
||||
#include "rdb_radar_reporter.h"
|
||||
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
#if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
|
||||
@ -33,9 +33,9 @@
|
||||
#endif
|
||||
#include "security_policy.h"
|
||||
#endif
|
||||
#include "rdb_fault_hiview_reporter.h"
|
||||
#include "sqlite_utils.h"
|
||||
#include "string_utils.h"
|
||||
#include "rdb_fault_hiview_reporter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
|
@ -18,10 +18,9 @@ namespace OHOS::ITypesUtil {
|
||||
template<>
|
||||
bool Marshalling(const SyncerParam &input, MessageParcel &data)
|
||||
{
|
||||
return ITypesUtil::Marshal(data, input.bundleName_, input.hapName_, input.storeName_, input.area_,
|
||||
input.level_, input.type_, input.isEncrypt_, input.password_, input.customDir_, input.isAutoClean_,
|
||||
input.isSearchable_, input.haMode_, input.infos_, input.tokenIds_, input.uids_, input.user_,
|
||||
input.permissionNames_);
|
||||
return ITypesUtil::Marshal(data, input.bundleName_, input.hapName_, input.storeName_, input.area_, input.level_,
|
||||
input.type_, input.isEncrypt_, input.password_, input.customDir_, input.isAutoClean_, input.isSearchable_,
|
||||
input.haMode_, input.infos_, input.tokenIds_, input.uids_, input.user_, input.permissionNames_);
|
||||
}
|
||||
template<>
|
||||
bool Unmarshalling(SyncerParam &output, MessageParcel &data)
|
||||
@ -162,14 +161,14 @@ bool Unmarshalling(Statistic &output, MessageParcel &data)
|
||||
template<>
|
||||
bool Marshalling(const PrimaryKeys &input, MessageParcel &data)
|
||||
{
|
||||
return Marshal(data, input[Observer::CHG_TYPE_INSERT], input[Observer::CHG_TYPE_UPDATE],
|
||||
input[Observer::CHG_TYPE_DELETE]);
|
||||
return Marshal(
|
||||
data, input[Observer::CHG_TYPE_INSERT], input[Observer::CHG_TYPE_UPDATE], input[Observer::CHG_TYPE_DELETE]);
|
||||
}
|
||||
template<>
|
||||
bool Unmarshalling(PrimaryKeys &output, MessageParcel &data)
|
||||
{
|
||||
return Unmarshal(data, output[Observer::CHG_TYPE_INSERT], output[Observer::CHG_TYPE_UPDATE],
|
||||
output[Observer::CHG_TYPE_DELETE]);
|
||||
return Unmarshal(
|
||||
data, output[Observer::CHG_TYPE_INSERT], output[Observer::CHG_TYPE_UPDATE], output[Observer::CHG_TYPE_DELETE]);
|
||||
}
|
||||
|
||||
template<>
|
||||
@ -217,13 +216,13 @@ bool Unmarshalling(Reference &output, MessageParcel &data)
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Marshalling(const BigInt& input, MessageParcel& data)
|
||||
bool Marshalling(const BigInt &input, MessageParcel &data)
|
||||
{
|
||||
return Marshal(data, input.Sign(), input.Value());
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Unmarshalling(BigInt& output, MessageParcel& data)
|
||||
bool Unmarshalling(BigInt &output, MessageParcel &data)
|
||||
{
|
||||
int32_t sign = 0;
|
||||
std::vector<uint64_t> value;
|
||||
@ -243,4 +242,4 @@ bool Unmarshalling(DebugInfo &output, MessageParcel &data)
|
||||
{
|
||||
return Unmarshal(data, output.inode_, output.mode_, output.uid_, output.gid_);
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::ITypesUtil
|
@ -99,10 +99,9 @@ int SharedBlockSetColumnNum(AppDataFwk::SharedBlock *sharedBlock, int columnNum)
|
||||
int FillSharedBlockOpt(SharedBlockInfo *info, sqlite3_stmt *stmt)
|
||||
{
|
||||
SharedBlockSerializerInfo serializer(info->sharedBlock, stmt, info->columnNum, info->startPos);
|
||||
Sqlite3SharedBlockMethods sqliteBlock = { 1, &serializer, info->isCountAllRows, info->startPos,
|
||||
info->requiredPos, SeriAddRow, SeriReset, SeriFinish, SeriPutString, SeriPutLong, SeriPutDouble, SeriPutBlob,
|
||||
SeriPutNull, SeriPutOther
|
||||
};
|
||||
Sqlite3SharedBlockMethods sqliteBlock = { 1, &serializer, info->isCountAllRows, info->startPos, info->requiredPos,
|
||||
SeriAddRow, SeriReset, SeriFinish, SeriPutString, SeriPutLong, SeriPutDouble, SeriPutBlob, SeriPutNull,
|
||||
SeriPutOther };
|
||||
auto db = sqlite3_db_handle(stmt);
|
||||
int err = sqlite3_db_config(db, SQLITE_DBCONFIG_SET_SHAREDBLOCK, stmt, &sqliteBlock);
|
||||
if (err != SQLITE_OK) {
|
||||
@ -181,8 +180,7 @@ void FillRow(SharedBlockInfo *info, sqlite3_stmt *stmt)
|
||||
info->sharedBlock->SetColumnNum(info->columnNum);
|
||||
info->startPos += info->addedRows;
|
||||
info->addedRows = 0;
|
||||
fillOneRowResult =
|
||||
FillOneRow(info->sharedBlock, stmt, info->columnNum, info->startPos, info->addedRows);
|
||||
fillOneRowResult = FillOneRow(info->sharedBlock, stmt, info->columnNum, info->startPos, info->addedRows);
|
||||
}
|
||||
|
||||
if (fillOneRowResult == FILL_ONE_ROW_SUCESS) {
|
||||
@ -194,8 +192,8 @@ void FillRow(SharedBlockInfo *info, sqlite3_stmt *stmt)
|
||||
}
|
||||
}
|
||||
|
||||
FillOneRowResult FillOneRow(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int numColumns,
|
||||
int startPos, int addedRows)
|
||||
FillOneRowResult FillOneRow(
|
||||
AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int numColumns, int startPos, int addedRows)
|
||||
{
|
||||
int status = sharedBlock->AllocRow();
|
||||
if (status != AppDataFwk::SharedBlock::SHARED_BLOCK_OK) {
|
||||
@ -241,9 +239,8 @@ FillOneRowResult FillOneRow(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
FillOneRowResult FillOneRowOfString(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
|
||||
int addedRows, int pos)
|
||||
FillOneRowResult FillOneRowOfString(
|
||||
AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, int addedRows, int pos)
|
||||
{
|
||||
const char *text = reinterpret_cast<const char *>(sqlite3_column_text(statement, pos));
|
||||
if (text == nullptr) {
|
||||
@ -262,8 +259,8 @@ FillOneRowResult FillOneRowOfString(AppDataFwk::SharedBlock *sharedBlock, sqlite
|
||||
return FILL_ONE_ROW_SUCESS;
|
||||
}
|
||||
|
||||
FillOneRowResult FillOneRowOfLong(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
|
||||
int addedRows, int pos)
|
||||
FillOneRowResult FillOneRowOfLong(
|
||||
AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, int addedRows, int pos)
|
||||
{
|
||||
int64_t value = sqlite3_column_int64(statement, pos);
|
||||
int status = sharedBlock->PutLong(addedRows, pos, value);
|
||||
@ -275,8 +272,8 @@ FillOneRowResult FillOneRowOfLong(AppDataFwk::SharedBlock *sharedBlock, sqlite3_
|
||||
return FILL_ONE_ROW_SUCESS;
|
||||
}
|
||||
|
||||
FillOneRowResult FillOneRowOfFloat(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
|
||||
int addedRows, int pos)
|
||||
FillOneRowResult FillOneRowOfFloat(
|
||||
AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, int addedRows, int pos)
|
||||
{
|
||||
double value = sqlite3_column_double(statement, pos);
|
||||
int status = sharedBlock->PutDouble(addedRows, pos, value);
|
||||
@ -288,8 +285,8 @@ FillOneRowResult FillOneRowOfFloat(AppDataFwk::SharedBlock *sharedBlock, sqlite3
|
||||
return FILL_ONE_ROW_SUCESS;
|
||||
}
|
||||
|
||||
FillOneRowResult FillOneRowOfBlob(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
|
||||
int addedRows, int pos)
|
||||
FillOneRowResult FillOneRowOfBlob(
|
||||
AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, int addedRows, int pos)
|
||||
{
|
||||
auto action = &AppDataFwk::SharedBlock::PutBlob;
|
||||
auto *declType = sqlite3_column_decltype(statement, pos);
|
||||
@ -315,8 +312,8 @@ FillOneRowResult FillOneRowOfBlob(AppDataFwk::SharedBlock *sharedBlock, sqlite3_
|
||||
return FILL_ONE_ROW_SUCESS;
|
||||
}
|
||||
|
||||
FillOneRowResult FillOneRowOfNull(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos,
|
||||
int addedRows, int pos)
|
||||
FillOneRowResult FillOneRowOfNull(
|
||||
AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *statement, int startPos, int addedRows, int pos)
|
||||
{
|
||||
int status = sharedBlock->PutNull(addedRows, pos);
|
||||
if (status != AppDataFwk::SharedBlock::SHARED_BLOCK_OK) {
|
||||
|
@ -22,8 +22,8 @@ namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
|
||||
SharedBlockSerializerInfo::SharedBlockSerializerInfo(AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *stat,
|
||||
int numColumns, int startPos)
|
||||
SharedBlockSerializerInfo::SharedBlockSerializerInfo(
|
||||
AppDataFwk::SharedBlock *sharedBlock, sqlite3_stmt *stat, int numColumns, int startPos)
|
||||
: sharedBlock_(sharedBlock), statement_(stat), anumColumns(numColumns), atotalRows(0), astartPos(startPos),
|
||||
raddedRows(0)
|
||||
{
|
||||
|
@ -16,12 +16,13 @@
|
||||
#define LOG_TAG "SqliteConnection"
|
||||
#include "sqlite_connection.h"
|
||||
|
||||
#include <sqlite3sym.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <memory>
|
||||
#include <sqlite3sym.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "sqlite3.h"
|
||||
#include "value_object.h"
|
||||
@ -35,6 +36,7 @@
|
||||
#include "logger.h"
|
||||
#include "raw_data_parser.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_fault_hiview_reporter.h"
|
||||
#include "rdb_security_manager.h"
|
||||
#include "rdb_sql_statistic.h"
|
||||
#include "rdb_store_config.h"
|
||||
@ -42,10 +44,9 @@
|
||||
#include "sqlite_errno.h"
|
||||
#include "sqlite_global_config.h"
|
||||
#include "sqlite_utils.h"
|
||||
#include "rdb_fault_hiview_reporter.h"
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
|
||||
#include "relational/relational_store_sqlite_ext.h"
|
||||
#include "rdb_manager_impl.h"
|
||||
#include "relational/relational_store_sqlite_ext.h"
|
||||
#endif
|
||||
#include "task_executor.h"
|
||||
|
||||
@ -55,7 +56,7 @@ using namespace OHOS::Rdb;
|
||||
using namespace std::chrono;
|
||||
using RdbKeyFile = RdbSecurityManager::KeyFileType;
|
||||
using Reportor = RdbFaultHiViewReporter;
|
||||
constexpr const char *INTEGRITIES[] = {nullptr, "PRAGMA quick_check", "PRAGMA integrity_check"};
|
||||
constexpr const char *INTEGRITIES[] = { nullptr, "PRAGMA quick_check", "PRAGMA integrity_check" };
|
||||
constexpr SqliteConnection::Suffix SqliteConnection::FILE_SUFFIXES[];
|
||||
constexpr const char *SqliteConnection::MERGE_ASSETS_FUNC;
|
||||
constexpr const char *SqliteConnection::MERGE_ASSET_FUNC;
|
||||
@ -156,7 +157,7 @@ std::pair<int32_t, std::shared_ptr<SqliteConnection>> SqliteConnection::CreateSl
|
||||
bool isSlaveLockExist = SqliteUtils::IsSlaveInterrupted(config_.GetPath());
|
||||
bool hasFailure = SqliteUtils::IsSlaveInvalid(config_.GetPath());
|
||||
bool walOverLimit = bugInfo.find(FILE_SUFFIXES[WAL_INDEX].debug_) != bugInfo.end() &&
|
||||
bugInfo[FILE_SUFFIXES[WAL_INDEX].debug_].size_ > SLAVE_WAL_SIZE_LIMIT;
|
||||
bugInfo[FILE_SUFFIXES[WAL_INDEX].debug_].size_ > SLAVE_WAL_SIZE_LIMIT;
|
||||
LOG_INFO("slave cfg:[%{public}d,%{public}d,%{public}d,%{public}d,%{public}d,%{public}d,%{public}d]%{public}s "
|
||||
"%{public}s,[%{public}d,%{public}d,%{public}d,%{public}d]",
|
||||
config.GetDBType(), config.GetHaMode(), config.IsEncrypt(), config.GetArea(), config.GetSecurityLevel(),
|
||||
@ -190,8 +191,8 @@ std::pair<int32_t, std::shared_ptr<SqliteConnection>> SqliteConnection::CreateSl
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
LOG_WARN("open slave failed:%{public}d, %{public}s", errCode,
|
||||
SqliteUtils::Anonymous(config.GetPath()).c_str());
|
||||
LOG_WARN(
|
||||
"open slave failed:%{public}d, %{public}s", errCode, SqliteUtils::Anonymous(config.GetPath()).c_str());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -248,7 +249,7 @@ int SqliteConnection::InnerOpen(const RdbStoreConfig &config)
|
||||
#endif
|
||||
isReadOnly_ = !isWriter_ || config.IsReadOnly();
|
||||
int openFileFlags = config.IsReadOnly() ? (SQLITE_OPEN_READONLY | SQLITE_OPEN_FULLMUTEX)
|
||||
: (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
|
||||
: (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX);
|
||||
errCode = OpenDatabase(dbPath, openFileFlags);
|
||||
if (errCode != E_OK) {
|
||||
return errCode;
|
||||
@ -272,8 +273,8 @@ int SqliteConnection::InnerOpen(const RdbStoreConfig &config)
|
||||
}
|
||||
if (errCode == E_OK && static_cast<std::string>(checkResult) != "ok") {
|
||||
LOG_ERROR("%{public}s integrity check result is %{public}s, sql:%{public}s",
|
||||
SqliteUtils::Anonymous(config.GetName()).c_str(),
|
||||
static_cast<std::string>(checkResult).c_str(), sql);
|
||||
SqliteUtils::Anonymous(config.GetName()).c_str(), static_cast<std::string>(checkResult).c_str(),
|
||||
sql);
|
||||
Reportor::ReportFault(Reportor::Create(config, errCode, static_cast<std::string>(checkResult)));
|
||||
}
|
||||
}
|
||||
@ -599,8 +600,8 @@ int SqliteConnection::ReSetKey(const RdbStoreConfig &config)
|
||||
if (!IsWriter()) {
|
||||
return E_OK;
|
||||
}
|
||||
LOG_INFO("name = %{public}s, iter = %{public}d", SqliteUtils::Anonymous(config.GetName()).c_str(),
|
||||
config.GetIter());
|
||||
LOG_INFO(
|
||||
"name = %{public}s, iter = %{public}d", SqliteUtils::Anonymous(config.GetName()).c_str(), config.GetIter());
|
||||
std::vector<uint8_t> newKey = config.GetNewEncryptKey();
|
||||
int errCode = sqlite3_rekey(dbHandle_, static_cast<const void *>(newKey.data()), static_cast<int>(newKey.size()));
|
||||
newKey.assign(newKey.size(), 0);
|
||||
@ -850,8 +851,8 @@ int SqliteConnection::ExecuteSql(const std::string &sql, const std::vector<Value
|
||||
return statement->Execute(bindArgs);
|
||||
}
|
||||
|
||||
std::pair<int32_t, ValueObject> SqliteConnection::ExecuteForValue(const std::string &sql,
|
||||
const std::vector<ValueObject> &bindArgs)
|
||||
std::pair<int32_t, ValueObject> SqliteConnection::ExecuteForValue(
|
||||
const std::string &sql, const std::vector<ValueObject> &bindArgs)
|
||||
{
|
||||
auto [errCode, statement] = CreateStatement(sql, nullptr);
|
||||
if (statement == nullptr || errCode != E_OK) {
|
||||
@ -946,8 +947,8 @@ int SqliteConnection::ConfigLocale(const std::string &localeStr)
|
||||
return E_ERROR;
|
||||
}
|
||||
|
||||
int err = sqlite3_create_collation_v2(dbHandle_, "LOCALES", SQLITE_UTF8, collator, Collate8Compare,
|
||||
(void (*)(void *))LocalizedCollatorDestroy);
|
||||
int err = sqlite3_create_collation_v2(
|
||||
dbHandle_, "LOCALES", SQLITE_UTF8, collator, Collate8Compare, (void (*)(void *))LocalizedCollatorDestroy);
|
||||
if (err != SQLITE_OK) {
|
||||
LOG_ERROR("SCreate collator in sqlite3 failed.");
|
||||
return err;
|
||||
@ -1082,8 +1083,8 @@ void SqliteConnection::MergeAsset(sqlite3_context *ctx, int argc, sqlite3_value
|
||||
sqlite3_result_blob(ctx, blob.data(), blob.size(), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
void SqliteConnection::CompAssets(std::map<std::string, ValueObject::Asset> &assets,
|
||||
std::map<std::string, ValueObject::Asset> &newAssets)
|
||||
void SqliteConnection::CompAssets(
|
||||
std::map<std::string, ValueObject::Asset> &assets, std::map<std::string, ValueObject::Asset> &newAssets)
|
||||
{
|
||||
auto oldIt = assets.begin();
|
||||
auto newIt = newAssets.begin();
|
||||
@ -1179,8 +1180,8 @@ int32_t SqliteConnection::Unsubscribe(const std::string &event, const std::share
|
||||
return UnsubscribeLocalDetailAll(event);
|
||||
}
|
||||
|
||||
int32_t SqliteConnection::UnsubscribeLocalDetail(const std::string &event,
|
||||
const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
int32_t SqliteConnection::UnsubscribeLocalDetail(
|
||||
const std::string &event, const std::shared_ptr<RdbStoreObserver> &observer)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto observers = observers_.find(event);
|
||||
@ -1236,8 +1237,8 @@ int32_t SqliteConnection::Backup(const std::string &databasePath, const std::vec
|
||||
LOG_INFO("backing up, return:%{public}s", config_.GetName().c_str());
|
||||
return E_OK;
|
||||
}
|
||||
LOG_INFO("begin backup to slave:%{public}s, isAsync:%{public}d",
|
||||
SqliteUtils::Anonymous(databasePath).c_str(), isAsync);
|
||||
LOG_INFO(
|
||||
"begin backup to slave:%{public}s, isAsync:%{public}d", SqliteUtils::Anonymous(databasePath).c_str(), isAsync);
|
||||
if (!isAsync) {
|
||||
if (slaveConnection_ == nullptr) {
|
||||
RdbStoreConfig rdbSlaveStoreConfig = GetSlaveRdbStoreConfig(config_);
|
||||
@ -1271,8 +1272,8 @@ int32_t SqliteConnection::Backup(const std::string &databasePath, const std::vec
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t SqliteConnection::Restore(const std::string &databasePath, const std::vector<uint8_t> &destEncryptKey,
|
||||
SlaveStatus &slaveStatus)
|
||||
int32_t SqliteConnection::Restore(
|
||||
const std::string &databasePath, const std::vector<uint8_t> &destEncryptKey, SlaveStatus &slaveStatus)
|
||||
{
|
||||
return ExchangeSlaverToMaster(true, true, slaveStatus);
|
||||
};
|
||||
@ -1286,8 +1287,8 @@ int SqliteConnection::LoadExtension(const RdbStoreConfig &config, sqlite3 *dbHan
|
||||
LOG_ERROR("failed, size %{public}zu is too large", config.GetPluginLibs().size());
|
||||
return E_INVALID_ARGS;
|
||||
}
|
||||
int err = sqlite3_db_config(dbHandle, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SqliteUtils::ENABLE_LOAD_EXTENSION,
|
||||
nullptr);
|
||||
int err = sqlite3_db_config(
|
||||
dbHandle, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SqliteUtils::ENABLE_LOAD_EXTENSION, nullptr);
|
||||
if (err != SQLITE_OK) {
|
||||
LOG_ERROR("enable failed, err=%{public}d, errno=%{public}d", err, errno);
|
||||
return SQLiteError::ErrNo(err);
|
||||
@ -1307,8 +1308,8 @@ int SqliteConnection::LoadExtension(const RdbStoreConfig &config, sqlite3 *dbHan
|
||||
break;
|
||||
}
|
||||
}
|
||||
int ret = sqlite3_db_config(dbHandle, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SqliteUtils::DISABLE_LOAD_EXTENSION,
|
||||
nullptr);
|
||||
int ret = sqlite3_db_config(
|
||||
dbHandle, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SqliteUtils::DISABLE_LOAD_EXTENSION, nullptr);
|
||||
if (ret != SQLITE_OK) {
|
||||
LOG_ERROR("disable failed, err=%{public}d, errno=%{public}d", err, errno);
|
||||
}
|
||||
@ -1524,8 +1525,8 @@ int SqliteConnection::ExchangeVerify(bool isRestore)
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
std::pair<int32_t, std::shared_ptr<SqliteConnection>> SqliteConnection::InnerCreate(const RdbStoreConfig &config,
|
||||
bool isWrite)
|
||||
std::pair<int32_t, std::shared_ptr<SqliteConnection>> SqliteConnection::InnerCreate(
|
||||
const RdbStoreConfig &config, bool isWrite)
|
||||
{
|
||||
std::pair<int32_t, std::shared_ptr<SqliteConnection>> result = { E_ERROR, nullptr };
|
||||
auto &[errCode, conn] = result;
|
||||
@ -1581,15 +1582,15 @@ int SqliteConnection::VeritySlaveIntegrity()
|
||||
}
|
||||
}
|
||||
bool isSlaveDbOverLimit = bugInfo.find(FILE_SUFFIXES[DB_INDEX].debug_) != bugInfo.end() &&
|
||||
bugInfo[FILE_SUFFIXES[DB_INDEX].debug_].size_ > SLAVE_INTEGRITY_CHECK_LIMIT;
|
||||
bugInfo[FILE_SUFFIXES[DB_INDEX].debug_].size_ > SLAVE_INTEGRITY_CHECK_LIMIT;
|
||||
if (isSlaveDbOverLimit && mCount == 0L) {
|
||||
return SqliteUtils::IsSlaveInvalid(config_.GetPath()) ? E_SQLITE_CORRUPT : E_OK;
|
||||
}
|
||||
|
||||
std::tie(err, obj) = slaveConnection_->ExecuteForValue(INTEGRITIES[2]); // 2 is integrity_check
|
||||
if (err == E_OK && (static_cast<std::string>(obj) != "ok")) {
|
||||
LOG_ERROR("slave corrupt, ret:%{public}s, cRet:%{public}d, %{public}d",
|
||||
static_cast<std::string>(obj).c_str(), err, errno);
|
||||
LOG_ERROR("slave corrupt, ret:%{public}s, cRet:%{public}d, %{public}d", static_cast<std::string>(obj).c_str(),
|
||||
err, errno);
|
||||
SqliteUtils::SetSlaveInvalid(config_.GetPath());
|
||||
return E_SQLITE_CORRUPT;
|
||||
}
|
||||
@ -1602,7 +1603,7 @@ bool SqliteConnection::IsDbVersionBelowSlave()
|
||||
return false;
|
||||
}
|
||||
|
||||
auto[cRet, cObj] = ExecuteForValue("SELECT COUNT(*) FROM sqlite_master WHERE type='table';");
|
||||
auto [cRet, cObj] = ExecuteForValue("SELECT COUNT(*) FROM sqlite_master WHERE type='table';");
|
||||
auto cVal = std::get_if<int64_t>(&cObj.value);
|
||||
if (cRet == E_SQLITE_CORRUPT || (cVal != nullptr && (static_cast<int64_t>(*cVal) == 0L))) {
|
||||
LOG_INFO("main empty, %{public}d, %{public}s", cRet, config_.GetName().c_str());
|
||||
|
@ -17,14 +17,16 @@
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <chrono>
|
||||
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
#include "logger.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "sqlite3sym.h"
|
||||
#include "sqlite_utils.h"
|
||||
#include "rdb_errno.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
@ -41,8 +43,7 @@ SqliteGlobalConfig::SqliteGlobalConfig()
|
||||
|
||||
sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
|
||||
|
||||
sqlite3_config(SQLITE_CONFIG_LOG, &Log,
|
||||
GlobalExpr::CALLBACK_LOG_SWITCH ? reinterpret_cast<void *>(1) : NULL);
|
||||
sqlite3_config(SQLITE_CONFIG_LOG, &Log, GlobalExpr::CALLBACK_LOG_SWITCH ? reinterpret_cast<void *>(1) : NULL);
|
||||
|
||||
sqlite3_soft_heap_limit(GlobalExpr::SOFT_HEAP_LIMIT);
|
||||
|
||||
@ -61,16 +62,15 @@ void SqliteGlobalConfig::Log(const void *data, int err, const char *msg)
|
||||
if (errType == SQLITE_ERROR && strstr(msg, "\"?\": syntax error in \"PRAGMA user_ve") != nullptr) {
|
||||
return;
|
||||
}
|
||||
if (errType == 0 || errType == SQLITE_CONSTRAINT || errType == SQLITE_SCHEMA || errType == SQLITE_NOTICE
|
||||
|| err == SQLITE_WARNING_AUTOINDEX) {
|
||||
if (errType == 0 || errType == SQLITE_CONSTRAINT || errType == SQLITE_SCHEMA || errType == SQLITE_NOTICE ||
|
||||
err == SQLITE_WARNING_AUTOINDEX) {
|
||||
if (verboseLog) {
|
||||
LOG_INFO("Error(%{public}d) %{public}s ", err, SqliteUtils::Anonymous(msg).c_str());
|
||||
}
|
||||
} else if (errType == SQLITE_WARNING) {
|
||||
LOG_WARN("WARNING(%{public}d) %{public}s ", err, SqliteUtils::Anonymous(msg).c_str());
|
||||
} else {
|
||||
LOG_ERROR("Error(%{public}d) errno is:%{public}d %{public}s.", err, errno,
|
||||
SqliteUtils::Anonymous(msg).c_str());
|
||||
LOG_ERROR("Error(%{public}d) errno is:%{public}d %{public}s.", err, errno, SqliteUtils::Anonymous(msg).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,29 +17,29 @@
|
||||
|
||||
#include <rdb_errno.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <tuple>
|
||||
#include <cinttypes>
|
||||
|
||||
#include "logger.h"
|
||||
#include "rdb_sql_utils.h"
|
||||
#include "rdb_sql_statistic.h"
|
||||
#include "rdb_sql_utils.h"
|
||||
#include "result_set.h"
|
||||
#include "share_block.h"
|
||||
#include "sqlite_connection.h"
|
||||
#include "sqlite_errno.h"
|
||||
#include "sqlite_statement.h"
|
||||
#include "sqlite_utils.h"
|
||||
#include "sqlite_errno.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
using namespace std::chrono;
|
||||
constexpr int64_t TIME_OUT = 1500;
|
||||
SqliteSharedResultSet::SqliteSharedResultSet(Time start, Conn conn, std::string sql, const Values &args,
|
||||
const std::string &path)
|
||||
SqliteSharedResultSet::SqliteSharedResultSet(
|
||||
Time start, Conn conn, std::string sql, const Values &args, const std::string &path)
|
||||
: AbsSharedResultSet(path), conn_(std::move(conn)), qrySql_(std::move(sql)), bindArgs_(args)
|
||||
{
|
||||
if (conn_ == nullptr) {
|
||||
@ -141,8 +141,8 @@ SqliteSharedResultSet::~SqliteSharedResultSet() {}
|
||||
std::pair<int, std::vector<std::string>> SqliteSharedResultSet::GetColumnNames()
|
||||
{
|
||||
if (isClosed_) {
|
||||
LOG_ERROR("fail, result set has been closed, ret %{public}d, sql %{public}s",
|
||||
E_ALREADY_CLOSED, qrySql_.c_str());
|
||||
LOG_ERROR(
|
||||
"fail, result set has been closed, ret %{public}d, sql %{public}s", E_ALREADY_CLOSED, qrySql_.c_str());
|
||||
return { E_ALREADY_CLOSED, {} };
|
||||
}
|
||||
|
||||
@ -179,15 +179,15 @@ int SqliteSharedResultSet::Close()
|
||||
int SqliteSharedResultSet::OnGo(int oldPosition, int newPosition)
|
||||
{
|
||||
if (isClosed_) {
|
||||
LOG_ERROR("fail, result set has been closed, ret %{public}d, sql %{public}s",
|
||||
E_ALREADY_CLOSED, qrySql_.c_str());
|
||||
LOG_ERROR(
|
||||
"fail, result set has been closed, ret %{public}d, sql %{public}s", E_ALREADY_CLOSED, qrySql_.c_str());
|
||||
return E_ALREADY_CLOSED;
|
||||
}
|
||||
if (GetBlock() == nullptr) {
|
||||
return E_ERROR;
|
||||
}
|
||||
if ((uint32_t)newPosition < GetBlock()->GetStartPos() || (uint32_t)newPosition >= GetBlock()->GetLastPos()
|
||||
|| oldPosition == rowCount_) {
|
||||
if ((uint32_t)newPosition < GetBlock()->GetStartPos() || (uint32_t)newPosition >= GetBlock()->GetLastPos() ||
|
||||
oldPosition == rowCount_) {
|
||||
return FillBlock(newPosition);
|
||||
}
|
||||
return E_OK;
|
||||
@ -215,12 +215,12 @@ int SqliteSharedResultSet::FillBlock(int requiredPos)
|
||||
return errCode;
|
||||
}
|
||||
blockCapacity_ = block->GetRowNum();
|
||||
if ((block->GetStartPos() == block->GetLastPos() && (uint32_t)rowCount_ != block->GetStartPos())
|
||||
|| ((uint32_t)requiredPos < block->GetStartPos() || block->GetLastPos() <= (uint32_t)requiredPos)
|
||||
|| block->GetStartPos() > 0) {
|
||||
if ((block->GetStartPos() == block->GetLastPos() && (uint32_t)rowCount_ != block->GetStartPos()) ||
|
||||
((uint32_t)requiredPos < block->GetStartPos() || block->GetLastPos() <= (uint32_t)requiredPos) ||
|
||||
block->GetStartPos() > 0) {
|
||||
LOG_WARN("blockRowNum=%{public}d, requiredPos= %{public}d, startPos_= %{public}" PRIu32
|
||||
", lastPos_= %{public}" PRIu32 ", blockPos_= %{public}" PRIu32 ".",
|
||||
rowCount_, requiredPos, block->GetStartPos(), block->GetLastPos(), block->GetBlockPos());
|
||||
", lastPos_= %{public}" PRIu32 ", blockPos_= %{public}" PRIu32 ".",
|
||||
rowCount_, requiredPos, block->GetStartPos(), block->GetLastPos(), block->GetBlockPos());
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
@ -298,8 +298,8 @@ std::string SqliteSqlBuilder::GetSqlArgs(size_t size)
|
||||
return args;
|
||||
}
|
||||
|
||||
SqliteSqlBuilder::BatchRefSqls SqliteSqlBuilder::GenerateSqls(const std::string &table, const ValuesBuckets &buckets,
|
||||
int limit)
|
||||
SqliteSqlBuilder::BatchRefSqls SqliteSqlBuilder::GenerateSqls(
|
||||
const std::string &table, const ValuesBuckets &buckets, int limit)
|
||||
{
|
||||
auto [fields, values] = buckets.GetFieldsAndValues();
|
||||
auto columnSize = fields->size();
|
||||
@ -324,8 +324,8 @@ SqliteSqlBuilder::BatchRefSqls SqliteSqlBuilder::GenerateSqls(const std::string
|
||||
return SqliteSqlBuilder::MakeExecuteSqls(sql, args, columnSize, limit);
|
||||
}
|
||||
|
||||
SqliteSqlBuilder::BatchRefSqls SqliteSqlBuilder::MakeExecuteSqls(const std::string &sql,
|
||||
const std::vector<RefValue> &args, int fieldSize, int limit)
|
||||
SqliteSqlBuilder::BatchRefSqls SqliteSqlBuilder::MakeExecuteSqls(
|
||||
const std::string &sql, const std::vector<RefValue> &args, int fieldSize, int limit)
|
||||
{
|
||||
if (fieldSize == 0) {
|
||||
return BatchRefSqls();
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "logger.h"
|
||||
#include "raw_data_parser.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_fault_hiview_reporter.h"
|
||||
#include "rdb_sql_statistic.h"
|
||||
#include "relational_store_client.h"
|
||||
#include "remote_result_set.h"
|
||||
@ -34,9 +35,8 @@
|
||||
#include "sqlite3ext.h"
|
||||
#include "sqlite_connection.h"
|
||||
#include "sqlite_errno.h"
|
||||
#include "sqlite_utils.h"
|
||||
#include "rdb_fault_hiview_reporter.h"
|
||||
#include "sqlite_global_config.h"
|
||||
#include "sqlite_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
@ -120,7 +120,7 @@ void SqliteStatement::ReadFile2Buffer()
|
||||
if (SqliteGlobalConfig::GetDbPath(*config_, fileName) != E_OK || access(fileName.c_str(), F_OK) != 0) {
|
||||
return;
|
||||
}
|
||||
uint64_t buffer[BUFFER_LEN] = {0x0};
|
||||
uint64_t buffer[BUFFER_LEN] = { 0x0 };
|
||||
FILE *file = fopen(fileName.c_str(), "r");
|
||||
if (file == nullptr) {
|
||||
LOG_ERROR(
|
||||
@ -135,8 +135,8 @@ void SqliteStatement::ReadFile2Buffer()
|
||||
}
|
||||
constexpr int bufferSize = 4;
|
||||
for (uint32_t i = 0; i < BUFFER_LEN; i += bufferSize) {
|
||||
LOG_WARN("line%{public}d: %{public}" PRIx64 "%{public}" PRIx64 "%{public}" PRIx64 "%{public}" PRIx64,
|
||||
i >> 2, buffer[i], buffer[i + 1], buffer[i + 2], buffer[i + 3]);
|
||||
LOG_WARN("line%{public}d: %{public}" PRIx64 "%{public}" PRIx64 "%{public}" PRIx64 "%{public}" PRIx64, i >> 2,
|
||||
buffer[i], buffer[i + 1], buffer[i + 2], buffer[i + 3]);
|
||||
}
|
||||
(void)fclose(file);
|
||||
}
|
||||
@ -145,7 +145,7 @@ 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)));
|
||||
refBindArgs.emplace_back(std::ref(const_cast<ValueObject &>(object)));
|
||||
}
|
||||
return BindArgs(refBindArgs);
|
||||
}
|
||||
@ -348,7 +348,7 @@ 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)));
|
||||
refArgs.emplace_back(std::ref(const_cast<ValueObject &>(object)));
|
||||
}
|
||||
return Execute(refArgs);
|
||||
}
|
||||
@ -388,8 +388,8 @@ int32_t SqliteStatement::Execute(const std::vector<std::reference_wrapper<ValueO
|
||||
if (slave_) {
|
||||
int errCode = slave_->Execute(args);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("slave execute error:%{public}d, sql is %{public}s, errno %{public}d",
|
||||
errCode, sql_.c_str(), errno);
|
||||
LOG_ERROR(
|
||||
"slave execute error:%{public}d, sql is %{public}s, errno %{public}d", errCode, sql_.c_str(), errno);
|
||||
SqliteUtils::SetSlaveInvalid(config_->GetPath());
|
||||
RdbStoreConfig slaveConfig(SqliteUtils::GetSlavePath(config_->GetPath()));
|
||||
Reportor::Report(Reportor::Create(slaveConfig, errCode, "ErrorType: slaveExecErr"));
|
||||
@ -701,8 +701,8 @@ int32_t SqliteStatement::BindBigInt(sqlite3_stmt *stat, int index, const ValueOb
|
||||
return sqlite3_bind_blob(stat, index, static_cast<const void *>(rawData.data()), rawData.size(), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
int SqliteStatement::ModifyLockStatus(const std::string &table, const std::vector<std::vector<uint8_t>> &hashKeys,
|
||||
bool isLock)
|
||||
int SqliteStatement::ModifyLockStatus(
|
||||
const std::string &table, const std::vector<std::vector<uint8_t>> &hashKeys, bool isLock)
|
||||
{
|
||||
::DistributedDB::DBStatus ret;
|
||||
auto db = sqlite3_db_handle(stmt_);
|
||||
|
@ -138,8 +138,8 @@ bool SqliteUtils::DeleteFile(const std::string &filePath)
|
||||
}
|
||||
auto ret = remove(filePath.c_str());
|
||||
if (ret != 0) {
|
||||
LOG_WARN("remove file failed errno %{public}d ret %{public}d %{public}s", errno, ret,
|
||||
Anonymous(filePath).c_str());
|
||||
LOG_WARN(
|
||||
"remove file failed errno %{public}d ret %{public}d %{public}s", errno, ret, Anonymous(filePath).c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -530,7 +530,7 @@ bool SqliteUtils::IsSlaveDbName(const std::string &fileName)
|
||||
return (pos != std::string::npos) && (pos == fileName.size() - slaveSuffix.size());
|
||||
}
|
||||
|
||||
std::string SqliteUtils::GetSlavePath(const std::string& name)
|
||||
std::string SqliteUtils::GetSlavePath(const std::string &name)
|
||||
{
|
||||
std::string suffix(".db");
|
||||
std::string slaveSuffix("_slave.db");
|
||||
|
@ -17,10 +17,10 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "connection_pool.h"
|
||||
#include "logger.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "sqlite3sym.h"
|
||||
#include "connection_pool.h"
|
||||
#include "sqlite_errno.h"
|
||||
#include "sqlite_statement.h"
|
||||
#include "sqlite_utils.h"
|
||||
|
@ -26,8 +26,8 @@ std::string StringUtils::SurroundWithQuote(const std::string &value, const std::
|
||||
}
|
||||
|
||||
// Join array members as parameters of a function call.
|
||||
std::string StringUtils::SurroundWithFunction(const std::string &function, const std::string &separator,
|
||||
const std::vector<std::string> &array)
|
||||
std::string StringUtils::SurroundWithFunction(
|
||||
const std::string &function, const std::string &separator, const std::vector<std::string> &array)
|
||||
{
|
||||
std::string builder(function);
|
||||
builder += "(";
|
||||
@ -60,12 +60,12 @@ std::vector<std::string> StringUtils::Split(const std::string &str, const std::s
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string StringUtils::ExtractFilePath(const std::string& fileFullName)
|
||||
std::string StringUtils::ExtractFilePath(const std::string &fileFullName)
|
||||
{
|
||||
return std::string(fileFullName).substr(0, fileFullName.rfind("/") + 1);
|
||||
}
|
||||
|
||||
std::string StringUtils::ExtractFileName(const std::string& fileFullName)
|
||||
std::string StringUtils::ExtractFileName(const std::string &fileFullName)
|
||||
{
|
||||
return std::string(fileFullName).substr(fileFullName.rfind("/") + 1, fileFullName.size());
|
||||
}
|
||||
|
@ -104,8 +104,8 @@ std::pair<int, int64_t> TransDB::BatchInsert(const std::string &table, const Ref
|
||||
return { E_OK, int64_t(rows.RowSize()) };
|
||||
}
|
||||
|
||||
std::pair<int, int> TransDB::Update(const std::string &table, const Row &row, const std::string &where,
|
||||
const Values &args, Resolution resolution)
|
||||
std::pair<int, int> TransDB::Update(
|
||||
const std::string &table, const Row &row, const std::string &where, const Values &args, Resolution resolution)
|
||||
{
|
||||
DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__));
|
||||
auto clause = SqliteUtils::GetConflictClause(static_cast<int>(resolution));
|
||||
|
@ -29,4 +29,4 @@ int32_t Transaction::RegisterCreator(Creator creator)
|
||||
creator_ = std::move(creator);
|
||||
return E_OK;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::NativeRdb
|
||||
|
@ -16,6 +16,7 @@
|
||||
#define LOG_TAG "TransactionImpl"
|
||||
|
||||
#include "transaction_impl.h"
|
||||
|
||||
#include "logger.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_store.h"
|
||||
@ -196,8 +197,8 @@ std::pair<int, int64_t> TransactionImpl::BatchInsert(const std::string &table, c
|
||||
return store->BatchInsert(table, rows);
|
||||
}
|
||||
|
||||
std::pair<int, int> TransactionImpl::Update(const std::string &table, const Row &row, const std::string &where,
|
||||
const Values &args, Resolution resolution)
|
||||
std::pair<int, int> TransactionImpl::Update(
|
||||
const std::string &table, const Row &row, const std::string &where, const Values &args, Resolution resolution)
|
||||
{
|
||||
auto store = GetStore();
|
||||
if (store == nullptr) {
|
||||
@ -207,20 +208,20 @@ std::pair<int, int> TransactionImpl::Update(const std::string &table, const Row
|
||||
return store->Update(table, row, where, args, resolution);
|
||||
}
|
||||
|
||||
std::pair<int32_t, int32_t> TransactionImpl::Update(const Row &row, const AbsRdbPredicates &predicates,
|
||||
Resolution resolution)
|
||||
std::pair<int32_t, int32_t> TransactionImpl::Update(
|
||||
const Row &row, const AbsRdbPredicates &predicates, Resolution resolution)
|
||||
{
|
||||
auto store = GetStore();
|
||||
if (store == nullptr) {
|
||||
LOG_ERROR("transaction already close");
|
||||
return { E_ALREADY_CLOSED, -1 };
|
||||
}
|
||||
return store->Update(predicates.GetTableName(), row, predicates.GetWhereClause(), predicates.GetBindArgs(),
|
||||
resolution);
|
||||
return store->Update(
|
||||
predicates.GetTableName(), row, predicates.GetWhereClause(), predicates.GetBindArgs(), resolution);
|
||||
}
|
||||
|
||||
std::pair<int32_t, int32_t> TransactionImpl::Delete(const std::string &table, const std::string &whereClause,
|
||||
const Values &args)
|
||||
std::pair<int32_t, int32_t> TransactionImpl::Delete(
|
||||
const std::string &table, const std::string &whereClause, const Values &args)
|
||||
{
|
||||
auto store = GetStore();
|
||||
if (store == nullptr) {
|
||||
@ -287,4 +288,4 @@ std::pair<int32_t, ValueObject> TransactionImpl::Execute(const std::string &sql,
|
||||
}
|
||||
return store->Execute(sql, args);
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::NativeRdb
|
||||
|
@ -86,7 +86,7 @@ void ValuesBucket::PutNull(const std::string &columnName)
|
||||
values_.insert(std::make_pair(columnName, ValueObject()));
|
||||
}
|
||||
|
||||
void ValuesBucket::Put(const std::string &columnName, const ValueObject &value)
|
||||
void ValuesBucket::Put(const std::string &columnName, const ValueObject &value)
|
||||
{
|
||||
values_.insert_or_assign(columnName, value);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "values_buckets.h"
|
||||
|
||||
#include "rdb_errno.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -40,7 +41,7 @@ void ValuesBuckets::Put(const ValuesBucket &bucket)
|
||||
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))));
|
||||
std::ref(const_cast<ValueObject &>(*valueResult.first))));
|
||||
}
|
||||
buckets_.push_back(std::move(row));
|
||||
}
|
||||
@ -61,5 +62,5 @@ std::pair<int, ValuesBuckets::ValueType> ValuesBuckets::Get(size_t row, const Fi
|
||||
|
||||
return { E_OK, it->second };
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace NativeRdb
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user