• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "napi_result_set.h"
17 
18 #include <functional>
19 
20 #include "abs_shared_result_set.h"
21 #include "js_logger.h"
22 #include "js_utils.h"
23 #include "napi_async_proxy.h"
24 #include "string_ex.h"
25 
26 using namespace OHOS::NativeRdb;
27 using namespace OHOS::AppDataMgrJsKit;
28 
29 namespace OHOS {
30 namespace RdbJsKit {
31 static napi_ref __thread ctorRef_ = nullptr;
32 static const int E_OK = 0;
NewInstance(napi_env env,std::shared_ptr<AbsSharedResultSet> resultSet)33 napi_value ResultSetProxy::NewInstance(napi_env env, std::shared_ptr<AbsSharedResultSet> resultSet)
34 {
35     napi_value cons = GetConstructor(env);
36     if (cons == nullptr) {
37         LOG_ERROR("NewInstance GetConstructor is nullptr!");
38         return nullptr;
39     }
40     napi_value instance;
41     napi_status status = napi_new_instance(env, cons, 0, nullptr, &instance);
42     if (status != napi_ok) {
43         LOG_ERROR("NewInstance napi_new_instance failed! code:%{public}d!", status);
44         return nullptr;
45     }
46 
47     ResultSetProxy *proxy = nullptr;
48     status = napi_unwrap(env, instance, reinterpret_cast<void **>(&proxy));
49     if (proxy == nullptr) {
50         LOG_ERROR("NewInstance native instance is nullptr! code:%{public}d!", status);
51         return instance;
52     }
53 
54     if (resultSet->GetBlock() != nullptr) {
55         proxy->sharedBlockName_ = resultSet->GetBlock()->Name();
56         proxy->sharedBlockAshmemFd_ = resultSet->GetBlock()->GetFd();
57     }
58     *proxy = std::move(resultSet);
59     return instance;
60 }
61 
GetNativeObject(napi_env const & env,napi_value const & arg)62 std::shared_ptr<NativeRdb::AbsSharedResultSet> ResultSetProxy::GetNativeObject(
63     napi_env const &env, napi_value const &arg)
64 {
65     if (arg == nullptr) {
66         LOG_ERROR("ResultSetProxy GetNativeObject arg is null.");
67         return nullptr;
68     }
69     ResultSetProxy *proxy = nullptr;
70     napi_unwrap(env, arg, reinterpret_cast<void **>(&proxy));
71     if (proxy == nullptr) {
72         LOG_ERROR("ResultSetProxy GetNativeObject proxy is null.");
73         return nullptr;
74     }
75     return proxy->resultSet_;
76 }
77 
GetConstructor(napi_env env)78 napi_value ResultSetProxy::GetConstructor(napi_env env)
79 {
80     napi_value cons;
81     if (ctorRef_ != nullptr) {
82         NAPI_CALL(env, napi_get_reference_value(env, ctorRef_, &cons));
83         return cons;
84     }
85     LOG_INFO("GetConstructor result set constructor");
86     napi_property_descriptor clzDes[] = {
87         DECLARE_NAPI_FUNCTION("goToRow", GoToRow),
88         DECLARE_NAPI_FUNCTION("getLong", GetLong),
89         DECLARE_NAPI_FUNCTION("getColumnType", GetColumnType),
90         DECLARE_NAPI_FUNCTION("goTo", GoTo),
91         DECLARE_NAPI_FUNCTION("getColumnIndex", GetColumnIndex),
92         DECLARE_NAPI_FUNCTION("getInt", GetInt),
93         DECLARE_NAPI_FUNCTION("getColumnName", GetColumnName),
94         DECLARE_NAPI_FUNCTION("close", Close),
95         DECLARE_NAPI_FUNCTION("goToFirstRow", GoToFirstRow),
96         DECLARE_NAPI_FUNCTION("goToLastRow", GoToLastRow),
97         DECLARE_NAPI_FUNCTION("goToNextRow", GoToNextRow),
98         DECLARE_NAPI_FUNCTION("goToPreviousRow", GoToPreviousRow),
99         DECLARE_NAPI_FUNCTION("getBlob", GetBlob),
100         DECLARE_NAPI_FUNCTION("getString", GetString),
101         DECLARE_NAPI_FUNCTION("getDouble", GetDouble),
102         DECLARE_NAPI_FUNCTION("isColumnNull", IsColumnNull),
103 
104         DECLARE_NAPI_GETTER("columnNames", GetAllColumnNames),
105         DECLARE_NAPI_GETTER("columnCount", GetColumnCount),
106         DECLARE_NAPI_GETTER("isEnded", IsEnded),
107         DECLARE_NAPI_GETTER("isStarted", IsBegin),
108         DECLARE_NAPI_GETTER("isClosed", IsClosed),
109         DECLARE_NAPI_GETTER("rowCount", GetRowCount),
110         DECLARE_NAPI_GETTER("rowIndex", GetRowIndex),
111         DECLARE_NAPI_GETTER("isAtFirstRow", IsAtFirstRow),
112         DECLARE_NAPI_GETTER("isAtLastRow", IsAtLastRow),
113 
114         DECLARE_NAPI_GETTER("sharedBlockName", GetSharedBlockName),
115         DECLARE_NAPI_GETTER("sharedBlockAshmemFd", GetSharedBlockAshmemFd),
116     };
117     NAPI_CALL(env, napi_define_class(env, "ResultSet", NAPI_AUTO_LENGTH, Initialize, nullptr,
118         sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons));
119     NAPI_CALL(env, napi_create_reference(env, cons, 1, &ctorRef_));
120     return cons;
121 }
122 
Initialize(napi_env env,napi_callback_info info)123 napi_value ResultSetProxy::Initialize(napi_env env, napi_callback_info info)
124 {
125     napi_value self = nullptr;
126     NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &self, nullptr));
127     auto *proxy = new ResultSetProxy();
128     auto finalize = [](napi_env env, void *data, void *hint) {
129         ResultSetProxy *proxy = reinterpret_cast<ResultSetProxy *>(data);
130         delete proxy;
131     };
132     napi_status status = napi_wrap(env, self, proxy, finalize, nullptr, nullptr);
133     if (status != napi_ok) {
134         LOG_ERROR("ResultSetProxy napi_wrap failed! code:%{public}d!", status);
135         finalize(env, proxy, nullptr);
136         return nullptr;
137     }
138     return self;
139 }
140 
~ResultSetProxy()141 ResultSetProxy::~ResultSetProxy()
142 {
143     LOG_INFO("ResultSetProxy destructor!");
144     if (resultSet_ != nullptr && !resultSet_->IsClosed()) {
145         resultSet_->Close();
146     }
147 }
148 
ResultSetProxy(std::shared_ptr<AbsSharedResultSet> resultSet)149 ResultSetProxy::ResultSetProxy(std::shared_ptr<AbsSharedResultSet> resultSet)
150 {
151     if (resultSet_ == resultSet) {
152         return;
153     }
154     resultSet_ = std::move(resultSet);
155 }
156 
operator =(std::shared_ptr<AbsSharedResultSet> resultSet)157 ResultSetProxy &ResultSetProxy::operator=(std::shared_ptr<AbsSharedResultSet> resultSet)
158 {
159     if (resultSet_ == resultSet) {
160         return *this;
161     }
162     resultSet_ = std::move(resultSet);
163     return *this;
164 }
165 
GetInnerResultSet(napi_env env,napi_callback_info info)166 std::shared_ptr<NativeRdb::AbsSharedResultSet> &ResultSetProxy::GetInnerResultSet(napi_env env, napi_callback_info info)
167 {
168     ResultSetProxy *resultSet = nullptr;
169     napi_value self = nullptr;
170     napi_get_cb_info(env, info, nullptr, nullptr, &self, nullptr);
171     napi_unwrap(env, self, reinterpret_cast<void **>(&resultSet));
172     return resultSet->resultSet_;
173 }
174 
GetAllColumnNames(napi_env env,napi_callback_info info)175 napi_value ResultSetProxy::GetAllColumnNames(napi_env env, napi_callback_info info)
176 {
177     std::vector<std::string> colNames;
178     int errCode = GetInnerResultSet(env, info)->GetAllColumnNames(colNames);
179     if (errCode != E_OK) {
180         LOG_ERROR("GetAllColumnNames failed code:%{public}d", errCode);
181     }
182     return JSUtils::Convert2JSValue(env, colNames);
183 }
184 
GoToRow(napi_env env,napi_callback_info info)185 napi_value ResultSetProxy::GoToRow(napi_env env, napi_callback_info info)
186 {
187     int32_t position;
188     size_t argc = MAX_INPUT_COUNT;
189     napi_value args[MAX_INPUT_COUNT] = { 0 };
190     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
191     NAPI_ASSERT(env, argc > 0, "Invalid argvs!");
192     NAPI_CALL(env, napi_get_value_int32(env, args[0], &position));
193     int errCode = GetInnerResultSet(env, info)->GoToRow(position);
194     if (errCode != E_OK) {
195         LOG_ERROR("GoToRow failed code:%{public}d", errCode);
196     }
197     napi_value output;
198     napi_get_undefined(env, &output);
199     return output;
200 }
201 
GetColumnCount(napi_env env,napi_callback_info info)202 napi_value ResultSetProxy::GetColumnCount(napi_env env, napi_callback_info info)
203 {
204     int32_t count = 0;
205     int errCode = GetInnerResultSet(env, info)->GetColumnCount(count);
206     if (errCode != E_OK) {
207         LOG_ERROR("GetColumnCount failed code:%{public}d", errCode);
208     }
209     return JSUtils::Convert2JSValue(env, count);
210 }
211 
GetLong(napi_env env,napi_callback_info info)212 napi_value ResultSetProxy::GetLong(napi_env env, napi_callback_info info)
213 {
214     int32_t columnIndex;
215     int64_t result;
216     size_t argc = MAX_INPUT_COUNT;
217     napi_value args[MAX_INPUT_COUNT] = { 0 };
218     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
219     NAPI_ASSERT(env, argc > 0, "Invalid argvs!");
220     NAPI_CALL(env, napi_get_value_int32(env, args[0], &columnIndex));
221     int errCode = GetInnerResultSet(env, info)->GetLong(columnIndex, result);
222     if (errCode != E_OK) {
223         LOG_ERROR("GetLong failed code:%{public}d", errCode);
224     }
225     return JSUtils::Convert2JSValue(env, result);
226 }
227 
GetColumnType(napi_env env,napi_callback_info info)228 napi_value ResultSetProxy::GetColumnType(napi_env env, napi_callback_info info)
229 {
230     int32_t columnIndex;
231     ColumnType columnType;
232     size_t argc = MAX_INPUT_COUNT;
233     napi_value args[MAX_INPUT_COUNT] = { 0 };
234     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
235     NAPI_ASSERT(env, argc > 0, "Invalid argvs!");
236     NAPI_CALL(env, napi_get_value_int32(env, args[0], &columnIndex));
237     int errCode = GetInnerResultSet(env, info)->GetColumnType(columnIndex, columnType);
238     if (errCode != E_OK) {
239         LOG_ERROR("GetColumnType failed code:%{public}d", errCode);
240     }
241     return JSUtils::Convert2JSValue(env, int32_t(columnType));
242 }
243 
GoTo(napi_env env,napi_callback_info info)244 napi_value ResultSetProxy::GoTo(napi_env env, napi_callback_info info)
245 {
246     int32_t columnIndex;
247     size_t argc = MAX_INPUT_COUNT;
248     napi_value args[MAX_INPUT_COUNT] = { 0 };
249     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
250     NAPI_ASSERT(env, argc > 0, "Invalid argvs!");
251     NAPI_CALL(env, napi_get_value_int32(env, args[0], &columnIndex));
252     int errCode = GetInnerResultSet(env, info)->GoTo(columnIndex);
253     if (errCode != E_OK) {
254         LOG_ERROR("GoTo failed code:%{public}d", errCode);
255     }
256     napi_value output;
257     napi_get_undefined(env, &output);
258     return output;
259 }
260 
GetColumnIndex(napi_env env,napi_callback_info info)261 napi_value ResultSetProxy::GetColumnIndex(napi_env env, napi_callback_info info)
262 {
263     int32_t result = -1;
264     size_t argc = MAX_INPUT_COUNT;
265     napi_value args[MAX_INPUT_COUNT] = { 0 };
266     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
267     NAPI_ASSERT(env, argc > 0, "Invalid argvs!");
268     std::string input = JSUtils::Convert2String(env, args[0]);
269     int errCode = GetInnerResultSet(env, info)->GetColumnIndex(input, result);
270     if (errCode != E_OK) {
271         LOG_ERROR("GetColumnIndex failed code:%{public}d", errCode);
272     }
273     return JSUtils::Convert2JSValue(env, result);
274 }
275 
GetInt(napi_env env,napi_callback_info info)276 napi_value ResultSetProxy::GetInt(napi_env env, napi_callback_info info)
277 {
278     int32_t columnIndex;
279     int32_t result;
280     size_t argc = MAX_INPUT_COUNT;
281     napi_value args[MAX_INPUT_COUNT] = { 0 };
282     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
283     NAPI_ASSERT(env, argc > 0, "Invalid argvs!");
284     NAPI_CALL(env, napi_get_value_int32(env, args[0], &columnIndex));
285     int errCode = GetInnerResultSet(env, info)->GetInt(columnIndex, result);
286     if (errCode != E_OK) {
287         LOG_ERROR("GetInt failed code:%{public}d", errCode);
288     }
289     return JSUtils::Convert2JSValue(env, result);
290 }
291 
GetColumnName(napi_env env,napi_callback_info info)292 napi_value ResultSetProxy::GetColumnName(napi_env env, napi_callback_info info)
293 {
294     int32_t columnIndex;
295     std::string result;
296     size_t argc = MAX_INPUT_COUNT;
297     napi_value args[MAX_INPUT_COUNT] = { 0 };
298     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
299     NAPI_ASSERT(env, argc > 0, "Invalid argvs!");
300     NAPI_CALL(env, napi_get_value_int32(env, args[0], &columnIndex));
301     int errCode = GetInnerResultSet(env, info)->GetColumnName(columnIndex, result);
302     if (errCode != E_OK) {
303         LOG_ERROR("GetColumnName failed code:%{public}d", errCode);
304     }
305     return JSUtils::Convert2JSValue(env, result);
306 }
307 
Close(napi_env env,napi_callback_info info)308 napi_value ResultSetProxy::Close(napi_env env, napi_callback_info info)
309 {
310     int errCode = GetInnerResultSet(env, info)->Close();
311     if (errCode != E_OK) {
312         LOG_ERROR("Close failed code:%{public}d", errCode);
313     }
314     return JSUtils::Convert2JSValue(env, (errCode == E_OK));
315 }
316 
GetRowCount(napi_env env,napi_callback_info info)317 napi_value ResultSetProxy::GetRowCount(napi_env env, napi_callback_info info)
318 {
319     int32_t result;
320     int errCode = GetInnerResultSet(env, info)->GetRowCount(result);
321     if (errCode != E_OK) {
322         LOG_ERROR("GetRowCount failed code:%{public}d", errCode);
323     }
324     return JSUtils::Convert2JSValue(env, result);
325 }
326 
GetRowIndex(napi_env env,napi_callback_info info)327 napi_value ResultSetProxy::GetRowIndex(napi_env env, napi_callback_info info)
328 {
329     int32_t result;
330     int errCode = GetInnerResultSet(env, info)->GetRowIndex(result);
331     if (errCode != E_OK) {
332         LOG_ERROR("GetRowIndex failed code:%{public}d", errCode);
333     }
334     return JSUtils::Convert2JSValue(env, result);
335 }
336 
IsEnded(napi_env env,napi_callback_info info)337 napi_value ResultSetProxy::IsEnded(napi_env env, napi_callback_info info)
338 {
339     bool result = false;
340     int errCode = GetInnerResultSet(env, info)->IsEnded(result);
341     if (errCode != E_OK) {
342         LOG_ERROR("IsEnded failed code:%{public}d", errCode);
343     }
344     return JSUtils::Convert2JSValue(env, result);
345 }
346 
IsBegin(napi_env env,napi_callback_info info)347 napi_value ResultSetProxy::IsBegin(napi_env env, napi_callback_info info)
348 {
349     bool result = false;
350     int errCode = GetInnerResultSet(env, info)->IsStarted(result);
351     if (errCode != E_OK) {
352         LOG_ERROR("IsBegin failed code:%{public}d", errCode);
353     }
354     return JSUtils::Convert2JSValue(env, result);
355 }
356 
GoToFirstRow(napi_env env,napi_callback_info info)357 napi_value ResultSetProxy::GoToFirstRow(napi_env env, napi_callback_info info)
358 {
359     int errCode = GetInnerResultSet(env, info)->GoToFirstRow();
360     if (errCode != E_OK) {
361         LOG_ERROR("GoToFirstRow failed code:%{public}d", errCode);
362     }
363     return JSUtils::Convert2JSValue(env, (errCode == E_OK));
364 }
365 
GoToLastRow(napi_env env,napi_callback_info info)366 napi_value ResultSetProxy::GoToLastRow(napi_env env, napi_callback_info info)
367 {
368     int errCode = GetInnerResultSet(env, info)->GoToLastRow();
369     if (errCode != E_OK) {
370         LOG_ERROR("GoToLastRow failed code:%{public}d", errCode);
371     }
372     return JSUtils::Convert2JSValue(env, (errCode == E_OK));
373 }
374 
GoToNextRow(napi_env env,napi_callback_info info)375 napi_value ResultSetProxy::GoToNextRow(napi_env env, napi_callback_info info)
376 {
377     int errCode = GetInnerResultSet(env, info)->GoToNextRow();
378     if (errCode != E_OK) {
379         LOG_ERROR("GoToNextRow failed code:%{public}d", errCode);
380     }
381     return JSUtils::Convert2JSValue(env, (errCode == E_OK));
382 }
383 
GoToPreviousRow(napi_env env,napi_callback_info info)384 napi_value ResultSetProxy::GoToPreviousRow(napi_env env, napi_callback_info info)
385 {
386     int errCode = GetInnerResultSet(env, info)->GoToPreviousRow();
387     if (errCode != E_OK) {
388         LOG_ERROR("GoToPreviousRow failed code:%{public}d", errCode);
389     }
390     return JSUtils::Convert2JSValue(env, (errCode == E_OK));
391 }
392 
IsAtFirstRow(napi_env env,napi_callback_info info)393 napi_value ResultSetProxy::IsAtFirstRow(napi_env env, napi_callback_info info)
394 {
395     bool result = false;
396     int errCode = GetInnerResultSet(env, info)->IsAtFirstRow(result);
397     if (errCode != E_OK) {
398         LOG_ERROR("IsAtFirstRow failed code:%{public}d", errCode);
399     }
400     return JSUtils::Convert2JSValue(env, result);
401 }
402 
IsAtLastRow(napi_env env,napi_callback_info info)403 napi_value ResultSetProxy::IsAtLastRow(napi_env env, napi_callback_info info)
404 {
405     bool result = false;
406     int errCode = GetInnerResultSet(env, info)->IsAtLastRow(result);
407     if (errCode != E_OK) {
408         LOG_ERROR("IsAtLastRow failed code:%{public}d", errCode);
409     }
410     return JSUtils::Convert2JSValue(env, result);
411 }
412 
GetBlob(napi_env env,napi_callback_info info)413 napi_value ResultSetProxy::GetBlob(napi_env env, napi_callback_info info)
414 {
415     int32_t columnIndex;
416     std::vector<uint8_t> result;
417     size_t argc = MAX_INPUT_COUNT;
418     napi_value args[MAX_INPUT_COUNT] = { 0 };
419     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
420     NAPI_ASSERT(env, argc > 0, "Invalid argvs!");
421     NAPI_CALL(env, napi_get_value_int32(env, args[0], &columnIndex));
422     int errCode = GetInnerResultSet(env, info)->GetBlob(columnIndex, result);
423     if (errCode != E_OK) {
424         LOG_ERROR("GetBlob failed code:%{public}d", errCode);
425     }
426     return JSUtils::Convert2JSValue(env, result);
427 }
428 
GetString(napi_env env,napi_callback_info info)429 napi_value ResultSetProxy::GetString(napi_env env, napi_callback_info info)
430 {
431     int32_t columnIndex;
432     std::string result;
433     size_t argc = MAX_INPUT_COUNT;
434     napi_value args[MAX_INPUT_COUNT] = { 0 };
435     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
436     NAPI_ASSERT(env, argc > 0, "Invalid argvs!");
437     NAPI_CALL(env, napi_get_value_int32(env, args[0], &columnIndex));
438     int errCode = GetInnerResultSet(env, info)->GetString(columnIndex, result);
439     if (errCode != E_OK) {
440         LOG_ERROR("GetString failed code:%{public}d", errCode);
441     }
442     return JSUtils::Convert2JSValue(env, result);
443 }
444 
GetDouble(napi_env env,napi_callback_info info)445 napi_value ResultSetProxy::GetDouble(napi_env env, napi_callback_info info)
446 {
447     int32_t columnIndex;
448     double result = 0.0;
449     size_t argc = MAX_INPUT_COUNT;
450     napi_value args[MAX_INPUT_COUNT] = { 0 };
451     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
452     NAPI_ASSERT(env, argc > 0, "Invalid argvs!");
453     NAPI_CALL(env, napi_get_value_int32(env, args[0], &columnIndex));
454     int errCode = GetInnerResultSet(env, info)->GetDouble(columnIndex, result);
455     if (errCode != E_OK) {
456         LOG_ERROR("GetDouble failed code:%{public}d", errCode);
457     }
458     return JSUtils::Convert2JSValue(env, result);
459 }
460 
IsColumnNull(napi_env env,napi_callback_info info)461 napi_value ResultSetProxy::IsColumnNull(napi_env env, napi_callback_info info)
462 {
463     int32_t columnIndex;
464     bool result = false;
465     size_t argc = MAX_INPUT_COUNT;
466     napi_value args[MAX_INPUT_COUNT] = { 0 };
467     napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
468     NAPI_ASSERT(env, argc > 0, "Invalid argvs!");
469     NAPI_CALL(env, napi_get_value_int32(env, args[0], &columnIndex));
470     int errCode = GetInnerResultSet(env, info)->IsColumnNull(columnIndex, result);
471     if (errCode != E_OK) {
472         LOG_ERROR("IsColumnNull failed code:%{public}d", errCode);
473     }
474     napi_value output;
475     napi_get_boolean(env, result, &output);
476     return output;
477 }
478 
IsClosed(napi_env env,napi_callback_info info)479 napi_value ResultSetProxy::IsClosed(napi_env env, napi_callback_info info)
480 {
481     int result = GetInnerResultSet(env, info)->IsClosed();
482     napi_value output;
483     napi_get_boolean(env, result, &output);
484     return output;
485 }
486 
GetSharedBlockName(napi_env env,napi_callback_info info)487 napi_value ResultSetProxy::GetSharedBlockName(napi_env env, napi_callback_info info)
488 {
489     napi_value thiz;
490     NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr));
491 
492     ResultSetProxy *proxy;
493     NAPI_CALL(env, napi_unwrap(env, thiz, reinterpret_cast<void **>(&proxy)));
494 
495     return JSUtils::Convert2JSValue(env, proxy->sharedBlockName_);
496 }
497 
GetSharedBlockAshmemFd(napi_env env,napi_callback_info info)498 napi_value ResultSetProxy::GetSharedBlockAshmemFd(napi_env env, napi_callback_info info)
499 {
500     napi_value thiz;
501     NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thiz, nullptr));
502 
503     ResultSetProxy *proxy;
504     NAPI_CALL(env, napi_unwrap(env, thiz, reinterpret_cast<void **>(&proxy)));
505 
506     return JSUtils::Convert2JSValue(env, proxy->sharedBlockAshmemFd_);
507 }
508 } // namespace RdbJsKit
509 } // namespace OHOS
510 
511 EXTERN_C_START
NAPI_OHOS_Data_RdbJsKit_ResultSetProxy_NewInstance(napi_env env,OHOS::NativeRdb::AbsSharedResultSet * resultSet)512 __attribute__((visibility("default"))) napi_value NAPI_OHOS_Data_RdbJsKit_ResultSetProxy_NewInstance(
513     napi_env env, OHOS::NativeRdb::AbsSharedResultSet *resultSet)
514 {
515     return OHOS::RdbJsKit::ResultSetProxy::NewInstance(
516         env, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet>(resultSet));
517 }
518 
519 __attribute__((visibility("default"))) OHOS::NativeRdb::AbsSharedResultSet *
NAPI_OHOS_Data_RdbJsKit_ResultSetProxy_GetNativeObject(const napi_env & env,const napi_value & arg)520 NAPI_OHOS_Data_RdbJsKit_ResultSetProxy_GetNativeObject(const napi_env &env, const napi_value &arg)
521 {
522     // the resultSet maybe release.
523     auto resultSet = OHOS::RdbJsKit::ResultSetProxy::GetNativeObject(env, arg);
524     return resultSet.get();
525 }
526 EXTERN_C_END