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