1# @ohos.data.relationalStore (RDB Store) (System API) 2 3The relational database (RDB) store manages data based on relational models. It provides a complete mechanism for managing local databases based on the underlying SQLite. To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements. The worker threads are not supported. 4ArkTS supports the following basic data types: number, string, binary data, and boolean. The maximum size of a data record is 2 MB. If a data record exceeds 2 MB, it can be inserted successfully but cannot be read. 5 6The **relationalStore** module provides the following functions: 7 8- [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates): provides predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store. 9- [RdbStore](#rdbstore): provides APIs for managing data in an RDB store. 10- [ResultSet](js-apis-data-relationalStore.md#resultset): provides APIs for accessing the result set obtained from the RDB store. 11 12> **NOTE** 13> 14> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 15> 16> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.data.relationalStore](js-apis-data-relationalStore.md). 17 18## Modules to Import 19 20```ts 21import { relationalStore } from '@kit.ArkData'; 22``` 23 24## StoreConfig 25 26Defines the configuration of an RDB store. 27 28**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 29 30| Name | Type | Mandatory| Description | 31| ------------- | ------------- | ---- | --------------------------------------------------------- | 32| isSearchable<sup>11+</sup> | boolean | No| Whether the RDB store is searchable. The value **true** means the RDB store is searchable; the value **false** means the opposite. The default value is **false**.<br>**System API**: This is a system API.<br>This parameter is supported since API version 11.| 33| haMode<sup>12+</sup> | [HAMode](#hamode12) | No| High availability (HA) mode.<br>The value **SINGLE** means data can be written only to a single RDB store. The value **MAIN_REPLICA** means data can be written to the main and replica RDB stores to ensure HA. However, this mode is not supported in encryption and attach scenarios. The default value is **SINGLE**. The value **MAIN_REPLICA** may affect the database write performance.<br>**System API**: This is a system API.<br>This parameter is supported since API version 12.<br>| 34 35## HAMode<sup>12+</sup> 36 37Enumerates the HA modes of an RDB store. 38 39**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 40 41| Name | Value | Description | 42| ------------------------------- | --- | -------------- | 43| SINGLE | 0 | Allows data to be written to a single RDB store. | 44| MAIN_REPLICA | 1 | Allows data to be written to the main and replica RDB stores for HA. This mode is not supported in encryption and attach scenarios.| 45 46## Reference<sup>11+</sup> 47 48Represents the reference between tables by field. If table **b** references table **a**, table **a** is the source table and **b** is the target table. 49 50**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 51 52**System API**: This is a system API. 53 54| Name | Type | Mandatory| Description | 55| ---------- | ------ | ---- | ---------------------------------------- | 56| sourceTable | string | Yes | Name of the table referenced. | 57| targetTable | string | Yes | Name of the table that references the source table. | 58| refFields | Record<string, string> | Yes | Fields referenced. In a KV pair, the key indicates the field in the source table, and the value indicates the field in the target table. | 59 60## DistributedConfig<sup>10+</sup> 61 62Defines the configuration of the distributed mode of tables. 63 64**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 65 66| Name | Type | Mandatory| Description | 67| -------- | ------- | ---- | ------------------------------------------------------------ | 68| references<sup>11+</sup> | Array<[Reference](#reference11)> | No | References between tables. You can reference multiple fields, and their values must be the same in the source and target tables. By default, database tables are not referenced with each other.<br>**System API**: This is a system API.<br>This parameter is supported since API version 11.| 69 70## RdbStore 71 72Provides APIs for managing data in an RDB store. 73Before using the **RdbStore** APIs, use [executeSql](js-apis-data-relationalStore.md#executesql) to initialize the database table structure and related data. 74 75### update 76 77update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>):void 78 79Updates data based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result. Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 80 81**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 82 83**Model restriction**: This API can be used only in the stage model. 84 85**System API**: This is a system API. 86 87**Parameters** 88 89| Name | Type | Mandatory| Description | 90| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 91| table | string | Yes | Name of the target table. | 92| values | [ValuesBucket](js-apis-data-relationalStore.md#valuesbucket) | Yes | Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.| 93| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Update conditions specified by the **DataSharePredicates** object. | 94| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows updated. | 95 96**Error codes** 97 98For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 99 100| **ID**| **Error Message** | 101|-----------| ------------------------------------------------------------ | 102| 202 | Permission verification failed, application which is not a system application uses system API. | 103| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 104| 14800000 | Inner error. | 105| 14800011 | Database corrupted. | 106| 14800014 | Already closed. | 107| 14800015 | The database does not respond. | 108| 14800021 | SQLite: Generic error. | 109| 14800022 | SQLite: Callback routine requested an abort. | 110| 14800023 | SQLite: Access permission denied. | 111| 14800024 | SQLite: The database file is locked. | 112| 14800025 | SQLite: A table in the database is locked. | 113| 14800026 | SQLite: The database is out of memory. | 114| 14800027 | SQLite: Attempt to write a readonly database. | 115| 14800028 | SQLite: Some kind of disk I/O error occurred. | 116| 14800029 | SQLite: The database is full. | 117| 14800030 | SQLite: Unable to open the database file. | 118| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 119| 14800032 | SQLite: Abort due to constraint violation. | 120| 14800033 | SQLite: Data type mismatch. | 121| 14800034 | SQLite: Library used incorrectly. | 122| 14800047 | The WAL file size exceeds the default limit. | 123 124**Example** 125 126```ts 127import { dataSharePredicates } from '@kit.ArkData'; 128import { ValuesBucket } from '@kit.ArkData'; 129 130let value1 = "Rose"; 131let value2 = 22; 132let value3 = 200.5; 133let value4 = new Uint8Array([1, 2, 3, 4, 5]); 134 135// You can use either of the following: 136const valueBucket1: ValuesBucket = { 137 'NAME': value1, 138 'AGE': value2, 139 'SALARY': value3, 140 'CODES': value4, 141}; 142const valueBucket2: ValuesBucket = { 143 NAME: value1, 144 AGE: value2, 145 SALARY: value3, 146 CODES: value4, 147}; 148const valueBucket3: ValuesBucket = { 149 "NAME": value1, 150 "AGE": value2, 151 "SALARY": value3, 152 "CODES": value4, 153}; 154 155let predicates = new dataSharePredicates.DataSharePredicates(); 156predicates.equalTo("NAME", "Lisa"); 157if(store != undefined) { 158 (store as relationalStore.RdbStore).update("EMPLOYEE", valueBucket1, predicates, (err, rows) => { 159 if (err) { 160 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 161 return; 162 } 163 console.info(`Updated row count: ${rows}`); 164 }) 165} 166``` 167 168### update 169 170update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates):Promise<number> 171 172Updates data based on the specified **DataSharePredicates** object. This API uses a promise to return the result. Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 173 174**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 175 176**Model restriction**: This API can be used only in the stage model. 177 178**System API**: This is a system API. 179 180**Parameters** 181 182| Name | Type | Mandatory| Description | 183| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 184| table | string | Yes | Name of the target table. | 185| values | [ValuesBucket](js-apis-data-relationalStore.md#valuesbucket) | Yes | Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.| 186| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Update conditions specified by the **DataSharePredicates** object. | 187 188**Return value** 189 190| Type | Description | 191| --------------------- | ----------------------------------------- | 192| Promise<number> | Promise used to return the number of rows updated.| 193 194**Error codes** 195 196For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 197 198| **ID**| **Error Message** | 199|-----------| ------------------------------------------------------------ | 200| 202 | Permission verification failed, application which is not a system application uses system API. | 201| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 202| 14800000 | Inner error. | 203| 14800011 | Database corrupted. | 204| 14800014 | Already closed. | 205| 14800015 | The database does not respond. | 206| 14800021 | SQLite: Generic error. | 207| 14800022 | SQLite: Callback routine requested an abort. | 208| 14800023 | SQLite: Access permission denied. | 209| 14800024 | SQLite: The database file is locked. | 210| 14800025 | SQLite: A table in the database is locked. | 211| 14800026 | SQLite: The database is out of memory. | 212| 14800027 | SQLite: Attempt to write a readonly database. | 213| 14800028 | SQLite: Some kind of disk I/O error occurred. | 214| 14800029 | SQLite: The database is full. | 215| 14800030 | SQLite: Unable to open the database file. | 216| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 217| 14800032 | SQLite: Abort due to constraint violation. | 218| 14800033 | SQLite: Data type mismatch. | 219| 14800034 | SQLite: Library used incorrectly. | 220| 14800047 | The WAL file size exceeds the default limit. | 221 222**Example** 223 224```ts 225import { dataSharePredicates } from '@kit.ArkData'; 226import { ValuesBucket } from '@kit.ArkData'; 227import { BusinessError } from '@kit.BasicServicesKit'; 228 229let value1 = "Rose"; 230let value2 = 22; 231let value3 = 200.5; 232let value4 = new Uint8Array([1, 2, 3, 4, 5]); 233 234// You can use either of the following: 235const valueBucket1: ValuesBucket = { 236 'NAME': value1, 237 'AGE': value2, 238 'SALARY': value3, 239 'CODES': value4, 240}; 241const valueBucket2: ValuesBucket = { 242 NAME: value1, 243 AGE: value2, 244 SALARY: value3, 245 CODES: value4, 246}; 247const valueBucket3: ValuesBucket = { 248 "NAME": value1, 249 "AGE": value2, 250 "SALARY": value3, 251 "CODES": value4, 252}; 253 254let predicates = new dataSharePredicates.DataSharePredicates(); 255predicates.equalTo("NAME", "Lisa"); 256if(store != undefined) { 257 (store as relationalStore.RdbStore).update("EMPLOYEE", valueBucket1, predicates).then(async (rows: Number) => { 258 console.info(`Updated row count: ${rows}`); 259 }).catch((err: BusinessError) => { 260 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 261 }) 262} 263``` 264 265### delete 266 267delete(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>):void 268 269Deletes data from the RDB store based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result. 270 271**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 272 273**Model restriction**: This API can be used only in the stage model. 274 275**System API**: This is a system API. 276 277**Parameters** 278 279| Name | Type | Mandatory| Description | 280| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- | 281| table | string | Yes | Name of the target table, which cannot be an empty string. | 282| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Conditions specified by the **DataSharePredicates** object for deleting data.| 283| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows deleted. | 284 285**Error codes** 286 287For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 288 289| **ID**| **Error Message** | 290|-----------| ------------------------------------------------------------ | 291| 202 | Permission verification failed, application which is not a system application uses system API. | 292| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 293| 14800000 | Inner error. | 294| 14800011 | Database corrupted. | 295| 14800014 | Already closed. | 296| 14800015 | The database does not respond. | 297| 14800021 | SQLite: Generic error. | 298| 14800022 | SQLite: Callback routine requested an abort. | 299| 14800023 | SQLite: Access permission denied. | 300| 14800024 | SQLite: The database file is locked. | 301| 14800025 | SQLite: A table in the database is locked. | 302| 14800026 | SQLite: The database is out of memory. | 303| 14800027 | SQLite: Attempt to write a readonly database. | 304| 14800028 | SQLite: Some kind of disk I/O error occurred. | 305| 14800029 | SQLite: The database is full. | 306| 14800030 | SQLite: Unable to open the database file. | 307| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 308| 14800032 | SQLite: Abort due to constraint violation. | 309| 14800033 | SQLite: Data type mismatch. | 310| 14800034 | SQLite: Library used incorrectly. | 311| 14800047 | The WAL file size exceeds the default limit. | 312 313**Example** 314 315```ts 316import { dataSharePredicates } from '@kit.ArkData'; 317 318let predicates = new dataSharePredicates.DataSharePredicates(); 319predicates.equalTo("NAME", "Lisa"); 320if(store != undefined) { 321 (store as relationalStore.RdbStore).delete("EMPLOYEE", predicates, (err, rows) => { 322 if (err) { 323 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 324 return; 325 } 326 console.info(`Delete rows: ${rows}`); 327 }) 328} 329``` 330 331### delete 332 333delete(table: string, predicates: dataSharePredicates.DataSharePredicates):Promise<number> 334 335Deletes data from the RDB store based on the specified **DataSharePredicates** object. This API uses a promise to return the result. 336 337**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 338 339**Model restriction**: This API can be used only in the stage model. 340 341**System API**: This is a system API. 342 343**Parameters** 344 345| Name | Type | Mandatory| Description | 346| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- | 347| table | string | Yes | Name of the target table. | 348| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Conditions specified by the **DataSharePredicates** object for deleting data.| 349 350**Return value** 351 352| Type | Description | 353| --------------------- | ------------------------------- | 354| Promise<number> | Promise used to return the number of rows deleted.| 355 356**Error codes** 357 358For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 359 360| **ID**| **Error Message** | 361|-----------| --------------------- | 362| 202 | Permission verification failed, application which is not a system application uses system API. | 363| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 364| 14800000 | Inner error. | 365| 14800011 | Database corrupted. | 366| 14800014 | Already closed. | 367| 14800015 | The database does not respond. | 368| 14800021 | SQLite: Generic error. | 369| 14800022 | SQLite: Callback routine requested an abort. | 370| 14800023 | SQLite: Access permission denied. | 371| 14800024 | SQLite: The database file is locked. | 372| 14800025 | SQLite: A table in the database is locked. | 373| 14800026 | SQLite: The database is out of memory. | 374| 14800027 | SQLite: Attempt to write a readonly database. | 375| 14800028 | SQLite: Some kind of disk I/O error occurred. | 376| 14800029 | SQLite: The database is full. | 377| 14800030 | SQLite: Unable to open the database file. | 378| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 379| 14800032 | SQLite: Abort due to constraint violation. | 380| 14800033 | SQLite: Data type mismatch. | 381| 14800034 | SQLite: Library used incorrectly. | 382| 14800047 | The WAL file size exceeds the default limit. | 383 384**Example** 385 386```ts 387import { dataSharePredicates } from '@kit.ArkData'; 388import { BusinessError } from '@kit.BasicServicesKit'; 389 390let predicates = new dataSharePredicates.DataSharePredicates(); 391predicates.equalTo("NAME", "Lisa"); 392if(store != undefined) { 393 (store as relationalStore.RdbStore).delete("EMPLOYEE", predicates).then((rows: Number) => { 394 console.info(`Delete rows: ${rows}`); 395 }).catch((err: BusinessError) => { 396 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 397 }) 398} 399``` 400 401### query<sup>10+</sup> 402 403query(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<ResultSet>):void 404 405Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result. Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 406 407**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 408 409**Model restriction**: This API can be used only in the stage model. 410 411**System API**: This is a system API. 412 413**Parameters** 414 415| Name | Type | Mandatory| Description | 416| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 417| table | string | Yes | Name of the target table. | 418| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Query conditions specified by the **DataSharePredicates** object. | 419| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 420 421**Error codes** 422 423For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 424 425| **ID**| **Error Message** | 426|-----------| ------------------ | 427| 202 | Permission verification failed, application which is not a system application uses system API. | 428| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 429| 14800000 | Inner error. | 430| 14800014 | Already closed. | 431| 14800015 | The database does not respond. | 432 433**Example** 434 435```ts 436import { dataSharePredicates } from '@kit.ArkData'; 437 438let predicates = new dataSharePredicates.DataSharePredicates(); 439predicates.equalTo("NAME", "Rose"); 440if(store != undefined) { 441 (store as relationalStore.RdbStore).query("EMPLOYEE", predicates, (err, resultSet) => { 442 if (err) { 443 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 444 return; 445 } 446 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 447 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 448 while (resultSet.goToNextRow()) { 449 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 450 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 451 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 452 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 453 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 454 } 455 // Release the dataset memory. 456 resultSet.close(); 457 }) 458} 459``` 460 461### query 462 463query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>):void 464 465Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result. Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 466 467**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 468 469**Model restriction**: This API can be used only in the stage model. 470 471**System API**: This is a system API. 472 473**Parameters** 474 475| Name | Type | Mandatory| Description | 476| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 477| table | string | Yes | Name of the target table. | 478| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Query conditions specified by the **DataSharePredicates** object. | 479| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | 480| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 481 482**Error codes** 483 484For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 485 486| **ID**| **Error Message** | 487|-----------| --------------- | 488| 202 | Permission verification failed, application which is not a system application uses system API. | 489| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 490| 14800000 | Inner error. | 491| 14800014 | Already closed. | 492| 14800015 | The database does not respond. | 493 494**Example** 495 496```ts 497import { dataSharePredicates } from '@kit.ArkData'; 498 499let predicates = new dataSharePredicates.DataSharePredicates(); 500predicates.equalTo("NAME", "Rose"); 501if(store != undefined) { 502 (store as relationalStore.RdbStore).query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], (err, resultSet) => { 503 if (err) { 504 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 505 return; 506 } 507 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 508 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 509 while (resultSet.goToNextRow()) { 510 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 511 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 512 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 513 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 514 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 515 } 516 // Release the dataset memory. 517 resultSet.close(); 518 }) 519} 520``` 521 522### query 523 524query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns?: Array<string>):Promise<ResultSet> 525 526Queries data from the RDB store based on specified conditions. This API uses a promise to return the result. Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 527 528**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 529 530**Model restriction**: This API can be used only in the stage model. 531 532**System API**: This is a system API. 533 534**Parameters** 535 536| Name | Type | Mandatory| Description | 537| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ | 538| table | string | Yes | Name of the target table. | 539| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Query conditions specified by the **DataSharePredicates** object. | 540| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 541 542**Return value** 543 544| Type | Description | 545| ------------------------------------------------------- | -------------------------------------------------- | 546| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 547 548**Error codes** 549 550For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 551 552| **ID**| **Error Message** | 553|-----------| ----------- | 554| 202 | Permission verification failed, application which is not a system application uses system API. | 555| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 556| 14800000 | Inner error. | 557| 14800014 | Already closed. | 558| 14800015 | The database does not respond. | 559 560**Example** 561 562```ts 563import { dataSharePredicates } from '@kit.ArkData'; 564import { BusinessError } from '@kit.BasicServicesKit'; 565 566let predicates = new dataSharePredicates.DataSharePredicates(); 567predicates.equalTo("NAME", "Rose"); 568if(store != undefined) { 569 (store as relationalStore.RdbStore).query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 570 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 571 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 572 while (resultSet.goToNextRow()) { 573 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 574 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 575 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 576 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 577 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 578 } 579 // Release the dataset memory. 580 resultSet.close(); 581 }).catch((err: BusinessError) => { 582 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 583 }) 584} 585``` 586 587### cloudSync<sup>11+</sup> 588 589cloudSync(mode: SyncMode, predicates: RdbPredicates, progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 590 591Manually performs device-cloud sync based on specified conditions. This API uses an asynchronous callback to return the result. The cloud sync function must be implemented. Otherwise, this API cannot be used. 592 593> **NOTE** 594> 595> Since API version 18, you can specify assets in predicates when performing manual device-cloud sync. In this case, the sync mode must be **relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST**. 596> 597> When specifying the predicates, you can use the primary key (mandatory) and asset (optional) as sync conditions. If assets are specified, the predicate supports only [equalTo](js-apis-data-relationalStore.md#equalto), with a limit of 50 assets. If more assets are involved, you are advised to use only the primary key as the sync condition. 598 599**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 600 601**System API**: This is a system API. 602 603**Parameters** 604 605| Name | Type | Mandatory| Description | 606|-------------|--------------------------------| ---- |-------------------------------| 607| mode | [SyncMode](js-apis-data-relationalStore.md#syncmode) | Yes | Sync mode of the database. | 608| predicates | [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | Yes | Conditions for data sync. | 609| progress | Callback<[ProgressDetails](js-apis-data-relationalStore.md#progressdetails10)> | Yes | Callback used to process database sync details. | 610| callback | AsyncCallback<void> | Yes | Callback used to return the sync result to the caller.| 611 612**Error codes** 613 614For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 615 616| **ID**| **Error Message** | 617|-----------|--------------| 618| 202 | if permission verification failed, application which is not a system application uses system API. | 619| 401 | Parameter error. Possible causes: 1. Need 2 - 4 parameter(s). 2. The RdbStore must be not nullptr. 3. The mode must be a SyncMode of cloud. 4. The tablesNames must be not empty. 5. The progress must be a callback type. 6.The callback must be a function.| 620| 801 | Capability not supported. | 621| 14800014 | Already closed. | 622 623**Example 1**: Manually sync data on the local device with the cloud. 624 625```ts 626let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 627predicates.in("id", ["id1", "id2"]); 628 629if(store != undefined) { 630 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, predicates, (progressDetail: relationalStore.ProgressDetails) => { 631 console.info(`progress: ${progressDetail}`); 632 }, (err) => { 633 if (err) { 634 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}}`); 635 return; 636 } 637 console.info('Cloud sync succeeded'); 638 }); 639}; 640``` 641**Example 2**: Download the specified asset. 642```ts 643import { BusinessError } from '@kit.BasicServicesKit'; 644 645let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 646let asset : relationalStore.Asset = { 647 name: "name", 648 uri: "uri", 649 path: "path", 650 createTime: new Date().getTime().toString(), 651 modifyTime: new Date().getTime().toString(), 652 size: "1024" 653} 654// Specify the primary key and asset (asset column in the database) in the predicates. 655predicates.beginWrap().equalTo("id", "id1").and().equalTo("asset", asset).endWrap(); 656 657if(store != undefined) { 658 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, predicates, (progressDetail: relationalStore.ProgressDetails) => { 659 console.info(`progress: ${progressDetail}`); 660 }, (err) => { 661 if (err) { 662 console.error(`cloud sync failed, code is ${err.code},message is ${err.message}}`); 663 return; 664 } 665 console.info('cloud sync succeeded'); 666 }); 667}; 668``` 669 670### cloudSync<sup>11+</sup> 671 672cloudSync(mode: SyncMode, predicates: RdbPredicates, progress: Callback<ProgressDetails>): Promise<void> 673 674Manually performs device-cloud sync based on specified conditions. This API uses a promise to return the result. The cloud sync function must be implemented. Otherwise, this API cannot be used. 675 676> **NOTE** 677> 678> Since API version 18, you can specify assets in predicates when performing manual device-cloud sync. In this case, the sync mode must be **relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST**. 679> 680> When specifying the predicates, you can use the primary key (mandatory) and asset (optional) as sync conditions. If assets are specified, the predicate supports only [equalTo](js-apis-data-relationalStore.md#equalto), with a limit of 50 assets. If more assets are involved, you are advised to use only the primary key as the sync condition. 681 682**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 683 684**System API**: This is a system API. 685 686**Parameters** 687 688| Name | Type | Mandatory| Description | 689|------------|---------------------------------| ---- |---------------------| 690| mode | [SyncMode](js-apis-data-relationalStore.md#syncmode) | Yes | Sync mode of the database. | 691| predicates | [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | Yes | Conditions for data sync. | 692| progress | Callback<[ProgressDetails](js-apis-data-relationalStore.md#progressdetails10)> | Yes | Callback used to process database sync details.| 693 694**Return value** 695 696| Type | Description | 697| ------------------- | --------------------------------------- | 698| Promise<void> | Promise used to return the sync result.| 699 700**Error codes** 701 702For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 703 704| **ID**| **Error Message** | 705|-----------|---------------------------| 706| 202 | if permission verification failed, application which is not a system application uses system API. | 707| 401 | Parameter error. Possible causes: 1. Need 2 - 4 parameter(s). 2. The RdbStore must be not nullptr. 3. The mode must be a SyncMode of cloud. 4. The tablesNames must be not empty. 5. The progress must be a callback type. | 708| 801 | Capability not supported. | 709| 14800014 | Already closed. | 710 711**Example 1**: Manually sync data on the local device with the cloud. 712 713```ts 714import { BusinessError } from '@kit.BasicServicesKit'; 715 716let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 717predicates.in("id", ["id1", "id2"]); 718 719if(store != undefined) { 720 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, predicates, (progressDetail: relationalStore.ProgressDetails) => { 721 console.info(`progress: ${progressDetail}`); 722 }).then(() => { 723 console.info('cloud sync succeeded'); 724 }).catch((err: BusinessError) => { 725 console.error(`cloud sync failed, code is ${err.code},message is ${err.message}}`); 726 }); 727}; 728``` 729**Example 2**: Download the specified asset. 730```ts 731import { BusinessError } from '@kit.BasicServicesKit'; 732 733let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 734let asset : relationalStore.Asset = { 735 name: "name", 736 uri: "uri", 737 path: "path", 738 createTime: new Date().getTime().toString(), 739 modifyTime: new Date().getTime().toString(), 740 size: "1024" 741} 742// Specify the primary key and asset (asset column in the database) in the predicates. 743predicates.beginWrap().equalTo("id", "id1").and().equalTo("asset", asset).endWrap(); 744 745if(store != undefined) { 746 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, predicates, (progressDetail: relationalStore.ProgressDetails) => { 747 console.info(`progress: ${progressDetail}`); 748 }).then(() => { 749 console.info('Cloud sync succeeded'); 750 }).catch((err: BusinessError) => { 751 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}}`); 752 }); 753}; 754``` 755 756### querySharingResource<sup>11+</sup> 757 758querySharingResource(predicates: RdbPredicates, columns?: Array<string>): Promise<ResultSet> 759 760Queries the shared resource of the data matching the specified conditions. This API uses a promise to return the result set, which includes the shared resource ID and the column names if the column names are specified. 761 762**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 763 764**System API**: This is a system API. 765 766**Parameters** 767 768| Name | Type | Mandatory| Description | 769| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 770| predicates | [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | Yes | Query conditions. | 771| columns | Array<string> | No | Columns to be searched for. If this parameter is not specified, the returned result set contains only the shared resource ID.| 772 773**Return value** 774 775| Name | Description | 776| -------- | ------------------------------------------------- | 777| Promise<[ResultSet](#resultset)> | Promise used to return the result set. | 778 779**Error codes** 780 781For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 782 783| **ID**| **Error Message** | 784|-----------|-------------| 785| 401 | Parameter error. Possible causes: 1. Need 1 - 3 parameter(s)! 2. The RdbStore must be not nullptr. 3. The predicates must be an RdbPredicates. 4. The columns must be a string array. | 786| 801 | Capability not supported. | 787| 14800000 | Inner error. | 788| 14800011 | Database corrupted. | 789| 14800014 | Already closed. | 790| 14800015 | The database does not respond. | 791| 14800021 | SQLite: Generic error. | 792| 14800022 | SQLite: Callback routine requested an abort. | 793| 14800023 | SQLite: Access permission denied. | 794| 14800024 | SQLite: The database file is locked. | 795| 14800025 | SQLite: A table in the database is locked. | 796| 14800026 | SQLite: The database is out of memory. | 797| 14800027 | SQLite: Attempt to write a readonly database. | 798| 14800028 | SQLite: Some kind of disk I/O error occurred. | 799| 14800029 | SQLite: The database is full. | 800| 14800030 | SQLite: Unable to open the database file. | 801| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 802| 14800032 | SQLite: Abort due to constraint violation. | 803| 14800033 | SQLite: Data type mismatch. | 804| 14800034 | SQLite: Library used incorrectly. | 805 806**Example** 807 808```ts 809import { BusinessError } from '@kit.BasicServicesKit'; 810 811let sharingResource: string; 812let predicates = new relationalStore.RdbPredicates('test_table'); 813predicates.equalTo('data', 'data_test'); 814if(store != undefined) { 815 (store as relationalStore.RdbStore).querySharingResource(predicates, ['uuid', 'data']).then((resultSet) => { 816 if (!resultSet.goToFirstRow()) { 817 console.error(`resultSet error`); 818 return; 819 } 820 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 821 console.info(`sharing resource: ${res}`); 822 sharingResource = res; 823 }).catch((err: BusinessError) => { 824 console.error(`query sharing resource failed, code is ${err.code},message is ${err.message}`); 825 }) 826} 827 828``` 829 830### querySharingResource<sup>11+</sup> 831 832querySharingResource(predicates: RdbPredicates, callback: AsyncCallback<ResultSet>): void 833 834Queries the shared resource of the data matching the specified conditions. This API uses an asynchronous callback to return the result set. 835 836**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 837 838**System API**: This is a system API. 839 840**Parameters** 841 842| Name | Type | Mandatory| Description | 843| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 844| predicates | [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | Yes | Query conditions. | 845| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result set.| 846 847**Error codes** 848 849For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 850 851| **ID**| **Error Message** | 852|-----------|------| 853| 401 | Parameter error. Possible causes: 1. Need 1 - 3 parameter(s)! 2. The RdbStore must be not nullptr. 3. The predicates must be an RdbPredicates. 4. The columns must be a string array. | 854| 801 | Capability not supported. | 855| 14800000 | Inner error. | 856| 14800011 | Database corrupted. | 857| 14800014 | Already closed. | 858| 14800015 | The database does not respond. | 859| 14800021 | SQLite: Generic error. | 860| 14800022 | SQLite: Callback routine requested an abort. | 861| 14800023 | SQLite: Access permission denied. | 862| 14800024 | SQLite: The database file is locked. | 863| 14800025 | SQLite: A table in the database is locked. | 864| 14800026 | SQLite: The database is out of memory. | 865| 14800027 | SQLite: Attempt to write a readonly database. | 866| 14800028 | SQLite: Some kind of disk I/O error occurred. | 867| 14800029 | SQLite: The database is full. | 868| 14800030 | SQLite: Unable to open the database file. | 869| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 870| 14800032 | SQLite: Abort due to constraint violation. | 871| 14800033 | SQLite: Data type mismatch. | 872| 14800034 | SQLite: Library used incorrectly. | 873 874 875**Example** 876 877```ts 878let sharingResource: string; 879let predicates = new relationalStore.RdbPredicates('test_table'); 880predicates.equalTo('data', 'data_test'); 881if(store != undefined) { 882 (store as relationalStore.RdbStore).querySharingResource(predicates,(err, resultSet) => { 883 if (err) { 884 console.error(`sharing resource failed, code is ${err.code},message is ${err.message}`); 885 return; 886 } 887 if (!resultSet.goToFirstRow()) { 888 console.error(`resultSet error`); 889 return; 890 } 891 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 892 console.info(`sharing resource: ${res}`); 893 sharingResource = res; 894 }) 895} 896 897``` 898 899### querySharingResource<sup>11+</sup> 900 901querySharingResource(predicates: RdbPredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>): void 902 903Queries the shared resource of the data matching the specified conditions. This API uses an asynchronous callback to return the shared resource ID and the column names specified. 904 905**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 906 907**System API**: This is a system API. 908 909**Parameters** 910 911| Name | Type | Mandatory| Description | 912| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 913| predicates | [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | Yes | Query conditions. | 914| columns | Array<string> | Yes | Columns to be searched for. | 915| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result set.| 916 917**Error codes** 918 919For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 920 921| **ID**| **Error Message** | 922|-----------|--------------| 923| 401 | Parameter error. Possible causes: 1. Need 1 - 3 parameter(s)! 2. The RdbStore must be not nullptr. 3. The predicates must be an RdbPredicates. 4. The columns must be a string array. | 924| 801 | Capability not supported. | 925| 14800000 | Inner error. | 926| 14800011 | Database corrupted. | 927| 14800014 | Already closed. | 928| 14800015 | The database does not respond. | 929| 14800021 | SQLite: Generic error. | 930| 14800022 | SQLite: Callback routine requested an abort. | 931| 14800023 | SQLite: Access permission denied. | 932| 14800024 | SQLite: The database file is locked. | 933| 14800025 | SQLite: A table in the database is locked. | 934| 14800026 | SQLite: The database is out of memory. | 935| 14800027 | SQLite: Attempt to write a readonly database. | 936| 14800028 | SQLite: Some kind of disk I/O error occurred. | 937| 14800029 | SQLite: The database is full. | 938| 14800030 | SQLite: Unable to open the database file. | 939| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 940| 14800032 | SQLite: Abort due to constraint violation. | 941| 14800033 | SQLite: Data type mismatch. | 942| 14800034 | SQLite: Library used incorrectly. | 943 944 945**Example** 946 947```ts 948let sharingResource: string; 949let predicates = new relationalStore.RdbPredicates('test_table'); 950predicates.equalTo('data', 'data_test'); 951if(store != undefined) { 952 (store as relationalStore.RdbStore).querySharingResource(predicates, ['uuid', 'data'], (err, resultSet) => { 953 if (err) { 954 console.error(`sharing resource failed, code is ${err.code},message is ${err.message}`); 955 return; 956 } 957 if (!resultSet.goToFirstRow()) { 958 console.error(`resultSet error`); 959 return; 960 } 961 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 962 console.info(`sharing resource: ${res}`); 963 sharingResource = res; 964 }) 965} 966 967``` 968 969 970### lockCloudContainer<sup>12+</sup> 971 972lockCloudContainer(): Promise<number> 973 974Manually locks the cloud database of an application. This API uses a promise to return the result. 975 976> **NOTE** 977> 978> After the cloud database is locked, data of the same application logged in with the same account on other devices cannot be synced to the cloud. The cloud sync function must be implemented. Otherwise, this API cannot be used. 979 980**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 981 982**System API**: This is a system API. 983 984**Return value** 985 986| Type | Description | 987| ------------------- | ---------------------------------------| 988| Promise<number> | Promise used to return the lock validity period (in ms) if the operation is successful. If the operation fails, **0** is returned.| 989 990**Error codes** 991 992For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 993 994| **ID**| **Error Message** | 995|-----------|---------------------------| 996| 202 | Permission verification failed, application which is not a system application uses system API. | 997 998**Example** 999 1000```ts 1001import { BusinessError } from '@kit.BasicServicesKit'; 1002 1003if(store != undefined) { 1004 (store as relationalStore.RdbStore).lockCloudContainer().then((time: Number) => { 1005 console.info('lockCloudContainer succeeded time:' + time); 1006 }).catch((err: BusinessError) => { 1007 console.error(`lockCloudContainer failed, code is ${err.code},message is ${err.message}`); 1008 }) 1009} 1010``` 1011 1012### unlockCloudContainer<sup>12+</sup> 1013 1014unlockCloudContainer(): Promise<void> 1015 1016Manually unlocks the cloud database of an application. This API uses a promise to return the result. The cloud sync function must be implemented. Otherwise, this API cannot be used. 1017 1018**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1019 1020**System API**: This is a system API. 1021 1022**Return value** 1023 1024| Type | Description | 1025| ------------------- | --------------------------------------- | 1026| Promise<void> | Promise that returns no value.| 1027 1028**Error codes** 1029 1030For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1031 1032| **ID**| **Error Message** | 1033|-----------|---------------------------| 1034| 202 | Permission verification failed, application which is not a system application uses system API. | 1035 1036**Example** 1037 1038```ts 1039import { BusinessError } from '@kit.BasicServicesKit'; 1040 1041if(store != undefined) { 1042 (store as relationalStore.RdbStore).unlockCloudContainer().then(() => { 1043 console.info('unlockCloudContainer succeeded'); 1044 }).catch((err: BusinessError) => { 1045 console.error(`unlockCloudContainer failed, code is ${err.code},message is ${err.message}`); 1046 }) 1047} 1048``` 1049 1050### restore<sup>12+</sup> 1051 1052restore(): Promise<void> 1053 1054Restores data from a replica RDB store file. This API uses a promise to return the result. This API can be used only when [HAMode](#hamode12) is **MAIN_REPLICA**, and cannot be used in transactions. 1055 1056**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1057 1058**System API**: This is a system API. 1059 1060**Return value** 1061 1062| Type | Description | 1063| ------------------- | ------------------------- | 1064| Promise<void> | Promise that returns no value.| 1065 1066**Error codes** 1067 1068For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 1069 1070| **ID**| **Error Message** | 1071|-----------| ------------------------------------------------------------ | 1072| 202 | Permission verification failed, application which is not a system application uses system API. | 1073| 14800000 | Inner error. | 1074| 14800010 | Invalid database path. | 1075| 14800011 | Database corrupted. | 1076| 14800014 | Already closed. | 1077| 14800015 | The database does not respond. | 1078| 14800021 | SQLite: Generic error. | 1079| 14800022 | SQLite: Callback routine requested an abort. | 1080| 14800023 | SQLite: Access permission denied. | 1081| 14800024 | SQLite: The database file is locked. | 1082| 14800025 | SQLite: A table in the database is locked. | 1083| 14800026 | SQLite: The database is out of memory. | 1084| 14800027 | SQLite: Attempt to write a readonly database. | 1085| 14800028 | SQLite: Some kind of disk I/O error occurred. | 1086| 14800029 | SQLite: The database is full. | 1087| 14800030 | SQLite: Unable to open the database file. | 1088| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 1089| 14800032 | SQLite: Abort due to constraint violation. | 1090| 14800033 | SQLite: Data type mismatch. | 1091| 14800034 | SQLite: Library used incorrectly. | 1092 1093**Example** 1094 1095```ts 1096import { BusinessError } from '@kit.BasicServicesKit'; 1097 1098let store: relationalStore.RdbStore | undefined = undefined; 1099if(store != undefined) { 1100 let promiseRestore = (store as relationalStore.RdbStore).restore(); 1101 promiseRestore.then(() => { 1102 console.info('Succeeded in restoring.'); 1103 }).catch((err: BusinessError) => { 1104 console.error(`Failed to restore, code is ${err.code},message is ${err.message}`); 1105 }) 1106} 1107``` 1108 1109## ResultSet 1110 1111Provides APIs to access the **resultSet** object returned by **query()**. 1112 1113### getFloat32Array<sup>12+</sup> 1114 1115getFloat32Array(columnIndex: number): Float32Array 1116 1117Obtains the value from the specified column in the current row and outputs it in a Float32Array (array of 32-bit floating-point numbers). This API is available only for a [vector store](#storeconfig). 1118 1119**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1120 1121**Parameters** 1122 1123| Name | Type | Mandatory| Description | 1124| ----------- | ------ | ---- | ----------------------- | 1125| columnIndex | number | Yes | Index of the target column, starting from 0.| 1126 1127**Return value** 1128 1129| Type | Description | 1130| ---------- | -------------------------------- | 1131| Float32Array | Value obtained, in a Float32Array.| 1132 1133**Error codes** 1134 1135For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 1136 1137| **ID**| **Error Message** | 1138|-----------| ------------ | 1139| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1140| 801 | The capability is not supported because the database is not a vector DB. | 1141| 14800011 | Database corrupted. | 1142| 14800013 | Column out of bounds. | 1143| 14800014 | Already closed. | 1144| 14800021 | SQLite: Generic error. | 1145| 14800022 | SQLite: Callback routine requested an abort. | 1146| 14800023 | SQLite: Access permission denied. | 1147| 14800024 | SQLite: The database file is locked. | 1148| 14800025 | SQLite: A table in the database is locked. | 1149| 14800026 | SQLite: The database is out of memory. | 1150| 14800027 | SQLite: Attempt to write a readonly database. | 1151| 14800028 | SQLite: Some kind of disk I/O error occurred. | 1152| 14800029 | SQLite: The database is full. | 1153| 14800030 | SQLite: Unable to open the database file. | 1154| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 1155| 14800032 | SQLite: Abort due to constraint violation. | 1156| 14800033 | SQLite: Data type mismatch. | 1157| 14800034 | SQLite: Library used incorrectly. | 1158 1159**Example** 1160 1161```ts 1162let resultSet: relationalStore.ResultSet | undefined; 1163if(resultSet != undefined) { 1164 const id = (resultSet as relationalStore.ResultSet).getFloat32Array(0); 1165} 1166``` 1167