mirror of
https://gitee.com/openharmony/distributeddatamgr_relational_store
synced 2024-11-27 01:01:02 +00:00
rdb v9 error code fix bug
Signed-off-by: PaDaBoo <xuejianwu@huawei.com>
This commit is contained in:
parent
e451ab8cf7
commit
6c5866d7b4
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@
|
||||
CMakeLists.txt
|
||||
cmake-build-debug
|
||||
.clang-format
|
||||
.vscode/
|
@ -22,6 +22,8 @@ namespace AppDataMgrJsKit {
|
||||
constexpr int MAX_INPUT_COUNT = 10;
|
||||
constexpr int OK = 0;
|
||||
constexpr int ERR = -1;
|
||||
constexpr int APIVERSION_V9 = 9;
|
||||
constexpr int APIVERSION_V8 = 8;
|
||||
|
||||
constexpr int E_PARAM_ERROR = 401;
|
||||
|
||||
@ -32,25 +34,30 @@ constexpr int E_DB_CORRUPTED = 14800011;
|
||||
constexpr int E_RESULT_GET_ERROR = 14800013;
|
||||
constexpr int E_RESULT_GOTO_ERROR = 14800012;
|
||||
|
||||
#define RDB_NAPI_ASSERT_BASE(env, assertion, error, retVal) \
|
||||
#define RDB_NAPI_ASSERT_BASE_FROMV9(env, assertion, error, retVal, version) \
|
||||
do { \
|
||||
if (!(assertion)) { \
|
||||
if (error != nullptr) { \
|
||||
LOG_ERROR("throw error: code = %{public}d , message = %{public}s", error->GetCode(), \
|
||||
error->GetMessage().c_str()); \
|
||||
napi_throw_error((env), std::to_string(error->GetCode()).c_str(), error->GetMessage().c_str()); \
|
||||
return retVal; \
|
||||
} \
|
||||
LOG_ERROR("throw error: error message is empty"); \
|
||||
if ((error) == nullptr) { \
|
||||
LOG_ERROR("throw error: error message is empty,version= %{public}d", version); \
|
||||
napi_throw_error((env), nullptr, "error message is empty"); \
|
||||
return retVal; \
|
||||
} \
|
||||
if (((version) > (APIVERSION_V8)) || ((error->GetCode()) == (401))) { \
|
||||
LOG_ERROR("throw error: code = %{public}d , message = %{public}s, version= %{public}d", \
|
||||
error->GetCode(), error->GetMessage().c_str(), version); \
|
||||
napi_throw_error((env), std::to_string(error->GetCode()).c_str(), error->GetMessage().c_str()); \
|
||||
return retVal; \
|
||||
} \
|
||||
LOG_ERROR("nothrow error: code = %{public}d , message = %{public}s, version= %{public}d", \
|
||||
error->GetCode(), error->GetMessage().c_str(), version); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define RDB_NAPI_ASSERT(env, assertion, error) RDB_NAPI_ASSERT_BASE(env, assertion, error, nullptr)
|
||||
#define RDB_NAPI_ASSERT_FROMV9(env, assertion, error, version) \
|
||||
RDB_NAPI_ASSERT_BASE_FROMV9(env, assertion, error, nullptr, version)
|
||||
|
||||
#define RDB_NAPI_ASSERT_RETURN_VOID(env, assertion, error) \
|
||||
RDB_NAPI_ASSERT_BASE(env, assertion, error, NAPI_RETVAL_NOTHING)
|
||||
#define RDB_NAPI_ASSERT_RETURN_VOID_FROMV9(env, assertion, error, version) \
|
||||
RDB_NAPI_ASSERT_BASE_FROMV9(env, assertion, error, NAPI_RETVAL_NOTHING, version)
|
||||
|
||||
#define RDB_ASYNC_PARAM_CHECK_FUNCTION(theCall) \
|
||||
do { \
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi_rdb_error.h"
|
||||
#include "rdb_predicates.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -28,16 +29,20 @@ namespace RdbJsKit {
|
||||
class RdbPredicatesProxy {
|
||||
public:
|
||||
static void Init(napi_env env, napi_value exports);
|
||||
static napi_value NewInstance(napi_env env, std::shared_ptr<NativeRdb::RdbPredicates> value);
|
||||
static napi_value NewInstance(
|
||||
napi_env env, std::shared_ptr<NativeRdb::RdbPredicates> value, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static void Destructor(napi_env env, void *nativeObject, void *finalize_hint);
|
||||
|
||||
explicit RdbPredicatesProxy(std::string &tableName);
|
||||
std::shared_ptr<NativeRdb::RdbPredicates> GetPredicates() const;
|
||||
int apiversion = AppDataMgrJsKit::APIVERSION_V8;
|
||||
|
||||
private:
|
||||
~RdbPredicatesProxy();
|
||||
|
||||
static napi_value New(napi_env env, napi_callback_info info);
|
||||
static napi_value NewV9(napi_env env, napi_callback_info info);
|
||||
static napi_value InnerNew(napi_env env, napi_callback_info info, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static std::shared_ptr<NativeRdb::RdbPredicates> GetNativePredicates(napi_env env, napi_callback_info info);
|
||||
|
||||
static RdbPredicatesProxy *ParseFieldArrayByName(napi_env env, napi_callback_info info, napi_value &thiz,
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi_rdb_error.h"
|
||||
#include "napi_rdb_store_observer.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "rdb_types.h"
|
||||
@ -31,14 +32,19 @@ namespace RdbJsKit {
|
||||
class RdbStoreProxy {
|
||||
public:
|
||||
static void Init(napi_env env, napi_value exports);
|
||||
static napi_value NewInstance(napi_env env, std::shared_ptr<OHOS::NativeRdb::RdbStore> value);
|
||||
static napi_value NewInstance(
|
||||
napi_env env, std::shared_ptr<OHOS::NativeRdb::RdbStore> value, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static RdbStoreProxy *GetNativeInstance(napi_env env, napi_value self);
|
||||
void Release(napi_env env);
|
||||
RdbStoreProxy();
|
||||
~RdbStoreProxy();
|
||||
int apiversion = AppDataMgrJsKit::APIVERSION_V8;
|
||||
|
||||
private:
|
||||
static napi_value InnerInitialize(
|
||||
napi_env env, napi_callback_info info, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static napi_value Initialize(napi_env env, napi_callback_info info);
|
||||
static napi_value InitializeV9(napi_env env, napi_callback_info info);
|
||||
static napi_value Delete(napi_env env, napi_callback_info info);
|
||||
static napi_value Update(napi_env env, napi_callback_info info);
|
||||
static napi_value Insert(napi_env env, napi_callback_info info);
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi_rdb_error.h"
|
||||
#include "result_set_bridge.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -32,20 +33,27 @@ public:
|
||||
~ResultSetProxy();
|
||||
ResultSetProxy(std::shared_ptr<NativeRdb::ResultSet> resultSet);
|
||||
ResultSetProxy &operator=(std::shared_ptr<NativeRdb::ResultSet> resultSet);
|
||||
static napi_value NewInstance(napi_env env, std::shared_ptr<NativeRdb::AbsSharedResultSet> resultSet);
|
||||
static napi_value NewInstance(napi_env env, std::shared_ptr<NativeRdb::ResultSet> resultSet);
|
||||
static napi_value NewInstance(napi_env env, std::shared_ptr<NativeRdb::AbsSharedResultSet> resultSet,
|
||||
int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static napi_value NewInstance(
|
||||
napi_env env, std::shared_ptr<NativeRdb::ResultSet> resultSet, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static std::shared_ptr<NativeRdb::AbsSharedResultSet> GetNativeObject(const napi_env &env, const napi_value &arg);
|
||||
static napi_value GetConstructor(napi_env env);
|
||||
static napi_value GetConstructor(napi_env env, int version);
|
||||
std::shared_ptr<DataShare::ResultSetBridge> Create() override;
|
||||
int apiversion = AppDataMgrJsKit::APIVERSION_V8;
|
||||
|
||||
private:
|
||||
static std::shared_ptr<NativeRdb::ResultSet> &GetInnerResultSet(napi_env env, napi_callback_info info);
|
||||
static std::shared_ptr<NativeRdb::ResultSet> &GetInnerResultSet(
|
||||
napi_env env, napi_callback_info info, int &version);
|
||||
static ResultSetProxy *ParseInt32FieldByName(
|
||||
napi_env env, napi_callback_info info, int32_t &field, const std::string fieldName);
|
||||
static ResultSetProxy *ParseFieldByName(
|
||||
napi_env env, napi_callback_info info, std::string &field, const std::string fieldName);
|
||||
|
||||
static napi_value InnerInitialize(
|
||||
napi_env env, napi_callback_info info, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static napi_value Initialize(napi_env env, napi_callback_info info);
|
||||
static napi_value InitializeV9(napi_env env, napi_callback_info info);
|
||||
static napi_value GetAllColumnNames(napi_env env, napi_callback_info info);
|
||||
static napi_value GoToRow(napi_env env, napi_callback_info info);
|
||||
static napi_value GetColumnCount(napi_env env, napi_callback_info info);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi_rdb_error.h"
|
||||
#include "rdb_predicates.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -28,16 +29,20 @@ namespace RdbJsKit {
|
||||
class RdbPredicatesProxy {
|
||||
public:
|
||||
static void Init(napi_env env, napi_value exports);
|
||||
static napi_value NewInstance(napi_env env, std::shared_ptr<NativeRdb::RdbPredicates> value);
|
||||
static napi_value NewInstance(
|
||||
napi_env env, std::shared_ptr<NativeRdb::RdbPredicates> value, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static void Destructor(napi_env env, void *nativeObject, void *finalize_hint);
|
||||
|
||||
explicit RdbPredicatesProxy(std::string &tableName);
|
||||
std::shared_ptr<NativeRdb::RdbPredicates> GetPredicates() const;
|
||||
int apiversion = AppDataMgrJsKit::APIVERSION_V8;
|
||||
|
||||
private:
|
||||
~RdbPredicatesProxy();
|
||||
|
||||
static napi_value New(napi_env env, napi_callback_info info);
|
||||
static napi_value NewV9(napi_env env, napi_callback_info info);
|
||||
static napi_value InnerNew(napi_env env, napi_callback_info info, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static std::shared_ptr<NativeRdb::RdbPredicates> GetNativePredicates(napi_env env, napi_callback_info info);
|
||||
|
||||
static RdbPredicatesProxy *ParseFieldArrayByName(napi_env env, napi_callback_info info, napi_value &thiz,
|
||||
|
@ -18,10 +18,11 @@
|
||||
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
#include "napi_rdb_error.h"
|
||||
#include "rdb_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -29,14 +30,19 @@ namespace RdbJsKit {
|
||||
class RdbStoreProxy {
|
||||
public:
|
||||
static void Init(napi_env env, napi_value exports);
|
||||
static napi_value NewInstance(napi_env env, std::shared_ptr<OHOS::NativeRdb::RdbStore> value);
|
||||
static napi_value NewInstance(
|
||||
napi_env env, std::shared_ptr<OHOS::NativeRdb::RdbStore> value, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static RdbStoreProxy *GetNativeInstance(napi_env env, napi_value self);
|
||||
void Release(napi_env env);
|
||||
RdbStoreProxy();
|
||||
~RdbStoreProxy();
|
||||
int apiversion = AppDataMgrJsKit::APIVERSION_V8;
|
||||
|
||||
private:
|
||||
static napi_value InnerInitialize(
|
||||
napi_env env, napi_callback_info info, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static napi_value Initialize(napi_env env, napi_callback_info info);
|
||||
static napi_value InitializeV9(napi_env env, napi_callback_info info);
|
||||
static napi_value Delete(napi_env env, napi_callback_info info);
|
||||
static napi_value Update(napi_env env, napi_callback_info info);
|
||||
static napi_value Insert(napi_env env, napi_callback_info info);
|
||||
|
@ -31,17 +31,20 @@ public:
|
||||
~ResultSetProxy();
|
||||
ResultSetProxy(std::shared_ptr<NativeRdb::ResultSet> resultSet);
|
||||
ResultSetProxy &operator=(std::shared_ptr<NativeRdb::ResultSet> resultSet);
|
||||
static napi_value NewInstance(napi_env env, std::shared_ptr<NativeRdb::ResultSet> resultSet);
|
||||
static napi_value GetConstructor(napi_env env);
|
||||
static napi_value NewInstance(napi_env env, std::shared_ptr<NativeRdb::ResultSet> resultSet, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static napi_value GetConstructor(napi_env env, int version);
|
||||
int apiversion = AppDataMgrJsKit::APIVERSION_V8;
|
||||
|
||||
private:
|
||||
static std::shared_ptr<NativeRdb::ResultSet> &GetInnerResultSet(napi_env env, napi_callback_info info);
|
||||
static std::shared_ptr<NativeRdb::ResultSet> &GetInnerResultSet(napi_env env, napi_callback_info info, int &version);
|
||||
static ResultSetProxy *ParseInt32FieldByName(
|
||||
napi_env env, napi_callback_info info, int32_t &field, const std::string fieldName);
|
||||
static ResultSetProxy *ParseFieldByName(
|
||||
napi_env env, napi_callback_info info, std::string &field, const std::string fieldName);
|
||||
|
||||
static napi_value InnerInitialize(napi_env env, napi_callback_info info, int version = AppDataMgrJsKit::APIVERSION_V8);
|
||||
static napi_value Initialize(napi_env env, napi_callback_info info);
|
||||
static napi_value InitializeV9(napi_env env, napi_callback_info info);
|
||||
static napi_value GetAllColumnNames(napi_env env, napi_callback_info info);
|
||||
static napi_value GoToRow(napi_env env, napi_callback_info info);
|
||||
static napi_value GetColumnCount(napi_env env, napi_callback_info info);
|
||||
|
@ -37,7 +37,7 @@ AsyncCall::AsyncCall(napi_env env, napi_callback_info info, std::shared_ptr<Cont
|
||||
// int -->input_(env, argc, argv, self)
|
||||
int status = (*context)(env, argc, argv, self);
|
||||
// if input return is not ok, then napi_throw_error context error
|
||||
RDB_NAPI_ASSERT_RETURN_VOID(env, status == OK, context->error);
|
||||
RDB_NAPI_ASSERT_RETURN_VOID_FROMV9(env, status == OK, context->error, context->apiversion);
|
||||
context_->ctx = std::move(context);
|
||||
napi_create_reference(env, self, 1, &context_->self);
|
||||
}
|
||||
@ -107,11 +107,16 @@ void AsyncCall::OnExecute(napi_env env, void *data)
|
||||
|
||||
void AsyncCall::SetBusinessError(napi_env env, napi_value *businessError, std::shared_ptr<Error> error, int apiversion)
|
||||
{
|
||||
napi_create_object(env, businessError);
|
||||
// if error is not inner error
|
||||
if (error != nullptr && error->GetCode() != E_INNER_ERROR) {
|
||||
napi_value code = nullptr;
|
||||
napi_value msg = nullptr;
|
||||
napi_create_object(env, businessError);
|
||||
if (apiversion < APIVERSION_V9) {
|
||||
napi_create_string_utf8(env, "async error.", NAPI_AUTO_LENGTH, &msg);
|
||||
napi_set_named_property(env, *businessError, "message", msg);
|
||||
return;
|
||||
}
|
||||
// if error is not inner error
|
||||
if (error != nullptr && error->GetCode() != E_INNER_ERROR) {
|
||||
napi_create_int32(env, error->GetCode(), &code);
|
||||
napi_create_string_utf8(env, error->GetMessage().c_str(), NAPI_AUTO_LENGTH, &msg);
|
||||
napi_set_named_property(env, *businessError, "code", code);
|
||||
|
@ -91,7 +91,7 @@ void RdbPredicatesProxy::Init(napi_env env, napi_value exports)
|
||||
SetGlobalNamedProperty(env, "RdbPredicatesConstructor", cons);
|
||||
|
||||
napi_value consV9;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_define_class(env, "RdbPredicatesV9", NAPI_AUTO_LENGTH, New, nullptr,
|
||||
NAPI_CALL_RETURN_VOID(env, napi_define_class(env, "RdbPredicatesV9", NAPI_AUTO_LENGTH, NewV9, nullptr,
|
||||
sizeof(descriptors) / sizeof(napi_property_descriptor), descriptors, &consV9));
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_reference(env, consV9, 1, &constructor_));
|
||||
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, exports, "RdbPredicatesV9", consV9));
|
||||
@ -102,6 +102,17 @@ void RdbPredicatesProxy::Init(napi_env env, napi_value exports)
|
||||
|
||||
napi_value RdbPredicatesProxy::New(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return InnerNew(env, info, APIVERSION_V8);
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::NewV9(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return InnerNew(env, info, APIVERSION_V9);
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::InnerNew(napi_env env, napi_callback_info info, int version)
|
||||
{
|
||||
LOG_DEBUG("RdbPredicatesProxy::New begin.");
|
||||
napi_value new_target;
|
||||
NAPI_CALL(env, napi_get_new_target(env, info, &new_target));
|
||||
bool is_constructor = (new_target != nullptr);
|
||||
@ -114,9 +125,11 @@ napi_value RdbPredicatesProxy::New(napi_env env, napi_callback_info info)
|
||||
if (is_constructor) {
|
||||
napi_valuetype valueType;
|
||||
NAPI_CALL(env, napi_typeof(env, args[0], &valueType));
|
||||
RDB_NAPI_ASSERT(env, valueType == napi_string, std::make_shared<ParamTypeError>("name", "a non empty string."));
|
||||
RDB_NAPI_ASSERT_FROMV9(
|
||||
env, valueType == napi_string, std::make_shared<ParamTypeError>("name", "a non empty string."), version);
|
||||
std::string tableName = JSUtils::Convert2String(env, args[0]);
|
||||
RDB_NAPI_ASSERT(env, !tableName.empty(), std::make_shared<ParamTypeError>("name", "a non empty string."));
|
||||
RDB_NAPI_ASSERT_FROMV9(
|
||||
env, !tableName.empty(), std::make_shared<ParamTypeError>("name", "a non empty string."), version);
|
||||
auto *proxy = new RdbPredicatesProxy(tableName);
|
||||
proxy->env_ = env;
|
||||
NAPI_CALL(env, napi_wrap(env, thiz, proxy, RdbPredicatesProxy::Destructor, nullptr, &proxy->wrapper_));
|
||||
@ -136,15 +149,15 @@ napi_value RdbPredicatesProxy::New(napi_env env, napi_callback_info info)
|
||||
return output;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::NewInstance(napi_env env, std::shared_ptr<NativeRdb::RdbPredicates> value)
|
||||
napi_value RdbPredicatesProxy::NewInstance(napi_env env, std::shared_ptr<NativeRdb::RdbPredicates> value, int version)
|
||||
{
|
||||
LOG_DEBUG("RdbPredicatesProxy::NewInstance begin.");
|
||||
napi_value cons;
|
||||
napi_status status = napi_get_reference_value(env, constructor_, &cons);
|
||||
if (status != napi_ok) {
|
||||
LOG_ERROR("RdbPredicatesProxy::NewInstance get constructor failed! napi_status:%{public}d!", status);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t argc = 1;
|
||||
napi_value args[1] = { JSUtils::Convert2JSValue(env, value->GetTableName()) };
|
||||
napi_value instance = nullptr;
|
||||
@ -161,6 +174,7 @@ napi_value RdbPredicatesProxy::NewInstance(napi_env env, std::shared_ptr<NativeR
|
||||
return instance;
|
||||
}
|
||||
proxy->predicates_ = std::move(value);
|
||||
proxy->apiversion = APIVERSION_V8;
|
||||
LOG_DEBUG("RdbPredicatesProxy::NewInstance end");
|
||||
return instance;
|
||||
}
|
||||
@ -184,11 +198,11 @@ RdbPredicatesProxy::RdbPredicatesProxy(std::string &tableName)
|
||||
|
||||
std::shared_ptr<NativeRdb::RdbPredicates> RdbPredicatesProxy::GetNativePredicates(napi_env env, napi_callback_info info)
|
||||
{
|
||||
LOG_DEBUG("RdbPredicatesProxy::GetNativePredicates begin.");
|
||||
RdbPredicatesProxy *predicatesProxy = nullptr;
|
||||
napi_value thiz;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
napi_unwrap(env, thiz, reinterpret_cast<void **>(&predicatesProxy));
|
||||
LOG_DEBUG("RdbPredicatesProxy::GetNativePredicates end");
|
||||
return predicatesProxy->predicates_;
|
||||
}
|
||||
|
||||
@ -200,14 +214,12 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldArrayByName(napi_env env, napi
|
||||
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
|
||||
RdbPredicatesProxy *predicatesProxy = nullptr;
|
||||
napi_unwrap(env, thiz, reinterpret_cast<void **>(&predicatesProxy));
|
||||
LOG_DEBUG("Get native predicates ok");
|
||||
RDB_NAPI_ASSERT(env, argc == 1, std::make_shared<ParamNumError>("1"));
|
||||
int version = predicatesProxy->apiversion;
|
||||
RDB_NAPI_ASSERT_FROMV9(env, argc == 1, std::make_shared<ParamNumError>("1"), version);
|
||||
|
||||
fieldarray = JSUtils::Convert2StrVector(env, args[0]);
|
||||
RDB_NAPI_ASSERT(
|
||||
env, fieldarray.size() >= 0, std::make_shared<ParamTypeError>(fieldName, "a " + fieldType + " array."));
|
||||
|
||||
LOG_DEBUG("Check field array ok");
|
||||
RDB_NAPI_ASSERT_FROMV9(env, fieldarray.size() >= 0,
|
||||
std::make_shared<ParamTypeError>(fieldName, "a " + fieldType + " array."), version);
|
||||
return predicatesProxy;
|
||||
}
|
||||
|
||||
@ -219,13 +231,12 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldByName(
|
||||
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
|
||||
RdbPredicatesProxy *predicatesProxy = nullptr;
|
||||
napi_unwrap(env, thiz, reinterpret_cast<void **>(&predicatesProxy));
|
||||
LOG_DEBUG("Get native predicates ok");
|
||||
RDB_NAPI_ASSERT(env, argc == 1, std::make_shared<ParamNumError>("1"));
|
||||
int version = predicatesProxy->apiversion;
|
||||
RDB_NAPI_ASSERT_FROMV9(env, argc == 1, std::make_shared<ParamNumError>("1"), version);
|
||||
|
||||
field = JSUtils::Convert2String(env, args[0]);
|
||||
RDB_NAPI_ASSERT(env, !field.empty(), std::make_shared<ParamTypeError>(fieldName, "a non empty string."));
|
||||
|
||||
LOG_DEBUG("Check field ok");
|
||||
RDB_NAPI_ASSERT_FROMV9(env, !field.empty(),
|
||||
std::make_shared<ParamTypeError>(fieldName, "a non empty string."), version);
|
||||
return predicatesProxy;
|
||||
}
|
||||
|
||||
@ -237,13 +248,12 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseInt32FieldByName(
|
||||
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
|
||||
RdbPredicatesProxy *predicatesProxy = nullptr;
|
||||
napi_unwrap(env, thiz, reinterpret_cast<void **>(&predicatesProxy));
|
||||
LOG_DEBUG("Get native predicates ok");
|
||||
RDB_NAPI_ASSERT(env, argc == 1, std::make_shared<ParamNumError>("1"));
|
||||
int version = predicatesProxy->apiversion;
|
||||
RDB_NAPI_ASSERT_FROMV9(env, argc == 1, std::make_shared<ParamNumError>("1"), version);
|
||||
|
||||
napi_status status = napi_get_value_int32(env, args[0], &field);
|
||||
RDB_NAPI_ASSERT(env, status == napi_ok, std::make_shared<ParamTypeError>(fieldName, "a number."));
|
||||
|
||||
LOG_DEBUG("Check int32 field ok");
|
||||
RDB_NAPI_ASSERT_FROMV9(env, status == napi_ok,
|
||||
std::make_shared<ParamTypeError>(fieldName, "a number."), version);
|
||||
return predicatesProxy;
|
||||
}
|
||||
|
||||
@ -255,17 +265,16 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldAndValueArray(napi_env env, na
|
||||
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
|
||||
RdbPredicatesProxy *predicatesProxy = nullptr;
|
||||
napi_unwrap(env, thiz, reinterpret_cast<void **>(&predicatesProxy));
|
||||
LOG_DEBUG("Get native predicates ok");
|
||||
RDB_NAPI_ASSERT(env, argc == 2, std::make_shared<ParamNumError>("2"));
|
||||
int version = predicatesProxy->apiversion;
|
||||
RDB_NAPI_ASSERT_FROMV9(env, argc == 2, std::make_shared<ParamNumError>("2"), version);
|
||||
|
||||
field = JSUtils::Convert2String(env, args[0]);
|
||||
RDB_NAPI_ASSERT(env, !field.empty(), std::make_shared<ParamTypeError>("field", "a non empty string."));
|
||||
RDB_NAPI_ASSERT_FROMV9(env, !field.empty(),
|
||||
std::make_shared<ParamTypeError>("field", "a non empty string."), version);
|
||||
|
||||
value = JSUtils::Convert2StrVector(env, args[1]);
|
||||
RDB_NAPI_ASSERT(
|
||||
env, value.size() >= 0, std::make_shared<ParamTypeError>("value", "a " + valueType + " array."));
|
||||
|
||||
LOG_DEBUG("Check field and value array ok");
|
||||
RDB_NAPI_ASSERT_FROMV9(env, value.size() >= 0,
|
||||
std::make_shared<ParamTypeError>("value", "a " + valueType + " array."), version);
|
||||
return predicatesProxy;
|
||||
}
|
||||
|
||||
@ -277,15 +286,14 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldAndValue(napi_env env, napi_ca
|
||||
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
|
||||
RdbPredicatesProxy *predicatesProxy = nullptr;
|
||||
napi_unwrap(env, thiz, reinterpret_cast<void **>(&predicatesProxy));
|
||||
LOG_DEBUG("Get native predicates ok");
|
||||
RDB_NAPI_ASSERT(env, argc == 2, std::make_shared<ParamNumError>("2"));
|
||||
int version = predicatesProxy->apiversion;
|
||||
RDB_NAPI_ASSERT_FROMV9(env, argc == 2, std::make_shared<ParamNumError>("2"), version);
|
||||
|
||||
field = JSUtils::Convert2String(env, args[0]);
|
||||
RDB_NAPI_ASSERT(env, !field.empty(), std::make_shared<ParamTypeError>("field", "a non empty string."));
|
||||
RDB_NAPI_ASSERT_FROMV9(env, !field.empty(),
|
||||
std::make_shared<ParamTypeError>("field", "a non empty string."), version);
|
||||
|
||||
value = JSUtils::ConvertAny2String(env, args[1]);
|
||||
|
||||
LOG_DEBUG("Check field and value ok");
|
||||
return predicatesProxy;
|
||||
}
|
||||
|
||||
@ -297,16 +305,20 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldLowAndHigh(
|
||||
napi_get_cb_info(env, info, &argc, args, &thiz, nullptr);
|
||||
RdbPredicatesProxy *predicatesProxy = nullptr;
|
||||
napi_unwrap(env, thiz, reinterpret_cast<void **>(&predicatesProxy));
|
||||
RDB_NAPI_ASSERT(env, argc == 3, std::make_shared<ParamNumError>("3"));
|
||||
int version = predicatesProxy->apiversion;
|
||||
RDB_NAPI_ASSERT_FROMV9(env, argc == 3, std::make_shared<ParamNumError>("3"), version);
|
||||
|
||||
field = JSUtils::Convert2String(env, args[0]);
|
||||
RDB_NAPI_ASSERT(env, !field.empty(), std::make_shared<ParamTypeError>("field", "a non empty string."));
|
||||
RDB_NAPI_ASSERT_FROMV9(env, !field.empty(),
|
||||
std::make_shared<ParamTypeError>("field", "a non empty string."), version);
|
||||
|
||||
low = JSUtils::ConvertAny2String(env, args[1]);
|
||||
RDB_NAPI_ASSERT(env, !low.empty(), std::make_shared<ParamTypeError>("low", "a non empty ValueType."));
|
||||
RDB_NAPI_ASSERT_FROMV9(env, !low.empty(),
|
||||
std::make_shared<ParamTypeError>("low", "a non empty ValueType."), version);
|
||||
|
||||
high = JSUtils::ConvertAny2String(env, args[2]);
|
||||
RDB_NAPI_ASSERT(env, !high.empty(), std::make_shared<ParamTypeError>("high", "a non empty ValueType."));
|
||||
RDB_NAPI_ASSERT_FROMV9(env, !high.empty(),
|
||||
std::make_shared<ParamTypeError>("high", "a non empty ValueType."), version);
|
||||
|
||||
LOG_DEBUG("Check field, low and high ok");
|
||||
return predicatesProxy;
|
||||
@ -314,462 +326,464 @@ RdbPredicatesProxy *RdbPredicatesProxy::ParseFieldLowAndHigh(
|
||||
|
||||
napi_value RdbPredicatesProxy::EqualTo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string value;
|
||||
LOG_DEBUG("RdbPredicatesProxy::EqualTo begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string value = "";
|
||||
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->EqualTo(field, value);
|
||||
LOG_DEBUG("RdbPredicatesProxy::EqualTo end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::NotEqualTo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string value;
|
||||
LOG_DEBUG("RdbPredicatesProxy::NotEqualTo begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string value = "";
|
||||
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->NotEqualTo(field, value);
|
||||
LOG_DEBUG("RdbPredicatesProxy::NotEqualTo end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::BeginWrap(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::BeginWrap begin.");
|
||||
napi_value thiz = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
GetNativePredicates(env, info)->BeginWrap();
|
||||
LOG_DEBUG("RdbPredicatesProxy::BeginWrap end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::EndWrap(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::EndWrap begin.");
|
||||
napi_value thiz = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
GetNativePredicates(env, info)->EndWrap();
|
||||
LOG_DEBUG("RdbPredicatesProxy::EndWrap end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::Or(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::Or begin.");
|
||||
napi_value thiz = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
GetNativePredicates(env, info)->Or();
|
||||
LOG_DEBUG("RdbPredicatesProxy::Or end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::And(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::And begin.");
|
||||
napi_value thiz = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
GetNativePredicates(env, info)->And();
|
||||
LOG_DEBUG("RdbPredicatesProxy::And end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::Contains(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string value;
|
||||
LOG_DEBUG("RdbPredicatesProxyV9::Contains begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string value = "";
|
||||
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->Contains(field, value);
|
||||
LOG_DEBUG("RdbPredicatesProxyV9::Contains end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::BeginsWith(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string value;
|
||||
LOG_DEBUG("RdbPredicatesProxy::BeginsWith begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string value = "";
|
||||
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->BeginsWith(field, value);
|
||||
LOG_DEBUG("RdbPredicatesProxy::BeginsWith end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::EndsWith(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string value;
|
||||
LOG_DEBUG("RdbPredicatesProxy::EndsWith begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string value = "";
|
||||
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->EndsWith(field, value);
|
||||
LOG_DEBUG("RdbPredicatesProxy::EndsWith end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::IsNull(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
LOG_DEBUG("RdbPredicatesProxy::IsNull begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
auto predicatesProxy = ParseFieldByName(env, info, thiz, field, "field");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->IsNull(field);
|
||||
LOG_DEBUG("RdbPredicatesProxy::IsNull end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::IsNotNull(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
LOG_DEBUG("RdbPredicatesProxy::IsNotNull begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
auto predicatesProxy = ParseFieldByName(env, info, thiz, field, "field");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->IsNotNull(field);
|
||||
LOG_DEBUG("RdbPredicatesProxy::IsNotNull end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::Like(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string value;
|
||||
LOG_DEBUG("RdbPredicatesProxy::Like begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string value = "";
|
||||
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->Like(field, value);
|
||||
LOG_DEBUG("RdbPredicatesProxy::Like end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::Glob(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string value;
|
||||
LOG_DEBUG("RdbPredicatesProxy::Glob begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string value = "";
|
||||
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->Glob(field, value);
|
||||
LOG_DEBUG("RdbPredicatesProxy::Glob end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::Between(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string low;
|
||||
std::string high;
|
||||
LOG_DEBUG("RdbPredicatesProxy::Between begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string low = "";
|
||||
std::string high = "";
|
||||
auto predicatesProxy = ParseFieldLowAndHigh(env, info, thiz, field, low, high);
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->Between(field, low, high);
|
||||
LOG_DEBUG("RdbPredicatesProxy::Between end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::NotBetween(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string low;
|
||||
std::string high;
|
||||
LOG_DEBUG("RdbPredicatesProxy::NotBetween begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string low = "";
|
||||
std::string high = "";
|
||||
auto predicatesProxy = ParseFieldLowAndHigh(env, info, thiz, field, low, high);
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->NotBetween(field, low, high);
|
||||
LOG_DEBUG("RdbPredicatesProxy::NotBetween end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::GreaterThan(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string value;
|
||||
LOG_DEBUG("RdbPredicatesProxy::GreaterThan begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string value = "";
|
||||
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->GreaterThan(field, value);
|
||||
LOG_DEBUG("RdbPredicatesProxy::GreaterThan end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::LessThan(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string value;
|
||||
LOG_DEBUG("RdbPredicatesProxy::LessThan begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string value = "";
|
||||
auto predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->LessThan(field, value);
|
||||
LOG_DEBUG("RdbPredicatesProxy::LessThan end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::GreaterThanOrEqualTo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string value;
|
||||
LOG_DEBUG("RdbPredicatesProxy::GreaterThanOrEqualTo begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string value = "";
|
||||
RdbPredicatesProxy *predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->GreaterThanOrEqualTo(field, value);
|
||||
LOG_DEBUG("RdbPredicatesProxy::GreaterThanOrEqualTo end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::LessThanOrEqualTo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
std::string value;
|
||||
LOG_DEBUG("RdbPredicatesProxy::LessThanOrEqualTo begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::string value = "";
|
||||
RdbPredicatesProxy *predicatesProxy = ParseFieldAndValue(env, info, thiz, field, value, "ValueType");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->LessThanOrEqualTo(field, value);
|
||||
LOG_DEBUG("RdbPredicatesProxy::LessThanOrEqualTo end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::OrderByAsc(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
LOG_DEBUG("RdbPredicatesProxy::OrderByAsc begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
auto predicatesProxy = ParseFieldByName(env, info, thiz, field, "field");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->OrderByAsc(field);
|
||||
LOG_DEBUG("RdbPredicatesProxy::OrderByAsc end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::OrderByDesc(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
LOG_DEBUG("RdbPredicatesProxy::OrderByDesc begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
auto predicatesProxy = ParseFieldByName(env, info, thiz, field, "field");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->OrderByDesc(field);
|
||||
LOG_DEBUG("RdbPredicatesProxy::OrderByDesc end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::Distinct(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::Distinct begin.");
|
||||
napi_value thiz = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
GetNativePredicates(env, info)->Distinct();
|
||||
LOG_DEBUG("RdbPredicatesProxy::Distinct end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::Limit(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::Limit begin.");
|
||||
napi_value thiz = nullptr;
|
||||
int32_t limit = 0;
|
||||
auto predicatesProxy = ParseInt32FieldByName(env, info, thiz, limit, "value");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->Limit(limit);
|
||||
LOG_DEBUG("RdbPredicatesProxy::Limit end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::Offset(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::Offset begin.");
|
||||
napi_value thiz = nullptr;
|
||||
int32_t offset = 0;
|
||||
auto predicatesProxy = ParseInt32FieldByName(env, info, thiz, offset, "rowOffset");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->Offset(offset);
|
||||
LOG_DEBUG("RdbPredicatesProxy::Offset end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::GroupBy(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
LOG_DEBUG("RdbPredicatesProxy::GroupBy begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::vector<std::string> fields;
|
||||
auto predicatesProxy = ParseFieldArrayByName(env, info, thiz, fields, "fields", "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->GroupBy(fields);
|
||||
LOG_DEBUG("RdbPredicatesProxy::GroupBy end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::IndexedBy(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string indexName;
|
||||
LOG_DEBUG("RdbPredicatesProxy::IndexedBy begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string indexName = "";
|
||||
auto predicatesProxy = ParseFieldByName(env, info, thiz, indexName, "fields");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->IndexedBy(indexName);
|
||||
LOG_DEBUG("RdbPredicatesProxy::IndexedBy end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::In(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
LOG_DEBUG("RdbPredicatesProxy::In begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::vector<std::string> values;
|
||||
auto predicatesProxy = ParseFieldAndValueArray(env, info, thiz, field, values, "ValueType");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->In(field, values);
|
||||
LOG_DEBUG("RdbPredicatesProxy::In end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::NotIn(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string field;
|
||||
LOG_DEBUG("RdbPredicatesProxy::NotIn begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string field = "";
|
||||
std::vector<std::string> values;
|
||||
auto predicatesProxy = ParseFieldAndValueArray(env, info, thiz, field, values, "ValueType");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->NotIn(field, values);
|
||||
LOG_DEBUG("RdbPredicatesProxy::NotIn end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::Using(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::Using begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::vector<std::string> fields;
|
||||
auto predicatesProxy = ParseFieldArrayByName(env, info, thiz, fields, "fields", "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->Using(fields);
|
||||
LOG_DEBUG("RdbPredicatesProxy::Using end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::LeftOuterJoin(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string tablename;
|
||||
LOG_DEBUG("RdbPredicatesProxy::LeftOuterJoin begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string tablename = "";
|
||||
auto predicatesProxy = ParseFieldByName(env, info, thiz, tablename, "tablename");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->LeftOuterJoin(tablename);
|
||||
LOG_DEBUG("RdbPredicatesProxy::LeftOuterJoin end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::InnerJoin(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string tablename;
|
||||
LOG_DEBUG("RdbPredicatesProxy::InnerJoin begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string tablename = "";
|
||||
auto predicatesProxy = ParseFieldByName(env, info, thiz, tablename, "tablename");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->InnerJoin(tablename);
|
||||
LOG_DEBUG("RdbPredicatesProxy::InnerJoin end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::On(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::On begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::vector<std::string> clauses;
|
||||
auto predicatesProxy = ParseFieldArrayByName(env, info, thiz, clauses, "clauses", "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->On(clauses);
|
||||
LOG_DEBUG("RdbPredicatesProxy::On end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::Clear(napi_env env, napi_callback_info info)
|
||||
{
|
||||
LOG_DEBUG("RdbPredicatesProxy::Clear begin.");
|
||||
napi_value thiz = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
GetNativePredicates(env, info)->Clear();
|
||||
LOG_DEBUG("RdbPredicatesProxy::Clear end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::CrossJoin(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
std::string tablename;
|
||||
LOG_DEBUG("RdbPredicatesProxy::CrossJoin begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::string tablename = "";
|
||||
auto predicatesProxy = ParseFieldByName(env, info, thiz, tablename, "tablename");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->CrossJoin(tablename);
|
||||
LOG_DEBUG("RdbPredicatesProxy::CrossJoin end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::GetJoinCount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
LOG_DEBUG("RdbPredicatesProxy::GetJoinCount begin.");
|
||||
napi_value thiz = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
int errCode = GetNativePredicates(env, info)->GetJoinCount();
|
||||
LOG_DEBUG("RdbPredicatesProxy::GetJoinCount end");
|
||||
return JSUtils::Convert2JSValue(env, errCode);
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::SetJoinCount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
LOG_DEBUG("RdbPredicatesProxy::SetJoinCount begin.");
|
||||
napi_value thiz;
|
||||
int32_t joinCount = 0;
|
||||
RdbPredicatesProxy *predicatesProxy = ParseInt32FieldByName(env, info, thiz, joinCount, "joinCount");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->SetJoinCount(joinCount);
|
||||
LOG_DEBUG("RdbPredicatesProxy::SetJoinCount end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::GetJoinTypes(napi_env env, napi_callback_info info)
|
||||
{
|
||||
LOG_DEBUG("RdbPredicatesProxy::GetJoinTypes begin.");
|
||||
napi_value thiz = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
auto joinTypes = GetNativePredicates(env, info)->GetJoinTypes();
|
||||
LOG_DEBUG("RdbPredicatesProxy::GetJoinTypes end");
|
||||
return JSUtils::Convert2JSValue(env, joinTypes);
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::GetJoinTableNames(napi_env env, napi_callback_info info)
|
||||
{
|
||||
LOG_DEBUG("RdbPredicatesProxy::GetJoinTableNames begin.");
|
||||
napi_value thiz = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
auto joinTableNames = GetNativePredicates(env, info)->GetJoinTableNames();
|
||||
LOG_DEBUG("RdbPredicatesProxy::GetJoinTableNames end");
|
||||
return JSUtils::Convert2JSValue(env, joinTableNames);
|
||||
;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::GetJoinConditions(napi_env env, napi_callback_info info)
|
||||
{
|
||||
LOG_DEBUG("RdbPredicatesProxy::GetJoinConditions begin.");
|
||||
napi_value thiz = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
auto joinConditions = GetNativePredicates(env, info)->GetJoinConditions();
|
||||
LOG_DEBUG("RdbPredicatesProxy::GetJoinConditions end");
|
||||
return JSUtils::Convert2JSValue(env, joinConditions);
|
||||
;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::SetJoinConditions(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::SetJoinConditions begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::vector<std::string> joinConditions;
|
||||
RdbPredicatesProxy *predicatesProxy =
|
||||
ParseFieldArrayByName(env, info, thiz, joinConditions, "joinConditions", "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->SetJoinConditions(joinConditions);
|
||||
LOG_DEBUG("RdbPredicatesProxy::SetJoinConditions end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::SetJoinTableNames(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::SetJoinTableNames begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::vector<std::string> joinNames;
|
||||
RdbPredicatesProxy *predicatesProxy = ParseFieldArrayByName(env, info, thiz, joinNames, "joinNames", "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->SetJoinTableNames(joinNames);
|
||||
LOG_DEBUG("RdbPredicatesProxy::SetJoinTableNames end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::SetJoinTypes(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::SetJoinTypes begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::vector<std::string> joinTypes;
|
||||
RdbPredicatesProxy *predicatesProxy = ParseFieldArrayByName(env, info, thiz, joinTypes, "joinTypes", "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->SetJoinTypes(joinTypes);
|
||||
LOG_DEBUG("RdbPredicatesProxy::SetJoinTypes end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
@ -781,21 +795,21 @@ std::shared_ptr<NativeRdb::RdbPredicates> RdbPredicatesProxy::GetPredicates() co
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
napi_value RdbPredicatesProxy::InDevices(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thiz;
|
||||
LOG_DEBUG("RdbPredicatesProxy::InDevices begin.");
|
||||
napi_value thiz = nullptr;
|
||||
std::vector<std::string> devices;
|
||||
RdbPredicatesProxy *predicatesProxy = ParseFieldArrayByName(env, info, thiz, devices, "devices", "string");
|
||||
RDB_CHECK_RETURN_NULLPTR(predicatesProxy != nullptr);
|
||||
predicatesProxy->predicates_->InDevices(devices);
|
||||
LOG_DEBUG("RdbPredicatesProxy::InDevices end");
|
||||
return thiz;
|
||||
}
|
||||
|
||||
napi_value RdbPredicatesProxy::InAllDevices(napi_env env, napi_callback_info info)
|
||||
{
|
||||
LOG_DEBUG("RdbPredicatesProxy::InAllDevices begin.");
|
||||
napi_value thiz = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr);
|
||||
GetNativePredicates(env, info)->InAllDevices();
|
||||
LOG_DEBUG("RdbPredicatesProxy::InAllDevices end");
|
||||
return thiz;
|
||||
}
|
||||
#endif
|
||||
|
@ -50,7 +50,7 @@ struct PredicatesProxy {
|
||||
};
|
||||
#endif
|
||||
struct RdbStoreContext : public AsyncCall::Context {
|
||||
bool isNapiString;
|
||||
bool isNapiString = false;
|
||||
int BindArgs(napi_env env, napi_value arg);
|
||||
std::string device;
|
||||
std::string tableName;
|
||||
@ -61,7 +61,7 @@ struct RdbStoreContext : public AsyncCall::Context {
|
||||
std::string sql;
|
||||
RdbPredicatesProxy *predicatesProxy;
|
||||
std::vector<std::string> columns;
|
||||
ValuesBucket *valuesBucket;
|
||||
ValuesBucket valuesBucket;
|
||||
std::vector<ValuesBucket> valuesBuckets;
|
||||
std::map<std::string, ValueObject> numberMaps;
|
||||
std::vector<ValueObject> bindArgs;
|
||||
@ -83,18 +83,12 @@ struct RdbStoreContext : public AsyncCall::Context {
|
||||
#endif
|
||||
std::shared_ptr<RdbPredicates> rdbPredicates = nullptr;
|
||||
|
||||
RdbStoreContext()
|
||||
: Context(nullptr, nullptr), predicatesProxy(nullptr), valuesBucket(nullptr), rowId(0), enumArg(0)
|
||||
RdbStoreContext() : Context(nullptr, nullptr), predicatesProxy(nullptr), rowId(0), enumArg(0)
|
||||
{
|
||||
isNapiString = false;
|
||||
valuesBucket = new ValuesBucket();
|
||||
}
|
||||
RdbStoreContext(InputAction input, OutputAction output)
|
||||
: Context(std::move(input), std::move(output)), predicatesProxy(nullptr), valuesBucket(nullptr), rowId(0),
|
||||
enumArg(0)
|
||||
: Context(std::move(input), std::move(output)), predicatesProxy(nullptr), rowId(0), enumArg(0)
|
||||
{
|
||||
isNapiString = false;
|
||||
valuesBucket = new ValuesBucket();
|
||||
}
|
||||
virtual ~RdbStoreContext()
|
||||
{
|
||||
@ -102,7 +96,6 @@ struct RdbStoreContext : public AsyncCall::Context {
|
||||
if (obj != nullptr) {
|
||||
obj->Release(_env);
|
||||
}
|
||||
delete valuesBucket;
|
||||
}
|
||||
|
||||
int operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
|
||||
@ -116,6 +109,7 @@ struct RdbStoreContext : public AsyncCall::Context {
|
||||
};
|
||||
|
||||
static __thread napi_ref constructor_ = nullptr;
|
||||
static __thread napi_ref constructorV9_ = nullptr;
|
||||
|
||||
int RdbStoreContext::BindArgs(napi_env env, napi_value arg)
|
||||
{
|
||||
@ -215,14 +209,14 @@ void RdbStoreProxy::Init(napi_env env, napi_value exports)
|
||||
sizeof(descriptors) / sizeof(napi_property_descriptor), descriptors, &cons));
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_reference(env, cons, 1, &constructor_));
|
||||
|
||||
NAPI_CALL_RETURN_VOID(env, napi_define_class(env, "RdbStoreV9", NAPI_AUTO_LENGTH, Initialize, nullptr,
|
||||
NAPI_CALL_RETURN_VOID(env, napi_define_class(env, "RdbStoreV9", NAPI_AUTO_LENGTH, InitializeV9, nullptr,
|
||||
sizeof(descriptors) / sizeof(napi_property_descriptor), descriptors, &cons));
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_reference(env, cons, 1, &constructor_));
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_reference(env, cons, 1, &constructorV9_));
|
||||
|
||||
LOG_DEBUG("Init RdbStoreProxy end");
|
||||
}
|
||||
|
||||
napi_value RdbStoreProxy::Initialize(napi_env env, napi_callback_info info)
|
||||
napi_value RdbStoreProxy::InnerInitialize(napi_env env, napi_callback_info info, int version)
|
||||
{
|
||||
napi_value self;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &self, nullptr));
|
||||
@ -235,6 +229,7 @@ napi_value RdbStoreProxy::Initialize(napi_env env, napi_callback_info info)
|
||||
delete proxy;
|
||||
};
|
||||
auto *proxy = new RdbStoreProxy();
|
||||
proxy->apiversion = version;
|
||||
napi_status status = napi_wrap(env, self, proxy, finalize, nullptr, &proxy->ref_);
|
||||
if (status != napi_ok) {
|
||||
LOG_ERROR("RdbStoreProxy::Initialize napi_wrap failed! code:%{public}d!", status);
|
||||
@ -247,10 +242,26 @@ napi_value RdbStoreProxy::Initialize(napi_env env, napi_callback_info info)
|
||||
return self;
|
||||
}
|
||||
|
||||
napi_value RdbStoreProxy::NewInstance(napi_env env, std::shared_ptr<OHOS::NativeRdb::RdbStore> value)
|
||||
napi_value RdbStoreProxy::Initialize(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return InnerInitialize(env, info, APIVERSION_V8);
|
||||
}
|
||||
|
||||
napi_value RdbStoreProxy::InitializeV9(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return InnerInitialize(env, info, APIVERSION_V9);
|
||||
}
|
||||
|
||||
napi_value RdbStoreProxy::NewInstance(napi_env env, std::shared_ptr<OHOS::NativeRdb::RdbStore> value, int version)
|
||||
{
|
||||
napi_value cons;
|
||||
napi_status status = napi_get_reference_value(env, constructor_, &cons);
|
||||
napi_status status;
|
||||
if (version > APIVERSION_V8) {
|
||||
status = napi_get_reference_value(env, constructorV9_, &cons);
|
||||
} else {
|
||||
status = napi_get_reference_value(env, constructor_, &cons);
|
||||
}
|
||||
|
||||
if (status != napi_ok) {
|
||||
LOG_ERROR("RdbStoreProxy::NewInstance get constructor failed! code:%{public}d!", status);
|
||||
return nullptr;
|
||||
@ -270,6 +281,7 @@ napi_value RdbStoreProxy::NewInstance(napi_env env, std::shared_ptr<OHOS::Native
|
||||
return instance;
|
||||
}
|
||||
proxy->rdbStore_ = std::move(value);
|
||||
proxy->apiversion = version;
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -312,7 +324,10 @@ void RdbStoreProxy::Release(napi_env env)
|
||||
|
||||
void ParserThis(const napi_env &env, const napi_value &self, std::shared_ptr<RdbStoreContext> context)
|
||||
{
|
||||
context->boundObj = RdbStoreProxy::GetNativeInstance(env, self);
|
||||
RdbStoreProxy *obj = RdbStoreProxy::GetNativeInstance(env, self);
|
||||
context->apiversion = obj->apiversion;
|
||||
context->boundObj = obj;
|
||||
LOG_DEBUG("ParserThis RdbStoreProxy is v%{public}d", obj->apiversion);
|
||||
}
|
||||
|
||||
int ParseTableName(const napi_env &env, const napi_value &arg, std::shared_ptr<RdbStoreContext> context)
|
||||
@ -356,13 +371,13 @@ int ParseTablesName(const napi_env &env, const napi_value &arg, std::shared_ptr<
|
||||
return OK;
|
||||
}
|
||||
|
||||
int ParseEnumArg(const napi_env &env, const napi_value &arg, std::shared_ptr<RdbStoreContext> context)
|
||||
int ParseSyncModeArg(const napi_env &env, const napi_value &arg, std::shared_ptr<RdbStoreContext> context)
|
||||
{
|
||||
napi_get_value_int32(env, arg, &context->enumArg);
|
||||
std::shared_ptr<Error> paramError = std::make_shared<ParamTypeError>("mode", "a SyncMode.");
|
||||
RDB_CHECK_RETURN_CALL_RESULT(context->enumArg == 0 || context->enumArg == 1, context->SetError(paramError));
|
||||
|
||||
LOG_DEBUG("ParseEnumArg end");
|
||||
LOG_DEBUG("ParseSyncModeArg end");
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -429,10 +444,7 @@ int ParseSrcName(const napi_env &env, const napi_value &arg, std::shared_ptr<Rdb
|
||||
|
||||
int ParseColumns(const napi_env &env, const napi_value &arg, std::shared_ptr<RdbStoreContext> context)
|
||||
{
|
||||
int status = JSUtils::Convert2StrVector(env, arg, context->columns);
|
||||
std::shared_ptr<Error> paramError = std::make_shared<ParamTypeError>("columns", "a string array.");
|
||||
RDB_CHECK_RETURN_CALL_RESULT(status == napi_ok, context->SetError(paramError));
|
||||
|
||||
context->columns = JSUtils::Convert2StrVector(env, arg);
|
||||
LOG_DEBUG("ParseColumns end");
|
||||
return OK;
|
||||
}
|
||||
@ -470,19 +482,13 @@ int ParsePath(const napi_env &env, const napi_value &arg, std::shared_ptr<RdbSto
|
||||
int ParseWhereArgs(const napi_env &env, const napi_value &arg, std::shared_ptr<RdbStoreContext> context)
|
||||
{
|
||||
context->whereArgs = JSUtils::Convert2StrVector(env, arg);
|
||||
std::shared_ptr<Error> paramError = std::make_shared<ParamTypeError>("whereArgs", "a non empty string.");
|
||||
RDB_CHECK_RETURN_CALL_RESULT(!context->pathName.empty(), context->SetError(paramError));
|
||||
|
||||
LOG_DEBUG("ParseWhereArgs end");
|
||||
return OK;
|
||||
}
|
||||
|
||||
int ParseSelectionArgs(const napi_env &env, const napi_value &arg, std::shared_ptr<RdbStoreContext> context)
|
||||
{
|
||||
int status = JSUtils::Convert2StrVector(env, arg, context->selectionArgs);
|
||||
std::shared_ptr<Error> paramError = std::make_shared<ParamTypeError>("bindArgs", "a ValueType array.");
|
||||
RDB_CHECK_RETURN_CALL_RESULT(status == napi_ok, context->SetError(paramError));
|
||||
|
||||
context->selectionArgs = JSUtils::Convert2StrVector(env, arg);
|
||||
LOG_DEBUG("ParseSelectionArgs end");
|
||||
return OK;
|
||||
}
|
||||
@ -521,26 +527,25 @@ int ParseValuesBucket(const napi_env &env, const napi_value &arg, std::shared_pt
|
||||
napi_typeof(env, value, &valueType);
|
||||
if (valueType == napi_string) {
|
||||
std::string valueString = JSUtils::Convert2String(env, value, false);
|
||||
context->valuesBucket->PutString(keyStr, valueString);
|
||||
context->valuesBucket.PutString(keyStr, valueString);
|
||||
LOG_DEBUG("ValueObject type napi_string");
|
||||
} else if (valueType == napi_number) {
|
||||
double valueNumber;
|
||||
napi_get_value_double(env, value, &valueNumber);
|
||||
context->valuesBucket->PutDouble(keyStr, valueNumber);
|
||||
context->valuesBucket.PutDouble(keyStr, valueNumber);
|
||||
LOG_DEBUG("ValueObject type napi_number");
|
||||
} else if (valueType == napi_boolean) {
|
||||
bool valueBool = false;
|
||||
napi_get_value_bool(env, value, &valueBool);
|
||||
context->valuesBucket->PutBool(keyStr, valueBool);
|
||||
context->valuesBucket.PutBool(keyStr, valueBool);
|
||||
LOG_DEBUG("ValueObject type napi_boolean");
|
||||
} else if (valueType == napi_null) {
|
||||
context->valuesBucket->PutNull(keyStr);
|
||||
context->valuesBucket.PutNull(keyStr);
|
||||
LOG_DEBUG("ValueObject type napi_null");
|
||||
} else if (valueType == napi_object) {
|
||||
context->valuesBucket->PutBlob(keyStr, JSUtils::Convert2U8Vector(env, value));
|
||||
context->valuesBucket.PutBlob(keyStr, JSUtils::Convert2U8Vector(env, value));
|
||||
LOG_DEBUG("ValueObject type napi_object");
|
||||
} else {
|
||||
RDB_CHECK_RETURN_CALL_RESULT(OK == OK, context->SetError(paramError));
|
||||
LOG_WARN("valuesBucket error");
|
||||
}
|
||||
}
|
||||
@ -567,8 +572,8 @@ int ParseValuesBuckets(const napi_env &env, const napi_value &arg, std::shared_p
|
||||
RDB_CHECK_RETURN_CALL_RESULT(status == napi_ok || arrLen >= 0, context->SetError(paramError));
|
||||
|
||||
ParseValuesBucket(env, obj, context);
|
||||
context->valuesBuckets.push_back(*(context->valuesBucket));
|
||||
context->valuesBucket->Clear();
|
||||
context->valuesBuckets.push_back(context->valuesBucket);
|
||||
context->valuesBucket.Clear();
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
@ -606,7 +611,7 @@ napi_value RdbStoreProxy::Insert(napi_env env, napi_callback_info info)
|
||||
RdbStoreProxy *obj = reinterpret_cast<RdbStoreProxy *>(context->boundObj);
|
||||
int64_t rowId = 0;
|
||||
LOG_DEBUG("RdbStoreProxy::Insert Async");
|
||||
int errCode = obj->rdbStore_->Insert(rowId, context->tableName, *(context->valuesBucket));
|
||||
int errCode = obj->rdbStore_->Insert(rowId, context->tableName, context->valuesBucket);
|
||||
context->rowId = rowId;
|
||||
LOG_DEBUG("RdbStoreProxy::Insert errCode is: %{public}d", errCode);
|
||||
return (errCode == E_OK) ? OK : ERR;
|
||||
@ -720,7 +725,7 @@ napi_value RdbStoreProxy::Update(napi_env env, napi_callback_info info)
|
||||
LOG_DEBUG("RdbStoreProxy::Update Async");
|
||||
RdbStoreProxy *obj = reinterpret_cast<RdbStoreProxy *>(context->boundObj);
|
||||
int changedRows = 0;
|
||||
int errCode = obj->rdbStore_->Update(changedRows, *(context->valuesBucket), *(context->rdbPredicates));
|
||||
int errCode = obj->rdbStore_->Update(changedRows, context->valuesBucket, *(context->rdbPredicates));
|
||||
context->rowId = changedRows;
|
||||
LOG_DEBUG("RdbStoreProxy::Update errCode is: %{public}d", errCode);
|
||||
return (errCode == E_OK) ? OK : ERR;
|
||||
@ -774,9 +779,11 @@ napi_value RdbStoreProxy::Query(napi_env env, napi_callback_info info)
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value &result) -> int {
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
result = ResultSetProxy::NewInstance(env, std::shared_ptr<ResultSet>(context->resultSet_value.release()));
|
||||
result = ResultSetProxy::NewInstance(
|
||||
env, std::shared_ptr<ResultSet>(context->resultSet_value.release()), context->apiversion);
|
||||
#else
|
||||
result = ResultSetProxy::NewInstance(env, std::shared_ptr<AbsSharedResultSet>(context->resultSet.release()));
|
||||
result = ResultSetProxy::NewInstance(
|
||||
env, std::shared_ptr<AbsSharedResultSet>(context->resultSet.release()), context->apiversion);
|
||||
#endif
|
||||
return (result != nullptr) ? OK : ERR;
|
||||
};
|
||||
@ -814,7 +821,7 @@ napi_value RdbStoreProxy::RemoteQuery(napi_env env, napi_callback_info info)
|
||||
LOG_DEBUG("RdbStoreProxy::RemoteQuery result is nullptr");
|
||||
return ERR;
|
||||
}
|
||||
result = ResultSetProxy::NewInstance(env, context->newResultSet);
|
||||
result = ResultSetProxy::NewInstance(env, context->newResultSet, context->apiversion);
|
||||
LOG_DEBUG("RdbStoreProxy::RemoteQuery end");
|
||||
return (result != nullptr) ? OK : ERR;
|
||||
};
|
||||
@ -827,7 +834,6 @@ napi_value RdbStoreProxy::RemoteQuery(napi_env env, napi_callback_info info)
|
||||
|
||||
napi_value RdbStoreProxy::QuerySql(napi_env env, napi_callback_info info)
|
||||
{
|
||||
LOG_DEBUG("RdbStoreProxy::QuerySql start");
|
||||
auto context = std::make_shared<RdbStoreContext>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> int {
|
||||
std::shared_ptr<Error> paramNumError = std::make_shared<ParamNumError>("1, 2 or 3");
|
||||
@ -844,7 +850,6 @@ napi_value RdbStoreProxy::QuerySql(napi_env env, napi_callback_info info)
|
||||
return OK;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
LOG_DEBUG("RdbStoreProxy::QuerySql Async");
|
||||
RdbStoreProxy *obj = reinterpret_cast<RdbStoreProxy *>(context->boundObj);
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
context->resultSet_value = obj->rdbStore_->QueryByStep(context->sql, context->columns);
|
||||
@ -864,11 +869,12 @@ napi_value RdbStoreProxy::QuerySql(napi_env env, napi_callback_info info)
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value &result) -> int {
|
||||
#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM)
|
||||
result = ResultSetProxy::NewInstance(env, std::shared_ptr<ResultSet>(context->resultSet_value.release()));
|
||||
result = ResultSetProxy::NewInstance(
|
||||
env, std::shared_ptr<ResultSet>(context->resultSet_value.release()), context->apiversion);
|
||||
#else
|
||||
result = ResultSetProxy::NewInstance(env, std::shared_ptr<AbsSharedResultSet>(context->resultSet.release()));
|
||||
result = ResultSetProxy::NewInstance(
|
||||
env, std::shared_ptr<AbsSharedResultSet>(context->resultSet.release()), context->apiversion);
|
||||
#endif
|
||||
LOG_DEBUG("RdbStoreProxy::QuerySql end");
|
||||
return (result != nullptr) ? OK : ERR;
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
@ -962,7 +968,7 @@ napi_value RdbStoreProxy::Replace(napi_env env, napi_callback_info info)
|
||||
LOG_DEBUG("RdbStoreProxy::Replace Async");
|
||||
RdbStoreProxy *obj = reinterpret_cast<RdbStoreProxy *>(context->boundObj);
|
||||
int64_t rowId = 0;
|
||||
int errCode = obj->rdbStore_->Replace(rowId, context->tableName, *(context->valuesBucket));
|
||||
int errCode = obj->rdbStore_->Replace(rowId, context->tableName, context->valuesBucket);
|
||||
context->rowId = rowId;
|
||||
LOG_DEBUG("RdbStoreProxy::Replace errCode is:%{public}d", errCode);
|
||||
return (errCode == E_OK) ? OK : ERR;
|
||||
@ -1142,7 +1148,8 @@ napi_value RdbStoreProxy::QueryByStep(napi_env env, napi_callback_info info)
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value &result) -> int {
|
||||
if (context->resultSet_value != nullptr) {
|
||||
result = ResultSetProxy::NewInstance(env, std::shared_ptr<ResultSet>(context->resultSet_value.release()));
|
||||
result = ResultSetProxy::NewInstance(
|
||||
env, std::shared_ptr<ResultSet>(context->resultSet_value.release()), context->apiversion);
|
||||
}
|
||||
LOG_DEBUG("RdbStoreProxy::QueryByStep end");
|
||||
return (result != nullptr) ? OK : ERR;
|
||||
@ -1358,7 +1365,7 @@ napi_value RdbStoreProxy::Sync(napi_env env, napi_callback_info info)
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> int {
|
||||
std::shared_ptr<Error> paramNumError = std::make_shared<ParamNumError>("2 or 3");
|
||||
RDB_CHECK_RETURN_CALL_RESULT(argc == 2 || argc == 3, context->SetError(paramNumError));
|
||||
RDB_ASYNC_PARAM_CHECK_FUNCTION(ParseEnumArg(env, argv[0], context));
|
||||
RDB_ASYNC_PARAM_CHECK_FUNCTION(ParseSyncModeArg(env, argv[0], context));
|
||||
RDB_ASYNC_PARAM_CHECK_FUNCTION(ParsePredicates(env, argv[1], context));
|
||||
ParserThis(env, self, context);
|
||||
return OK;
|
||||
@ -1482,7 +1489,7 @@ napi_value RdbStoreProxy::OnEvent(napi_env env, napi_callback_info info)
|
||||
}
|
||||
|
||||
proxy->Release(env);
|
||||
LOG_ERROR("RdbStoreProxy::OnEvent end");
|
||||
LOG_INFO("RdbStoreProxy::OnEvent end");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -1507,7 +1514,7 @@ napi_value RdbStoreProxy::OffEvent(napi_env env, napi_callback_info info)
|
||||
}
|
||||
|
||||
proxy->Release(env);
|
||||
LOG_ERROR("RdbStoreProxy::OffEvent end");
|
||||
LOG_INFO("RdbStoreProxy::OffEvent end");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
@ -34,8 +34,6 @@ using namespace OHOS::AppDataMgrJsKit;
|
||||
|
||||
namespace OHOS {
|
||||
namespace RdbJsKit {
|
||||
const int APIVERSION_V9 = 9;
|
||||
const int APIVERSION_V8 = 8;
|
||||
|
||||
class OpenCallback : public OHOS::NativeRdb::RdbOpenCallback {
|
||||
public:
|
||||
@ -472,7 +470,7 @@ napi_value InnerGetRdbStore(napi_env env, napi_callback_info info, std::shared_p
|
||||
return (errCode == E_OK) ? OK : ERR;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value &result) -> int {
|
||||
result = RdbStoreProxy::NewInstance(env, context->proxy);
|
||||
result = RdbStoreProxy::NewInstance(env, context->proxy, context->apiversion);
|
||||
context->openCallback.DelayNotify();
|
||||
LOG_DEBUG("RdbJsKit::GetRdbStore end");
|
||||
return (result != nullptr) ? OK : ERR;
|
||||
|
@ -33,11 +33,13 @@ using namespace OHOS::AppDataMgrJsKit;
|
||||
namespace OHOS {
|
||||
namespace RdbJsKit {
|
||||
static napi_ref __thread ctorRef_ = nullptr;
|
||||
static napi_ref __thread ctorRefV9_ = nullptr;
|
||||
static const int E_OK = 0;
|
||||
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM)
|
||||
napi_value ResultSetProxy::NewInstance(napi_env env, std::shared_ptr<AbsSharedResultSet> resultSet)
|
||||
napi_value ResultSetProxy::NewInstance(napi_env env, std::shared_ptr<AbsSharedResultSet> resultSet, int version)
|
||||
{
|
||||
auto instance = NewInstance(env, std::static_pointer_cast<NativeRdb::ResultSet>(resultSet));
|
||||
auto instance = NewInstance(env, std::static_pointer_cast<NativeRdb::ResultSet>(resultSet), version);
|
||||
ResultSetProxy *proxy = nullptr;
|
||||
auto status = napi_unwrap(env, instance, reinterpret_cast<void **>(&proxy));
|
||||
if (proxy == nullptr) {
|
||||
@ -54,9 +56,9 @@ napi_value ResultSetProxy::NewInstance(napi_env env, std::shared_ptr<AbsSharedRe
|
||||
}
|
||||
#endif
|
||||
|
||||
napi_value ResultSetProxy::NewInstance(napi_env env, std::shared_ptr<NativeRdb::ResultSet> resultSet)
|
||||
napi_value ResultSetProxy::NewInstance(napi_env env, std::shared_ptr<NativeRdb::ResultSet> resultSet, int version)
|
||||
{
|
||||
napi_value cons = GetConstructor(env);
|
||||
napi_value cons = GetConstructor(env, version);
|
||||
if (cons == nullptr) {
|
||||
LOG_ERROR("NewInstance GetConstructor is nullptr!");
|
||||
return nullptr;
|
||||
@ -101,10 +103,14 @@ std::shared_ptr<DataShare::ResultSetBridge> ResultSetProxy::Create()
|
||||
}
|
||||
#endif
|
||||
|
||||
napi_value ResultSetProxy::GetConstructor(napi_env env)
|
||||
napi_value ResultSetProxy::GetConstructor(napi_env env, int version)
|
||||
{
|
||||
napi_value cons;
|
||||
if (ctorRef_ != nullptr) {
|
||||
if (version > APIVERSION_V8 && ctorRefV9_ != nullptr) {
|
||||
NAPI_CALL(env, napi_get_reference_value(env, ctorRefV9_, &cons));
|
||||
return cons;
|
||||
}
|
||||
if (version == APIVERSION_V8 && ctorRef_ != nullptr) {
|
||||
NAPI_CALL(env, napi_get_reference_value(env, ctorRef_, &cons));
|
||||
return cons;
|
||||
}
|
||||
@ -139,35 +145,48 @@ napi_value ResultSetProxy::GetConstructor(napi_env env)
|
||||
DECLARE_NAPI_GETTER("isAtLastRow", IsAtLastRow),
|
||||
};
|
||||
|
||||
NAPI_CALL(env, napi_define_class(env, "ResultSetV9", NAPI_AUTO_LENGTH, Initialize, nullptr,
|
||||
if (version > APIVERSION_V8) {
|
||||
NAPI_CALL(env, napi_define_class(env, "ResultSetV9", NAPI_AUTO_LENGTH, InitializeV9, nullptr,
|
||||
sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons));
|
||||
NAPI_CALL(env, napi_create_reference(env, cons, 1, &ctorRef_));
|
||||
NAPI_CALL(env, napi_create_reference(env, cons, 1, &ctorRefV9_));
|
||||
return cons;
|
||||
}
|
||||
|
||||
NAPI_CALL(env, napi_define_class(env, "ResultSet", 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 ResultSetProxy::Initialize(napi_env env, napi_callback_info info)
|
||||
napi_value ResultSetProxy::InnerInitialize(napi_env env, napi_callback_info info, int version)
|
||||
{
|
||||
napi_value self = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &self, nullptr));
|
||||
auto *proxy = new ResultSetProxy();
|
||||
proxy->apiversion = version;
|
||||
auto finalize = [](napi_env env, void *data, void *hint) {
|
||||
ResultSetProxy *proxy = reinterpret_cast<ResultSetProxy *>(data);
|
||||
delete proxy;
|
||||
};
|
||||
napi_status status = napi_wrap(env, self, proxy, finalize, nullptr, nullptr);
|
||||
if (status != napi_ok) {
|
||||
LOG_ERROR("ResultSetProxy napi_wrap failed! code:%{public}d!", status);
|
||||
LOG_ERROR("ResultSetProxy napi_wrap failed! code:%{public}d!, version:%{public}d", status, version);
|
||||
finalize(env, proxy, nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::Initialize(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return InnerInitialize(env, info, APIVERSION_V8);
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::InitializeV9(napi_env env, napi_callback_info info)
|
||||
{
|
||||
return InnerInitialize(env, info, APIVERSION_V9);
|
||||
}
|
||||
|
||||
ResultSetProxy::~ResultSetProxy()
|
||||
{
|
||||
LOG_INFO("ResultSetProxy destructor!");
|
||||
@ -193,12 +212,14 @@ ResultSetProxy &ResultSetProxy::operator=(std::shared_ptr<ResultSet> resultSet)
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::shared_ptr<NativeRdb::ResultSet> &ResultSetProxy::GetInnerResultSet(napi_env env, napi_callback_info info)
|
||||
std::shared_ptr<NativeRdb::ResultSet> &ResultSetProxy::GetInnerResultSet(
|
||||
napi_env env, napi_callback_info info, int &version)
|
||||
{
|
||||
ResultSetProxy *resultSetProxy = nullptr;
|
||||
napi_value self = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, &self, nullptr);
|
||||
napi_unwrap(env, self, reinterpret_cast<void **>(&resultSetProxy));
|
||||
version = resultSetProxy->apiversion;
|
||||
return resultSetProxy->resultSet_;
|
||||
}
|
||||
|
||||
@ -211,14 +232,11 @@ ResultSetProxy *ResultSetProxy::ParseInt32FieldByName(
|
||||
napi_get_cb_info(env, info, &argc, args, &self, nullptr);
|
||||
ResultSetProxy *resultSetProxy = nullptr;
|
||||
napi_unwrap(env, self, reinterpret_cast<void **>(&resultSetProxy));
|
||||
LOG_DEBUG("Get native predicates ok");
|
||||
|
||||
RDB_NAPI_ASSERT(env, argc == 1, std::make_shared<ParamNumError>("1"));
|
||||
int version = resultSetProxy->apiversion;
|
||||
RDB_NAPI_ASSERT_FROMV9(env, argc == 1, std::make_shared<ParamNumError>("1"), version);
|
||||
|
||||
napi_status status = napi_get_value_int32(env, args[0], &field);
|
||||
RDB_NAPI_ASSERT(env, status == napi_ok, std::make_shared<ParamTypeError>(name, "a number."));
|
||||
|
||||
LOG_DEBUG("Check int32 field ok");
|
||||
RDB_NAPI_ASSERT_FROMV9(env, status == napi_ok, std::make_shared<ParamTypeError>(name, "a number."), version);
|
||||
return resultSetProxy;
|
||||
}
|
||||
|
||||
@ -231,22 +249,21 @@ ResultSetProxy *ResultSetProxy::ParseFieldByName(
|
||||
napi_get_cb_info(env, info, &argc, args, &self, nullptr);
|
||||
ResultSetProxy *resultSetProxy = nullptr;
|
||||
napi_unwrap(env, self, reinterpret_cast<void **>(&resultSetProxy));
|
||||
LOG_DEBUG("Get native predicates ok");
|
||||
RDB_NAPI_ASSERT(env, argc == 1, std::make_shared<ParamNumError>("1"));
|
||||
int version = resultSetProxy->apiversion;
|
||||
RDB_NAPI_ASSERT_FROMV9(env, argc == 1, std::make_shared<ParamNumError>("1"), version);
|
||||
|
||||
field = JSUtils::Convert2String(env, args[0]);
|
||||
RDB_NAPI_ASSERT(env, !field.empty(), std::make_shared<ParamTypeError>(name, "a non empty string."));
|
||||
|
||||
LOG_DEBUG("Check field ok");
|
||||
RDB_NAPI_ASSERT_FROMV9(env, !field.empty(), std::make_shared<ParamTypeError>(name, "a non empty string."), version);
|
||||
return resultSetProxy;
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::GetAllColumnNames(napi_env env, napi_callback_info info)
|
||||
{
|
||||
std::vector<std::string> colNames;
|
||||
int errCode = GetInnerResultSet(env, info)->GetAllColumnNames(colNames);
|
||||
int version = 0;
|
||||
int errCode = GetInnerResultSet(env, info, version)->GetAllColumnNames(colNames);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("GetAllColumnNames failed code:%{public}d", errCode);
|
||||
LOG_ERROR("GetAllColumnNames failed code:%{public}d, version:%{public}d", errCode, version);
|
||||
}
|
||||
return JSUtils::Convert2JSValue(env, colNames);
|
||||
}
|
||||
@ -255,7 +272,8 @@ napi_value ResultSetProxy::GoToRow(napi_env env, napi_callback_info info)
|
||||
{
|
||||
int32_t position;
|
||||
auto resultSetProxy = ParseInt32FieldByName(env, info, position, "position");
|
||||
RDB_NAPI_ASSERT(env, resultSetProxy != nullptr, std::make_shared<ResultGotoError>());
|
||||
RDB_NAPI_ASSERT_FROMV9(
|
||||
env, resultSetProxy != nullptr, std::make_shared<ResultGotoError>(), resultSetProxy->apiversion);
|
||||
int errCode = resultSetProxy->resultSet_->GoToRow(position);
|
||||
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
|
||||
}
|
||||
@ -263,9 +281,10 @@ napi_value ResultSetProxy::GoToRow(napi_env env, napi_callback_info info)
|
||||
napi_value ResultSetProxy::GetColumnCount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
int32_t count = 0;
|
||||
int errCode = GetInnerResultSet(env, info)->GetColumnCount(count);
|
||||
int version = 0;
|
||||
int errCode = GetInnerResultSet(env, info, version)->GetColumnCount(count);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("GetColumnCount failed code:%{public}d", errCode);
|
||||
LOG_ERROR("GetColumnCount failed code:%{public}d, version:%{public}d", errCode, version);
|
||||
}
|
||||
return JSUtils::Convert2JSValue(env, count);
|
||||
}
|
||||
@ -277,7 +296,9 @@ napi_value ResultSetProxy::GetLong(napi_env env, napi_callback_info info)
|
||||
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
|
||||
RDB_CHECK_RETURN_NULLPTR(resultSetProxy != nullptr);
|
||||
int errCode = resultSetProxy->resultSet_->GetLong(columnIndex, result);
|
||||
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<ResultGetError>());
|
||||
int version = resultSetProxy->apiversion;
|
||||
LOG_INFO("GetLong code:%{public}d, version:%{public}d", errCode, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared<ResultGetError>(), version);
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
|
||||
@ -288,7 +309,9 @@ napi_value ResultSetProxy::GetColumnType(napi_env env, napi_callback_info info)
|
||||
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
|
||||
RDB_CHECK_RETURN_NULLPTR(resultSetProxy != nullptr);
|
||||
int errCode = resultSetProxy->resultSet_->GetColumnType(columnIndex, columnType);
|
||||
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<ResultGetError>());
|
||||
int version = resultSetProxy->apiversion;
|
||||
LOG_INFO("GetColumnType code:%{public}d, version:%{public}d", errCode, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared<ResultGetError>(), version);
|
||||
return JSUtils::Convert2JSValue(env, int32_t(columnType));
|
||||
}
|
||||
|
||||
@ -296,7 +319,8 @@ napi_value ResultSetProxy::GoTo(napi_env env, napi_callback_info info)
|
||||
{
|
||||
int32_t offset;
|
||||
auto resultSetProxy = ParseInt32FieldByName(env, info, offset, "offset");
|
||||
RDB_NAPI_ASSERT(env, resultSetProxy != nullptr, std::make_shared<ResultGotoError>());
|
||||
RDB_NAPI_ASSERT_FROMV9(
|
||||
env, resultSetProxy != nullptr, std::make_shared<ResultGotoError>(), resultSetProxy->apiversion);
|
||||
int errCode = resultSetProxy->resultSet_->GoTo(offset);
|
||||
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
|
||||
}
|
||||
@ -309,7 +333,7 @@ napi_value ResultSetProxy::GetColumnIndex(napi_env env, napi_callback_info info)
|
||||
RDB_CHECK_RETURN_NULLPTR(resultSetProxy != nullptr);
|
||||
int errCode = resultSetProxy->resultSet_->GetColumnIndex(input, result);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("GetColumnIndex failed code:%{public}d", errCode);
|
||||
LOG_ERROR("GetColumnIndex failed code:%{public}d, version:%{public}d", errCode, resultSetProxy->apiversion);
|
||||
}
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
@ -321,7 +345,9 @@ napi_value ResultSetProxy::GetInt(napi_env env, napi_callback_info info)
|
||||
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
|
||||
RDB_CHECK_RETURN_NULLPTR(resultSetProxy != nullptr);
|
||||
int errCode = resultSetProxy->resultSet_->GetInt(columnIndex, result);
|
||||
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<ResultGetError>());
|
||||
int version = resultSetProxy->apiversion;
|
||||
LOG_INFO("GetInt code:%{public}d, version:%{public}d", errCode, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared<ResultGetError>(), version);
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
|
||||
@ -333,17 +359,18 @@ napi_value ResultSetProxy::GetColumnName(napi_env env, napi_callback_info info)
|
||||
RDB_CHECK_RETURN_NULLPTR(resultSetProxy != nullptr);
|
||||
int errCode = resultSetProxy->resultSet_->GetColumnName(columnIndex, result);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("GetColumnName failed code:%{public}d", errCode);
|
||||
LOG_ERROR("GetColumnName failed code:%{public}d, version:%{public}d", errCode, resultSetProxy->apiversion);
|
||||
}
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::Close(napi_env env, napi_callback_info info)
|
||||
{
|
||||
auto resultSet = GetInnerResultSet(env, info);
|
||||
RDB_NAPI_ASSERT(env, resultSet != nullptr, std::make_shared<ResultGotoError>());
|
||||
int version;
|
||||
auto resultSet = GetInnerResultSet(env, info, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, resultSet != nullptr, std::make_shared<ResultGotoError>(), version);
|
||||
int errCode = resultSet->Close();
|
||||
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<ResultGetError>());
|
||||
RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared<ResultGotoError>(), version);
|
||||
napi_value result = nullptr;
|
||||
napi_get_null(env, &result);
|
||||
return result;
|
||||
@ -351,92 +378,102 @@ napi_value ResultSetProxy::Close(napi_env env, napi_callback_info info)
|
||||
|
||||
napi_value ResultSetProxy::GetRowCount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
int version;
|
||||
int32_t result;
|
||||
int errCode = GetInnerResultSet(env, info)->GetRowCount(result);
|
||||
int errCode = GetInnerResultSet(env, info, version)->GetRowCount(result);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("GetRowCount failed code:%{public}d", errCode);
|
||||
LOG_ERROR("GetRowCount failed code:%{public}d, version:%{public}d", errCode, version);
|
||||
}
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::GetRowIndex(napi_env env, napi_callback_info info)
|
||||
{
|
||||
int version;
|
||||
int32_t result;
|
||||
int errCode = GetInnerResultSet(env, info)->GetRowIndex(result);
|
||||
int errCode = GetInnerResultSet(env, info, version)->GetRowIndex(result);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("GetRowIndex failed code:%{public}d", errCode);
|
||||
LOG_ERROR("GetRowIndex failed code:%{public}d, version:%{public}d", errCode, version);
|
||||
}
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::IsEnded(napi_env env, napi_callback_info info)
|
||||
{
|
||||
int version;
|
||||
bool result = false;
|
||||
int errCode = GetInnerResultSet(env, info)->IsEnded(result);
|
||||
int errCode = GetInnerResultSet(env, info, version)->IsEnded(result);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("IsEnded failed code:%{public}d", errCode);
|
||||
LOG_ERROR("IsEnded failed code:%{public}d, version:%{public}d", errCode, version);
|
||||
}
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::IsBegin(napi_env env, napi_callback_info info)
|
||||
{
|
||||
int version;
|
||||
bool result = false;
|
||||
int errCode = GetInnerResultSet(env, info)->IsStarted(result);
|
||||
int errCode = GetInnerResultSet(env, info, version)->IsStarted(result);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("IsBegin failed code:%{public}d", errCode);
|
||||
LOG_ERROR("IsBegin failed code:%{public}d, version:%{public}d", errCode, version);
|
||||
}
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::GoToFirstRow(napi_env env, napi_callback_info info)
|
||||
{
|
||||
auto resultSet = GetInnerResultSet(env, info);
|
||||
RDB_NAPI_ASSERT(env, resultSet != nullptr, std::make_shared<ResultGotoError>());
|
||||
int version;
|
||||
auto resultSet = GetInnerResultSet(env, info, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, resultSet != nullptr, std::make_shared<ResultGotoError>(), version);
|
||||
int errCode = resultSet->GoToFirstRow();
|
||||
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::GoToLastRow(napi_env env, napi_callback_info info)
|
||||
{
|
||||
auto resultSet = GetInnerResultSet(env, info);
|
||||
RDB_NAPI_ASSERT(env, resultSet != nullptr, std::make_shared<ResultGotoError>());
|
||||
int version;
|
||||
auto resultSet = GetInnerResultSet(env, info, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, resultSet != nullptr, std::make_shared<ResultGotoError>(), version);
|
||||
int errCode = resultSet->GoToLastRow();
|
||||
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::GoToNextRow(napi_env env, napi_callback_info info)
|
||||
{
|
||||
auto resultSet = GetInnerResultSet(env, info);
|
||||
RDB_NAPI_ASSERT(env, resultSet != nullptr, std::make_shared<ResultGotoError>());
|
||||
int version;
|
||||
auto resultSet = GetInnerResultSet(env, info, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, resultSet != nullptr, std::make_shared<ResultGotoError>(), version);
|
||||
int errCode = resultSet->GoToNextRow();
|
||||
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::GoToPreviousRow(napi_env env, napi_callback_info info)
|
||||
{
|
||||
auto resultSet = GetInnerResultSet(env, info);
|
||||
RDB_NAPI_ASSERT(env, resultSet != nullptr, std::make_shared<ResultGotoError>());
|
||||
int version;
|
||||
auto resultSet = GetInnerResultSet(env, info, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, resultSet != nullptr, std::make_shared<ResultGotoError>(), version);
|
||||
int errCode = resultSet->GoToPreviousRow();
|
||||
return JSUtils::Convert2JSValue(env, (errCode == E_OK));
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::IsAtFirstRow(napi_env env, napi_callback_info info)
|
||||
{
|
||||
int version;
|
||||
bool result = false;
|
||||
int errCode = GetInnerResultSet(env, info)->IsAtFirstRow(result);
|
||||
int errCode = GetInnerResultSet(env, info, version)->IsAtFirstRow(result);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("IsAtFirstRow failed code:%{public}d", errCode);
|
||||
LOG_ERROR("IsAtFirstRow failed code:%{public}d, version:%{public}d", errCode, version);
|
||||
}
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
|
||||
napi_value ResultSetProxy::IsAtLastRow(napi_env env, napi_callback_info info)
|
||||
{
|
||||
int version;
|
||||
bool result = false;
|
||||
int errCode = GetInnerResultSet(env, info)->IsAtLastRow(result);
|
||||
int errCode = GetInnerResultSet(env, info, version)->IsAtLastRow(result);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("IsAtLastRow failed code:%{public}d", errCode);
|
||||
LOG_ERROR("IsAtLastRow failed code:%{public}d, version:%{public}d", errCode, version);
|
||||
}
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
@ -448,7 +485,9 @@ napi_value ResultSetProxy::GetBlob(napi_env env, napi_callback_info info)
|
||||
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
|
||||
RDB_CHECK_RETURN_NULLPTR(resultSetProxy != nullptr);
|
||||
int errCode = resultSetProxy->resultSet_->GetBlob(columnIndex, result);
|
||||
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<ResultGetError>());
|
||||
int version = resultSetProxy->apiversion;
|
||||
LOG_INFO("GetBlob code:%{public}d, version:%{public}d", errCode, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared<ResultGetError>(), version);
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
|
||||
@ -459,7 +498,9 @@ napi_value ResultSetProxy::GetString(napi_env env, napi_callback_info info)
|
||||
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
|
||||
RDB_CHECK_RETURN_NULLPTR(resultSetProxy != nullptr);
|
||||
int errCode = resultSetProxy->resultSet_->GetString(columnIndex, result);
|
||||
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<ResultGetError>());
|
||||
int version = resultSetProxy->apiversion;
|
||||
LOG_INFO("GetString code:%{public}d, version:%{public}d", errCode, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared<ResultGetError>(), version);
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
|
||||
@ -470,7 +511,9 @@ napi_value ResultSetProxy::GetDouble(napi_env env, napi_callback_info info)
|
||||
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
|
||||
RDB_CHECK_RETURN_NULLPTR(resultSetProxy != nullptr);
|
||||
int errCode = resultSetProxy->resultSet_->GetDouble(columnIndex, result);
|
||||
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<ResultGetError>());
|
||||
int version = resultSetProxy->apiversion;
|
||||
LOG_INFO("GetDouble code:%{public}d, version:%{public}d", errCode, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared<ResultGetError>(), version);
|
||||
return JSUtils::Convert2JSValue(env, result);
|
||||
}
|
||||
|
||||
@ -481,7 +524,9 @@ napi_value ResultSetProxy::IsColumnNull(napi_env env, napi_callback_info info)
|
||||
auto resultSetProxy = ParseInt32FieldByName(env, info, columnIndex, "columnIndex");
|
||||
RDB_CHECK_RETURN_NULLPTR(resultSetProxy != nullptr);
|
||||
int errCode = resultSetProxy->resultSet_->IsColumnNull(columnIndex, result);
|
||||
RDB_NAPI_ASSERT(env, errCode == E_OK, std::make_shared<ResultGetError>());
|
||||
int version = resultSetProxy->apiversion;
|
||||
LOG_INFO("IsColumnNull code:%{public}d, version:%{public}d", errCode, version);
|
||||
RDB_NAPI_ASSERT_FROMV9(env, errCode == E_OK, std::make_shared<ResultGetError>(), version);
|
||||
napi_value output;
|
||||
napi_get_boolean(env, result, &output);
|
||||
return output;
|
||||
@ -489,7 +534,8 @@ napi_value ResultSetProxy::IsColumnNull(napi_env env, napi_callback_info info)
|
||||
|
||||
napi_value ResultSetProxy::IsClosed(napi_env env, napi_callback_info info)
|
||||
{
|
||||
int result = GetInnerResultSet(env, info)->IsClosed();
|
||||
int version;
|
||||
int result = GetInnerResultSet(env, info, version)->IsClosed();
|
||||
napi_value output;
|
||||
napi_get_boolean(env, result, &output);
|
||||
return output;
|
||||
|
@ -1563,12 +1563,8 @@ describe('rdbResultSetTest', function () {
|
||||
{
|
||||
let predicates = await new dataRdb.RdbPredicates("test")
|
||||
let resultSet = await rdbStore.query(predicates)
|
||||
try {
|
||||
resultSet.goToRow(5)
|
||||
expect(false).assertEqual(resultSet.isColumnNull(1));
|
||||
} catch (err) {
|
||||
console.info("catch err: goToRow failed, err: code=" + err.code + " message=" + err.message)
|
||||
}
|
||||
resultSet = null;
|
||||
done();
|
||||
console.log(TAG + "************* testIsColumnNull0003 end *************");
|
||||
|
@ -2199,6 +2199,7 @@ describe('rdbPredicatesTest', function () {
|
||||
result = null
|
||||
} catch (err) {
|
||||
console.log("catch err: failed, err: code=" + err.code + " message=" + err.message)
|
||||
expect("401").assertEqual(err.code)
|
||||
}
|
||||
done();
|
||||
console.log(TAG + "************* testIndexedBy0002 end *************");
|
||||
|
@ -95,14 +95,15 @@ describe('V9_rdbStoreCallBackTest', async function () {
|
||||
}
|
||||
console.log("Delete RdbStore successfully.")
|
||||
done()
|
||||
console.log(TAG + "************* testV9RdbStoreCallBackTest0001 end *************")
|
||||
});
|
||||
})
|
||||
} catch(err) {
|
||||
console.log("catch err: Get RdbStore failed, err: code=" + err.code + " message=" + err.message)
|
||||
expect(false).assertTrue()
|
||||
}
|
||||
done()
|
||||
console.log(TAG + "************* testV9RdbStoreCallBackTest0001 end *************")
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
|
@ -95,8 +95,9 @@ describe('V9_rdbStorePromiseTest', function () {
|
||||
} catch(err) {
|
||||
console.info("catch err: Get RdbStore failed, err: code=" + err.code + " message=" + err.message)
|
||||
expect(null).assertFail()
|
||||
}
|
||||
done()
|
||||
console.log(TAG + "************* testV9RdbStorePromiseTest0001 end *************");
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user