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