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