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 9 91 */ 92export default interface DataShareResultSet { 93 /** 94 * Obtains the names of all columns or keys in a result set. 95 * The column or key names are returned as a string array, in which the strings are in the same order 96 * as the columns or keys in the result set. 97 * 98 * @type { Array<string> } 99 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 100 * @systemapi 101 * @StageModelOnly 102 * @since 9 103 */ 104 columnNames: Array<string>; 105 106 /** 107 * Obtains the number of columns or keys in the result set. 108 * The returned number is equal to the length of the string array returned by the columnCount method. 109 * 110 * @type { number } 111 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 112 * @systemapi 113 * @StageModelOnly 114 * @since 9 115 */ 116 columnCount: number; 117 118 /** 119 * Obtains the number of rows in the result set. 120 * 121 * @type { number } 122 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 123 * @systemapi 124 * @StageModelOnly 125 * @since 9 126 */ 127 rowCount: number; 128 129 /** 130 * Checks whether the current result set is closed. 131 * If the result set is closed by calling the close method, true will be returned. 132 * 133 * @type { boolean } 134 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 135 * @systemapi 136 * @StageModelOnly 137 * @since 9 138 */ 139 isClosed: boolean; 140 141 /** 142 * Go to the first row of the result set. 143 * 144 * @returns { boolean } Returns true if the result set is moved successfully; 145 * returns false otherwise, for example, if the result set is empty. 146 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 147 * @systemapi 148 * @StageModelOnly 149 * @since 9 150 */ 151 goToFirstRow(): boolean; 152 153 /** 154 * Go to the last row of the result set. 155 * 156 * @returns { boolean } Returns true if the result set is moved successfully; 157 * returns false otherwise, for example, if the result set is empty. 158 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 159 * @systemapi 160 * @StageModelOnly 161 * @since 9 162 */ 163 goToLastRow(): boolean; 164 165 /** 166 * Go to the next row of the result set. 167 * 168 * @returns { boolean } Returns true if the result set is moved successfully; 169 * returns false otherwise, for example, if the result set is already in the last row. 170 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 171 * @systemapi 172 * @StageModelOnly 173 * @since 9 174 */ 175 goToNextRow(): boolean; 176 177 /** 178 * Go to the previous row of the result set. 179 * 180 * @returns { boolean } Returns true if the result set is moved successfully; 181 * returns false otherwise, for example, if the result set is already in the first row. 182 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 183 * @systemapi 184 * @StageModelOnly 185 * @since 9 186 */ 187 goToPreviousRow(): boolean; 188 189 /** 190 * Go to the specified row of the result set forwards or backwards by an offset relative to its current position. 191 * A positive offset indicates moving backwards, and a negative offset indicates moving forwards. 192 * 193 * @param { number } offset - Indicates the offset relative to the current position. 194 * @returns { boolean } Returns true if the result set is moved successfully and does not go beyond the range; 195 * returns false otherwise. 196 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 197 * @systemapi 198 * @StageModelOnly 199 * @since 9 200 */ 201 goTo(offset: number): boolean; 202 203 /** 204 * Go to the specified row of the result set. 205 * 206 * @param { number } position - Indicates the index of the specified row, which starts from 0. 207 * @returns { boolean } Returns true if the result set is moved successfully; returns false otherwise. 208 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 209 * @systemapi 210 * @StageModelOnly 211 * @since 9 212 */ 213 goToRow(position: number): boolean; 214 215 /** 216 * Obtains the value of the specified column or key in the current row as a byte array. 217 * The implementation class determines whether to throw an exception if the value of the specified 218 * column or key in the current row is null or the specified column or key is not of the Blob type. 219 * 220 * @param { number } columnIndex - Indicates the specified column index or key index, which starts from 0. 221 * @returns { Uint8Array } Returns the value of the specified column or key as a byte array. 222 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 223 * @systemapi 224 * @StageModelOnly 225 * @since 9 226 */ 227 getBlob(columnIndex: number): Uint8Array; 228 229 /** 230 * Obtains the value of the specified column or key in the current row as string. 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 or the specified column or key is not of the string type. 233 * 234 * @param { number } columnIndex - Indicates the specified column index or key index, which starts from 0. 235 * @returns { string } Returns the value of the specified column or key as a string. 236 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 237 * @systemapi 238 * @StageModelOnly 239 * @since 9 240 */ 241 getString(columnIndex: number): string; 242 243 /** 244 * Obtains the value of the specified column or key in the current row as long. 245 * The implementation class determines whether to throw an exception if the value of the specified 246 * column or key in the current row is null, the specified column or key is not of the long type. 247 * 248 * @param { number } columnIndex - Indicates the specified column index or key index, which starts from 0. 249 * @returns { number } Returns the value of the specified column or key as a long. 250 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 251 * @systemapi 252 * @StageModelOnly 253 * @since 9 254 */ 255 getLong(columnIndex: number): number; 256 257 /** 258 * Obtains the value of the specified column or key in the current row as double. 259 * The implementation class determines whether to throw an exception if the value of the specified 260 * column or key in the current row is null, the specified column or key is not of the double type. 261 * 262 * @param { number } columnIndex - Indicates the specified column index or key index, which starts from 0. 263 * @returns { number } Returns the value of the specified column or key as a double. 264 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 265 * @systemapi 266 * @StageModelOnly 267 * @since 9 268 */ 269 getDouble(columnIndex: number): number; 270 271 /** 272 * Closes the result set. 273 * Calling this method on the result set will release all of its resources and makes it ineffective. 274 * 275 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 276 * @systemapi 277 * @StageModelOnly 278 * @since 9 279 */ 280 close(): void; 281 282 /** 283 * Obtains the column index or key index based on the specified column name or key name. 284 * The column name or key name is passed as an input parameter. 285 * 286 * @param { string } columnName - Indicates the name of the specified column or key in the result set. 287 * @returns { number } Returns the index of the specified column or key. 288 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 289 * @systemapi 290 * @StageModelOnly 291 * @since 9 292 */ 293 getColumnIndex(columnName: string): number; 294 295 /** 296 * Obtains the column name or key name based on the specified column index or key index. 297 * The column index or key index is passed as an input parameter. 298 * 299 * @param { number } columnIndex - Indicates the index of the specified column or key in the result set. 300 * @returns { string } Returns the name of the specified column or key. 301 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 302 * @systemapi 303 * @StageModelOnly 304 * @since 9 305 */ 306 getColumnName(columnIndex: number): string; 307 308 /** 309 * Obtains the dataType of the specified column or key. 310 * The implementation class determines whether to throw an exception if the value of the specified 311 * column or key in the current row is null, the specified column or key is not in the data type. 312 * 313 * @param { number } columnIndex - Indicates the specified column index or key index, which starts from 0. 314 * @returns { DataType } Returns the dataType of the specified column or key. 315 * @syscap SystemCapability.DistributedDataManager.DataShare.Core 316 * @systemapi 317 * @StageModelOnly 318 * @since 9 319 */ 320 getDataType(columnIndex: number): DataType; 321} 322