datashare适配多种数据类型相关代码提交

Signed-off-by: songruirui <songruirui1@huawei.com>
This commit is contained in:
songruirui 2022-05-24 21:55:51 +08:00
parent fe95a6943d
commit d0f0ac0c2c
53 changed files with 2115 additions and 1165 deletions

View File

@ -48,10 +48,6 @@ public:
static napi_value Convert2JSValue(napi_env env, bool value);
static napi_value Convert2JSValue(napi_env env, const std::map<std::string, int>& value);
static std::vector<uint8_t> ConvertU8Vector(napi_env env, napi_value jsValue);
static double Convert2Value(napi_env env, napi_value jsValue, double valType);
static bool Convert2Value(napi_env env, napi_value jsValue, bool valType);
static std::string Convert2Value(napi_env env, napi_value jsValue, std::string valType);
};
} // namespace DataShare
} // namespace OHOS

View File

@ -76,7 +76,7 @@ private:
napi_ref wrapper_;
};
napi_value GetNapiObject(napi_env env, OHOS::DataShare::DataSharePredicates *predicates);
napi_value GetNapiObject(napi_env env, DataSharePredicates *predicates);
DataSharePredicates *GetNativePredicatesObject(const napi_env &env, const napi_value &arg);
} // namespace DataShare
} // namespace OHOS

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NAPI_DATASHARE_ABSTRACT_RESULT_SET_H
#define NAPI_DATASHARE_ABSTRACT_RESULT_SET_H
#include <memory>
#include "datashare_abstract_result_set.h"
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "napi/native_node_api.h"
namespace OHOS {
namespace DataShare {
class NapiDataShareAbstractResultSet final {
public:
NapiDataShareAbstractResultSet() = default;
~NapiDataShareAbstractResultSet();
explicit NapiDataShareAbstractResultSet(std::shared_ptr<DataShareAbstractResultSet> resultSet);
NapiDataShareAbstractResultSet &operator=(std::shared_ptr<DataShareAbstractResultSet> resultSet);
static napi_value NewInstance(napi_env env, std::shared_ptr<DataShareAbstractResultSet> resultSet);
static std::shared_ptr<DataShareAbstractResultSet> GetNativeObject(
const napi_env &env, const napi_value &arg);
static napi_value GetConstructor(napi_env env);
private:
static std::shared_ptr<DataShareAbstractResultSet> &GetInnerAbstractResultSet(napi_env env,
napi_callback_info info);
static napi_value Initialize(napi_env env, napi_callback_info info);
std::shared_ptr<DataShareAbstractResultSet> resultSet_;
};
napi_value GetNapiAbstractResultSetObject(napi_env env, DataShareAbstractResultSet *resultSet);
DataShareAbstractResultSet *GetNativeAbstractResultSetObject(const napi_env &env, const napi_value &arg);
} // namespace DataShare
} // namespace OHOS
#endif // NAPI_DATASHARE_ABSTRACT_RESULT_SET_H

View File

@ -25,8 +25,6 @@
namespace OHOS {
namespace DataShare {
napi_value DataShareValueBucketNewInstance(napi_env env, DataShareValuesBucket &valuesBucket);
void SetValuesBucketObject(
DataShareValuesBucket &valuesBucket, const napi_env &env, std::string keyStr, napi_value value);
void GetValueBucketObject(DataShareValuesBucket &valuesBucket, const napi_env &env, const napi_value &arg);
} // namespace DataShare
} // namespace OHOS

View File

@ -121,27 +121,6 @@ std::string DataShareJSUtils::ConvertAny2String(napi_env env, napi_value jsValue
return "invalid type";
}
double DataShareJSUtils::Convert2Value(napi_env env, napi_value jsValue, double TypeValue)
{
double valueNumber;
napi_status status = napi_get_value_double(env, jsValue, &valueNumber);
LOG_INFO("napi_get_value_double : %{public}d", status);
return valueNumber;
}
bool DataShareJSUtils::Convert2Value(napi_env env, napi_value jsValue, bool TypeValue)
{
bool valueBool = false;
napi_status status = napi_get_value_bool(env, jsValue, &valueBool);
LOG_INFO("napi_get_value_bool : %{public}d", status);
return valueBool;
}
std::string DataShareJSUtils::Convert2Value(napi_env env, napi_value jsValue, std::string TypeValue)
{
return DataShareJSUtils::Convert2String(env, jsValue, DataShareJSUtils::DEFAULT_BUF_SIZE);
}
napi_value DataShareJSUtils::Convert2JSValue(napi_env env, const std::vector<std::string> &value)
{
napi_value jsValue;

View File

@ -172,23 +172,31 @@ napi_value DataSharePredicatesProxy::EqualTo(napi_env env, napi_callback_info in
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
napi_valuetype valueType = napi_undefined;
napi_status status = napi_typeof(env, args[1], &valueType);
LOG_INFO("napi_typeof status : %{public}d", status);
if (status != napi_ok) {
LOG_ERROR("napi_typeof status : %{public}d", status);
return thiz;
}
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
switch (valueType) {
case napi_number: {
double value;
napi_get_value_double(env, args[1], &value);
GetNativePredicates(env, info)->EqualTo(field, value);
nativePredicates->EqualTo(field, value);
break;
}
case napi_boolean: {
bool value = false;
napi_get_value_bool(env, args[1], &value);
GetNativePredicates(env, info)->EqualTo(field, value);
nativePredicates->EqualTo(field, value);
break;
}
case napi_string: {
std::string value = DataShareJSUtils::Convert2String(env, args[1], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->EqualTo(field, value);
nativePredicates->EqualTo(field, value);
break;
}
default:
@ -208,23 +216,31 @@ napi_value DataSharePredicatesProxy::NotEqualTo(napi_env env, napi_callback_info
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
napi_valuetype valueType = napi_undefined;
napi_status status = napi_typeof(env, args[1], &valueType);
LOG_INFO("napi_typeof status : %{public}d", status);
if (status != napi_ok) {
LOG_ERROR("napi_typeof status : %{public}d", status);
return thiz;
}
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
switch (valueType) {
case napi_number: {
double value;
napi_get_value_double(env, args[1], &value);
GetNativePredicates(env, info)->NotEqualTo(field, value);
nativePredicates->NotEqualTo(field, value);
break;
}
case napi_boolean: {
bool value = false;
napi_get_value_bool(env, args[1], &value);
GetNativePredicates(env, info)->NotEqualTo(field, value);
nativePredicates->NotEqualTo(field, value);
break;
}
case napi_string: {
std::string value = DataShareJSUtils::Convert2String(env, args[1], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->NotEqualTo(field, value);
nativePredicates->NotEqualTo(field, value);
break;
}
default:
@ -238,7 +254,12 @@ napi_value DataSharePredicatesProxy::BeginWrap(napi_env env, napi_callback_info
LOG_DEBUG("DataSharePredicatesProxy::BeginWrap on called.");
napi_value thiz;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
GetNativePredicates(env, info)->BeginWrap();
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->BeginWrap();
return thiz;
}
@ -247,7 +268,12 @@ napi_value DataSharePredicatesProxy::EndWrap(napi_env env, napi_callback_info in
LOG_DEBUG("DataSharePredicatesProxy::EndWrap on called.");
napi_value thiz;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
GetNativePredicates(env, info)->EndWrap();
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->EndWrap();
return thiz;
}
@ -256,7 +282,12 @@ napi_value DataSharePredicatesProxy::Or(napi_env env, napi_callback_info info)
LOG_DEBUG("DataSharePredicatesProxy::Or on called.");
napi_value thiz;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
GetNativePredicates(env, info)->Or();
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->Or();
return thiz;
}
@ -265,7 +296,12 @@ napi_value DataSharePredicatesProxy::And(napi_env env, napi_callback_info info)
LOG_DEBUG("DataSharePredicatesProxy::And on called.");
napi_value thiz;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
GetNativePredicates(env, info)->And();
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->And();
return thiz;
}
@ -280,7 +316,12 @@ napi_value DataSharePredicatesProxy::Contains(napi_env env, napi_callback_info i
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
std::string value = DataShareJSUtils::ConvertAny2String(env, args[1]);
GetNativePredicates(env, info)->Contains(field, value);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->Contains(field, value);
return thiz;
}
@ -294,7 +335,12 @@ napi_value DataSharePredicatesProxy::BeginsWith(napi_env env, napi_callback_info
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::BeginsWith Invalid argvs!");
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
std::string value = DataShareJSUtils::ConvertAny2String(env, args[1]);
GetNativePredicates(env, info)->BeginsWith(field, value);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->BeginsWith(field, value);
return thiz;
}
@ -308,7 +354,12 @@ napi_value DataSharePredicatesProxy::EndsWith(napi_env env, napi_callback_info i
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::EndsWith Invalid argvs!");
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
std::string value = DataShareJSUtils::ConvertAny2String(env, args[1]);
GetNativePredicates(env, info)->EndsWith(field, value);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->EndsWith(field, value);
return thiz;
}
@ -321,8 +372,12 @@ napi_value DataSharePredicatesProxy::IsNull(napi_env env, napi_callback_info inf
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::IsNull Invalid argvs!");
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
LOG_DEBUG("DataSharePredicatesProxy::IsNull on called.");
GetNativePredicates(env, info)->IsNull(field);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->IsNull(field);
return thiz;
}
@ -335,7 +390,12 @@ napi_value DataSharePredicatesProxy::IsNotNull(napi_env env, napi_callback_info
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::IsNotNull Invalid argvs!");
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->IsNotNull(field);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->IsNotNull(field);
return thiz;
}
@ -349,7 +409,12 @@ napi_value DataSharePredicatesProxy::Like(napi_env env, napi_callback_info info)
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::Like Invalid argvs!");
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
std::string value = DataShareJSUtils::ConvertAny2String(env, args[1]);
GetNativePredicates(env, info)->Like(field, value);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->Like(field, value);
return thiz;
}
@ -363,7 +428,12 @@ napi_value DataSharePredicatesProxy::Unlike(napi_env env, napi_callback_info inf
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::Unlike Invalid argvs!");
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
std::string value = DataShareJSUtils::ConvertAny2String(env, args[1]);
GetNativePredicates(env, info)->Unlike(field, value);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->Unlike(field, value);
return thiz;
}
@ -377,7 +447,12 @@ napi_value DataSharePredicatesProxy::Glob(napi_env env, napi_callback_info info)
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::Glob Invalid argvs!");
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
std::string value = DataShareJSUtils::ConvertAny2String(env, args[1]);
GetNativePredicates(env, info)->Glob(field, value);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->Glob(field, value);
return thiz;
}
@ -392,7 +467,12 @@ napi_value DataSharePredicatesProxy::Between(napi_env env, napi_callback_info in
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
std::string low = DataShareJSUtils::ConvertAny2String(env, args[1]);
std::string high = DataShareJSUtils::ConvertAny2String(env, args[2]);
GetNativePredicates(env, info)->Between(field, low, high);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->Between(field, low, high);
return thiz;
}
@ -407,7 +487,12 @@ napi_value DataSharePredicatesProxy::NotBetween(napi_env env, napi_callback_info
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
std::string low = DataShareJSUtils::ConvertAny2String(env, args[1]);
std::string high = DataShareJSUtils::ConvertAny2String(env, args[2]);
GetNativePredicates(env, info)->NotBetween(field, low, high);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->NotBetween(field, low, high);
return thiz;
}
@ -422,17 +507,25 @@ napi_value DataSharePredicatesProxy::GreaterThan(napi_env env, napi_callback_inf
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
napi_valuetype valueType = napi_undefined;
napi_status status = napi_typeof(env, args[1], &valueType);
LOG_INFO("napi_typeof status : %{public}d", status);
if (status != napi_ok) {
LOG_ERROR("napi_typeof status : %{public}d", status);
return thiz;
}
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
switch (valueType) {
case napi_number: {
double value;
napi_get_value_double(env, args[1], &value);
GetNativePredicates(env, info)->GreaterThan(field, value);
nativePredicates->GreaterThan(field, value);
break;
}
case napi_string: {
std::string value = DataShareJSUtils::Convert2String(env, args[1], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->GreaterThan(field, value);
nativePredicates->GreaterThan(field, value);
break;
}
default:
@ -451,17 +544,26 @@ napi_value DataSharePredicatesProxy::LessThan(napi_env env, napi_callback_info i
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::LessThan Invalid argvs!");
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
napi_valuetype valueType = napi_undefined;
napi_typeof(env, args[1], &valueType);
napi_status status = napi_typeof(env, args[1], &valueType);
if (status != napi_ok) {
LOG_ERROR("napi_typeof status : %{public}d", status);
return thiz;
}
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
switch (valueType) {
case napi_number: {
double value;
napi_get_value_double(env, args[1], &value);
GetNativePredicates(env, info)->LessThan(field, value);
nativePredicates->LessThan(field, value);
break;
}
case napi_string: {
std::string value = DataShareJSUtils::Convert2String(env, args[1], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->LessThan(field, value);
nativePredicates->LessThan(field, value);
break;
}
default:
@ -481,17 +583,25 @@ napi_value DataSharePredicatesProxy::GreaterThanOrEqualTo(napi_env env, napi_cal
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
napi_valuetype valueType = napi_undefined;
napi_status status = napi_typeof(env, args[1], &valueType);
LOG_INFO("napi_typeof status : %{public}d", status);
if (status != napi_ok) {
LOG_ERROR("napi_typeof status : %{public}d", status);
return thiz;
}
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
switch (valueType) {
case napi_number: {
double value;
napi_get_value_double(env, args[1], &value);
GetNativePredicates(env, info)->GreaterThanOrEqualTo(field, value);
nativePredicates->GreaterThanOrEqualTo(field, value);
break;
}
case napi_string: {
std::string value = DataShareJSUtils::Convert2String(env, args[1], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->GreaterThanOrEqualTo(field, value);
nativePredicates->GreaterThanOrEqualTo(field, value);
break;
}
default:
@ -511,17 +621,25 @@ napi_value DataSharePredicatesProxy::LessThanOrEqualTo(napi_env env, napi_callba
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
napi_valuetype valueType = napi_undefined;
napi_status status = napi_typeof(env, args[1], &valueType);
LOG_INFO("napi_typeof status : %{public}d", status);
if (status != napi_ok) {
LOG_ERROR("napi_typeof status : %{public}d", status);
return thiz;
}
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
switch (valueType) {
case napi_number: {
double value;
napi_get_value_double(env, args[1], &value);
GetNativePredicates(env, info)->LessThanOrEqualTo(field, value);
nativePredicates->LessThanOrEqualTo(field, value);
break;
}
case napi_string: {
std::string value = DataShareJSUtils::Convert2String(env, args[1], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->LessThanOrEqualTo(field, value);
nativePredicates->LessThanOrEqualTo(field, value);
break;
}
default:
@ -539,7 +657,12 @@ napi_value DataSharePredicatesProxy::OrderByAsc(napi_env env, napi_callback_info
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::OrderByAsc Invalid argvs!");
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->OrderByAsc(field);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->OrderByAsc(field);
return thiz;
}
@ -552,7 +675,12 @@ napi_value DataSharePredicatesProxy::OrderByDesc(napi_env env, napi_callback_inf
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::OrderByDesc Invalid argvs!");
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->OrderByDesc(field);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->OrderByDesc(field);
return thiz;
}
@ -561,7 +689,12 @@ napi_value DataSharePredicatesProxy::Distinct(napi_env env, napi_callback_info i
LOG_DEBUG("DataSharePredicatesProxy::Distinct on called.");
napi_value thiz;
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
GetNativePredicates(env, info)->Distinct();
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->Distinct();
return thiz;
}
@ -579,7 +712,12 @@ napi_value DataSharePredicatesProxy::Limit(napi_env env, napi_callback_info info
int offset = 0;
status = napi_get_value_int32(env, args[1], &offset);
LOG_INFO("offset, napi_get_value_int32 : %{public}d", status);
GetNativePredicates(env, info)->Limit(number, offset);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->Limit(number, offset);
return thiz;
}
@ -593,7 +731,12 @@ napi_value DataSharePredicatesProxy::GroupBy(napi_env env, napi_callback_info in
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::GroupBy Invalid argvs!");
std::vector<std::string> fields = DataShareJSUtils::Convert2StrVector(env,
args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->GroupBy(fields);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->GroupBy(fields);
return thiz;
}
@ -606,7 +749,12 @@ napi_value DataSharePredicatesProxy::IndexedBy(napi_env env, napi_callback_info
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::IndexedBy Invalid argvs!");
std::string indexName = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->IndexedBy(indexName);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->IndexedBy(indexName);
return thiz;
}
@ -621,7 +769,12 @@ napi_value DataSharePredicatesProxy::In(napi_env env, napi_callback_info info)
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
std::vector<std::string> values = DataShareJSUtils::Convert2StrVector(env,
args[1], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->In(field, values);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->In(field, values);
return thiz;
}
@ -636,7 +789,12 @@ napi_value DataSharePredicatesProxy::NotIn(napi_env env, napi_callback_info info
std::string field = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
std::vector<std::string> values = DataShareJSUtils::Convert2StrVector(env,
args[1], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->NotIn(field, values);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->NotIn(field, values);
return thiz;
}
@ -654,7 +812,12 @@ napi_value DataSharePredicatesProxy::PrefixKey(napi_env env, napi_callback_info
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::PrefixKey Invalid argvs!");
std::string prefix = DataShareJSUtils::Convert2String(env, args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->KeyPrefix(prefix);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->KeyPrefix(prefix);
return thiz;
}
@ -668,7 +831,12 @@ napi_value DataSharePredicatesProxy::InKeys(napi_env env, napi_callback_info inf
NAPI_ASSERT(env, argc > 0, "DataSharePredicatesProxy::InKeys Invalid argvs!");
std::vector<std::string> keys = DataShareJSUtils::Convert2StrVector(env,
args[0], DataShareJSUtils::DEFAULT_BUF_SIZE);
GetNativePredicates(env, info)->InKeys(keys);
std::shared_ptr<DataSharePredicates> nativePredicates = GetNativePredicates(env, info);
if (nativePredicates == nullptr) {
LOG_ERROR("GetNativePredicates failed.");
return thiz;
}
nativePredicates->InKeys(keys);
return thiz;
}

View File

@ -26,7 +26,6 @@
namespace OHOS {
namespace DataShare {
static napi_ref __thread ctorRef_ = nullptr;
static const int E_OK = 0;
napi_value DataShareResultSetProxy::NewInstance(napi_env env, std::shared_ptr<DataShareResultSet> resultSet)
{
napi_value cons = GetConstructor(env);

View File

@ -1,145 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "napi_datashare_abstract_result_set.h"
#include <functional>
#include "datashare_js_utils.h"
#include "napi_datashare_async_proxy.h"
#include "string_ex.h"
#include "datashare_log.h"
namespace OHOS {
namespace DataShare {
static napi_ref __thread ctorRef_ = nullptr;
napi_value NapiDataShareAbstractResultSet::NewInstance(napi_env env,
std::shared_ptr<DataShareAbstractResultSet> resultSet)
{
napi_value cons = GetConstructor(env);
if (cons == nullptr) {
LOG_ERROR("NewInstance GetConstructor is nullptr!");
return nullptr;
}
napi_value instance;
napi_status status = napi_new_instance(env, cons, 0, nullptr, &instance);
if (status != napi_ok) {
LOG_ERROR("NewInstance napi_new_instance failed! code:%{public}d!", status);
return nullptr;
}
NapiDataShareAbstractResultSet *proxy = nullptr;
status = napi_unwrap(env, instance, reinterpret_cast<void **>(&proxy));
if (proxy == nullptr) {
LOG_ERROR("NewInstance native instance is nullptr! code:%{public}d!", status);
return instance;
}
*proxy = std::move(resultSet);
return instance;
}
std::shared_ptr<DataShareAbstractResultSet> NapiDataShareAbstractResultSet::GetNativeObject(
napi_env const &env, napi_value const &arg)
{
if (arg == nullptr) {
LOG_ERROR("NapiDataShareAbstractResultSet GetNativeObject arg is null.");
return nullptr;
}
NapiDataShareAbstractResultSet *proxy = nullptr;
napi_unwrap(env, arg, reinterpret_cast<void **>(&proxy));
if (proxy == nullptr) {
LOG_ERROR("NapiDataShareAbstractResultSet GetNativeObject proxy is null.");
return nullptr;
}
return proxy->resultSet_;
}
napi_value NapiDataShareAbstractResultSet::GetConstructor(napi_env env)
{
napi_value cons;
if (ctorRef_ != nullptr) {
NAPI_CALL(env, napi_get_reference_value(env, ctorRef_, &cons));
return cons;
}
LOG_INFO("GetConstructor DataShareAbstractResultSet constructor");
napi_property_descriptor clzDes[] = {};
NAPI_CALL(env, napi_define_class(env, "DataShareAbstractResultSet", NAPI_AUTO_LENGTH, Initialize, nullptr,
sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons));
NAPI_CALL(env, napi_create_reference(env, cons, 1, &ctorRef_));
return cons;
}
napi_value NapiDataShareAbstractResultSet::Initialize(napi_env env, napi_callback_info info)
{
napi_value self = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &self, nullptr));
auto *proxy = new NapiDataShareAbstractResultSet();
auto finalize = [](napi_env env, void *data, void *hint) {
NapiDataShareAbstractResultSet *proxy = reinterpret_cast<NapiDataShareAbstractResultSet *>(data);
delete proxy;
};
napi_status status = napi_wrap(env, self, proxy, finalize, nullptr, nullptr);
if (status != napi_ok) {
LOG_ERROR("NapiDataShareAbstractResultSet napi_wrap failed! code:%{public}d!", status);
finalize(env, proxy, nullptr);
return nullptr;
}
return self;
}
NapiDataShareAbstractResultSet::~NapiDataShareAbstractResultSet()
{
LOG_INFO("NapiDataShareAbstractResultSet destructor!");
}
NapiDataShareAbstractResultSet::NapiDataShareAbstractResultSet(std::shared_ptr<DataShareAbstractResultSet> resultSet)
{
if (resultSet_ == resultSet) {
return;
}
resultSet_ = std::move(resultSet);
}
NapiDataShareAbstractResultSet &NapiDataShareAbstractResultSet::operator=(
std::shared_ptr<DataShareAbstractResultSet> resultSet)
{
if (resultSet_ == resultSet) {
return *this;
}
resultSet_ = std::move(resultSet);
return *this;
}
std::shared_ptr<DataShareAbstractResultSet> &NapiDataShareAbstractResultSet::GetInnerAbstractResultSet(napi_env env,
napi_callback_info info)
{
NapiDataShareAbstractResultSet *resultSet = nullptr;
napi_value self = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &self, nullptr);
napi_unwrap(env, self, reinterpret_cast<void **>(&resultSet));
return resultSet->resultSet_;
}
napi_value GetNapiAbstractResultSetObject(napi_env env, DataShareAbstractResultSet *resultSet)
{
return NapiDataShareAbstractResultSet::NewInstance(env, std::shared_ptr<DataShareAbstractResultSet>(resultSet));
}
DataShareAbstractResultSet *GetNativeAbstractResultSetObject(const napi_env &env, const napi_value &arg)
{
auto resultSet = NapiDataShareAbstractResultSet::GetNativeObject(env, arg);
return resultSet.get();
}
} // namespace DataShare
} // namespace OHOS

View File

@ -70,6 +70,39 @@ napi_value DataShareValueBucketNewInstance(napi_env env, DataShareValuesBucket &
return ret;
}
void SetValuesBucketObject(
DataShareValuesBucket &valuesBucket, const napi_env &env, std::string keyStr, napi_value value)
{
napi_valuetype valueType = napi_undefined;
napi_typeof(env, value, &valueType);
if (valueType == napi_string) {
std::string valueString = DataShareJSUtils::UnwrapStringFromJS(env, value);
LOG_INFO("ValueObject type:%{public}d, key:%{public}s, value:%{public}s",
valueType, keyStr.c_str(), valueString.c_str());
valuesBucket.PutString(keyStr, valueString);
} else if (valueType == napi_number) {
double valueNumber = 0;
napi_get_value_double(env, value, &valueNumber);
valuesBucket.PutDouble(keyStr, valueNumber);
LOG_INFO(
"ValueObject type:%{public}d, key:%{public}s, value:%{public}lf", valueType, keyStr.c_str(), valueNumber);
} else if (valueType == napi_boolean) {
bool valueBool = false;
napi_get_value_bool(env, value, &valueBool);
LOG_INFO(
"ValueObject type:%{public}d, key:%{public}s, value:%{public}d", valueType, keyStr.c_str(), valueBool);
valuesBucket.PutBool(keyStr, valueBool);
} else if (valueType == napi_null) {
valuesBucket.PutNull(keyStr);
LOG_INFO("ValueObject type:%{public}d, key:%{public}s, value:null", valueType, keyStr.c_str());
} else if (valueType == napi_object) {
LOG_INFO("ValueObject type:%{public}d, key:%{public}s, value:Uint8Array", valueType, keyStr.c_str());
valuesBucket.PutBlob(keyStr, DataShareJSUtils::Convert2U8Vector(env, value));
} else {
LOG_ERROR("valuesBucket error");
}
}
void AnalysisValuesBucket(DataShareValuesBucket &valuesBucket, const napi_env &env, const napi_value &arg)
{
napi_value keys = 0;
@ -92,41 +125,6 @@ void AnalysisValuesBucket(DataShareValuesBucket &valuesBucket, const napi_env &e
}
}
void SetValuesBucketObject(
DataShareValuesBucket &valuesBucket, const napi_env &env, std::string keyStr, napi_value value)
{
napi_valuetype valueType = napi_undefined;
napi_typeof(env, value, &valueType);
if (valueType == napi_string) {
std::string valueString = DataShareJSUtils::UnwrapStringFromJS(env, value);
LOG_INFO("ValueObject type:%{public}d, key:%{public}s, value:%{public}s",
valueType,
keyStr.c_str(),
valueString.c_str());
valuesBucket.PutString(keyStr, valueString);
} else if (valueType == napi_number) {
double valueNumber = 0;
napi_get_value_double(env, value, &valueNumber);
valuesBucket.PutDouble(keyStr, valueNumber);
LOG_INFO(
"ValueObject type:%{public}d, key:%{public}s, value:%{public}lf", valueType, keyStr.c_str(), valueNumber);
} else if (valueType == napi_boolean) {
bool valueBool = false;
napi_get_value_bool(env, value, &valueBool);
LOG_INFO(
"ValueObject type:%{public}d, key:%{public}s, value:%{public}d", valueType, keyStr.c_str(), valueBool);
valuesBucket.PutBool(keyStr, valueBool);
} else if (valueType == napi_null) {
valuesBucket.PutNull(keyStr);
LOG_INFO("ValueObject type:%{public}d, key:%{public}s, value:null", valueType, keyStr.c_str());
} else if (valueType == napi_object) {
LOG_INFO("ValueObject type:%{public}d, key:%{public}s, value:Uint8Array", valueType, keyStr.c_str());
valuesBucket.PutBlob(keyStr, DataShareJSUtils::ConvertU8Vector(env, value));
} else {
LOG_ERROR("valuesBucket error");
}
}
void GetValueBucketObject(DataShareValuesBucket &valuesBucket, const napi_env &env, const napi_value &arg)
{
AnalysisValuesBucket(valuesBucket, env, arg);

View File

@ -2161,8 +2161,10 @@ napi_value UpdateWrap(napi_env env, napi_callback_info info, DSHelperUpdateCB *u
}
UnwrapDataSharePredicates(updateCB->predicates, env, args[PARAM1]);
updateCB->valueBucket.Clear();
AnalysisValuesBucket(updateCB->valueBucket, env, args[PARAM2]);
DataShareHelper *objectInfo = nullptr;
napi_unwrap(env, thisVar, (void **)&objectInfo);
LOG_INFO("%{public}s,DataShareHelper objectInfo = %{public}p", __func__, objectInfo);

View File

@ -60,6 +60,9 @@ ohos_shared_library("rdb") {
"napi:ace_napi",
"relational_store:native_appdatafwk",
"relational_store:native_rdb",
"data_share:datashare_abilitykit",
"relational_store:native_rdb_data_share_adapter",
"data_share:datashare_common",
]
subsystem_name = "distributeddatamgr"

View File

@ -21,10 +21,11 @@
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "napi/native_node_api.h"
#include "result_set_bridge.h"
namespace OHOS {
namespace RdbJsKit {
class ResultSetProxy final {
class ResultSetProxy final : public DataShare::ResultSetBridge::Creator {
public:
ResultSetProxy() = default;
~ResultSetProxy();
@ -34,6 +35,7 @@ public:
static std::shared_ptr<NativeRdb::AbsSharedResultSet> GetNativeObject(
const napi_env &env, const napi_value &arg);
static napi_value GetConstructor(napi_env env);
std::shared_ptr<DataShare::ResultSetBridge> Create() override;
private:
static std::shared_ptr<NativeRdb::AbsSharedResultSet> &GetInnerResultSet(napi_env env, napi_callback_info info);

View File

@ -78,6 +78,12 @@ void RdbPredicatesProxy::Init(napi_env env, napi_value exports)
NAPI_CALL_RETURN_VOID(env, napi_create_reference(env, cons, 1, &constructor_));
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, exports, "RdbPredicates", cons));
napi_value global = nullptr;
napi_status status = napi_get_global(env, &global);
NAPI_ASSERT_RETURN_VOID(env, status == napi_ok, "RdbPredicatesProxy get napi global failed");
status = napi_set_named_property(env, global, "RdbPredicatesConstructor", cons);
NAPI_ASSERT_RETURN_VOID(env, status == napi_ok, "RdbPredicatesProxy set RdbPredicates Constructor failed");
LOG_DEBUG("RdbPredicatesProxy::Init end");
}

View File

@ -17,12 +17,14 @@
#include <cinttypes>
#include "datashare_predicates_proxy.h"
#include "js_logger.h"
#include "js_utils.h"
#include "napi_async_proxy.h"
#include "napi_rdb_predicates.h"
#include "napi_result_set.h"
#include "rdb_errno.h"
#include "rdb_utils.h"
#include "securec.h"
using namespace OHOS::NativeRdb;
@ -74,6 +76,7 @@ public:
std::string srcName;
int32_t enumArg;
DistributedRdb::SyncResult syncResult;
std::shared_ptr<RdbPredicates> rdbPredicates = nullptr;
};
static __thread napi_ref constructor_ = nullptr;
@ -338,8 +341,27 @@ void ParseEnumArg(const napi_env &env, const napi_value &arg, RdbStoreContext *a
void ParsePredicates(const napi_env &env, const napi_value &arg, RdbStoreContext *asyncContext)
{
napi_unwrap(env, arg, reinterpret_cast<void **>(&asyncContext->predicatesProxy));
asyncContext->tableName = asyncContext->predicatesProxy->GetPredicates()->GetTableName();
bool result = false;
napi_value global = nullptr;
napi_status status = napi_get_global(env, &global);
NAPI_ASSERT_RETURN_VOID(env, status == napi_ok, "get napi global failed");
napi_value rdbPredicatesConstructor = nullptr;
status = napi_get_named_property(env, global, "RdbPredicatesConstructor", &rdbPredicatesConstructor);
NAPI_ASSERT_RETURN_VOID(env, status == napi_ok, "get RdbPredicates constructor failed");
status = napi_instanceof(env, arg,rdbPredicatesConstructor, &result);
if ((status == napi_ok) && (result != false)) {
LOG_DEBUG("Parse RDB Predicates");
napi_unwrap(env, arg, reinterpret_cast<void **>(&asyncContext->predicatesProxy));
asyncContext->tableName = asyncContext->predicatesProxy->GetPredicates()->GetTableName();
asyncContext->rdbPredicates = asyncContext->predicatesProxy->GetPredicates();
} else {
LOG_DEBUG("Parse DataShare Predicates");
std::shared_ptr<DataShare::DataSharePredicates> dsPredicates =
DataShare::DataSharePredicatesProxy::GetNativePredicates(env, arg);
asyncContext->rdbPredicates = std::make_shared<RdbPredicates>(
RdbDataShareAdapter::RdbUtils::ToPredicates(*dsPredicates, asyncContext->tableName));
}
LOG_DEBUG("ParsePredicates end");
}
@ -410,7 +432,7 @@ void ParseValuesBucket(const napi_env &env, const napi_value &arg, RdbStoreConte
uint32_t arrLen = 0;
napi_status status = napi_get_array_length(env, keys, &arrLen);
if (status != napi_ok) {
LOG_DEBUG("ValuesBucket get_array_length errr");
LOG_DEBUG("ValuesBucket errr");
return;
}
for (size_t i = 0; i < arrLen; ++i) {
@ -451,6 +473,23 @@ void ParseValuesBucket(const napi_env &env, const napi_value &arg, RdbStoreConte
LOG_DEBUG("ParseValuesBucket end");
}
bool IsNapiString(napi_env env, napi_callback_info info)
{
constexpr size_t MIN_ARGC = 1;
size_t argc = MIN_ARGC;
napi_value args[1] = { 0 };
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
if (argc < MIN_ARGC) {
return false;
}
napi_valuetype type;
napi_typeof(env, args[0], &type);
if (type == napi_string) {
return true;
}
return false;
}
napi_value RdbStoreProxy::Insert(napi_env env, napi_callback_info info)
{
LOG_DEBUG("RdbStoreProxy::Insert start");
@ -485,6 +524,9 @@ napi_value RdbStoreProxy::Delete(napi_env env, napi_callback_info info)
NapiAsyncProxy<RdbStoreContext> proxy;
proxy.Init(env, info);
std::vector<NapiAsyncProxy<RdbStoreContext>::InputParser> parsers;
if (IsNapiString(env, info)) {
parsers.push_back(ParseTableName);
}
parsers.push_back(ParsePredicates);
proxy.ParseInputs(parsers, ParseThis);
return proxy.DoAsyncWork(
@ -492,9 +534,9 @@ napi_value RdbStoreProxy::Delete(napi_env env, napi_callback_info info)
[](RdbStoreContext *context) {
LOG_DEBUG("RdbStoreProxy::Delete Async");
RdbStoreProxy *obj = reinterpret_cast<RdbStoreProxy *>(context->boundObj);
int temp = 0;
int errCode = obj->rdbStore_->Delete(temp, *(context->predicatesProxy->GetPredicates()));
context->rowId = temp;
int deletedRows = 0;
int errCode = obj->rdbStore_->Delete(deletedRows, *(context->rdbPredicates));
context->rowId = deletedRows;
LOG_DEBUG("RdbStoreProxy::Delete errCode is: %{public}d", errCode);
return errCode;
},
@ -511,6 +553,9 @@ napi_value RdbStoreProxy::Update(napi_env env, napi_callback_info info)
NapiAsyncProxy<RdbStoreContext> proxy;
proxy.Init(env, info);
std::vector<NapiAsyncProxy<RdbStoreContext>::InputParser> parsers;
if (IsNapiString(env, info)) {
parsers.push_back(ParseTableName);
}
parsers.push_back(ParseValuesBucket);
parsers.push_back(ParsePredicates);
proxy.ParseInputs(parsers, ParseThis);
@ -519,11 +564,11 @@ napi_value RdbStoreProxy::Update(napi_env env, napi_callback_info info)
[](RdbStoreContext *context) {
LOG_DEBUG("RdbStoreProxy::Update Async");
RdbStoreProxy *obj = reinterpret_cast<RdbStoreProxy *>(context->boundObj);
int temp = 0;
int changedRows = 0;
context->JSNumber2NativeType(obj->rdbStore_);
int errCode =
obj->rdbStore_->Update(temp, *(context->valuesBucket), *(context->predicatesProxy->GetPredicates()));
context->rowId = temp;
obj->rdbStore_->Update(changedRows, *(context->valuesBucket), *(context->rdbPredicates));
context->rowId = changedRows;
LOG_DEBUG("RdbStoreProxy::Update errCode is: %{public}d", errCode);
return errCode;
},
@ -540,6 +585,9 @@ napi_value RdbStoreProxy::Query(napi_env env, napi_callback_info info)
NapiAsyncProxy<RdbStoreContext> proxy;
proxy.Init(env, info);
std::vector<NapiAsyncProxy<RdbStoreContext>::InputParser> parsers;
if (IsNapiString(env, info)) {
parsers.push_back(ParseTableName);
}
parsers.push_back(ParsePredicates);
parsers.push_back(ParseColumns);
proxy.ParseInputs(parsers, ParseThis);
@ -548,7 +596,7 @@ napi_value RdbStoreProxy::Query(napi_env env, napi_callback_info info)
[](RdbStoreContext *context) {
LOG_DEBUG("RdbStoreProxy::Query Async");
RdbStoreProxy *obj = reinterpret_cast<RdbStoreProxy *>(context->boundObj);
context->resultSet = obj->rdbStore_->Query(*(context->predicatesProxy->GetPredicates()), context->columns);
context->resultSet = obj->rdbStore_->Query(*(context->rdbPredicates), context->columns);
LOG_DEBUG("RdbStoreProxy::Query result is nullptr ? %{public}d", (context->resultSet == nullptr));
return (context->resultSet != nullptr) ? OK : ERR;
},

View File

@ -22,6 +22,7 @@
#include "js_utils.h"
#include "napi_async_proxy.h"
#include "string_ex.h"
#include "rdb_result_set_bridge.h"
using namespace OHOS::NativeRdb;
using namespace OHOS::AppDataMgrJsKit;
@ -75,6 +76,11 @@ std::shared_ptr<NativeRdb::AbsSharedResultSet> ResultSetProxy::GetNativeObject(
return proxy->resultSet_;
}
std::shared_ptr<DataShare::ResultSetBridge> ResultSetProxy::Create()
{
return std::make_shared<RdbDataShareAdapter::RdbResultSetBridge>(resultSet_);
}
napi_value ResultSetProxy::GetConstructor(napi_env env)
{
napi_value cons;

View File

@ -41,7 +41,6 @@ ohos_shared_library("datashare_common") {
"${datashare_common_napi_path}/src/datashare_js_utils.cpp",
"${datashare_common_napi_path}/src/datashare_predicates_proxy.cpp",
"${datashare_common_napi_path}/src/datashare_result_set_proxy.cpp",
"${datashare_common_napi_path}/src/napi_datashare_abstract_result_set.cpp",
"${datashare_common_napi_path}/src/napi_datashare_values_bucket.cpp",
"${datashare_common_native_path}/src/datashare_abs_result_set.cpp",
"${datashare_common_native_path}/src/datashare_block_writer_impl.cpp",
@ -51,7 +50,6 @@ ohos_shared_library("datashare_common") {
"${datashare_common_native_path}/src/datashare_predicates_object.cpp",
"${datashare_common_native_path}/src/datashare_result.cpp",
"${datashare_common_native_path}/src/datashare_result_set.cpp",
"${datashare_common_native_path}/src/datashare_string_utils.cpp",
"${datashare_common_native_path}/src/datashare_value_object.cpp",
"${datashare_common_native_path}/src/datashare_values_bucket.cpp",
"${datashare_common_native_path}/src/ishared_result_set.cpp",

View File

@ -26,16 +26,14 @@ namespace DataShare {
class DataShareAbsPredicates {
public:
virtual ~DataShareAbsPredicates() {}
virtual DataShareAbsPredicates *EqualTo(const std::string &field, const int value) = 0;
virtual DataShareAbsPredicates *EqualTo(const std::string &field, const int64_t value) = 0;
virtual DataShareAbsPredicates *EqualTo(const std::string &field, const double value) = 0;
virtual DataShareAbsPredicates *EqualTo(const std::string &field, const std::string &value) = 0;
virtual DataShareAbsPredicates *EqualTo(const std::string &field, const bool value) = 0;
virtual DataShareAbsPredicates *NotEqualTo(const std::string &field, const int value) = 0;
virtual DataShareAbsPredicates *NotEqualTo(const std::string &field, const int64_t value) = 0;
virtual DataShareAbsPredicates *NotEqualTo(const std::string &field, const double value) = 0;
virtual DataShareAbsPredicates *NotEqualTo(const std::string &field, const std::string &value) = 0;
virtual DataShareAbsPredicates *NotEqualTo(const std::string &field, const bool value) = 0;
virtual DataShareAbsPredicates *EqualTo(const std::string &field, const DataSharePredicatesObject &value) = 0;
virtual DataShareAbsPredicates *NotEqualTo(const std::string &field, const DataSharePredicatesObject &value) = 0;
virtual DataShareAbsPredicates *GreaterThan(const std::string &field, const DataSharePredicatesObject &value) = 0;
virtual DataShareAbsPredicates *LessThan(const std::string &field, const DataSharePredicatesObject &value) = 0;
virtual DataShareAbsPredicates *GreaterThanOrEqualTo(const std::string &field, const DataSharePredicatesObject &value) = 0;
virtual DataShareAbsPredicates *LessThanOrEqualTo(const std::string &field, const DataSharePredicatesObject & value) = 0;
virtual DataShareAbsPredicates *In(const std::string &field, const DataSharePredicatesObject &value) = 0;
virtual DataShareAbsPredicates *NotIn(const std::string &field, const DataSharePredicatesObject &value) = 0;
virtual DataShareAbsPredicates *BeginWrap() = 0;
virtual DataShareAbsPredicates *EndWrap() = 0;
virtual DataShareAbsPredicates *Or() = 0;
@ -51,36 +49,12 @@ public:
const std::string &low, const std::string &high) = 0;
virtual DataShareAbsPredicates *NotBetween(const std::string &field,
const std::string &low, const std::string &high) = 0;
virtual DataShareAbsPredicates *GreaterThan(const std::string &field, const int value) = 0;
virtual DataShareAbsPredicates *GreaterThan(const std::string &field, const int64_t value) = 0;
virtual DataShareAbsPredicates *GreaterThan(const std::string &field, const double value) = 0;
virtual DataShareAbsPredicates *GreaterThan(const std::string &field, const std::string &value) = 0;
virtual DataShareAbsPredicates *LessThan(const std::string &field, const int value) = 0;
virtual DataShareAbsPredicates *LessThan(const std::string &field, const int64_t value) = 0;
virtual DataShareAbsPredicates *LessThan(const std::string &field, const double value) = 0;
virtual DataShareAbsPredicates *LessThan(const std::string &field, const std::string &value) = 0;
virtual DataShareAbsPredicates *GreaterThanOrEqualTo(const std::string &field, const int value) = 0;
virtual DataShareAbsPredicates *GreaterThanOrEqualTo(const std::string &field, const int64_t value) = 0;
virtual DataShareAbsPredicates *GreaterThanOrEqualTo(const std::string &field, const double value) = 0;
virtual DataShareAbsPredicates *GreaterThanOrEqualTo(const std::string &field, const std::string &value) = 0;
virtual DataShareAbsPredicates *LessThanOrEqualTo(const std::string &field, const int value) = 0;
virtual DataShareAbsPredicates *LessThanOrEqualTo(const std::string &field, const int64_t value) = 0;
virtual DataShareAbsPredicates *LessThanOrEqualTo(const std::string &field, const double value) = 0;
virtual DataShareAbsPredicates *LessThanOrEqualTo(const std::string &field, const std::string &value) = 0;
virtual DataShareAbsPredicates *OrderByAsc(const std::string &field) = 0;
virtual DataShareAbsPredicates *OrderByDesc(const std::string &field) = 0;
virtual DataShareAbsPredicates *Distinct() = 0;
virtual DataShareAbsPredicates *Limit(const int number, const int offset) = 0;
virtual DataShareAbsPredicates *GroupBy(const std::vector<std::string> &fields) = 0;
virtual DataShareAbsPredicates *IndexedBy(const std::string &indexName) = 0;
virtual DataShareAbsPredicates *In(const std::string &field, const std::vector<int> &value) = 0;
virtual DataShareAbsPredicates *In(const std::string &field, const std::vector<int64_t> &value) = 0;
virtual DataShareAbsPredicates *In(const std::string &field, const std::vector<double> &value) = 0;
virtual DataShareAbsPredicates *In(const std::string &field, const std::vector<std::string> &value) = 0;
virtual DataShareAbsPredicates *NotIn(const std::string &field, const std::vector<int> &value) = 0;
virtual DataShareAbsPredicates *NotIn(const std::string &field, const std::vector<int64_t> &value) = 0;
virtual DataShareAbsPredicates *NotIn(const std::string &field, const std::vector<double> &value) = 0;
virtual DataShareAbsPredicates *NotIn(const std::string &field, const std::vector<std::string> &value) = 0;
virtual DataShareAbsPredicates *KeyPrefix(const std::string &prefix) = 0;
virtual DataShareAbsPredicates *InKeys(const std::vector<std::string> &keys) = 0;
virtual const std::list<OperationItem>& GetOperationList() const = 0;

View File

@ -54,6 +54,7 @@ public:
protected:
// The default position of the result set
static const int INIT_POS = -1;
// Current row position
int rowPos_;
// Indicates whether the result set is closed
bool isClosed_;

View File

@ -16,9 +16,9 @@
#ifndef DATASHARE_BLOCK_WRITER_IMPL_H
#define DATASHARE_BLOCK_WRITER_IMPL_H
#include <string>
#include "shared_block.h"
#include "datashare_block_writer.h"
#include "result_set_bridge.h"
#include "datashare_errno.h"
namespace OHOS {
namespace DataShare {
@ -26,7 +26,7 @@ namespace DataShare {
* This class stores a set of rows from a database in a buffer
* which is used as the set of query result.
*/
class DataShareBlockWriterImpl : public virtual DataShareBlockWriter {
class DataShareBlockWriterImpl : public virtual ResultSetBridge::Writer {
public:
/**
* SharedBlock constructor.
@ -41,17 +41,17 @@ public:
/**
* SharedBlock Deconstruction.
*/
~DataShareBlockWriterImpl();
virtual ~DataShareBlockWriterImpl();
/**
* Clear current shared block.
*/
int Clear() override;
int Clear();
/**
* Set a shared block column.
*/
int SetColumnNum(uint32_t numColumns) override;
int SetColumnNum(uint32_t numColumns);
/**
* Allocate a row unit and its directory.
@ -61,32 +61,32 @@ public:
/**
* Release the value of the last row.
*/
int FreeLastRow() override;
/**
* Write blob data to the shared block.
*/
int WriteBlob(uint32_t row, uint32_t column, const void *value, size_t Size) override;
/**
* Write string data to the shared block.
*/
int WriteString(uint32_t row, uint32_t column, const char *value, size_t sizeIncludingNull) override;
/**
* Write long data to the shared block.
*/
int WriteLong(uint32_t row, uint32_t column, int64_t value) override;
/**
* Write Double data to the shared block.
*/
int WriteDouble(uint32_t row, uint32_t column, double value) override;
int FreeLastRow();
/**
* Write Null data to the shared block.
*/
int WriteNull(uint32_t row, uint32_t column) override;
virtual int Write(uint32_t column) override;
/**
* Write long data to the shared block.
*/
virtual int Write(uint32_t column, int64_t value) override;
/**
* Write Double data to the shared block.
*/
virtual int Write(uint32_t column, double value) override;
/**
* Write blob data to the shared block.
*/
virtual int Write(uint32_t column, const uint8_t *value, size_t Size) override;
/**
* Write string data to the shared block.
*/
virtual int Write(uint32_t column, const char *value, size_t sizeIncludingNull) override;
/**
* The mHeader of the current result set.
@ -96,32 +96,32 @@ public:
/**
* Size of the used byte in the block.
*/
size_t GetUsedBytes() override;
size_t GetUsedBytes();
/**
* The name of the current result set.
*/
std::string Name() override;
std::string Name();
/**
* The size of the current result set.
*/
size_t Size() override;
size_t Size();
/**
* The row number of the current result set.
*/
uint32_t GetRowNum() override;
uint32_t GetRowNum();
/**
* The column number of the current result set.
*/
uint32_t GetColumnNum() override;
uint32_t GetColumnNum();
/**
* Write raw data in block.
*/
size_t SetRawData(const void *rawData, size_t size) override;
size_t SetRawData(const void *rawData, size_t size);
/**
* The fd of shared memory
@ -133,6 +133,20 @@ public:
*/
AppDataFwk::SharedBlock *GetBlock() const;
private:
/**
* The fd of shared memory
*/
bool GetCurrentRowIndex(uint32_t &rowIndex);
/**
* Convert ShareBlock error code to DataShare format
*/
int ConvertErrorCode(int shareBlockErr)
{
return shareBlockErr == AppDataFwk::SharedBlock::SHARED_BLOCK_OK ? E_OK : E_ERROR;
}
private:
AppDataFwk::SharedBlock *shareBlock_;
};

View File

@ -86,9 +86,8 @@ int DataShareAbsResultSet::GoTo(int offset)
int ret = GoToRow(rowPos_ + offset);
if (ret != E_OK) {
LOG_ERROR("DataShareAbsResultSet::GoTo return ret is wrong!");
return ret;
}
return E_OK;
return ret;
}
int DataShareAbsResultSet::GoToFirstRow()
@ -96,9 +95,8 @@ int DataShareAbsResultSet::GoToFirstRow()
int ret = GoToRow(0);
if (ret != E_OK) {
LOG_ERROR("DataShareAbsResultSet::GoToFirstRow return ret is wrong!");
return ret;
}
return E_OK;
return ret;
}
int DataShareAbsResultSet::GoToLastRow()
@ -113,9 +111,8 @@ int DataShareAbsResultSet::GoToLastRow()
ret = GoToRow(rowCnt - 1);
if (ret != E_OK) {
LOG_ERROR("DataShareAbsResultSet::GoToLastRow return GoToRow::ret is wrong!");
return ret;
}
return E_OK;
return ret;
}
int DataShareAbsResultSet::GoToNextRow()
@ -123,9 +120,8 @@ int DataShareAbsResultSet::GoToNextRow()
int ret = GoToRow(rowPos_ + 1);
if (ret != E_OK) {
LOG_ERROR("DataShareAbsResultSet::GoToNextRow return GoToRow::ret is wrong!");
return ret;
}
return E_OK;
return ret;
}
int DataShareAbsResultSet::GoToPreviousRow()
@ -133,9 +129,8 @@ int DataShareAbsResultSet::GoToPreviousRow()
int ret = GoToRow(rowPos_ - 1);
if (ret != E_OK) {
LOG_ERROR("DataShareAbsResultSet::GoToPreviousRow return GoToRow::ret is wrong!");
return ret;
}
return E_OK;
return ret;
}
int DataShareAbsResultSet::IsAtFirstRow(bool &result) const

View File

@ -38,7 +38,7 @@ int DataShareBlockWriterImpl::Clear()
LOG_INFO("DataShareBlockWriterImpl::Clear shareBlock_ is nullptr");
return E_ERROR;
}
return shareBlock_->Clear();
return ConvertErrorCode(shareBlock_->Clear());
}
int DataShareBlockWriterImpl::SetColumnNum(uint32_t numColumns)
@ -47,7 +47,7 @@ int DataShareBlockWriterImpl::SetColumnNum(uint32_t numColumns)
LOG_INFO("DataShareBlockWriterImpl::SetColumnNum shareBlock_ is nullptr");
return E_ERROR;
}
return shareBlock_->SetColumnNum(numColumns);
return ConvertErrorCode(shareBlock_->SetColumnNum(numColumns));
}
int DataShareBlockWriterImpl::AllocRow()
@ -56,7 +56,7 @@ int DataShareBlockWriterImpl::AllocRow()
LOG_INFO("DataShareBlockWriterImpl::AllocRow shareBlock_ is nullptr");
return E_ERROR;
}
return shareBlock_->AllocRow();
return ConvertErrorCode(shareBlock_->AllocRow());
}
int DataShareBlockWriterImpl::FreeLastRow()
@ -65,52 +65,57 @@ int DataShareBlockWriterImpl::FreeLastRow()
LOG_INFO("DataShareBlockWriterImpl::FreeLastRow shareBlock_ is nullptr");
return E_ERROR;
}
return shareBlock_->FreeLastRow();
return ConvertErrorCode(shareBlock_->FreeLastRow());
}
int DataShareBlockWriterImpl::WriteBlob(uint32_t row, uint32_t column, const void *value, size_t size)
int DataShareBlockWriterImpl::Write(uint32_t column)
{
if (shareBlock_ == nullptr) {
LOG_INFO("DataShareBlockWriterImpl::WriteBlob shareBlock_ is nullptr");
uint32_t currentRowIndex = 0;
if (!GetCurrentRowIndex(currentRowIndex)) {
LOG_INFO("Write null fail");
return E_ERROR;
}
return shareBlock_->PutBlob(row, column, value, size);
return ConvertErrorCode(shareBlock_->PutNull(currentRowIndex, column));
}
int DataShareBlockWriterImpl::WriteString(uint32_t row, uint32_t column, const char *value, size_t sizeIncludingNull)
int DataShareBlockWriterImpl::Write(uint32_t column, int64_t value)
{
if (shareBlock_ == nullptr) {
LOG_INFO("DataShareBlockWriterImpl::WriteString shareBlock_ is nullptr");
uint32_t currentRowIndex = 0;
if (!GetCurrentRowIndex(currentRowIndex)) {
LOG_INFO("Write long fail");
return E_ERROR;
}
return shareBlock_->PutString(row, column, value, sizeIncludingNull);
return ConvertErrorCode(shareBlock_->PutLong(currentRowIndex, column, value));
}
int DataShareBlockWriterImpl::WriteLong(uint32_t row, uint32_t column, int64_t value)
int DataShareBlockWriterImpl::Write(uint32_t column, double value)
{
if (shareBlock_ == nullptr) {
LOG_INFO("DataShareBlockWriterImpl::WriteLong shareBlock_ is nullptr");
uint32_t currentRowIndex = 0;
if (!GetCurrentRowIndex(currentRowIndex)) {
LOG_INFO("Write double fail");
return E_ERROR;
}
return shareBlock_->PutLong(row, column, value);
return ConvertErrorCode(shareBlock_->PutDouble(currentRowIndex, column, value));
}
int DataShareBlockWriterImpl::WriteDouble(uint32_t row, uint32_t column, double value)
int DataShareBlockWriterImpl::Write(uint32_t column, const uint8_t *value, size_t size)
{
if (shareBlock_ == nullptr) {
LOG_INFO("DataShareBlockWriterImpl::WriteDouble shareBlock_ is nullptr");
uint32_t currentRowIndex = 0;
if (!GetCurrentRowIndex(currentRowIndex)) {
LOG_INFO("Write blob fail");
return E_ERROR;
}
return shareBlock_->PutDouble(row, column, value);
return ConvertErrorCode(shareBlock_->PutBlob(currentRowIndex, column, value, size));
}
int DataShareBlockWriterImpl::WriteNull(uint32_t row, uint32_t column)
int DataShareBlockWriterImpl::Write(uint32_t column, const char *value, size_t sizeIncludingNull)
{
if (shareBlock_ == nullptr) {
LOG_INFO("DataShareBlockWriterImpl::WriteNull shareBlock_ is nullptr");
uint32_t currentRowIndex = 0;
if (!GetCurrentRowIndex(currentRowIndex)) {
LOG_INFO("Write string fail");
return E_ERROR;
}
return shareBlock_->PutNull(row, column);
return ConvertErrorCode(shareBlock_->PutString(currentRowIndex, column, value, sizeIncludingNull));
}
const void *DataShareBlockWriterImpl::GetHeader()
@ -188,5 +193,19 @@ AppDataFwk::SharedBlock *DataShareBlockWriterImpl::GetBlock() const
{
return shareBlock_;
}
bool DataShareBlockWriterImpl::GetCurrentRowIndex(uint32_t &rowIndex)
{
if (shareBlock_ == nullptr) {
LOG_INFO("shareBlock_ is nullptr");
return false;
}
uint32_t rowNum = shareBlock_->GetRowNum();
if (rowNum > 0) {
rowIndex = rowNum - 1;
return true;
}
return false;
}
} // namespace DataShare
} // namespace OHOS

View File

@ -36,57 +36,10 @@ DataSharePredicates::~DataSharePredicates()
/**
* EqualTo
*/
DataSharePredicates *DataSharePredicates::EqualTo(const std::string &field, const int value)
DataSharePredicates *DataSharePredicates::EqualTo(const std::string &field, const DataSharePredicatesObject &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}d", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::EqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::EqualTo(const std::string &field, const int64_t value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}" PRId64 "", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::EqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::EqualTo(const std::string &field, const double value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}f", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::EqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::EqualTo(const std::string &field, const std::string &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}s", __func__, field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::EqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::EqualTo(const std::string &field, const bool value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}d", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("%{public}s call field%{public}s", __func__, field.c_str());
SetOperationList(EQUAL_TO, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::EqualTo End");
return this;
}
@ -94,57 +47,10 @@ DataSharePredicates *DataSharePredicates::EqualTo(const std::string &field, cons
/**
* NotEqualTo
*/
DataSharePredicates *DataSharePredicates::NotEqualTo(const std::string &field, const int value)
DataSharePredicates *DataSharePredicates::NotEqualTo(const std::string &field, const DataSharePredicatesObject &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}d", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(NOT_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::NotEqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::NotEqualTo(const std::string &field, const int64_t value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}" PRId64 "", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(NOT_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::NotEqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::NotEqualTo(const std::string &field, const double value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}f", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(NOT_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::NotEqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::NotEqualTo(const std::string &field, const std::string &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}s", __func__, field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(NOT_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::NotEqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::NotEqualTo(const std::string &field, const bool value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}d", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(NOT_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("%{public}s call field%{public}s", __func__, field.c_str());
SetOperationList(NOT_EQUAL_TO, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::NotEqualTo End");
return this;
}
@ -152,46 +58,10 @@ DataSharePredicates *DataSharePredicates::NotEqualTo(const std::string &field, c
/**
* GreaterThan
*/
DataSharePredicates *DataSharePredicates::GreaterThan(const std::string &field, const int value)
DataSharePredicates *DataSharePredicates::GreaterThan(const std::string &field, const DataSharePredicatesObject &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}d", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(GREATER_THAN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::GreaterThan End");
return this;
}
DataSharePredicates *DataSharePredicates::GreaterThan(const std::string &field, const int64_t value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}" PRId64 "", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(GREATER_THAN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::GreaterThan End");
return this;
}
DataSharePredicates *DataSharePredicates::GreaterThan(const std::string &field, const double value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}f", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(GREATER_THAN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::GreaterThan End");
return this;
}
DataSharePredicates *DataSharePredicates::GreaterThan(const std::string &field, const std::string &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}s", __func__, field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(GREATER_THAN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("%{public}s call field%{public}s", __func__, field.c_str());
SetOperationList(GREATER_THAN, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::GreaterThan End");
return this;
}
@ -199,46 +69,10 @@ DataSharePredicates *DataSharePredicates::GreaterThan(const std::string &field,
/**
* LessThan
*/
DataSharePredicates *DataSharePredicates::LessThan(const std::string &field, const int value)
DataSharePredicates *DataSharePredicates::LessThan(const std::string &field, const DataSharePredicatesObject &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}d", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(LESS_THAN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::LessThan End");
return this;
}
DataSharePredicates *DataSharePredicates::LessThan(const std::string &field, const int64_t value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}" PRId64 "", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(LESS_THAN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::LessThan End");
return this;
}
DataSharePredicates *DataSharePredicates::LessThan(const std::string &field, const double value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}f", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(LESS_THAN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::LessThan End");
return this;
}
DataSharePredicates *DataSharePredicates::LessThan(const std::string &field, const std::string &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}s", __func__, field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(LESS_THAN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("%{public}s call field%{public}s", __func__, field.c_str());
SetOperationList(LESS_THAN, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::LessThan End");
return this;
}
@ -246,46 +80,10 @@ DataSharePredicates *DataSharePredicates::LessThan(const std::string &field, con
/**
* GreaterThanOrEqualTo
*/
DataSharePredicates *DataSharePredicates::GreaterThanOrEqualTo(const std::string &field, const int value)
DataSharePredicates *DataSharePredicates::GreaterThanOrEqualTo(const std::string &field, const DataSharePredicatesObject &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}d", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(GREATER_THAN_OR_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::GreaterThanOrEqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::GreaterThanOrEqualTo(const std::string &field, const int64_t value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}" PRId64 "", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(GREATER_THAN_OR_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::GreaterThanOrEqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::GreaterThanOrEqualTo(const std::string &field, const double value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}f", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(GREATER_THAN_OR_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::GreaterThanOrEqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::GreaterThanOrEqualTo(const std::string &field, const std::string &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}s", __func__, field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(GREATER_THAN_OR_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("%{public}s call field%{public}s", __func__, field.c_str());
SetOperationList(GREATER_THAN_OR_EQUAL_TO, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::GreaterThanOrEqualTo End");
return this;
}
@ -293,46 +91,10 @@ DataSharePredicates *DataSharePredicates::GreaterThanOrEqualTo(const std::string
/**
* LessThanOrEqualTo
*/
DataSharePredicates *DataSharePredicates::LessThanOrEqualTo(const std::string &field, const int value)
DataSharePredicates *DataSharePredicates::LessThanOrEqualTo(const std::string &field, const DataSharePredicatesObject &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}d", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(GREATER_THAN_OR_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::LessThanOrEqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::LessThanOrEqualTo(const std::string &field, const int64_t value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}" PRId64 "", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(LESS_THAN_OR_EQUAL_TO, para1, para2, para3, TWO_COUNT);
return this;
LOG_DEBUG("DataSharePredicates::LessThanOrEqualTo End");
}
DataSharePredicates *DataSharePredicates::LessThanOrEqualTo(const std::string &field, const double value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}f", __func__, field.c_str(), value);
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(LESS_THAN_OR_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::LessThanOrEqualTo End");
return this;
}
DataSharePredicates *DataSharePredicates::LessThanOrEqualTo(const std::string &field, const std::string &value)
{
LOG_DEBUG("%{public}s call field%{public}s,value%{public}s", __func__, field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(LESS_THAN_OR_EQUAL_TO, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("%{public}s call field%{public}s", __func__, field.c_str());
SetOperationList(GREATER_THAN_OR_EQUAL_TO, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::LessThanOrEqualTo End");
return this;
}
@ -340,43 +102,10 @@ DataSharePredicates *DataSharePredicates::LessThanOrEqualTo(const std::string &f
/**
* In
*/
DataSharePredicates *DataSharePredicates::In(const std::string &field, const std::vector<int> &value)
DataSharePredicates *DataSharePredicates::In(const std::string &field, const DataSharePredicatesObject &value)
{
LOG_DEBUG("DataSharePredicates::In Start field%{public}s,value%{public}d", field.c_str(), value.at(0));
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(IN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::In End");
return this;
}
DataSharePredicates *DataSharePredicates::In(const std::string &field, const std::vector<int64_t> &value)
{
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(IN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::In End");
return this;
}
DataSharePredicates *DataSharePredicates::In(const std::string &field, const std::vector<double> &value)
{
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(IN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::In End");
return this;
}
DataSharePredicates *DataSharePredicates::In(const std::string &field, const std::vector<std::string> &value)
{
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(IN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::In Start field%{public}s", field.c_str());
SetOperationList(IN, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::In End");
return this;
}
@ -384,43 +113,10 @@ DataSharePredicates *DataSharePredicates::In(const std::string &field, const std
/**
* NotIn
*/
DataSharePredicates *DataSharePredicates::NotIn(const std::string &field, const std::vector<int> &value)
DataSharePredicates *DataSharePredicates::NotIn(const std::string &field, const DataSharePredicatesObject &value)
{
LOG_DEBUG("DataSharePredicates::NotIn Start field%{public}s,value%{public}d", field.c_str(), value.at(0));
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(NOT_IN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::NotIn End");
return this;
}
DataSharePredicates *DataSharePredicates::NotIn(const std::string &field, const std::vector<int64_t> &value)
{
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(NOT_IN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::NotIn End");
return this;
}
DataSharePredicates *DataSharePredicates::NotIn(const std::string &field, const std::vector<double> &value)
{
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(NOT_IN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::NotIn End");
return this;
}
DataSharePredicates *DataSharePredicates::NotIn(const std::string &field, const std::vector<std::string> &value)
{
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(NOT_IN, para1, para2, para3, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::NotIn Start field%{public}s", field.c_str());
SetOperationList(NOT_IN, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::NotIn End");
return this;
}
@ -431,10 +127,7 @@ DataSharePredicates *DataSharePredicates::NotIn(const std::string &field, const
DataSharePredicates *DataSharePredicates::BeginWrap()
{
LOG_DEBUG("DataSharePredicates::BeginWrap Start");
DataSharePredicatesObject para1;
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(BEGIN_WARP, para1, para2, para3, ZERO_COUNT);
SetOperationList(BEGIN_WARP, {}, {}, {}, ZERO_COUNT);
LOG_DEBUG("DataSharePredicates::BeginWrap End");
return this;
}
@ -445,10 +138,7 @@ DataSharePredicates *DataSharePredicates::BeginWrap()
DataSharePredicates *DataSharePredicates::EndWrap()
{
LOG_DEBUG("DataSharePredicates::EndWrap Start");
DataSharePredicatesObject para1;
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(END_WARP, para1, para2, para3, ZERO_COUNT);
SetOperationList(END_WARP, {}, {}, {}, ZERO_COUNT);
LOG_DEBUG("DataSharePredicates::EndWrap End");
return this;
}
@ -459,10 +149,7 @@ DataSharePredicates *DataSharePredicates::EndWrap()
DataSharePredicates *DataSharePredicates::Or()
{
LOG_DEBUG("DataSharePredicates::Or Start");
DataSharePredicatesObject para1;
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(OR, para1, para2, para3, ZERO_COUNT);
SetOperationList(OR, {}, {}, {}, ZERO_COUNT);
LOG_DEBUG("DataSharePredicates::Or End");
return this;
}
@ -473,10 +160,7 @@ DataSharePredicates *DataSharePredicates::Or()
DataSharePredicates *DataSharePredicates::And()
{
LOG_DEBUG("DataSharePredicates::And Start");
DataSharePredicatesObject para1;
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(AND, para1, para2, para3, ZERO_COUNT);
SetOperationList(AND, {}, {}, {}, ZERO_COUNT);
LOG_DEBUG("DataSharePredicates::And End");
return this;
}
@ -487,10 +171,7 @@ DataSharePredicates *DataSharePredicates::And()
DataSharePredicates *DataSharePredicates::Contains(const std::string &field, const std::string &value)
{
LOG_DEBUG("DataSharePredicates::Contains Start field%{public}s,value%{public}s", field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(CONTAINS, para1, para2, para3, TWO_COUNT);
SetOperationList(CONTAINS, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::Contains End");
return this;
}
@ -501,10 +182,7 @@ DataSharePredicates *DataSharePredicates::Contains(const std::string &field, con
DataSharePredicates *DataSharePredicates::BeginsWith(const std::string &field, const std::string &value)
{
LOG_DEBUG("DataSharePredicates::BeginsWith Start field%{public}s,value%{public}s", field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(BEGIN_WITH, para1, para2, para3, TWO_COUNT);
SetOperationList(BEGIN_WITH, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::BeginsWith End");
return this;
}
@ -515,10 +193,7 @@ DataSharePredicates *DataSharePredicates::BeginsWith(const std::string &field, c
DataSharePredicates *DataSharePredicates::EndsWith(const std::string &field, const std::string &value)
{
LOG_DEBUG("DataSharePredicates::EndsWith Start field%{public}s,value%{public}s", field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(END_WITH, para1, para2, para3, TWO_COUNT);
SetOperationList(END_WITH, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::EndsWith End");
return this;
}
@ -529,10 +204,7 @@ DataSharePredicates *DataSharePredicates::EndsWith(const std::string &field, con
DataSharePredicates *DataSharePredicates::IsNull(const std::string &field)
{
LOG_DEBUG("DataSharePredicates::IsNull Start field%{public}s", field.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(IS_NULL, para1, para2, para3, ONE_COUNT);
SetOperationList(IS_NULL, field, {}, {}, ONE_COUNT);
LOG_DEBUG("DataSharePredicates::IsNull End");
return this;
}
@ -543,10 +215,7 @@ DataSharePredicates *DataSharePredicates::IsNull(const std::string &field)
DataSharePredicates *DataSharePredicates::IsNotNull(const std::string &field)
{
LOG_DEBUG("DataSharePredicates::IsNotNull Start field%{public}s", field.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(IS_NOT_NULL, para1, para2, para3, ONE_COUNT);
SetOperationList(IS_NOT_NULL, field, {}, {}, ONE_COUNT);
LOG_DEBUG("DataSharePredicates::IsNotNull End");
return this;
}
@ -557,10 +226,7 @@ DataSharePredicates *DataSharePredicates::IsNotNull(const std::string &field)
DataSharePredicates *DataSharePredicates::Like(const std::string &field, const std::string &value)
{
LOG_DEBUG("DataSharePredicates::Like Start field%{public}s value%{public}s", field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(LIKE, para1, para2, para3, TWO_COUNT);
SetOperationList(LIKE, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::Like End");
return this;
}
@ -571,10 +237,7 @@ DataSharePredicates *DataSharePredicates::Like(const std::string &field, const s
DataSharePredicates *DataSharePredicates::Unlike(const std::string &field, const std::string &value)
{
LOG_DEBUG("DataSharePredicates::Unlike Start field%{public}s value%{public}s", field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(UNLIKE, para1, para2, para3, TWO_COUNT);
SetOperationList(UNLIKE, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::Unlike End");
return this;
}
@ -585,10 +248,7 @@ DataSharePredicates *DataSharePredicates::Unlike(const std::string &field, const
DataSharePredicates *DataSharePredicates::Glob(const std::string &field, const std::string &value)
{
LOG_DEBUG("DataSharePredicates::Glob Start field%{public}s value%{public}s", field.c_str(), value.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(value);
DataSharePredicatesObject para3;
SetOperationList(GLOB, para1, para2, para3, TWO_COUNT);
SetOperationList(GLOB, field, value, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::Glob End");
return this;
}
@ -601,10 +261,7 @@ DataSharePredicates *DataSharePredicates::Between(const std::string &field,
{
LOG_DEBUG("DataSharePredicates::Between Start field%{public}s low%{public}s high%{public}s",
field.c_str(), low.c_str(), high.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(low);
DataSharePredicatesObject para3(high);
SetOperationList(BETWEEN, para1, para2, para3, THREE_COUNT);
SetOperationList(BETWEEN, field, low, high, THREE_COUNT);
LOG_DEBUG("DataSharePredicates::Between End");
return this;
}
@ -617,10 +274,7 @@ DataSharePredicates *DataSharePredicates::NotBetween(const std::string &field,
{
LOG_DEBUG("DataSharePredicates::NotBetween Start field%{public}s low%{public}s high%{public}s",
field.c_str(), low.c_str(), high.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2(low);
DataSharePredicatesObject para3(high);
SetOperationList(NOTBETWEEN, para1, para2, para3, THREE_COUNT);
SetOperationList(NOTBETWEEN, field, low, high, THREE_COUNT);
LOG_DEBUG("DataSharePredicates::NotBetween End");
return this;
}
@ -631,10 +285,7 @@ DataSharePredicates *DataSharePredicates::NotBetween(const std::string &field,
DataSharePredicates *DataSharePredicates::OrderByAsc(const std::string &field)
{
LOG_DEBUG("DataSharePredicates::OrderByAsc Start field%{public}s", field.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(ORDER_BY_ASC, para1, para2, para3, ONE_COUNT);
SetOperationList(ORDER_BY_ASC, field, {}, {}, ONE_COUNT);
LOG_DEBUG("DataSharePredicates::OrderByAsc End");
return this;
}
@ -645,10 +296,7 @@ DataSharePredicates *DataSharePredicates::OrderByAsc(const std::string &field)
DataSharePredicates *DataSharePredicates::OrderByDesc(const std::string &field)
{
LOG_DEBUG("DataSharePredicates::OrderByDesc Start field%{public}s", field.c_str());
DataSharePredicatesObject para1(field);
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(ORDER_BY_DESC, para1, para2, para3, ONE_COUNT);
SetOperationList(ORDER_BY_DESC, field, {}, {}, ONE_COUNT);
LOG_DEBUG("DataSharePredicates::OrderByDesc End");
return this;
}
@ -659,10 +307,7 @@ DataSharePredicates *DataSharePredicates::OrderByDesc(const std::string &field)
DataSharePredicates *DataSharePredicates::Distinct()
{
LOG_DEBUG("DataSharePredicates::Distinct Start");
DataSharePredicatesObject para1;
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(DISTINCT, para1, para2, para3, ZERO_COUNT);
SetOperationList(DISTINCT, {}, {}, {}, ZERO_COUNT);
LOG_DEBUG("DataSharePredicates::Distinct End");
return this;
}
@ -673,10 +318,7 @@ DataSharePredicates *DataSharePredicates::Distinct()
DataSharePredicates *DataSharePredicates::Limit(const int number, const int offset)
{
LOG_DEBUG("DataSharePredicates::Limit Start number%{public}d offset%{public}d", number, offset);
DataSharePredicatesObject para1(number);
DataSharePredicatesObject para2(offset);
DataSharePredicatesObject para3;
SetOperationList(LIMIT, para1, para2, para3, TWO_COUNT);
SetOperationList(LIMIT, number, offset, {}, TWO_COUNT);
LOG_DEBUG("DataSharePredicates::Limit End");
return this;
}
@ -687,10 +329,7 @@ DataSharePredicates *DataSharePredicates::Limit(const int number, const int offs
DataSharePredicates *DataSharePredicates::GroupBy(const std::vector<std::string> &fields)
{
LOG_DEBUG("DataSharePredicates::GroupBy Start fields%{public}s", fields.at(0).c_str());
DataSharePredicatesObject para1(fields);
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(GROUP_BY, para1, para2, para3, ONE_COUNT);
SetOperationList(GROUP_BY, fields, {}, {}, ONE_COUNT);
LOG_DEBUG("DataSharePredicates::GroupBy End");
return this;
}
@ -701,10 +340,7 @@ DataSharePredicates *DataSharePredicates::GroupBy(const std::vector<std::string>
DataSharePredicates *DataSharePredicates::IndexedBy(const std::string &indexName)
{
LOG_DEBUG("DataSharePredicates::IndexedBy Start indexName%{public}s", indexName.c_str());
DataSharePredicatesObject para1(indexName);
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(INDEXED_BY, para1, para2, para3, ONE_COUNT);
SetOperationList(INDEXED_BY, indexName, {}, {}, ONE_COUNT);
LOG_DEBUG("DataSharePredicates::IndexedBy End");
return this;
}
@ -715,10 +351,7 @@ DataSharePredicates *DataSharePredicates::IndexedBy(const std::string &indexName
DataSharePredicates *DataSharePredicates::KeyPrefix(const std::string &prefix)
{
LOG_DEBUG("DataSharePredicates::KeyPrefix Start prefix%{public}s", prefix.c_str());
DataSharePredicatesObject para1(prefix);
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(KEY_PREFIX, para1, para2, para3, ONE_COUNT);
SetOperationList(KEY_PREFIX, prefix, {}, {}, ONE_COUNT);
LOG_DEBUG("DataSharePredicates::KeyPrefix End");
return this;
}
@ -729,10 +362,7 @@ DataSharePredicates *DataSharePredicates::KeyPrefix(const std::string &prefix)
DataSharePredicates *DataSharePredicates::InKeys(const std::vector<std::string> &keys)
{
LOG_DEBUG("DataSharePredicates::InKeys Start keys%{public}s", keys.at(0).c_str());
DataSharePredicatesObject para1(keys);
DataSharePredicatesObject para2;
DataSharePredicatesObject para3;
SetOperationList(IN_KEY, para1, para2, para3, ONE_COUNT);
SetOperationList(IN_KEY, keys, {}, {}, ONE_COUNT);
LOG_DEBUG("DataSharePredicates::InKeys End");
return this;
}
@ -848,8 +478,8 @@ SettingMode DataSharePredicates::GetSettingMode() const
/**
* SetOperationList
*/
void DataSharePredicates::SetOperationList(OperationType operationType, DataSharePredicatesObject &para1,
DataSharePredicatesObject &para2, DataSharePredicatesObject &para3, ParameterCount parameterCount)
void DataSharePredicates::SetOperationList(OperationType operationType, const DataSharePredicatesObject &para1,
const DataSharePredicatesObject &para2, const DataSharePredicatesObject &para3, ParameterCount parameterCount)
{
LOG_DEBUG("DataSharePredicates::SetOperationList Start");
OperationItem operationItem {};

View File

@ -29,8 +29,8 @@ DataShareResultSet::DataShareResultSet()
{
}
DataShareResultSet::DataShareResultSet(std::shared_ptr<DataShareAbstractResultSet> &resultSet)
: resultSet_(resultSet)
DataShareResultSet::DataShareResultSet(std::shared_ptr<ResultSetBridge> &bridge)
: bridge_(bridge)
{
std::string name = "DataShare" + std::to_string(blockId_++);
blockWriter_ = std::make_shared<DataShareBlockWriterImpl>(name, DEFAULT_BLOCK_SIZE);
@ -44,29 +44,29 @@ DataShareResultSet::~DataShareResultSet()
int DataShareResultSet::GetAllColumnNames(std::vector<std::string> &columnNames)
{
if (resultSet_ == nullptr) {
LOG_ERROR("resultSet_ is null!");
if (bridge_ == nullptr) {
LOG_ERROR("bridge_ is null!");
return E_ERROR;
}
return resultSet_->GetAllColumnOrKeyName(columnNames);
return bridge_->GetAllColumnNames(columnNames);
}
int DataShareResultSet::GetRowCount(int &count)
{
if (resultSet_ == nullptr) {
LOG_ERROR("resultSet_ is null!");
if (bridge_ == nullptr) {
LOG_ERROR("bridge_ is null!");
return E_ERROR;
}
return resultSet_->GetRowCount(count);
return bridge_->GetRowCount(count);
}
bool DataShareResultSet::OnGo(int oldRowIndex, int newRowIndex)
bool DataShareResultSet::OnGo(int startRowIndex, int targetRowIndex)
{
if (resultSet_ == nullptr) {
LOG_ERROR("resultSet_ is null!");
if (bridge_ == nullptr || blockWriter_ == nullptr) {
LOG_ERROR("bridge_ or blockWriter_ is null!");
return E_ERROR;
}
return resultSet_->OnGo(oldRowIndex, newRowIndex, std::dynamic_pointer_cast<DataShareBlockWriter>(blockWriter_));
return bridge_->OnGo(startRowIndex, targetRowIndex, *blockWriter_);
}
void DataShareResultSet::FillBlock(int startRowIndex, AppDataFwk::SharedBlock *block)
@ -84,7 +84,7 @@ AppDataFwk::SharedBlock *DataShareResultSet::GetBlock() const
int DataShareResultSet::GetDataType(int columnIndex, DataType &dataType)
{
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit((uint32_t)rowPos_, (uint32_t)columnIndex);
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit((uint32_t)rowPos_ - startRowPos_, (uint32_t)columnIndex);
if (!cellUnit) {
LOG_ERROR("DataShareResultSet::GetDataType cellUnit is null!");
return E_ERROR;
@ -95,6 +95,10 @@ int DataShareResultSet::GetDataType(int columnIndex, DataType &dataType)
int DataShareResultSet::GoToRow(int position)
{
if (sharedBlock_ == nullptr) {
LOG_ERROR("sharedBlock_ is null!");
return E_ERROR;
}
int rowCnt = 0;
GetRowCount(rowCnt);
if (position >= rowCnt) {
@ -109,11 +113,18 @@ int DataShareResultSet::GoToRow(int position)
return E_OK;
}
bool result = true;
if (sharedBlock_ == nullptr || (uint32_t)position >= sharedBlock_->GetRowNum()) {
result = OnGo(rowPos_, position);
if (position > endRowPos_ || position < startRowPos_) {
result = OnGo(position, std::min(position + STEP_LENGTH, rowCnt - 1));
if (result) {
startRowPos_ = position;
endRowPos_ = position + sharedBlock_->GetRowNum() -1;
}
}
if (!result) {
rowPos_ = INIT_POS;
startRowPos_ = INIT_POS;
endRowPos_ = INIT_POS;
return E_ERROR;
} else {
rowPos_ = position;
@ -128,7 +139,7 @@ int DataShareResultSet::GetBlob(int columnIndex, std::vector<uint8_t> &value)
return errorCode;
}
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_, columnIndex);
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_ - startRowPos_, columnIndex);
if (!cellUnit) {
LOG_ERROR("DataShareResultSet::GetBlob cellUnit is null!");
return E_ERROR;
@ -168,7 +179,7 @@ int DataShareResultSet::GetString(int columnIndex, std::string &value)
if (errorCode != E_OK) {
return errorCode;
}
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_, columnIndex);
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_ - startRowPos_, columnIndex);
if (!cellUnit) {
LOG_ERROR("DataShareResultSet::GetString cellUnit is null!");
return E_ERROR;
@ -207,7 +218,7 @@ int DataShareResultSet::GetString(int columnIndex, std::string &value)
int DataShareResultSet::GetInt(int columnIndex, int &value)
{
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_, columnIndex);
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_ - startRowPos_, columnIndex);
if (!cellUnit) {
LOG_ERROR("DataShareResultSet::GetInt cellUnit is null!");
return E_ERROR;
@ -222,7 +233,7 @@ int DataShareResultSet::GetLong(int columnIndex, int64_t &value)
if (errorCode != E_OK) {
return errorCode;
}
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_, columnIndex);
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_ - startRowPos_, columnIndex);
if (!cellUnit) {
LOG_ERROR("DataShareResultSet::GetLong cellUnit is null!");
return E_ERROR;
@ -262,7 +273,7 @@ int DataShareResultSet::GetDouble(int columnIndex, double &value)
if (errorCode != E_OK) {
return errorCode;
}
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_, columnIndex);
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_ - startRowPos_, columnIndex);
if (!cellUnit) {
LOG_ERROR("DataShareResultSet::GetDouble cellUnit is null!");
return E_ERROR;
@ -300,7 +311,7 @@ int DataShareResultSet::IsColumnNull(int columnIndex, bool &isNull)
if (errorCode != E_OK) {
return errorCode;
}
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_, columnIndex);
AppDataFwk::SharedBlock::CellUnit *cellUnit = sharedBlock_->GetCellUnit(rowPos_ - startRowPos_, columnIndex);
if (!cellUnit) {
LOG_ERROR("DataShareResultSet::IsColumnNull cellUnit is null!");
return E_ERROR;

View File

@ -30,44 +30,44 @@ DataShareValuesBucket::~DataShareValuesBucket()
{
}
void DataShareValuesBucket::PutString(const std::string &columnOrKeyName, const std::string &value)
void DataShareValuesBucket::PutString(const std::string &columnName, const std::string &value)
{
valuesMap.insert(std::make_pair(columnOrKeyName, DataShareValueObject(value)));
valuesMap.insert(std::make_pair(columnName, DataShareValueObject(value)));
}
void DataShareValuesBucket::PutInt(const std::string &columnOrKeyName, int value)
void DataShareValuesBucket::PutInt(const std::string &columnName, int value)
{
valuesMap.insert(std::make_pair(columnOrKeyName, DataShareValueObject(value)));
valuesMap.insert(std::make_pair(columnName, DataShareValueObject(value)));
}
void DataShareValuesBucket::PutLong(const std::string &columnOrKeyName, int64_t value)
void DataShareValuesBucket::PutLong(const std::string &columnName, int64_t value)
{
valuesMap.insert(std::make_pair(columnOrKeyName, DataShareValueObject(value)));
valuesMap.insert(std::make_pair(columnName, DataShareValueObject(value)));
}
void DataShareValuesBucket::PutDouble(const std::string &columnOrKeyName, double value)
void DataShareValuesBucket::PutDouble(const std::string &columnName, double value)
{
valuesMap.insert(std::make_pair(columnOrKeyName, DataShareValueObject(value)));
valuesMap.insert(std::make_pair(columnName, DataShareValueObject(value)));
}
void DataShareValuesBucket::PutBool(const std::string &columnOrKeyName, bool value)
void DataShareValuesBucket::PutBool(const std::string &columnName, bool value)
{
valuesMap.insert(std::make_pair(columnOrKeyName, DataShareValueObject(value)));
valuesMap.insert(std::make_pair(columnName, DataShareValueObject(value)));
}
void DataShareValuesBucket::PutBlob(const std::string &columnOrKeyName, const std::vector<uint8_t> &value)
void DataShareValuesBucket::PutBlob(const std::string &columnName, const std::vector<uint8_t> &value)
{
valuesMap.insert(std::make_pair(columnOrKeyName, DataShareValueObject(value)));
valuesMap.insert(std::make_pair(columnName, DataShareValueObject(value)));
}
void DataShareValuesBucket::PutNull(const std::string &columnOrKeyName)
void DataShareValuesBucket::PutNull(const std::string &columnName)
{
valuesMap.insert(std::make_pair(columnOrKeyName, DataShareValueObject()));
valuesMap.insert(std::make_pair(columnName, DataShareValueObject()));
}
void DataShareValuesBucket::Delete(const std::string &columnOrKeyName)
void DataShareValuesBucket::Delete(const std::string &columnName)
{
valuesMap.erase(columnOrKeyName);
valuesMap.erase(columnName);
}
void DataShareValuesBucket::Clear()
@ -85,18 +85,18 @@ bool DataShareValuesBucket::IsEmpty() const
return valuesMap.empty();
}
bool DataShareValuesBucket::HasColumnOrKey(const std::string &columnOrKeyName) const
bool DataShareValuesBucket::HasColumn(const std::string &columnName) const
{
auto iter = valuesMap.find(columnOrKeyName);
auto iter = valuesMap.find(columnName);
if (iter == valuesMap.end()) {
return false;
}
return true;
}
bool DataShareValuesBucket::GetObject(const std::string &columnOrKeyName, DataShareValueObject &value) const
bool DataShareValuesBucket::GetObject(const std::string &columnName, DataShareValueObject &value) const
{
auto iter = valuesMap.find(columnOrKeyName);
auto iter = valuesMap.find(columnName);
if (iter == valuesMap.end()) {
return false;
}

View File

@ -101,7 +101,14 @@ int ISharedResultSetStub::HandleOnGoRequest(MessageParcel &data, MessageParcel &
{
int oldRow = data.ReadInt32();
int newRow = data.ReadInt32();
int errCode = resultSet_->OnGo(oldRow, newRow);
std::vector<std::string> columnNames;
resultSet_->GetAllColumnNames(columnNames);
auto block = resultSet_->GetBlock();
int errCode = block->Clear();
errCode |= block->SetColumnNum(columnNames.size());
if (errCode == E_OK) {
errCode = resultSet_->OnGo(oldRow, newRow);
}
reply.WriteInt32(errCode);
LOG_DEBUG("HandleOnGoRequest call %{public}d", errCode);
return NO_ERROR;

View File

@ -91,7 +91,7 @@ void DataShareHelper::OnSchedulerDied(const wptr<IRemoteObject> &remote)
*
* @param context Indicates the Context object on OHOS.
* @param strUri Indicates the database table or disk file to operate.
* @return Returns the created DataShareHelper instance.
*/
std::shared_ptr<DataShareHelper> DataShareHelper::Creator(

View File

@ -20,7 +20,7 @@
#include "datashare_values_bucket.h"
#include "datashare_result.h"
#include "datashare_predicates.h"
#include "datashare_abstract_result_set.h"
#include "result_set_bridge.h"
#include "datashare_operation.h"
namespace OHOS {
@ -142,7 +142,7 @@ public:
*
* @return Returns the query result.
*/
virtual std::shared_ptr<DataShareAbstractResultSet> Query(
virtual std::shared_ptr<ResultSetBridge> Query(
const Uri &uri, const DataSharePredicates &predicates, std::vector<std::string> &columns);
/**

View File

@ -32,7 +32,7 @@ public:
explicit DataShareUvQueue(napi_env env);
virtual ~DataShareUvQueue() = default;
void SyncCall(NapiVoidFunc func = NapiVoidFunc());
void SyncCall(NapiVoidFunc func = NapiVoidFunc(), NapiVoidFunc retFunc = NapiVoidFunc());
private:
struct UvEntry {
@ -42,6 +42,7 @@ private:
bool purge;
std::condition_variable condition;
std::mutex mutex;
NapiVoidFunc retFunc;
};
static void Purge(uv_work_t* work);

View File

@ -154,7 +154,7 @@ public:
*
* @return Returns the query result.
*/
std::shared_ptr<DataShareAbstractResultSet> Query(const Uri &uri, const DataSharePredicates &predicates,
std::shared_ptr<ResultSetBridge> Query(const Uri &uri, const DataSharePredicates &predicates,
std::vector<std::string> &columns) override;
/**
@ -238,14 +238,92 @@ public:
std::vector<std::shared_ptr<DataShareResult>> ExecuteBatch(
const std::vector<std::shared_ptr<DataShareOperation>> &operations) override;
bool GetBlockWaiting() const
{
return isBlockWaiting_;
}
void SetBlockWaiting(bool blockWaiting)
{
isBlockWaiting_ = blockWaiting;
}
NativeValue* GetAsyncResult() const
{
return callbackData_;
}
void SetAsyncResult(NativeValue* asyncResult)
{
callbackData_ = asyncResult;
}
void GetResult(int &value)
{
value = callbackResultNumber_;
}
void SetResult(const int value)
{
callbackResultNumber_ = value;
}
void GetResult(std::string &value)
{
value = callbackResultString_;
}
void SetResult(const std::string value)
{
callbackResultString_ = value;
}
void GetResult(std::vector<std::string> &value)
{
value = callbackResultStringArr_;
}
void SetResult(const std::vector<std::string> value)
{
callbackResultStringArr_ = value;
}
void GetResult(std::shared_ptr<ResultSetBridge> &value)
{
value = std::move(callbackResultObject_);
}
void SetResult(const std::shared_ptr<ResultSetBridge> value)
{
callbackResultObject_ = value;
}
private:
NativeValue* CallObjectMethod(const char *name, NativeValue * const *argv = nullptr, size_t argc = 0);
enum AsyncType {
ASYNC_DEFAULT = 0,
ASYNC_NUMBER,
ASYNC_STRING,
ASYNC_STRARR,
ASYNC_OBJECT,
};
NativeValue* CallObjectMethod(const char *name, NativeValue * const *argv = nullptr, size_t argc = 0,
AsyncType asyncType = ASYNC_DEFAULT);
void GetSrcPath(std::string &srcPath);
bool CheckCallingPermission(const std::string &permission);
napi_value MakePredicates(napi_env env, const DataSharePredicates &predicates);
static NativeValue* AsyncCallbackNumber(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* AsyncCallbackString(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* AsyncCallbackStrArr(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* AsyncCallbackObject(NativeEngine* engine, NativeCallbackInfo* info);
JsRuntime& jsRuntime_;
std::unique_ptr<NativeReference> jsObj_;
bool isBlockWaiting_ = false;
NativeValue* callbackData_ = nullptr;
int callbackResultNumber_ = -1;
std::string callbackResultString_ = "";
std::vector<std::string> callbackResultStringArr_ = {};
std::shared_ptr<ResultSetBridge> callbackResultObject_ = nullptr;
};
} // namespace DataShare
} // namespace OHOS

View File

@ -105,11 +105,11 @@ int DataShareExtAbility::Delete(const Uri &uri, const DataSharePredicates &predi
return 0;
}
std::shared_ptr<DataShareAbstractResultSet> DataShareExtAbility::Query(const Uri &uri,
std::shared_ptr<ResultSetBridge> DataShareExtAbility::Query(const Uri &uri,
const DataSharePredicates &predicates, std::vector<std::string> &columns)
{
LOG_INFO("begin.");
std::shared_ptr<DataShareAbstractResultSet> ret;
std::shared_ptr<ResultSetBridge> ret;
LOG_INFO("end.");
return ret;
}

View File

@ -36,7 +36,15 @@ std::vector<std::string> DataShareStubImpl::GetFileTypes(const Uri &uri, const s
}
ret = extension->GetFileTypes(uri, mimeTypeFilter);
};
uvQueue_->SyncCall(syncTaskFunc);
std::function<void()> getRetFunc = [=, &ret, client = sptr<DataShareStubImpl>(this)]() {
auto extension = client->GetOwner();
if (extension == nullptr) {
LOG_ERROR("%{public}s end failed.", __func__);
return;
}
extension->GetResult(ret);
};
uvQueue_->SyncCall(syncTaskFunc, getRetFunc);
LOG_INFO("end successfully.");
return ret;
}
@ -53,7 +61,15 @@ int DataShareStubImpl::OpenFile(const Uri &uri, const std::string &mode)
}
ret = extension->OpenFile(uri, mode);
};
uvQueue_->SyncCall(syncTaskFunc);
std::function<void()> getRetFunc = [=, &ret, client = sptr<DataShareStubImpl>(this)]() {
auto extension = client->GetOwner();
if (extension == nullptr) {
LOG_ERROR("%{public}s end failed.", __func__);
return;
}
extension->GetResult(ret);
};
uvQueue_->SyncCall(syncTaskFunc, getRetFunc);
LOG_INFO("end successfully.");
return ret;
}
@ -87,7 +103,15 @@ int DataShareStubImpl::Insert(const Uri &uri, const DataShareValuesBucket &value
}
ret = extension->Insert(uri, value);
};
uvQueue_->SyncCall(syncTaskFunc);
std::function<void()> getRetFunc = [=, &ret, client = sptr<DataShareStubImpl>(this)]() {
auto extension = client->GetOwner();
if (extension == nullptr) {
LOG_ERROR("%{public}s end failed.", __func__);
return;
}
extension->GetResult(ret);
};
uvQueue_->SyncCall(syncTaskFunc, getRetFunc);
LOG_INFO("end successfully.");
return ret;
}
@ -105,7 +129,15 @@ int DataShareStubImpl::Update(const Uri &uri, const DataSharePredicates &predica
}
ret = extension->Update(uri, predicates, value);
};
uvQueue_->SyncCall(syncTaskFunc);
std::function<void()> getRetFunc = [=, &ret, client = sptr<DataShareStubImpl>(this)]() {
auto extension = client->GetOwner();
if (extension == nullptr) {
LOG_ERROR("%{public}s end failed.", __func__);
return;
}
extension->GetResult(ret);
};
uvQueue_->SyncCall(syncTaskFunc, getRetFunc);
LOG_INFO("end successfully.");
return ret;
}
@ -122,7 +154,15 @@ int DataShareStubImpl::Delete(const Uri &uri, const DataSharePredicates &predica
}
ret = extension->Delete(uri, predicates);
};
uvQueue_->SyncCall(syncTaskFunc);
std::function<void()> getRetFunc = [=, &ret, client = sptr<DataShareStubImpl>(this)]() {
auto extension = client->GetOwner();
if (extension == nullptr) {
LOG_ERROR("%{public}s end failed.", __func__);
return;
}
extension->GetResult(ret);
};
uvQueue_->SyncCall(syncTaskFunc, getRetFunc);
LOG_INFO("end successfully.");
return ret;
}
@ -131,7 +171,7 @@ std::shared_ptr<DataShareResultSet> DataShareStubImpl::Query(const Uri &uri,
const DataSharePredicates &predicates, std::vector<std::string> &columns)
{
LOG_INFO("begin.");
std::shared_ptr<DataShareAbstractResultSet> ret = nullptr;
std::shared_ptr<ResultSetBridge> ret = nullptr;
std::function<void()> syncTaskFunc = [=, &columns, &ret, client = sptr<DataShareStubImpl>(this)]() {
auto extension = client->GetOwner();
if (extension == nullptr) {
@ -140,8 +180,18 @@ std::shared_ptr<DataShareResultSet> DataShareStubImpl::Query(const Uri &uri,
}
ret = extension->Query(uri, predicates, columns);
};
uvQueue_->SyncCall(syncTaskFunc);
std::shared_ptr<DataShareResultSet> resultSet = std::make_shared<DataShareResultSet>(ret);
std::function<void()> getRetFunc = [=, &resultSet, &ret, client = sptr<DataShareStubImpl>(this)]() {
auto extension = client->GetOwner();
if (extension == nullptr) {
LOG_ERROR("%{public}s end failed.", __func__);
return;
}
extension->GetResult(ret);
std::shared_ptr<DataShareResultSet> tmpResultSet = std::make_shared<DataShareResultSet>(ret);
resultSet = std::move(tmpResultSet);
};
uvQueue_->SyncCall(syncTaskFunc, getRetFunc);
LOG_INFO("end successfully.");
return resultSet;
}
@ -158,7 +208,15 @@ std::string DataShareStubImpl::GetType(const Uri &uri)
}
ret = extension->GetType(uri);
};
uvQueue_->SyncCall(syncTaskFunc);
std::function<void()> getRetFunc = [=, &ret, client = sptr<DataShareStubImpl>(this)]() {
auto extension = client->GetOwner();
if (extension == nullptr) {
LOG_ERROR("%{public}s end failed.", __func__);
return;
}
extension->GetResult(ret);
};
uvQueue_->SyncCall(syncTaskFunc, getRetFunc);
LOG_INFO("end successfully.");
return ret;
}
@ -175,7 +233,15 @@ int DataShareStubImpl::BatchInsert(const Uri &uri, const std::vector<DataShareVa
}
ret = extension->BatchInsert(uri, values);
};
uvQueue_->SyncCall(syncTaskFunc);
std::function<void()> getRetFunc = [=, &ret, client = sptr<DataShareStubImpl>(this)]() {
auto extension = client->GetOwner();
if (extension == nullptr) {
LOG_ERROR("%{public}s end failed.", __func__);
return;
}
extension->GetResult(ret);
};
uvQueue_->SyncCall(syncTaskFunc, getRetFunc);
LOG_INFO("end successfully.");
return ret;
}
@ -243,7 +309,18 @@ Uri DataShareStubImpl::NormalizeUri(const Uri &uri)
}
urivalue = extension->NormalizeUri(uri);
};
uvQueue_->SyncCall(syncTaskFunc);
std::function<void()> getRetFunc = [=, &urivalue, client = sptr<DataShareStubImpl>(this)]() {
auto extension = client->GetOwner();
if (extension == nullptr) {
LOG_ERROR("%{public}s end failed.", __func__);
return;
}
std::string ret;
extension->GetResult(ret);
Uri tmp(ret);
urivalue = tmp;
};
uvQueue_->SyncCall(syncTaskFunc, getRetFunc);
LOG_INFO("end successfully.");
return urivalue;
}
@ -260,7 +337,18 @@ Uri DataShareStubImpl::DenormalizeUri(const Uri &uri)
}
urivalue = extension->DenormalizeUri(uri);
};
uvQueue_->SyncCall(syncTaskFunc);
std::function<void()> getRetFunc = [=, &urivalue, client = sptr<DataShareStubImpl>(this)]() {
auto extension = client->GetOwner();
if (extension == nullptr) {
LOG_ERROR("%{public}s end failed.", __func__);
return;
}
std::string ret;
extension->GetResult(ret);
Uri tmp(ret);
urivalue = tmp;
};
uvQueue_->SyncCall(syncTaskFunc, getRetFunc);
LOG_INFO("end successfully.");
return urivalue;
}

View File

@ -14,7 +14,7 @@
*/
#include "datashare_uv_queue.h"
#include <unistd.h>
#include "datashare_log.h"
namespace OHOS {
@ -26,14 +26,14 @@ DataShareUvQueue::DataShareUvQueue(napi_env env)
napi_get_uv_event_loop(env, &loop_);
}
void DataShareUvQueue::SyncCall(NapiVoidFunc func)
void DataShareUvQueue::SyncCall(NapiVoidFunc func, NapiVoidFunc retFunc)
{
LOG_INFO("begin.");
uv_work_t* work = new (std::nothrow) uv_work_t;
if (work == nullptr) {
return;
}
work->data = new UvEntry {env_, std::move(func), false, false, {}, {}};
work->data = new UvEntry {env_, std::move(func), false, false, {}, {}, std::move(retFunc)};
auto status = uv_queue_work(
loop_, work, [](uv_work_t* work) {},
[](uv_work_t* work, int uvstatus) {
@ -66,6 +66,10 @@ void DataShareUvQueue::SyncCall(NapiVoidFunc func)
if (uvEntry->condition.wait_for(lock, std::chrono::seconds(WAIT_TIME), [uvEntry] { return uvEntry->done; })) {
LOG_INFO("Wait uv_queue_work timeout.");
}
if (uvEntry->retFunc) {
sleep(1);
uvEntry->retFunc();
}
if (!uvEntry->done && !uv_cancel((uv_req_t*)&work)) {
LOG_ERROR("%{public}s uv_cancel failed.", __func__);
uvEntry->purge = true;

View File

@ -31,7 +31,6 @@
#include "napi_remote_object.h"
#include "napi_datashare_values_bucket.h"
#include "napi_datashare_abstract_result_set.h"
#include "datashare_predicates_proxy.h"
namespace OHOS {
@ -42,6 +41,10 @@ constexpr size_t ARGC_ONE = 1;
constexpr size_t ARGC_TWO = 2;
constexpr size_t ARGC_THREE = 3;
constexpr int INVALID_VALUE = -1;
const std::string ASYNC_CALLBACK_NUMBER_NAME = "AsyncCallbackNumber";
const std::string ASYNC_CALLBACK_STRING_NAME = "AsyncCallbackString";
const std::string ASYNC_CALLBACK_STRARR_NAME = "AsyncCallbackStrArr";
const std::string ASYNC_CALLBACK_OBJECT_NAME = "AsyncCallbackObject";
}
void PrintPredicates(const DataSharePredicates &predicates);
@ -150,7 +153,180 @@ sptr<IRemoteObject> JsDataShareExtAbility::OnConnect(const AAFwk::Want &want)
return remoteObject->AsObject();
}
NativeValue* JsDataShareExtAbility::CallObjectMethod(const char* name, NativeValue* const* argv, size_t argc)
NativeValue* JsDataShareExtAbility::AsyncCallbackNumber(NativeEngine* engine, NativeCallbackInfo* info)
{
LOG_INFO("engine == nullptr : %{public}d, info == nullptr : %{public}d.", engine == nullptr, info == nullptr);
if (engine == nullptr || info == nullptr) {
LOG_ERROR("%{public}s invalid param.", __func__);
return nullptr;
}
if (info->argc < ARGC_TWO || info->argv[0] == nullptr || info->argv[1] == nullptr) {
LOG_ERROR("%{public}s invalid args.", __func__);
return engine->CreateUndefined();
}
int32_t value = -1;
if ((info->argv[0])->TypeOf() == NATIVE_NUMBER) {
value = OHOS::AppExecFwk::UnwrapInt32FromJS(reinterpret_cast<napi_env>(engine),
reinterpret_cast<napi_value>(info->argv[0]));
LOG_INFO("%{public}s value_number : %{public}d.", __func__, value);
}
if (info->functionInfo == nullptr || info->functionInfo->data == nullptr) {
LOG_ERROR("%{public}s invalid object.", __func__);
return engine->CreateUndefined();
}
JsDataShareExtAbility* instance = static_cast<JsDataShareExtAbility*>(info->functionInfo->data);
instance->SetResult(-1);
instance->SetBlockWaiting(true);
instance->SetAsyncResult(info->argv[1]);
auto result = instance->GetAsyncResult();
auto type = result->TypeOf();
if (type == NATIVE_NUMBER) {
value = OHOS::AppExecFwk::UnwrapInt32FromJS(reinterpret_cast<napi_env>(engine),
reinterpret_cast<napi_value>(result));
instance->SetResult(value);
}
LOG_INFO("%{public}s end.", __func__);
return engine->CreateUndefined();
}
NativeValue* JsDataShareExtAbility::AsyncCallbackString(NativeEngine* engine, NativeCallbackInfo* info)
{
LOG_INFO("engine == nullptr : %{public}d, info == nullptr : %{public}d.", engine == nullptr, info == nullptr);
if (engine == nullptr || info == nullptr) {
LOG_ERROR("%{public}s invalid param.", __func__);
return nullptr;
}
if (info->argc < ARGC_TWO || info->argv[0] == nullptr || info->argv[1] == nullptr) {
LOG_ERROR("%{public}s invalid args.", __func__);
return engine->CreateUndefined();
}
int32_t value = -1;
if ((info->argv[0])->TypeOf() == NATIVE_NUMBER) {
value = OHOS::AppExecFwk::UnwrapInt32FromJS(reinterpret_cast<napi_env>(engine),
reinterpret_cast<napi_value>(info->argv[0]));
LOG_INFO("%{public}s value_number : %{public}d.", __func__, value);
}
if (info->functionInfo == nullptr || info->functionInfo->data == nullptr) {
LOG_ERROR("%{public}s invalid object.", __func__);
return engine->CreateUndefined();
}
JsDataShareExtAbility* instance = static_cast<JsDataShareExtAbility*>(info->functionInfo->data);
instance->SetResult("");
instance->SetBlockWaiting(true);
instance->SetAsyncResult(info->argv[1]);
auto result = instance->GetAsyncResult();
auto type = result->TypeOf();
if (type == NATIVE_STRING) {
std::string value = OHOS::AppExecFwk::UnwrapStringFromJS(reinterpret_cast<napi_env>(engine),
reinterpret_cast<napi_value>(result));
instance->SetResult(value);
}
LOG_INFO("%{public}s end.", __func__);
return engine->CreateUndefined();
}
NativeValue* JsDataShareExtAbility::AsyncCallbackStrArr(NativeEngine* engine, NativeCallbackInfo* info)
{
LOG_INFO("engine == nullptr : %{public}d, info == nullptr : %{public}d.", engine == nullptr, info == nullptr);
if (engine == nullptr || info == nullptr) {
LOG_ERROR("%{public}s invalid param.", __func__);
return nullptr;
}
if (info->argc < ARGC_TWO || info->argv[0] == nullptr || info->argv[1] == nullptr) {
LOG_ERROR("%{public}s invalid args.", __func__);
return engine->CreateUndefined();
}
int32_t value = -1;
if ((info->argv[0])->TypeOf() == NATIVE_NUMBER) {
value = OHOS::AppExecFwk::UnwrapInt32FromJS(reinterpret_cast<napi_env>(engine),
reinterpret_cast<napi_value>(info->argv[0]));
LOG_INFO("%{public}s value_number : %{public}d.", __func__, value);
}
if (info->functionInfo == nullptr || info->functionInfo->data == nullptr) {
LOG_ERROR("%{public}s invalid object.", __func__);
return engine->CreateUndefined();
}
JsDataShareExtAbility* instance = static_cast<JsDataShareExtAbility*>(info->functionInfo->data);
instance->callbackResultStringArr_ = {};
instance->SetBlockWaiting(true);
instance->SetAsyncResult(info->argv[1]);
auto result = instance->GetAsyncResult();
auto type = result->TypeOf();
if (type == NATIVE_OBJECT) {
std::vector<std::string> value;
OHOS::AppExecFwk::UnwrapArrayStringFromJS(reinterpret_cast<napi_env>(engine),
reinterpret_cast<napi_value>(result), value);
instance->SetResult(value);
}
LOG_INFO("%{public}s end.", __func__);
return engine->CreateUndefined();
}
NativeValue* JsDataShareExtAbility::AsyncCallbackObject(NativeEngine* engine, NativeCallbackInfo* info)
{
LOG_INFO("engine == nullptr : %{public}d, info == nullptr : %{public}d.", engine == nullptr, info == nullptr);
if (engine == nullptr || info == nullptr) {
LOG_ERROR("%{public}s invalid param.", __func__);
return nullptr;
}
if (info->argc < ARGC_TWO || info->argv[0] == nullptr || info->argv[1] == nullptr) {
LOG_ERROR("%{public}s invalid args.", __func__);
return engine->CreateUndefined();
}
int32_t value = -1;
if ((info->argv[0])->TypeOf() == NATIVE_NUMBER) {
value = OHOS::AppExecFwk::UnwrapInt32FromJS(reinterpret_cast<napi_env>(engine),
reinterpret_cast<napi_value>(info->argv[0]));
LOG_INFO("%{public}s value_number : %{public}d.", __func__, value);
}
if (info->functionInfo == nullptr || info->functionInfo->data == nullptr) {
LOG_ERROR("%{public}s invalid object.", __func__);
return engine->CreateUndefined();
}
JsDataShareExtAbility* instance = static_cast<JsDataShareExtAbility*>(info->functionInfo->data);
instance->callbackResultObject_ = nullptr;
instance->SetBlockWaiting(true);
instance->SetAsyncResult(info->argv[1]);
auto result = instance->GetAsyncResult();
auto type = result->TypeOf();
if (type == NATIVE_OBJECT) {
std::shared_ptr<ResultSetBridge> value = nullptr;
ResultSetBridge::Creator *proxy = nullptr;
napi_unwrap(reinterpret_cast<napi_env>(engine), reinterpret_cast<napi_value>(result),
reinterpret_cast<void **>(&proxy));
if (proxy == nullptr) {
LOG_ERROR("unwrap ResultSetBridge::Creator proxy is null.");
return nullptr;
}
value = proxy->Create();
instance->SetResult(value);
}
LOG_INFO("%{public}s end.", __func__);
return engine->CreateUndefined();
}
NativeValue* JsDataShareExtAbility::CallObjectMethod(const char* name, NativeValue* const* argv, size_t argc,
AsyncType asyncType)
{
LOG_INFO("JsDataShareExtAbility::CallObjectMethod(%{public}s), begin", name);
@ -174,8 +350,36 @@ NativeValue* JsDataShareExtAbility::CallObjectMethod(const char* name, NativeVal
LOG_ERROR("Failed to get '%{public}s' from DataShareExtAbility object", name);
return nullptr;
}
LOG_INFO("JsDataShareExtAbility::CallFunction(%{public}s), success", name);
return handleScope.Escape(nativeEngine.CallFunction(value, method, argv, argc));
size_t count = argc + 1;
NativeValue **args = new NativeValue *[count];
for (size_t i = 0; i < argc; i++) {
args[i] = argv[i];
}
if (asyncType == AsyncType::ASYNC_NUMBER) {
args[argc] = nativeEngine.CreateFunction(ASYNC_CALLBACK_NUMBER_NAME.c_str(),
ASYNC_CALLBACK_NUMBER_NAME.length(), JsDataShareExtAbility::AsyncCallbackNumber, this);
LOG_INFO("AsyncType::ASYNC_NUMBER.");
} else if (asyncType == AsyncType::ASYNC_STRING) {
args[argc] = nativeEngine.CreateFunction(ASYNC_CALLBACK_STRING_NAME.c_str(),
ASYNC_CALLBACK_STRING_NAME.length(), JsDataShareExtAbility::AsyncCallbackString, this);
LOG_INFO("AsyncType::ASYNC_STRING.");
} else if (asyncType == AsyncType::ASYNC_STRARR) {
args[argc] = nativeEngine.CreateFunction(ASYNC_CALLBACK_STRARR_NAME.c_str(),
ASYNC_CALLBACK_STRARR_NAME.length(), JsDataShareExtAbility::AsyncCallbackStrArr, this);
LOG_INFO("AsyncType::ASYNC_STRARR.");
} else if (asyncType == AsyncType::ASYNC_OBJECT) {
args[argc] = nativeEngine.CreateFunction(ASYNC_CALLBACK_OBJECT_NAME.c_str(),
ASYNC_CALLBACK_OBJECT_NAME.length(), JsDataShareExtAbility::AsyncCallbackObject, this);
LOG_INFO("AsyncType::ASYNC_OBJECT.");
} else {
args[argc] = nullptr;
}
SetBlockWaiting(false);
LOG_INFO("%{public}s(%{public}s) end", __func__, name);
return handleScope.Escape(nativeEngine.CallFunction(value, method, args, count));
}
void JsDataShareExtAbility::GetSrcPath(std::string &srcPath)
@ -222,7 +426,7 @@ std::vector<std::string> JsDataShareExtAbility::GetFileTypes(const Uri &uri, con
NativeValue* nativeUri = reinterpret_cast<NativeValue*>(napiUri);
NativeValue* nativeMimeTypeFilter = reinterpret_cast<NativeValue*>(napiMimeTypeFilter);
NativeValue* argv[] = {nativeUri, nativeMimeTypeFilter};
NativeValue* nativeResult = CallObjectMethod("getFileTypes", argv, ARGC_TWO);
NativeValue* nativeResult = CallObjectMethod("getFileTypes", argv, ARGC_TWO, AsyncType::ASYNC_STRARR);
if (nativeResult == nullptr) {
LOG_ERROR("%{public}s call getFileTypes with return null.", __func__);
return ret;
@ -260,7 +464,7 @@ int JsDataShareExtAbility::OpenFile(const Uri &uri, const std::string &mode)
NativeValue* nativeUri = reinterpret_cast<NativeValue*>(napiUri);
NativeValue* nativeMode = reinterpret_cast<NativeValue*>(napiMode);
NativeValue* argv[] = {nativeUri, nativeMode};
NativeValue* nativeResult = CallObjectMethod("openFile", argv, ARGC_TWO);
NativeValue* nativeResult = CallObjectMethod("openFile", argv, ARGC_TWO, AsyncType::ASYNC_NUMBER);
if (nativeResult == nullptr) {
LOG_ERROR("%{public}s call openFile with return null.", __func__);
return ret;
@ -332,7 +536,7 @@ int JsDataShareExtAbility::Insert(const Uri &uri, const DataShareValuesBucket &v
NativeValue* nativeUri = reinterpret_cast<NativeValue*>(napiUri);
NativeValue* nativeValue = reinterpret_cast<NativeValue*>(napiValue);
NativeValue* argv[] = {nativeUri, nativeValue};
NativeValue* nativeResult = CallObjectMethod("insert", argv, ARGC_TWO);
NativeValue* nativeResult = CallObjectMethod("insert", argv, ARGC_TWO, AsyncType::ASYNC_NUMBER);
if (nativeResult == nullptr) {
LOG_ERROR("%{public}s call insert with return null.", __func__);
return ret;
@ -381,7 +585,7 @@ int JsDataShareExtAbility::Update(const Uri &uri, const DataSharePredicates &pre
NativeValue* nativePredicates = reinterpret_cast<NativeValue*>(napiPredicates);
NativeValue* nativeValue = reinterpret_cast<NativeValue*>(napiValue);
NativeValue* argv[] = {nativeUri, nativePredicates, nativeValue};
NativeValue* nativeResult = CallObjectMethod("update", argv, ARGC_THREE);
NativeValue* nativeResult = CallObjectMethod("update", argv, ARGC_THREE, AsyncType::ASYNC_NUMBER);
if (nativeResult == nullptr) {
LOG_ERROR("%{public}s call update with return null.", __func__);
return ret;
@ -421,7 +625,7 @@ int JsDataShareExtAbility::Delete(const Uri &uri, const DataSharePredicates &pre
NativeValue* nativeUri = reinterpret_cast<NativeValue*>(napiUri);
NativeValue* nativePredicates = reinterpret_cast<NativeValue*>(napiPredicates);
NativeValue* argv[] = {nativeUri, nativePredicates};
NativeValue* nativeResult = CallObjectMethod("delete", argv, ARGC_TWO);
NativeValue* nativeResult = CallObjectMethod("delete", argv, ARGC_TWO, AsyncType::ASYNC_NUMBER);
if (nativeResult == nullptr) {
LOG_ERROR("%{public}s call delete with return null.", __func__);
return ret;
@ -432,12 +636,12 @@ int JsDataShareExtAbility::Delete(const Uri &uri, const DataSharePredicates &pre
return ret;
}
std::shared_ptr<DataShareAbstractResultSet> JsDataShareExtAbility::Query(const Uri &uri,
std::shared_ptr<ResultSetBridge> JsDataShareExtAbility::Query(const Uri &uri,
const DataSharePredicates &predicates, std::vector<std::string> &columns)
{
LOG_INFO("begin.");
PrintPredicates(predicates);
std::shared_ptr<DataShareAbstractResultSet> ret;
std::shared_ptr<ResultSetBridge> ret;
if (!CheckCallingPermission(abilityInfo_->readPermission)) {
LOG_ERROR("%{public}s Check calling permission failed.", __func__);
return ret;
@ -470,19 +674,21 @@ std::shared_ptr<DataShareAbstractResultSet> JsDataShareExtAbility::Query(const U
NativeValue* nativePredicates = reinterpret_cast<NativeValue*>(napiPredicates);
NativeValue* nativeColumns = reinterpret_cast<NativeValue*>(napiColumns);
NativeValue* argv[] = {nativeUri, nativePredicates, nativeColumns};
NativeValue* nativeResult = CallObjectMethod("query", argv, ARGC_THREE);
NativeValue* nativeResult = CallObjectMethod("query", argv, ARGC_THREE, AsyncType::ASYNC_OBJECT);
if (nativeResult == nullptr) {
LOG_ERROR("%{public}s call query with return null.", __func__);
return ret;
}
auto nativeObject = GetNativeAbstractResultSetObject(env, reinterpret_cast<napi_value>(nativeResult));
if (nativeObject == nullptr) {
return ret;
ResultSetBridge::Creator *proxy = nullptr;
napi_unwrap(env, reinterpret_cast<napi_value>(nativeResult), reinterpret_cast<void **>(&proxy));
if (proxy == nullptr) {
LOG_ERROR("unwrap ResultSetBridge::Creator proxy is null.");
return nullptr;
}
ret.reset(nativeObject);
LOG_INFO("end.");
ret = proxy->Create();
LOG_INFO("ret == nullptr : %{public}d.", ret == nullptr);
return ret;
}
@ -501,7 +707,7 @@ std::string JsDataShareExtAbility::GetType(const Uri &uri)
}
NativeValue* nativeUri = reinterpret_cast<NativeValue*>(napiUri);
NativeValue* argv[] = {nativeUri};
NativeValue* nativeResult = CallObjectMethod("getType", argv, ARGC_ONE);
NativeValue* nativeResult = CallObjectMethod("getType", argv, ARGC_ONE, AsyncType::ASYNC_STRING);
if (nativeResult == nullptr) {
LOG_ERROR("%{public}s call getType with return null.", __func__);
return ret;
@ -556,7 +762,7 @@ int JsDataShareExtAbility::BatchInsert(const Uri &uri, const std::vector<DataSha
NativeValue* nativeUri = reinterpret_cast<NativeValue*>(napiUri);
NativeValue* nativeValues = reinterpret_cast<NativeValue*>(napiValues);
NativeValue* argv[] = {nativeUri, nativeValues};
NativeValue* nativeResult = CallObjectMethod("batchInsert", argv, ARGC_TWO);
NativeValue* nativeResult = CallObjectMethod("batchInsert", argv, ARGC_TWO, AsyncType::ASYNC_NUMBER);
if (nativeResult == nullptr) {
LOG_ERROR("%{public}s call batchInsert with return null.", __func__);
return ret;
@ -639,7 +845,7 @@ Uri JsDataShareExtAbility::NormalizeUri(const Uri &uri)
}
NativeValue* nativeUri = reinterpret_cast<NativeValue*>(napiUri);
NativeValue* argv[] = {nativeUri};
NativeValue* nativeResult = CallObjectMethod("normalizeUri", argv, ARGC_ONE);
NativeValue* nativeResult = CallObjectMethod("normalizeUri", argv, ARGC_ONE, AsyncType::ASYNC_STRING);
if (nativeResult == nullptr) {
LOG_ERROR("%{public}s call normalizeUri with return null.", __func__);
return ret;
@ -665,7 +871,7 @@ Uri JsDataShareExtAbility::DenormalizeUri(const Uri &uri)
}
NativeValue* nativeUri = reinterpret_cast<NativeValue*>(napiUri);
NativeValue* argv[] = {nativeUri};
NativeValue* nativeResult = CallObjectMethod("denormalizeUri", argv, ARGC_ONE);
NativeValue* nativeResult = CallObjectMethod("denormalizeUri", argv, ARGC_ONE, AsyncType::ASYNC_STRING);
if (nativeResult == nullptr) {
LOG_ERROR("%{public}s call denormalizeUri with return null.", __func__);
return ret;

View File

@ -27,6 +27,7 @@
#include "sqlite_connection_pool.h"
#include "sqlite_statement.h"
#include "store_session.h"
#include "transaction_observer.h"
namespace OHOS::NativeRdb {
@ -99,22 +100,23 @@ public:
std::unique_ptr<ResultSet> QueryByStep(const std::string &sql,
const std::vector<std::string> &selectionArgs) override;
std::unique_ptr<AbsSharedResultSet> Query(const AbsRdbPredicates &predicates,
const std::vector<std::string> columns) override;
int Count(int64_t &outValue, const AbsRdbPredicates &predicates) override;
int Update(int &changedRows, const ValuesBucket &values, const AbsRdbPredicates &predicates) override;
int Delete(int &deletedRows, const AbsRdbPredicates &predicates) override;
bool SetDistributedTables(const std::vector<std::string>& tables) override;
std::string ObtainDistributedTableName(const std::string& device, const std::string& table) override;
bool Sync(const SyncOption& option, const AbsRdbPredicates& predicate, const SyncCallback& callback) override;
bool Subscribe(const SubscribeOption& option, RdbStoreObserver *observer) override;
bool UnSubscribe(const SubscribeOption& option, RdbStoreObserver *observer) override;
// user must use UDID
bool DropDeviceData(const std::vector<std::string>& devices, const DropOption& option) override;
@ -142,5 +144,4 @@ private:
DistributedRdb::RdbSyncerParam syncerParam_;
};
} // namespace OHOS::NativeRdb
#endif

View File

@ -0,0 +1,166 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "RdbResultSetBridge"
#include "rdb_result_set_bridge.h"
#include "rdb_errno.h"
#include "rdb_logger.h"
#include "result_set.h"
namespace OHOS {
namespace RdbDataShareAdapter {
using namespace OHOS::NativeRdb;
RdbResultSetBridge::RdbResultSetBridge(std::shared_ptr<ResultSet> resultSet) : rdbResultSet_(resultSet)
{
}
RdbResultSetBridge::~RdbResultSetBridge()
{
rdbResultSet_->Close();
}
int RdbResultSetBridge::GetRowCount(int &count)
{
return rdbResultSet_->GetRowCount(count);
}
int RdbResultSetBridge::GetAllColumnNames(std::vector<std::string> &columnOrKeyNames)
{
return rdbResultSet_->GetAllColumnNames(columnOrKeyNames);
}
bool RdbResultSetBridge::OnGo(int32_t start, int32_t target, Writer &writer)
{
int rowCount;
rdbResultSet_->GetRowCount(rowCount);
if (start < 0 || target < 0 || target >= rowCount) {
LOG_ERROR("Invalid targetRowIndex: %{public}d.", rowCount);
return false;
}
int columnCount;
rdbResultSet_->GetColumnCount(columnCount);
if (columnCount <= 0) {
LOG_ERROR("Invalid columnCount: %{public}d.", columnCount);
return false;
}
LOG_DEBUG("rowCount: %{public}d, columnCount: %{public}d.", rowCount, columnCount);
bool bResultSet = false;
rdbResultSet_->IsStarted(bResultSet);
if (!bResultSet) {
rdbResultSet_->GoToFirstRow();
}
int errCode = rdbResultSet_->GoToRow(start);
if (errCode) {
LOG_ERROR("Go to row %{public}d failed.", start);
return false;
}
ColumnType columnTypes[columnCount];
GetColumnTypes(columnCount, columnTypes);
WriteBlock(start, target, columnCount, columnTypes, writer);
return true;
}
void RdbResultSetBridge::GetColumnTypes(int columnCount, ColumnType columnTypes[])
{
for (int i = 0; i < columnCount; ++i) {
ColumnType type;
rdbResultSet_->GetColumnType(i, type);
columnTypes[i] = type;
}
}
void RdbResultSetBridge::WriteBlock(
int32_t start, int32_t target, int columnCount, ColumnType columnTypes[], Writer &writer)
{
bool isFull = false;
int errCode = 0;
int row = start;
while (!isFull && !errCode && row <= target) {
int status = writer.AllocRow();
if (status != 0) {
isFull = true;
LOG_ERROR("SharedBlock is full.");
break;
}
WriteColumn(columnCount, columnTypes, writer, row);
row++;
errCode = rdbResultSet_->GoToNextRow();
}
}
void RdbResultSetBridge::WriteColumn(int columnCount, const ColumnType *columnTypes, Writer &writer, int row)
{
for (int i = 0; i < columnCount; i++) {
LOG_DEBUG("Write data of row: %{public}d, column: %{public}d", row, i);
switch (columnTypes[i]) {
case ColumnType::TYPE_INTEGER:
int64_t value;
rdbResultSet_->GetLong(i, value);
if (writer.Write(i, value)) {
LOG_DEBUG("WriteLong failed of row: %{public}d, column: %{public}d", row, i);
}
break;
case ColumnType::TYPE_FLOAT:
double dValue;
rdbResultSet_->GetDouble(i, dValue);
if (writer.Write(i, dValue)) {
LOG_DEBUG("WriteDouble failed of row: %{public}d, column: %{public}d", row, i);
}
break;
case ColumnType::TYPE_NULL:
if (writer.Write(i)) {
LOG_DEBUG("WriteNull failed of row: row: %{public}d, column: %{public}d", row, i);
}
break;
case ColumnType::TYPE_BLOB:
if (WriteBlobData(i, writer)) {
LOG_DEBUG("WriteBlob failed of row: %{public}d, column: %{public}d", row, i);
}
break;
default:
std::string stringValue;
rdbResultSet_->GetString(i, stringValue);
if (writer.Write(i, (char *)stringValue.c_str(), strlen(stringValue.c_str()) + 1)) {
LOG_DEBUG("WriteString failed of row: %{public}d, column: %{public}d", row, i);
}
}
}
}
bool RdbResultSetBridge::WriteBlobData(int column, Writer &writer)
{
std::vector<uint8_t> blobValue;
rdbResultSet_->GetBlob(column, blobValue);
if (blobValue.empty()) {
return false;
}
std::string str;
str.assign(blobValue.begin(), blobValue.end());
const char *value = str.c_str();
return writer.Write(column, value, strlen(value));
}
} // namespace RdbDataShareAdapter
} // namespace OHOS

View File

@ -0,0 +1,241 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "rdb_utils.h"
#include "rdb_logger.h"
using namespace OHOS::RdbDataShareAdapter;
using namespace OHOS::DataShare;
using namespace OHOS::NativeRdb;
ValuesBucket RdbUtils::ToValuesBucket(const DataShareValuesBucket &dataShareValuesBucket)
{
std::map<std::string, ValueObject> valuesMap;
std::map<std::string, DataShareValueObject> dataShareValuesMap;
dataShareValuesBucket.GetAll(dataShareValuesMap);
for (auto &[key, value] : dataShareValuesMap) {
if (value.GetType() == DataShareValueObjectType::TYPE_BOOL) {
bool tmpVal;
value.GetBool(tmpVal);
valuesMap.insert(std::pair<std::string, ValueObject>(key, ValueObject(tmpVal)));
} else if (value.GetType() == DataShareValueObjectType::TYPE_INT) {
int32_t tmpVal;
value.GetInt(tmpVal);
valuesMap.insert(std::pair<std::string, ValueObject>(key, ValueObject(tmpVal)));
} else if (value.GetType() == DataShareValueObjectType::TYPE_DOUBLE) {
double tmpVal;
value.GetDouble(tmpVal);
valuesMap.insert(std::pair<std::string, ValueObject>(key, ValueObject(tmpVal)));
} else if (value.GetType() == DataShareValueObjectType::TYPE_STRING) {
std::string tmpVal;
value.GetString(tmpVal);
valuesMap.insert(std::pair<std::string, ValueObject>(key, ValueObject(tmpVal)));
} else if (value.GetType() == DataShareValueObjectType::TYPE_BLOB) {
std::vector<uint8_t> tmpVal;
value.GetBlob(tmpVal);
valuesMap.insert(std::pair<std::string, ValueObject>(key, ValueObject(tmpVal)));
} else {
LOG_INFO("Convert ValueBucket successful.");
}
}
return ValuesBucket(valuesMap);
}
void RdbUtils::ToOperateFirst(
const std::list<OperationItem>::iterator operations, std::shared_ptr<RdbPredicates> &predicates)
{
switch (operations->operation) {
case OperationType::EQUAL_TO:
predicates->EqualTo(ToString(operations->para1), ToString(operations->para2));
break;
case OperationType::NOT_EQUAL_TO:
predicates->NotEqualTo(ToString(operations->para1), ToString(operations->para2));
break;
case OperationType::GREATER_THAN:
predicates->GreaterThan(ToString(operations->para1), ToString(operations->para2));
break;
case OperationType::LESS_THAN:
predicates->LessThan(ToString(operations->para1), ToString(operations->para2));
break;
case OperationType::GREATER_THAN_OR_EQUAL_TO:
predicates->GreaterThanOrEqualTo(ToString(operations->para1), ToString(operations->para2));
break;
case OperationType::AND:
predicates->And();
break;
case OperationType::OR:
predicates->Or();
break;
case OperationType::BEGIN_WARP:
predicates->BeginWrap();
break;
case OperationType::BETWEEN:
predicates->Between(
ToString(operations->para1), ToString(operations->para2), ToString(operations->para3));
break;
default:
LOG_INFO("RdbUtils::ToOperateFirst successful");
return;
}
}
void RdbUtils::ToOperateSecond(
const std::list<OperationItem>::iterator operations, std::shared_ptr<RdbPredicates> &predicates)
{
switch (operations->operation) {
case OperationType::BEGIN_WITH:
predicates->BeginsWith(ToString(operations->para1), ToString(operations->para2));
break;
case OperationType::CONTAINS:
predicates->Contains(ToString(operations->para1), ToString(operations->para2));
break;
case OperationType::DISTINCT:
predicates->Distinct();
break;
case OperationType::IN:
predicates->In(ToString(operations->para1), std::get<std::vector<std::string>>(operations->para2.value));
break;
case OperationType::GLOB:
predicates->Glob(ToString(operations->para1), ToString(operations->para2));
break;
case OperationType::END_WARP:
predicates->EndWrap();
break;
case OperationType::INDEXED_BY:
predicates->IndexedBy(ToString(operations->para1));
break;
case OperationType::NOTBETWEEN:
predicates->NotBetween(
ToString(operations->para1), ToString(operations->para2), ToString(operations->para3));
break;
case OperationType::ORDER_BY_ASC:
predicates->OrderByAsc(ToString(operations->para1));
break;
default:
LOG_INFO("RdbUtils::ToOperateFirst successful");
return;
}
}
void RdbUtils::ToOperateThird(
const std::list<OperationItem>::iterator operations, std::shared_ptr<RdbPredicates> &predicates)
{
switch (operations->operation) {
case OperationType::ORDER_BY_DESC:
predicates->OrderByDesc(ToString(operations->para1));
break;
case OperationType::END_WITH:
predicates->EndsWith(ToString(operations->para1), ToString(operations->para2));
break;
case OperationType::IS_NULL:
predicates->IsNull(ToString(operations->para1));
break;
case OperationType::IS_NOT_NULL:
predicates->IsNotNull(ToString(operations->para1));
break;
case OperationType::OFFSET:
int offsetVal;
operations->para1.GetInt(offsetVal);
predicates->Offset(offsetVal);
break;
case OperationType::LESS_THAN_OR_EQUAL_TO:
predicates->LessThanOrEqualTo(ToString(operations->para1), ToString(operations->para2));
break;
case OperationType::NOT_IN:
predicates->NotIn(
ToString(operations->para1), std::get<std::vector<std::string>>(operations->para2.value));
break;
case OperationType::LIKE:
predicates->Like(ToString(operations->para1), ToString(operations->para2));
break;
case OperationType::LIMIT:
int val;
operations->para1.GetInt(val);
predicates->Limit(val);
break;
case OperationType::GROUP_BY:
predicates->GroupBy(std::get<std::vector<std::string>>(operations->para1.value));
break;
default:
LOG_INFO("RdbUtils::ToOperateFirst successful");
return;
}
}
RdbPredicates RdbUtils::ToPredicates(const DataSharePredicates &dataSharePredicates, const std::string &table)
{
std::shared_ptr<RdbPredicates> predicates = std::make_shared<RdbPredicates>(table);
std::list<OperationItem> operationLists = dataSharePredicates.GetOperationList();
std::list<OperationItem>::iterator operations;
for (operations = operationLists.begin(); operations != operationLists.end(); ++operations) {
ToOperateFirst(operations, predicates);
ToOperateSecond(operations, predicates);
ToOperateThird(operations, predicates);
}
if (dataSharePredicates.GetSettingMode() == QUERY_LANGUAGE) {
predicates->SetWhereClause(dataSharePredicates.GetWhereClause());
predicates->SetWhereArgs(dataSharePredicates.GetWhereArgs());
predicates->SetOrder(dataSharePredicates.GetOrder());
}
return *(predicates.get());
}
std::string RdbUtils::ToString(const DataSharePredicatesObject &predicatesObject)
{
std::string str = " ";
switch (predicatesObject.GetType()) {
case DataSharePredicatesObjectType::TYPE_INT:
int intValue;
predicatesObject.GetInt(intValue);
str = std::to_string(intValue);
break;
case DataSharePredicatesObjectType::TYPE_DOUBLE:
double doubleValue;
predicatesObject.GetDouble(doubleValue);
str = std::to_string(doubleValue);
break;
case DataSharePredicatesObjectType::TYPE_STRING:
predicatesObject.GetString(str);
break;
case DataSharePredicatesObjectType::TYPE_BOOL:
bool boolValue;
predicatesObject.GetBool(boolValue);
str = std::to_string(boolValue);
break;
case DataSharePredicatesObjectType::TYPE_LONG:
int64_t longValue;
predicatesObject.GetLong(longValue);
str = std::to_string(longValue);
break;
default:
LOG_INFO("RdbUtils::ToString No matching type");
return str;
}
return str;
}
std::shared_ptr<ResultSetBridge> RdbUtils::ToResultSetBridge(std::shared_ptr<ResultSet> resultSet)
{
return std::make_shared<RdbResultSetBridge>(resultSet);
}
RdbUtils::RdbUtils()
{
}
RdbUtils::~RdbUtils()
{
}

View File

@ -0,0 +1,71 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("//foundation/distributeddatamgr/appdatamgr/appdatamgr.gni")
module_output_path = "relational_store/native_rdb_data_share_adapter"
###############################################################################
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [
"../include/",
"../../../../frameworks/native/data_share/common/include",
"../../../../frameworks/native/rdb/src",
"../../../../frameworks/native/rdb_data_share_adapter/src",
"../../../../interfaces/inner_api/native/data_share/common/include",
"../../../../interfaces/inner_api/native/data_share/consumer/include",
"../../../../interfaces/inner_api/native/data_share/provider/include",
"../../../../interfaces/inner_api/native/rdb/include",
"../../../../interfaces/inner_api/native/rdb_data_share_adapter/include",
"//utils/native/base/include",
]
if (relational_store_rdb_support_icu) {
include_dirs += [
"//third_party/icu/icu4c/source/i18n",
"//third_party/icu/icu4c/source/common",
]
}
}
ohos_unittest("NativeRdbDataShareAdapterTest") {
module_out_path = module_output_path
sources = [ "unittest/rdb_data_share_adapter_test.cpp" ]
configs = [ ":module_private_config" ]
external_deps = [
"data_share:datashare_common",
"hilog_native:libhilog",
"relational_store:native_rdb",
"relational_store:native_rdb_data_share_adapter",
]
deps = [
"//third_party/googletest:gtest_main",
"//third_party/icu/icu4c:shared_icui18n",
"//third_party/icu/icu4c:shared_icuuc",
"//utils/native/base:utils",
]
}
###############################################################################
group("unittest") {
testonly = true
deps = [ ":NativeRdbDataShareAdapterTest" ]
}
###############################################################################

View File

@ -0,0 +1,308 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <string>
#include "datashare_block_writer_impl.h"
#include "datashare_predicates.h"
#include "datashare_result_set.h"
#include "logger.h"
#include "rdb_errno.h"
#include "rdb_helper.h"
#include "rdb_open_callback.h"
#include "rdb_utils.h"
using namespace testing::ext;
using namespace OHOS::NativeRdb;
using namespace OHOS::DataShare;
using namespace OHOS::RdbDataShareAdapter;
class RdbDataShareAdapterTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
void GenerateDefaultTable();
void GenerateDefaultEmptyTable();
static const std::string DATABASE_NAME;
static std::shared_ptr<RdbStore> store;
static const int E_SQLITE_ERROR;
static const int E_INVALID_COLUMN_TYPE;
static const size_t DEFAULT_BLOCK_SIZE;
static const std::string RDB_ADAPTER_TEST_PATH;
};
const std::string RdbDataShareAdapterTest::RDB_ADAPTER_TEST_PATH = "/data/test/";
const std::string RdbDataShareAdapterTest::DATABASE_NAME = RDB_ADAPTER_TEST_PATH + "rdbDataShareAdapter_test.db";
const int RdbDataShareAdapterTest::E_SQLITE_ERROR = -1; // errno SQLITE_ERROR
const int RdbDataShareAdapterTest::E_INVALID_COLUMN_TYPE = 1009; // errno SQLITE_NULL
const size_t RdbDataShareAdapterTest::DEFAULT_BLOCK_SIZE = 2 * 1024 * 1024;
std::shared_ptr<RdbStore> RdbDataShareAdapterTest::store = nullptr;
class RdbStepSharedResultSetOpenCallback : public RdbOpenCallback {
public:
int OnCreate(RdbStore &rdbStore) override;
int OnUpgrade(RdbStore &rdbStore, int oldVersion, int newVersion) override;
static const std::string CREATE_TABLE_TEST;
};
int RdbStepSharedResultSetOpenCallback::OnCreate(RdbStore &store)
{
return OHOS::NativeRdb::E_OK;
}
int RdbStepSharedResultSetOpenCallback::OnUpgrade(RdbStore &store, int oldVersion, int newVersion)
{
return OHOS::NativeRdb::E_OK;
}
void RdbDataShareAdapterTest::SetUpTestCase(void)
{
int errCode = OHOS::NativeRdb::E_OK;
RdbStoreConfig config(RdbDataShareAdapterTest::DATABASE_NAME);
RdbStepSharedResultSetOpenCallback helper;
RdbDataShareAdapterTest::store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
EXPECT_NE(RdbDataShareAdapterTest::store, nullptr);
EXPECT_EQ(errCode, OHOS::NativeRdb::E_OK);
}
void RdbDataShareAdapterTest::TearDownTestCase(void)
{
RdbHelper::DeleteRdbStore(RdbDataShareAdapterTest::DATABASE_NAME);
}
void RdbDataShareAdapterTest::SetUp(void)
{
store->ExecuteSql("DROP TABLE IF EXISTS test");
}
void RdbDataShareAdapterTest::TearDown(void)
{
RdbHelper::ClearCache();
}
void RdbDataShareAdapterTest::GenerateDefaultTable()
{
std::string createTableSql = std::string("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, data1 TEXT, ")
+ std::string("data2 INTEGER, data3 FLOAT, data4 BLOB);");
store->ExecuteSql(createTableSql);
std::string insertSql = "INSERT INTO test (data1, data2, data3, data4) VALUES (?, ?, ?, ?);";
/* insert first entry data */
uint8_t uValue = 66;
std::vector<uint8_t> typeBlob;
typeBlob.push_back(uValue);
store->ExecuteSql(insertSql, std::vector<ValueObject>{ ValueObject(std::string("hello")), ValueObject((int)10),
ValueObject((double)1.0), ValueObject((std::vector<uint8_t>)typeBlob) });
/* insert second entry data */
typeBlob.clear();
store->ExecuteSql(insertSql, std::vector<ValueObject>{
ValueObject(std::string("2")), ValueObject((int)-5), ValueObject((double)2.5),
ValueObject() // set double value 2.5
});
/* insert third entry data */
store->ExecuteSql(
insertSql, std::vector<ValueObject>{
ValueObject(std::string("hello world")), ValueObject((int)3), ValueObject((double)1.8),
ValueObject(std::vector<uint8_t>{ 4, 5, 6 }) // set int value 3, double 1.8
});
/* insert four entry data */
store->ExecuteSql(insertSql, std::vector<ValueObject>{
ValueObject(std::string("new world")), ValueObject((int)5),
ValueObject((double)5.8), ValueObject() // set int value 5, double 5.8
});
}
void RdbDataShareAdapterTest::GenerateDefaultEmptyTable()
{
std::string createTableSql = std::string("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, data1 TEXT, ")
+ std::string("data2 INTEGER, data3 FLOAT, data4 BLOB);");
store->ExecuteSql(createTableSql);
}
/* *
* @tc.name: Rdb_DataShare_Adapter_001
* @tc.desc: test RdbDataShareAdapter
* @tc.type: FUNC
*/
HWTEST_F(RdbDataShareAdapterTest, Rdb_DataShare_Adapter_001, TestSize.Level1)
{
GenerateDefaultTable();
std::shared_ptr<OHOS::NativeRdb::ResultSet> resultSet = store->QueryByStep("SELECT * FROM test");
EXPECT_NE(resultSet, nullptr);
int rowCount;
resultSet.get()->GetRowCount(rowCount);
LOG_INFO("result row count: %{public}d", rowCount);
EXPECT_NE(rowCount, 0);
}
/* *
* @tc.name: Rdb_DataShare_Adapter_002
* @tc.desc: normal testcase of RdbDataShareAdapter
* @tc.type: FUNC
*/
HWTEST_F(RdbDataShareAdapterTest, Rdb_DataShare_Adapter_002, TestSize.Level1)
{
GenerateDefaultTable();
std::string table = "test";
std::string column = "data1";
std::string value = "hello";
DataSharePredicates predicates;
predicates.EqualTo(column, value);
std::vector<std::string> columns;
std::shared_ptr<AbsSharedResultSet> allDataTypes =
store->Query(RdbUtils::ToPredicates(predicates, table), columns);
int rdbRowCount;
allDataTypes.get()->GetRowCount(rdbRowCount);
EXPECT_EQ(rdbRowCount, 1);
std::shared_ptr<ResultSetBridge> resultSetBridge = RdbUtils::ToResultSetBridge(allDataTypes);
int rowCount;
resultSetBridge->GetRowCount(rowCount);
EXPECT_EQ(rowCount, 1);
}
/* *
* @tc.name: Rdb_DataShare_Adapter_003
* @tc.desc: normal testcase of RdbDataShareAdapter
* @tc.type: FUNC
*/
HWTEST_F(RdbDataShareAdapterTest, Rdb_DataShare_Adapter_003, TestSize.Level1)
{
GenerateDefaultTable();
std::string table = "test";
OHOS::DataShare::DataSharePredicates predicates;
predicates.GreaterThan("data2", -5);
std::vector<std::string> columns;
std::shared_ptr<AbsSharedResultSet> allDataTypes =
store->Query(RdbUtils::ToPredicates(predicates, table), columns);
int rdbRowCount;
allDataTypes.get()->GetRowCount(rdbRowCount);
EXPECT_EQ(rdbRowCount, 3);
std::shared_ptr<ResultSetBridge> resultSetBridge = RdbUtils::ToResultSetBridge(allDataTypes);
int bridgeRowCount;
resultSetBridge->GetRowCount(bridgeRowCount);
EXPECT_EQ(bridgeRowCount, 3);
std::shared_ptr<DataShareResultSet> dataShareResultSet =
std::make_shared<OHOS::DataShare::DataShareResultSet>(resultSetBridge);
dataShareResultSet->GoToFirstRow();
int dataShareRowCount;
dataShareResultSet->GetRowCount(dataShareRowCount);
EXPECT_EQ(dataShareRowCount, 3);
std::string strValue;
dataShareResultSet->GetString(1, strValue);
EXPECT_EQ("hello", strValue);
int intValue;
dataShareResultSet->GetInt(2, intValue);
EXPECT_EQ(intValue, 10);
std::vector<uint8_t> blobValue;
uint8_t blobData = 66;
dataShareResultSet->GetBlob(4, blobValue);
EXPECT_EQ(blobData, blobValue[0]);
dataShareResultSet->GoToNextRow();
dataShareResultSet->GetBlob(4, blobValue);
EXPECT_EQ(3, static_cast<int>(blobValue.size()));
blobData = 5;
EXPECT_EQ(blobData, blobValue[1]);
}
/* *
* @tc.name: Rdb_DataShare_Adapter_004
* @tc.desc: normal testcase of RdbDataShareAdapter
* @tc.type: FUNC
*/
HWTEST_F(RdbDataShareAdapterTest, Rdb_DataShare_Adapter_004, TestSize.Level1)
{
GenerateDefaultTable();
std::string table = "test";
OHOS::DataShare::DataSharePredicates predicates;
predicates.SetWhereClause("`data2` > ?");
predicates.SetWhereArgs(std::vector<std::string>{ "-5" });
predicates.SetOrder("data3");
std::vector<std::string> columns;
std::shared_ptr<AbsSharedResultSet> allDataTypes =
store->Query(RdbUtils::ToPredicates(predicates, table), columns);
int rowCount;
allDataTypes.get()->GetRowCount(rowCount);
EXPECT_EQ(rowCount, 3);
std::shared_ptr<ResultSetBridge> resultSetBridge = RdbUtils::ToResultSetBridge(allDataTypes);
std::shared_ptr<DataShareResultSet> dataShareResultSet =
std::make_shared<OHOS::DataShare::DataShareResultSet>(resultSetBridge);
dataShareResultSet->GoToFirstRow();
int dataShareRowCount;
dataShareResultSet->GetRowCount(dataShareRowCount);
EXPECT_EQ(dataShareRowCount, 3);
std::string strValue;
dataShareResultSet->GetString(1, strValue);
EXPECT_EQ("hello", strValue);
int intValue;
dataShareResultSet->GetInt(2, intValue);
EXPECT_EQ(intValue, 10);
std::vector<uint8_t> blobValue;
dataShareResultSet->GetBlob(4, blobValue);
EXPECT_EQ(1, static_cast<int>(blobValue.size()));
dataShareResultSet->GoToNextRow();
std::string strValue3;
dataShareResultSet->GetString(1, strValue3);
EXPECT_EQ("hello world", strValue3);
int intValue3;
dataShareResultSet->GetInt(2, intValue3);
EXPECT_EQ(intValue3, 3);
std::vector<uint8_t> blobValue2;
dataShareResultSet->GetBlob(4, blobValue2);
EXPECT_EQ(3, static_cast<int>(blobValue2.size()));
uint8_t blobData = 5;
EXPECT_EQ(blobData, blobValue2[1]);
}

View File

@ -82,8 +82,7 @@
"name": "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/data_share:datashare_abilitykit",
"header": {
"header_files": [
"datashare_abstract_result_set.h",
"datashare_block_writer.h"
"result_set_bridge.h"
],
"header_base": "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/data_share/provider/include"
}

View File

@ -30,40 +30,14 @@ public:
DataSharePredicates();
explicit DataSharePredicates(Predicates &predicates);
~DataSharePredicates();
DataSharePredicates *EqualTo(const std::string &field, const int value)override;
DataSharePredicates *EqualTo(const std::string &field, const int64_t value)override;
DataSharePredicates *EqualTo(const std::string &field, const double value)override;
DataSharePredicates *EqualTo(const std::string &field, const std::string &value)override;
DataSharePredicates *EqualTo(const std::string &field, const bool value)override;
DataSharePredicates *NotEqualTo(const std::string &field, const int value)override;
DataSharePredicates *NotEqualTo(const std::string &field, const int64_t value)override;
DataSharePredicates *NotEqualTo(const std::string &field, const double value)override;
DataSharePredicates *NotEqualTo(const std::string &field, const std::string &value)override;
DataSharePredicates *NotEqualTo(const std::string &field, const bool value)override;
DataSharePredicates *GreaterThan(const std::string &field, const int value)override;
DataSharePredicates *GreaterThan(const std::string &field, const int64_t value)override;
DataSharePredicates *GreaterThan(const std::string &field, const double value)override;
DataSharePredicates *GreaterThan(const std::string &field, const std::string &value)override;
DataSharePredicates *LessThan(const std::string &field, const int value)override;
DataSharePredicates *LessThan(const std::string &field, const int64_t value)override;
DataSharePredicates *LessThan(const std::string &field, const double value)override;
DataSharePredicates *LessThan(const std::string &field, const std::string &value)override;
DataSharePredicates *GreaterThanOrEqualTo(const std::string &field, const int value)override;
DataSharePredicates *GreaterThanOrEqualTo(const std::string &field, const int64_t value)override;
DataSharePredicates *GreaterThanOrEqualTo(const std::string &field, const double value)override;
DataSharePredicates *GreaterThanOrEqualTo(const std::string &field, const std::string &value)override;
DataSharePredicates *LessThanOrEqualTo(const std::string &field, const int value)override;
DataSharePredicates *LessThanOrEqualTo(const std::string &field, const int64_t value)override;
DataSharePredicates *LessThanOrEqualTo(const std::string &field, const double value)override;
DataSharePredicates *LessThanOrEqualTo(const std::string &field, const std::string &value)override;
DataSharePredicates *In(const std::string &field, const std::vector<int> &values)override;
DataSharePredicates *In(const std::string &field, const std::vector<int64_t> &values)override;
DataSharePredicates *In(const std::string &field, const std::vector<double> &values)override;
DataSharePredicates *In(const std::string &field, const std::vector<std::string> &values)override;
DataSharePredicates *NotIn(const std::string &field, const std::vector<int> &values)override;
DataSharePredicates *NotIn(const std::string &field, const std::vector<int64_t> &values)override;
DataSharePredicates *NotIn(const std::string &field, const std::vector<double> &values)override;
DataSharePredicates *NotIn(const std::string &field, const std::vector<std::string> &values)override;
DataSharePredicates *EqualTo(const std::string &field, const DataSharePredicatesObject &value)override;
DataSharePredicates *NotEqualTo(const std::string &field, const DataSharePredicatesObject &value)override;
DataSharePredicates *GreaterThan(const std::string &field, const DataSharePredicatesObject &value)override;
DataSharePredicates *LessThan(const std::string &field, const DataSharePredicatesObject &value)override;
DataSharePredicates *GreaterThanOrEqualTo(const std::string &field, const DataSharePredicatesObject &value)override;
DataSharePredicates *LessThanOrEqualTo(const std::string &field, const DataSharePredicatesObject &value)override;
DataSharePredicates *In(const std::string &field, const DataSharePredicatesObject &values)override;
DataSharePredicates *NotIn(const std::string &field, const DataSharePredicatesObject &values)override;
DataSharePredicates *BeginWrap()override;
DataSharePredicates *EndWrap()override;
DataSharePredicates *Or()override;
@ -99,11 +73,11 @@ public:
std::string GetTableName() const;
private:
void SetOperationList(OperationType operationType, DataSharePredicatesObject &para1,
DataSharePredicatesObject &para2, DataSharePredicatesObject &para3, ParameterCount parameterCount);
void SetOperationList(OperationType operationType, const DataSharePredicatesObject &para1,
const DataSharePredicatesObject &para2, const DataSharePredicatesObject &para3, ParameterCount parameterCount);
void ClearQueryLanguage();
void SetSettingMode(const SettingMode &settingMode);
mutable Predicates predicates_;
Predicates predicates_;
std::string whereClause_;
std::vector<std::string> whereArgs_;
std::string order_;

View File

@ -42,18 +42,18 @@ public:
~DataSharePredicatesObject();
DataSharePredicatesObject(DataSharePredicatesObject &&DataSharePredicatesObject) noexcept;
DataSharePredicatesObject(const DataSharePredicatesObject &DataSharePredicatesObject);
explicit DataSharePredicatesObject(int val);
explicit DataSharePredicatesObject(int16_t val);
explicit DataSharePredicatesObject(int64_t val);
explicit DataSharePredicatesObject(double val);
explicit DataSharePredicatesObject(bool val);
explicit DataSharePredicatesObject(const std::string &val);
explicit DataSharePredicatesObject(const std::vector<int> &val);
explicit DataSharePredicatesObject(const std::vector<int64_t> &val);
explicit DataSharePredicatesObject(const std::vector<double> &val);
explicit DataSharePredicatesObject(const std::vector<std::string> &val);
DataSharePredicatesObject &operator=(DataSharePredicatesObject &&DataSharePredicatesObject) noexcept;
DataSharePredicatesObject &operator=(const DataSharePredicatesObject &DataSharePredicatesObject);
DataSharePredicatesObject(int val);
DataSharePredicatesObject(int64_t val);
DataSharePredicatesObject(double val);
DataSharePredicatesObject(bool val);
DataSharePredicatesObject(const std::string &val);
DataSharePredicatesObject(const std::vector<int> &val);
DataSharePredicatesObject(const std::vector<int64_t> &val);
DataSharePredicatesObject(const std::vector<double> &val);
DataSharePredicatesObject(const std::vector<std::string> &val);
DataSharePredicatesObjectType GetType() const;
int GetInt(int &val) const;
int GetLong(int64_t &val) const;
@ -66,8 +66,13 @@ public:
int GetStringVector(std::vector<std::string> &val) const;
bool Marshalling(Parcel &parcel) const override;
static DataSharePredicatesObject *Unmarshalling(Parcel &parcel);
std::variant<int, int64_t, double, std::string, bool, std::vector<int>, std::vector<int64_t>,
std::variant<std::monostate, int, int64_t, double, std::string, bool, std::vector<int>, std::vector<int64_t>,
std::vector<std::string>, std::vector<double>> value;
template<typename T>
operator T () const
{
return std::get<T>(value);
}
private:
void MarshallingVector(Parcel &parcel) const;

View File

@ -38,12 +38,12 @@ public:
~DataShareValueObject();
DataShareValueObject(DataShareValueObject &&DataShareValueObject) noexcept;
DataShareValueObject(const DataShareValueObject &DataShareValueObject);
explicit DataShareValueObject(int val);
explicit DataShareValueObject(int64_t val);
explicit DataShareValueObject(double val);
explicit DataShareValueObject(bool val);
explicit DataShareValueObject(const std::string &val);
explicit DataShareValueObject(const std::vector<uint8_t> &blob);
DataShareValueObject(int val);
DataShareValueObject(int64_t val);
DataShareValueObject(double val);
DataShareValueObject(bool val);
DataShareValueObject(const std::string &val);
DataShareValueObject(const std::vector<uint8_t> &blob);
DataShareValueObject &operator=(DataShareValueObject &&DataShareValueObject) noexcept;
DataShareValueObject &operator=(const DataShareValueObject &DataShareValueObject);
@ -58,9 +58,8 @@ public:
bool Marshalling(Parcel &parcel) const override;
static DataShareValueObject *Unmarshalling(Parcel &parcel);
private:
DataShareValueObjectType type;
std::variant<int64_t, double, std::string, bool, std::vector<uint8_t>> value;
std::variant<std::monostate, int64_t, double, std::string, bool, std::vector<uint8_t>> value;
};
} // namespace DataShare
} // namespace OHOS

View File

@ -29,19 +29,23 @@ public:
DataShareValuesBucket();
explicit DataShareValuesBucket(std::map<std::string, DataShareValueObject> &valuesMap);
~DataShareValuesBucket();
void PutString(const std::string &columnOrKeyName, const std::string &value);
void PutInt(const std::string &columnOrKeyName, int value);
void PutLong(const std::string &columnOrKeyName, int64_t value);
void PutDouble(const std::string &columnOrKeyName, double value);
void PutBool(const std::string &columnOrKeyName, bool value);
void PutBlob(const std::string &columnOrKeyName, const std::vector<uint8_t> &value);
void PutNull(const std::string &columnOrKeyName);
void Delete(const std::string &columnOrKeyName);
void Put(const std::string &columnName, const DataShareValueObject &value = {})
{
valuesMap.insert(std::make_pair(columnName, value));
}
void PutString(const std::string &columnName, const std::string &value);
void PutInt(const std::string &columnName, int value);
void PutLong(const std::string &columnName, int64_t value);
void PutDouble(const std::string &columnName, double value);
void PutBool(const std::string &columnName, bool value);
void PutBlob(const std::string &columnName, const std::vector<uint8_t> &value);
void PutNull(const std::string &columnName);
void Delete(const std::string &columnName);
void Clear();
int Size() const;
bool IsEmpty() const;
bool HasColumnOrKey(const std::string &columnOrKeyName) const;
bool GetObject(const std::string &columnOrKeyName, DataShareValueObject &value) const;
bool HasColumn(const std::string &columnName) const;
bool GetObject(const std::string &columnName, DataShareValueObject &value) const;
void GetAll(std::map<std::string, DataShareValueObject> &valuesMap) const;
bool Marshalling(Parcel &parcel) const override;

View File

@ -26,7 +26,7 @@
#include "parcel.h"
#include "shared_block.h"
#include "datashare_shared_result_set.h"
#include "datashare_abstract_result_set.h"
#include "result_set_bridge.h"
#include "datashare_block_writer_impl.h"
namespace OHOS {
@ -34,7 +34,7 @@ namespace DataShare {
class DataShareResultSet : public DataShareAbsResultSet, public DataShareSharedResultSet {
public:
DataShareResultSet();
explicit DataShareResultSet(std::shared_ptr<DataShareAbstractResultSet> &resultSet);
explicit DataShareResultSet(std::shared_ptr<ResultSetBridge> &bridge);
virtual ~DataShareResultSet();
int GetBlob(int columnIndex, std::vector<uint8_t> &blob) override;
int GetString(int columnIndex, std::string &value) override;
@ -47,7 +47,7 @@ public:
int GetAllColumnNames(std::vector<std::string> &columnNames) override;
int GetRowCount(int &count) override;
AppDataFwk::SharedBlock *GetBlock() const override;
bool OnGo(int oldRowIndex, int newRowIndex) override;
bool OnGo(int startRowIndex, int targetRowIndex) override;
void FillBlock(int startRowIndex, AppDataFwk::SharedBlock *block) override;
virtual void SetBlock(AppDataFwk::SharedBlock *block);
int Close() override;
@ -69,10 +69,16 @@ private:
static const int INIT_POS = -1;
static const size_t DEFAULT_BLOCK_SIZE = 2 * 1024 * 1024;
static int blockId_;
// Equivalent to filling in setp + 1 rows each time
static const int STEP_LENGTH = 2;
// The actual position of the first row of data in the shareblock
int startRowPos_ = -1;
// The actual position of the last row of data in the shareblock
int endRowPos_ = -1;
// The SharedBlock owned by this DataShareResultSet
AppDataFwk::SharedBlock *sharedBlock_ = nullptr;
std::shared_ptr<DataShareBlockWriterImpl> blockWriter_ = nullptr;
std::shared_ptr<DataShareAbstractResultSet> resultSet_ = nullptr;
std::shared_ptr<ResultSetBridge> bridge_ = nullptr;
};
} // namespace DataShare
} // namespace OHOS

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATASHARE_ABSTRACT_RESULT_SET_H
#define DATASHARE_ABSTRACT_RESULT_SET_H
#include <string>
#include "datashare_block_writer.h"
namespace OHOS {
namespace DataShare {
class DataShareAbstractResultSet {
public:
virtual ~DataShareAbstractResultSet() {}
/**
* Returns a string array holding the names of all of the columns in the
* result set.
*
* return the names of the columns contains in this query result.
*/
virtual int GetAllColumnOrKeyName(std::vector<std::string> &columnOrKeyNames) = 0;
/**
* return the numbers of rows in the result set.
*/
virtual int GetRowCount(int &count) = 0;
/**
* Called when the position of the result set changes
*/
virtual bool OnGo(int oldRowIndex, int targetRowIndex, const std::shared_ptr<DataShareBlockWriter>& writer) = 0;
};
} // namespace DataShare
} // namespace OHOS
#endif

View File

@ -1,111 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATASHARE_BLOCK_WRITER_H
#define DATASHARE_BLOCK_WRITER_H
#include <string>
namespace OHOS {
namespace DataShare {
/**
* This class stores a set of rows from a database in a buffer
* which is used as the set of query result.
*/
class DataShareBlockWriter {
public:
/**
* SharedBlock Deconstruction.
*/
virtual ~DataShareBlockWriter() {}
/**
* Clear current shared block.
*/
virtual int Clear() = 0;
/**
* Set a shared block column.
*/
virtual int SetColumnNum(uint32_t numColumns) = 0;
/**
* Allocate a row unit and its directory.
*/
virtual int AllocRow() = 0;
/**
* Release the value of the last row.
*/
virtual int FreeLastRow() = 0;
/**
* Write blob data to the shared block.
*/
virtual int WriteBlob(uint32_t row, uint32_t column, const void *value, size_t Size) = 0;
/**
* Write string data to the shared block.
*/
virtual int WriteString(uint32_t row, uint32_t column, const char *value, size_t sizeIncludingNull) = 0;
/**
* Write long data to the shared block.
*/
virtual int WriteLong(uint32_t row, uint32_t column, int64_t value) = 0;
/**
* Write Double data to the shared block.
*/
virtual int WriteDouble(uint32_t row, uint32_t column, double value) = 0;
/**
* Write Null data to the shared block.
*/
virtual int WriteNull(uint32_t row, uint32_t column) = 0;
/**
* Size of the used byte in the block.
*/
virtual size_t GetUsedBytes() = 0;
/**
* The name of the current result set.
*/
virtual std::string Name() = 0;
/**
* The size of the current result set.
*/
virtual size_t Size() = 0;
/**
* The row number of the current result set.
*/
virtual uint32_t GetRowNum() = 0;
/**
* The column number of the current result set.
*/
virtual uint32_t GetColumnNum() = 0;
/**
* Write raw data in block.
*/
virtual size_t SetRawData(const void *rawData, size_t size) = 0;
};
} // namespace DataShare
} // namespace OHOS
#endif

View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATASHARE_RESULT_SET_BRIDGE_H
#define DATASHARE_RESULT_SET_BRIDGE_H
#include <string>
namespace OHOS {
namespace DataShare {
// build the bridge between the database's ResultSet and DataShare's ResultSet
class ResultSetBridge {
public:
class Creator {
public:
virtual std::shared_ptr<ResultSetBridge> Create() = 0;
};
class Writer {
public:
/**
* Allocate a row unit and its directory.
*/
virtual int AllocRow() = 0;
/**
* Write Null data to the shared block.
*/
virtual int Write(uint32_t column) = 0;
/**
* Write long data to the shared block.
*/
virtual int Write(uint32_t column, int64_t value) = 0;
/**
* Write Double data to the shared block.
*/
virtual int Write(uint32_t column, double value) = 0;
/**
* Write blob data to the shared block.
*/
virtual int Write(uint32_t column, const uint8_t *value, size_t size) = 0;
/**
* Write string data to the shared block.
*/
virtual int Write(uint32_t column, const char *value, size_t size) = 0;
};
virtual ~ResultSetBridge() {}
/**
* Return a string array holding the names of all of the columns in the
* result set.
*
* return the names of the columns contains in this query result.
*/
virtual int GetAllColumnNames(std::vector<std::string> &columnNames) = 0;
/**
* Return the numbers of rows in the result set.
*/
virtual int GetRowCount(int32_t &count) = 0;
/**
* Called when the position of the result set changes
*/
virtual bool OnGo(int32_t startRowIndex, int32_t targetRowIndex, Writer &writer) = 0;
};
} // namespace DataShare
} // namespace OHOS
#endif

View File

@ -68,6 +68,7 @@
"build": {
"sub_component": [
"//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/appdatafwk:native_appdatafwk",
"//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb_data_share_adapter:native_rdb_data_share_adapter",
"//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb:native_rdb",
"//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/rdb:rdb"
],
@ -102,11 +103,21 @@
],
"header_base": "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/appdatafwk/include"
}
},
{
"name": "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb_data_share_adapter:native_rdb_data_share_adapter",
"header": {
"header_files": [
"rdb_utils.h"
],
"header_base": "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb_data_share_adapter/include"
}
}
],
"test": [
"//foundation/distributeddatamgr/appdatamgr/frameworks/native/rdb/test:unittest",
"//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/rdb/test:unittest"
"//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/rdb/test:unittest",
"//foundation/distributeddatamgr/appdatamgr/frameworks/native/rdb_data_share_adapter/test:unittest"
]
}
}

View File

@ -104,17 +104,17 @@ public:
virtual bool IsMemoryRdb() const = 0;
virtual int ChangeDbFileForRestore(const std::string newPath, const std::string backupPath,
const std::vector<uint8_t> &newKey) = 0;
virtual bool SetDistributedTables(const std::vector<std::string>& tables) = 0;
virtual std::string ObtainDistributedTableName(const std::string& device, const std::string& table) = 0;
virtual bool Sync(const SyncOption& option, const AbsRdbPredicates& predicate, const SyncCallback& callback) = 0;
virtual bool Subscribe(const SubscribeOption& option, RdbStoreObserver *observer) = 0;
virtual bool UnSubscribe(const SubscribeOption& option, RdbStoreObserver *observer) = 0;
// user must use UDID
virtual bool DropDeviceData(const std::vector<std::string>& devices, const DropOption& option) = 0;
};

View File

@ -0,0 +1,53 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
config("rdb_data_share_adapter_config") {
visibility = [ ":*" ]
include_dirs = [
"include",
"//utils/native/base/include",
"../../../../interfaces/inner_api/native/data_share/common/include",
"../../../../interfaces/inner_api/native/data_share/consumer/include",
"../../../../interfaces/inner_api/native/data_share/provider/include",
"../../../../interfaces/inner_api/native/rdb/include",
"../../../../frameworks/native/data_share/common/include",
]
}
config("rdb_data_share_adapter_public_config") {
visibility = [ ":*" ]
include_dirs = [ "include", "../../../../interfaces/inner_api/native/data_share/provider/include" ]
}
ohos_shared_library("native_rdb_data_share_adapter") {
sources = [
"../../../../frameworks/native/rdb_data_share_adapter/src/rdb_utils.cpp",
"../../../../frameworks/native/rdb_data_share_adapter/src/rdb_result_set_bridge.cpp",
]
configs = [ ":rdb_data_share_adapter_config" ]
subsystem_name = "distributeddatamgr"
part_name = "relational_store"
deps = [ "//utils/native/base:utils" ]
external_deps = [
"hilog_native:libhilog",
"relational_store:native_rdb",
"data_share:datashare_common",
]
public_configs = [ ":rdb_data_share_adapter_public_config" ]
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DATA_SHARE_ADAPTER_LOGGER_H
#define DATA_SHARE_ADAPTER_LOGGER_H
#include "hilog/log.h"
namespace OHOS {
namespace RdbDataShareAdapter {
static const OHOS::HiviewDFX::HiLogLabel DATA_SHARE_ADAPTER_LABEL = { LOG_CORE, 0xD001650,
"DATA_SHARE_ADAPTER_NATIVE" };
#define LOG_DEBUG(...) ((void)OHOS::HiviewDFX::HiLog::Debug(DATA_SHARE_ADAPTER_LABEL, __VA_ARGS__))
#define LOG_INFO(...) ((void)OHOS::HiviewDFX::HiLog::Info(DATA_SHARE_ADAPTER_LABEL, __VA_ARGS__))
#define LOG_WARN(...) ((void)OHOS::HiviewDFX::HiLog::Warn(DATA_SHARE_ADAPTER_LABEL, __VA_ARGS__))
#define LOG_ERROR(...) ((void)OHOS::HiviewDFX::HiLog::Error(DATA_SHARE_ADAPTER_LABEL, __VA_ARGS__))
#define LOG_FATAL(...) ((void)OHOS::HiviewDFX::HiLog::Fatal(DATA_SHARE_ADAPTER_LABEL, __VA_ARGS__))
} // namespace RdbDataShareAdapter
} // namespace OHOS
#endif // DATA_SHARE_ADAPTER_LOGGER_H

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RDB_RESULT_SET_BRIDGE_H
#define RDB_RESULT_SET_BRIDGE_H
#include "../../rdb/include/result_set.h"
#include "rdb_errno.h"
#include "result_set_bridge.h"
#include "string.h"
namespace OHOS {
namespace NativeRdb {
class ResultSet;
}
namespace RdbDataShareAdapter {
class RdbResultSetBridge : public DataShare::ResultSetBridge {
public:
using ResultSet = NativeRdb::ResultSet;
using ColumnType = NativeRdb::ColumnType;
RdbResultSetBridge(std::shared_ptr<ResultSet> resultSet);
~RdbResultSetBridge();
int GetAllColumnNames(std::vector<std::string> &columnNames) override;
int GetRowCount(int32_t &count) override;
bool OnGo(int32_t start, int32_t length, Writer &writer) override;
private:
void GetColumnTypes(int columnCount, ColumnType columnTypes[]);
void WriteBlock(int32_t start, int32_t target, int columnCount, ColumnType columnTypes[], Writer &writer);
bool WriteBlobData(int column, Writer &writer);
void WriteColumn(int columnCount, const ColumnType *columnTypes, Writer &writer, int row);
std::shared_ptr<ResultSet> rdbResultSet_;
};
} // namespace RdbDataShareAdapter
} // namespace OHOS
#endif // RDB_RESULT_SET_BRIDGE_H

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NATIVE_RDB_UTILS_H
#define NATIVE_RDB_UTILS_H
#include <list>
#include <memory>
#include <string>
#include <vector>
#include "../../rdb/include/result_set.h"
#include "abs_predicates.h"
#include "datashare_predicates.h"
#include "datashare_values_bucket.h"
#include "rdb_predicates.h"
#include "rdb_result_set_bridge.h"
#include "result_set_bridge.h"
#include "value_object.h"
#include "values_bucket.h"
namespace OHOS {
namespace RdbDataShareAdapter {
class RdbUtils {
public:
using RdbPredicates = NativeRdb::RdbPredicates;
using ResultSet = NativeRdb::ResultSet;
using ValuesBucket = NativeRdb::ValuesBucket;
using DataShareValuesBucket = DataShare::DataShareValuesBucket;
using DataSharePredicates = DataShare::DataSharePredicates;
using ResultSetBridge = DataShare::ResultSetBridge;
using OperationItem = DataShare::OperationItem;
using DataSharePredicatesObject = DataShare::DataSharePredicatesObject;
static ValuesBucket ToValuesBucket(const DataShareValuesBucket &bucket);
static RdbPredicates ToPredicates(const DataSharePredicates &predicates, const std::string &table);
static std::shared_ptr<ResultSetBridge> ToResultSetBridge(std::shared_ptr<ResultSet> resultSet);
private:
RdbUtils();
~RdbUtils();
static void ToOperateThird(
const std::list<OperationItem>::iterator operations, std::shared_ptr<RdbPredicates> &predicates);
static void ToOperateSecond(
const std::list<OperationItem>::iterator operations, std::shared_ptr<RdbPredicates> &predicates);
static void ToOperateFirst(
const std::list<OperationItem>::iterator operations, std::shared_ptr<RdbPredicates> &predicates);
static std::string ToString(const DataSharePredicatesObject &predicatesObject);
};
} // namespace RdbDataShareAdapter
} // namespace OHOS
#endif // NATIVE_RDB_UTILS_H