• 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 
16 #ifndef NATIVE_RDB_REMOTE_RESULT_SET_H
17 #define NATIVE_RDB_REMOTE_RESULT_SET_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "rdb_visibility.h"
23 #include "rdb_types.h"
24 
25 namespace OHOS {
26 namespace NativeRdb {
27 using ColumnType = DistributedRdb::ColumnType;
28 /**
29  * The RemoteResultSet class of RDB.
30  * Provides methods for accessing a database result set generated by remote query the database.
31  */
32 class API_EXPORT RemoteResultSet {
33 public:
34     /**
35      * @brief The error CMD in the correct case.
36      */
37     enum Code {
38         /** Indicates the current CMD is CMD_GET_ALL_COLUMN_NAMES.*/
39         CMD_GET_ALL_COLUMN_NAMES,
40         /** Indicates the current CMD is CMD_GET_COLUMN_COUNT.*/
41         CMD_GET_COLUMN_COUNT,
42         /** Indicates the current CMD is CMD_GET_COLUMN_TYPE.*/
43         CMD_GET_COLUMN_TYPE,
44         /** Indicates the current CMD is CMD_GET_ROW_COUNT.*/
45         CMD_GET_ROW_COUNT,
46         /** Indicates the current CMD is CMD_GET_ROW_INDEX.*/
47         CMD_GET_ROW_INDEX,
48         /** Indicates the current CMD is CMD_GO_TO.*/
49         CMD_GO_TO,
50         /** Indicates the current CMD is CMD_GO_TO_ROW.*/
51         CMD_GO_TO_ROW,
52         /** Indicates the current CMD is CMD_GO_TO_FIRST_ROW.*/
53         CMD_GO_TO_FIRST_ROW,
54         /** Indicates the current CMD is CMD_GO_TO_LAST_ROW.*/
55         CMD_GO_TO_LAST_ROW,
56         /** Indicates the current CMD is CMD_GO_TO_NEXT_ROW.*/
57         CMD_GO_TO_NEXT_ROW,
58         /** Indicates the current CMD is CMD_GO_TO_PREV_ROW.*/
59         CMD_GO_TO_PREV_ROW,
60         /** Indicates the current CMD is CMD_IS_ENDED_ROW.*/
61         CMD_IS_ENDED_ROW,
62         /** Indicates the current CMD is CMD_IS_STARTED_ROW.*/
63         CMD_IS_STARTED_ROW,
64         /** Indicates the current CMD is CMD_IS_AT_FIRST_ROW.*/
65         CMD_IS_AT_FIRST_ROW,
66         /** Indicates the current CMD is CMD_IS_AT_LAST_ROW.*/
67         CMD_IS_AT_LAST_ROW,
68         /** Indicates the current CMD is CMD_GET.*/
69         CMD_GET,
70         /** Indicates the current CMD is CMD_GET.*/
71         CMD_GET_SIZE,
72         /** Indicates the current CMD is CMD_CLOSE.*/
73         CMD_CLOSE,
74         /** Indicates the current CMD is CMD_MAX.*/
75         CMD_MAX
76     };
77 
78     /**
79      * @brief Destructor.
80      */
~RemoteResultSet()81     virtual ~RemoteResultSet() {}
82 
83     /**
84      * @brief Obtains a string array holding the names of all of the columns in the result set.
85      *
86      * @return Returns the names of the columns contains in this query result.
87      */
88     virtual int GetAllColumnNames(std::vector<std::string> &columnNames) = 0;
89 
90     /**
91      * @brief Obtains the total number of columns.
92      *
93      * @return Returns the number of columns
94      */
95     virtual int GetColumnCount(int &count) = 0;
96 
97     /**
98      * @brief Obtains data type of the given column's value.
99      *
100      * @param columnIndex Indicates the zero-based index of the target column.
101      * @return Returns column value type.
102      */
103     virtual int GetColumnType(int columnIndex, ColumnType &columnType) = 0;
104 
105     /**
106      * @brief Obtains the zero-based index for the given column name.
107      *
108      * @param columnName Indicates the name of the column.
109      * @return Returns the column index for the given column, or -1 if the column does not exist.
110      */
111     virtual int GetColumnIndex(const std::string &columnName, int &columnIndex) = 0;
112 
113     /**
114      * @brief Obtains the column name at the given column index.
115      *
116      * @param columnIndex Indicates the zero-based index.
117      * @return Returns the column name for the given index.
118      */
119     virtual int GetColumnName(int columnIndex, std::string &columnName) = 0;
120 
121     /**
122      * @brief Obtains the numbers of rows in the result set.
123      */
124     virtual int GetRowCount(int &count) = 0;
125 
126     /**
127      * @brief Obtains the current position of the cursor in the result set.
128      *
129      * The value is zero-based. When the result set is first returned the cursor
130      * will be at position -1, which is before the first row.
131      * After the last row is returned another call to next() will leave the cursor past
132      * the last entry, at a position of count().
133      *
134      * @return Returns the current cursor position.
135      */
136     virtual int GetRowIndex(int &position) const = 0;
137 
138     /**
139      * @brief Move the cursor a relative amount from current position. Positive offset move forward,
140      * negative offset move backward.
141      *
142      * @param offset Indicates the offset to be applied from the current position.
143      * @return Returns whether the requested move succeeded.
144      */
145     virtual int GoTo(int offset) = 0;
146 
147     /**
148      * @brief Move the cursor to an absolute position.
149      *
150      * @param position Indicates the zero-based position to move to.
151      * @return Returns whether the requested move succeeded.
152      */
153     virtual int GoToRow(int position) = 0;
154 
155     /**
156      * @brief Move the cursor to the first row.
157      *
158      * @return Returns whether the requested move succeeded.
159      */
160     virtual int GoToFirstRow() = 0;
161 
162     /**
163      * @brief Move the cursor to the last row.
164      *
165      * @return Returns whether the requested move succeeded.
166      */
167     virtual int GoToLastRow() = 0;
168 
169     /**
170      * @brief Move the cursor to the next row.
171      *
172      * @return Returns whether the requested move succeeded.
173      */
174     virtual int GoToNextRow() = 0;
175 
176     /**
177      * @brief Move the cursor to the previous row.
178      *
179      * @return Returns whether the requested move succeeded.
180      */
181     virtual int GoToPreviousRow() = 0;
182 
183     /**
184      * @brief Obtains whether the cursor is pointing to the position after the last row.
185      *
186      * @return Returns whether the cursor is after the last row.
187      */
188     virtual int IsEnded(bool &result) = 0;
189 
190     /**
191      * @brief Obtains whether the cursor is pointing to the position before the first row.
192      *
193      * @return Returns whether the cursor is before the first row.
194      */
195     virtual int IsStarted(bool &result) const = 0;
196 
197     /**
198      * @brief Obtains whether the cursor is pointing to the first row.
199      *
200      * @return Returns whether the cursor is pointing at the first entry.
201      */
202     virtual int IsAtFirstRow(bool &result) const = 0;
203 
204     /**
205      * @brief Obtains whether the cursor is pointing to the last row.
206      *
207      * @return Returns whether the cursor is pointing at the last entry.
208      */
209     virtual int IsAtLastRow(bool &result) = 0;
210 
211     /**
212      * @brief Obtains the value of the requested column as a byte array.
213      *
214      * @param columnIndex Indicates the zero-based index of the target column.
215      * @return Returns the value of the requested column as a byte array.
216      */
217     virtual int GetBlob(int columnIndex, std::vector<uint8_t> &blob) = 0;
218 
219     /**
220      * @brief Obtains the value of the requested column as a String.
221      *
222      * @param columnIndex Indicates the zero-based index of the target column.
223      * @return Returns the value of the requested column as a String.
224      */
225     virtual int GetString(int columnIndex, std::string &value) = 0;
226 
227     /**
228      * @brief Obtains the value of the requested column as a int.
229      *
230      * @param columnIndex Indicates the zero-based index of the target column.
231      * @return Returns the value of the requested column as a int.
232      */
233     virtual int GetInt(int columnIndex, int &value) = 0;
234 
235     /**
236      * @brief Obtains the value of the requested column as a long.
237      *
238      * @param columnIndex Indicates the zero-based index of the target column.
239      * @return Returns the value of the requested column as a long.
240      */
241     virtual int GetLong(int columnIndex, int64_t &value) = 0;
242 
243     /**
244      * @brief Obtains the value of the requested column as a double.
245      *
246      * @param columnIndex Indicates the zero-based index of the target column.
247      * @return Returns the value of the requested column as a double.
248      */
249     virtual int GetDouble(int columnIndex, double &value) = 0;
250 
251     /**
252      * @brief Obtains Whether the value of the requested column is null.
253      *
254      * @param columnIndex Indicates the zero-based index of the target column.
255      * @return Returns whether the column value is null.
256      */
257     virtual int IsColumnNull(int columnIndex, bool &isNull) = 0;
258 
259     /**
260      * @brief Obtains Return true if the result set is closed.
261      *
262      * @return Returns true if the result set is closed.
263      */
264     virtual bool IsClosed() const = 0;
265 
266     /**
267      * @brief Closes the result set, releasing all of its resources and making it completely invalid.
268      */
269     virtual int Close() = 0;
270 };
271 
272 } // namespace NativeRdb
273 } // namespace OHOS
274 #endif
275