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