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