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