1# Interface (ResultSet) 2<!--Kit: ArkData--> 3<!--Subsystem: DistributedDataManager--> 4<!--Owner: @baijidong--> 5<!--Designer: @widecode; @htt1997--> 6<!--Tester: @yippo; @logic42--> 7<!--Adviser: @ge-yafang--> 8 9> **说明:** 10> 11> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 12 13提供通过查询数据库生成的数据库结果集的访问方法。结果集是指用户调用关系型数据库查询接口之后返回的结果集合,提供了多种灵活的数据访问方式,以便用户获取各项数据。 14 15下列API示例中,都需先使用[query](arkts-apis-data-relationalStore-RdbStore.md#query)、[querySql](arkts-apis-data-relationalStore-RdbStore.md#querysql)、[remoteQuery](arkts-apis-data-relationalStore-RdbStore.md#remotequery-1)、[queryLockedRow](arkts-apis-data-relationalStore-RdbStore.md#querylockedrow12)等query类方法中任一方法获取到ResultSet实例,再通过此实例调用对应方法。 16 17## 导入模块 18 19```ts 20import { relationalStore } from '@kit.ArkData'; 21``` 22 23## 属性 24 25**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 26 27| 名称 | 类型 | 必填 | 说明 | 28| ------------ | ------------------- | ---- | -------------------------------- | 29| columnNames | Array<string> | 是 | 获取结果集中所有列的名称。 | 30| columnCount | number | 是 | 获取结果集中列的数量。 | 31| rowCount | number | 是 | 获取结果集中行的数量。 | 32| rowIndex | number | 是 | 获取结果集当前行的索引位置,默认值为-1。索引位置下标从0开始。 | 33| isAtFirstRow | boolean | 是 | 检查结果集指针是否位于第一行(行索引为0),true表示位于第一行,false表示不位于第一行。 | 34| isAtLastRow | boolean | 是 | 检查结果集指针是否位于最后一行,true表示位于最后一行,false表示不位于最后一行。 | 35| isEnded | boolean | 是 | 检查结果集指针是否位于最后一行之后,true表示位于最后一行之后,false表示不位于最后一行之后。 | 36| isStarted | boolean | 是 | 检查指针是否移动过,true表示指针已移动过,false表示指针未移动过。 | 37| isClosed | boolean | 是 | 检查当前结果集是否关闭,true表示结果集已关闭,false表示结果集未关闭。 | 38 39## getColumnIndex 40 41getColumnIndex(columnName: string): number 42 43根据指定的列名获取列索引。 44 45**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 46 47**参数:** 48 49| 参数名 | 类型 | 必填 | 说明 | 50| ---------- | ------ | ---- | -------------------------- | 51| columnName | string | 是 | 表示结果集中指定列的名称。 | 52 53**返回值:** 54 55| 类型 | 说明 | 56| ------ | ------------------ | 57| number | 返回指定列的索引。 | 58 59**错误码:** 60 61以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 62 63| **错误码ID** | **错误信息** | 64|-----------| ------------------------------------------------------------ | 65| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 66| 14800000 | Inner error. | 67| 14800011 | Failed to open the database because it is corrupted. | 68| 14800013 | ResultSet is empty or column index is out of bounds. | 69| 14800014 | The RdbStore or ResultSet is already closed. | 70| 14800019 | The SQL must be a query statement. | 71| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 72| 14800022 | SQLite: Callback routine requested an abort. | 73| 14800023 | SQLite: Access permission denied. | 74| 14800024 | SQLite: The database file is locked. | 75| 14800025 | SQLite: A table in the database is locked. | 76| 14800026 | SQLite: The database is out of memory. | 77| 14800027 | SQLite: Attempt to write a readonly database. | 78| 14800028 | SQLite: Some kind of disk I/O error occurred. | 79| 14800029 | SQLite: The database is full. | 80| 14800030 | SQLite: Unable to open the database file. | 81| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 82| 14800032 | SQLite: Abort due to constraint violation. | 83| 14800033 | SQLite: Data type mismatch. | 84| 14800034 | SQLite: Library used incorrectly. | 85 86**示例:** 87 88```ts 89if (resultSet != undefined) { 90 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 91 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 92 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 93 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 94} 95``` 96 97## getColumnName 98 99getColumnName(columnIndex: number): string 100 101根据指定的列索引获取列名。 102 103**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 104 105**参数:** 106 107| 参数名 | 类型 | 必填 | 说明 | 108| ----------- | ------ | ---- | -------------------------- | 109| columnIndex | number | 是 | 表示结果集中指定列的索引。 | 110 111**返回值:** 112 113| 类型 | 说明 | 114| ------ | ------------------ | 115| string | 返回指定列的名称。 | 116 117**错误码:** 118 119以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 120 121| **错误码ID** | **错误信息** | 122|-----------| ------------------------------------------------------------ | 123| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 124| 14800000 | Inner error. | 125| 14800011 | Failed to open the database because it is corrupted. | 126| 14800013 | ResultSet is empty or column index is out of bounds. | 127| 14800014 | The RdbStore or ResultSet is already closed. | 128| 14800019 | The SQL must be a query statement. | 129| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 130| 14800022 | SQLite: Callback routine requested an abort. | 131| 14800023 | SQLite: Access permission denied. | 132| 14800024 | SQLite: The database file is locked. | 133| 14800025 | SQLite: A table in the database is locked. | 134| 14800026 | SQLite: The database is out of memory. | 135| 14800027 | SQLite: Attempt to write a readonly database. | 136| 14800028 | SQLite: Some kind of disk I/O error occurred. | 137| 14800029 | SQLite: The database is full. | 138| 14800030 | SQLite: Unable to open the database file. | 139| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 140| 14800032 | SQLite: Abort due to constraint violation. | 141| 14800033 | SQLite: Data type mismatch. | 142| 14800034 | SQLite: Library used incorrectly. | 143 144**示例:** 145 146```ts 147if (resultSet != undefined) { 148 const id = (resultSet as relationalStore.ResultSet).getColumnName(0); 149 const name = (resultSet as relationalStore.ResultSet).getColumnName(1); 150 const age = (resultSet as relationalStore.ResultSet).getColumnName(2); 151} 152``` 153 154## getColumnType<sup>18+</sup> 155 156getColumnType(columnIdentifier: number | string): Promise\<ColumnType> 157 158根据指定的列索引或列名称获取列数据类型,使用Promise异步回调。 159 160**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 161 162**参数:** 163 164| 参数名 | 类型 | 必填 | 说明 | 165| ---------------- | ---------------- | ---- | ------------------------------------------------------------ | 166| columnIdentifier | number \| string | 是 | 表示结果集中指定列的索引或名称。索引必须是非负整数,最大不能超过属性columnNames的长度。列名必须是属性columnNames内的名称。 | 167 168**返回值:** 169 170| 类型 | 说明 | 171| ------------------------------------ | ----------------------------------- | 172| Promise<[ColumnType](arkts-apis-data-relationalStore-e.md#columntype18)> | Promise对象。返回指定列的数据类型。 | 173 174**错误码:** 175 176以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 177 178| **错误码ID** | **错误信息** | 179| ------------ | ------------------------------------------------------------ | 180| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 181| 14800000 | Inner error. | 182| 14800011 | Failed to open the database because it is corrupted. | 183| 14800012 | ResultSet is empty or pointer index is out of bounds. | 184| 14800013 | ResultSet is empty or column index is out of bounds. | 185| 14800014 | The RdbStore or ResultSet is already closed. | 186| 14800019 | The SQL must be a query statement. | 187| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 188| 14800022 | SQLite: Callback routine requested an abort. | 189| 14800023 | SQLite: Access permission denied. | 190| 14800024 | SQLite: The database file is locked. | 191| 14800025 | SQLite: A table in the database is locked. | 192| 14800026 | SQLite: The database is out of memory. | 193| 14800027 | SQLite: Attempt to write a readonly database. | 194| 14800028 | SQLite: Some kind of disk I/O error occurred. | 195| 14800029 | SQLite: The database is full. | 196| 14800030 | SQLite: Unable to open the database file. | 197| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 198| 14800032 | SQLite: Abort due to constraint violation. | 199| 14800033 | SQLite: Data type mismatch. | 200| 14800034 | SQLite: Library used incorrectly. | 201 202**示例:** 203 204```ts 205if (resultSet != undefined) { 206 let idType = await (resultSet as relationalStore.ResultSet).getColumnType("ID") as relationalStore.ColumnType; 207 let nameType = await (resultSet as relationalStore.ResultSet).getColumnType("NAME") as relationalStore.ColumnType; 208 let ageType = await (resultSet as relationalStore.ResultSet).getColumnType("AGE") as relationalStore.ColumnType; 209 let salaryType = await (resultSet as relationalStore.ResultSet).getColumnType("SALARY") as relationalStore.ColumnType; 210 let codesType = await (resultSet as relationalStore.ResultSet).getColumnType("CODES") as relationalStore.ColumnType; 211 let identityType = await (resultSet as relationalStore.ResultSet).getColumnType(5) as relationalStore.ColumnType; 212 let assetDataType = await (resultSet as relationalStore.ResultSet).getColumnType(6) as relationalStore.ColumnType; 213 let assetsDataType = await (resultSet as relationalStore.ResultSet).getColumnType(7) as relationalStore.ColumnType; 214 let floatArrayType = await (resultSet as relationalStore.ResultSet).getColumnType(8) as relationalStore.ColumnType; 215} 216``` 217 218## getColumnTypeSync<sup>18+</sup> 219 220getColumnTypeSync(columnIdentifier: number | string): ColumnType 221 222根据指定的列索引或列名称获取列数据类型。 223 224**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 225 226**参数:** 227 228| 参数名 | 类型 | 必填 | 说明 | 229| ---------------- | ---------------- | ---- | ------------------------------------------------------------ | 230| columnIdentifier | number \| string | 是 | 表示结果集中指定列的索引或名称。索引必须是非负整数,最大不能超过属性columnNames的长度。列名必须是属性columnNames内的名称。 | 231 232**返回值:** 233 234| 类型 | 说明 | 235| --------------------------- | ---------------------- | 236| [ColumnType](arkts-apis-data-relationalStore-e.md#columntype18) | 返回指定列的数据类型。 | 237 238**错误码:** 239 240以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 241 242| **错误码ID** | **错误信息** | 243| ------------ | ------------------------------------------------------------ | 244| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 245| 14800000 | Inner error. | 246| 14800011 | Failed to open the database because it is corrupted. | 247| 14800012 | ResultSet is empty or pointer index is out of bounds. | 248| 14800013 | ResultSet is empty or column index is out of bounds. | 249| 14800014 | The RdbStore or ResultSet is already closed. | 250| 14800019 | The SQL must be a query statement. | 251| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 252| 14800022 | SQLite: Callback routine requested an abort. | 253| 14800023 | SQLite: Access permission denied. | 254| 14800024 | SQLite: The database file is locked. | 255| 14800025 | SQLite: A table in the database is locked. | 256| 14800026 | SQLite: The database is out of memory. | 257| 14800027 | SQLite: Attempt to write a readonly database. | 258| 14800028 | SQLite: Some kind of disk I/O error occurred. | 259| 14800029 | SQLite: The database is full. | 260| 14800030 | SQLite: Unable to open the database file. | 261| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 262| 14800032 | SQLite: Abort due to constraint violation. | 263| 14800033 | SQLite: Data type mismatch. | 264| 14800034 | SQLite: Library used incorrectly. | 265 266**示例:** 267 268```ts 269if (resultSet != undefined) { 270 let idType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("ID") as relationalStore.ColumnType; 271 let nameType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("NAME") as relationalStore.ColumnType; 272 let ageType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("AGE") as relationalStore.ColumnType; 273 let salaryType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("SALARY") as relationalStore.ColumnType; 274 let codesType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("CODES") as relationalStore.ColumnType; 275 let identityType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(5) as relationalStore.ColumnType; 276 let assetDataType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(6) as relationalStore.ColumnType; 277 let assetsDataType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(7) as relationalStore.ColumnType; 278 let floatArrayType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(8) as relationalStore.ColumnType; 279} 280``` 281 282## goTo 283 284goTo(offset:number): boolean 285 286指定相对当前结果集指针位置的偏移量,以移动结果集的指针位置。 287 288**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 289 290**参数:** 291 292| 参数名 | 类型 | 必填 | 说明 | 293| ------ | ------ | ---- | ---------------------------- | 294| offset | number | 是 | 表示相对当前结果集指针位置的偏移量,正值表示向后移动,负值表示向前移动。 | 295 296**返回值:** 297 298| 类型 | 说明 | 299| ------- | --------------------------------------------- | 300| boolean | 如果成功移动结果集,则为true;否则返回false。 | 301 302**错误码:** 303 304以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 305 306| **错误码ID** | **错误信息** | 307|-----------| ------------------------------------------------------------ | 308| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 309| 14800000 | Inner error. | 310| 14800011 | Failed to open the database because it is corrupted. | 311| 14800012 | ResultSet is empty or pointer index is out of bounds. | 312| 14800014 | The RdbStore or ResultSet is already closed. | 313| 14800019 | The SQL must be a query statement. | 314| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 315| 14800022 | SQLite: Callback routine requested an abort. | 316| 14800023 | SQLite: Access permission denied. | 317| 14800024 | SQLite: The database file is locked. | 318| 14800025 | SQLite: A table in the database is locked. | 319| 14800026 | SQLite: The database is out of memory. | 320| 14800027 | SQLite: Attempt to write a readonly database. | 321| 14800028 | SQLite: Some kind of disk I/O error occurred. | 322| 14800029 | SQLite: The database is full. | 323| 14800030 | SQLite: Unable to open the database file. | 324| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 325| 14800032 | SQLite: Abort due to constraint violation. | 326| 14800033 | SQLite: Data type mismatch. | 327| 14800034 | SQLite: Library used incorrectly. | 328 329**示例:** 330 331```ts 332if (resultSet != undefined) { 333 (resultSet as relationalStore.ResultSet).goTo(1); 334} 335``` 336 337## goToRow 338 339goToRow(position: number): boolean 340 341转到结果集的指定行。 342 343**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 344 345**参数:** 346 347| 参数名 | 类型 | 必填 | 说明 | 348| -------- | ------ | ---- | ------------------------ | 349| position | number | 是 | 表示要移动到的指定位置。 | 350 351**返回值:** 352 353| 类型 | 说明 | 354| ------- | --------------------------------------------- | 355| boolean | 如果成功移动结果集,则为true;否则返回false。 | 356 357**错误码:** 358 359以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 360 361| **错误码ID** | **错误信息** | 362|-----------| ------------------------------------------------------------ | 363| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 364| 14800000 | Inner error. | 365| 14800011 | Failed to open the database because it is corrupted. | 366| 14800012 | ResultSet is empty or pointer index is out of bounds. | 367| 14800014 | The RdbStore or ResultSet is already closed. | 368| 14800019 | The SQL must be a query statement. | 369| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 370| 14800022 | SQLite: Callback routine requested an abort. | 371| 14800023 | SQLite: Access permission denied. | 372| 14800024 | SQLite: The database file is locked. | 373| 14800025 | SQLite: A table in the database is locked. | 374| 14800026 | SQLite: The database is out of memory. | 375| 14800027 | SQLite: Attempt to write a readonly database. | 376| 14800028 | SQLite: Some kind of disk I/O error occurred. | 377| 14800029 | SQLite: The database is full. | 378| 14800030 | SQLite: Unable to open the database file. | 379| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 380| 14800032 | SQLite: Abort due to constraint violation. | 381| 14800033 | SQLite: Data type mismatch. | 382| 14800034 | SQLite: Library used incorrectly. | 383 384**示例:** 385 386```ts 387if (resultSet != undefined) { 388 (resultSet as relationalStore.ResultSet).goToRow(5); 389} 390``` 391 392## goToFirstRow 393 394goToFirstRow(): boolean 395 396 397转到结果集的第一行。 398 399**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 400 401**返回值:** 402 403| 类型 | 说明 | 404| ------- | --------------------------------------------- | 405| boolean | 如果成功移动结果集,则为true;否则返回false。 | 406 407**错误码:** 408 409以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 410 411| **错误码ID** | **错误信息** | 412|-----------| ------------------------------------------------------------ | 413| 14800000 | Inner error. | 414| 14800011 | Failed to open the database because it is corrupted. | 415| 14800012 | ResultSet is empty or pointer index is out of bounds. | 416| 14800014 | The RdbStore or ResultSet is already closed. | 417| 14800019 | The SQL must be a query statement. | 418| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 419| 14800022 | SQLite: Callback routine requested an abort. | 420| 14800023 | SQLite: Access permission denied. | 421| 14800024 | SQLite: The database file is locked. | 422| 14800025 | SQLite: A table in the database is locked. | 423| 14800026 | SQLite: The database is out of memory. | 424| 14800027 | SQLite: Attempt to write a readonly database. | 425| 14800028 | SQLite: Some kind of disk I/O error occurred. | 426| 14800029 | SQLite: The database is full. | 427| 14800030 | SQLite: Unable to open the database file. | 428| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 429| 14800032 | SQLite: Abort due to constraint violation. | 430| 14800033 | SQLite: Data type mismatch. | 431| 14800034 | SQLite: Library used incorrectly. | 432 433**示例:** 434 435```ts 436if (resultSet != undefined) { 437 (resultSet as relationalStore.ResultSet).goToFirstRow(); 438} 439``` 440 441## goToLastRow 442 443goToLastRow(): boolean 444 445转到结果集的最后一行。 446 447**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 448 449**返回值:** 450 451| 类型 | 说明 | 452| ------- | --------------------------------------------- | 453| boolean | 如果成功移动结果集,则为true;否则返回false。 | 454 455**错误码:** 456 457以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 458 459| **错误码ID** | **错误信息** | 460|-----------| ------------------------------------------------------------ | 461| 14800000 | Inner error. | 462| 14800011 | Failed to open the database because it is corrupted. | 463| 14800012 | ResultSet is empty or pointer index is out of bounds. | 464| 14800014 | The RdbStore or ResultSet is already closed. | 465| 14800019 | The SQL must be a query statement. | 466| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 467| 14800022 | SQLite: Callback routine requested an abort. | 468| 14800023 | SQLite: Access permission denied. | 469| 14800024 | SQLite: The database file is locked. | 470| 14800025 | SQLite: A table in the database is locked. | 471| 14800026 | SQLite: The database is out of memory. | 472| 14800027 | SQLite: Attempt to write a readonly database. | 473| 14800028 | SQLite: Some kind of disk I/O error occurred. | 474| 14800029 | SQLite: The database is full. | 475| 14800030 | SQLite: Unable to open the database file. | 476| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 477| 14800032 | SQLite: Abort due to constraint violation. | 478| 14800033 | SQLite: Data type mismatch. | 479| 14800034 | SQLite: Library used incorrectly. | 480 481**示例:** 482 483```ts 484if (resultSet != undefined) { 485 (resultSet as relationalStore.ResultSet).goToLastRow(); 486} 487``` 488 489## goToNextRow 490 491goToNextRow(): boolean 492 493转到结果集的下一行。 494 495**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 496 497**返回值:** 498 499| 类型 | 说明 | 500| ------- | --------------------------------------------- | 501| boolean | 如果成功移动结果集,则为true;否则返回false。 | 502 503**错误码:** 504 505以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 506 507| **错误码ID** | **错误信息** | 508|-----------| ------------------------------------------------------------ | 509| 14800000 | Inner error. | 510| 14800011 | Failed to open the database because it is corrupted. | 511| 14800012 | ResultSet is empty or pointer index is out of bounds. | 512| 14800014 | The RdbStore or ResultSet is already closed. | 513| 14800019 | The SQL must be a query statement. | 514| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 515| 14800022 | SQLite: Callback routine requested an abort. | 516| 14800023 | SQLite: Access permission denied. | 517| 14800024 | SQLite: The database file is locked. | 518| 14800025 | SQLite: A table in the database is locked. | 519| 14800026 | SQLite: The database is out of memory. | 520| 14800027 | SQLite: Attempt to write a readonly database. | 521| 14800028 | SQLite: Some kind of disk I/O error occurred. | 522| 14800029 | SQLite: The database is full. | 523| 14800030 | SQLite: Unable to open the database file. | 524| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 525| 14800032 | SQLite: Abort due to constraint violation. | 526| 14800033 | SQLite: Data type mismatch. | 527| 14800034 | SQLite: Library used incorrectly. | 528 529**示例:** 530 531```ts 532if (resultSet != undefined) { 533 (resultSet as relationalStore.ResultSet).goToNextRow(); 534} 535``` 536 537## goToPreviousRow 538 539goToPreviousRow(): boolean 540 541转到结果集的上一行。 542 543**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 544 545**返回值:** 546 547| 类型 | 说明 | 548| ------- | --------------------------------------------- | 549| boolean | 如果成功移动结果集,则为true;否则返回false。 | 550 551**错误码:** 552 553以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 554 555| **错误码ID** | **错误信息** | 556|-----------| ------------------------------------------------------------ | 557| 14800000 | Inner error. | 558| 14800011 | Failed to open the database because it is corrupted. | 559| 14800012 | ResultSet is empty or pointer index is out of bounds. | 560| 14800014 | The RdbStore or ResultSet is already closed. | 561| 14800019 | The SQL must be a query statement. | 562| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 563| 14800022 | SQLite: Callback routine requested an abort. | 564| 14800023 | SQLite: Access permission denied. | 565| 14800024 | SQLite: The database file is locked. | 566| 14800025 | SQLite: A table in the database is locked. | 567| 14800026 | SQLite: The database is out of memory. | 568| 14800027 | SQLite: Attempt to write a readonly database. | 569| 14800028 | SQLite: Some kind of disk I/O error occurred. | 570| 14800029 | SQLite: The database is full. | 571| 14800030 | SQLite: Unable to open the database file. | 572| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 573| 14800032 | SQLite: Abort due to constraint violation. | 574| 14800033 | SQLite: Data type mismatch. | 575| 14800034 | SQLite: Library used incorrectly. | 576 577**示例:** 578 579```ts 580if (resultSet != undefined) { 581 (resultSet as relationalStore.ResultSet).goToPreviousRow(); 582} 583``` 584 585## getValue<sup>12+</sup> 586 587getValue(columnIndex: number): ValueType 588 589获取当前行中指定列的值,如果值类型是ValueType中指定的任意类型,返回指定类型的值,否则返回14800000。如果值类型为INTEGER,值大于 Number.MAX_SAFE_INTEGER 或小于 Number.MIN_SAFE_INTEGER 且不希望丢失精度,建议使用[getString](#getstring)接口获取。 590 591**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 592 593**参数:** 594 595| 参数名 | 类型 | 必填 | 说明 | 596| ----------- | ------ | ---- | ----------------------- | 597| columnIndex | number | 是 | 指定的列索引,从0开始。 | 598 599**返回值:** 600 601| 类型 | 说明 | 602| ---------- | -------------------------------- | 603| [ValueType](arkts-apis-data-relationalStore-t.md#valuetype) | 表示允许的数据字段类型。 | 604 605**错误码:** 606 607以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 608 609| **错误码ID** | **错误信息** | 610|-----------|---------| 611| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 612| 14800000 | Inner error. | 613| 14800011 | Failed to open the database because it is corrupted. | 614| 14800012 | ResultSet is empty or pointer index is out of bounds. | 615| 14800013 | ResultSet is empty or column index is out of bounds. | 616| 14800014 | The RdbStore or ResultSet is already closed. | 617| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 618| 14800022 | SQLite: Callback routine requested an abort. | 619| 14800023 | SQLite: Access permission denied. | 620| 14800024 | SQLite: The database file is locked. | 621| 14800025 | SQLite: A table in the database is locked. | 622| 14800026 | SQLite: The database is out of memory. | 623| 14800027 | SQLite: Attempt to write a readonly database. | 624| 14800028 | SQLite: Some kind of disk I/O error occurred. | 625| 14800029 | SQLite: The database is full. | 626| 14800030 | SQLite: Unable to open the database file. | 627| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 628| 14800032 | SQLite: Abort due to constraint violation. | 629| 14800033 | SQLite: Data type mismatch. | 630| 14800034 | SQLite: Library used incorrectly. | 631 632**示例:** 633 634```ts 635if (resultSet != undefined) { 636 const codes = (resultSet as relationalStore.ResultSet).getValue((resultSet as relationalStore.ResultSet).getColumnIndex("BIGINT_COLUMN")); 637} 638``` 639 640## getBlob 641 642getBlob(columnIndex: number): Uint8Array 643 644 645以字节数组的形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成字节数组类型返回指定值,如果该列内容为空时,会返回空字节数组,其他类型则返回14800000。 646 647**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 648 649**参数:** 650 651| 参数名 | 类型 | 必填 | 说明 | 652| ----------- | ------ | ---- | ----------------------- | 653| columnIndex | number | 是 | 指定的列索引,从0开始。 | 654 655**返回值:** 656 657| 类型 | 说明 | 658| ---------- | -------------------------------- | 659| Uint8Array | 以字节数组的形式返回指定列的值。 | 660 661**错误码:** 662 663以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 664 665| **错误码ID** | **错误信息** | 666|-----------| ------------------------------------------------------------ | 667| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 668| 14800000 | Inner error. | 669| 14800011 | Failed to open the database because it is corrupted. | 670| 14800012 | ResultSet is empty or pointer index is out of bounds. | 671| 14800013 | ResultSet is empty or column index is out of bounds. | 672| 14800014 | The RdbStore or ResultSet is already closed. | 673| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 674| 14800022 | SQLite: Callback routine requested an abort. | 675| 14800023 | SQLite: Access permission denied. | 676| 14800024 | SQLite: The database file is locked. | 677| 14800025 | SQLite: A table in the database is locked. | 678| 14800026 | SQLite: The database is out of memory. | 679| 14800027 | SQLite: Attempt to write a readonly database. | 680| 14800028 | SQLite: Some kind of disk I/O error occurred. | 681| 14800029 | SQLite: The database is full. | 682| 14800030 | SQLite: Unable to open the database file. | 683| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 684| 14800032 | SQLite: Abort due to constraint violation. | 685| 14800033 | SQLite: Data type mismatch. | 686| 14800034 | SQLite: Library used incorrectly. | 687 688**示例:** 689 690```ts 691if (resultSet != undefined) { 692 const codes = (resultSet as relationalStore.ResultSet).getBlob((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 693} 694``` 695 696## getString 697 698getString(columnIndex: number): string 699 700以字符串形式获取当前行中指定列的值,如果当前列中的值为INTEGER、DOUBLE、TEXT、BLOB类型,会以字符串形式返回指定值,如果是当前列中的值为INTEGER,并且为空,则会返回空字符串"",其他类型则返回14800000。如果当前列中的值为DOUBLE类型,可能存在精度的丢失,建议使用[getDouble](#getdouble)接口获取。 701 702**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 703 704**参数:** 705 706| 参数名 | 类型 | 必填 | 说明 | 707| ----------- | ------ | ---- | ----------------------- | 708| columnIndex | number | 是 | 指定的列索引,从0开始。 | 709 710**返回值:** 711 712| 类型 | 说明 | 713| ------ | ---------------------------- | 714| string | 以字符串形式返回指定列的值。 | 715 716**错误码:** 717 718以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 719 720| **错误码ID** | **错误信息** | 721|-----------| ------------------------------------------------------------ | 722| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 723| 14800000 | Inner error. | 724| 14800011 | Failed to open the database because it is corrupted. | 725| 14800012 | ResultSet is empty or pointer index is out of bounds. | 726| 14800013 | ResultSet is empty or column index is out of bounds. | 727| 14800014 | The RdbStore or ResultSet is already closed. | 728| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 729| 14800022 | SQLite: Callback routine requested an abort. | 730| 14800023 | SQLite: Access permission denied. | 731| 14800024 | SQLite: The database file is locked. | 732| 14800025 | SQLite: A table in the database is locked. | 733| 14800026 | SQLite: The database is out of memory. | 734| 14800027 | SQLite: Attempt to write a readonly database. | 735| 14800028 | SQLite: Some kind of disk I/O error occurred. | 736| 14800029 | SQLite: The database is full. | 737| 14800030 | SQLite: Unable to open the database file. | 738| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 739| 14800032 | SQLite: Abort due to constraint violation. | 740| 14800033 | SQLite: Data type mismatch. | 741| 14800034 | SQLite: Library used incorrectly. | 742 743**示例:** 744 745```ts 746if (resultSet != undefined) { 747 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 748} 749``` 750 751## getLong 752 753getLong(columnIndex: number): number 754 755以Long形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成Long类型返回指定值,如果该列内容为空时,会返回0,其他类型则返回14800000。如果当前列的数据类型为INTEGER,值大于 Number.MAX_SAFE_INTEGER 或小于 Number.MIN_SAFE_INTEGER 且不希望丢失精度,建议使用[getString](#getstring)接口获取。如果当前列的数据类型为DOUBLE且不希望丢失精度,建议使用[getDouble](#getdouble)接口获取。 756 757**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 758 759**参数:** 760 761| 参数名 | 类型 | 必填 | 说明 | 762| ----------- | ------ | ---- | ----------------------- | 763| columnIndex | number | 是 | 指定的列索引,从0开始。 | 764 765**返回值:** 766 767| 类型 | 说明 | 768| ------ | ------------------------------------------------------------ | 769| number | 以Long形式返回指定列的值。<br>该接口支持的精度范围是:Number.MIN_SAFE_INTEGER ~ Number.MAX_SAFE_INTEGER,若超出该范围,建议对于DOUBLE类型的值使用[getDouble](#getdouble),对于INTEGER类型的值使用[getString](#getstring)。 | 770 771**错误码:** 772 773以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 774 775| **错误码ID** | **错误信息** | 776|-----------| ------------------------------------------------------------ | 777| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 778| 14800000 | Inner error. | 779| 14800011 | Failed to open the database because it is corrupted. | 780| 14800012 | ResultSet is empty or pointer index is out of bounds. | 781| 14800013 | ResultSet is empty or column index is out of bounds. | 782| 14800014 | The RdbStore or ResultSet is already closed. | 783| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 784| 14800022 | SQLite: Callback routine requested an abort. | 785| 14800023 | SQLite: Access permission denied. | 786| 14800024 | SQLite: The database file is locked. | 787| 14800025 | SQLite: A table in the database is locked. | 788| 14800026 | SQLite: The database is out of memory. | 789| 14800027 | SQLite: Attempt to write a readonly database. | 790| 14800028 | SQLite: Some kind of disk I/O error occurred. | 791| 14800029 | SQLite: The database is full. | 792| 14800030 | SQLite: Unable to open the database file. | 793| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 794| 14800032 | SQLite: Abort due to constraint violation. | 795| 14800033 | SQLite: Data type mismatch. | 796| 14800034 | SQLite: Library used incorrectly. | 797 798**示例:** 799 800```ts 801if (resultSet != undefined) { 802 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 803} 804``` 805 806## getDouble 807 808getDouble(columnIndex: number): number 809 810以double形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成double类型返回指定值,如果该列内容为空时,会返回0.0,其他类型则返回14800000。 811 812**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 813 814**参数:** 815 816| 参数名 | 类型 | 必填 | 说明 | 817| ----------- | ------ | ---- | ----------------------- | 818| columnIndex | number | 是 | 指定的列索引,从0开始。 | 819 820**返回值:** 821 822| 类型 | 说明 | 823| ------ | ---------------------------- | 824| number | 以double形式返回指定列的值。 | 825 826**错误码:** 827 828以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 829 830| **错误码ID** | **错误信息** | 831|-----------| ------------------------------------------------------------ | 832| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 833| 14800000 | Inner error. | 834| 14800011 | Failed to open the database because it is corrupted. | 835| 14800012 | ResultSet is empty or pointer index is out of bounds. | 836| 14800013 | ResultSet is empty or column index is out of bounds. | 837| 14800014 | The RdbStore or ResultSet is already closed. | 838| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 839| 14800022 | SQLite: Callback routine requested an abort. | 840| 14800023 | SQLite: Access permission denied. | 841| 14800024 | SQLite: The database file is locked. | 842| 14800025 | SQLite: A table in the database is locked. | 843| 14800026 | SQLite: The database is out of memory. | 844| 14800027 | SQLite: Attempt to write a readonly database. | 845| 14800028 | SQLite: Some kind of disk I/O error occurred. | 846| 14800029 | SQLite: The database is full. | 847| 14800030 | SQLite: Unable to open the database file. | 848| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 849| 14800032 | SQLite: Abort due to constraint violation. | 850| 14800033 | SQLite: Data type mismatch. | 851| 14800034 | SQLite: Library used incorrectly. | 852 853**示例:** 854 855```ts 856if (resultSet != undefined) { 857 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 858} 859``` 860 861## getAsset<sup>10+</sup> 862 863getAsset(columnIndex: number): Asset 864 865以[Asset](arkts-apis-data-relationalStore-i.md#asset10)形式获取当前行中指定列的值,如果当前列的数据类型为Asset类型,会以Asset类型返回指定值,如果当前列中的值为null时,会返回null,其他类型则返回14800000。 866 867**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 868 869**参数:** 870 871| 参数名 | 类型 | 必填 | 说明 | 872| ----------- | ------ | --- | ------------ | 873| columnIndex | number | 是 | 指定的列索引,从0开始。 | 874 875**返回值:** 876 877| 类型 | 说明 | 878| --------------- | -------------------------- | 879| [Asset](arkts-apis-data-relationalStore-i.md#asset10) | 以Asset形式返回指定列的值。 | 880 881**错误码:** 882 883以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 884 885| **错误码ID** | **错误信息** | 886|-----------| ------------------------------------------------------------ | 887| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 888| 14800000 | Inner error. | 889| 14800011 | Failed to open the database because it is corrupted. | 890| 14800012 | ResultSet is empty or pointer index is out of bounds. | 891| 14800013 | ResultSet is empty or column index is out of bounds. | 892| 14800014 | The RdbStore or ResultSet is already closed. | 893| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 894| 14800022 | SQLite: Callback routine requested an abort. | 895| 14800023 | SQLite: Access permission denied. | 896| 14800024 | SQLite: The database file is locked. | 897| 14800025 | SQLite: A table in the database is locked. | 898| 14800026 | SQLite: The database is out of memory. | 899| 14800027 | SQLite: Attempt to write a readonly database. | 900| 14800028 | SQLite: Some kind of disk I/O error occurred. | 901| 14800029 | SQLite: The database is full. | 902| 14800030 | SQLite: Unable to open the database file. | 903| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 904| 14800032 | SQLite: Abort due to constraint violation. | 905| 14800033 | SQLite: Data type mismatch. | 906| 14800034 | SQLite: Library used incorrectly. | 907 908**示例:** 909 910```ts 911if (resultSet != undefined) { 912 const doc = (resultSet as relationalStore.ResultSet).getAsset((resultSet as relationalStore.ResultSet).getColumnIndex("DOC")); 913} 914``` 915 916## getAssets<sup>10+</sup> 917 918getAssets(columnIndex: number): Assets 919 920以[Assets](arkts-apis-data-relationalStore-t.md#assets10)形式获取当前行中指定列的值,如果当前列的数据类型为Assets类型,会以Assets类型返回指定值,如果当前列中的值为null时,会返回null,其他类型则返回14800000。 921 922**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 923 924**参数:** 925 926| 参数名 | 类型 | 必填 | 说明 | 927| ----------- | ------ | --- | ------------ | 928| columnIndex | number | 是 | 指定的列索引,从0开始。 | 929 930**返回值:** 931 932| 类型 | 说明 | 933| ---------------- | ---------------------------- | 934| [Assets](arkts-apis-data-relationalStore-t.md#assets10)| 以Assets形式返回指定列的值。 | 935 936**错误码:** 937 938以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 939 940| **错误码ID** | **错误信息** | 941|-----------| ------------------------------------------------------------ | 942| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 943| 14800000 | Inner error. | 944| 14800011 | Failed to open the database because it is corrupted. | 945| 14800012 | ResultSet is empty or pointer index is out of bounds. | 946| 14800013 | ResultSet is empty or column index is out of bounds. | 947| 14800014 | The RdbStore or ResultSet is already closed. | 948| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 949| 14800022 | SQLite: Callback routine requested an abort. | 950| 14800023 | SQLite: Access permission denied. | 951| 14800024 | SQLite: The database file is locked. | 952| 14800025 | SQLite: A table in the database is locked. | 953| 14800026 | SQLite: The database is out of memory. | 954| 14800027 | SQLite: Attempt to write a readonly database. | 955| 14800028 | SQLite: Some kind of disk I/O error occurred. | 956| 14800029 | SQLite: The database is full. | 957| 14800030 | SQLite: Unable to open the database file. | 958| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 959| 14800032 | SQLite: Abort due to constraint violation. | 960| 14800033 | SQLite: Data type mismatch. | 961| 14800034 | SQLite: Library used incorrectly. | 962 963**示例:** 964 965```ts 966if (resultSet != undefined) { 967 const docs = (resultSet as relationalStore.ResultSet).getAssets((resultSet as relationalStore.ResultSet).getColumnIndex("DOCS")); 968} 969``` 970 971## getRow<sup>11+</sup> 972 973getRow(): ValuesBucket 974 975获取当前行。 976 977**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 978 979**返回值:** 980 981| 类型 | 说明 | 982| ---------------- | ---------------------------- | 983| [ValuesBucket](arkts-apis-data-relationalStore-t.md#valuesbucket) | 返回指定行的值。 | 984 985**错误码:** 986 987以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 988 989| **错误码ID** | **错误信息** | 990|-----------| ------------------------------------------------------------ | 991| 14800000 | Inner error. | 992| 14800011 | Failed to open the database because it is corrupted. | 993| 14800012 | ResultSet is empty or pointer index is out of bounds. | 994| 14800013 | ResultSet is empty or column index is out of bounds. | 995| 14800014 | The RdbStore or ResultSet is already closed. | 996| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 997| 14800022 | SQLite: Callback routine requested an abort. | 998| 14800023 | SQLite: Access permission denied. | 999| 14800024 | SQLite: The database file is locked. | 1000| 14800025 | SQLite: A table in the database is locked. | 1001| 14800026 | SQLite: The database is out of memory. | 1002| 14800027 | SQLite: Attempt to write a readonly database. | 1003| 14800028 | SQLite: Some kind of disk I/O error occurred. | 1004| 14800029 | SQLite: The database is full. | 1005| 14800030 | SQLite: Unable to open the database file. | 1006| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 1007| 14800032 | SQLite: Abort due to constraint violation. | 1008| 14800033 | SQLite: Data type mismatch. | 1009| 14800034 | SQLite: Library used incorrectly. | 1010 1011**示例:** 1012 1013```ts 1014if (resultSet != undefined) { 1015 const row = (resultSet as relationalStore.ResultSet).getRow(); 1016} 1017``` 1018 1019## getRows<sup>18+</sup> 1020 1021getRows(maxCount: number, position?: number): Promise<Array\<ValuesBucket>> 1022 1023从结果集中获取指定数量的数据,使用Promise异步回调。禁止与[ResultSet](arkts-apis-data-relationalStore-ResultSet.md)的其他接口并发调用,否则获取的数据可能非预期。 1024 1025**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1026 1027**参数:** 1028 1029| 参数名 | 类型 | 必填 | 说明 | 1030| ----------- | ------ | ---- | ----------------------- | 1031| maxCount | number | 是 | 正整数,指定要从结果集中获取数据的条数。不为正整数则参数非法,抛出错误码401。 | 1032| position | number | 否 | 非负整数,指定从结果集中获取数据的起始位置,不填则从结果集的当前行(默认首次获取数据时为当前结果集的第一行)开始获取数据。不为非负整数则参数非法,抛出错误码401。 | 1033 1034 1035**返回值:** 1036 1037| 类型 | 说明 | 1038| ---------------- | ---------------------------- | 1039| Promise<Array<[ValuesBucket](arkts-apis-data-relationalStore-t.md#valuesbucket)>> | 返回maxCount条数据,剩余数据不足maxCount条则返回剩余数据,返回空数组时代表已经遍历到结果集的末尾。 | 1040 1041**错误码:** 1042 1043以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 1044 1045| **错误码ID** | **错误信息** | 1046|-----------| ------------------------------------------------------------ | 1047| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1048| 14800000 | Inner error. | 1049| 14800011 | Failed to open the database because it is corrupted. | 1050| 14800012 | ResultSet is empty or pointer index is out of bounds. | 1051| 14800013 | ResultSet is empty or column index is out of bounds. | 1052| 14800014 | The RdbStore or ResultSet is already closed. | 1053| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 1054| 14800022 | SQLite: Callback routine requested an abort. | 1055| 14800023 | SQLite: Access permission denied. | 1056| 14800024 | SQLite: The database file is locked. | 1057| 14800025 | SQLite: A table in the database is locked. | 1058| 14800026 | SQLite: The database is out of memory. | 1059| 14800028 | SQLite: Some kind of disk I/O error occurred. | 1060| 14800029 | SQLite: The database is full. | 1061| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 1062| 14800032 | SQLite: Abort due to constraint violation. | 1063| 14800033 | SQLite: Data type mismatch. | 1064 1065**示例:** 1066 1067```ts 1068// 以查到100条数据为例 1069async function proccessRows(resultSet: relationalStore.ResultSet) { 1070 // 示例1:仅指定maxCount 1071 if (resultSet != undefined) { 1072 let rows: Array<relationalStore.ValuesBucket>; 1073 let maxCount: number = 50; 1074 // 从结果集的当前行(默认首次获取数据时为当前结果集的第一行,后续为上次获取数据结束位置的下一行)开始获取数据 1075 // getRows会自动移动结果集当前行到上次getRows获取结束位置的下一行,无需使用goToFirstRow、goToNextRow等接口移动 1076 while ((rows = await (resultSet as relationalStore.ResultSet).getRows(maxCount)).length != 0) { 1077 console.info(JSON.stringify(rows[0])); 1078 } 1079 } 1080 1081 // 示例2:指定maxCount和起始的position 1082 if (resultSet != undefined) { 1083 let rows: Array<relationalStore.ValuesBucket>; 1084 let maxCount: number = 50; 1085 let position: number = 50; 1086 while ((rows = await (resultSet as relationalStore.ResultSet).getRows(maxCount, position)).length != 0) { 1087 console.info(JSON.stringify(rows[0])); 1088 position += rows.length; 1089 } 1090 } 1091} 1092``` 1093 1094## getSendableRow<sup>12+</sup> 1095 1096getSendableRow(): sendableRelationalStore.ValuesBucket 1097 1098获取当前行数据的sendable形式,用于跨线程传递。 1099 1100**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1101 1102**返回值:** 1103 1104| 类型 | 说明 | 1105| ---------------------------------------------------------------------------------------------- | -------------------------------------------- | 1106| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | 当前行数据的sendable形式,用于跨线程传递。 | 1107 1108**错误码:** 1109 1110以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 1111 1112| **错误码ID** | **错误信息** | 1113| ------------ | --------------------------------------------- | 1114| 14800000 | Inner error. | 1115| 14800011 | Failed to open the database because it is corrupted. | 1116| 14800012 | ResultSet is empty or pointer index is out of bounds. | 1117| 14800013 | ResultSet is empty or column index is out of bounds. | 1118| 14800014 | The RdbStore or ResultSet is already closed. | 1119| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 1120| 14800022 | SQLite: Callback routine requested an abort. | 1121| 14800023 | SQLite: Access permission denied. | 1122| 14800024 | SQLite: The database file is locked. | 1123| 14800025 | SQLite: A table in the database is locked. | 1124| 14800026 | SQLite: The database is out of memory. | 1125| 14800027 | SQLite: Attempt to write a readonly database. | 1126| 14800028 | SQLite: Some kind of disk I/O error occurred. | 1127| 14800029 | SQLite: The database is full. | 1128| 14800030 | SQLite: Unable to open the database file. | 1129| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 1130| 14800032 | SQLite: Abort due to constraint violation. | 1131| 14800033 | SQLite: Data type mismatch. | 1132| 14800034 | SQLite: Library used incorrectly. | 1133 1134**示例:** 1135 1136<!--code_no_check--> 1137```ts 1138import { window } from '@kit.ArkUI'; 1139import { UIAbility } from '@kit.AbilityKit'; 1140import { relationalStore } from '@kit.ArkData'; 1141import { taskpool } from '@kit.ArkTS'; 1142import type ctx from '@ohos.app.ability.common'; 1143import { sendableRelationalStore } from '@kit.ArkData'; 1144 1145@Concurrent 1146async function getDataByName(name: string, context: ctx.UIAbilityContext) { 1147 const STORE_CONFIG: relationalStore.StoreConfig = { 1148 name: "RdbTest.db", 1149 securityLevel: relationalStore.SecurityLevel.S3 1150 }; 1151 const store = await relationalStore.getRdbStore(context, STORE_CONFIG); 1152 const predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1153 predicates.equalTo("NAME", name); 1154 const resultSet = store.querySync(predicates); 1155 1156 if (resultSet.rowCount > 0) { 1157 resultSet.goToFirstRow(); 1158 const sendableValuesBucket = resultSet.getSendableRow(); 1159 return sendableValuesBucket; 1160 } else { 1161 return null; 1162 } 1163} 1164 1165export default class EntryAbility extends UIAbility { 1166 async onWindowStageCreate(windowStage: window.WindowStage) { 1167 const task = new taskpool.Task(getDataByName, 'Lisa', this.context); 1168 const sendableValuesBucket = await taskpool.execute(task) as sendableRelationalStore.ValuesBucket; 1169 1170 if (sendableValuesBucket) { 1171 const columnCount = sendableValuesBucket.size; 1172 const age = sendableValuesBucket.get('age'); 1173 const name = sendableValuesBucket.get('name'); 1174 console.info(`Query data in taskpool succeeded, name is "${name}", age is "${age}"`); 1175 } 1176 } 1177} 1178``` 1179 1180## isColumnNull 1181 1182isColumnNull(columnIndex: number): boolean 1183 1184检查当前行中指定列的值是否为null。 1185 1186**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1187 1188**参数:** 1189 1190| 参数名 | 类型 | 必填 | 说明 | 1191| ----------- | ------ | ---- | ----------------------- | 1192| columnIndex | number | 是 | 指定的列索引,从0开始。 | 1193 1194**返回值:** 1195 1196| 类型 | 说明 | 1197| ------- | --------------------------------------------------------- | 1198| boolean | 如果当前行中指定列的值为null,则返回true,否则返回false。 | 1199 1200**错误码:** 1201 1202以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 1203 1204| **错误码ID** | **错误信息** | 1205|-----------| ------------------------------------------------------- | 1206| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1207| 14800000 | Inner error. | 1208| 14800011 | Failed to open the database because it is corrupted. | 1209| 14800012 | ResultSet is empty or pointer index is out of bounds. | 1210| 14800013 | ResultSet is empty or column index is out of bounds. | 1211| 14800014 | The RdbStore or ResultSet is already closed. | 1212| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 1213| 14800022 | SQLite: Callback routine requested an abort. | 1214| 14800023 | SQLite: Access permission denied. | 1215| 14800024 | SQLite: The database file is locked. | 1216| 14800025 | SQLite: A table in the database is locked. | 1217| 14800026 | SQLite: The database is out of memory. | 1218| 14800027 | SQLite: Attempt to write a readonly database. | 1219| 14800028 | SQLite: Some kind of disk I/O error occurred. | 1220| 14800029 | SQLite: The database is full. | 1221| 14800030 | SQLite: Unable to open the database file. | 1222| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 1223| 14800032 | SQLite: Abort due to constraint violation. | 1224| 14800033 | SQLite: Data type mismatch. | 1225| 14800034 | SQLite: Library used incorrectly. | 1226 1227**示例:** 1228 1229```ts 1230if (resultSet != undefined) { 1231 const isColumnNull = (resultSet as relationalStore.ResultSet).isColumnNull((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 1232} 1233``` 1234 1235## close 1236 1237close(): void 1238 1239关闭结果集,若不关闭可能会引起fd泄露和内存泄露。 1240 1241**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1242 1243**示例:** 1244 1245```ts 1246if (resultSet != undefined) { 1247 (resultSet as relationalStore.ResultSet).close(); 1248} 1249``` 1250 1251**错误码:** 1252 1253以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。 1254 1255| **错误码ID** | **错误信息** | 1256|-----------| ------------------------------------------------------------ | 1257| 14800000 | Inner error. | 1258| 14800012 | ResultSet is empty or pointer index is out of bounds. |