• 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 */
15import { AsyncCallback } from '../../basic'
16
17/**
18 * Provides methods for accessing a database result set generated by querying the database.
19 *
20 * @since 7
21 * @sysCap SystemCapability.Data.DATA_APPDATAMGR
22 * @devices phone, tablet, tv, wearable, car
23 * @import import data_rdb from '@ohos.data.rdb';
24 * @permission N/A
25 */
26interface ResultSet {
27    /**
28     * Obtains the names of all columns in a result set.
29     *
30     * @note The column names are returned as a string array, in which the strings are in the same order
31     * as the columns in the result set.
32     * @since 7
33     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
34     * @devices phone, tablet, tv, wearable, car
35     */
36    columnNames: Array<string>;
37
38    /**
39     * Obtains the number of columns in the result set.
40     *
41     * @note The returned number is equal to the length of the string array returned by the
42     * columnCount method.
43     * @since 7
44     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
45     * @devices phone, tablet, tv, wearable, car
46     */
47    columnCount: number;
48
49    /**
50     * Obtains the number of rows in the result set.
51     *
52     * @note N/A
53     * @since 7
54     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
55     * @devices phone, tablet, tv, wearable, car
56     */
57    rowCount: number;
58
59    /**
60     * Obtains the current index of the result set.
61     *
62     * @note The result set index starts from 0.
63     * @since 7
64     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
65     * @devices phone, tablet, tv, wearable, car
66     */
67    rowIndex: number;
68
69    /**
70     * Checks whether the result set is positioned at the first row.
71     *
72     * @note N/A
73     * @since 7
74     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
75     * @devices phone, tablet, tv, wearable, car
76     */
77    isAtFirstRow: boolean;
78
79    /**
80     * Checks whether the result set is positioned at the last row.
81     *
82     * @note N/A
83     * @since 7
84     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
85     * @devices phone, tablet, tv, wearable, car
86     */
87    isAtLastRow: boolean;
88
89    /**
90     * Checks whether the result set is positioned after the last row.
91     *
92     * @note N/A
93     * @since 7
94     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
95     * @devices phone, tablet, tv, wearable, car
96     */
97    isEnded: boolean;
98
99    /**
100     * Returns whether the cursor is pointing to the position before the first
101     * row.
102     *
103     * @note N/A
104     * @since 7
105     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
106     * @devices phone, tablet, tv, wearable, car
107     */
108    isStarted: boolean;
109
110    /**
111     * Checks whether the current result set is closed.
112     *
113     * If the result set is closed by calling the close method, true will be returned.
114     *
115     * @note N/A
116     * @since 7
117     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
118     * @devices phone, tablet, tv, wearable, car
119     */
120    isClosed: boolean;
121
122    /**
123     * Obtains the column index based on the specified column name.
124     *
125     * @note The column name is passed as an input parameter.
126     * @since 7
127     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
128     * @devices phone, tablet, tv, wearable, car
129     * @param columnName Indicates the name of the specified column in the result set.
130     * @return Returns the index of the specified column.
131     */
132    getColumnIndex(columnName: string): number;
133
134    /**
135     * Obtains the column name based on the specified column index.
136     *
137     * @note The column index is passed as an input parameter.
138     * @since 7
139     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
140     * @devices phone, tablet, tv, wearable, car
141     * @param columnIndex Indicates the index of the specified column in the result set.
142     * @return Returns the name of the specified column.
143     */
144    getColumnName(columnIndex: number): string;
145
146    /**
147     * Go to the specified row of the result set forwards or backwards by an offset relative to its current position.
148     * A positive offset indicates moving backwards, and a negative offset indicates moving forwards.
149     *
150     * @note N/A
151     * @since 7
152     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
153     * @devices phone, tablet, tv, wearable, car
154     * @param offset Indicates the offset relative to the current position.
155     * @return Returns true if the result set is moved successfully and does not go beyond the range;
156     * returns false otherwise.
157     */
158    goTo(offset: number): boolean;
159
160    /**
161     * Go to the specified row of the result set.
162     *
163     * @note N/A
164     * @since 7
165     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
166     * @devices phone, tablet, tv, wearable, car
167     * @param rowIndex Indicates the index of the specified row, which starts from 0.
168     * @return Returns true if the result set is moved successfully; returns false otherwise.
169     */
170    goToRow(position: number): boolean;
171
172    /**
173     * Go to the first row of the result set.
174     *
175     * @note N/A
176     * @since 7
177     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
178     * @devices phone, tablet, tv, wearable, car
179     * @return Returns true if the result set is moved successfully;
180     * returns false otherwise, for example, if the result set is empty.
181     */
182    goToFirstRow(): boolean;
183
184    /**
185     * Go to the last row of the result set.
186     *
187     * @note N/A
188     * @since 7
189     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
190     * @devices phone, tablet, tv, wearable, car
191     * @return Returns true if the result set is moved successfully;
192     * returns false otherwise, for example, if the result set is empty.
193     */
194    goToLastRow(): boolean;
195
196    /**
197     * Go to the next row of the result set.
198     *
199     * @note N/A
200     * @since 7
201     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
202     * @devices phone, tablet, tv, wearable, car
203     * @return Returns true if the result set is moved successfully;
204     * returns false otherwise, for example, if the result set is already in the last row.
205     */
206    goToNextRow(): boolean;
207
208    /**
209     * Go to the previous row of the result set.
210     *
211     * @note N/A
212     * @since 7
213     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
214     * @devices phone, tablet, tv, wearable, car
215     * @return Returns true if the result set is moved successfully;
216     * returns false otherwise, for example, if the result set is already in the first row.
217     */
218    goToPreviousRow(): boolean;
219
220    /**
221     * Obtains the value of the specified column in the current row as a byte array.
222     *
223     * @note The implementation class determines whether to throw an exception if the value of the specified column
224     * in the current row is null or the specified column is not of the Blob type.
225     * @since 7
226     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
227     * @devices phone, tablet, tv, wearable, car
228     * @param columnIndex Indicates the specified column index, which starts from 0.
229     * @return Returns the value of the specified column as a byte array.
230     */
231    getBlob(columnIndex: number): Uint8Array;
232
233    /**
234     * Obtains the value of the specified column in the current row as string.
235     *
236     * @note The implementation class determines whether to throw an exception if the value of the specified column
237     * in the current row is null or the specified column is not of the string type.
238     * @since 7
239     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
240     * @devices phone, tablet, tv, wearable, car
241     * @param columnIndex Indicates the specified column index, which starts from 0.
242     * @return Returns the value of the specified column as a string.
243     */
244    getString(columnIndex: number): string;
245
246    /**
247     * Obtains the value of the specified column in the current row as long.
248     *
249     * @note The implementation class determines whether to throw an exception if the value of the specified column
250     * in the current row is null, the specified column is not of the integer type.
251     * @since 7
252     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
253     * @devices phone, tablet, tv, wearable, car
254     * @param columnIndex Indicates the specified column index, which starts from 0.
255     * @return Returns the value of the specified column as a long.
256     */
257    getLong(columnIndex: number): number;
258
259    /**
260     * Obtains the value of the specified column in the current row as double.
261     *
262     * @note The implementation class determines whether to throw an exception if the value of the specified column
263     * in the current row is null, the specified column is not of the double type.
264     * @since 7
265     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
266     * @devices phone, tablet, tv, wearable, car
267     * @param columnIndex Indicates the specified column index, which starts from 0.
268     * @return Returns the value of the specified column as a double.
269     */
270    getDouble(columnIndex: number): number;
271
272    /**
273     * Checks whether the value of the specified column in the current row is null.
274     *
275     * @note N/A
276     * @since 7
277     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
278     * @devices phone, tablet, tv, wearable, car
279     * @param columnIndex Indicates the specified column index, which starts from 0.
280     * @return Returns true if the value of the specified column in the current row is null;
281     * returns false otherwise.
282     */
283    isColumnNull(columnIndex: number): boolean;
284
285    /**
286     * Closes the result set.
287     *
288     * @note Calling this method on the result set will release all of its resources and makes it ineffective.
289     * @since 7
290     * @sysCap SystemCapability.Data.DATA_APPDATAMGR
291     * @devices phone, tablet, tv, wearable, car
292     * @return Returns true if the result set is closed; returns false otherwise.
293     */
294    close(): void;
295}