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