• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2023 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 #include "grd_base/grd_resultset_api.h"
16 
17 #include <mutex>
18 
19 #include "doc_errno.h"
20 #include "grd_base/grd_error.h"
21 #include "grd_resultset_inner.h"
22 #include "log_print.h"
23 
24 using namespace DocumentDB;
25 
GRD_Next(GRD_ResultSet * resultSet)26 GRD_API int32_t GRD_Next(GRD_ResultSet *resultSet)
27 {
28     if (resultSet == nullptr) {
29         GLOGE("resultSet is nullptr");
30         return GRD_INVALID_ARGS;
31     };
32     int ret = resultSet->resultSet_.GetNext(true, true);
33     return TransferDocErr(ret);
34 }
35 
GRD_GetValue(GRD_ResultSet * resultSet,char ** value)36 GRD_API int32_t GRD_GetValue(GRD_ResultSet *resultSet, char **value)
37 {
38     if (resultSet == nullptr || value == nullptr) {
39         GLOGE("resultSet is nullptr,cant get value from it");
40         return GRD_INVALID_ARGS;
41     };
42     char *val = nullptr;
43     int ret = resultSet->resultSet_.GetValue(&val);
44     if (val == nullptr) {
45         GLOGE("Value that get from resultSet is nullptr");
46         return GRD_NOT_AVAILABLE;
47     }
48     *value = val;
49     return TransferDocErr(ret);
50 }
51 
GRD_FreeValue(char * value)52 GRD_API int32_t GRD_FreeValue(char *value)
53 {
54     if (value == nullptr) {
55         return GRD_INVALID_ARGS;
56     }
57     delete[] value;
58     return GRD_OK;
59 }
60 
GRD_FreeResultSet(GRD_ResultSet * resultSet)61 GRD_API int32_t GRD_FreeResultSet(GRD_ResultSet *resultSet)
62 {
63     if (resultSet == nullptr) {
64         return GRD_INVALID_ARGS;
65     }
66     resultSet->resultSet_.EraseCollection();
67     delete resultSet;
68     return GRD_OK;
69 }