1# @ohos.data.relationalStore (RDB Store) 2 3The relational database (RDB) store manages data based on relational models. The **relationalStore** module provides a complete mechanism for managing local databases based on the underlying SQLite. You can use the APIs to perform operations such as adding, deleting, modifying, and querying data, and directly run SQL statements. You can also use [ResultSet.getSendableRow](#getsendablerow12) to obtain sendable data for cross-thread transmission. 4 5The 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. 6 7Querying data from a large amount of data may take time or even cause application suspension. In this case, you can perform batch operations. For details, see [Batch Database Operations](../../arkts-utils/batch-database-operations-guide.md). Moreover, observe the following: 8- The number of data records to be queried at a time should not exceed 5000. 9- Use [TaskPool](../apis-arkts/js-apis-taskpool.md) if there is a large amount of data needs to be queried. 10- Keep concatenated SQL statements as concise as possible. 11- Query data in batches. 12 13The **relationalStore** module provides the following functionalities: 14 15- [RdbPredicates](#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. 16- [RdbStore](#rdbstore): provides APIs for managing data in an RDB store. 17- [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store. 18- [Transaction](#transaction14): provides APIs for managing transaction objects. 19 20> **NOTE** 21> 22> 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. 23 24## Modules to Import 25 26```ts 27import { relationalStore } from '@kit.ArkData'; 28``` 29 30## relationalStore.getRdbStore 31 32getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback<RdbStore>): void 33 34Obtains an RDB store. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. 35 36The parameter [encrypt](#storeconfig) takes effect only when the RDB store is created for the first time, and cannot be modified. It is important to set this parameter correctly. 37 38| Encryption Type When the RDB Store Is Opened | Encryption Type When the RDB Store Is Created | Behavior| 39| ------- | -------------------------------- | ---- | 40| Not encrypt| Encrypt | The RDB store is opened in encrypted mode. | 41| Encrypt| Not encrypt | The RDB store is opened in non-encrypted mode. | 42 43Currently, **getRdbStore()** does not support multi-thread concurrent operations. 44 45**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 46 47**Parameters** 48 49| Name | Type | Mandatory| Description | 50| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | 51| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).| 52| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 53| callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes | Callback used to return the RDB store obtained. | 54 55**Error codes** 56 57For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 58 59| **ID**| **Error Message** | 60|-----------|---------| 61| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 62| 14800000 | Inner error. | 63| 14800010 | Invalid database path. | 64| 14800011 | Database corrupted. | 65| 14801001 | The operation is supported in the stage model only. | 66| 14801002 | Invalid data group ID. | 67| 14800017 | Config changed. | 68| 14800020 | The secret key is corrupted or lost. | 69| 14800021 | SQLite: Generic error. | 70| 14800022 | SQLite: Callback routine requested an abort. | 71| 14800023 | SQLite: Access permission denied. | 72| 14800027 | SQLite: Attempt to write a readonly database. | 73| 14800028 | SQLite: Some kind of disk I/O error occurred. | 74| 14800029 | SQLite: The database is full. | 75| 14800030 | SQLite: Unable to open the database file. | 76 77**Example** 78 79FA model: 80 81<!--code_no_check_fa--> 82```js 83import { featureAbility } from '@kit.AbilityKit'; 84import { BusinessError } from '@kit.BasicServicesKit'; 85 86let store: relationalStore.RdbStore | undefined = undefined; 87let context = featureAbility.getContext(); 88 89const STORE_CONFIG: relationalStore.StoreConfig = { 90 name: "RdbTest.db", 91 securityLevel: relationalStore.SecurityLevel.S3 92}; 93 94relationalStore.getRdbStore(context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 95 store = rdbStore; 96 if (err) { 97 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 98 return; 99 } 100 console.info('Get RdbStore successfully.'); 101}) 102``` 103 104Stage model: 105 106```ts 107import { UIAbility } from '@kit.AbilityKit'; 108import { window } from '@kit.ArkUI'; 109import { BusinessError } from '@kit.BasicServicesKit'; 110 111let store: relationalStore.RdbStore | undefined = undefined; 112 113class EntryAbility extends UIAbility { 114 onWindowStageCreate(windowStage: window.WindowStage) { 115 const STORE_CONFIG: relationalStore.StoreConfig = { 116 name: "RdbTest.db", 117 securityLevel: relationalStore.SecurityLevel.S3 118 }; 119 120 relationalStore.getRdbStore(this.context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 121 store = rdbStore; 122 if (err) { 123 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 124 return; 125 } 126 console.info('Get RdbStore successfully.'); 127 }) 128 } 129} 130``` 131 132## relationalStore.getRdbStore 133 134getRdbStore(context: Context, config: StoreConfig): Promise<RdbStore> 135 136Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. 137 138The parameter [encrypt](#storeconfig) takes effect only when the RDB store is created for the first time, and cannot be modified. It is important to set this parameter correctly. 139 140| Encryption Type When the RDB Store Is Opened | Encryption Type When the RDB Store Is Created | Behavior| 141| ------- | -------------------------------- | ---- | 142| Not encrypt| Encrypt | The RDB store is opened in encrypted mode. | 143| Encrypt| Not encrypt | The RDB store is opened in non-encrypted mode. | 144 145Currently, **getRdbStore()** does not support multi-thread concurrent operations. 146 147**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 148 149**Parameters** 150 151| Name | Type | Mandatory| Description | 152| ------- | -------------------------------- | ---- | ------------------------------------------------------------ | 153| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).| 154| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 155 156**Return value** 157 158| Type | Description | 159| ----------------------------------------- | --------------------------------- | 160| Promise<[RdbStore](#rdbstore)> | Promise used to return the **RdbStore** object obtained.| 161 162**Error codes** 163 164For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 165 166| **ID**| **Error Message** | 167|-----------| ------------------------------------------------------------ | 168| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 169| 14800000 | Inner error. | 170| 14800010 | Invalid database path. | 171| 14800011 | Database corrupted. | 172| 14801001 | The operation is supported in the stage model only. | 173| 14801002 | Invalid data group ID. | 174| 14800017 | Config changed. | 175| 14800020 | The secret key is corrupted or lost. | 176| 14800021 | SQLite: Generic error. | 177| 14800022 | SQLite: Callback routine requested an abort. | 178| 14800023 | SQLite: Access permission denied. | 179| 14800027 | SQLite: Attempt to write a readonly database. | 180| 14800028 | SQLite: Some kind of disk I/O error occurred. | 181| 14800029 | SQLite: The database is full. | 182| 14800030 | SQLite: Unable to open the database file. | 183 184**Example** 185 186FA model: 187 188<!--code_no_check_fa--> 189```js 190import { featureAbility } from '@kit.AbilityKit'; 191import { BusinessError } from '@kit.BasicServicesKit'; 192 193let store: relationalStore.RdbStore | undefined = undefined; 194let context = featureAbility.getContext(); 195 196const STORE_CONFIG: relationalStore.StoreConfig = { 197 name: "RdbTest.db", 198 securityLevel: relationalStore.SecurityLevel.S3 199}; 200 201relationalStore.getRdbStore(context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 202 store = rdbStore; 203 console.info('Get RdbStore successfully.') 204}).catch((err: BusinessError) => { 205 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 206}) 207``` 208 209Stage model: 210 211```ts 212import { UIAbility } from '@kit.AbilityKit'; 213import { window } from '@kit.ArkUI'; 214import { BusinessError } from '@kit.BasicServicesKit'; 215 216let store: relationalStore.RdbStore | undefined = undefined; 217 218class EntryAbility extends UIAbility { 219 onWindowStageCreate(windowStage: window.WindowStage) { 220 const STORE_CONFIG: relationalStore.StoreConfig = { 221 name: "RdbTest.db", 222 securityLevel: relationalStore.SecurityLevel.S3 223 }; 224 225 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 226 store = rdbStore; 227 console.info('Get RdbStore successfully.') 228 }).catch((err: BusinessError) => { 229 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 230 }) 231 } 232} 233``` 234 235## relationalStore.deleteRdbStore 236 237deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void 238 239Deletes an RDB store. This API uses an asynchronous callback to return the result. 240 241After the deletion, you are advised to set the database object to null. If a custom path is set in [StoreConfig](#storeconfig) when an RDB store is created, using this API cannot delete the RDB store. Use [deleteRdbStore](#relationalstoredeleterdbstore10) instead. 242 243**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 244 245**Parameters** 246 247| Name | Type | Mandatory| Description | 248| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 249| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).| 250| name | string | Yes | Name of the RDB store to delete. | 251| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 252 253**Error codes** 254 255For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 256 257| **ID**| **Error Message** | 258|-----------|---------------------------------------| 259| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 260| 14800000 | Inner error. | 261| 14800010 | Failed to open or delete database by invalid database path. | 262 263**Example** 264 265FA model: 266 267<!--code_no_check_fa--> 268```js 269import { featureAbility } from '@kit.AbilityKit'; 270import { BusinessError } from '@kit.BasicServicesKit'; 271 272let store: relationalStore.RdbStore | undefined = undefined; 273let context = featureAbility.getContext(); 274 275relationalStore.deleteRdbStore(context, "RdbTest.db", (err: BusinessError) => { 276 if (err) { 277 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 278 return; 279 } 280 store = undefined; 281 console.info('Delete RdbStore successfully.'); 282}) 283``` 284 285Stage model: 286 287```ts 288import { UIAbility } from '@kit.AbilityKit'; 289import { window } from '@kit.ArkUI'; 290import { BusinessError } from '@kit.BasicServicesKit'; 291 292let store: relationalStore.RdbStore | undefined = undefined; 293 294class EntryAbility extends UIAbility { 295 onWindowStageCreate(windowStage: window.WindowStage){ 296 relationalStore.deleteRdbStore(this.context, "RdbTest.db", (err: BusinessError) => { 297 if (err) { 298 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 299 return; 300 } 301 store = undefined; 302 console.info('Delete RdbStore successfully.'); 303 }) 304 } 305} 306``` 307 308## relationalStore.deleteRdbStore 309 310deleteRdbStore(context: Context, name: string): Promise<void> 311 312Deletes an RDB store. This API uses a promise to return the result. 313 314After the deletion, you are advised to set the database object to null. If a custom path is set in [StoreConfig](#storeconfig) when an RDB store is created, using this API cannot delete the RDB store. Use [deleteRdbStore](#relationalstoredeleterdbstore10-1) instead. 315 316**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 317 318**Parameters** 319 320| Name | Type | Mandatory| Description | 321| ------- | ------- | ---- | ------------------------------------------------------------ | 322| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).| 323| name | string | Yes | Name of the RDB store to delete. | 324 325**Return value** 326 327| Type | Description | 328| ------------------- | ------------------------- | 329| Promise<void> | Promise that returns no value.| 330 331**Error codes** 332 333For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 334 335| **ID**| **Error Message** | 336|-----------|----------------------------------------------------------------------------------| 337| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 338| 14800000 | Inner error. | 339| 14800010 | Invalid database path. | 340 341**Example** 342 343FA model: 344 345<!--code_no_check_fa--> 346```js 347import { featureAbility } from '@kit.AbilityKit'; 348import { BusinessError } from '@kit.BasicServicesKit'; 349 350let store: relationalStore.RdbStore | undefined = undefined; 351let context = featureAbility.getContext(); 352 353relationalStore.deleteRdbStore(context, "RdbTest.db").then(()=>{ 354 store = undefined; 355 console.info('Delete RdbStore successfully.'); 356}).catch((err: BusinessError) => { 357 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 358}) 359``` 360 361Stage model: 362 363```ts 364import { UIAbility } from '@kit.AbilityKit'; 365import { window } from '@kit.ArkUI'; 366import { BusinessError } from '@kit.BasicServicesKit'; 367 368let store: relationalStore.RdbStore | undefined = undefined; 369 370class EntryAbility extends UIAbility { 371 onWindowStageCreate(windowStage: window.WindowStage){ 372 relationalStore.deleteRdbStore(this.context, "RdbTest.db").then(()=>{ 373 store = undefined; 374 console.info('Delete RdbStore successfully.'); 375 }).catch((err: BusinessError) => { 376 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 377 }) 378 } 379} 380``` 381 382## relationalStore.deleteRdbStore<sup>10+</sup> 383 384deleteRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback\<void>): void 385 386Deletes an RDB store. This API uses an asynchronous callback to return the result. 387 388After the deletion, you are advised to set the database object to null. If the database file is in the public sandbox directory, you must use this API to delete the database. If the database is accessed by multiple processes at the same time, you are advised to send a database deletion notification to other processes. Use this API to delete the RDB store that has a customized path set in [StoreConfig](#storeconfig). 389 390**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 391 392**Parameters** 393 394| Name | Type | Mandatory| Description | 395| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 396| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).| 397| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 398| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 399 400**Error codes** 401 402For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 403 404| **ID**| **Error Message** | 405|-----------|----------| 406| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 407| 14800000 | Inner error. | 408| 14800010 | Failed to open or delete database by invalid database path. | 409| 14801001 | The operation is supported in the stage model only. | 410| 14801002 | Invalid data group ID. | 411 412**Example** 413 414FA model: 415 416<!--code_no_check_fa--> 417```js 418import { featureAbility } from '@kit.AbilityKit'; 419import { BusinessError } from '@kit.BasicServicesKit'; 420 421let store: relationalStore.RdbStore | undefined = undefined; 422let context = featureAbility.getContext(); 423 424const STORE_CONFIG: relationalStore.StoreConfig = { 425 name: "RdbTest.db", 426 securityLevel: relationalStore.SecurityLevel.S3 427}; 428 429relationalStore.deleteRdbStore(context, STORE_CONFIG, (err: BusinessError) => { 430 if (err) { 431 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 432 return; 433 } 434 store = undefined; 435 console.info('Delete RdbStore successfully.'); 436}) 437``` 438 439Stage model: 440 441```ts 442import { UIAbility } from '@kit.AbilityKit'; 443import { window } from '@kit.ArkUI'; 444import { BusinessError } from '@kit.BasicServicesKit'; 445 446let store: relationalStore.RdbStore | undefined = undefined; 447 448class EntryAbility extends UIAbility { 449 onWindowStageCreate(windowStage: window.WindowStage){ 450 const STORE_CONFIG: relationalStore.StoreConfig = { 451 name: "RdbTest.db", 452 securityLevel: relationalStore.SecurityLevel.S3 453 }; 454 relationalStore.deleteRdbStore(this.context, STORE_CONFIG, (err: BusinessError) => { 455 if (err) { 456 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 457 return; 458 } 459 store = undefined; 460 console.info('Delete RdbStore successfully.'); 461 }) 462 } 463} 464``` 465 466## relationalStore.deleteRdbStore<sup>10+</sup> 467 468deleteRdbStore(context: Context, config: StoreConfig): Promise\<void> 469 470Deletes an RDB store. This API uses a promise to return the result. 471 472After the deletion, you are advised to set the database object to null. If the database file is in the public sandbox directory, you must use this API to delete the database. If the database is accessed by multiple processes at the same time, you are advised to send a database deletion notification to other processes. Use this API to delete the RDB store that has a customized path set in [StoreConfig](#storeconfig). 473 474**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 475 476**Parameters** 477 478| Name | Type | Mandatory| Description | 479| ------- | --------------------------- | ---- | ------------------------------------------------------------ | 480| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).| 481| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 482 483**Return value** 484 485| Type | Description | 486| ------------------- | ------------------------- | 487| Promise<void> | Promise that returns no value.| 488 489**Error codes** 490 491For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 492 493| **ID**| **Error Message** | 494|-----------|---------------------| 495| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 496| 801 | Capability not supported. | 497| 14800000 | Inner error. | 498| 14800010 | Invalid database path. | 499| 14801001 | The operation is supported in the stage model only. | 500| 14801002 | Invalid data group ID. | 501 502 503**Example** 504 505FA model: 506 507<!--code_no_check_fa--> 508```js 509import { featureAbility } from "@kit.AbilityKit"; 510import { BusinessError } from '@kit.BasicServicesKit'; 511 512let store: relationalStore.RdbStore | undefined = undefined; 513let context = featureAbility.getContext(); 514 515const STORE_CONFIG: relationalStore.StoreConfig = { 516 name: "RdbTest.db", 517 securityLevel: relationalStore.SecurityLevel.S3 518}; 519 520relationalStore.deleteRdbStore(context, STORE_CONFIG).then(()=>{ 521 store = undefined; 522 console.info('Delete RdbStore successfully.'); 523}).catch((err: BusinessError) => { 524 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 525}) 526``` 527 528Stage model: 529 530```ts 531import { UIAbility } from '@kit.AbilityKit'; 532import { window } from '@kit.ArkUI'; 533import { BusinessError } from '@kit.BasicServicesKit'; 534 535let store: relationalStore.RdbStore | undefined = undefined; 536 537class EntryAbility extends UIAbility { 538 onWindowStageCreate(windowStage: window.WindowStage){ 539 const STORE_CONFIG: relationalStore.StoreConfig = { 540 name: "RdbTest.db", 541 securityLevel: relationalStore.SecurityLevel.S3 542 }; 543 relationalStore.deleteRdbStore(this.context, STORE_CONFIG).then(()=>{ 544 store = undefined; 545 console.info('Delete RdbStore successfully.'); 546 }).catch((err: BusinessError) => { 547 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 548 }) 549 } 550} 551``` 552 553## StoreConfig 554 555Defines the RDB store configuration. 556 557| Name | Type | Mandatory| Description | 558| ------------- | ------------- | ---- | --------------------------------------------------------- | 559| name | string | Yes | Database file name, which is the unique identifier of the database.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 560| securityLevel | [SecurityLevel](#securitylevel) | Yes | Security level of the RDB store.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 561| encrypt | boolean | No | Whether to encrypt the RDB store.<br> The value **true** means to encrypt the RDB store; the value **false** (default) means the opposite.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 562| dataGroupId<sup>10+</sup> | string | No| Application group ID. <!--RP3-->Currently, this parameter is not supported.<!--RP3End--><br>**Model restriction**: This parameter can be used only in the stage model.<br>This parameter is supported since API version 10. If **dataGroupId** is specified, the **RdbStore** instance will be created in the sandbox directory of the specified **dataGroupId**. However, the encrypted RDB store in this sandbox directory does not support multi-process access. If this parameter is left blank, the **RdbStore** instance will be created in the sandbox directory of the application by default.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 563| customDir<sup>11+</sup> | string | No| Customized path of the RDB store.<br>**Constraints**: The value cannot exceed 128 bytes.<br>This parameter is supported since API version 11. The RDB store directory is in the **context.databaseDir**/**rdb**/**customDir** format. **context.databaseDir** specifies the application sandbox path. **rdb** is a fixed field that indicates an RDB store. **customDir** specifies the customized path. If this parameter is not specified, the **RdbStore** instance is created in the sandbox directory of the application.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 564| autoCleanDirtyData<sup>11+</sup> | boolean | No| Whether to automatically clear the dirty data (data that has been deleted from the cloud) from the local device. The value **true** means to clear the dirty data automatically. The value **false** means to clear the data manually. The default value is **true**.<br>This parameter applies to the RDB stores with device-cloud synergy. To manually clear the dirty data, use [cleanDirtyData<sup>11+</sup>](#cleandirtydata11).<br>This parameter is supported since API version 11.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 565| allowRebuild<sup>12+</sup> | boolean | No| Whether to automatically delete the RDB store and create an empty table in the case of an exception.<br>The value **true** means to delete the RDB store and create an empty table in the case of an exception;<br>the value **false** (default) means the opposite.<br>This parameter is supported since API version 12.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 566| isReadOnly<sup>12+</sup> | boolean | No| Whether the RDB store is read-only. <br>Default value: **false**, which means the RDB store is readable and writeable.<br>If the value is **true** (read-only), writing data to the RDB store will throw error code 801.<br>The value **false** means the RDB store is readable and writeable.<br>This parameter is supported since API version 12.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 567| pluginLibs<sup>12+</sup> | Array\<string> | No| Dynamic libraries with capabilities such as Full-Text Search (FTS).<br>**Constraints**<br>1. The maximum number of dynamic library names is 16. If the number of dynamic library names exceeds 16, the library fails to be opened and an error is returned.<br>2. The dynamic libraries must be those in the sandbox directory or system directory of the application. If a dynamic library fails to be loaded, the RDB store cannot be opened and an error will be returned.<br>3. The dynamic library name must be a complete path that can be loaded by SQLite.<br>Example: [context.bundleCodeDir + "/libs/arm64/" + libtokenizer.so], where **context.bundleCodeDir** indicates the application sandbox path, **/libs/arm64/** is the subdirectory, **libtokenizer.so** indicates the file name of the dynamic library. If this parameter is left blank, dynamic libraries are not loaded by default.<br>4. The dynamic library must contain all its dependencies to prevent the failure caused by the lack of dependencies.<br>For example, in an NDK project, the default compilation parameters are used to build **libtokenizer.so**, which depends on the C++ standard library. When the dynamic library is loaded, **libc++_shared.so** is linked by mistake because the namespace is different from that during compilation. As a result, the **__emutls_get_address** symbol cannot be found. To solve this problem, you need to statically link the C++ standard library during compilation. For details, see [NDK Project Building Overview](../../napi/build-with-ndk-overview.md).<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 568| cryptoParam<sup>14+</sup> | [CryptoParam](#cryptoparam14) | No| Custom encryption parameters.<br>If this parameter is left empty, the default encryption parameters are used. For details, see default values of [CryptoParam](#cryptoparam14).<br>This parameter is valid only when **encrypt** is **true**.<br>This parameter is supported since API version 14.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 569 570## SecurityLevel 571 572Enumerates the RDB store security levels. Use the enum name rather than the enum value. You cannot change the security level of an RDB store from a higher level to a lower one. 573 574> **NOTE** 575> 576> To perform data sync operations, the RDB store security level must be lower than or equal to that of the peer device. For details, see [Access Control Mechanism in Cross-Device Sync](../../database/access-control-by-device-and-data-level.md#access-control-mechanism-in-cross-device-sync). 577 578**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 579 580| Name| Value | Description | 581| ---- | ---- | ------------------------------------------------------------ | 582| S1 | 1 | The RDB store security level is low. If data leakage occurs, minor impact will be caused on the database. For example, an RDB store that contains system data such as wallpapers.| 583| S2 | 2 | The RDB store security level is medium. If data leakage occurs, moderate impact will be caused on the database. For example, an RDB store that contains information created by users or call records, such as audio or video clips.| 584| S3 | 3 | The RDB store security level is high. If data leakage occurs, major impact will be caused on the database. For example, an RDB store that contains information such as user fitness, health, and location data.| 585| S4 | 4 | The RDB store security level is critical. If data leakage occurs, severe impact will be caused on the database. For example, an RDB store that contains information such as authentication credentials and financial data.| 586 587## CryptoParam<sup>14+</sup> 588 589Represents the configuration of database encryption parameters. This parameter is valid only when **encrypt** in **StoreConfig** is **true**. 590 591**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 592 593| Name | Type | Mandatory| Description | 594| ------------- | ------ | ---- | ------------------------------------------------------------ | 595| encryptionKey | Uint8Array | Yes | Key used for database encryption and decryption.<br>If this parameter is not specified, the RDB store generates a key, saves the key, and uses the key to open the database file.<br>If the key is not required, you need to set the key to 0s.| 596| iterationCount | number | No| Number of iterations of the PBKDF2 algorithm used in the RDB store. The value is an integer. <br>Default value: **10000**.<br>The value must be an integer greater than 0. If it is not an integer, the value is rounded down.<br>If this parameter is not specified or is set to **0**, the default value **10000** and the default encryption algorithm **AES_256_GCM** are used.| 597| encryptionAlgo | [EncryptionAlgo](#encryptionalgo14) | No| Algorithm used for database encryption and decryption. <br>Default value: **AES_256_GCM**.| 598| hmacAlgo | [HmacAlgo](#hmacalgo14) | No| HMAC algorithm used for database encryption and decryption. <br>Default value: **SHA256**.| 599| kdfAlgo | [KdfAlgo](#kdfalgo14) | No| PBKDF2 algorithm used for database encryption and decryption. <br>Default value: the same as the HMAC algorithm used.| 600| cryptoPageSize | number | No| Page size used for database encryption and decryption. <br>Default value: **1024** bytes.<br>The value must be an integer within the range of 1024 to 65536 and must be 2<sup>n</sup>. If the specified value is not an integer, the value is rounded down.| 601 602## EncryptionAlgo<sup>14+</sup> 603 604Enumerates the database encryption algorithms. Use the enum name rather than the enum value. 605 606**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 607 608| Name| Value | Description| 609| ---- | ---- | ---- | 610| AES_256_GCM | 0 | AES_256_GCM. | 611| AES_256_CBC | 1 | AES_256_CBC. | 612 613## HmacAlgo<sup>14+</sup> 614 615Enumerates the HMAC algorithms for the database. Use the enum name rather than the enum value. 616 617**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 618 619| Name| Value | Description| 620| ---- | ---- | ---- | 621| SHA1 | 0 | HMAC_SHA1. | 622| SHA256 | 1 | HMAC_SHA256. | 623| SHA512 | 2 | HMAC_SHA512. | 624 625## KdfAlgo<sup>14+</sup> 626 627Enumerates the PBKDF2 algorithms for the database. Use the enum name rather than the enum value. 628 629**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 630 631| Name| Value | Description| 632| ---- | ---- | ---- | 633| KDF_SHA1 | 0 | PBKDF2_HMAC_SHA1. | 634| KDF_SHA256 | 1 | PBKDF2_HMAC_SHA256. | 635| KDF_SHA512 | 2 | PBKDF2_HMAC_SHA512. | 636 637## AssetStatus<sup>10+</sup> 638 639Enumerates the asset statuses. Use the enum name rather than the enum value. 640 641**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 642 643| Name | Value | Description | 644| ------------------------------- | --- | -------------- | 645| ASSET_NORMAL | 1 | The asset is in normal status. | 646| ASSET_INSERT | 2 | The asset is to be inserted to the cloud.| 647| ASSET_UPDATE | 3 | The asset is to be updated to the cloud.| 648| ASSET_DELETE | 4 | The asset is to be deleted from the cloud.| 649| ASSET_ABNORMAL | 5 | The asset is in abnormal status. | 650| ASSET_DOWNLOADING | 6 | The asset is being downloaded to a local device.| 651 652## Asset<sup>10+</sup> 653 654Defines information about an asset (such as a document, image, and video). 655 656**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 657 658| Name | Type | Mandatory | Description | 659| ----------- | --------------------------- | --- | ------------ | 660| name | string | Yes | Asset name. | 661| uri | string | Yes | Asset URI, which is an absolute path in the system. | 662| path | string | Yes | Application sandbox path of the asset. | 663| createTime | string | Yes | Time when the asset was created. | 664| modifyTime | string | Yes | Time when the asset was last modified.| 665| size | string | Yes | Size of the asset. | 666| status | [AssetStatus](#assetstatus10) | No | Asset status. <br>Default value: **ASSET_NORMAL**. | 667 668## Assets<sup>10+</sup> 669 670type Assets = Asset[] 671 672Defines an array of the [Asset](#asset10) type. 673 674**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 675 676| Type | Description | 677| ------- | -------------------- | 678| [Asset](#asset10)[] | Array of assets. | 679 680## ValueType 681 682type ValueType = null | number | string | boolean | Uint8Array | Asset | Assets | Float32Array | bigint 683 684Enumerates the types of the value in a KV pair. The type varies with the parameter usage. 685 686**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 687 688| Type | Description | 689| ------- | -------------------- | 690| null<sup>10+</sup> | Null. | 691| number | Number. | 692| string | String. | 693| boolean | Boolean.| 694| Uint8Array<sup>10+</sup> | Uint8 array. | 695| Asset<sup>10+</sup> | [Asset](#asset10).<br>If the value type is Asset, the type in the SQL statement for creating a table must be ASSET.| 696| Assets<sup>10+</sup> | [Assets](#assets10).<br>If the value type is Assets, the type in the SQL statement for creating a table must be ASSETS.| 697| Float32Array<sup>12+</sup> | Array of 32-bit floating-point numbers.<br>If the field type is Float32Array, the type in the SQL statement for creating a table must be floatvector(128).| 698| bigint<sup>12+</sup> | Integer of any length.<br>If the value type is bigint, the type in the SQL statement for creating a table must be **UNLIMITED INT**. For details, see [Persisting RDB Store Data](../../database/data-persistence-by-rdb-store.md).<br>**NOTE**<br>The bigint type does not support value comparison and cannot be used with the following predicates: **between**, **notBetween**, **greaterThanlessThan**, **greaterThanOrEqualTo**, **lessThanOrEqualTo**, **orderByAsc**, and **orderByDesc**<br>To write a value of bigint type, use **BigInt()** or add **n** to the end of the value, for example,'let data = BigInt(1234)' or 'let data = 1234n'.<br>If data of the number type is written to a bigint field, the type of the return value obtained (queried) is number but not bigint.| 699 700## ValuesBucket 701 702type ValuesBucket = Record<string, ValueType> 703 704Defines the data in the form of a KV pair. **ValuesBucket** cannot be passed across threads. 705 706**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 707 708| Type | Description | 709| ---------------- | ---------------------------- | 710| Record<string, [ValueType](#valuetype)> | Types of the key and value in a KV pair. The key type is string, and the value type is [ValueType](#valuetype).| 711 712## PRIKeyType<sup>10+</sup> 713 714type PRIKeyType = number | string 715 716Enumerates the types of the primary key in a row of a database table. 717 718**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 719 720| Type | Description | 721| ---------------- | ---------------------------------- | 722| number | The primary key is a number.| 723| string | The primary key is a string.| 724 725## UTCTime<sup>10+</sup> 726 727type UTCTime = Date 728 729Represents the data type of the UTC time. 730 731**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 732 733| Type| Description | 734| ---- | --------------- | 735| Date | UTC time.| 736 737## ModifyTime<sup>10+</sup> 738 739type ModifyTime = Map<PRIKeyType, UTCTime> 740 741Represents the data type of the primary key and modification time of a database table. 742 743**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 744 745| Type | Description | 746| ------------------------------------------------------- | ------------------------------------------------------------ | 747| Map<[PRIKeyType](#prikeytype10), [UTCTime](#utctime10)> | The key is the primary key of a row in the database table, and the value is the last modification time of the row in UTC format.| 748 749## SyncMode 750 751Enumerates the database sync modes. Use the enum name rather than the enum value. 752 753| Name | Value | Description | 754| -------------- | ---- | ---------------------------------- | 755| SYNC_MODE_PUSH | 0 | Push data from a local device to a remote device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 756| SYNC_MODE_PULL | 1 | Pull data from a remote device to a local device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 757| SYNC_MODE_TIME_FIRST<sup>10+</sup> | 4 | Synchronize with the data with the latest modification time.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 758| SYNC_MODE_NATIVE_FIRST<sup>10+</sup> | 5 | Synchronize data from a local device to the cloud.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 759| SYNC_MODE_CLOUD_FIRST<sup>10+</sup> | 6 | Synchronize data from the cloud to a local device.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 760 761## Origin<sup>11+</sup> 762 763Enumerates the data sources. Use the enum name rather than the enum value. 764 765**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 766 767| Name | Value | Description | 768| -------------- | ---- | ---------------------------------- | 769| LOCAL | 0 | Local data. | 770| CLOUD | 1 | Cloud data. | 771| REMOTE | 2 | Remote device data.| 772 773## Field<sup>11+</sup> 774 775Enumerates the special fields used in predicates. Use the enum name rather than the enum value. 776 777**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 778 779| Name | Value | Description | 780| -------------- | ---- | ---------------------------------- | 781| CURSOR_FIELD | '#_cursor' | Field name to be searched based on the cursor.| 782| ORIGIN_FIELD | '#_origin' | Data source to be searched based on the cursor. | 783| DELETED_FLAG_FIELD | '#_deleted_flag' | Whether the dirty data (data deleted from the cloud) is cleared from the local device. It fills in the result set returned upon the cursor-based search.<br>The value **true** means the dirty data is cleared; the value **false** means the opposite.| 784| DATA_STATUS_FIELD<sup>12+</sup> | '#_data_status' | Data status in the cursor-based search result set. The value **0** indicates normal data status; **1** indicates that data is retained after the account is logged out; **2** indicates that data is deleted from the cloud; **3** indicates that data is deleted after the account is logged out.| 785| OWNER_FIELD | '#_cloud_owner' | Party who shares the data. It fills in the result set returned when the owner of the shared data is searched.| 786| PRIVILEGE_FIELD | '#_cloud_privilege' | Operation permission on the shared data. It fills in the result set returned when the permission on the shared data is searched.| 787| SHARING_RESOURCE_FIELD | '#_sharing_resource_field' | Resource shared. It fills in the result set returned when the shared resource is searched.| 788 789## SubscribeType 790 791Enumerates the subscription types. Use the enum name rather than the enum value. 792 793| Name | Value | Description | 794| --------------------- | ---- | ------------------ | 795| SUBSCRIBE_TYPE_REMOTE | 0 | Subscribe to remote data changes.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 796| SUBSCRIBE_TYPE_CLOUD<sup>10+</sup> | 1 | Subscribe to cloud data changes.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 797| SUBSCRIBE_TYPE_CLOUD_DETAILS<sup>10+</sup> | 2 | Subscribe to cloud data change details.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 798| SUBSCRIBE_TYPE_LOCAL_DETAILS<sup>12+</sup> | 3 | Subscribe to details of the local data change.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 799 800## RebuildType<sup>12+</sup> 801 802Enumerates the RDB store rebuild types. Use the enum name rather than the enum value. 803 804**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 805 806| Name | Value | Description | 807| ------- | ---- |----------------------------------------------------------------------------------------------------------------| 808| NONE | 0 | The RDB store is not rebuilt. | 809| REBUILT | 1 | Create an empty database to rebuild the RDB store. You need to create tables and restore data. | 810| REPAIRED | 2 | The RDB store is repaired and undamaged data is restored. <!--RP2-->Currently, this value is available only to a [vector database](js-apis-data-relationalStore-sys.md#storeconfig).<!--RP2End--> | 811 812## ChangeType<sup>10+</sup> 813 814Enumerates data change types. Use the enum name rather than the enum value. 815 816**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 817 818| Name | Value | Description | 819| -------------------------- | --- | -------------------------- | 820| DATA_CHANGE | 0 | Data change. | 821| ASSET_CHANGE | 1 | Asset change.| 822 823## ChangeInfo<sup>10+</sup> 824 825Represents the detail information about the device-cloud sync process. 826 827**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 828 829| Name | Type | Mandatory| Description | 830| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ | 831| table | string | Yes | Name of the table with data changes. | 832| type | [ChangeType](#changetype10) | Yes | Type of the data changed, which can be data or asset. | 833| inserted | Array\<string\> \| Array\<number\> | Yes | Location where data is inserted. If the primary key of the table is of the string type, the value is the value of the primary key. Otherwise, the value is the row number of the inserted data.| 834| updated | Array\<string\> \| Array\<number\> | Yes | Location where data is updated. If the primary key of the table is of the string type, the value is the value of the primary key. Otherwise, the value is the row number of the updated data.| 835| deleted | Array\<string\> \| Array\<number\> | Yes | Location where data is deleted. If the primary key of the table is of the string type, the value is the value of the primary key. Otherwise, the value is the row number of the deleted data.| 836 837## DistributedType<sup>10+</sup> 838 839Enumerates the distributed table types. Use the enum name rather than the enum value. 840 841| Name | Value | Description | 842| ------------------ | --- | -------------------------------------------------------------------------------------------------- | 843| DISTRIBUTED_DEVICE | 0 | Distributed database table between devices.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 844| DISTRIBUTED_CLOUD | 1 | Distributed database table between the device and the cloud.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 845 846## DistributedConfig<sup>10+</sup> 847 848Defines the configuration of the distributed mode of tables. 849 850**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 851 852| Name | Type | Mandatory| Description | 853| -------- | ------- | ---- | ------------------------------------------------------------ | 854| autoSync | boolean | Yes | The value **true** means both auto sync and manual sync are supported for the table. The value **false** means only manual sync is supported for the table.| 855 856## ConflictResolution<sup>10+</sup> 857 858Defines the resolution to use when a conflict occurs during data insertion or modification. Use the enum name rather than the enum value. 859 860**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 861 862| Name | Value | Description | 863| -------------------- | ---- | ------------------------------------------------------------ | 864| ON_CONFLICT_NONE | 0 | No operation is performed.| 865| ON_CONFLICT_ROLLBACK | 1 | Abort the SQL statement and roll back the current transaction. | 866| ON_CONFLICT_ABORT | 2 | Abort the current SQL statement and revert any changes made by the current SQL statement. However, the changes made by the previous SQL statement in the same transaction are retained and the transaction remains active.| 867| ON_CONFLICT_FAIL | 3 | Abort the current SQL statement. The **FAIL** resolution does not revert previous changes made by the failed SQL statement or end the transaction.| 868| ON_CONFLICT_IGNORE | 4 | Skip the rows that contain constraint violations and continue to process the subsequent rows of the SQL statement.| 869| ON_CONFLICT_REPLACE | 5 | Delete pre-existing rows that cause the constraint violation before inserting or updating the current row, and continue to execute the command normally.| 870 871## Progress<sup>10+</sup> 872 873Enumerates the stages in the device-cloud sync progress. Use the enum name rather than the enum value. 874 875**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 876 877| Name | Value | Description | 878| ---------------- | ---- | ------------------------ | 879| SYNC_BEGIN | 0 | The device-cloud sync starts. | 880| SYNC_IN_PROGRESS | 1 | The device-cloud sync is in progress.| 881| SYNC_FINISH | 2 | The device-cloud sync is complete.| 882 883## Statistic<sup>10+</sup> 884 885Represents the device-cloud sync statistics information. 886 887**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 888 889| Name | Type | Mandatory| Description | 890| ---------- | ------ | ---- | ---------------------------------------- | 891| total | number | Yes | Total number of rows to be synchronized between the device and cloud in the database table. | 892| successful | number | Yes | Number of rows that are successfully synchronized between the device and cloud in the database table. | 893| failed | number | Yes | Number of rows that failed to be synchronized between the device and cloud in the database table. | 894| remained | number | Yes | Number of rows that are not executed for device-cloud sync in the database table.| 895 896## TableDetails<sup>10+</sup> 897 898Represents the upload and download statistics of device-cloud sync tasks. 899 900**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 901 902| Name | Type | Mandatory| Description | 903| -------- | ------------------------- | ---- | ------------------------------------------ | 904| upload | [Statistic](#statistic10) | Yes | Statistics of the device-cloud upload tasks.| 905| download | [Statistic](#statistic10) | Yes | Statistics of the device-cloud download tasks.| 906 907## ProgressCode<sup>10+</sup> 908 909Enumerates the device-cloud sync states. Use the enum name rather than the enum value. 910 911**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 912 913| Name | Value | Description | 914| --------------------- | ---- | ------------------------------------------------------------ | 915| SUCCESS | 0 | The device-cloud sync is successful. | 916| UNKNOWN_ERROR | 1 | An unknown error occurs during device-cloud sync. | 917| NETWORK_ERROR | 2 | A network error occurs during device-cloud sync. | 918| CLOUD_DISABLED | 3 | The cloud is unavailable. | 919| LOCKED_BY_OTHERS | 4 | The device-cloud sync of another device is being performed.<br>Start device-cloud sync after checking that cloud resources are not occupied by other devices.| 920| RECORD_LIMIT_EXCEEDED | 5 | The number of records or size of the data to be synchronized exceeds the maximum. The maximum value is configured on the cloud.| 921| NO_SPACE_FOR_ASSET | 6 | The remaining cloud space is less than the size of the data to be synchronized. | 922| BLOCKED_BY_NETWORK_STRATEGY<sup>12+</sup> | 7 | The device-cloud sync is blocked due to the network strategy. | 923 924## ProgressDetails<sup>10+</sup> 925 926Represents the statistics of the overall device-cloud sync (upload and download) tasks. 927 928**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 929 930| Name | Type | Mandatory| Description | 931| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | 932| schedule | [Progress](#progress10) | Yes | Device-cloud sync progress. | 933| code | [ProgressCode](#progresscode10) | Yes | Device-cloud sync state. | 934| details | Record<string, [TableDetails](#tabledetails10)> | Yes | Statistics of each table.<br>The key indicates the table name, and the value indicates the device-cloud sync statistics of the table.| 935 936## SqlExecutionInfo<sup>12+</sup> 937 938Represents statistics about SQL statements executed by the database. 939 940**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 941 942| Name | Type | Read-Only| Optional |Description | 943| -------- | ------------------------------------------------- | ---- | ---- | -------------------------------------------------------- | 944| sql<sup>12+</sup> | Array<string> | Yes | No | SQL statements executed. If the value of [batchInsert](#batchinsert) is too large, there may be multiple SQL statements. | 945| totalTime<sup>12+</sup> | number | Yes | No | Total time used to execute the SQL statements, in μs. | 946| waitTime<sup>12+</sup> | number | Yes | No | Time used to obtain the handle, in μs. | 947| prepareTime<sup>12+</sup> | number | Yes | No | Time used to get the SQL statements ready and bind parameters, in μs. | 948| executeTime<sup>12+</sup> | number | Yes | No | Total time used to execute the SQL statements, in μs.| 949 950## TransactionType<sup>14+</sup> 951 952Enumerates the types of transaction objects that can be created. Use the enum name rather than the enum value. 953 954**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 955 956| Name | Value | Description | 957| ---------------- | ---- | ------------------------ | 958| DEFERRED | 0 | Deferred transaction object. When a deferred transaction object is created, automatic commit is disabled and no transaction will start. A read or write transaction starts only when the first read or write operation is performed. | 959| IMMEDIATE | 1 | Immediate transaction object. When an immediate transaction object is created, a write transaction starts. If there is any uncommitted write transaction, the transaction object cannot be created and error 14800024 is returned.| 960| EXCLUSIVE | 2 | Exclusive transaction object. In WAL mode, the exclusive transaction object is the same as the immediate transaction object. In other log modes, this type of transaction can prevent the database from being read by other connections during the transaction.| 961 962## TransactionOptions<sup>14+</sup> 963 964Represents the configuration of a transaction object. 965 966**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 967 968| Name | Type | Mandatory| Description | 969| ------------- | ------------- | ---- | --------------------------------------------------------- | 970| transactionType | [TransactionType](#transactiontype14) | No | Transaction object type. <br>Default value: **DEFERRED**. | 971 972## RdbPredicates 973 974Defines the predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false. Multiple predicates statements can be concatenated by using **and()** by default. **RdbPredicates** cannot be passed across threads. 975 976### constructor 977 978constructor(name: string) 979 980A constructor used to create an **RdbPredicates** object. 981 982**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 983 984**Parameters** 985 986| Name| Type | Mandatory| Description | 987| ------ | ------ | ---- | ------------ | 988| name | string | Yes | Database table name.| 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| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 997 998**Example** 999 1000```ts 1001let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1002``` 1003 1004### inDevices 1005 1006inDevices(devices: Array<string>): RdbPredicates 1007 1008Sets an **RdbPredicates** object to specify the remote devices to connect during the distributed database sync. 1009 1010> **NOTE** 1011> 1012> **devices** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 1013If **inDevices** is specified in **predicates** when **sync()** is called, data is synchronized with the specified device. If **inDevices** is not specified, data is synchronized with all devices on the network by default. 1014 1015**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1016 1017**Parameters** 1018 1019| Name | Type | Mandatory| Description | 1020| ------- | ------------------- | ---- | -------------------------- | 1021| devices | Array<string> | Yes | IDs of the remote devices in the same network.| 1022 1023**Return value** 1024 1025| Type | Description | 1026| ------------------------------------ | -------------------------- | 1027| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1028 1029**Error codes** 1030 1031For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1032 1033| **ID**| **Error Message** | 1034| --------- |----------------------------------------------------------------------------------------------------------------| 1035| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1036 1037**Example** 1038 1039```ts 1040import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 1041import { BusinessError } from '@kit.BasicServicesKit'; 1042 1043let dmInstance: distributedDeviceManager.DeviceManager; 1044let deviceIds: Array<string> = []; 1045 1046try { 1047 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 1048 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 1049 for (let i = 0; i < devices.length; i++) { 1050 deviceIds[i] = devices[i].networkId!; 1051 } 1052} catch (err) { 1053 let code = (err as BusinessError).code; 1054 let message = (err as BusinessError).message 1055 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 1056} 1057 1058let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1059predicates.inDevices(deviceIds); 1060``` 1061 1062### inAllDevices 1063 1064inAllDevices(): RdbPredicates 1065 1066Sets an **RdbPredicates** object to specify all remote devices to connect during the distributed database sync. 1067 1068 1069**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1070 1071**Return value** 1072 1073| Type | Description | 1074| ------------------------------------ | -------------------------- | 1075| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1076 1077**Example** 1078 1079```ts 1080let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1081predicates.inAllDevices(); 1082``` 1083 1084### equalTo 1085 1086equalTo(field: string, value: ValueType): RdbPredicates 1087 1088Sets an **RdbPredicates** object to match the fields in the specified column that are equal to the given value. 1089 1090**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1091 1092**Parameters** 1093 1094| Name| Type | Mandatory| Description | 1095| ------ | ----------------------- | ---- | ---------------------- | 1096| field | string | Yes | Column name in the database table. | 1097| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1098 1099**Return value** 1100 1101| Type | Description | 1102| ------------------------------------ | -------------------------- | 1103| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1104 1105**Error codes** 1106 1107For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1108 1109| **ID**| **Error Message** | 1110| --------- |----------------------------------------------------------------------------------------------------------------| 1111| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1112 1113**Example** 1114 1115```ts 1116// Locate data of Lisa in the EMPLOYEE table. 1117let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1118predicates.equalTo("NAME", "Lisa"); 1119``` 1120 1121 1122### notEqualTo 1123 1124notEqualTo(field: string, value: ValueType): RdbPredicates 1125 1126Sets an **RdbPredicates** object to match the fields in the specified column that are not equal to the given value. 1127 1128**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1129 1130**Parameters** 1131 1132| Name| Type | Mandatory| Description | 1133| ------ | ----------------------- | ---- | ---------------------- | 1134| field | string | Yes | Column name in the database table. | 1135| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1136 1137**Return value** 1138 1139| Type | Description | 1140| ------------------------------------ | -------------------------- | 1141| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1142 1143**Error codes** 1144 1145For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1146 1147| **ID**| **Error Message** | 1148| --------- |----------------------------------------------------------------------------------------------------------------| 1149| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1150 1151**Example** 1152 1153```ts 1154// Locate data of the employees whose name is not Lisa in the table. 1155let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1156predicates.notEqualTo("NAME", "Lisa"); 1157``` 1158 1159 1160### beginWrap 1161 1162beginWrap(): RdbPredicates 1163 1164Adds a left parenthesis to the **RdbPredicates**. 1165 1166**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1167 1168**Return value** 1169 1170| Type | Description | 1171| ------------------------------------ | ------------------------- | 1172| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.| 1173 1174**Example** 1175 1176```ts 1177let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1178predicates.equalTo("NAME", "Lisa") 1179 .beginWrap() 1180 .equalTo("AGE", 18) 1181 .or() 1182 .equalTo("SALARY", 200.5) 1183 .endWrap() 1184``` 1185 1186### endWrap 1187 1188endWrap(): RdbPredicates 1189 1190Adds a right parenthesis to the **RdbPredicates**. 1191 1192**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1193 1194**Return value** 1195 1196| Type | Description | 1197| ------------------------------------ | ------------------------- | 1198| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.| 1199 1200**Example** 1201 1202```ts 1203let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1204predicates.equalTo("NAME", "Lisa") 1205 .beginWrap() 1206 .equalTo("AGE", 18) 1207 .or() 1208 .equalTo("SALARY", 200.5) 1209 .endWrap() 1210``` 1211 1212### or 1213 1214or(): RdbPredicates 1215 1216Adds the OR condition to the **RdbPredicates**. 1217 1218**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1219 1220**Return value** 1221 1222| Type | Description | 1223| ------------------------------------ | ------------------------- | 1224| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.| 1225 1226**Example** 1227 1228```ts 1229// Locate the employees named Lisa or Rose in the table. 1230let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1231predicates.equalTo("NAME", "Lisa") 1232 .or() 1233 .equalTo("NAME", "Rose") 1234``` 1235 1236### and 1237 1238and(): RdbPredicates 1239 1240Adds the AND condition to the **RdbPredicates**. 1241 1242**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1243 1244**Return value** 1245 1246| Type | Description | 1247| ------------------------------------ | ------------------------- | 1248| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.| 1249 1250**Example** 1251 1252```ts 1253// Locate the field with name of Lisa and salary of 200.5 in the table. 1254let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1255predicates.equalTo("NAME", "Lisa") 1256 .and() 1257 .equalTo("SALARY", 200.5) 1258``` 1259 1260### contains 1261 1262contains(field: string, value: string): RdbPredicates 1263 1264Sets an **RdbPredicates** object to match the fields in the specified column that contain the given value. 1265 1266**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1267 1268**Parameters** 1269 1270| Name| Type | Mandatory| Description | 1271| ------ | ------ | ---- | ---------------------- | 1272| field | string | Yes | Column name in the database table. | 1273| value | string | Yes | Value to match the **RdbPredicates**.| 1274 1275**Return value** 1276 1277| Type | Description | 1278| ------------------------------------ | -------------------------- | 1279| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1280 1281**Error codes** 1282 1283For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1284 1285| **ID**| **Error Message** | 1286| --------- |----------------------------------------------------------------------------------------------------------------| 1287| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1288 1289**Example** 1290 1291```ts 1292// Locate data of the employees whose name contains os, for example, Rose, in the table. 1293let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1294predicates.contains("NAME", "os"); 1295``` 1296 1297### beginsWith 1298 1299beginsWith(field: string, value: string): RdbPredicates 1300 1301Sets an **RdbPredicates** object to match the fields in the specified column that begin with the given value. 1302 1303**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1304 1305**Parameters** 1306 1307| Name| Type | Mandatory| Description | 1308| ------ | ------ | ---- | ---------------------- | 1309| field | string | Yes | Column name in the database table. | 1310| value | string | Yes | Value to match the **RdbPredicates**.| 1311 1312**Return value** 1313 1314| Type | Description | 1315| ------------------------------------ | -------------------------- | 1316| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1317 1318**Error codes** 1319 1320For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1321 1322| **ID**| **Error Message** | 1323| --------- |----------------------------------------------------------------------------------------------------------------| 1324| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1325 1326**Example** 1327 1328```ts 1329// Locate data of the employees whose name begins with Li, for example, Lisa, in the table. 1330let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1331predicates.beginsWith("NAME", "Li"); 1332``` 1333 1334### endsWith 1335 1336endsWith(field: string, value: string): RdbPredicates 1337 1338Sets an **RdbPredicates** object to match the fields in the specified column that end with the given value. 1339 1340**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1341 1342**Parameters** 1343 1344| Name| Type | Mandatory| Description | 1345| ------ | ------ | ---- | ---------------------- | 1346| field | string | Yes | Column name in the database table. | 1347| value | string | Yes | Value to match the **RdbPredicates**.| 1348 1349**Return value** 1350 1351| Type | Description | 1352| ------------------------------------ | -------------------------- | 1353| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1354 1355**Error codes** 1356 1357For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1358 1359| **ID**| **Error Message** | 1360| --------- |----------------------------------------------------------------------------------------------------------------| 1361| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1362 1363**Example** 1364 1365```ts 1366// Locate data of the employees whose name ends with se, for example, Rose, in the table. 1367let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1368predicates.endsWith("NAME", "se"); 1369``` 1370 1371### isNull 1372 1373isNull(field: string): RdbPredicates 1374 1375Sets an **RdbPredicates** object to match the fields in the specified column that are **null**. 1376 1377**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1378 1379**Parameters** 1380 1381| Name| Type | Mandatory| Description | 1382| ------ | ------ | ---- | ------------------ | 1383| field | string | Yes | Column name in the database table.| 1384 1385**Return value** 1386 1387| Type | Description | 1388| ------------------------------------ | -------------------------- | 1389| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1390 1391**Error codes** 1392 1393For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1394 1395| **ID**| **Error Message** | 1396| --------- |----------------------------------------------------------------------------------------------------------------| 1397| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1398 1399**Example** 1400 1401```ts 1402let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1403predicates.isNull("NAME"); 1404``` 1405 1406### isNotNull 1407 1408isNotNull(field: string): RdbPredicates 1409 1410Sets an **RdbPredicates** object to match the fields in the specified column that are not **null**. 1411 1412**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1413 1414**Parameters** 1415 1416| Name| Type | Mandatory| Description | 1417| ------ | ------ | ---- | ------------------ | 1418| field | string | Yes | Column name in the database table.| 1419 1420**Return value** 1421 1422| Type | Description | 1423| ------------------------------------ | -------------------------- | 1424| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1425 1426**Error codes** 1427 1428For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1429 1430| **ID**| **Error Message** | 1431| --------- |----------------------------------------------------------------------------------------------------------------| 1432| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1433 1434**Example** 1435 1436```ts 1437let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1438predicates.isNotNull("NAME"); 1439``` 1440 1441### like 1442 1443like(field: string, value: string): RdbPredicates 1444 1445Sets an **RdbPredicates** object to match the fields in the specified column that are similar to the given value. 1446 1447**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1448 1449**Parameters** 1450 1451| Name| Type | Mandatory| Description | 1452| ------ | ------ | ---- | ---------------------- | 1453| field | string | Yes | Column name in the database table. | 1454| value | string | Yes | Value to match the **RdbPredicates**.| 1455 1456**Return value** 1457 1458| Type | Description | 1459| ------------------------------------ | -------------------------- | 1460| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1461 1462**Error codes** 1463 1464For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1465 1466| **ID**| **Error Message** | 1467| --------- |----------------------------------------------------------------------------------------------------------------| 1468| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1469 1470**Example** 1471 1472```ts 1473// Locate data of the employees whose name is similar to os in the table, for example, Rose. 1474let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1475predicates.like("NAME", "%os%"); 1476``` 1477 1478### glob 1479 1480glob(field: string, value: string): RdbPredicates 1481 1482Sets an **RdbPredicates** object to locate the fields in the specified column that match the given string. 1483 1484**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1485 1486**Parameters** 1487 1488| Name| Type | Mandatory| Description | 1489| ------ | ------ | ---- | ------------------------------------------------------------ | 1490| field | string | Yes | Column name in the database table. | 1491| value | string | Yes | Value to match the **RdbPredicates**.<br><br>Wildcards are supported. * indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character.| 1492 1493**Return value** 1494 1495| Type | Description | 1496| ------------------------------------ | -------------------------- | 1497| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1498 1499**Error codes** 1500 1501For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1502 1503| **ID**| **Error Message** | 1504| --------- |----------------------------------------------------------------------------------------------------------------| 1505| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1506 1507**Example** 1508 1509```ts 1510// Locate data of the employees whose name matches the "?h*g" string in the table. 1511let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1512predicates.glob("NAME", "?h*g"); 1513``` 1514 1515### between 1516 1517between(field: string, low: ValueType, high: ValueType): RdbPredicates 1518 1519Sets an **RdbPredicates** object to match the fields in the specified column that are within the given range (including the min. and max. values). 1520 1521**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1522 1523**Parameters** 1524 1525| Name| Type | Mandatory| Description | 1526| ------ | ----------------------- | ---- | -------------------------- | 1527| field | string | Yes | Column name in the database table. | 1528| low | [ValueType](#valuetype) | Yes | Minimum value to match. | 1529| high | [ValueType](#valuetype) | Yes | Maximum value to match.| 1530 1531**Return value** 1532 1533| Type | Description | 1534| ------------------------------------ | -------------------------- | 1535| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1536 1537**Error codes** 1538 1539For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1540 1541| **ID**| **Error Message** | 1542| --------- |----------------------------------------------------------------------------------------------------------------| 1543| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1544 1545**Example** 1546 1547```ts 1548// Locate data of the employees with age between 10 and 50 (including 10 and 50) in the table. 1549let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1550predicates.between("AGE", 10, 50); 1551``` 1552 1553### notBetween 1554 1555notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates 1556 1557Sets an **RdbPredicates** object to match the fields in the specified column that are out of the given range (excluding the min. and max. values). 1558 1559**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1560 1561**Parameters** 1562 1563| Name| Type | Mandatory| Description | 1564| ------ | ----------------------- | ---- | -------------------------- | 1565| field | string | Yes | Column name in the database table. | 1566| low | [ValueType](#valuetype) | Yes | Minimum value to match. | 1567| high | [ValueType](#valuetype) | Yes | Maximum value to match.| 1568 1569**Return value** 1570 1571| Type | Description | 1572| ------------------------------------ | -------------------------- | 1573| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1574 1575**Error codes** 1576 1577For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1578 1579| **ID**| **Error Message** | 1580| --------- |----------------------------------------------------------------------------------------------------------------| 1581| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1582 1583**Example** 1584 1585```ts 1586// Locate data of the employees who are younger than 10 or older than 50 in the table. 1587let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1588predicates.notBetween("AGE", 10, 50); 1589``` 1590 1591### greaterThan 1592 1593greaterThan(field: string, value: ValueType): RdbPredicates 1594 1595Sets an **RdbPredicates** object to match the fields in the specified column that are greater than the given value. 1596 1597**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1598 1599**Parameters** 1600 1601| Name| Type | Mandatory| Description | 1602| ------ | ----------------------- | ---- | ---------------------- | 1603| field | string | Yes | Column name in the database table. | 1604| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1605 1606**Return value** 1607 1608| Type | Description | 1609| ------------------------------------ | -------------------------- | 1610| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1611 1612**Error codes** 1613 1614For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1615 1616| **ID**| **Error Message** | 1617| --------- |----------------------------------------------------------------------------------------------------------------| 1618| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1619 1620**Example** 1621 1622```ts 1623// Locate data of the employees who are older than 18 in the table. 1624let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1625predicates.greaterThan("AGE", 18); 1626``` 1627 1628### lessThan 1629 1630lessThan(field: string, value: ValueType): RdbPredicates 1631 1632Sets an **RdbPredicates** object to match the fields in the specified column that are less than the given value. 1633 1634**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1635 1636**Parameters** 1637 1638| Name| Type | Mandatory| Description | 1639| ------ | ----------------------- | ---- | ---------------------- | 1640| field | string | Yes | Column name in the database table. | 1641| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1642 1643**Return value** 1644 1645| Type | Description | 1646| ------------------------------------ | -------------------------- | 1647| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1648 1649**Error codes** 1650 1651For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1652 1653| **ID**| **Error Message** | 1654| --------- |----------------------------------------------------------------------------------------------------------------| 1655| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1656 1657**Example** 1658 1659```ts 1660// Locate data of the employees who are younger than 20 in the table. 1661let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1662predicates.lessThan("AGE", 20); 1663``` 1664 1665### greaterThanOrEqualTo 1666 1667greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1668 1669Sets an **RdbPredicates** object to match the fields in the specified column that are greater than or equal to the given value. 1670 1671**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1672 1673**Parameters** 1674 1675| Name| Type | Mandatory| Description | 1676| ------ | ----------------------- | ---- | ---------------------- | 1677| field | string | Yes | Column name in the database table. | 1678| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1679 1680**Return value** 1681 1682| Type | Description | 1683| ------------------------------------ | -------------------------- | 1684| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1685 1686**Error codes** 1687 1688For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1689 1690| **ID**| **Error Message** | 1691| --------- |----------------------------------------------------------------------------------------------------------------| 1692| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1693 1694**Example** 1695 1696```ts 1697// Locate data of the employees who are 18 or older in the table. 1698let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1699predicates.greaterThanOrEqualTo("AGE", 18); 1700``` 1701 1702### lessThanOrEqualTo 1703 1704lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1705 1706Sets an **RdbPredicates** object to match the fields in the specified column that are less than or equal to the given value. 1707 1708**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1709 1710**Parameters** 1711 1712| Name| Type | Mandatory| Description | 1713| ------ | ----------------------- | ---- | ---------------------- | 1714| field | string | Yes | Column name in the database table. | 1715| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1716 1717**Return value** 1718 1719| Type | Description | 1720| ------------------------------------ | -------------------------- | 1721| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1722 1723**Error codes** 1724 1725For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1726 1727| **ID**| **Error Message** | 1728| --------- |----------------------------------------------------------------------------------------------------------------| 1729| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1730 1731**Example** 1732 1733```ts 1734// Locate data of the employees who are 20 or younger in the table. 1735let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1736predicates.lessThanOrEqualTo("AGE", 20); 1737``` 1738 1739### orderByAsc 1740 1741orderByAsc(field: string): RdbPredicates 1742 1743Sets an **RdbPredicates** object to sort the fields in the specified column in ascending order. 1744 1745**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1746 1747**Parameters** 1748 1749| Name| Type | Mandatory| Description | 1750| ------ | ------ | ---- | ------------------ | 1751| field | string | Yes | Column name in the database table.| 1752 1753**Return value** 1754 1755| Type | Description | 1756| ------------------------------------ | -------------------------- | 1757| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1758 1759**Error codes** 1760 1761For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1762 1763| **ID**| **Error Message** | 1764| --------- |----------------------------------------------------------------------------------------------------------------| 1765| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1766 1767**Example** 1768 1769```ts 1770let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1771predicates.orderByAsc("NAME"); 1772``` 1773 1774### orderByDesc 1775 1776orderByDesc(field: string): RdbPredicates 1777 1778Sets an **RdbPredicates** object to sort the fields in the specified column in descending order. 1779 1780**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1781 1782**Parameters** 1783 1784| Name| Type | Mandatory| Description | 1785| ------ | ------ | ---- | ------------------ | 1786| field | string | Yes | Column name in the database table.| 1787 1788**Return value** 1789 1790| Type | Description | 1791| ------------------------------------ | -------------------------- | 1792| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1793 1794**Error codes** 1795 1796For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1797 1798| **ID**| **Error Message** | 1799| --------- |----------------------------------------------------------------------------------------------------------------| 1800| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1801 1802**Example** 1803 1804```ts 1805let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1806predicates.orderByDesc("AGE"); 1807``` 1808 1809### distinct 1810 1811distinct(): RdbPredicates 1812 1813Sets an **RdbPredicates** object to filter out duplicate records. 1814 1815**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1816 1817**Return value** 1818 1819| Type | Description | 1820| ------------------------------------ | ------------------------------ | 1821| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.| 1822 1823**Example** 1824 1825```ts 1826let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1827predicates.equalTo("NAME", "Rose").distinct(); 1828``` 1829 1830### limitAs 1831 1832limitAs(value: number): RdbPredicates 1833 1834Sets an **RdbPredicates** object to specify the maximum number of records. 1835 1836**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1837 1838**Parameters** 1839 1840| Name| Type | Mandatory| Description | 1841| ------ | ------ | ---- | ---------------- | 1842| value | number | Yes | Maximum number of records.| 1843 1844**Return value** 1845 1846| Type | Description | 1847| ------------------------------------ | ------------------------------------ | 1848| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.| 1849 1850**Error codes** 1851 1852For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1853 1854| **ID**| **Error Message** | 1855| --------- |--------------------------| 1856| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1857 1858**Example** 1859 1860```ts 1861let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1862predicates.equalTo("NAME", "Rose").limitAs(3); 1863``` 1864 1865### offsetAs 1866 1867offsetAs(rowOffset: number): RdbPredicates 1868 1869Sets an **RdbPredicates** object to specify the start position of the returned result. 1870 1871**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1872 1873**Parameters** 1874 1875| Name | Type | Mandatory| Description | 1876| --------- | ------ | ---- | ---------------------------------- | 1877| rowOffset | number | Yes | Number of rows to offset from the beginning. The value is a positive integer.| 1878 1879**Return value** 1880 1881| Type | Description | 1882| ------------------------------------ | ------------------------------------ | 1883| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.| 1884 1885**Error codes** 1886 1887For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1888 1889| **ID**| **Error Message** | 1890| --------- |----------------------------------------------------------------------------------------------------------------| 1891| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1892 1893**Example** 1894 1895```ts 1896let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1897predicates.equalTo("NAME", "Rose").offsetAs(3); 1898``` 1899 1900### groupBy 1901 1902groupBy(fields: Array<string>): RdbPredicates 1903 1904Sets an **RdbPredicates** object to group rows that have the same value into summary rows. 1905 1906**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1907 1908**Parameters** 1909 1910| Name| Type | Mandatory| Description | 1911| ------ | ------------------- | ---- | -------------------- | 1912| fields | Array<string> | Yes | Names of columns to group.| 1913 1914**Return value** 1915 1916| Type | Description | 1917| ------------------------------------ | ---------------------- | 1918| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.| 1919 1920**Error codes** 1921 1922For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1923 1924| **ID**| **Error Message** | 1925| --------- |----------------------------------------------------------------------------------------------------------------| 1926| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1927 1928**Example** 1929 1930```ts 1931let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1932predicates.groupBy(["AGE", "NAME"]); 1933``` 1934 1935### indexedBy 1936 1937indexedBy(field: string): RdbPredicates 1938 1939Sets an **RdbPredicates** object to specify the index column. 1940 1941**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1942 1943**Parameters** 1944 1945| Name| Type | Mandatory| Description | 1946| ------ | ------ | ---- | -------------- | 1947| field | string | Yes | Name of the index column.| 1948 1949**Return value** 1950 1951 1952| Type | Description | 1953| ------------------------------------ | ------------------------------------- | 1954| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.| 1955 1956**Error codes** 1957 1958For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1959 1960| **ID**| **Error Message** | 1961| --------- |----------------------------------------------------------------------------------------------------------------| 1962| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1963 1964**Example** 1965 1966```ts 1967let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1968predicates.indexedBy("SALARY"); 1969``` 1970 1971### in 1972 1973in(field: string, value: Array<ValueType>): RdbPredicates 1974 1975Sets an **RdbPredicates** object to match the fields in the specified column that are in the given range. 1976 1977**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1978 1979**Parameters** 1980 1981| Name| Type | Mandatory| Description | 1982| ------ | ------------------------------------ | ---- | --------------------------------------- | 1983| field | string | Yes | Column name in the database table. | 1984| value | Array<[ValueType](#valuetype)> | Yes | Array of **ValueType**s to match.| 1985 1986**Return value** 1987 1988| Type | Description | 1989| ------------------------------------ | -------------------------- | 1990| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1991 1992**Error codes** 1993 1994For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1995 1996| **ID**| **Error Message** | 1997| --------- |----------------------------------------------------------------------------------------------------------------| 1998| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1999 2000**Example** 2001 2002```ts 2003// Locate data of the employees with age of [18, 20] in the table. 2004let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2005predicates.in("AGE", [18, 20]); 2006``` 2007 2008### notIn 2009 2010notIn(field: string, value: Array<ValueType>): RdbPredicates 2011 2012Sets an **RdbPredicates** object to match the fields in the specified column that are out of the given range. 2013 2014**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2015 2016**Parameters** 2017 2018| Name| Type | Mandatory| Description | 2019| ------ | ------------------------------------ | ---- | ------------------------------------- | 2020| field | string | Yes | Column name in the database table. | 2021| value | Array<[ValueType](#valuetype)> | Yes | Array of **ValueType**s to match.| 2022 2023**Return value** 2024 2025| Type | Description | 2026| ------------------------------------ | -------------------------- | 2027| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2028 2029**Error codes** 2030 2031For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2032 2033| **ID**| **Error Message** | 2034| --------- |----------------------------------------------------------------------------------------------------------------| 2035| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2036 2037**Example** 2038 2039```ts 2040// Locate data of all the employees except Lisa and Rose in the table. 2041let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2042predicates.notIn("NAME", ["Lisa", "Rose"]); 2043``` 2044 2045### notContains<sup>12+</sup> 2046 2047notContains(field: string, value: string): RdbPredicates 2048 2049Sets an **RdbPredicates** object to match the fields in the specified column that do not contain the given value. 2050 2051**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2052 2053**Parameters** 2054 2055| Name| Type | Mandatory| Description | 2056| ------ | ------ | ---- | ---------------------- | 2057| field | string | Yes | Column name in the database table. | 2058| value | string | Yes | Value to match the **RdbPredicates**.| 2059 2060**Return value** 2061 2062| Type | Description | 2063| ------------------------------- | -------------------------- | 2064| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2065 2066**Error codes** 2067 2068For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2069 2070| **ID**| **Error Message** | 2071| --------- |----------------------------------------------------------------------------------------------------------------| 2072| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2073 2074**Example** 2075 2076```ts 2077// Match the fields that do not contain "os" in the NAME column of the data table, for example, Lisa in the list. 2078let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2079predicates.notContains("NAME", "os"); 2080``` 2081 2082### notLike<sup>12+</sup> 2083 2084notLike(field: string, value: string): RdbPredicates 2085 2086Sets an **RdbPredicates** object to match the fields in the specified column that are not similar to the given value. 2087 2088**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2089 2090**Parameters** 2091 2092| Name| Type | Mandatory| Description | 2093| ------ | ------ | ---- | ---------------------- | 2094| field | string | Yes | Column name in the database table. | 2095| value | string | Yes | Value to match the **RdbPredicates**.| 2096 2097**Return value** 2098 2099| Type | Description | 2100| ------------------------------- | -------------------------- | 2101| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2102 2103**Error codes** 2104 2105For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2106 2107| **ID**| **Error Message** | 2108| --------- |----------------------------------------------------------------------------------------------------------------| 2109| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2110 2111**Example** 2112 2113```ts 2114// Match the fields that are not "os" in the NAME column of the data table, for example, Rose in the list. 2115let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2116predicates.notLike("NAME", "os"); 2117``` 2118 2119 2120 2121## RdbStore 2122 2123Provides APIs to manage an RDB store. 2124 2125Before using the APIs of this class, use [executeSql](#executesql) to initialize the database table structure and related data. 2126 2127### Properties 2128 2129**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2130 2131| Name | Type | Read-Only | Optional| Description | 2132| ------------ | ----------- | ---- | -------------------------------- | -------------------------------- | 2133| version<sup>10+</sup> | number | No| No | RDB store version, which is an integer greater than 0. | 2134| rebuilt<sup>12+</sup> | [RebuildType](#rebuildtype12) | Yes| No| Whether the RDB store has been rebuilt or repaired.| 2135 2136**Error codes** 2137 2138For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 2139 2140| **ID**| **Error Message** | 2141|-----------| ------------------------------------------------------------ | 2142| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2143| 801 | Capability not supported. | 2144| 14800000 | Inner error. | 2145| 14800014 | Already closed. | 2146| 14800015 | The database does not respond. | 2147| 14800021 | SQLite: Generic error. | 2148| 14800023 | SQLite: Access permission denied. | 2149| 14800024 | SQLite: The database file is locked. | 2150| 14800025 | SQLite: A table in the database is locked. | 2151| 14800026 | SQLite: The database is out of memory. | 2152| 14800027 | SQLite: Attempt to write a readonly database. | 2153| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2154| 14800029 | SQLite: The database is full. | 2155| 14800030 | SQLite: Unable to open the database file. | 2156 2157**Example** 2158 2159```ts 2160import { UIAbility } from '@kit.AbilityKit'; 2161import { BusinessError } from '@kit.BasicServicesKit'; 2162import { window } from '@kit.ArkUI'; 2163 2164let store: relationalStore.RdbStore | undefined = undefined; 2165 2166class EntryAbility extends UIAbility { 2167 onWindowStageCreate(windowStage: window.WindowStage) { 2168 const STORE_CONFIG: relationalStore.StoreConfig = { 2169 name: "RdbTest.db", 2170 securityLevel: relationalStore.SecurityLevel.S3, 2171 }; 2172 2173 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 2174 store = rdbStore; 2175 console.info('Get RdbStore successfully.') 2176 }).catch((err: BusinessError) => { 2177 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 2178 }) 2179 2180 // Set the RDB store version. 2181 if(store != undefined) { 2182 (store as relationalStore.RdbStore).version = 3; 2183 // Obtain the RDB store version. 2184 console.info(`RdbStore version is ${store.version}`); 2185 // Whether the RDB store has been rebuilt. 2186 console.info(`RdbStore rebuilt is ${store.rebuilt}`); 2187 } 2188 } 2189} 2190``` 2191 2192### insert 2193 2194insert(table: string, values: ValuesBucket, callback: AsyncCallback<number>):void 2195 2196Inserts a row of data into a table. 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. 2197 2198**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2199 2200**Parameters** 2201 2202| Name | Type | Mandatory| Description | 2203| -------- | ----------------------------- | ---- | ---------------------------------------------------------- | 2204| table | string | Yes | Name of the target table. | 2205| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2206| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2207 2208**Error codes** 2209 2210For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 2211 2212| **ID**| **Error Message** | 2213|-----------| ------------------------------------------------------------ | 2214| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2215| 14800000 | Inner error. | 2216| 14800011 | Database corrupted. | 2217| 14800014 | Already closed. | 2218| 14800015 | The database does not respond. | 2219| 14800021 | SQLite: Generic error. | 2220| 14800022 | SQLite: Callback routine requested an abort. | 2221| 14800023 | SQLite: Access permission denied. | 2222| 14800024 | SQLite: The database file is locked. | 2223| 14800025 | SQLite: A table in the database is locked. | 2224| 14800026 | SQLite: The database is out of memory. | 2225| 14800027 | SQLite: Attempt to write a readonly database. | 2226| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2227| 14800029 | SQLite: The database is full. | 2228| 14800030 | SQLite: Unable to open the database file. | 2229| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2230| 14800032 | SQLite: Abort due to constraint violation. | 2231| 14800033 | SQLite: Data type mismatch. | 2232| 14800034 | SQLite: Library used incorrectly. | 2233| 14800047 | The WAL file size exceeds the default limit. | 2234 2235**Example** 2236 2237```ts 2238let value1 = "Lisa"; 2239let value2 = 18; 2240let value3 = 100.5; 2241let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2242 2243// You can use either of the following: 2244const valueBucket1: relationalStore.ValuesBucket = { 2245 'NAME': value1, 2246 'AGE': value2, 2247 'SALARY': value3, 2248 'CODES': value4, 2249}; 2250const valueBucket2: relationalStore.ValuesBucket = { 2251 NAME: value1, 2252 AGE: value2, 2253 SALARY: value3, 2254 CODES: value4, 2255}; 2256const valueBucket3: relationalStore.ValuesBucket = { 2257 "NAME": value1, 2258 "AGE": value2, 2259 "SALARY": value3, 2260 "CODES": value4, 2261}; 2262 2263if(store != undefined) { 2264 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, (err: BusinessError, rowId: number) => { 2265 if (err) { 2266 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2267 return; 2268 } 2269 console.info(`Insert is successful, rowId = ${rowId}`); 2270 }) 2271} 2272``` 2273 2274### insert<sup>10+</sup> 2275 2276insert(table: string, values: ValuesBucket, conflict: ConflictResolution, callback: AsyncCallback<number>):void 2277 2278Inserts a row of data into a table. 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. 2279 2280**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2281 2282**Parameters** 2283 2284| Name | Type | Mandatory| Description | 2285| -------- | ------------------------------------------- | ---- | ---------------------------------------------------------- | 2286| table | string | Yes | Name of the target table. | 2287| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2288| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 2289| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2290 2291**Error codes** 2292 2293For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 2294 2295| **ID**| **Error Message** | 2296|-----------| ---------------------------------------------------- | 2297| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2298| 14800000 | Inner error. | 2299| 14800011 | Database corrupted. | 2300| 14800014 | Already closed. | 2301| 14800015 | The database does not respond. | 2302| 14800021 | SQLite: Generic error. | 2303| 14800022 | SQLite: Callback routine requested an abort. | 2304| 14800023 | SQLite: Access permission denied. | 2305| 14800024 | SQLite: The database file is locked. | 2306| 14800025 | SQLite: A table in the database is locked. | 2307| 14800026 | SQLite: The database is out of memory. | 2308| 14800027 | SQLite: Attempt to write a readonly database. | 2309| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2310| 14800029 | SQLite: The database is full. | 2311| 14800030 | SQLite: Unable to open the database file. | 2312| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2313| 14800032 | SQLite: Abort due to constraint violation. | 2314| 14800033 | SQLite: Data type mismatch. | 2315| 14800034 | SQLite: Library used incorrectly. | 2316| 14800047 | The WAL file size exceeds the default limit. | 2317 2318**Example** 2319 2320```ts 2321let value1 = "Lisa"; 2322let value2 = 18; 2323let value3 = 100.5; 2324let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2325 2326// You can use either of the following: 2327const valueBucket1: relationalStore.ValuesBucket = { 2328 'NAME': value1, 2329 'AGE': value2, 2330 'SALARY': value3, 2331 'CODES': value4, 2332}; 2333const valueBucket2: relationalStore.ValuesBucket = { 2334 NAME: value1, 2335 AGE: value2, 2336 SALARY: value3, 2337 CODES: value4, 2338}; 2339const valueBucket3: relationalStore.ValuesBucket = { 2340 "NAME": value1, 2341 "AGE": value2, 2342 "SALARY": value3, 2343 "CODES": value4, 2344}; 2345 2346if(store != undefined) { 2347 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, 2348 (err: BusinessError, rowId: number) => { 2349 if (err) { 2350 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2351 return; 2352 } 2353 console.info(`Insert is successful, rowId = ${rowId}`); 2354 }) 2355} 2356``` 2357 2358### insert 2359 2360insert(table: string, values: ValuesBucket):Promise<number> 2361 2362Inserts a row of data into a table. 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. 2363 2364**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2365 2366**Parameters** 2367 2368| Name| Type | Mandatory| Description | 2369| ------ | ----------------------------- | ---- | -------------------------- | 2370| table | string | Yes | Name of the target table. | 2371| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 2372 2373**Return value** 2374 2375| Type | Description | 2376| --------------------- | ------------------------------------------------- | 2377| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2378 2379**Error codes** 2380 2381For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 2382 2383| **ID**| **Error Message** | 2384|-----------| ------------------------------------------------------------ | 2385| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2386| 14800000 | Inner error. | 2387| 14800011 | Database corrupted. | 2388| 14800014 | Already closed. | 2389| 14800015 | The database does not respond. | 2390| 14800021 | SQLite: Generic error. | 2391| 14800022 | SQLite: Callback routine requested an abort. | 2392| 14800023 | SQLite: Access permission denied. | 2393| 14800024 | SQLite: The database file is locked. | 2394| 14800025 | SQLite: A table in the database is locked. | 2395| 14800026 | SQLite: The database is out of memory. | 2396| 14800027 | SQLite: Attempt to write a readonly database. | 2397| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2398| 14800029 | SQLite: The database is full. | 2399| 14800030 | SQLite: Unable to open the database file. | 2400| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2401| 14800032 | SQLite: Abort due to constraint violation. | 2402| 14800033 | SQLite: Data type mismatch. | 2403| 14800034 | SQLite: Library used incorrectly. | 2404| 14800047 | The WAL file size exceeds the default limit. | 2405 2406**Example** 2407 2408```ts 2409import { BusinessError } from '@kit.BasicServicesKit'; 2410 2411let value1 = "Lisa"; 2412let value2 = 18; 2413let value3 = 100.5; 2414let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2415 2416// You can use either of the following: 2417const valueBucket1: relationalStore.ValuesBucket = { 2418 'NAME': value1, 2419 'AGE': value2, 2420 'SALARY': value3, 2421 'CODES': value4, 2422}; 2423const valueBucket2: relationalStore.ValuesBucket = { 2424 NAME: value1, 2425 AGE: value2, 2426 SALARY: value3, 2427 CODES: value4, 2428}; 2429const valueBucket3: relationalStore.ValuesBucket = { 2430 "NAME": value1, 2431 "AGE": value2, 2432 "SALARY": value3, 2433 "CODES": value4, 2434}; 2435 2436if(store != undefined) { 2437 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1).then((rowId: number) => { 2438 console.info(`Insert is successful, rowId = ${rowId}`); 2439 }).catch((err: BusinessError) => { 2440 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2441 }) 2442} 2443``` 2444 2445### insert<sup>10+</sup> 2446 2447insert(table: string, values: ValuesBucket, conflict: ConflictResolution):Promise<number> 2448 2449Inserts a row of data into a table. 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. 2450 2451**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2452 2453**Parameters** 2454 2455| Name | Type | Mandatory| Description | 2456| -------- | ------------------------------------------- | ---- | -------------------------- | 2457| table | string | Yes | Name of the target table. | 2458| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 2459| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 2460 2461**Return value** 2462 2463| Type | Description | 2464| --------------------- | ------------------------------------------------- | 2465| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2466 2467**Error codes** 2468 2469For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 2470 2471| **ID**| **Error Message** | 2472|-----------| ------------------------------------------------------------ | 2473| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2474| 14800000 | Inner error. | 2475| 14800011 | Database corrupted. | 2476| 14800014 | Already closed. | 2477| 14800015 | The database does not respond. | 2478| 14800021 | SQLite: Generic error. | 2479| 14800022 | SQLite: Callback routine requested an abort. | 2480| 14800023 | SQLite: Access permission denied. | 2481| 14800024 | SQLite: The database file is locked. | 2482| 14800025 | SQLite: A table in the database is locked. | 2483| 14800026 | SQLite: The database is out of memory. | 2484| 14800027 | SQLite: Attempt to write a readonly database. | 2485| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2486| 14800029 | SQLite: The database is full. | 2487| 14800030 | SQLite: Unable to open the database file. | 2488| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2489| 14800032 | SQLite: Abort due to constraint violation. | 2490| 14800033 | SQLite: Data type mismatch. | 2491| 14800034 | SQLite: Library used incorrectly. | 2492| 14800047 | The WAL file size exceeds the default limit. | 2493 2494**Example** 2495 2496```ts 2497import { BusinessError } from '@kit.BasicServicesKit'; 2498 2499let value1 = "Lisa"; 2500let value2 = 18; 2501let value3 = 100.5; 2502let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2503 2504// You can use either of the following: 2505const valueBucket1: relationalStore.ValuesBucket = { 2506 'NAME': value1, 2507 'AGE': value2, 2508 'SALARY': value3, 2509 'CODES': value4, 2510}; 2511const valueBucket2: relationalStore.ValuesBucket = { 2512 NAME: value1, 2513 AGE: value2, 2514 SALARY: value3, 2515 CODES: value4, 2516}; 2517const valueBucket3: relationalStore.ValuesBucket = { 2518 "NAME": value1, 2519 "AGE": value2, 2520 "SALARY": value3, 2521 "CODES": value4, 2522}; 2523 2524if(store != undefined) { 2525 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => { 2526 console.info(`Insert is successful, rowId = ${rowId}`); 2527 }).catch((err: BusinessError) => { 2528 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2529 }) 2530} 2531``` 2532 2533### insertSync<sup>12+</sup> 2534 2535insertSync(table: string, values: ValuesBucket, conflict?: ConflictResolution):number 2536 2537Inserts a row of data into a table. 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. 2538 2539**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2540 2541**Parameters** 2542 2543| Name | Type | Mandatory| Description | 2544| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 2545| table | string | Yes | Name of the target table. | 2546| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2547| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 2548 2549**Return value** 2550 2551| Type | Description | 2552| ------ | ------------------------------------ | 2553| number | If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2554 2555**Error codes** 2556 2557For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 2558 2559| **ID**| **Error Message** | 2560| ------------ | ------------------------------------------------------------ | 2561| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2562| 14800000 | Inner error. | 2563| 14800011 | Database corrupted. | 2564| 14800014 | Already closed. | 2565| 14800015 | The database does not respond. | 2566| 14800021 | SQLite: Generic error. | 2567| 14800022 | SQLite: Callback routine requested an abort. | 2568| 14800023 | SQLite: Access permission denied. | 2569| 14800024 | SQLite: The database file is locked. | 2570| 14800025 | SQLite: A table in the database is locked. | 2571| 14800026 | SQLite: The database is out of memory. | 2572| 14800027 | SQLite: Attempt to write a readonly database. | 2573| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2574| 14800029 | SQLite: The database is full. | 2575| 14800030 | SQLite: Unable to open the database file. | 2576| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2577| 14800032 | SQLite: Abort due to constraint violation. | 2578| 14800033 | SQLite: Data type mismatch. | 2579| 14800034 | SQLite: Library used incorrectly. | 2580| 14800047 | The WAL file size exceeds the default limit. | 2581 2582**Example** 2583 2584```ts 2585import { BusinessError } from '@kit.BasicServicesKit'; 2586 2587let value1 = "Lisa"; 2588let value2 = 18; 2589let value3 = 100.5; 2590let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2591 2592// You can use either of the following: 2593const valueBucket1: relationalStore.ValuesBucket = { 2594 'NAME': value1, 2595 'AGE': value2, 2596 'SALARY': value3, 2597 'CODES': value4, 2598}; 2599const valueBucket2: relationalStore.ValuesBucket = { 2600 NAME: value1, 2601 AGE: value2, 2602 SALARY: value3, 2603 CODES: value4, 2604}; 2605const valueBucket3: relationalStore.ValuesBucket = { 2606 "NAME": value1, 2607 "AGE": value2, 2608 "SALARY": value3, 2609 "CODES": value4, 2610}; 2611 2612if(store != undefined) { 2613 try { 2614 let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 2615 console.info(`Insert is successful, rowId = ${rowId}`); 2616 } catch (error) { 2617 console.error(`Insert is failed, code is ${error.code},message is ${error.message}`); 2618 } 2619} 2620``` 2621 2622### insertSync<sup>12+</sup> 2623 2624insertSync(table: string, values: sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution):number 2625 2626Inserts a row of Sendable data into a table. This API returns the result synchronously. 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. 2627 2628**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2629 2630**Parameters** 2631 2632| Name | Type | Mandatory| Description | 2633| -------- | ---------------------------------------------------------------------------------------------- | ---- | ------------------------------------------------------------------------------- | 2634| table | string | Yes | Name of the target table. | 2635| values | [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | Yes | Sendable data to insert. | 2636| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 2637 2638**Return value** 2639 2640| Type | Description | 2641| ------ | ------------------------------------ | 2642| number | If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2643 2644**Error codes** 2645 2646For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 2647 2648| **ID**| **Error Message** | 2649| ------------ | ------------------------------------------------------------ | 2650| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2651| 14800000 | Inner error. | 2652| 14800011 | Database corrupted. | 2653| 14800014 | Already closed. | 2654| 14800015 | The database does not respond. | 2655| 14800021 | SQLite: Generic error. | 2656| 14800022 | SQLite: Callback routine requested an abort. | 2657| 14800023 | SQLite: Access permission denied. | 2658| 14800024 | SQLite: The database file is locked. | 2659| 14800025 | SQLite: A table in the database is locked. | 2660| 14800026 | SQLite: The database is out of memory. | 2661| 14800027 | SQLite: Attempt to write a readonly database. | 2662| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2663| 14800029 | SQLite: The database is full. | 2664| 14800030 | SQLite: Unable to open the database file. | 2665| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2666| 14800032 | SQLite: Abort due to constraint violation. | 2667| 14800033 | SQLite: Data type mismatch. | 2668| 14800034 | SQLite: Library used incorrectly. | 2669| 14800047 | The WAL file size exceeds the default limit. | 2670 2671**Example** 2672 2673```ts 2674import { sendableRelationalStore } from '@kit.ArkData'; 2675 2676const valuesBucket: relationalStore.ValuesBucket = { 2677 "NAME": 'hangman', 2678 "AGE": 18, 2679 "SALARY": 100.5, 2680 "CODES": new Uint8Array([1,2,3]), 2681}; 2682const sendableValuesBucket = sendableRelationalStore.toSendableValuesBucket(valuesBucket); 2683 2684if(store != undefined) { 2685 try { 2686 let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", sendableValuesBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 2687 console.info(`Insert is successful, rowId = ${rowId}`); 2688 } catch (error) { 2689 console.error(`Insert is failed, code is ${error.code},message is ${error.message}`); 2690 } 2691} 2692``` 2693 2694### batchInsert 2695 2696batchInsert(table: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>):void 2697 2698Inserts a batch of data into a table. This API uses an asynchronous callback to return the result. 2699 2700**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2701 2702**Parameters** 2703 2704| Name | Type | Mandatory| Description | 2705| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ | 2706| table | string | Yes | Name of the target table. | 2707| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert. | 2708| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 2709 2710**Error codes** 2711 2712For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 2713 2714| **ID**| **Error Message** | 2715|-----------| ------------------------------------------------------------ | 2716| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2717| 14800000 | Inner error. | 2718| 14800011 | Database corrupted. | 2719| 14800014 | Already closed. | 2720| 14800015 | The database does not respond. | 2721| 14800021 | SQLite: Generic error. | 2722| 14800022 | SQLite: Callback routine requested an abort. | 2723| 14800023 | SQLite: Access permission denied. | 2724| 14800024 | SQLite: The database file is locked. | 2725| 14800025 | SQLite: A table in the database is locked. | 2726| 14800026 | SQLite: The database is out of memory. | 2727| 14800027 | SQLite: Attempt to write a readonly database. | 2728| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2729| 14800029 | SQLite: The database is full. | 2730| 14800030 | SQLite: Unable to open the database file. | 2731| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2732| 14800032 | SQLite: Abort due to constraint violation. | 2733| 14800033 | SQLite: Data type mismatch. | 2734| 14800034 | SQLite: Library used incorrectly. | 2735| 14800047 | The WAL file size exceeds the default limit. | 2736 2737**Example** 2738 2739```ts 2740 2741let value1 = "Lisa"; 2742let value2 = 18; 2743let value3 = 100.5; 2744let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2745let value5 = "Jack"; 2746let value6 = 19; 2747let value7 = 101.5; 2748let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2749let value9 = "Tom"; 2750let value10 = 20; 2751let value11 = 102.5; 2752let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2753 2754const valueBucket1: relationalStore.ValuesBucket = { 2755 'NAME': value1, 2756 'AGE': value2, 2757 'SALARY': value3, 2758 'CODES': value4, 2759}; 2760const valueBucket2: relationalStore.ValuesBucket = { 2761 'NAME': value5, 2762 'AGE': value6, 2763 'SALARY': value7, 2764 'CODES': value8, 2765}; 2766const valueBucket3: relationalStore.ValuesBucket = { 2767 'NAME': value9, 2768 'AGE': value10, 2769 'SALARY': value11, 2770 'CODES': value12, 2771}; 2772 2773let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2774if(store != undefined) { 2775 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets, (err, insertNum) => { 2776 if (err) { 2777 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2778 return; 2779 } 2780 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2781 }) 2782} 2783``` 2784 2785### batchInsert 2786 2787batchInsert(table: string, values: Array<ValuesBucket>):Promise<number> 2788 2789Inserts a batch of data into a table. This API uses a promise to return the result. 2790 2791**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2792 2793**Parameters** 2794 2795| Name| Type | Mandatory| Description | 2796| ------ | ------------------------------------------ | ---- | ---------------------------- | 2797| table | string | Yes | Name of the target table. | 2798| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 2799 2800**Return value** 2801 2802| Type | Description | 2803| --------------------- | ----------------------------------------------------------- | 2804| Promise<number> | Promise used to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 2805 2806**Error codes** 2807 2808For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 2809 2810| **ID**| **Error Message** | 2811|-----------| ------------------------------------------------------------ | 2812| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2813| 14800000 | Inner error. | 2814| 14800011 | Database corrupted. | 2815| 14800014 | Already closed. | 2816| 14800015 | The database does not respond. | 2817| 14800021 | SQLite: Generic error. | 2818| 14800022 | SQLite: Callback routine requested an abort. | 2819| 14800023 | SQLite: Access permission denied. | 2820| 14800024 | SQLite: The database file is locked. | 2821| 14800025 | SQLite: A table in the database is locked. | 2822| 14800026 | SQLite: The database is out of memory. | 2823| 14800027 | SQLite: Attempt to write a readonly database. | 2824| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2825| 14800029 | SQLite: The database is full. | 2826| 14800030 | SQLite: Unable to open the database file. | 2827| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2828| 14800032 | SQLite: Abort due to constraint violation. | 2829| 14800033 | SQLite: Data type mismatch. | 2830| 14800034 | SQLite: Library used incorrectly. | 2831| 14800047 | The WAL file size exceeds the default limit. | 2832 2833**Example** 2834 2835```ts 2836import { BusinessError } from '@kit.BasicServicesKit'; 2837 2838let value1 = "Lisa"; 2839let value2 = 18; 2840let value3 = 100.5; 2841let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2842let value5 = "Jack"; 2843let value6 = 19; 2844let value7 = 101.5; 2845let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2846let value9 = "Tom"; 2847let value10 = 20; 2848let value11 = 102.5; 2849let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2850 2851const valueBucket1: relationalStore.ValuesBucket = { 2852 'NAME': value1, 2853 'AGE': value2, 2854 'SALARY': value3, 2855 'CODES': value4, 2856}; 2857const valueBucket2: relationalStore.ValuesBucket = { 2858 'NAME': value5, 2859 'AGE': value6, 2860 'SALARY': value7, 2861 'CODES': value8, 2862}; 2863const valueBucket3: relationalStore.ValuesBucket = { 2864 'NAME': value9, 2865 'AGE': value10, 2866 'SALARY': value11, 2867 'CODES': value12, 2868}; 2869 2870let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2871if(store != undefined) { 2872 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => { 2873 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2874 }).catch((err: BusinessError) => { 2875 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2876 }) 2877} 2878``` 2879 2880### batchInsertSync<sup>12+</sup> 2881 2882batchInsertSync(table: string, values: Array<ValuesBucket>):number 2883 2884Inserts a batch of data into a table. This API returns the result synchronously. 2885 2886**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2887 2888**Parameters** 2889 2890| Name| Type | Mandatory| Description | 2891| ------ | ------------------------------------------ | ---- | ---------------------------- | 2892| table | string | Yes | Name of the target table. | 2893| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 2894 2895**Return value** 2896 2897| Type | Description | 2898| ------ | ---------------------------------------------- | 2899| number | If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 2900 2901**Error codes** 2902 2903For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 2904 2905| **ID**| **Error Message** | 2906| ------------ | ------------------------------------------------------------ | 2907| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2908| 14800000 | Inner error. | 2909| 14800011 | Database corrupted. | 2910| 14800014 | Already closed. | 2911| 14800015 | The database does not respond. | 2912| 14800021 | SQLite: Generic error. | 2913| 14800022 | SQLite: Callback routine requested an abort. | 2914| 14800023 | SQLite: Access permission denied. | 2915| 14800024 | SQLite: The database file is locked. | 2916| 14800025 | SQLite: A table in the database is locked. | 2917| 14800026 | SQLite: The database is out of memory. | 2918| 14800027 | SQLite: Attempt to write a readonly database. | 2919| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2920| 14800029 | SQLite: The database is full. | 2921| 14800030 | SQLite: Unable to open the database file. | 2922| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2923| 14800032 | SQLite: Abort due to constraint violation. | 2924| 14800033 | SQLite: Data type mismatch. | 2925| 14800034 | SQLite: Library used incorrectly. | 2926| 14800047 | The WAL file size exceeds the default limit. | 2927 2928**Example** 2929 2930```ts 2931import { BusinessError } from '@kit.BasicServicesKit'; 2932 2933let value1 = "Lisa"; 2934let value2 = 18; 2935let value3 = 100.5; 2936let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2937let value5 = "Jack"; 2938let value6 = 19; 2939let value7 = 101.5; 2940let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2941let value9 = "Tom"; 2942let value10 = 20; 2943let value11 = 102.5; 2944let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2945 2946const valueBucket1: relationalStore.ValuesBucket = { 2947 'NAME': value1, 2948 'AGE': value2, 2949 'SALARY': value3, 2950 'CODES': value4, 2951}; 2952const valueBucket2: relationalStore.ValuesBucket = { 2953 'NAME': value5, 2954 'AGE': value6, 2955 'SALARY': value7, 2956 'CODES': value8, 2957}; 2958const valueBucket3: relationalStore.ValuesBucket = { 2959 'NAME': value9, 2960 'AGE': value10, 2961 'SALARY': value11, 2962 'CODES': value12, 2963}; 2964 2965let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2966if(store != undefined) { 2967 try { 2968 let insertNum: number = (store as relationalStore.RdbStore).batchInsertSync("EMPLOYEE", valueBuckets); 2969 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2970 } catch (err) { 2971 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2972 } 2973} 2974``` 2975 2976### update 2977 2978update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback<number>):void 2979 2980Updates data in the RDB store based on the specified **RdbPredicates** 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. 2981 2982**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2983 2984**Parameters** 2985 2986| Name | Type | Mandatory| Description | 2987| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 2988| values | [ValuesBucket](#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.| 2989| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 2990| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows updated. | 2991 2992**Error codes** 2993 2994For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 2995 2996| **ID**| **Error Message** | 2997|-----------| ------------------------------------------------------------ | 2998| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2999| 14800000 | Inner error. | 3000| 14800011 | Database corrupted. | 3001| 14800014 | Already closed. | 3002| 14800015 | The database does not respond. | 3003| 14800021 | SQLite: Generic error. | 3004| 14800022 | SQLite: Callback routine requested an abort. | 3005| 14800023 | SQLite: Access permission denied. | 3006| 14800024 | SQLite: The database file is locked. | 3007| 14800025 | SQLite: A table in the database is locked. | 3008| 14800026 | SQLite: The database is out of memory. | 3009| 14800027 | SQLite: Attempt to write a readonly database. | 3010| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3011| 14800029 | SQLite: The database is full. | 3012| 14800030 | SQLite: Unable to open the database file. | 3013| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3014| 14800032 | SQLite: Abort due to constraint violation. | 3015| 14800033 | SQLite: Data type mismatch. | 3016| 14800034 | SQLite: Library used incorrectly. | 3017| 14800047 | The WAL file size exceeds the default limit. | 3018 3019**Example** 3020 3021```ts 3022 3023let value1 = "Rose"; 3024let value2 = 22; 3025let value3 = 200.5; 3026let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3027 3028// You can use either of the following: 3029const valueBucket1: relationalStore.ValuesBucket = { 3030 'NAME': value1, 3031 'AGE': value2, 3032 'SALARY': value3, 3033 'CODES': value4, 3034}; 3035const valueBucket2: relationalStore.ValuesBucket = { 3036 NAME: value1, 3037 AGE: value2, 3038 SALARY: value3, 3039 CODES: value4, 3040}; 3041const valueBucket3: relationalStore.ValuesBucket = { 3042 "NAME": value1, 3043 "AGE": value2, 3044 "SALARY": value3, 3045 "CODES": value4, 3046}; 3047 3048let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3049predicates.equalTo("NAME", "Lisa"); 3050if(store != undefined) { 3051 (store as relationalStore.RdbStore).update(valueBucket1, predicates,(err, rows) => { 3052 if (err) { 3053 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3054 return; 3055 } 3056 console.info(`Updated row count: ${rows}`); 3057 }) 3058} 3059``` 3060 3061### update<sup>10+</sup> 3062 3063update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution, callback: AsyncCallback<number>):void 3064 3065Updates data in the RDB store based on the specified **RdbPredicates** 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. 3066 3067**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3068 3069**Parameters** 3070 3071| Name | Type | Mandatory| Description | 3072| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3073| values | [ValuesBucket](#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.| 3074| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3075| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 3076| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows updated. | 3077 3078**Error codes** 3079 3080For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 3081 3082| **ID**| **Error Message** | 3083|-----------| ------------------------------------------------------------ | 3084| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3085| 14800000 | Inner error. | 3086| 14800011 | Database corrupted. | 3087| 14800014 | Already closed. | 3088| 14800015 | The database does not respond. | 3089| 14800021 | SQLite: Generic error. | 3090| 14800022 | SQLite: Callback routine requested an abort. | 3091| 14800023 | SQLite: Access permission denied. | 3092| 14800024 | SQLite: The database file is locked. | 3093| 14800025 | SQLite: A table in the database is locked. | 3094| 14800026 | SQLite: The database is out of memory. | 3095| 14800027 | SQLite: Attempt to write a readonly database. | 3096| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3097| 14800029 | SQLite: The database is full. | 3098| 14800030 | SQLite: Unable to open the database file. | 3099| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3100| 14800032 | SQLite: Abort due to constraint violation. | 3101| 14800033 | SQLite: Data type mismatch. | 3102| 14800034 | SQLite: Library used incorrectly. | 3103| 14800047 | The WAL file size exceeds the default limit. | 3104 3105**Example** 3106 3107```ts 3108 3109let value1 = "Rose"; 3110let value2 = 22; 3111let value3 = 200.5; 3112let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3113 3114// You can use either of the following: 3115const valueBucket1: relationalStore.ValuesBucket = { 3116 'NAME': value1, 3117 'AGE': value2, 3118 'SALARY': value3, 3119 'CODES': value4, 3120}; 3121const valueBucket2: relationalStore.ValuesBucket = { 3122 NAME: value1, 3123 AGE: value2, 3124 SALARY: value3, 3125 CODES: value4, 3126}; 3127const valueBucket3: relationalStore.ValuesBucket = { 3128 "NAME": value1, 3129 "AGE": value2, 3130 "SALARY": value3, 3131 "CODES": value4, 3132}; 3133 3134let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3135predicates.equalTo("NAME", "Lisa"); 3136if(store != undefined) { 3137 (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, (err, rows) => { 3138 if (err) { 3139 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3140 return; 3141 } 3142 console.info(`Updated row count: ${rows}`); 3143 }) 3144} 3145``` 3146 3147### update 3148 3149update(values: ValuesBucket, predicates: RdbPredicates):Promise<number> 3150 3151Updates data based on the specified **RdbPredicates** 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. 3152 3153**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3154 3155**Parameters** 3156 3157| Name | Type | Mandatory| Description | 3158| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 3159| values | [ValuesBucket](#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.| 3160| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3161 3162**Return value** 3163 3164| Type | Description | 3165| --------------------- | ----------------------------------------- | 3166| Promise<number> | Promise used to return the number of rows updated.| 3167 3168**Error codes** 3169 3170For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 3171 3172| **ID**| **Error Message** | 3173|-----------| ------------------------------------------------------------ | 3174| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3175| 14800000 | Inner error. | 3176| 14800011 | Database corrupted. | 3177| 14800014 | Already closed. | 3178| 14800015 | The database does not respond. | 3179| 14800021 | SQLite: Generic error. | 3180| 14800022 | SQLite: Callback routine requested an abort. | 3181| 14800023 | SQLite: Access permission denied. | 3182| 14800024 | SQLite: The database file is locked. | 3183| 14800025 | SQLite: A table in the database is locked. | 3184| 14800026 | SQLite: The database is out of memory. | 3185| 14800027 | SQLite: Attempt to write a readonly database. | 3186| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3187| 14800029 | SQLite: The database is full. | 3188| 14800030 | SQLite: Unable to open the database file. | 3189| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3190| 14800032 | SQLite: Abort due to constraint violation. | 3191| 14800033 | SQLite: Data type mismatch. | 3192| 14800034 | SQLite: Library used incorrectly. | 3193| 14800047 | The WAL file size exceeds the default limit. | 3194 3195**Example** 3196 3197```ts 3198import { BusinessError } from '@kit.BasicServicesKit'; 3199 3200let value1 = "Rose"; 3201let value2 = 22; 3202let value3 = 200.5; 3203let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3204 3205// You can use either of the following: 3206const valueBucket1: relationalStore.ValuesBucket = { 3207 'NAME': value1, 3208 'AGE': value2, 3209 'SALARY': value3, 3210 'CODES': value4, 3211}; 3212const valueBucket2: relationalStore.ValuesBucket = { 3213 NAME: value1, 3214 AGE: value2, 3215 SALARY: value3, 3216 CODES: value4, 3217}; 3218const valueBucket3: relationalStore.ValuesBucket = { 3219 "NAME": value1, 3220 "AGE": value2, 3221 "SALARY": value3, 3222 "CODES": value4, 3223}; 3224 3225let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3226predicates.equalTo("NAME", "Lisa"); 3227if(store != undefined) { 3228 (store as relationalStore.RdbStore).update(valueBucket1, predicates).then(async (rows: Number) => { 3229 console.info(`Updated row count: ${rows}`); 3230 }).catch((err: BusinessError) => { 3231 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3232 }) 3233} 3234``` 3235 3236### update<sup>10+</sup> 3237 3238update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution):Promise<number> 3239 3240Updates data based on the specified **RdbPredicates** 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. 3241 3242**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3243 3244**Parameters** 3245 3246| Name | Type | Mandatory| Description | 3247| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3248| values | [ValuesBucket](#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.| 3249| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3250| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 3251 3252**Return value** 3253 3254| Type | Description | 3255| --------------------- | ----------------------------------------- | 3256| Promise<number> | Promise used to return the number of rows updated.| 3257 3258**Error codes** 3259 3260For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 3261 3262| **ID**| **Error Message** | 3263|-----------| ------------------------------------------------------------ | 3264| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3265| 14800000 | Inner error. | 3266| 14800011 | Database corrupted. | 3267| 14800014 | Already closed. | 3268| 14800015 | The database does not respond. | 3269| 14800021 | SQLite: Generic error. | 3270| 14800022 | SQLite: Callback routine requested an abort. | 3271| 14800023 | SQLite: Access permission denied. | 3272| 14800024 | SQLite: The database file is locked. | 3273| 14800025 | SQLite: A table in the database is locked. | 3274| 14800026 | SQLite: The database is out of memory. | 3275| 14800027 | SQLite: Attempt to write a readonly database. | 3276| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3277| 14800029 | SQLite: The database is full. | 3278| 14800030 | SQLite: Unable to open the database file. | 3279| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3280| 14800032 | SQLite: Abort due to constraint violation. | 3281| 14800033 | SQLite: Data type mismatch. | 3282| 14800034 | SQLite: Library used incorrectly. | 3283| 14800047 | The WAL file size exceeds the default limit. | 3284 3285**Example** 3286 3287```ts 3288import { BusinessError } from '@kit.BasicServicesKit'; 3289 3290let value1 = "Rose"; 3291let value2 = 22; 3292let value3 = 200.5; 3293let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3294 3295// You can use either of the following: 3296const valueBucket1: relationalStore.ValuesBucket = { 3297 'NAME': value1, 3298 'AGE': value2, 3299 'SALARY': value3, 3300 'CODES': value4, 3301}; 3302const valueBucket2: relationalStore.ValuesBucket = { 3303 NAME: value1, 3304 AGE: value2, 3305 SALARY: value3, 3306 CODES: value4, 3307}; 3308const valueBucket3: relationalStore.ValuesBucket = { 3309 "NAME": value1, 3310 "AGE": value2, 3311 "SALARY": value3, 3312 "CODES": value4, 3313}; 3314 3315let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3316predicates.equalTo("NAME", "Lisa"); 3317if(store != undefined) { 3318 (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => { 3319 console.info(`Updated row count: ${rows}`); 3320 }).catch((err: BusinessError) => { 3321 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3322 }) 3323} 3324``` 3325 3326### updateSync<sup>12+</sup> 3327 3328updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution):number 3329 3330Updates data in the RDB store based on the specified **RdbPredicates** instance. 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. 3331 3332**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3333 3334**Parameters** 3335 3336| Name | Type | Mandatory| Description | 3337| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3338| values | [ValuesBucket](#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.| 3339| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3340| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. The default value is **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 3341 3342**Return value** 3343 3344| Type | Description | 3345| ------ | ------------------ | 3346| number | return the number of rows updated.| 3347 3348**Error codes** 3349 3350For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 3351 3352| **ID**| **Error Message** | 3353| ------------ | ------------------------------------------------------------ | 3354| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3355| 14800000 | Inner error. | 3356| 14800011 | Database corrupted. | 3357| 14800014 | Already closed. | 3358| 14800015 | The database does not respond. | 3359| 14800021 | SQLite: Generic error. | 3360| 14800022 | SQLite: Callback routine requested an abort. | 3361| 14800023 | SQLite: Access permission denied. | 3362| 14800024 | SQLite: The database file is locked. | 3363| 14800025 | SQLite: A table in the database is locked. | 3364| 14800026 | SQLite: The database is out of memory. | 3365| 14800027 | SQLite: Attempt to write a readonly database. | 3366| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3367| 14800029 | SQLite: The database is full. | 3368| 14800030 | SQLite: Unable to open the database file. | 3369| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3370| 14800032 | SQLite: Abort due to constraint violation. | 3371| 14800033 | SQLite: Data type mismatch. | 3372| 14800034 | SQLite: Library used incorrectly. | 3373| 14800047 | The WAL file size exceeds the default limit. | 3374 3375**Example** 3376 3377```ts 3378import { BusinessError } from '@kit.BasicServicesKit'; 3379 3380let value1 = "Rose"; 3381let value2 = 22; 3382let value3 = 200.5; 3383let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3384 3385// You can use either of the following: 3386const valueBucket1: relationalStore.ValuesBucket = { 3387 'NAME': value1, 3388 'AGE': value2, 3389 'SALARY': value3, 3390 'CODES': value4, 3391}; 3392const valueBucket2: relationalStore.ValuesBucket = { 3393 NAME: value1, 3394 AGE: value2, 3395 SALARY: value3, 3396 CODES: value4, 3397}; 3398const valueBucket3: relationalStore.ValuesBucket = { 3399 "NAME": value1, 3400 "AGE": value2, 3401 "SALARY": value3, 3402 "CODES": value4, 3403}; 3404 3405let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3406predicates.equalTo("NAME", "Lisa"); 3407if(store != undefined) { 3408 try { 3409 let rows: Number = (store as relationalStore.RdbStore).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 3410 console.info(`Updated row count: ${rows}`); 3411 } catch (error) { 3412 console.error(`Updated failed, code is ${error.code},message is ${error.message}`); 3413 } 3414} 3415``` 3416 3417### delete 3418 3419delete(predicates: RdbPredicates, callback: AsyncCallback<number>):void 3420 3421Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result. 3422 3423**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3424 3425**Parameters** 3426 3427| Name | Type | Mandatory| Description | 3428| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 3429| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 3430| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows deleted. | 3431 3432**Error codes** 3433 3434For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 3435 3436| **ID**| **Error Message** | 3437|-----------| ------------------------------------------------------------ | 3438| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3439| 14800000 | Inner error. | 3440| 14800011 | Database corrupted. | 3441| 14800014 | Already closed. | 3442| 14800015 | The database does not respond. | 3443| 14800021 | SQLite: Generic error. | 3444| 14800022 | SQLite: Callback routine requested an abort. | 3445| 14800023 | SQLite: Access permission denied. | 3446| 14800024 | SQLite: The database file is locked. | 3447| 14800025 | SQLite: A table in the database is locked. | 3448| 14800026 | SQLite: The database is out of memory. | 3449| 14800027 | SQLite: Attempt to write a readonly database. | 3450| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3451| 14800029 | SQLite: The database is full. | 3452| 14800030 | SQLite: Unable to open the database file. | 3453| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3454| 14800032 | SQLite: Abort due to constraint violation. | 3455| 14800033 | SQLite: Data type mismatch. | 3456| 14800034 | SQLite: Library used incorrectly. | 3457| 14800047 | The WAL file size exceeds the default limit. | 3458 3459**Example** 3460 3461```ts 3462let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3463predicates.equalTo("NAME", "Lisa"); 3464if(store != undefined) { 3465 (store as relationalStore.RdbStore).delete(predicates, (err, rows) => { 3466 if (err) { 3467 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3468 return; 3469 } 3470 console.info(`Delete rows: ${rows}`); 3471 }) 3472} 3473``` 3474 3475### delete 3476 3477delete(predicates: RdbPredicates):Promise<number> 3478 3479Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result. 3480 3481**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3482 3483**Parameters** 3484 3485| Name | Type | Mandatory| Description | 3486| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 3487| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 3488 3489**Return value** 3490 3491| Type | Description | 3492| --------------------- | ------------------------------- | 3493| Promise<number> | Promise used to return the number of rows deleted.| 3494 3495**Error codes** 3496 3497For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 3498 3499| **ID**| **Error Message** | 3500|-----------| ------------------------------------------------------------ | 3501| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3502| 14800000 | Inner error. | 3503| 14800011 | Database corrupted. | 3504| 14800014 | Already closed. | 3505| 14800015 | The database does not respond. | 3506| 14800021 | SQLite: Generic error. | 3507| 14800022 | SQLite: Callback routine requested an abort. | 3508| 14800023 | SQLite: Access permission denied. | 3509| 14800024 | SQLite: The database file is locked. | 3510| 14800025 | SQLite: A table in the database is locked. | 3511| 14800026 | SQLite: The database is out of memory. | 3512| 14800027 | SQLite: Attempt to write a readonly database. | 3513| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3514| 14800029 | SQLite: The database is full. | 3515| 14800030 | SQLite: Unable to open the database file. | 3516| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3517| 14800032 | SQLite: Abort due to constraint violation. | 3518| 14800033 | SQLite: Data type mismatch. | 3519| 14800034 | SQLite: Library used incorrectly. | 3520| 14800047 | The WAL file size exceeds the default limit. | 3521 3522**Example** 3523 3524```ts 3525import { BusinessError } from '@kit.BasicServicesKit'; 3526 3527let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3528predicates.equalTo("NAME", "Lisa"); 3529if(store != undefined) { 3530 (store as relationalStore.RdbStore).delete(predicates).then((rows: Number) => { 3531 console.info(`Delete rows: ${rows}`); 3532 }).catch((err: BusinessError) => { 3533 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3534 }) 3535} 3536``` 3537 3538### deleteSync<sup>12+</sup> 3539 3540deleteSync(predicates: RdbPredicates):number 3541 3542Deletes data from the RDB store based on the specified **RdbPredicates** object. 3543 3544**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3545 3546**Parameters** 3547 3548| Name | Type | Mandatory| Description | 3549| ---------- | ------------------------------- | ---- | --------------------------------------- | 3550| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 3551 3552**Return value** 3553 3554| Type | Description | 3555| ------ | ------------------ | 3556| number | return the number of rows updated.| 3557 3558**Error codes** 3559 3560For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 3561 3562| **ID**| **Error Message** | 3563| ------------ | ------------------------------------------------------------ | 3564| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3565| 14800000 | Inner error. | 3566| 14800011 | Database corrupted. | 3567| 14800014 | Already closed. | 3568| 14800015 | The database does not respond. | 3569| 14800021 | SQLite: Generic error. | 3570| 14800022 | SQLite: Callback routine requested an abort. | 3571| 14800023 | SQLite: Access permission denied. | 3572| 14800024 | SQLite: The database file is locked. | 3573| 14800025 | SQLite: A table in the database is locked. | 3574| 14800026 | SQLite: The database is out of memory. | 3575| 14800027 | SQLite: Attempt to write a readonly database. | 3576| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3577| 14800029 | SQLite: The database is full. | 3578| 14800030 | SQLite: Unable to open the database file. | 3579| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3580| 14800032 | SQLite: Abort due to constraint violation. | 3581| 14800033 | SQLite: Data type mismatch. | 3582| 14800034 | SQLite: Library used incorrectly. | 3583| 14800047 | The WAL file size exceeds the default limit. | 3584 3585**Example** 3586 3587```ts 3588import { BusinessError } from '@kit.BasicServicesKit'; 3589 3590let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3591predicates.equalTo("NAME", "Lisa"); 3592if(store != undefined) { 3593 try { 3594 let rows: Number = (store as relationalStore.RdbStore).deleteSync(predicates) 3595 console.info(`Delete rows: ${rows}`); 3596 } catch (err) { 3597 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3598 } 3599} 3600``` 3601 3602### query<sup>10+</sup> 3603 3604query(predicates: RdbPredicates, callback: AsyncCallback<ResultSet>):void 3605 3606Queries 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. 3607 3608**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3609 3610**Parameters** 3611 3612| Name | Type | Mandatory| Description | 3613| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 3614| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3615| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3616 3617**Error codes** 3618 3619For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3620 3621| **ID**| **Error Message** | 3622|-----------| ------------------------------------------------------------ | 3623| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3624| 14800000 | Inner error. | 3625| 14800014 | Already closed. | 3626| 14800015 | The database does not respond. | 3627 3628**Example** 3629 3630```ts 3631let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3632predicates.equalTo("NAME", "Rose"); 3633if(store != undefined) { 3634 (store as relationalStore.RdbStore).query(predicates, (err, resultSet) => { 3635 if (err) { 3636 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3637 return; 3638 } 3639 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3640 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3641 while (resultSet.goToNextRow()) { 3642 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3643 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3644 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3645 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3646 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3647 } 3648 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3649 resultSet.close(); 3650 }) 3651} 3652``` 3653 3654### query 3655 3656query(predicates: RdbPredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>):void 3657 3658Queries 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. 3659 3660**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3661 3662**Parameters** 3663 3664| Name | Type | Mandatory| Description | 3665| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 3666| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3667| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | 3668| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3669 3670**Error codes** 3671 3672For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3673 3674| **ID**| **Error Message** | 3675|-----------| ------------------------------------------------------------ | 3676| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3677| 14800000 | Inner error. | 3678| 14800014 | Already closed. | 3679| 14800015 | The database does not respond. | 3680 3681**Example** 3682 3683```ts 3684let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3685predicates.equalTo("NAME", "Rose"); 3686if(store != undefined) { 3687 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], (err, resultSet) => { 3688 if (err) { 3689 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3690 return; 3691 } 3692 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3693 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3694 while (resultSet.goToNextRow()) { 3695 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3696 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3697 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3698 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3699 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3700 } 3701 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3702 resultSet.close(); 3703 }) 3704} 3705``` 3706 3707### query 3708 3709query(predicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> 3710 3711Queries 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. 3712 3713**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3714 3715**Parameters** 3716 3717| Name | Type | Mandatory| Description | 3718| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 3719| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3720| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 3721 3722**Error codes** 3723 3724For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3725 3726| **ID**| **Error Message** | 3727|-----------| ------------------------------------------------------------ | 3728| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3729| 14800000 | Inner error. | 3730| 14800014 | Already closed. | 3731| 14800015 | The database does not respond. | 3732 3733**Return value** 3734 3735| Type | Description | 3736| ------------------------------------------------------- | -------------------------------------------------- | 3737| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3738 3739**Example** 3740 3741```ts 3742import { BusinessError } from '@kit.BasicServicesKit'; 3743 3744let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3745predicates.equalTo("NAME", "Rose"); 3746if(store != undefined) { 3747 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 3748 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3749 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3750 while (resultSet.goToNextRow()) { 3751 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3752 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3753 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3754 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3755 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3756 } 3757 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3758 resultSet.close(); 3759 }).catch((err: BusinessError) => { 3760 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3761 }) 3762} 3763``` 3764 3765### querySync<sup>12+</sup> 3766 3767querySync(predicates: RdbPredicates, columns?: Array<string>):ResultSet 3768 3769Queries data in the RDB store based on specified conditions. This API returns the result synchronously. If complex logic and a large number of loops are involved in the operations on the **resultSet** obtained by **querySync()**, the freeze problem may occur. You are advised to perform this operation in the [taskpool](../apis-arkts/js-apis-taskpool.md) thread. 3770 3771**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3772 3773**Parameters** 3774 3775| Name | Type | Mandatory| Description | 3776| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ | 3777| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3778| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns. The default value is null.| 3779 3780**Error codes** 3781 3782For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3783 3784| **ID**| **Error Message** | 3785| ------------ | ------------------------------------------------------------ | 3786| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3787| 14800000 | Inner error. | 3788| 14800014 | Already closed. | 3789| 14800015 | The database does not respond. | 3790 3791**Return value** 3792 3793| Type | Description | 3794| ----------------------- | ----------------------------------- | 3795| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 3796 3797**Example** 3798 3799```ts 3800import { BusinessError } from '@kit.BasicServicesKit'; 3801 3802let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3803predicates.equalTo("NAME", "Rose"); 3804if(store != undefined) { 3805 try { 3806 let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); 3807 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3808 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3809 while (resultSet.goToNextRow()) { 3810 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3811 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3812 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3813 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3814 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3815 } 3816 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3817 resultSet.close(); 3818 } catch (err) { 3819 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3820 } 3821} 3822``` 3823 3824### remoteQuery 3825 3826remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string> , callback: AsyncCallback<ResultSet>): void 3827 3828Queries data from the RDB store of a remote device based on specified conditions. This API uses an asynchronous callback to return the result. 3829 3830> **NOTE** 3831> 3832> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 3833 3834**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3835 3836**Parameters** 3837 3838| Name | Type | Mandatory| Description | 3839| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- | 3840| device | string | Yes | ID of the remote device. | 3841| table | string | Yes | Name of the target table. | 3842| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3843| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | 3844| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3845 3846**Error codes** 3847 3848For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3849 3850| **ID**| **Error Message** | 3851|-----------| ------------------------------------------------------------ | 3852| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3853| 801 | Capability not supported. | 3854| 14800000 | Inner error. | 3855| 14800014 | Already closed. | 3856 3857**Example** 3858 3859```ts 3860import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 3861import { BusinessError } from '@kit.BasicServicesKit'; 3862 3863let dmInstance: distributedDeviceManager.DeviceManager; 3864let deviceId: string | undefined = undefined; 3865 3866try { 3867 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 3868 let devices = dmInstance.getAvailableDeviceListSync(); 3869 if(deviceId != undefined) { 3870 deviceId = devices[0].networkId; 3871 } 3872} catch (err) { 3873 let code = (err as BusinessError).code; 3874 let message = (err as BusinessError).message; 3875 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 3876} 3877 3878let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 3879predicates.greaterThan("id", 0); 3880if(store != undefined && deviceId != undefined) { 3881 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 3882 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3883 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3884 while (resultSet.goToNextRow()) { 3885 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3886 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3887 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3888 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3889 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3890 } 3891 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3892 resultSet.close(); 3893 }).catch((err: BusinessError) => { 3894 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 3895 }) 3896} 3897``` 3898 3899### remoteQuery 3900 3901remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string>): Promise<ResultSet> 3902 3903Queries data from the RDB store of a remote device based on specified conditions. This API uses a promise to return the result. 3904 3905> **NOTE** 3906> 3907> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 3908 3909**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3910 3911**Parameters** 3912 3913| Name | Type | Mandatory| Description | 3914| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 3915| device | string | Yes | ID of the remote device. | 3916| table | string | Yes | Name of the target table. | 3917| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3918| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns.| 3919 3920**Return value** 3921 3922| Type | Description | 3923| ------------------------------------------------------------ | -------------------------------------------------- | 3924| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3925 3926**Error codes** 3927 3928For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3929 3930| **ID**| **Error Message** | 3931|-----------| ------------------------------------------------------------ | 3932| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3933| 801 | Capability not supported. | 3934| 14800000 | Inner error. | 3935| 14800014 | Already closed. | 3936 3937**Example** 3938 3939```ts 3940import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 3941import { BusinessError } from '@kit.BasicServicesKit'; 3942 3943let dmInstance: distributedDeviceManager.DeviceManager; 3944let deviceId: string | undefined = undefined; 3945 3946try { 3947 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 3948 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 3949 if(devices != undefined) { 3950 deviceId = devices[0].networkId; 3951 } 3952} catch (err) { 3953 let code = (err as BusinessError).code; 3954 let message = (err as BusinessError).message; 3955 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 3956} 3957 3958let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 3959predicates.greaterThan("id", 0); 3960if(store != undefined && deviceId != undefined) { 3961 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 3962 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3963 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3964 while (resultSet.goToNextRow()) { 3965 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3966 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3967 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3968 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3969 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3970 } 3971 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3972 resultSet.close(); 3973 }).catch((err: BusinessError) => { 3974 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 3975 }) 3976} 3977``` 3978 3979### querySql<sup>10+</sup> 3980 3981querySql(sql: string, callback: AsyncCallback<ResultSet>):void 3982 3983Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. This API uses an asynchronous callback to return the result. 3984 3985**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3986 3987**Parameters** 3988 3989| Name | Type | Mandatory| Description | 3990| -------- | -------------------------------------------- | ---- |---------------------------------------| 3991| sql | string | Yes | SQL statement to run. | 3992| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3993 3994**Error codes** 3995 3996For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3997 3998| **ID**| **Error Message** | 3999|-----------| ------------------------------------------------------------ | 4000| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4001| 14800000 | Inner error. | 4002| 14800014 | Already closed. | 4003| 14800015 | The database does not respond. | 4004 4005**Example** 4006 4007```ts 4008if(store != undefined) { 4009 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'", (err, resultSet) => { 4010 if (err) { 4011 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4012 return; 4013 } 4014 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4015 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4016 while (resultSet.goToNextRow()) { 4017 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4018 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4019 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4020 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4021 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4022 } 4023 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4024 resultSet.close(); 4025 }) 4026} 4027``` 4028 4029### querySql 4030 4031querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void 4032 4033Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. This API uses an asynchronous callback to return the result. 4034 4035**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4036 4037**Parameters** 4038 4039| Name | Type | Mandatory| Description | 4040| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | 4041| sql | string | Yes | SQL statement to run. | 4042| bindArgs | Array<[ValueType](#valuetype)> | Yes | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, the value of this parameter must be an empty array.| 4043| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned. | 4044 4045**Error codes** 4046 4047For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4048 4049| **ID**| **Error Message** | 4050|-----------| ------------------------------------------------------------ | 4051| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4052| 14800000 | Inner error. | 4053| 14800014 | Already closed. | 4054| 14800015 | The database does not respond. | 4055 4056**Example** 4057 4058```ts 4059if(store != undefined) { 4060 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], (err, resultSet) => { 4061 if (err) { 4062 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4063 return; 4064 } 4065 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4066 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4067 while (resultSet.goToNextRow()) { 4068 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4069 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4070 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4071 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4072 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4073 } 4074 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4075 resultSet.close(); 4076 }) 4077} 4078``` 4079 4080### querySql 4081 4082querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> 4083 4084Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. This API uses a promise to return the result. 4085 4086**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4087 4088**Parameters** 4089 4090| Name | Type | Mandatory| Description | 4091| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4092| sql | string | Yes | SQL statement to run. | 4093| bindArgs | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank.| 4094 4095**Return value** 4096 4097| Type | Description | 4098| ------------------------------------------------------- | -------------------------------------------------- | 4099| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 4100 4101**Error codes** 4102 4103For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4104 4105| **ID**| **Error Message** | 4106|-----------| ------------------------------------------------------------ | 4107| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4108| 14800000 | Inner error. | 4109| 14800014 | Already closed. | 4110| 14800015 | The database does not respond. | 4111 4112**Example** 4113 4114```ts 4115import { BusinessError } from '@kit.BasicServicesKit'; 4116 4117if(store != undefined) { 4118 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then((resultSet: relationalStore.ResultSet) => { 4119 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4120 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4121 while (resultSet.goToNextRow()) { 4122 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4123 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4124 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4125 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4126 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4127 } 4128 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4129 resultSet.close(); 4130 }).catch((err: BusinessError) => { 4131 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4132 }) 4133} 4134``` 4135 4136### querySqlSync<sup>12+</sup> 4137 4138querySqlSync(sql: string, bindArgs?: Array<ValueType>):ResultSet 4139 4140Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. If complex logic and a large number of loops are involved in the operations on the **resultSet** obtained by **querySync()**, the freeze problem may occur. You are advised to perform this operation in the [taskpool](../apis-arkts/js-apis-taskpool.md) thread. 4141 4142**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4143 4144**Parameters** 4145 4146| Name | Type | Mandatory| Description | 4147| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4148| sql | string | Yes | SQL statement to run. | 4149| bindArgs | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank. The default value is null.| 4150 4151**Return value** 4152 4153| Type | Description | 4154| ----------------------- | ----------------------------------- | 4155| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 4156 4157**Error codes** 4158 4159For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4160 4161| **ID**| **Error Message** | 4162| ------------ | ------------------------------------------------------------ | 4163| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4164| 14800000 | Inner error. | 4165| 14800014 | Already closed. | 4166| 14800015 | The database does not respond. | 4167 4168**Example** 4169 4170```ts 4171import { BusinessError } from '@kit.BasicServicesKit'; 4172 4173if(store != undefined) { 4174 try { 4175 let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'"); 4176 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4177 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4178 while (resultSet.goToNextRow()) { 4179 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4180 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4181 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4182 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4183 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4184 } 4185 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4186 resultSet.close(); 4187 } catch (err) { 4188 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4189 } 4190} 4191``` 4192 4193### executeSql<sup>10+</sup> 4194 4195executeSql(sql: string, callback: AsyncCallback<void>):void 4196 4197Executes an SQL statement that contains specified arguments but returns no value. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses an asynchronous callback to return the result. 4198 4199This API does not support query, attach, or transaction operations. To perform these operations, use [querySql](#querysql10), [query](#query10), [attach](#attach12), [beginTransaction](#begintransaction), and [commit](#commit). 4200 4201Statements separated by semicolons (\;) are not supported. 4202 4203**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4204 4205**Parameters** 4206 4207| Name | Type | Mandatory| Description | 4208| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4209| sql | string | Yes | SQL statement to run. | 4210| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4211 4212**Error codes** 4213 4214For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4215 4216| **ID**| **Error Message** | 4217|-----------| ------------------------------------------------------------ | 4218| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4219| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4220| 14800000 | Inner error. | 4221| 14800011 | Database corrupted. | 4222| 14800014 | Already closed. | 4223| 14800015 | The database does not respond. | 4224| 14800021 | SQLite: Generic error. | 4225| 14800022 | SQLite: Callback routine requested an abort. | 4226| 14800023 | SQLite: Access permission denied. | 4227| 14800024 | SQLite: The database file is locked. | 4228| 14800025 | SQLite: A table in the database is locked. | 4229| 14800026 | SQLite: The database is out of memory. | 4230| 14800027 | SQLite: Attempt to write a readonly database. | 4231| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4232| 14800029 | SQLite: The database is full. | 4233| 14800030 | SQLite: Unable to open the database file. | 4234| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4235| 14800032 | SQLite: Abort due to constraint violation. | 4236| 14800033 | SQLite: Data type mismatch. | 4237| 14800034 | SQLite: Library used incorrectly. | 4238| 14800047 | The WAL file size exceeds the default limit. | 4239 4240**Example** 4241 4242```ts 4243const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" 4244if(store != undefined) { 4245 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, (err) => { 4246 if (err) { 4247 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4248 return; 4249 } 4250 console.info('Delete table done.'); 4251 }) 4252} 4253``` 4254 4255### executeSql 4256 4257executeSql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<void>):void 4258 4259Executes an SQL statement that contains specified arguments but returns no value. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses an asynchronous callback to return the result. 4260 4261This API does not support query, attach, or transaction operations. To perform these operations, use [querySql](#querysql10), [query](#query10), [attach](#attach12), [beginTransaction](#begintransaction), and [commit](#commit). 4262 4263Statements separated by semicolons (\;) are not supported. 4264 4265**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4266 4267**Parameters** 4268 4269| Name | Type | Mandatory| Description | 4270| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4271| sql | string | Yes | SQL statement to run. | 4272| bindArgs | Array<[ValueType](#valuetype)> | Yes | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, the value of this parameter must be an empty array.| 4273| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4274 4275**Error codes** 4276 4277For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4278 4279| **ID**| **Error Message** | 4280|-----------| ------------------------------------------------------------ | 4281| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4282| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4283| 14800000 | Inner error. | 4284| 14800011 | Database corrupted. | 4285| 14800014 | Already closed. | 4286| 14800015 | The database does not respond. | 4287| 14800021 | SQLite: Generic error. | 4288| 14800022 | SQLite: Callback routine requested an abort. | 4289| 14800023 | SQLite: Access permission denied. | 4290| 14800024 | SQLite: The database file is locked. | 4291| 14800025 | SQLite: A table in the database is locked. | 4292| 14800026 | SQLite: The database is out of memory. | 4293| 14800027 | SQLite: Attempt to write a readonly database. | 4294| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4295| 14800029 | SQLite: The database is full. | 4296| 14800030 | SQLite: Unable to open the database file. | 4297| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4298| 14800032 | SQLite: Abort due to constraint violation. | 4299| 14800033 | SQLite: Data type mismatch. | 4300| 14800034 | SQLite: Library used incorrectly. | 4301| 14800047 | The WAL file size exceeds the default limit. | 4302 4303**Example** 4304 4305```ts 4306const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?" 4307if(store != undefined) { 4308 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, ['zhangsan'], (err) => { 4309 if (err) { 4310 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4311 return; 4312 } 4313 console.info('Delete table done.'); 4314 }) 4315} 4316``` 4317 4318### executeSql 4319 4320executeSql(sql: string, bindArgs?: Array<ValueType>):Promise<void> 4321 4322Executes an SQL statement that contains specified arguments but returns no value. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses a promise to return the result. 4323 4324This API does not support query, attach, or transaction operations. To perform these operations, use [querySql](#querysql10), [query](#query10), [attach](#attach12), [beginTransaction](#begintransaction), and [commit](#commit). 4325 4326Statements separated by semicolons (\;) are not supported. 4327 4328**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4329 4330**Parameters** 4331 4332| Name | Type | Mandatory| Description | 4333| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4334| sql | string | Yes | SQL statement to run. | 4335| bindArgs | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank.| 4336 4337**Return value** 4338 4339| Type | Description | 4340| ------------------- | ------------------------- | 4341| Promise<void> | Promise that returns no value.| 4342 4343**Error codes** 4344 4345For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4346 4347| **ID**| **Error Message** | 4348|-----------| ------------------------------------------------------------ | 4349| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4350| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4351| 14800000 | Inner error. | 4352| 14800011 | Database corrupted. | 4353| 14800014 | Already closed. | 4354| 14800015 | The database does not respond. | 4355| 14800021 | SQLite: Generic error. | 4356| 14800022 | SQLite: Callback routine requested an abort. | 4357| 14800023 | SQLite: Access permission denied. | 4358| 14800024 | SQLite: The database file is locked. | 4359| 14800025 | SQLite: A table in the database is locked. | 4360| 14800026 | SQLite: The database is out of memory. | 4361| 14800027 | SQLite: Attempt to write a readonly database. | 4362| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4363| 14800029 | SQLite: The database is full. | 4364| 14800030 | SQLite: Unable to open the database file. | 4365| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4366| 14800032 | SQLite: Abort due to constraint violation. | 4367| 14800033 | SQLite: Data type mismatch. | 4368| 14800034 | SQLite: Library used incorrectly. | 4369| 14800047 | The WAL file size exceeds the default limit. | 4370 4371**Example** 4372 4373```ts 4374import { BusinessError } from '@kit.BasicServicesKit'; 4375 4376const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" 4377if(store != undefined) { 4378 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE).then(() => { 4379 console.info('Delete table done.'); 4380 }).catch((err: BusinessError) => { 4381 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4382 }) 4383} 4384``` 4385 4386### execute<sup>12+</sup> 4387 4388execute(sql: string, args?: Array<ValueType>):Promise<ValueType> 4389 4390Executes an SQL statement that contains specified arguments. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses a promise to return a value of the ValueType type. 4391 4392This API can be used to add, delete, and modify data, run SQL statements of the PRAGMA syntax, and create, delete, and modify a table. The type of the return value varies, depending on the execution result. 4393 4394This API does not support query, attach, or transaction operations. To perform these operations, use [querySql](#querysql10), [query](#query10), [attach](#attach12), [beginTransaction](#begintransaction), and [commit](#commit). 4395 4396Statements separated by semicolons (\;) are not supported. 4397 4398**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4399 4400**Parameters** 4401 4402| Name | Type | Mandatory| Description | 4403| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4404| sql | string | Yes | SQL statement to run. | 4405| args | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank.| 4406 4407**Return value** 4408 4409| Type | Description | 4410| ------------------- | ------------------------- | 4411| Promise<[ValueType](#valuetype)> | Promise used to return the SQL execution result.| 4412 4413**Error codes** 4414 4415For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4416 4417| **ID**| **Error Message** | 4418|-----------| ------------------------------------------------------------ | 4419| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4420| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4421| 14800000 | Inner error. | 4422| 14800011 | Database corrupted. | 4423| 14800014 | Already closed. | 4424| 14800015 | The database does not respond. | 4425| 14800021 | SQLite: Generic error. | 4426| 14800022 | SQLite: Callback routine requested an abort. | 4427| 14800023 | SQLite: Access permission denied. | 4428| 14800024 | SQLite: The database file is locked. | 4429| 14800025 | SQLite: A table in the database is locked. | 4430| 14800026 | SQLite: The database is out of memory. | 4431| 14800027 | SQLite: Attempt to write a readonly database. | 4432| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4433| 14800029 | SQLite: The database is full. | 4434| 14800030 | SQLite: Unable to open the database file. | 4435| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4436| 14800032 | SQLite: Abort due to constraint violation. | 4437| 14800033 | SQLite: Data type mismatch. | 4438| 14800034 | SQLite: Library used incorrectly. | 4439| 14800047 | The WAL file size exceeds the default limit. | 4440 4441**Example** 4442 4443```ts 4444import { BusinessError } from '@kit.BasicServicesKit'; 4445 4446// Check the RDB store integrity. 4447if(store != undefined) { 4448 const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check'; 4449 (store as relationalStore.RdbStore).execute(SQL_CHECK_INTEGRITY).then((data) => { 4450 console.info(`check result: ${data}`); 4451 }).catch((err: BusinessError) => { 4452 console.error(`check failed, code is ${err.code}, message is ${err.message}`); 4453 }) 4454} 4455 4456// Delete all data from the table. 4457if(store != undefined) { 4458 const SQL_DELETE_TABLE = 'DELETE FROM test'; 4459 (store as relationalStore.RdbStore).execute(SQL_DELETE_TABLE).then((data) => { 4460 console.info(`delete result: ${data}`); 4461 }).catch((err: BusinessError) => { 4462 console.error(`delete failed, code is ${err.code}, message is ${err.message}`); 4463 }) 4464} 4465 4466// Delete a table. 4467if(store != undefined) { 4468 const SQL_DROP_TABLE = 'DROP TABLE test'; 4469 (store as relationalStore.RdbStore).execute(SQL_DROP_TABLE).then((data) => { 4470 console.info(`drop result: ${data}`); 4471 }).catch((err: BusinessError) => { 4472 console.error(`drop failed, code is ${err.code}, message is ${err.message}`); 4473 }) 4474} 4475``` 4476 4477### execute<sup>12+</sup> 4478 4479execute(sql: string, txId: number, args?: Array<ValueType>): Promise<ValueType> 4480 4481Executes an SQL statement that contains specified arguments. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses a promise to return the result. 4482 4483<!--RP1--> 4484This API is available only to [vector stores](js-apis-data-relationalStore-sys.md#storeconfig).<!--RP1End--> 4485 4486This API does not support query, attach, or transaction operations. To perform these operations, use [querySql](#querysql10), [query](#query10), [attach](#attach12), [beginTransaction](#begintransaction), and [commit](#commit). 4487 4488Statements separated by semicolons (\;) are not supported. 4489 4490**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4491 4492**Parameters** 4493 4494| Name | Type | Mandatory| Description | 4495| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4496| sql | string | Yes | SQL statement to run. | 4497| txId | number | Yes | Transaction ID obtained via [beginTrans](#begintrans12). If the value is **0**, the SQL statement is executed in a separate transaction by default. | 4498| args | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If this parameter is left blank or set to **null** or **undefined**, the SQL statement is considered complete.| 4499 4500**Return value** 4501 4502| Type | Description | 4503| ------------------- | ------------------------- | 4504| Promise<[ValueType](#valuetype)> | Promise that returns **null**.| 4505 4506**Error codes** 4507 4508For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4509 4510| **ID**| **Error Message** | 4511|-----------| ------------------------------------------------------------ | 4512| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4513| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4514| 14800000 | Inner error. | 4515| 14800011 | Database corrupted. | 4516| 14800014 | Already closed. | 4517| 14800015 | The database does not respond. | 4518| 14800021 | SQLite: Generic error. | 4519| 14800022 | SQLite: Callback routine requested an abort. | 4520| 14800023 | SQLite: Access permission denied. | 4521| 14800024 | SQLite: The database file is locked. | 4522| 14800025 | SQLite: A table in the database is locked. | 4523| 14800026 | SQLite: The database is out of memory. | 4524| 14800027 | SQLite: Attempt to write a readonly database. | 4525| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4526| 14800029 | SQLite: The database is full. | 4527| 14800030 | SQLite: Unable to open the database file. | 4528| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4529| 14800032 | SQLite: Abort due to constraint violation. | 4530| 14800033 | SQLite: Data type mismatch. | 4531| 14800034 | SQLite: Library used incorrectly. | 4532| 14800047 | The WAL file size exceeds the default limit. | 4533 4534**Example** 4535 4536```ts 4537import { BusinessError } from '@kit.BasicServicesKit'; 4538if(store != null) { 4539 let txId : number; 4540 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 4541 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 4542 .then(() => { 4543 (store as relationalStore.RdbStore).commit(txId); 4544 }) 4545 .catch((err: BusinessError) => { 4546 (store as relationalStore.RdbStore).rollback(txId) 4547 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 4548 }); 4549 }); 4550} 4551``` 4552 4553### executeSync<sup>12+</sup> 4554 4555executeSync(sql: string, args?: Array<ValueType>): ValueType 4556 4557Executes an SQL statement that contains specified arguments. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API returns a value of theValueType type. 4558 4559This API can be used to add, delete, and modify data, run SQL statements of the PRAGMA syntax, and create, delete, and modify a table. The type of the return value varies, depending on the execution result. 4560 4561This API does not support query, attach, or transaction operations. To perform these operations, use [querySql](#querysql10), [query](#query10), [attach](#attach12), [beginTransaction](#begintransaction), and [commit](#commit). 4562 4563Statements separated by semicolons (\;) are not supported. 4564 4565**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4566 4567**Parameters** 4568 4569| Name| Type | Mandatory| Description | 4570| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 4571| sql | string | Yes | SQL statement to run. | 4572| args | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If this parameter is left blank or set to **null** or **undefined**, the SQL statement is complete. <br>Default value: null.| 4573 4574**Return value** 4575 4576| Type | Description | 4577| ----------------------- | ------------------- | 4578| [ValueType](#valuetype) | SQL execution result.| 4579 4580**Error codes** 4581 4582For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4583 4584| **ID**| **Error Message** | 4585| ------------ | ------------------------------------------------------------ | 4586| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4587| 14800000 | Inner error. | 4588| 14800011 | Database corrupted. | 4589| 14800014 | Already closed. | 4590| 14800015 | The database does not respond. | 4591| 14800021 | SQLite: Generic error. | 4592| 14800022 | SQLite: Callback routine requested an abort. | 4593| 14800023 | SQLite: Access permission denied. | 4594| 14800024 | SQLite: The database file is locked. | 4595| 14800025 | SQLite: A table in the database is locked. | 4596| 14800026 | SQLite: The database is out of memory. | 4597| 14800027 | SQLite: Attempt to write a readonly database. | 4598| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4599| 14800029 | SQLite: The database is full. | 4600| 14800030 | SQLite: Unable to open the database file. | 4601| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4602| 14800032 | SQLite: Abort due to constraint violation. | 4603| 14800033 | SQLite: Data type mismatch. | 4604| 14800034 | SQLite: Library used incorrectly. | 4605| 14800047 | The WAL file size exceeds the default limit. | 4606 4607**Example** 4608 4609```ts 4610import { BusinessError } from '@kit.BasicServicesKit'; 4611 4612// Check the RDB store integrity. 4613if(store != undefined) { 4614 const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check'; 4615 try { 4616 let data = (store as relationalStore.RdbStore).executeSync(SQL_CHECK_INTEGRITY) 4617 console.info(`check result: ${data}`); 4618 } catch (err) { 4619 console.error(`check failed, code is ${err.code}, message is ${err.message}`); 4620 } 4621} 4622 4623// Delete all data from the table. 4624if(store != undefined) { 4625 const SQL_DELETE_TABLE = 'DELETE FROM test'; 4626 try { 4627 let data = (store as relationalStore.RdbStore).executeSync(SQL_DELETE_TABLE) 4628 console.info(`delete result: ${data}`); 4629 } catch (err) { 4630 console.error(`delete failed, code is ${err.code}, message is ${err.message}`); 4631 } 4632} 4633 4634// Delete a table. 4635if(store != undefined) { 4636 const SQL_DROP_TABLE = 'DROP TABLE test'; 4637 try { 4638 let data = (store as relationalStore.RdbStore).executeSync(SQL_DROP_TABLE) 4639 console.info(`drop result: ${data}`); 4640 } catch (err) { 4641 console.error(`drop failed, code is ${err.code}, message is ${err.message}`); 4642 } 4643} 4644``` 4645 4646### getModifyTime<sup>10+</sup> 4647 4648getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[], callback: AsyncCallback<ModifyTime>): void 4649 4650Obtains the last modification time of the data in a table. This API uses an asynchronous callback to return the result. 4651 4652**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4653 4654**Parameters** 4655 4656| Name | Type | Mandatory| Description | 4657| ----------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 4658| table | string | Yes | Name of the database table to query. | 4659| columnName | string | Yes | Column name of the database table to query. | 4660| primaryKeys | [PRIKeyType](#prikeytype10)[] | Yes | Primary keys of the rows to query.<br>If the database table has no primary key, **rowid** must be passed in through **columnName**. In this case, **primaryKeys** specifies the row numbers of the database table to query.<br>If the database table has no primary key and no **rowid** is passed in through **columnName**, an error code will be returned.| 4661| callback | AsyncCallback<[ModifyTime](#modifytime10)> | Yes | Callback used to return the result. If the operation is successful, the **ModifyTime** object is returned.| 4662 4663**Error codes** 4664 4665For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4666 4667| **ID**| **Error Message** | 4668|-----------| ------------------------------------------------------------ | 4669| 401 | Parameter error. Possible causes: 1. Need 3 - 4 parameter(s)! 2. The RdbStore must be not nullptr.3. The tablesNames must be not empty string. 4. The columnName must be not empty string. 5. The PRIKey must be number or string. | 4670| 801 | Capability not supported. | 4671| 14800000 | Inner error. | 4672| 14800011 | Database corrupted. | 4673| 14800014 | Already closed. | 4674| 14800015 | The database does not respond. | 4675| 14800021 | SQLite: Generic error. | 4676| 14800022 | SQLite: Callback routine requested an abort. | 4677| 14800023 | SQLite: Access permission denied. | 4678| 14800024 | SQLite: The database file is locked. | 4679| 14800025 | SQLite: A table in the database is locked. | 4680| 14800026 | SQLite: The database is out of memory. | 4681| 14800027 | SQLite: Attempt to write a readonly database. | 4682| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4683| 14800029 | SQLite: The database is full. | 4684| 14800030 | SQLite: Unable to open the database file. | 4685| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4686| 14800032 | SQLite: Abort due to constraint violation. | 4687| 14800033 | SQLite: Data type mismatch. | 4688| 14800034 | SQLite: Library used incorrectly. | 4689 4690**Example** 4691 4692```ts 4693let PRIKey = [1, 4, 2, 3]; 4694if(store != undefined) { 4695 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey, (err, modifyTime: relationalStore.ModifyTime) => { 4696 if (err) { 4697 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 4698 return; 4699 } 4700 let size = modifyTime.size; 4701 }); 4702} 4703``` 4704 4705### getModifyTime<sup>10+</sup> 4706 4707getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[]): Promise<ModifyTime> 4708 4709Obtains the last modification time of the data in a table. This API uses a promise to return the result. 4710 4711**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4712 4713**Parameters** 4714 4715| Name | Type | Mandatory| Description | 4716| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ | 4717| table | string | Yes | Name of the database table to query. | 4718| columnName | string | Yes | Column name of the database table to query. | 4719| primaryKeys | [PRIKeyType](#prikeytype10)[] | Yes | Primary keys of the rows to query.<br>If the database table has no primary key, **rowid** must be passed in through **columnName**. In this case, **primaryKeys** specifies the row numbers of the database table to query.<br>If the database table has no primary key and no **rowid** is passed in through **columnName**, an error code will be returned.| 4720 4721**Return value** 4722 4723| Type | Description | 4724| ------------------------------------------ | --------------------------------------------------------- | 4725| Promise<[ModifyTime](#modifytime10)> | Promise used to return the **ModifyTime** object.| 4726 4727**Error codes** 4728 4729For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4730 4731| **ID**| **Error Message** | 4732|-----------| ------------------------------------------------------------ | 4733| 401 | Parameter error. Possible causes: 1. Need 3 - 4 parameter(s)! 2. The RdbStore must be not nullptr.3. The tablesNames must be not empty string. 4. The columnName must be not empty string. 5. The PRIKey must be number or string. | 4734| 801 | Capability not supported. | 4735| 14800000 | Inner error. | 4736| 14800011 | Database corrupted. | 4737| 14800014 | Already closed. | 4738| 14800015 | The database does not respond. | 4739| 14800021 | SQLite: Generic error. | 4740| 14800022 | SQLite: Callback routine requested an abort. | 4741| 14800023 | SQLite: Access permission denied. | 4742| 14800024 | SQLite: The database file is locked. | 4743| 14800025 | SQLite: A table in the database is locked. | 4744| 14800026 | SQLite: The database is out of memory. | 4745| 14800027 | SQLite: Attempt to write a readonly database. | 4746| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4747| 14800029 | SQLite: The database is full. | 4748| 14800030 | SQLite: Unable to open the database file. | 4749| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4750| 14800032 | SQLite: Abort due to constraint violation. | 4751| 14800033 | SQLite: Data type mismatch. | 4752| 14800034 | SQLite: Library used incorrectly. | 4753 4754**Example** 4755 4756```ts 4757import { BusinessError } from '@kit.BasicServicesKit'; 4758 4759let PRIKey = [1, 2, 3]; 4760if(store != undefined) { 4761 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey) 4762 .then((modifyTime: relationalStore.ModifyTime) => { 4763 let size = modifyTime.size; 4764 }) 4765 .catch((err: BusinessError) => { 4766 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 4767 }); 4768} 4769``` 4770 4771### beginTransaction 4772 4773beginTransaction():void 4774 4775Begins a transaction before executing an SQL statement. 4776This API does not allow nested transactions and cannot be used across processes or threads. 4777 4778**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4779 4780**Error codes** 4781 4782For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4783 4784| **ID**| **Error Message** | 4785|-----------| ------------------------------------------------------------ | 4786| 401 | Parameter error. The store must not be nullptr. | 4787| 14800000 | Inner error. | 4788| 14800011 | Database corrupted. | 4789| 14800014 | Already closed. | 4790| 14800015 | The database does not respond. | 4791| 14800021 | SQLite: Generic error. | 4792| 14800022 | SQLite: Callback routine requested an abort. | 4793| 14800023 | SQLite: Access permission denied. | 4794| 14800024 | SQLite: The database file is locked. | 4795| 14800025 | SQLite: A table in the database is locked. | 4796| 14800026 | SQLite: The database is out of memory. | 4797| 14800027 | SQLite: Attempt to write a readonly database. | 4798| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4799| 14800029 | SQLite: The database is full. | 4800| 14800030 | SQLite: Unable to open the database file. | 4801| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4802| 14800032 | SQLite: Abort due to constraint violation. | 4803| 14800033 | SQLite: Data type mismatch. | 4804| 14800034 | SQLite: Library used incorrectly. | 4805| 14800047 | The WAL file size exceeds the default limit. | 4806 4807**Example** 4808 4809```ts 4810 4811let value1 = "Lisa"; 4812let value2 = 18; 4813let value3 = 100.5; 4814let value4 = new Uint8Array([1, 2, 3]); 4815 4816if(store != undefined) { 4817 (store as relationalStore.RdbStore).beginTransaction(); 4818 const valueBucket: relationalStore.ValuesBucket = { 4819 'NAME': value1, 4820 'AGE': value2, 4821 'SALARY': value3, 4822 'CODES': value4, 4823 }; 4824 (store as relationalStore.RdbStore).insert("test", valueBucket); 4825 (store as relationalStore.RdbStore).commit(); 4826} 4827``` 4828 4829### beginTrans<sup>12+</sup> 4830 4831beginTrans(): Promise<number> 4832 4833Begins a transaction before executing the SQL statement. This API uses a promise to return the result. 4834 4835Different from [beginTransaction](#begintransaction), this API returns a transaction ID. [execute](#execute12-1) can specify the transaction ID to isolate different transactions. 4836 4837<!--RP1--> 4838This API is available only to [vector stores](js-apis-data-relationalStore-sys.md#storeconfig).<!--RP1End--> 4839 4840**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4841 4842**Return value** 4843 4844| Type | Description | 4845| ------------------- | ------------------------- | 4846| Promise<number> | Promise used to return the transaction ID.| 4847 4848**Error codes** 4849 4850For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4851 4852| **ID**| **Error Message** | 4853|-----------| ------------------------------------------------------------ | 4854| 401 | Parameter error. The store must not be nullptr. | 4855| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4856| 14800000 | Inner error. | 4857| 14800011 | Database corrupted. | 4858| 14800014 | Already closed. | 4859| 14800015 | The database does not respond. | 4860| 14800021 | SQLite: Generic error. | 4861| 14800022 | SQLite: Callback routine requested an abort. | 4862| 14800023 | SQLite: Access permission denied. | 4863| 14800024 | SQLite: The database file is locked. | 4864| 14800025 | SQLite: A table in the database is locked. | 4865| 14800026 | SQLite: The database is out of memory. | 4866| 14800027 | SQLite: Attempt to write a readonly database. | 4867| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4868| 14800029 | SQLite: The database is full. | 4869| 14800030 | SQLite: Unable to open the database file. | 4870| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4871| 14800032 | SQLite: Abort due to constraint violation. | 4872| 14800033 | SQLite: Data type mismatch. | 4873| 14800034 | SQLite: Library used incorrectly. | 4874| 14800047 | The WAL file size exceeds the default limit. | 4875 4876**Example** 4877 4878```ts 4879import { BusinessError } from '@kit.BasicServicesKit'; 4880if(store != null) { 4881 let txId : number; 4882 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 4883 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 4884 .then(() => { 4885 (store as relationalStore.RdbStore).commit(txId); 4886 }) 4887 .catch((err: BusinessError) => { 4888 (store as relationalStore.RdbStore).rollback(txId) 4889 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 4890 }); 4891 }); 4892} 4893``` 4894 4895### createTransaction<sup>14+</sup> 4896 4897createTransaction(options?: TransactionOptions): Promise<Transaction> 4898 4899Creates a transaction object and starts a transaction. This API uses a promise to return the result. 4900 4901Different from [beginTransaction](#begintransaction), **createTransaction()** returns a transaction object, which is isolated from other transaction objects. When a transaction object is used to insert, delete, or update data, these changes cannot be detected by [on ('dataChange')](#ondatachange). 4902 4903A store supports a maximum of four transaction objects at a time. Exceeding the limit will return error 14800015. If this occurs, check for the transaction object that is being held too long or if there are too many concurrent transactions. If the problem persists, wait for other transactions to be released before creating new transaction objects. 4904 4905You are advised to use **createTransaction** instead of **beginTransaction**. 4906 4907**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4908 4909**Parameters** 4910 4911| Name | Type | Mandatory| Description | 4912| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ | 4913| options | [TransactionOptions](#transactionoptions14) | No | Configuration of the transaction object to create. | 4914 4915**Return value** 4916 4917| Type | Description | 4918| ------------------- | ------------------------- | 4919| Promise<[Transaction](#transaction14)> | Promise used to return the transaction object created.| 4920 4921**Error codes** 4922 4923For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4924 4925| **ID**| **Error Message** | 4926|-----------| ------------------------------------------------------------ | 4927| 14800000 | Inner error. | 4928| 14800011 | Database corrupted. | 4929| 14800014 | Already closed. | 4930| 14800015 | The database is busy. | 4931| 14800023 | SQLite: Access permission denied. | 4932| 14800024 | SQLite: The database file is locked. | 4933| 14800026 | SQLite: The database is out of memory. | 4934| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4935| 14800029 | SQLite: The database is full. | 4936| 14800030 | SQLite: Unable to open the database file. | 4937 4938**Example** 4939 4940```ts 4941import { BusinessError } from '@kit.BasicServicesKit'; 4942 4943if(store != undefined) { 4944 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 4945 transaction.execute("DELETE FROM test WHERE age = ? OR age = ?", [21, 20]).then(() => { 4946 transaction.commit(); 4947 }).catch((e: BusinessError) => { 4948 transaction.rollback(); 4949 console.error(`execute sql failed, code is ${e.code},message is ${e.message}`); 4950 }); 4951 }).catch((err: BusinessError) => { 4952 console.error(`createTransaction faided, code is ${err.code},message is ${err.message}`); 4953 }); 4954} 4955``` 4956 4957### commit 4958 4959commit():void 4960 4961Commits the executed SQL statement. This API must be used with [beginTransaction](#begintransaction). 4962This API does not allow nested transactions and cannot be used across processes or threads. 4963 4964**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4965 4966**Error codes** 4967 4968For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 4969 4970| **ID**| **Error Message** | 4971|-----------| ------------------------------------------------------------ | 4972| 401 | Parameter error. The store must not be nullptr. | 4973| 14800000 | Inner error. | 4974| 14800011 | Database corrupted. | 4975| 14800014 | Already closed. | 4976| 14800015 | The database does not respond. | 4977| 14800021 | SQLite: Generic error. | 4978| 14800022 | SQLite: Callback routine requested an abort. | 4979| 14800023 | SQLite: Access permission denied. | 4980| 14800024 | SQLite: The database file is locked. | 4981| 14800025 | SQLite: A table in the database is locked. | 4982| 14800026 | SQLite: The database is out of memory. | 4983| 14800027 | SQLite: Attempt to write a readonly database. | 4984| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4985| 14800029 | SQLite: The database is full. | 4986| 14800030 | SQLite: Unable to open the database file. | 4987| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4988| 14800032 | SQLite: Abort due to constraint violation. | 4989| 14800033 | SQLite: Data type mismatch. | 4990| 14800034 | SQLite: Library used incorrectly. | 4991 4992**Example** 4993 4994```ts 4995 4996let value1 = "Lisa"; 4997let value2 = 18; 4998let value3 = 100.5; 4999let value4 = new Uint8Array([1, 2, 3]); 5000 5001if(store != undefined) { 5002 (store as relationalStore.RdbStore).beginTransaction(); 5003 const valueBucket: relationalStore.ValuesBucket = { 5004 'NAME': value1, 5005 'AGE': value2, 5006 'SALARY': value3, 5007 'CODES': value4, 5008 }; 5009 (store as relationalStore.RdbStore).insert("test", valueBucket); 5010 (store as relationalStore.RdbStore).commit(); 5011} 5012``` 5013 5014### commit<sup>12+</sup> 5015 5016commit(txId : number):Promise<void> 5017 5018Commits the executed SQL statement. This API must be used with [beginTrans](#begintrans12). 5019 5020<!--RP1--> 5021This API is available only to [vector stores](js-apis-data-relationalStore-sys.md#storeconfig).<!--RP1End--> 5022 5023**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5024 5025**Parameters** 5026 5027| Name | Type | Mandatory| Description | 5028| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 5029| txId | number | Yes | Transaction ID obtained via [beginTrans](#begintrans12). | 5030 5031**Return value** 5032 5033| Type | Description | 5034| ------------------- | ------------------------- | 5035| Promise<void> | Promise that returns no value.| 5036 5037**Error codes** 5038 5039For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 5040 5041| **ID**| **Error Message** | 5042|-----------| ------------------------------------------------------------ | 5043| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5044| 14800000 | Inner error. | 5045| 14800011 | Database corrupted. | 5046| 14800014 | Already closed. | 5047| 14800015 | The database does not respond. | 5048| 14800021 | SQLite: Generic error. | 5049| 14800022 | SQLite: Callback routine requested an abort. | 5050| 14800023 | SQLite: Access permission denied. | 5051| 14800024 | SQLite: The database file is locked. | 5052| 14800025 | SQLite: A table in the database is locked. | 5053| 14800026 | SQLite: The database is out of memory. | 5054| 14800027 | SQLite: Attempt to write a readonly database. | 5055| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5056| 14800029 | SQLite: The database is full. | 5057| 14800030 | SQLite: Unable to open the database file. | 5058| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5059| 14800032 | SQLite: Abort due to constraint violation. | 5060| 14800033 | SQLite: Data type mismatch. | 5061| 14800034 | SQLite: Library used incorrectly. | 5062 5063**Example** 5064 5065```ts 5066import { BusinessError } from '@kit.BasicServicesKit'; 5067if(store != null) { 5068 let txId : number; 5069 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 5070 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 5071 .then(() => { 5072 (store as relationalStore.RdbStore).commit(txId); 5073 }) 5074 .catch((err: BusinessError) => { 5075 (store as relationalStore.RdbStore).rollback(txId) 5076 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 5077 }); 5078 }); 5079} 5080``` 5081 5082### rollBack 5083 5084rollBack():void 5085 5086Rolls back the executed SQL statement. 5087This API does not allow nested transactions and cannot be used across processes or threads. 5088 5089**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5090 5091**Error codes** 5092 5093For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 5094 5095| **ID**| **Error Message** | 5096|-----------| ------------------------------------------------------------ | 5097| 401 | Parameter error. The store must not be nullptr. | 5098| 14800000 | Inner error. | 5099| 14800011 | Database corrupted. | 5100| 14800014 | Already closed. | 5101| 14800015 | The database does not respond. | 5102| 14800021 | SQLite: Generic error. | 5103| 14800022 | SQLite: Callback routine requested an abort. | 5104| 14800023 | SQLite: Access permission denied. | 5105| 14800024 | SQLite: The database file is locked. | 5106| 14800025 | SQLite: A table in the database is locked. | 5107| 14800026 | SQLite: The database is out of memory. | 5108| 14800027 | SQLite: Attempt to write a readonly database. | 5109| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5110| 14800029 | SQLite: The database is full. | 5111| 14800030 | SQLite: Unable to open the database file. | 5112| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5113| 14800032 | SQLite: Abort due to constraint violation. | 5114| 14800033 | SQLite: Data type mismatch. | 5115| 14800034 | SQLite: Library used incorrectly. | 5116 5117**Example** 5118 5119```ts 5120import { BusinessError } from '@kit.BasicServicesKit'; 5121 5122let value1 = "Lisa"; 5123let value2 = 18; 5124let value3 = 100.5; 5125let value4 = new Uint8Array([1, 2, 3]); 5126 5127if(store != undefined) { 5128 try { 5129 (store as relationalStore.RdbStore).beginTransaction() 5130 const valueBucket: relationalStore.ValuesBucket = { 5131 'NAME': value1, 5132 'AGE': value2, 5133 'SALARY': value3, 5134 'CODES': value4, 5135 }; 5136 (store as relationalStore.RdbStore).insert("test", valueBucket); 5137 (store as relationalStore.RdbStore).commit(); 5138 } catch (err) { 5139 let code = (err as BusinessError).code; 5140 let message = (err as BusinessError).message 5141 console.error(`Transaction failed, code is ${code},message is ${message}`); 5142 (store as relationalStore.RdbStore).rollBack(); 5143 } 5144} 5145``` 5146 5147### rollback<sup>12+</sup> 5148 5149rollback(txId : number):Promise<void> 5150 5151Rolls back the executed SQL statement. This API must be used with [beginTrans](#begintrans12). 5152 5153<!--RP1--> 5154This API is available only to [vector stores](js-apis-data-relationalStore-sys.md#storeconfig).<!--RP1End--> 5155 5156**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5157 5158**Parameters** 5159 5160| Name | Type | Mandatory| Description | 5161| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 5162| txId | number | Yes | Transaction ID obtained via [beginTrans](#begintrans12). | 5163 5164**Return value** 5165 5166| Type | Description | 5167| ------------------- | ------------------------- | 5168| Promise<void> | Promise that returns no value.| 5169 5170**Error codes** 5171 5172For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 5173 5174| **ID**| **Error Message** | 5175|-----------| ------------------------------------------------------------ | 5176| 401 | Parameter error. The store must not be nullptr. | 5177| 14800000 | Inner error. | 5178| 14800011 | Database corrupted. | 5179| 14800014 | Already closed. | 5180| 14800015 | The database does not respond. | 5181| 14800021 | SQLite: Generic error. | 5182| 14800022 | SQLite: Callback routine requested an abort. | 5183| 14800023 | SQLite: Access permission denied. | 5184| 14800024 | SQLite: The database file is locked. | 5185| 14800025 | SQLite: A table in the database is locked. | 5186| 14800026 | SQLite: The database is out of memory. | 5187| 14800027 | SQLite: Attempt to write a readonly database. | 5188| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5189| 14800029 | SQLite: The database is full. | 5190| 14800030 | SQLite: Unable to open the database file. | 5191| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5192| 14800032 | SQLite: Abort due to constraint violation. | 5193| 14800033 | SQLite: Data type mismatch. | 5194| 14800034 | SQLite: Library used incorrectly. | 5195 5196**Example** 5197 5198```ts 5199import { BusinessError } from '@kit.BasicServicesKit'; 5200if(store != null) { 5201 let txId : number; 5202 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 5203 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 5204 .then(() => { 5205 (store as relationalStore.RdbStore).commit(txId); 5206 }) 5207 .catch((err: BusinessError) => { 5208 (store as relationalStore.RdbStore).rollback(txId) 5209 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 5210 }); 5211 }); 5212} 5213``` 5214 5215### backup 5216 5217backup(destName:string, callback: AsyncCallback<void>):void 5218 5219Backs up an RDB store. This API uses an asynchronous callback to return the result. 5220 5221**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5222 5223**Parameters** 5224 5225| Name | Type | Mandatory| Description | 5226| -------- | ------------------------- | ---- | ------------------------ | 5227| destName | string | Yes | Name of the RDB store backup file.| 5228| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5229 5230**Error codes** 5231 5232For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 5233 5234| **ID**| **Error Message** | 5235|-----------| ------------------------------------------------------------ | 5236| 401 | Parameter error. The store must not be nullptr. | 5237| 14800000 | Inner error. | 5238| 14800010 | Invalid database path. | 5239| 14800011 | Database corrupted. | 5240| 14800014 | Already closed. | 5241| 14800015 | The database does not respond. | 5242| 14800021 | SQLite: Generic error. | 5243| 14800022 | SQLite: Callback routine requested an abort. | 5244| 14800023 | SQLite: Access permission denied. | 5245| 14800024 | SQLite: The database file is locked. | 5246| 14800025 | SQLite: A table in the database is locked. | 5247| 14800026 | SQLite: The database is out of memory. | 5248| 14800027 | SQLite: Attempt to write a readonly database. | 5249| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5250| 14800029 | SQLite: The database is full. | 5251| 14800030 | SQLite: Unable to open the database file. | 5252| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5253| 14800032 | SQLite: Abort due to constraint violation. | 5254| 14800033 | SQLite: Data type mismatch. | 5255| 14800034 | SQLite: Library used incorrectly. | 5256 5257**Example** 5258 5259```ts 5260if(store != undefined) { 5261 (store as relationalStore.RdbStore).backup("dbBackup.db", (err) => { 5262 if (err) { 5263 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 5264 return; 5265 } 5266 console.info('Backup success.'); 5267 }) 5268} 5269``` 5270 5271### backup 5272 5273backup(destName:string): Promise<void> 5274 5275Backs up an RDB store. This API uses a promise to return the result. 5276 5277**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5278 5279**Parameters** 5280 5281| Name | Type | Mandatory| Description | 5282| -------- | ------ | ---- | ------------------------ | 5283| destName | string | Yes | Name of the RDB store backup file.| 5284 5285**Return value** 5286 5287| Type | Description | 5288| ------------------- | ------------------------- | 5289| Promise<void> | Promise that returns no value.| 5290 5291**Error codes** 5292 5293For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 5294 5295| **ID**| **Error Message** | 5296|-----------| ------------------------------------------------------------ | 5297| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5298| 14800000 | Inner error. | 5299| 14800011 | Database corrupted. | 5300| 14800014 | Already closed. | 5301| 14800015 | The database does not respond. | 5302| 14800021 | SQLite: Generic error. | 5303| 14800022 | SQLite: Callback routine requested an abort. | 5304| 14800023 | SQLite: Access permission denied. | 5305| 14800024 | SQLite: The database file is locked. | 5306| 14800025 | SQLite: A table in the database is locked. | 5307| 14800026 | SQLite: The database is out of memory. | 5308| 14800027 | SQLite: Attempt to write a readonly database. | 5309| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5310| 14800029 | SQLite: The database is full. | 5311| 14800030 | SQLite: Unable to open the database file. | 5312| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5313| 14800032 | SQLite: Abort due to constraint violation. | 5314| 14800033 | SQLite: Data type mismatch. | 5315| 14800034 | SQLite: Library used incorrectly. | 5316 5317**Example** 5318 5319```ts 5320import { BusinessError } from '@kit.BasicServicesKit'; 5321 5322if(store != undefined) { 5323 let promiseBackup = (store as relationalStore.RdbStore).backup("dbBackup.db"); 5324 promiseBackup.then(() => { 5325 console.info('Backup success.'); 5326 }).catch((err: BusinessError) => { 5327 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 5328 }) 5329} 5330``` 5331 5332### restore 5333 5334restore(srcName:string, callback: AsyncCallback<void>):void 5335 5336Restores an RDB store from a backup file. This API uses an asynchronous callback to return the result. 5337 5338**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5339 5340**Parameters** 5341 5342| Name | Type | Mandatory| Description | 5343| -------- | ------------------------- | ---- | ------------------------ | 5344| srcName | string | Yes | Name of the RDB store backup file.| 5345| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5346 5347**Error codes** 5348 5349For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 5350 5351| **ID**| **Error Message** | 5352|-----------| ------------------------------------------------------------ | 5353| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5354| 14800000 | Inner error. | 5355| 14800011 | Database corrupted. | 5356| 14800014 | Already closed. | 5357| 14800015 | The database does not respond. | 5358| 14800021 | SQLite: Generic error. | 5359| 14800022 | SQLite: Callback routine requested an abort. | 5360| 14800023 | SQLite: Access permission denied. | 5361| 14800024 | SQLite: The database file is locked. | 5362| 14800025 | SQLite: A table in the database is locked. | 5363| 14800026 | SQLite: The database is out of memory. | 5364| 14800027 | SQLite: Attempt to write a readonly database. | 5365| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5366| 14800029 | SQLite: The database is full. | 5367| 14800030 | SQLite: Unable to open the database file. | 5368| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5369| 14800032 | SQLite: Abort due to constraint violation. | 5370| 14800033 | SQLite: Data type mismatch. | 5371| 14800034 | SQLite: Library used incorrectly. | 5372 5373**Example** 5374 5375```ts 5376if(store != undefined) { 5377 (store as relationalStore.RdbStore).restore("dbBackup.db", (err) => { 5378 if (err) { 5379 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 5380 return; 5381 } 5382 console.info('Restore success.'); 5383 }) 5384} 5385``` 5386 5387### restore 5388 5389restore(srcName:string): Promise<void> 5390 5391Restores an RDB store from a backup file. This API uses a promise to return the result. 5392 5393**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5394 5395**Parameters** 5396 5397| Name | Type | Mandatory| Description | 5398| ------- | ------ | ---- | ------------------------ | 5399| srcName | string | Yes | Name of the RDB store backup file.| 5400 5401**Return value** 5402 5403| Type | Description | 5404| ------------------- | ------------------------- | 5405| Promise<void> | Promise that returns no value.| 5406 5407**Error codes** 5408 5409For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 5410 5411| **ID**| **Error Message** | 5412|-----------| ------------------------------------------------------------ | 5413| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5414| 14800000 | Inner error. | 5415| 14800011 | Database corrupted. | 5416| 14800014 | Already closed. | 5417| 14800015 | The database does not respond. | 5418| 14800021 | SQLite: Generic error. | 5419| 14800022 | SQLite: Callback routine requested an abort. | 5420| 14800023 | SQLite: Access permission denied. | 5421| 14800024 | SQLite: The database file is locked. | 5422| 14800025 | SQLite: A table in the database is locked. | 5423| 14800026 | SQLite: The database is out of memory. | 5424| 14800027 | SQLite: Attempt to write a readonly database. | 5425| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5426| 14800029 | SQLite: The database is full. | 5427| 14800030 | SQLite: Unable to open the database file. | 5428| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5429| 14800032 | SQLite: Abort due to constraint violation. | 5430| 14800033 | SQLite: Data type mismatch. | 5431| 14800034 | SQLite: Library used incorrectly. | 5432 5433**Example** 5434 5435```ts 5436import { BusinessError } from '@kit.BasicServicesKit'; 5437 5438if(store != undefined) { 5439 let promiseRestore = (store as relationalStore.RdbStore).restore("dbBackup.db"); 5440 promiseRestore.then(() => { 5441 console.info('Restore success.'); 5442 }).catch((err: BusinessError) => { 5443 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 5444 }) 5445} 5446``` 5447 5448### setDistributedTables 5449 5450setDistributedTables(tables: Array<string>, callback: AsyncCallback<void>): void 5451 5452Sets distributed tables. This API uses an asynchronous callback to return the result. 5453 5454**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5455 5456**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5457 5458**Parameters** 5459 5460| Name | Type | Mandatory| Description | 5461| -------- | ------------------------- | ---- | ---------------------- | 5462| tables | Array<string> | Yes | Names of the distributed tables to set.| 5463| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 5464 5465**Error codes** 5466 5467For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5468 5469| **ID**| **Error Message** | 5470|-----------| ------------------------------------------------------------ | 5471| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5472| 801 | Capability not supported. | 5473| 14800000 | Inner error. | 5474| 14800014 | Already closed. | 5475 5476**Example** 5477 5478```ts 5479if(store != undefined) { 5480 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], (err) => { 5481 if (err) { 5482 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5483 return; 5484 } 5485 console.info('SetDistributedTables successfully.'); 5486 }) 5487} 5488``` 5489 5490### setDistributedTables 5491 5492 setDistributedTables(tables: Array<string>): Promise<void> 5493 5494Sets distributed tables. This API uses a promise to return the result. 5495 5496**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5497 5498**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5499 5500**Parameters** 5501 5502| Name| Type | Mandatory| Description | 5503| ------ | ------------------------ | ---- | ------------------------ | 5504| tables | ArrayArray<string> | Yes | Names of the distributed tables to set.| 5505 5506**Return value** 5507 5508| Type | Description | 5509| ------------------- | ------------------------- | 5510| Promise<void> | Promise that returns no value.| 5511 5512**Error codes** 5513 5514For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5515 5516| **ID**| **Error Message** | 5517|-----------| ------------------------------------------------------------ | 5518| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5519| 801 | Capability not supported. | 5520| 14800000 | Inner error. | 5521| 14800014 | Already closed. | 5522 5523**Example** 5524 5525```ts 5526import { BusinessError } from '@kit.BasicServicesKit'; 5527 5528if(store != undefined) { 5529 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"]).then(() => { 5530 console.info('SetDistributedTables successfully.'); 5531 }).catch((err: BusinessError) => { 5532 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5533 }) 5534} 5535``` 5536 5537### setDistributedTables<sup>10+</sup> 5538 5539setDistributedTables(tables: Array<string>, type: DistributedType, callback: AsyncCallback<void>): void 5540 5541Sets distributed tables. This API uses an asynchronous callback to return the result. 5542 5543**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5544 5545**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5546 5547**Parameters** 5548 5549| Name | Type | Mandatory| Description | 5550| -------- | ------------------------------------- | ---- | ---------------------------- | 5551| tables | Array<string> | Yes | Names of the distributed tables to set.| 5552| type | [DistributedType](#distributedtype10) | Yes | Distributed type of the tables. | 5553| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5554 5555**Error codes** 5556 5557For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5558 5559| **ID**| **Error Message** | 5560|-----------| ------------------------------------------------------------ | 5561| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5562| 801 | Capability not supported. | 5563| 14800000 | Inner error. | 5564| 14800014 | Already closed. | 5565| 14800051 | The type of the distributed table does not match. | 5566 5567**Example** 5568 5569```ts 5570if(store != undefined) { 5571 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, (err) => { 5572 if (err) { 5573 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5574 return; 5575 } 5576 console.info('SetDistributedTables successfully.'); 5577 }) 5578} 5579``` 5580 5581### setDistributedTables<sup>10+</sup> 5582 5583setDistributedTables(tables: Array<string>, type: DistributedType, config: DistributedConfig, callback: AsyncCallback<void>): void 5584 5585Sets distributed tables. This API uses an asynchronous callback to return the result. 5586 5587**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5588 5589**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5590 5591**Parameters** 5592 5593| Name | Type | Mandatory | Description | 5594| -------- | ----------------------------------- | --- | --------------- | 5595| tables | Array<string> | Yes | Names of the distributed tables to set. | 5596| type | [DistributedType](#distributedtype10) | Yes | Distributed type of the tables.| 5597| config | [DistributedConfig](#distributedconfig10) | Yes| Configuration of the distributed mode.| 5598| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 5599 5600**Error codes** 5601 5602For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5603 5604| **ID**| **Error Message** | 5605|-----------| ------------------------------------------------------------ | 5606| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5607| 801 | Capability not supported. | 5608| 14800000 | Inner error. | 5609| 14800014 | Already closed. | 5610| 14800051 | The type of the distributed table does not match. | 5611 5612**Example** 5613 5614```ts 5615if(store != undefined) { 5616 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 5617 autoSync: true 5618 }, (err) => { 5619 if (err) { 5620 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5621 return; 5622 } 5623 console.info('SetDistributedTables successfully.'); 5624 }) 5625} 5626``` 5627 5628### setDistributedTables<sup>10+</sup> 5629 5630 setDistributedTables(tables: Array<string>, type?: DistributedType, config?: DistributedConfig): Promise<void> 5631 5632Sets distributed tables. This API uses a promise to return the result. 5633 5634**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5635 5636**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5637 5638**Parameters** 5639 5640| Name| Type | Mandatory| Description | 5641| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ | 5642| tables | Array<string> | Yes | Names of the distributed tables to set. | 5643| type | [DistributedType](#distributedtype10) | No | Distributed type of the tables. <br>Default value: **relationalStore.DistributedType.DISTRIBUTED_DEVICE**.| 5644| config | [DistributedConfig](#distributedconfig10) | No | Configuration of the distributed mode. If this parameter is not specified, the value of **autoSync** is **false** by default, which means only manual sync is supported.| 5645 5646**Return value** 5647 5648| Type | Description | 5649| ------------------- | ------------------------- | 5650| Promise<void> | Promise that returns no value.| 5651 5652**Error codes** 5653 5654For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5655 5656| **ID**| **Error Message** | 5657|-----------| ------------------------------------------------------------ | 5658| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5659| 801 | Capability not supported. | 5660| 14800000 | Inner error. | 5661| 14800014 | Already closed. | 5662| 14800051 | The type of the distributed table does not match. | 5663 5664**Example** 5665 5666```ts 5667import { BusinessError } from '@kit.BasicServicesKit'; 5668 5669if(store != undefined) { 5670 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 5671 autoSync: true 5672 }).then(() => { 5673 console.info('SetDistributedTables successfully.'); 5674 }).catch((err: BusinessError) => { 5675 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5676 }) 5677} 5678``` 5679 5680### obtainDistributedTableName 5681 5682obtainDistributedTableName(device: string, table: string, callback: AsyncCallback<string>): void 5683 5684Obtains the distributed table name of a remote device based on the local table name of the device. The distributed table name is required when the RDB store of a remote device is queried. 5685 5686> **NOTE** 5687> 5688> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 5689 5690**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5691 5692**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5693 5694**Parameters** 5695 5696| Name | Type | Mandatory| Description | 5697| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 5698| device | string | Yes | ID of the remote device. | 5699| table | string | Yes | Local table name of the remote device. | 5700| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| 5701 5702**Error codes** 5703 5704For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5705 5706| **ID**| **Error Message** | 5707|-----------| ------------------------------------------------------------ | 5708| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5709| 801 | Capability not supported. | 5710| 14800000 | Inner error. | 5711| 14800014 | Already closed. | 5712 5713**Example** 5714 5715```ts 5716import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5717import { BusinessError } from '@kit.BasicServicesKit'; 5718 5719let dmInstance: distributedDeviceManager.DeviceManager; 5720let deviceId: string | undefined = undefined; 5721 5722try { 5723 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5724 let devices = dmInstance.getAvailableDeviceListSync(); 5725 deviceId = devices[0].networkId; 5726} catch (err) { 5727 let code = (err as BusinessError).code; 5728 let message = (err as BusinessError).message 5729 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5730} 5731 5732if(store != undefined && deviceId != undefined) { 5733 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE", (err, tableName) => { 5734 if (err) { 5735 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 5736 return; 5737 } 5738 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 5739 }) 5740} 5741``` 5742 5743### obtainDistributedTableName 5744 5745 obtainDistributedTableName(device: string, table: string): Promise<string> 5746 5747Obtains the distributed table name of a remote device based on the local table name of the device. The distributed table name is required when the RDB store of a remote device is queried. 5748 5749> **NOTE** 5750> 5751> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 5752 5753**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5754 5755**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5756 5757**Parameters** 5758 5759| Name| Type | Mandatory| Description | 5760| ------ | ------ | ---- | -------------------- | 5761| device | string | Yes | ID of the remote device. | 5762| table | string | Yes | Local table name of the remote device.| 5763 5764**Return value** 5765 5766| Type | Description | 5767| --------------------- | ----------------------------------------------------- | 5768| Promise<string> | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| 5769 5770**Error codes** 5771 5772For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5773 5774| **ID**| **Error Message** | 5775|-----------| ------------------------------------------------------------ | 5776| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5777| 801 | Capability not supported. | 5778| 14800000 | Inner error. | 5779| 14800014 | Already closed. | 5780 5781**Example** 5782 5783```ts 5784import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5785import { BusinessError } from '@kit.BasicServicesKit'; 5786 5787let dmInstance: distributedDeviceManager.DeviceManager; 5788let deviceId: string | undefined = undefined; 5789 5790try { 5791 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5792 let devices = dmInstance.getAvailableDeviceListSync(); 5793 deviceId = devices[0].networkId; 5794} catch (err) { 5795 let code = (err as BusinessError).code; 5796 let message = (err as BusinessError).message 5797 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5798} 5799 5800if(store != undefined && deviceId != undefined) { 5801 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE").then((tableName: string) => { 5802 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 5803 }).catch((err: BusinessError) => { 5804 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 5805 }) 5806} 5807``` 5808 5809### sync 5810 5811sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void 5812 5813Synchronizes data between devices. This API uses an asynchronous callback to return the result. 5814 5815**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5816 5817**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5818 5819**Parameters** 5820 5821| Name | Type | Mandatory| Description | 5822| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ | 5823| mode | [SyncMode](#syncmode) | Yes | Data sync mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**. | 5824| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | 5825| callback | AsyncCallback<Array<[string, number]>> | Yes | Callback used to send the sync result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the sync status of that device. The value **0** indicates a successful sync. Other values indicate a sync failure. | 5826 5827**Error codes** 5828 5829For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5830 5831| **ID**| **Error Message** | 5832|-----------| ------------------------------------------------------------ | 5833| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5834| 801 | Capability not supported. | 5835| 14800000 | Inner error. | 5836| 14800014 | Already closed. | 5837 5838**Example** 5839 5840```ts 5841import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5842import { BusinessError } from '@kit.BasicServicesKit'; 5843 5844let dmInstance: distributedDeviceManager.DeviceManager; 5845let deviceIds: Array<string> = []; 5846 5847try { 5848 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5849 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 5850 for (let i = 0; i < devices.length; i++) { 5851 deviceIds[i] = devices[i].networkId!; 5852 } 5853} catch (err) { 5854 let code = (err as BusinessError).code; 5855 let message = (err as BusinessError).message 5856 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5857} 5858 5859let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 5860predicates.inDevices(deviceIds); 5861if(store != undefined) { 5862 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, (err, result) => { 5863 if (err) { 5864 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 5865 return; 5866 } 5867 console.info('Sync done.'); 5868 for (let i = 0; i < result.length; i++) { 5869 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 5870 } 5871 }) 5872} 5873``` 5874 5875### sync 5876 5877 sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>> 5878 5879Synchronizes data between devices. This API uses a promise to return the result. 5880 5881**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5882 5883**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5884 5885**Parameters** 5886 5887| Name | Type | Mandatory| Description | 5888| ---------- | ------------------------------------ | ---- | ------------------------------ | 5889| mode | [SyncMode](#syncmode) | Yes | Data sync mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**.| 5890| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | 5891 5892**Return value** 5893 5894| Type | Description | 5895| -------------------------------------------- | ------------------------------------------------------------ | 5896| Promise<Array<[string, number]>> | Promise used to send the sync result. <br>**string** indicates the device ID. <br>**number** indicates the sync status of that device. The value **0** indicates a successful sync. Other values indicate a sync failure. | 5897 5898**Error codes** 5899 5900For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5901 5902| **ID**| **Error Message** | 5903|-----------| ------------------------------------------------------------ | 5904| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5905| 801 | Capability not supported. | 5906| 14800000 | Inner error. | 5907| 14800014 | Already closed. | 5908 5909**Example** 5910 5911```ts 5912import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5913import { BusinessError } from '@kit.BasicServicesKit'; 5914 5915let dmInstance: distributedDeviceManager.DeviceManager; 5916let deviceIds: Array<string> = []; 5917 5918try { 5919 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5920 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 5921 for (let i = 0; i < devices.length; i++) { 5922 deviceIds[i] = devices[i].networkId!; 5923 } 5924} catch (err) { 5925 let code = (err as BusinessError).code; 5926 let message = (err as BusinessError).message 5927 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5928} 5929 5930let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 5931predicates.inDevices(deviceIds); 5932if(store != undefined) { 5933 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates).then((result: Object[][]) => { 5934 console.info('Sync done.'); 5935 for (let i = 0; i < result.length; i++) { 5936 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 5937 } 5938 }).catch((err: BusinessError) => { 5939 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 5940 }) 5941} 5942``` 5943 5944### cloudSync<sup>10+</sup> 5945 5946cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 5947 5948Manually starts device-cloud sync for all distributed tables. This API uses an asynchronous callback to return the result. Before using this API, ensure that the cloud service must be available. 5949 5950**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 5951 5952**Parameters** 5953 5954| Name | Type | Mandatory| Description | 5955| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 5956| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 5957| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details. | 5958| callback | AsyncCallback<void> | Yes | Callback used to send the sync result to the caller.| 5959 5960**Error codes** 5961 5962For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5963 5964| **ID**| **Error Message** | 5965|-----------|-------| 5966| 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 progress must be a callback type. 5. The callback must be a function. | 5967| 801 | Capability not supported. | 5968| 14800014 | Already closed. | 5969 5970**Example** 5971 5972```ts 5973if(store != undefined) { 5974 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetails) => { 5975 console.info(`Progess: ${progressDetails}`); 5976 }, (err) => { 5977 if (err) { 5978 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 5979 return; 5980 } 5981 console.info('Cloud sync succeeded'); 5982 }); 5983} 5984``` 5985 5986### cloudSync<sup>10+</sup> 5987 5988cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>): Promise<void> 5989 5990Manually starts device-cloud sync for all distributed tables. This API uses a promise to return the result. Before using this API, ensure that the cloud service must be available. 5991 5992**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 5993 5994**Parameters** 5995 5996| Name | Type | Mandatory| Description | 5997| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 5998| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 5999| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details.| 6000 6001**Return value** 6002 6003| Type | Description | 6004| ------------------- | --------------------------------------- | 6005| Promise<void> | Promise used to send the sync result.| 6006 6007**Error codes** 6008 6009For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6010 6011| **ID**| **Error Message** | 6012|-----------|------------------| 6013| 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 progress must be a callback type. | 6014| 801 | Capability not supported. | 6015| 14800014 | Already closed. | 6016 6017**Example** 6018 6019```ts 6020import { BusinessError } from '@kit.BasicServicesKit'; 6021 6022if(store != undefined) { 6023 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetail: relationalStore.ProgressDetails) => { 6024 console.info(`progress: ${progressDetail}`); 6025 }).then(() => { 6026 console.info('Cloud sync succeeded'); 6027 }).catch((err: BusinessError) => { 6028 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 6029 }); 6030} 6031``` 6032 6033### cloudSync<sup>10+</sup> 6034 6035cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 6036 6037Manually starts device-cloud sync of the specified table. This API uses an asynchronous callback to return the result. Before using this API, ensure that the cloud service must be available. 6038 6039**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6040 6041**Parameters** 6042 6043| Name | Type | Mandatory| Description | 6044| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6045| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 6046| tables | string[] | Yes | Name of the table to synchronize. | 6047| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details. | 6048| callback | AsyncCallback<void> | Yes | Callback used to send the sync result to the caller.| 6049 6050**Error codes** 6051 6052For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6053 6054| **ID**| **Error Message** | 6055|-----------|-------| 6056| 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.| 6057| 801 | Capability not supported. | 6058| 14800014 | Already closed. | 6059 6060**Example** 6061 6062```ts 6063const tables = ["table1", "table2"]; 6064 6065if(store != undefined) { 6066 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => { 6067 console.info(`Progess: ${progressDetail}`); 6068 }, (err) => { 6069 if (err) { 6070 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 6071 return; 6072 } 6073 console.info('Cloud sync succeeded'); 6074 }); 6075}; 6076``` 6077 6078### cloudSync<sup>10+</sup> 6079 6080cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>): Promise<void> 6081 6082Manually starts device-cloud sync of the specified table. This API uses a promise to return the result. Before using this API, ensure that the cloud service must be available. 6083 6084**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6085 6086**Parameters** 6087 6088| Name | Type | Mandatory| Description | 6089| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 6090| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 6091| tables | string[] | Yes | Name of the table to synchronize. | 6092| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details.| 6093 6094**Return value** 6095 6096| Type | Description | 6097| ------------------- | --------------------------------------- | 6098| Promise<void> | Promise used to send the sync result.| 6099 6100**Error codes** 6101 6102For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6103 6104| **ID**| **Error Message** | 6105|-----------|---------------| 6106| 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 | 6107| 801 | Capability not supported. | 6108| 14800014 | Already closed. | 6109 6110**Example** 6111 6112```ts 6113import { BusinessError } from '@kit.BasicServicesKit'; 6114 6115const tables = ["table1", "table2"]; 6116 6117if(store != undefined) { 6118 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => { 6119 console.info(`progress: ${progressDetail}`); 6120 }).then(() => { 6121 console.info('Cloud sync succeeded'); 6122 }).catch((err: BusinessError) => { 6123 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 6124 }); 6125}; 6126``` 6127 6128### on('dataChange') 6129 6130on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 6131 6132Subscribes to data changes of specified devices. When the data of the specified devices changes, a callback is invoked to return the data change. 6133 6134**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6135 6136**Parameters** 6137 6138| Name | Type | Mandatory| Description | 6139| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6140| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6141| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe. | 6142| observer | Callback<Array<string>> | Yes | Callback used to return the data change. Array<string> holds the IDs of the peer devices whose data is changed.| 6143 6144**Error codes** 6145 6146For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6147 6148| **ID**| **Error Message** | 6149|-----------|-------------| 6150| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6151| 801 | Capability not supported. | 6152| 14800014 | Already closed. | 6153 6154**Example** 6155 6156```ts 6157import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6158import { BusinessError } from '@kit.BasicServicesKit'; 6159 6160let storeObserver = (devices: Array<string>) => { 6161 if (devices != undefined) { 6162 for (let i = 0; i < devices.length; i++) { 6163 console.info(`device= ${devices[i]} data changed`); 6164 } 6165 } 6166} 6167 6168try { 6169 if (store != undefined) { 6170 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) 6171 } 6172} catch (err) { 6173 let code = (err as BusinessError).code; 6174 let message = (err as BusinessError).message 6175 console.error(`Register observer failed, code is ${code},message is ${message}`); 6176} 6177``` 6178 6179### on('dataChange')<sup>10+</sup> 6180 6181on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 6182 6183Subscribes to data changes of the specified devices. The registered callback will be called when data in a distributed or local RDB store changes. 6184 6185**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6186 6187**Parameters** 6188 6189| Name | Type | Mandatory| Description | 6190| -------- | ----------------------------------- | ---- | ------------------------------------------- | 6191| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6192| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe.| 6193| observer | Callback<Array<string>> \| Callback<Array<[ChangeInfo](#changeinfo10)>> | Yes | Callback used to return the data change.<br>- If **type** is **SUBSCRIBE_TYPE_REMOTE**, **observer** must be **Callback<Array<string>>**, where **Array<string>** holds the IDs of the peer devices with data changes.<br> - If **type** is **SUBSCRIBE_TYPE_CLOUD**, **observer** must be **Callback<Array<string>>**, where **Array<string>** holds the cloud accounts with data changes.<br> - If **type** is **SUBSCRIBE_TYPE_CLOUD_DETAILS**, **observer** must be **Callback<Array<ChangeInfo>>**, where **Array<ChangeInfo>** holds the details about the device-cloud sync.<br>If **type** is **SUBSCRIBE_TYPE_LOCAL_DETAILS**, **observer** must be **Callback<Array<ChangeInfo>>**, where **Array<ChangeInfo>** holds the data change details in the local RDB store.| 6194 6195**Error codes** 6196 6197For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6198 6199| **ID**| **Error Message** | 6200|-----------|-------------| 6201| 202 | Permission verification failed, application which is not a system application uses system API. | 6202| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6203| 801 | Capability not supported. | 6204| 14800014 | Already closed. | 6205 6206Example 1: **type** is **SUBSCRIBE_TYPE_REMOTE**. 6207 6208```ts 6209import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6210import { BusinessError } from '@kit.BasicServicesKit'; 6211 6212let storeObserver = (devices: Array<string>) => { 6213 if (devices != undefined) { 6214 for (let i = 0; i < devices.length; i++) { 6215 console.info(`device= ${devices[i]} data changed`); 6216 } 6217 } 6218} 6219 6220try { 6221 if(store != undefined) { 6222 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6223 } 6224} catch (err) { 6225 let code = (err as BusinessError).code; 6226 let message = (err as BusinessError).message; 6227 console.error(`Register observer failed, code is ${code},message is ${message}`); 6228} 6229``` 6230 6231Example 2: **type** is **SUBSCRIBE_TYPE_LOCAL_DETAILS**. 6232 6233```ts 6234import { BusinessError } from '@kit.BasicServicesKit'; 6235 6236let changeInfos = (changeInfos: Array<relationalStore.ChangeInfo>) => { 6237 for (let i = 0; i < changeInfos.length; i++) { 6238 console.info(`changeInfos = ${changeInfos[i]}`); 6239 } 6240} 6241 6242try { 6243 if(store != undefined) { 6244 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_LOCAL_DETAILS, changeInfos); 6245 } 6246} catch (err) { 6247 let code = (err as BusinessError).code; 6248 let message = (err as BusinessError).message; 6249 console.error(`on dataChange fail, code is ${code},message is ${message}`); 6250} 6251 6252let value1 = "Lisa"; 6253let value2 = 18; 6254let value3 = 100.5; 6255let value4 = new Uint8Array([1, 2, 3]); 6256 6257try { 6258 const valueBucket: relationalStore.ValuesBucket = { 6259 'name': value1, 6260 'age': value2, 6261 'salary': value3, 6262 'blobType': value4, 6263 }; 6264 6265 if(store != undefined) { 6266 (store as relationalStore.RdbStore).insert('test', valueBucket); 6267 } 6268} catch (err) { 6269 let code = (err as BusinessError).code; 6270 let message = (err as BusinessError).message; 6271 console.error(`insert fail, code is ${code},message is ${message}`); 6272} 6273``` 6274 6275### on<sup>10+</sup> 6276 6277on(event: string, interProcess: boolean, observer: Callback\<void>): void 6278 6279Subscribes to process events. This callback is invoked by [emit](#emit10). 6280 6281**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6282 6283**Parameters** 6284 6285| Name | Type | Mandatory| Description | 6286| ------------ | --------------- | ---- | ------------------------------------------------------------ | 6287| event | string | Yes | Event name to observe. | 6288| interProcess | boolean | Yes | Type of the data to observe.<br> The value **true** means inter-process events.<br> The value **false** means intra-process events.| 6289| observer | Callback\<void> | Yes | Callback used to return the result. | 6290 6291**Error codes** 6292 6293For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6294 6295| **ID**| **Error Message** | 6296|-----------|-------------| 6297| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6298| 801 | Capability not supported. | 6299| 14800000 | Inner error. | 6300| 14800014 | Already closed. | 6301| 14800050 | Failed to obtain the subscription service. | 6302 6303**Example** 6304 6305```ts 6306import { BusinessError } from '@kit.BasicServicesKit'; 6307 6308let storeObserver = () => { 6309 console.info(`storeObserver`); 6310} 6311 6312try { 6313 if(store != undefined) { 6314 (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver); 6315 } 6316} catch (err) { 6317 let code = (err as BusinessError).code; 6318 let message = (err as BusinessError).message 6319 console.error(`Register observer failed, code is ${code},message is ${message}`); 6320} 6321``` 6322 6323### on('autoSyncProgress')<sup>11+</sup> 6324 6325on(event: 'autoSyncProgress', progress: Callback<ProgressDetails>): void 6326 6327Subscribes to the auto sync progress. This API can be called only when device-cloud sync is enabled and the network connection is normal. When auto sync is performed, a callback will be invoked to send a notification of the sync progress. 6328 6329**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6330 6331**Parameters** 6332 6333| Name | Type | Mandatory| Description | 6334| ------------ |---------------------------------| ---- |-----------------------------------| 6335| event | string | Yes | Event type. The value is **'autoSyncProgress'**, which indicates the auto sync progress.| 6336| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to return the auto sync progress. | 6337 6338**Error codes** 6339 6340For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6341 6342| **ID**| **Error Message** | 6343|-----------|--------| 6344| 401 | Parameter error. Possible causes: 1. Need 2 - 3 parameter(s)! 2. The RdbStore must be valid. 3. The event must be a not empty string. 4. The progress must be function. | 6345| 801 | Capability not supported. | 6346| 14800014 | Already closed. | 6347 6348**Example** 6349 6350```ts 6351import { BusinessError } from '@kit.BasicServicesKit'; 6352 6353let progressDetail = (progressDetail: relationalStore.ProgressDetails) => { 6354 console.info(`progress: ${progressDetail}`); 6355} 6356 6357try { 6358 if(store != undefined) { 6359 (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail) 6360 } 6361} catch (err) { 6362 let code = (err as BusinessError).code; 6363 let message = (err as BusinessError).message 6364 console.error(`Register observer failed, code is ${code},message is ${message}`); 6365} 6366``` 6367 6368### on('statistics')<sup>12+</sup> 6369 6370on(event: 'statistics', observer: Callback<SqlExecutionInfo>): void 6371 6372Subscribes to SQL statistics. 6373 6374**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6375 6376**Parameters** 6377 6378| Name | Type | Mandatory| Description | 6379| ------------ |---------------------------------| ---- |-----------------------------------| 6380| event | string | Yes | Event type. The value is **'statistics'**, which indicates the statistics of the SQL execution time.| 6381| observer | Callback<[SqlExecutionInfo](#sqlexecutioninfo12)> | Yes | Callback used to return the statistics about the SQL execution time in the database. | 6382 6383**Error codes** 6384 6385For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6386 6387| **ID**| **Error Message** | 6388|-----------|--------| 6389| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 6390| 801 | Capability not supported. | 6391| 14800000 | Inner error. | 6392| 14800014 | Already closed. | 6393 6394**Example** 6395 6396```ts 6397import { BusinessError } from '@kit.BasicServicesKit'; 6398 6399let sqlExecutionInfo = (sqlExecutionInfo: relationalStore.SqlExecutionInfo) => { 6400 console.info(`sql: ${sqlExecutionInfo.sql[0]}`); 6401 console.info(`totalTime: ${sqlExecutionInfo.totalTime}`); 6402 console.info(`waitTime: ${sqlExecutionInfo.waitTime}`); 6403 console.info(`prepareTime: ${sqlExecutionInfo.prepareTime}`); 6404 console.info(`executeTime: ${sqlExecutionInfo.executeTime}`); 6405} 6406 6407try { 6408 if(store != undefined) { 6409 (store as relationalStore.RdbStore).on('statistics', sqlExecutionInfo); 6410 } 6411} catch (err) { 6412 let code = (err as BusinessError).code; 6413 let message = (err as BusinessError).message; 6414 console.error(`Register observer failed, code is ${code},message is ${message}`); 6415} 6416 6417try { 6418 let value1 = "Lisa"; 6419 let value2 = 18; 6420 let value3 = 100.5; 6421 let value4 = new Uint8Array([1, 2, 3, 4, 5]); 6422 6423 const valueBucket: relationalStore.ValuesBucket = { 6424 'NAME': value1, 6425 'AGE': value2, 6426 'SALARY': value3, 6427 'CODES': value4, 6428 }; 6429 if(store != undefined) { 6430 (store as relationalStore.RdbStore).insert('test', valueBucket); 6431 } 6432} catch (err) { 6433 console.error(`insert fail, code:${err.code}, message: ${err.message}`); 6434} 6435``` 6436 6437### off('dataChange') 6438 6439off(event:'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 6440 6441Unsubscribes from data changes of the specified devices. 6442 6443**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6444 6445**Parameters** 6446 6447| Name | Type | Mandatory| Description | 6448| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6449| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6450| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe. | 6451| observer | Callback<Array<string>> | Yes | Callback to unregister. **Array<string>** holds the IDs of the peer devices whose data is changed.| 6452 6453**Error codes** 6454 6455For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6456 6457| **ID**| **Error Message** | 6458|-----------|-------------| 6459| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6460| 801 | Capability not supported. | 6461| 14800014 | Already closed. | 6462 6463**Example** 6464 6465```ts 6466import { BusinessError } from '@kit.BasicServicesKit'; 6467 6468let storeObserver = (devices: Array<string>) => { 6469 if (devices != undefined) { 6470 for (let i = 0; i < devices.length; i++) { 6471 console.info(`device= ${devices[i]} data changed`); 6472 } 6473 } 6474} 6475 6476try { 6477 if (store != undefined) { 6478 // The Lambda expression cannot be used here. 6479 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) 6480 } 6481} catch (err) { 6482 let code = (err as BusinessError).code; 6483 let message = (err as BusinessError).message 6484 console.error(`Register observer failed, code is ${code},message is ${message}`); 6485} 6486 6487try { 6488 if(store != undefined) { 6489 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6490 } 6491} catch (err) { 6492 let code = (err as BusinessError).code; 6493 let message = (err as BusinessError).message 6494 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6495} 6496``` 6497 6498### off('dataChange')<sup>10+</sup> 6499 6500off(event:'dataChange', type: SubscribeType, observer?: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 6501 6502Unsubscribes from data changes of this RDB store. 6503 6504**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6505 6506**Parameters** 6507 6508| Name | Type | Mandatory| Description | 6509| -------- | ---------------------------------- | ---- | ------------------------------------------ | 6510| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6511| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe. | 6512| observer | Callback<Array<string>>\| Callback<Array<[ChangeInfo](#changeinfo10)>> | No| Callback to unregister.<br>- If **type** is **SUBSCRIBE_TYPE_REMOTE**, **observer** must be **Callback<Array<string>>**, where **Array<string>** holds the IDs of the peer devices with data changes.<br> - If **type** is **SUBSCRIBE_TYPE_CLOUD**, **observer** must be **Callback<Array<string>>**, where **Array<string>** holds the cloud accounts with data changes.<br> - If **type** is **SUBSCRIBE_TYPE_CLOUD_DETAILS**, **observer** must be **Callback<Array<ChangeInfo>>**, where **Array<ChangeInfo>** holds the details about the device-cloud sync.<br>- If **type** is **SUBSCRIBE_TYPE_LOCAL_DETAILS**, **observer** must be **Callback<Array<ChangeInfo>>**, where **Array<ChangeInfo>** holds the data change details in the local RDB store.<br> If **observer** is not specified, this API unregisters all callbacks for data changes of the specified **type**.| 6513 6514**Error codes** 6515 6516For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6517 6518| **ID**| **Error Message** | 6519|-----------|-------------| 6520| 202 | Permission verification failed, application which is not a system application uses system API. | 6521| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6522| 801 | Capability not supported. | 6523| 14800014 | Already closed. | 6524 6525**Example** 6526 6527```ts 6528import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6529import { BusinessError } from '@kit.BasicServicesKit'; 6530 6531let storeObserver = (devices: Array<string>) => { 6532 if (devices != undefined) { 6533 for (let i = 0; i < devices.length; i++) { 6534 console.info(`device= ${devices[i]} data changed`); 6535 } 6536 } 6537} 6538 6539try { 6540 if(store != undefined) { 6541 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6542 } 6543} catch (err) { 6544 let code = (err as BusinessError).code; 6545 let message = (err as BusinessError).message; 6546 console.error(`Register observer failed, code is ${code},message is ${message}`); 6547} 6548 6549try { 6550 if(store != undefined) { 6551 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6552 } 6553} catch (err) { 6554 let code = (err as BusinessError).code; 6555 let message = (err as BusinessError).message 6556 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6557} 6558``` 6559 6560### off<sup>10+</sup> 6561 6562off(event: string, interProcess: boolean, observer?: Callback\<void>): void 6563 6564Unsubscribes from process events. 6565 6566**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6567 6568**Parameters** 6569 6570| Name | Type | Mandatory| Description | 6571| ------------ | --------------- | ---- | ------------------------------------------------------------ | 6572| event | string | Yes | Name of the event. | 6573| interProcess | boolean | Yes | Type of the data to observe.<br> The value **true** means inter-process events.<br> The value **false** means intra-process events.| 6574| observer | Callback\<void> | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 6575 6576**Error codes** 6577 6578For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6579 6580| **ID**| **Error Message** | 6581| ------------ | -------------------------------------- | 6582| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6583| 801 | Capability not supported. | 6584| 14800000 | Inner error. | 6585| 14800014 | Already closed. | 6586| 14800050 | Failed to obtain the subscription service. | 6587 6588**Example** 6589 6590```ts 6591import { BusinessError } from '@kit.BasicServicesKit'; 6592 6593let storeObserver = () => { 6594 console.info(`storeObserver`); 6595} 6596 6597try { 6598 if(store != undefined) { 6599 (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver); 6600 } 6601} catch (err) { 6602 let code = (err as BusinessError).code; 6603 let message = (err as BusinessError).message 6604 console.error(`Register observer failed, code is ${code},message is ${message}`); 6605} 6606 6607try { 6608 if(store != undefined) { 6609 (store as relationalStore.RdbStore).off('storeObserver', false, storeObserver); 6610 } 6611} catch (err) { 6612 let code = (err as BusinessError).code; 6613 let message = (err as BusinessError).message 6614 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6615} 6616``` 6617 6618### off('autoSyncProgress')<sup>11+</sup> 6619 6620off(event: 'autoSyncProgress', progress?: Callback<ProgressDetails>): void 6621 6622Unsubscribes from the auto sync progress. 6623 6624**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6625 6626**Parameters** 6627 6628| Name | Type | Mandatory| Description | 6629| ------------ |---------------------------------| ---- |------------------------------------------------------------------| 6630| event | string | Yes | Event type. The value is **'autoSyncProgress'**, which indicates the auto sync progress. | 6631| progress | Callback<[ProgressDetails](#progressdetails10)> | No | Callback to unregister. If this parameter is **null** or **undefined** or not specified, this API unregisters all callbacks for the auto sync progress.| 6632 6633**Error codes** 6634 6635For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6636 6637| **ID**| **Error Message** | 6638| ------------ |--------------------| 6639| 401 | Parameter error. Possible causes: 1. Need 1 - 3 parameter(s)! 2. The RdbStore must be valid. 3. The event must be a not empty string. 4. The progress must be function. | 6640| 801 | Capability not supported. | 6641| 14800014 | Already closed. | 6642 6643**Example** 6644 6645```ts 6646import { BusinessError } from '@kit.BasicServicesKit'; 6647 6648let progressDetail = (progressDetail: relationalStore.ProgressDetails) => { 6649 console.info(`progress: ${progressDetail}`); 6650} 6651 6652try { 6653 if(store != undefined) { 6654 (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail) 6655 } 6656} catch (err) { 6657 let code = (err as BusinessError).code; 6658 let message = (err as BusinessError).message 6659 console.error(`Register observer failed, code is ${code},message is ${message}`); 6660} 6661 6662try { 6663 if(store != undefined) { 6664 (store as relationalStore.RdbStore).off('autoSyncProgress', progressDetail); 6665 } 6666} catch (err) { 6667 let code = (err as BusinessError).code; 6668 let message = (err as BusinessError).message; 6669 console.error(`Unregister failed, code is ${code},message is ${message}`); 6670} 6671``` 6672 6673### off('statistics')<sup>12+</sup> 6674 6675off(event: 'statistics', observer?: Callback<SqlExecutionInfo>): void 6676 6677Unsubscribes from SQL statistics. 6678 6679**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6680 6681**Parameters** 6682 6683| Name | Type | Mandatory| Description | 6684| ------------ |---------------------------------| ---- |-----------------------------------| 6685| event | string | Yes | Event type. The value is **'statistics'**, which indicates the statistics of the SQL execution time.| 6686| observer | Callback<[SqlExecutionInfo](#sqlexecutioninfo12)> | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 6687 6688 6689**Error codes** 6690 6691For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6692 6693| **ID**| **Error Message** | 6694|-----------|--------| 6695| 401 | Parameter error. | 6696| 801 | Capability not supported. | 6697| 14800000 | Inner error. | 6698| 14800014 | Already closed. | 6699 6700```ts 6701import { BusinessError } from '@kit.BasicServicesKit'; 6702 6703try { 6704 if(store != undefined) { 6705 (store as relationalStore.RdbStore).off('statistics'); 6706 } 6707} catch (err) { 6708 let code = (err as BusinessError).code; 6709 let message = (err as BusinessError).message; 6710 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6711} 6712``` 6713 6714### emit<sup>10+</sup> 6715 6716emit(event: string): void 6717 6718Triggers the inter-process or intra-process event listener registered in [on](#on10). 6719 6720**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6721 6722**Parameters** 6723 6724| Name| Type | Mandatory| Description | 6725| ------ | ------ | ---- | -------------------- | 6726| event | string | Yes | Name of the event.| 6727 6728**Error codes** 6729 6730For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6731 6732| **ID**| **Error Message** | 6733| --------- |---------------------------------------------------------------------------------------------------------------| 6734| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6735| 801 | Capability not supported. | 6736| 14800000 | Inner error. | 6737| 14800014 | Already closed. | 6738| 14800050 | Failed to obtain the subscription service. | 6739 6740 6741**Example** 6742 6743```ts 6744if(store != undefined) { 6745 (store as relationalStore.RdbStore).emit('storeObserver'); 6746} 6747``` 6748 6749### cleanDirtyData<sup>11+</sup> 6750 6751cleanDirtyData(table: string, cursor: number, callback: AsyncCallback<void>): void 6752 6753Clears the dirty data whose cursor is smaller than the specified cursor from the local device. The dirty data is the data that has been deleted from the cloud. 6754 6755**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6756 6757**Parameters** 6758 6759| Name | Type | Mandatory| Description | 6760| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6761| table | string | Yes | Name of the table in the RDB store. | 6762| cursor | number | Yes | Cursor of the data, which is an integer. All the dirty data with the cursor smaller than the specified value will be cleared. | 6763| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 6764 6765**Error codes** 6766 6767For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 6768 6769| **ID**| **Error Message** | 6770|-----------|---------------| 6771| 401 | Parameter error. Possible causes: 1. Need 1 - 3 parameter(s)! 2. The RdbStore must be not nullptr. 3. The tablesNames must be not empty string. 4. The cursor must be valid cursor. | 6772| 801 | Capability not supported. | 6773| 14800000 | Inner error. | 6774| 14800011 | Database corrupted. | 6775| 14800014 | Already closed. | 6776| 14800015 | The database does not respond. | 6777| 14800021 | SQLite: Generic error. | 6778| 14800022 | SQLite: Callback routine requested an abort. | 6779| 14800023 | SQLite: Access permission denied. | 6780| 14800024 | SQLite: The database file is locked. | 6781| 14800025 | SQLite: A table in the database is locked. | 6782| 14800026 | SQLite: The database is out of memory. | 6783| 14800027 | SQLite: Attempt to write a readonly database. | 6784| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6785| 14800029 | SQLite: The database is full. | 6786| 14800030 | SQLite: Unable to open the database file. | 6787| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6788| 14800032 | SQLite: Abort due to constraint violation. | 6789| 14800033 | SQLite: Data type mismatch. | 6790| 14800034 | SQLite: Library used incorrectly. | 6791 6792**Example** 6793 6794```ts 6795if(store != undefined) { 6796 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100, (err) => { 6797 if (err) { 6798 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 6799 return; 6800 } 6801 console.info('clean dirty data succeeded'); 6802 }) 6803} 6804``` 6805 6806### cleanDirtyData<sup>11+</sup> 6807 6808cleanDirtyData(table: string, callback: AsyncCallback<void>): void 6809 6810Clears all dirty data from the local device. The dirty data is the data that has been deleted from the cloud. 6811 6812**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6813 6814**Parameters** 6815 6816| Name | Type | Mandatory| Description | 6817| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6818| table | string | Yes | Name of the table in the RDB store.| 6819| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 6820 6821**Error codes** 6822 6823For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 6824 6825| **ID**| **Error Message** | 6826|-----------|---------| 6827| 401 | Parameter error. Possible causes: 1. Need 1 - 3 parameter(s). 2. The RdbStore must be not nullptr. 3. The tablesNames must be not empty string. | 6828| 801 | Capability not supported. | 6829| 14800000 | Inner error. | 6830| 14800011 | Database corrupted. | 6831| 14800014 | Already closed. | 6832| 14800015 | The database does not respond. | 6833| 14800021 | SQLite: Generic error. | 6834| 14800022 | SQLite: Callback routine requested an abort. | 6835| 14800023 | SQLite: Access permission denied. | 6836| 14800024 | SQLite: The database file is locked. | 6837| 14800025 | SQLite: A table in the database is locked. | 6838| 14800026 | SQLite: The database is out of memory. | 6839| 14800027 | SQLite: Attempt to write a readonly database. | 6840| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6841| 14800029 | SQLite: The database is full. | 6842| 14800030 | SQLite: Unable to open the database file. | 6843| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6844| 14800032 | SQLite: Abort due to constraint violation. | 6845| 14800033 | SQLite: Data type mismatch. | 6846| 14800034 | SQLite: Library used incorrectly. | 6847 6848**Example** 6849 6850```ts 6851if(store != undefined) { 6852 (store as relationalStore.RdbStore).cleanDirtyData('test_table', (err) => { 6853 if (err) { 6854 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 6855 return; 6856 } 6857 console.info('clean dirty data succeeded'); 6858 }) 6859} 6860``` 6861 6862### cleanDirtyData<sup>11+</sup> 6863 6864cleanDirtyData(table: string, cursor?: number): Promise<void> 6865 6866Clears the dirty data whose cursor is smaller than the specified cursor from the local device. The dirty data is the data that has been deleted from the cloud. If **cursor** is not specified, all the dirty data will be cleared. 6867 6868**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6869 6870**Parameters** 6871 6872| Name | Type | Mandatory| Description | 6873| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6874| table | string | Yes | Name of the table in the RDB store. | 6875| cursor | number | No | Cursor of the data, which is an integer. All the dirty data with the cursor smaller than the specified value will be cleared. If this parameter is not specified, all dirty data in the current table will be cleared.| 6876 6877**Return value** 6878| Name | Description | 6879| -------- | ------------------------------------------------- | 6880| Promise\<void> | Promise that returns no value. | 6881 6882**Error codes** 6883 6884For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 6885 6886| **ID**| **Error Message** | 6887|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 6888| 401 | Parameter error. Possible causes: 1. Need 1 - 3 parameter(s)! 2. The RdbStore must be not nullptr. 3. The tablesNames must be not empty string. 4. The cursor must be valid cursor. | 6889| 801 | Capability not supported. | 6890| 14800000 | Inner error. | 6891| 14800011 | Database corrupted. | 6892| 14800014 | Already closed. | 6893| 14800015 | The database does not respond. | 6894| 14800021 | SQLite: Generic error. | 6895| 14800022 | SQLite: Callback routine requested an abort. | 6896| 14800023 | SQLite: Access permission denied. | 6897| 14800024 | SQLite: The database file is locked. | 6898| 14800025 | SQLite: A table in the database is locked. | 6899| 14800026 | SQLite: The database is out of memory. | 6900| 14800027 | SQLite: Attempt to write a readonly database. | 6901| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6902| 14800029 | SQLite: The database is full. | 6903| 14800030 | SQLite: Unable to open the database file. | 6904| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6905| 14800032 | SQLite: Abort due to constraint violation. | 6906| 14800033 | SQLite: Data type mismatch. | 6907| 14800034 | SQLite: Library used incorrectly. | 6908 6909**Example** 6910 6911```ts 6912import { BusinessError } from '@kit.BasicServicesKit'; 6913 6914if(store != undefined) { 6915 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100).then(() => { 6916 console.info('clean dirty data succeeded'); 6917 }).catch ((err: BusinessError) => { 6918 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 6919 }) 6920} 6921``` 6922 6923### attach<sup>12+</sup> 6924 6925attach(fullPath: string, attachName: string, waitTime?: number) : Promise<number> 6926 6927Attaches an RDB store to this RDB store so that the data in the attached RDB store can be directly accessed using the SQL statement. 6928 6929The RDB store is attached via a database file. This API cannot be used for encrypted RDB stores. After the **attach()** API is called, the RDB store is switched to the non-WAL mode, which may affect the performance. 6930 6931Before the RDB store is switched to the non-WAL mode, ensure that all **ResultSet**s are closed and all write operations are complete. Otherwise, error 14800015 will be reported. 6932 6933The **attach()** API cannot be called concurrently. Concurrent calls may cause the system to become unresponsive and trigger 14800015. If this occurs, try to call **attach()** again later. 6934 6935**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6936 6937**Parameters** 6938 6939| Name | Type | Mandatory | Description | 6940| ----------- | ------ | --- | ------------ | 6941| fullPath | string | Yes | Path of the database file to attach.| 6942| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 6943| waitTime | number | No | Maximum time period (in seconds) allowed for attaching the database file. <br>Value range: 1 to 300<br>Default value: 2| 6944 6945**Return value** 6946 6947| Type | Description | 6948| ---------------- | ---------------------------- | 6949| Promise<number> | Promise used to return the number of attached RDB stores.| 6950 6951**Error codes** 6952 6953For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 6954 6955| **ID**| **Error Message** | 6956|-----------| ------------------------------------------------------------ | 6957| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6958| 801 | Capability not supported. | 6959| 14800000 | Inner error. | 6960| 14800010 | Invalid database path. | 6961| 14800011 | Database corrupted. | 6962| 14800014 | Already closed. | 6963| 14800015 | The database does not respond. | 6964| 14800016 | The database alias already exists. | 6965| 14800021 | SQLite: Generic error. | 6966| 14800022 | SQLite: Callback routine requested an abort. | 6967| 14800023 | SQLite: Access permission denied. | 6968| 14800024 | SQLite: The database file is locked. | 6969| 14800025 | SQLite: A table in the database is locked. | 6970| 14800026 | SQLite: The database is out of memory. | 6971| 14800027 | SQLite: Attempt to write a readonly database. | 6972| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6973| 14800029 | SQLite: The database is full. | 6974| 14800030 | SQLite: Unable to open the database file. | 6975| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6976| 14800032 | SQLite: Abort due to constraint violation. | 6977| 14800033 | SQLite: Data type mismatch. | 6978| 14800034 | SQLite: Library used incorrectly. | 6979 6980**Example** 6981 6982```ts 6983// Attach a non-encrypted RDB store to a non-encrypted RDB store. 6984import { BusinessError } from '@kit.BasicServicesKit'; 6985 6986if(store != undefined) { 6987 (store as relationalStore.RdbStore).attach("/path/rdbstore1.db", "attachDB").then((number: number) => { 6988 console.info('attach succeeded'); 6989 }).catch ((err: BusinessError) => { 6990 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 6991 }) 6992} 6993``` 6994 6995### attach<sup>12+</sup> 6996 6997attach(context: Context, config: StoreConfig, attachName: string, waitTime?: number) : Promise<number> 6998 6999Attaches an RDB store to this RDB store so that the data in the attached RDB store can be directly accessed using the SQL statement. 7000 7001This API cannot be used to attach a non-encrypted RDB store to an encrypted RDB store. After the **attach()** API is called, the RDB store is switched to non-WAL mode, which may affect the performance. 7002 7003Before the RDB store is switched to non-WAL mode, ensure that all **ResultSet**s are closed and all write operations are complete. Otherwise, error 14800015 will be reported. 7004 7005The **attach()** API cannot be called concurrently. Concurrent calls may cause the system to become unresponsive and trigger 14800015. If this occurs, try to call **attach()** again later. In addition, when an encrypted database is attached, the database may fail to be decrypted due to concurrency and error 14800011 is reported. In this case, explicitly specify encryption parameters and try again. 7006 7007**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7008 7009**Parameters** 7010 7011| Name | Type | Mandatory | Description | 7012| ----------- | ------ | --- | ------------ | 7013| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).| 7014| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store to attach. | 7015| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 7016| waitTime | number | No | Maximum time period (in seconds) allowed for attaching the database file. <br>Value range: 1 to 300<br>Default value: 2| 7017 7018**Return value** 7019 7020| Type | Description | 7021| ---------------- | ---------------------------- | 7022| Promise<number> | Promise used to return the number of attached RDB stores.| 7023 7024**Error codes** 7025 7026For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7027 7028| **ID**| **Error Message** | 7029|-----------| ------------------------------------------------------------ | 7030| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7031| 801 | Capability not supported. | 7032| 14800000 | Inner error. | 7033| 14800010 | Invalid database path. | 7034| 14800011 | Database corrupted. | 7035| 14800014 | Already closed. | 7036| 14800015 | The database does not respond. | 7037| 14800016 | The database alias already exists. | 7038| 14801001 | The operation is supported in the stage model only. | 7039| 14801002 | Invalid data group ID. | 7040| 14800021 | SQLite: Generic error. | 7041| 14800022 | SQLite: Callback routine requested an abort. | 7042| 14800023 | SQLite: Access permission denied. | 7043| 14800024 | SQLite: The database file is locked. | 7044| 14800025 | SQLite: A table in the database is locked. | 7045| 14800026 | SQLite: The database is out of memory. | 7046| 14800027 | SQLite: Attempt to write a readonly database. | 7047| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7048| 14800029 | SQLite: The database is full. | 7049| 14800030 | SQLite: Unable to open the database file. | 7050| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7051| 14800032 | SQLite: Abort due to constraint violation. | 7052| 14800033 | SQLite: Data type mismatch. | 7053| 14800034 | SQLite: Library used incorrectly. | 7054 7055Example 1: Attach a non-encrypted RDB store to a non-encrypted RDB store. 7056 7057```ts 7058import { BusinessError } from '@kit.BasicServicesKit'; 7059 7060let attachStore: relationalStore.RdbStore | undefined = undefined; 7061 7062const STORE_CONFIG1: relationalStore.StoreConfig = { 7063 name: "rdbstore1.db", 7064 securityLevel: relationalStore.SecurityLevel.S3, 7065} 7066 7067relationalStore.getRdbStore(this.context, STORE_CONFIG1).then(async (rdbStore: relationalStore.RdbStore) => { 7068 attachStore = rdbStore; 7069 console.info('Get RdbStore successfully.') 7070}).catch((err: BusinessError) => { 7071 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 7072}) 7073 7074if(store != undefined) { 7075 (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG1, "attachDB").then((number: number) => { 7076 console.info(`attach succeeded, number is ${number}`); 7077 }).catch ((err: BusinessError) => { 7078 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 7079 }) 7080} 7081``` 7082 7083Example 2: Attach an encrypted RDB store to a non-encrypted RDB store. 7084 7085```ts 7086import { BusinessError } from '@kit.BasicServicesKit'; 7087 7088let attachStore: relationalStore.RdbStore | undefined = undefined; 7089 7090 7091const STORE_CONFIG2: relationalStore.StoreConfig = { 7092 name: "rdbstore2.db", 7093 encrypt: true, 7094 securityLevel: relationalStore.SecurityLevel.S3, 7095} 7096 7097relationalStore.getRdbStore(this.context, STORE_CONFIG2).then(async (rdbStore: relationalStore.RdbStore) => { 7098 attachStore = rdbStore; 7099 console.info('Get RdbStore successfully.') 7100}).catch((err: BusinessError) => { 7101 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 7102}) 7103 7104if(store != undefined) { 7105 (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG2, "attachDB2", 10).then((number: number) => { 7106 console.info(`attach succeeded, number is ${number}`); 7107 }).catch ((err: BusinessError) => { 7108 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 7109 }) 7110} 7111``` 7112 7113### detach<sup>12+</sup> 7114 7115detach(attachName: string, waitTime?: number) : Promise<number> 7116 7117Detaches an RDB store from this RDB store. 7118 7119After all attached RDB stores are detached, the RDB is switched to the WAL mode. 7120 7121Before calling **detach()**, ensure that all database operations are complete and all **ResultSet**s are closed. In addition, **detach()** cannot be called concurrently. Concurrent calls may cause the system to become unresponsive. If this occurs, try to call **detach()** again later. 7122 7123**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7124 7125**Parameters** 7126 7127| Name | Type | Mandatory | Description | 7128| ----------- | ------ | --- | ------------ | 7129| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 7130| waitTime | number | No | Maximum time period (in seconds) allowed for detaching the RDB store. <br>Value range: 1 to 300<br>Default value: 2| 7131 7132**Return value** 7133 7134| Type | Description | 7135| ---------------- | ---------------------------- | 7136| Promise<number> | Promise used to return the number of remaining attached RDB stores.| 7137 7138**Error codes** 7139 7140For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7141 7142| **ID**| **Error Message** | 7143|-----------|------------------------| 7144| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7145| 14800000 | Inner error. | 7146| 14800011 | Database corrupted. | 7147| 14800014 | Already closed. | 7148| 14800015 | The database does not respond. | 7149| 14800021 | SQLite: Generic error. | 7150| 14800022 | SQLite: Callback routine requested an abort. | 7151| 14800023 | SQLite: Access permission denied. | 7152| 14800024 | SQLite: The database file is locked. | 7153| 14800025 | SQLite: A table in the database is locked. | 7154| 14800026 | SQLite: The database is out of memory. | 7155| 14800027 | SQLite: Attempt to write a readonly database. | 7156| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7157| 14800029 | SQLite: The database is full. | 7158| 14800030 | SQLite: Unable to open the database file. | 7159| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7160| 14800032 | SQLite: Abort due to constraint violation. | 7161| 14800033 | SQLite: Data type mismatch. | 7162| 14800034 | SQLite: Library used incorrectly. | 7163 7164**Example** 7165 7166```ts 7167import { BusinessError } from '@kit.BasicServicesKit'; 7168 7169if(store != undefined) { 7170 (store as relationalStore.RdbStore).detach("attachDB").then((number: number) => { 7171 console.info(`detach succeeded, number is ${number}`); 7172 }).catch ((err: BusinessError) => { 7173 console.error(`detach failed, code is ${err.code},message is ${err.message}`); 7174 }) 7175} 7176``` 7177 7178### lockRow<sup>12+</sup> 7179 7180lockRow(predicates: RdbPredicates):Promise<void> 7181 7182Locks data in this RDB store. This API uses a promise to return the result. The locked data is blocked from device-cloud sync. 7183 7184This API supports only the tables with the primary keys of the basic types. It is not available to shared tables, tables without primary keys, or tables with primary keys of composite types. 7185This API does not support lock transfer between tables with dependencies. If this table has dependent tables, you need to call this API for the related tables based on the dependency relationships. 7186This API cannot be used for deleted data. 7187 7188**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7189 7190**Parameters** 7191 7192| Name | Type | Mandatory| Description | 7193| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 7194| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions for locking data.| 7195 7196**Return value** 7197 7198| Type | Description | 7199| --------------------- | ------------------------------- | 7200| Promise<void> | Promise that returns no value. | 7201 7202**Error codes** 7203 7204For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7205 7206| **ID**| **Error Message** | 7207|-----------|----------------------------------------------------------------------------------------------| 7208| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7209| 14800000 | Inner error. | 7210| 14800011 | Database corrupted. | 7211| 14800014 | Already closed. | 7212| 14800015 | The database does not respond. | 7213| 14800018 | No data meets the condition. | 7214| 14800021 | SQLite: Generic error. | 7215| 14800022 | SQLite: Callback routine requested an abort. | 7216| 14800023 | SQLite: Access permission denied. | 7217| 14800024 | SQLite: The database file is locked. | 7218| 14800025 | SQLite: A table in the database is locked. | 7219| 14800026 | SQLite: The database is out of memory. | 7220| 14800027 | SQLite: Attempt to write a readonly database. | 7221| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7222| 14800029 | SQLite: The database is full. | 7223| 14800030 | SQLite: Unable to open the database file. | 7224| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7225| 14800032 | SQLite: Abort due to constraint violation. | 7226| 14800033 | SQLite: Data type mismatch. | 7227| 14800034 | SQLite: Library used incorrectly. | 7228 7229**Example** 7230 7231```ts 7232import { BusinessError } from '@kit.BasicServicesKit'; 7233 7234let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7235predicates.equalTo("NAME", "Lisa"); 7236if(store != undefined) { 7237 (store as relationalStore.RdbStore).lockRow(predicates).then(() => { 7238 console.info(`Lock success`); 7239 }).catch((err: BusinessError) => { 7240 console.error(`Lock failed, code is ${err.code},message is ${err.message}`); 7241 }) 7242} 7243``` 7244 7245### unlockRow<sup>12+</sup> 7246 7247unlockRow(predicates: RdbPredicates):Promise<void> 7248 7249Unlocks data in this RDB store. This API uses a promise to return the result. 7250 7251This API supports only the tables with the primary keys of the basic types. It is not available to shared tables, tables without primary keys, or tables with primary keys of composite types. 7252This API does not support lock transfer between tables with dependencies. If this table has dependent tables, you need to call this API for the related tables based on the dependency relationships. 7253This API cannot be used for deleted data. 7254 7255**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7256 7257**Parameters** 7258 7259| Name | Type | Mandatory| Description | 7260| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 7261| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions for unlocking data.| 7262 7263**Return value** 7264 7265| Type | Description | 7266| --------------------- | ------------------------------- | 7267| Promise<void> | Promise that returns no value. | 7268 7269**Error codes** 7270 7271For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7272 7273| **ID**| **Error Message** | 7274|-----------| ------------------------------------------------------------ | 7275| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7276| 14800000 | Inner error. | 7277| 14800011 | Database corrupted. | 7278| 14800014 | Already closed. | 7279| 14800015 | The database does not respond. | 7280| 14800018 | No data meets the condition. | 7281| 14800021 | SQLite: Generic error. | 7282| 14800022 | SQLite: Callback routine requested an abort. | 7283| 14800023 | SQLite: Access permission denied. | 7284| 14800024 | SQLite: The database file is locked. | 7285| 14800025 | SQLite: A table in the database is locked. | 7286| 14800026 | SQLite: The database is out of memory. | 7287| 14800027 | SQLite: Attempt to write a readonly database. | 7288| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7289| 14800029 | SQLite: The database is full. | 7290| 14800030 | SQLite: Unable to open the database file. | 7291| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7292| 14800032 | SQLite: Abort due to constraint violation. | 7293| 14800033 | SQLite: Data type mismatch. | 7294| 14800034 | SQLite: Library used incorrectly. | 7295 7296**Example** 7297 7298```ts 7299import { BusinessError } from '@kit.BasicServicesKit'; 7300 7301let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7302predicates.equalTo("NAME", "Lisa"); 7303if(store != undefined) { 7304 (store as relationalStore.RdbStore).unlockRow(predicates).then(() => { 7305 console.info(`Unlock success`); 7306 }).catch((err: BusinessError) => { 7307 console.error(`Unlock failed, code is ${err.code},message is ${err.message}`); 7308 }) 7309} 7310``` 7311 7312### queryLockedRow<sup>12+</sup> 7313 7314queryLockedRow(predicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> 7315 7316Queries the locked data in this RDB store. This API uses a promise to return the result. 7317Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 7318 7319**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7320 7321**Parameters** 7322 7323| Name | Type | Mandatory| Description | 7324| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 7325| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 7326| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 7327 7328**Error codes** 7329 7330For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7331 7332| **ID**| **Error Message** | 7333|-----------| ------------------------------------------------------------ | 7334| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7335| 14800000 | Inner error. | 7336| 14800011 | Database corrupted. | 7337| 14800014 | Already closed. | 7338| 14800015 | The database does not respond. | 7339| 14800021 | SQLite: Generic error. | 7340| 14800022 | SQLite: Callback routine requested an abort. | 7341| 14800023 | SQLite: Access permission denied. | 7342| 14800024 | SQLite: The database file is locked. | 7343| 14800025 | SQLite: A table in the database is locked. | 7344| 14800026 | SQLite: The database is out of memory. | 7345| 14800027 | SQLite: Attempt to write a readonly database. | 7346| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7347| 14800029 | SQLite: The database is full. | 7348| 14800030 | SQLite: Unable to open the database file. | 7349| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7350| 14800032 | SQLite: Abort due to constraint violation. | 7351| 14800033 | SQLite: Data type mismatch. | 7352| 14800034 | SQLite: Library used incorrectly. | 7353 7354**Return value** 7355 7356| Type | Description | 7357| ------------------------------------------------------- | -------------------------------------------------- | 7358| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 7359 7360**Example** 7361 7362```ts 7363import { BusinessError } from '@kit.BasicServicesKit'; 7364 7365let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7366predicates.equalTo("NAME", "Rose"); 7367if(store != undefined) { 7368 (store as relationalStore.RdbStore).queryLockedRow(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 7369 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 7370 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 7371 while (resultSet.goToNextRow()) { 7372 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 7373 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 7374 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 7375 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 7376 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 7377 } 7378 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 7379 resultSet.close(); 7380 }).catch((err: BusinessError) => { 7381 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 7382 }) 7383} 7384``` 7385### close<sup>12+</sup> 7386 7387close(): Promise<void> 7388 7389Closes this RDB store. This API uses a promise to return the result. 7390 7391**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7392 7393**Return value** 7394 7395| Type | Description | 7396| ------------------- | ------------- | 7397| Promise<void> | Promise used to| 7398 7399**Error codes** 7400 7401For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 7402 7403| **ID**| **Error Message** | 7404| ------------ | ----------------------------------------------- | 7405| 401 | Parameter error. The store must not be nullptr. | 7406| 14800000 | Inner error. | 7407 7408**Example** 7409 7410```ts 7411import { BusinessError } from '@kit.BasicServicesKit'; 7412 7413if(store != undefined) { 7414 (store as relationalStore.RdbStore).close().then(() => { 7415 console.info(`close succeeded`); 7416 }).catch ((err: BusinessError) => { 7417 console.error(`close failed, code is ${err.code},message is ${err.message}`); 7418 }) 7419} 7420``` 7421 7422## ResultSet 7423 7424Provides APIs to access the **resultSet** object returned by **query()**. 7425 7426### Usage 7427 7428Obtain the **resultSet** object first. 7429 7430**Example** 7431 7432<!--code_no_check--> 7433```ts 7434import { UIAbility } from '@kit.AbilityKit'; 7435import { BusinessError } from '@kit.BasicServicesKit'; 7436import { window } from '@kit.ArkUI'; 7437 7438let store: relationalStore.RdbStore | undefined = undefined; 7439 7440class EntryAbility extends UIAbility { 7441 onWindowStageCreate(windowStage: window.WindowStage) { 7442 const STORE_CONFIG: relationalStore.StoreConfig = { 7443 name: "RdbTest.db", 7444 securityLevel: relationalStore.SecurityLevel.S3, 7445 }; 7446 7447 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 7448 store = rdbStore; 7449 console.info('Get RdbStore successfully.') 7450 }).catch((err: BusinessError) => { 7451 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 7452 }) 7453 7454 let resultSet: relationalStore.ResultSet | undefined = undefined; 7455 let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7456 predicates.equalTo("AGE", 18); 7457 if(store != undefined) { 7458 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((result: relationalStore.ResultSet) => { 7459 resultSet = result; 7460 console.info(`resultSet columnNames: ${resultSet.columnNames}`); 7461 console.info(`resultSet columnCount: ${resultSet.columnCount}`); 7462 }); 7463 } 7464 } 7465} 7466``` 7467 7468### Properties 7469 7470**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7471 7472| Name | Type | Mandatory| Description | 7473| ------------ | ------------------- | ---- | -------------------------------- | 7474| columnNames | Array<string> | Yes | Names of all columns in the result set. | 7475| columnCount | number | Yes | Number of columns in the result set. | 7476| rowCount | number | Yes | Number of rows in the result set. | 7477| rowIndex | number | Yes | Index of the current row in the result set. | 7478| isAtFirstRow | boolean | Yes | Whether the cursor is in the first row of the result set. | 7479| isAtLastRow | boolean | Yes | Whether the cursor is in the last row of the result set. | 7480| isEnded | boolean | Yes | Whether the cursor is after the last row of the result set.| 7481| isStarted | boolean | Yes | Whether the cursor has been moved. | 7482| isClosed | boolean | Yes | Whether the result set is closed. | 7483 7484### getColumnIndex 7485 7486getColumnIndex(columnName: string): number 7487 7488Obtains the column index based on the column name. 7489 7490**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7491 7492**Parameters** 7493 7494| Name | Type | Mandatory| Description | 7495| ---------- | ------ | ---- | -------------------------- | 7496| columnName | string | Yes | Column name.| 7497 7498**Return value** 7499 7500| Type | Description | 7501| ------ | ------------------ | 7502| number | Column index obtained.| 7503 7504**Error codes** 7505 7506For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7507 7508| **ID**| **Error Message** | 7509|-----------| ------------------------------------------------------------ | 7510| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7511| 14800000 | Inner error. | 7512| 14800011 | Database corrupted. | 7513| 14800013 | Column out of bounds. | 7514| 14800014 | Already closed. | 7515| 14800019 | The SQL must be a query statement. | 7516| 14800021 | SQLite: Generic error. | 7517| 14800022 | SQLite: Callback routine requested an abort. | 7518| 14800023 | SQLite: Access permission denied. | 7519| 14800024 | SQLite: The database file is locked. | 7520| 14800025 | SQLite: A table in the database is locked. | 7521| 14800026 | SQLite: The database is out of memory. | 7522| 14800027 | SQLite: Attempt to write a readonly database. | 7523| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7524| 14800029 | SQLite: The database is full. | 7525| 14800030 | SQLite: Unable to open the database file. | 7526| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7527| 14800032 | SQLite: Abort due to constraint violation. | 7528| 14800033 | SQLite: Data type mismatch. | 7529| 14800034 | SQLite: Library used incorrectly. | 7530 7531**Example** 7532 7533```ts 7534if(resultSet != undefined) { 7535 const id = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("ID")); 7536 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 7537 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 7538 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 7539} 7540``` 7541 7542### getColumnName 7543 7544getColumnName(columnIndex: number): string 7545 7546Obtains the column name based on the specified column index. 7547 7548**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7549 7550**Parameters** 7551 7552| Name | Type | Mandatory| Description | 7553| ----------- | ------ | ---- | -------------------------- | 7554| columnIndex | number | Yes | Column index.| 7555 7556**Return value** 7557 7558| Type | Description | 7559| ------ | ------------------ | 7560| string | Column name obtained.| 7561 7562**Error codes** 7563 7564For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7565 7566| **ID**| **Error Message** | 7567|-----------| ------------------------------------------------------------ | 7568| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7569| 14800000 | Inner error. | 7570| 14800011 | Database corrupted. | 7571| 14800013 | Column out of bounds. | 7572| 14800014 | Already closed. | 7573| 14800019 | The SQL must be a query statement. | 7574| 14800021 | SQLite: Generic error. | 7575| 14800022 | SQLite: Callback routine requested an abort. | 7576| 14800023 | SQLite: Access permission denied. | 7577| 14800024 | SQLite: The database file is locked. | 7578| 14800025 | SQLite: A table in the database is locked. | 7579| 14800026 | SQLite: The database is out of memory. | 7580| 14800027 | SQLite: Attempt to write a readonly database. | 7581| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7582| 14800029 | SQLite: The database is full. | 7583| 14800030 | SQLite: Unable to open the database file. | 7584| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7585| 14800032 | SQLite: Abort due to constraint violation. | 7586| 14800033 | SQLite: Data type mismatch. | 7587| 14800034 | SQLite: Library used incorrectly. | 7588 7589**Example** 7590 7591```ts 7592if(resultSet != undefined) { 7593 const id = (resultSet as relationalStore.ResultSet).getColumnName(0); 7594 const name = (resultSet as relationalStore.ResultSet).getColumnName(1); 7595 const age = (resultSet as relationalStore.ResultSet).getColumnName(2); 7596} 7597``` 7598 7599### goTo 7600 7601goTo(offset:number): boolean 7602 7603Moves the cursor to the row based on the specified offset. 7604 7605**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7606 7607**Parameters** 7608 7609| Name| Type | Mandatory| Description | 7610| ------ | ------ | ---- | ---------------------------- | 7611| offset | number | Yes | Offset relative to the current position.| 7612 7613**Return value** 7614 7615| Type | Description | 7616| ------- | --------------------------------------------- | 7617| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7618 7619**Error codes** 7620 7621For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7622 7623| **ID**| **Error Message** | 7624|-----------| ------------------------------------------------------------ | 7625| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7626| 14800000 | Inner error. | 7627| 14800011 | Database corrupted. | 7628| 14800012 | Row out of bounds. | 7629| 14800014 | Already closed. | 7630| 14800019 | The SQL must be a query statement. | 7631| 14800021 | SQLite: Generic error. | 7632| 14800022 | SQLite: Callback routine requested an abort. | 7633| 14800023 | SQLite: Access permission denied. | 7634| 14800024 | SQLite: The database file is locked. | 7635| 14800025 | SQLite: A table in the database is locked. | 7636| 14800026 | SQLite: The database is out of memory. | 7637| 14800027 | SQLite: Attempt to write a readonly database. | 7638| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7639| 14800029 | SQLite: The database is full. | 7640| 14800030 | SQLite: Unable to open the database file. | 7641| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7642| 14800032 | SQLite: Abort due to constraint violation. | 7643| 14800033 | SQLite: Data type mismatch. | 7644| 14800034 | SQLite: Library used incorrectly. | 7645 7646**Example** 7647 7648```ts 7649if(resultSet != undefined) { 7650 (resultSet as relationalStore.ResultSet).goTo(1); 7651} 7652``` 7653 7654### goToRow 7655 7656goToRow(position: number): boolean 7657 7658Moves to the specified row in the result set. 7659 7660**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7661 7662**Parameters** 7663 7664| Name | Type | Mandatory| Description | 7665| -------- | ------ | ---- | ------------------------ | 7666| position | number | Yes | Destination position to move to.| 7667 7668**Return value** 7669 7670| Type | Description | 7671| ------- | --------------------------------------------- | 7672| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7673 7674**Error codes** 7675 7676For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7677 7678| **ID**| **Error Message** | 7679|-----------| ------------------------------------------------------------ | 7680| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7681| 14800000 | Inner error. | 7682| 14800011 | Database corrupted. | 7683| 14800012 | Row out of bounds. | 7684| 14800014 | Already closed. | 7685| 14800019 | The SQL must be a query statement. | 7686| 14800021 | SQLite: Generic error. | 7687| 14800022 | SQLite: Callback routine requested an abort. | 7688| 14800023 | SQLite: Access permission denied. | 7689| 14800024 | SQLite: The database file is locked. | 7690| 14800025 | SQLite: A table in the database is locked. | 7691| 14800026 | SQLite: The database is out of memory. | 7692| 14800027 | SQLite: Attempt to write a readonly database. | 7693| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7694| 14800029 | SQLite: The database is full. | 7695| 14800030 | SQLite: Unable to open the database file. | 7696| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7697| 14800032 | SQLite: Abort due to constraint violation. | 7698| 14800033 | SQLite: Data type mismatch. | 7699| 14800034 | SQLite: Library used incorrectly. | 7700 7701**Example** 7702 7703```ts 7704if(resultSet != undefined) { 7705 (resultSet as relationalStore.ResultSet).goToRow(5); 7706} 7707``` 7708 7709### goToFirstRow 7710 7711goToFirstRow(): boolean 7712 7713 7714Moves to the first row of the result set. 7715 7716**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7717 7718**Return value** 7719 7720| Type | Description | 7721| ------- | --------------------------------------------- | 7722| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7723 7724**Error codes** 7725 7726For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7727 7728| **ID**| **Error Message** | 7729|-----------| ------------------------------------------------------------ | 7730| 14800000 | Inner error. | 7731| 14800011 | Database corrupted. | 7732| 14800012 | Row out of bounds. | 7733| 14800014 | Already closed. | 7734| 14800019 | The SQL must be a query statement. | 7735| 14800021 | SQLite: Generic error. | 7736| 14800022 | SQLite: Callback routine requested an abort. | 7737| 14800023 | SQLite: Access permission denied. | 7738| 14800024 | SQLite: The database file is locked. | 7739| 14800025 | SQLite: A table in the database is locked. | 7740| 14800026 | SQLite: The database is out of memory. | 7741| 14800027 | SQLite: Attempt to write a readonly database. | 7742| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7743| 14800029 | SQLite: The database is full. | 7744| 14800030 | SQLite: Unable to open the database file. | 7745| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7746| 14800032 | SQLite: Abort due to constraint violation. | 7747| 14800033 | SQLite: Data type mismatch. | 7748| 14800034 | SQLite: Library used incorrectly. | 7749 7750**Example** 7751 7752```ts 7753if(resultSet != undefined) { 7754 (resultSet as relationalStore.ResultSet).goToFirstRow(); 7755} 7756``` 7757 7758### goToLastRow 7759 7760goToLastRow(): boolean 7761 7762Moves to the last row of the result set. 7763 7764**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7765 7766**Return value** 7767 7768| Type | Description | 7769| ------- | --------------------------------------------- | 7770| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7771 7772**Error codes** 7773 7774For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7775 7776| **ID**| **Error Message** | 7777|-----------| ------------------------------------------------------------ | 7778| 14800000 | Inner error. | 7779| 14800011 | Database corrupted. | 7780| 14800012 | Row out of bounds. | 7781| 14800014 | Already closed. | 7782| 14800019 | The SQL must be a query statement. | 7783| 14800021 | SQLite: Generic error. | 7784| 14800022 | SQLite: Callback routine requested an abort. | 7785| 14800023 | SQLite: Access permission denied. | 7786| 14800024 | SQLite: The database file is locked. | 7787| 14800025 | SQLite: A table in the database is locked. | 7788| 14800026 | SQLite: The database is out of memory. | 7789| 14800027 | SQLite: Attempt to write a readonly database. | 7790| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7791| 14800029 | SQLite: The database is full. | 7792| 14800030 | SQLite: Unable to open the database file. | 7793| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7794| 14800032 | SQLite: Abort due to constraint violation. | 7795| 14800033 | SQLite: Data type mismatch. | 7796| 14800034 | SQLite: Library used incorrectly. | 7797 7798**Example** 7799 7800```ts 7801if(resultSet != undefined) { 7802 (resultSet as relationalStore.ResultSet).goToLastRow(); 7803} 7804``` 7805 7806### goToNextRow 7807 7808goToNextRow(): boolean 7809 7810Moves to the next row in the result set. 7811 7812**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7813 7814**Return value** 7815 7816| Type | Description | 7817| ------- | --------------------------------------------- | 7818| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7819 7820**Error codes** 7821 7822For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7823 7824| **ID**| **Error Message** | 7825|-----------| ------------------------------------------------------------ | 7826| 14800000 | Inner error. | 7827| 14800011 | Database corrupted. | 7828| 14800012 | Row out of bounds. | 7829| 14800014 | Already closed. | 7830| 14800019 | The SQL must be a query statement. | 7831| 14800021 | SQLite: Generic error. | 7832| 14800022 | SQLite: Callback routine requested an abort. | 7833| 14800023 | SQLite: Access permission denied. | 7834| 14800024 | SQLite: The database file is locked. | 7835| 14800025 | SQLite: A table in the database is locked. | 7836| 14800026 | SQLite: The database is out of memory. | 7837| 14800027 | SQLite: Attempt to write a readonly database. | 7838| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7839| 14800029 | SQLite: The database is full. | 7840| 14800030 | SQLite: Unable to open the database file. | 7841| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7842| 14800032 | SQLite: Abort due to constraint violation. | 7843| 14800033 | SQLite: Data type mismatch. | 7844| 14800034 | SQLite: Library used incorrectly. | 7845 7846**Example** 7847 7848```ts 7849if(resultSet != undefined) { 7850 (resultSet as relationalStore.ResultSet).goToNextRow(); 7851} 7852``` 7853 7854### goToPreviousRow 7855 7856goToPreviousRow(): boolean 7857 7858Moves to the previous row in the result set. 7859 7860**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7861 7862**Return value** 7863 7864| Type | Description | 7865| ------- | --------------------------------------------- | 7866| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7867 7868**Error codes** 7869 7870For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7871 7872| **ID**| **Error Message** | 7873|-----------| ------------------------------------------------------------ | 7874| 14800000 | Inner error. | 7875| 14800011 | Database corrupted. | 7876| 14800012 | Row out of bounds. | 7877| 14800014 | Already closed. | 7878| 14800019 | The SQL must be a query statement. | 7879| 14800021 | SQLite: Generic error. | 7880| 14800022 | SQLite: Callback routine requested an abort. | 7881| 14800023 | SQLite: Access permission denied. | 7882| 14800024 | SQLite: The database file is locked. | 7883| 14800025 | SQLite: A table in the database is locked. | 7884| 14800026 | SQLite: The database is out of memory. | 7885| 14800027 | SQLite: Attempt to write a readonly database. | 7886| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7887| 14800029 | SQLite: The database is full. | 7888| 14800030 | SQLite: Unable to open the database file. | 7889| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7890| 14800032 | SQLite: Abort due to constraint violation. | 7891| 14800033 | SQLite: Data type mismatch. | 7892| 14800034 | SQLite: Library used incorrectly. | 7893 7894**Example** 7895 7896```ts 7897if(resultSet != undefined) { 7898 (resultSet as relationalStore.ResultSet).goToPreviousRow(); 7899} 7900``` 7901 7902### getValue<sup>12+</sup> 7903 7904getValue(columnIndex: number): ValueType 7905 7906Obtains the value from the specified column and current row. If the value type is any of **ValueType**, the value of the corresponding type will be returned. Otherwise, **14800000** will be returned. 7907 7908**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7909 7910**Parameters** 7911 7912| Name | Type | Mandatory| Description | 7913| ----------- | ------ | ---- | ----------------------- | 7914| columnIndex | number | Yes | Index of the target column, starting from 0.| 7915 7916**Return value** 7917 7918| Type | Description | 7919| ---------- | -------------------------------- | 7920| [ValueType](#valuetype) | Value obtained. | 7921 7922**Error codes** 7923 7924For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7925 7926| **ID**| **Error Message** | 7927|-----------|---------| 7928| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7929| 14800000 | Inner error. | 7930| 14800011 | Database corrupted. | 7931| 14800012 | Row out of bounds. | 7932| 14800013 | Column out of bounds. | 7933| 14800014 | Already closed. | 7934| 14800021 | SQLite: Generic error. | 7935| 14800022 | SQLite: Callback routine requested an abort. | 7936| 14800023 | SQLite: Access permission denied. | 7937| 14800024 | SQLite: The database file is locked. | 7938| 14800025 | SQLite: A table in the database is locked. | 7939| 14800026 | SQLite: The database is out of memory. | 7940| 14800027 | SQLite: Attempt to write a readonly database. | 7941| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7942| 14800029 | SQLite: The database is full. | 7943| 14800030 | SQLite: Unable to open the database file. | 7944| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7945| 14800032 | SQLite: Abort due to constraint violation. | 7946| 14800033 | SQLite: Data type mismatch. | 7947| 14800034 | SQLite: Library used incorrectly. | 7948 7949**Example** 7950 7951```ts 7952if(resultSet != undefined) { 7953 const codes = (resultSet as relationalStore.ResultSet).getValue((resultSet as relationalStore.ResultSet).getColumnIndex("BIGINT_COLUMN")); 7954} 7955``` 7956 7957### getBlob 7958 7959getBlob(columnIndex: number): Uint8Array 7960 7961 7962Obtains the value from the specified column and current row, and returns it in a byte array.<br>If the type of the value in the specified column is INTEGER, DOUBLE, TEXT, or BLOB, the value will be converted into a byte array and returned. If the column is empty, an empty byte array will be returned. If the value is of any other type, **14800000** will be returned. 7963 7964**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7965 7966**Parameters** 7967 7968| Name | Type | Mandatory| Description | 7969| ----------- | ------ | ---- | ----------------------- | 7970| columnIndex | number | Yes | Index of the target column, starting from 0.| 7971 7972**Return value** 7973 7974| Type | Description | 7975| ---------- | -------------------------------- | 7976| Uint8Array | Value obtained.| 7977 7978**Error codes** 7979 7980For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 7981 7982| **ID**| **Error Message** | 7983|-----------| ------------------------------------------------------------ | 7984| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7985| 14800000 | Inner error. | 7986| 14800011 | Database corrupted. | 7987| 14800012 | Row out of bounds. | 7988| 14800013 | Column out of bounds. | 7989| 14800014 | Already closed. | 7990| 14800021 | SQLite: Generic error. | 7991| 14800022 | SQLite: Callback routine requested an abort. | 7992| 14800023 | SQLite: Access permission denied. | 7993| 14800024 | SQLite: The database file is locked. | 7994| 14800025 | SQLite: A table in the database is locked. | 7995| 14800026 | SQLite: The database is out of memory. | 7996| 14800027 | SQLite: Attempt to write a readonly database. | 7997| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7998| 14800029 | SQLite: The database is full. | 7999| 14800030 | SQLite: Unable to open the database file. | 8000| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8001| 14800032 | SQLite: Abort due to constraint violation. | 8002| 14800033 | SQLite: Data type mismatch. | 8003| 14800034 | SQLite: Library used incorrectly. | 8004 8005**Example** 8006 8007```ts 8008if(resultSet != undefined) { 8009 const codes = (resultSet as relationalStore.ResultSet).getBlob((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 8010} 8011``` 8012 8013### getString 8014 8015getString(columnIndex: number): string 8016 8017Obtains the value from the specified column and current row, and returns it in the form of a string.<br>If the type of the value in the specified column is INTEGER, DOUBLE, TEXT, or BLOB, a string will be returned. If the value type is INTEGER and the column is empty, an empty string will be returned. If the value is of any other type, **14800000** will be returned. If the value in the current column is of the DOUBLE type, the precision may be lost. You are advised to use [getDouble](#getdouble) to obtain the value. 8018 8019**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8020 8021**Parameters** 8022 8023| Name | Type | Mandatory| Description | 8024| ----------- | ------ | ---- | ----------------------- | 8025| columnIndex | number | Yes | Index of the target column, starting from 0.| 8026 8027**Return value** 8028 8029| Type | Description | 8030| ------ | ---------------------------- | 8031| string | String obtained.| 8032 8033**Error codes** 8034 8035For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8036 8037| **ID**| **Error Message** | 8038|-----------| ------------------------------------------------------------ | 8039| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8040| 14800000 | Inner error. | 8041| 14800011 | Database corrupted. | 8042| 14800012 | Row out of bounds. | 8043| 14800013 | Column out of bounds. | 8044| 14800014 | Already closed. | 8045| 14800021 | SQLite: Generic error. | 8046| 14800022 | SQLite: Callback routine requested an abort. | 8047| 14800023 | SQLite: Access permission denied. | 8048| 14800024 | SQLite: The database file is locked. | 8049| 14800025 | SQLite: A table in the database is locked. | 8050| 14800026 | SQLite: The database is out of memory. | 8051| 14800027 | SQLite: Attempt to write a readonly database. | 8052| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8053| 14800029 | SQLite: The database is full. | 8054| 14800030 | SQLite: Unable to open the database file. | 8055| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8056| 14800032 | SQLite: Abort due to constraint violation. | 8057| 14800033 | SQLite: Data type mismatch. | 8058| 14800034 | SQLite: Library used incorrectly. | 8059 8060**Example** 8061 8062```ts 8063if(resultSet != undefined) { 8064 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 8065} 8066``` 8067 8068### getLong 8069 8070getLong(columnIndex: number): number 8071 8072Obtains the value from the specified column and current row, and returns a value of Long type.<br>If the type of the value in the specified column is INTEGER, DOUBLE, TEXT, or BLOB, a value of Long type will be returned. If the column is empty, **0** will be returned. If the value is of any other type, **14800000** will be returned. 8073 8074**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8075 8076**Parameters** 8077 8078| Name | Type | Mandatory| Description | 8079| ----------- | ------ | ---- | ----------------------- | 8080| columnIndex | number | Yes | Index of the target column, starting from 0.| 8081 8082**Return value** 8083 8084| Type | Description | 8085| ------ | ------------------------------------------------------------ | 8086| number | Value obtained.<br>The value range supported by this API is **Number.MIN_SAFE_INTEGER** to **Number.MAX_SAFE_INTEGER**. If the value is out of this range, use [getDouble](#getdouble).| 8087 8088**Error codes** 8089 8090For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8091 8092| **ID**| **Error Message** | 8093|-----------| ------------------------------------------------------------ | 8094| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8095| 14800000 | Inner error. | 8096| 14800011 | Database corrupted. | 8097| 14800012 | Row out of bounds. | 8098| 14800013 | Column out of bounds. | 8099| 14800014 | Already closed. | 8100| 14800021 | SQLite: Generic error. | 8101| 14800022 | SQLite: Callback routine requested an abort. | 8102| 14800023 | SQLite: Access permission denied. | 8103| 14800024 | SQLite: The database file is locked. | 8104| 14800025 | SQLite: A table in the database is locked. | 8105| 14800026 | SQLite: The database is out of memory. | 8106| 14800027 | SQLite: Attempt to write a readonly database. | 8107| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8108| 14800029 | SQLite: The database is full. | 8109| 14800030 | SQLite: Unable to open the database file. | 8110| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8111| 14800032 | SQLite: Abort due to constraint violation. | 8112| 14800033 | SQLite: Data type mismatch. | 8113| 14800034 | SQLite: Library used incorrectly. | 8114 8115**Example** 8116 8117```ts 8118if(resultSet != undefined) { 8119 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 8120 } 8121``` 8122 8123### getDouble 8124 8125getDouble(columnIndex: number): number 8126 8127Obtains the value from the specified column and current row, and returns a value of double type.<br>If the type of the value in the specified column is INTEGER, DOUBLE, TEXT, or BLOB, a value of double type will be returned. If the column is empty, **0.0** will be returned. If the value is of any other type, **14800000** will be returned. 8128 8129**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8130 8131**Parameters** 8132 8133| Name | Type | Mandatory| Description | 8134| ----------- | ------ | ---- | ----------------------- | 8135| columnIndex | number | Yes | Index of the target column, starting from 0.| 8136 8137**Return value** 8138 8139| Type | Description | 8140| ------ | ---------------------------- | 8141| number | Returns the value obtained.| 8142 8143**Error codes** 8144 8145For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8146 8147| **ID**| **Error Message** | 8148|-----------| ------------------------------------------------------------ | 8149| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8150| 14800000 | Inner error. | 8151| 14800011 | Database corrupted. | 8152| 14800012 | Row out of bounds. | 8153| 14800013 | Column out of bounds. | 8154| 14800014 | Already closed. | 8155| 14800021 | SQLite: Generic error. | 8156| 14800022 | SQLite: Callback routine requested an abort. | 8157| 14800023 | SQLite: Access permission denied. | 8158| 14800024 | SQLite: The database file is locked. | 8159| 14800025 | SQLite: A table in the database is locked. | 8160| 14800026 | SQLite: The database is out of memory. | 8161| 14800027 | SQLite: Attempt to write a readonly database. | 8162| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8163| 14800029 | SQLite: The database is full. | 8164| 14800030 | SQLite: Unable to open the database file. | 8165| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8166| 14800032 | SQLite: Abort due to constraint violation. | 8167| 14800033 | SQLite: Data type mismatch. | 8168| 14800034 | SQLite: Library used incorrectly. | 8169 8170**Example** 8171 8172```ts 8173if(resultSet != undefined) { 8174 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 8175} 8176``` 8177 8178### getAsset<sup>10+</sup> 8179 8180getAsset(columnIndex: number): Asset 8181 8182Obtains the value from the specified column and current row, and returns the value in the [Asset](#asset10) format. If the type of the value in the column is **Asset**, the value of the Asset type is returned. If the value in the column is null, **null** is returned. If the value in the column is of other types, **14800000** is returned. 8183 8184**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8185 8186**Parameters** 8187 8188| Name | Type | Mandatory | Description | 8189| ----------- | ------ | --- | ------------ | 8190| columnIndex | number | Yes | Index of the target column, starting from 0.| 8191 8192**Return value** 8193 8194| Type | Description | 8195| --------------- | -------------------------- | 8196| [Asset](#asset10) | Returns the value obtained.| 8197 8198**Error codes** 8199 8200For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8201 8202| **ID**| **Error Message** | 8203|-----------| ------------------------------------------------------------ | 8204| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8205| 14800000 | Inner error. | 8206| 14800011 | Database corrupted. | 8207| 14800012 | Row out of bounds. | 8208| 14800013 | Column out of bounds. | 8209| 14800014 | Already closed. | 8210| 14800021 | SQLite: Generic error. | 8211| 14800022 | SQLite: Callback routine requested an abort. | 8212| 14800023 | SQLite: Access permission denied. | 8213| 14800024 | SQLite: The database file is locked. | 8214| 14800025 | SQLite: A table in the database is locked. | 8215| 14800026 | SQLite: The database is out of memory. | 8216| 14800027 | SQLite: Attempt to write a readonly database. | 8217| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8218| 14800029 | SQLite: The database is full. | 8219| 14800030 | SQLite: Unable to open the database file. | 8220| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8221| 14800032 | SQLite: Abort due to constraint violation. | 8222| 14800033 | SQLite: Data type mismatch. | 8223| 14800034 | SQLite: Library used incorrectly. | 8224 8225**Example** 8226 8227```ts 8228if(resultSet != undefined) { 8229 const doc = (resultSet as relationalStore.ResultSet).getAsset((resultSet as relationalStore.ResultSet).getColumnIndex("DOC")); 8230} 8231``` 8232 8233### getAssets<sup>10+</sup> 8234 8235getAssets(columnIndex: number): Assets 8236 8237Obtains the value from the specified column and current row, and returns the value in the [Assets](#assets10) format. If the type of the value in the column is **Assets**, the value of the Assets type is returned. If the value in the column is null, **null** is returned. If the value in the column is of other types, **14800000** is returned. 8238 8239**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8240 8241**Parameters** 8242 8243| Name | Type | Mandatory | Description | 8244| ----------- | ------ | --- | ------------ | 8245| columnIndex | number | Yes | Index of the target column, starting from 0.| 8246 8247**Return value** 8248 8249| Type | Description | 8250| ---------------- | ---------------------------- | 8251| [Assets](#assets10)| Returns the value obtained.| 8252 8253**Error codes** 8254 8255For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8256 8257| **ID**| **Error Message** | 8258|-----------| ------------------------------------------------------------ | 8259| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8260| 14800000 | Inner error. | 8261| 14800011 | Database corrupted. | 8262| 14800012 | Row out of bounds. | 8263| 14800013 | Column out of bounds. | 8264| 14800014 | Already closed. | 8265| 14800021 | SQLite: Generic error. | 8266| 14800022 | SQLite: Callback routine requested an abort. | 8267| 14800023 | SQLite: Access permission denied. | 8268| 14800024 | SQLite: The database file is locked. | 8269| 14800025 | SQLite: A table in the database is locked. | 8270| 14800026 | SQLite: The database is out of memory. | 8271| 14800027 | SQLite: Attempt to write a readonly database. | 8272| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8273| 14800029 | SQLite: The database is full. | 8274| 14800030 | SQLite: Unable to open the database file. | 8275| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8276| 14800032 | SQLite: Abort due to constraint violation. | 8277| 14800033 | SQLite: Data type mismatch. | 8278| 14800034 | SQLite: Library used incorrectly. | 8279 8280**Example** 8281 8282```ts 8283if(resultSet != undefined) { 8284 const docs = (resultSet as relationalStore.ResultSet).getAssets((resultSet as relationalStore.ResultSet).getColumnIndex("DOCS")); 8285} 8286``` 8287 8288### getRow<sup>11+</sup> 8289 8290getRow(): ValuesBucket 8291 8292Obtains the data in the current row. 8293 8294**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8295 8296**Return value** 8297 8298| Type | Description | 8299| ---------------- | ---------------------------- | 8300| [ValuesBucket](#valuesbucket) | Data obtained.| 8301 8302**Error codes** 8303 8304For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8305 8306| **ID**| **Error Message** | 8307|-----------| ------------------------------------------------------------ | 8308| 14800000 | Inner error. | 8309| 14800011 | Database corrupted. | 8310| 14800012 | Row out of bounds. | 8311| 14800013 | Column out of bounds. | 8312| 14800014 | Already closed. | 8313| 14800021 | SQLite: Generic error. | 8314| 14800022 | SQLite: Callback routine requested an abort. | 8315| 14800023 | SQLite: Access permission denied. | 8316| 14800024 | SQLite: The database file is locked. | 8317| 14800025 | SQLite: A table in the database is locked. | 8318| 14800026 | SQLite: The database is out of memory. | 8319| 14800027 | SQLite: Attempt to write a readonly database. | 8320| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8321| 14800029 | SQLite: The database is full. | 8322| 14800030 | SQLite: Unable to open the database file. | 8323| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8324| 14800032 | SQLite: Abort due to constraint violation. | 8325| 14800033 | SQLite: Data type mismatch. | 8326| 14800034 | SQLite: Library used incorrectly. | 8327 8328**Example** 8329 8330```ts 8331if(resultSet != undefined) { 8332 const row = (resultSet as relationalStore.ResultSet).getRow(); 8333} 8334``` 8335 8336### getSendableRow<sup>12+</sup> 8337 8338getSendableRow(): sendableRelationalStore.ValuesBucket 8339 8340Obtains the sendable data from the current row. The sendable data can be passed across threads. 8341 8342**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8343 8344**Return value** 8345 8346| Type | Description | 8347| ---------------------------------------------------------------------------------------------- | ---------------------------------------------- | 8348| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | Sendable data obtained for cross-thread transfer.| 8349 8350**Error codes** 8351 8352For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8353 8354| **ID**| **Error Message** | 8355| ------------ | --------------------------------------------- | 8356| 14800000 | Inner error. | 8357| 14800011 | Database corrupted. | 8358| 14800012 | Row out of bounds. | 8359| 14800013 | Column out of bounds. | 8360| 14800014 | Already closed. | 8361| 14800021 | SQLite: Generic error. | 8362| 14800022 | SQLite: Callback routine requested an abort. | 8363| 14800023 | SQLite: Access permission denied. | 8364| 14800024 | SQLite: The database file is locked. | 8365| 14800025 | SQLite: A table in the database is locked. | 8366| 14800026 | SQLite: The database is out of memory. | 8367| 14800027 | SQLite: Attempt to write a readonly database. | 8368| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8369| 14800029 | SQLite: The database is full. | 8370| 14800030 | SQLite: Unable to open the database file. | 8371| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8372| 14800032 | SQLite: Abort due to constraint violation. | 8373| 14800033 | SQLite: Data type mismatch. | 8374| 14800034 | SQLite: Library used incorrectly. | 8375 8376**Example** 8377 8378```ts 8379import { taskpool } from '@kit.ArkTS'; 8380import type ctx from '@ohos.app.ability.common'; 8381import { sendableRelationalStore } from '@kit.ArkData'; 8382 8383@Concurrent 8384async function getDataByName(name: string, context: ctx.UIAbilityContext) { 8385 const STORE_CONFIG: relationalStore.StoreConfig = { 8386 name: "RdbTest.db", 8387 securityLevel: relationalStore.SecurityLevel.S3 8388 }; 8389 const store = await relationalStore.getRdbStore(context, STORE_CONFIG); 8390 const predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 8391 predicates.equalTo("NAME", name); 8392 const resultSet = store.querySync(predicates); 8393 8394 if (resultSet.rowCount > 0) { 8395 resultSet.goToFirstRow(); 8396 const sendableValuesBucket = resultSet.getSendableRow(); 8397 return sendableValuesBucket; 8398 } else { 8399 return null; 8400 } 8401} 8402 8403async function run() { 8404 const task = new taskpool.Task(getDataByName, 'Lisa', getContext()); 8405 const sendableValuesBucket = await taskpool.execute(task) as sendableRelationalStore.ValuesBucket; 8406 8407 if (sendableValuesBucket) { 8408 const columnCount = sendableValuesBucket.size; 8409 const age = sendableValuesBucket.get('age'); 8410 const name = sendableValuesBucket.get('name'); 8411 console.info(`Query data in taskpool succeeded, name is "${name}", age is "${age}"`) 8412 } 8413} 8414 8415run() 8416``` 8417 8418### isColumnNull 8419 8420isColumnNull(columnIndex: number): boolean 8421 8422Checks whether the value in the specified column is null. 8423 8424**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8425 8426**Parameters** 8427 8428| Name | Type | Mandatory| Description | 8429| ----------- | ------ | ---- | ----------------------- | 8430| columnIndex | number | Yes | Index of the target column, starting from 0.| 8431 8432**Return value** 8433 8434| Type | Description | 8435| ------- | --------------------------------------------------------- | 8436| boolean | Returns **true** if the value is null; returns **false** otherwise.| 8437 8438**Error codes** 8439 8440For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8441 8442| **ID**| **Error Message** | 8443|-----------| ------------------------------------------------------- | 8444| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8445| 14800000 | Inner error. | 8446| 14800011 | Database corrupted. | 8447| 14800012 | Row out of bounds. | 8448| 14800013 | Column out of bounds. | 8449| 14800014 | Already closed. | 8450| 14800021 | SQLite: Generic error. | 8451| 14800022 | SQLite: Callback routine requested an abort. | 8452| 14800023 | SQLite: Access permission denied. | 8453| 14800024 | SQLite: The database file is locked. | 8454| 14800025 | SQLite: A table in the database is locked. | 8455| 14800026 | SQLite: The database is out of memory. | 8456| 14800027 | SQLite: Attempt to write a readonly database. | 8457| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8458| 14800029 | SQLite: The database is full. | 8459| 14800030 | SQLite: Unable to open the database file. | 8460| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8461| 14800032 | SQLite: Abort due to constraint violation. | 8462| 14800033 | SQLite: Data type mismatch. | 8463| 14800034 | SQLite: Library used incorrectly. | 8464 8465**Example** 8466 8467```ts 8468if(resultSet != undefined) { 8469 const isColumnNull = (resultSet as relationalStore.ResultSet).isColumnNull((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 8470} 8471``` 8472 8473### close 8474 8475close(): void 8476 8477Closes this **resultSet** to release memory. If the **resultSet** is not closed, FD or memory leaks may occur. 8478 8479**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8480 8481**Example** 8482 8483```ts 8484if(resultSet != undefined) { 8485 (resultSet as relationalStore.ResultSet).close(); 8486} 8487``` 8488 8489**Error codes** 8490 8491For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 8492 8493| **ID**| **Error Message** | 8494|-----------| ------------------------------------------------------------ | 8495| 14800000 | Inner error. | 8496| 14800012 | Row out of bounds. | 8497 8498## Transaction<sup>14+</sup> 8499 8500Provides API for managing databases in transaction mode. A transaction object is created by using [createTransaction](#createtransaction14). Operations on different transaction objects are isolated. For details about the transaction types, see [TransactionType](#transactiontype14). 8501 8502Currently, an RDB store supports only one write transaction at a time. If the current [RdbStore](#rdbstore) has a write transaction that is not released, creating an **IMMEDIATE** or **EXCLUSIVE** transaction object will return error 14800024. If a **DEFERRED** transaction object is created, error 14800024 may be returned when it is used to invoke a write operation for the first time. After a write transaction is created using **IMMEDIATE** or **EXCLUSIVE**, or a **DEFERRED** transaction is upgraded to a write transaction, write operations in the [RdbStore](#rdbstore) will also return error 14800024. 8503 8504When the number of concurrent transactions is large and the write transaction duration is long, the frequency of returning error 14800024 may increase. You can reduce the occurrence of error 14800024 by shortening the transaction duration or by handling the error 14800024 through retries. 8505 8506**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8507 8508**Example** 8509 8510```ts 8511import { UIAbility } from '@kit.AbilityKit'; 8512import { BusinessError } from '@kit.BasicServicesKit'; 8513import { window } from '@kit.ArkUI'; 8514 8515let store: relationalStore.RdbStore | undefined = undefined; 8516 8517class EntryAbility extends UIAbility { 8518 onWindowStageCreate(windowStage: window.WindowStage) { 8519 const STORE_CONFIG: relationalStore.StoreConfig = { 8520 name: "RdbTest.db", 8521 securityLevel: relationalStore.SecurityLevel.S3, 8522 }; 8523 8524 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 8525 store = rdbStore; 8526 console.info('Get RdbStore successfully.') 8527 }).catch((err: BusinessError) => { 8528 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 8529 }) 8530 8531 if(store != undefined) { 8532 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 8533 console.info(`createTransaction success`); 8534 }).catch((err: BusinessError) => { 8535 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 8536 }); 8537 } 8538 } 8539} 8540``` 8541 8542### commit<sup>14+</sup> 8543 8544commit(): Promise<void> 8545 8546Commits the executed SQL statements. When using asynchronous APIs to execute SQL statements, ensure that **commit()** is called after the asynchronous API execution is completed. Otherwise, the SQL operations may be lost. After **commit()** is called, the transaction object and the created **ResultSet** object will be closed. 8547 8548**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8549 8550**Return value** 8551 8552| Type | Description | 8553| ------------------- | ------------------------- | 8554| Promise<void> | Promise that returns no value.| 8555 8556**Error codes** 8557 8558For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8559 8560| **ID**| **Error Message** | 8561|-----------| ------------------------------------------------------------ | 8562| 14800000 | Inner error. | 8563| 14800011 | Database corrupted. | 8564| 14800014 | Already closed. | 8565| 14800023 | SQLite: Access permission denied. | 8566| 14800024 | SQLite: The database file is locked. | 8567| 14800026 | SQLite: The database is out of memory. | 8568| 14800027 | SQLite: Attempt to write a readonly database. | 8569| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8570| 14800029 | SQLite: The database is full. | 8571 8572**Example** 8573 8574```ts 8575let value1 = "Lisa"; 8576let value2 = 18; 8577let value3 = 100.5; 8578let value4 = new Uint8Array([1, 2, 3]); 8579 8580if(store != undefined) { 8581 const valueBucket: relationalStore.ValuesBucket = { 8582 'NAME': value1, 8583 'AGE': value2, 8584 'SALARY': value3, 8585 'CODES': value4, 8586 }; 8587 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 8588 transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => { 8589 transaction.commit(); 8590 }).catch((e: BusinessError) => { 8591 transaction.rollback(); 8592 console.error(`execute sql failed, code is ${e.code},message is ${e.message}`); 8593 }); 8594 }).catch((err: BusinessError) => { 8595 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 8596 }); 8597} 8598``` 8599 8600### rollback<sup>14+</sup> 8601 8602rollback(): Promise<void> 8603 8604Rolls back the executed SQL statement. After **rollback()** is called, the transaction object and the created **ResultSet** object will be closed. 8605 8606**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8607 8608**Return value** 8609 8610| Type | Description | 8611| ------------------- | ------------------------- | 8612| Promise<void> | Promise that returns no value.| 8613 8614**Error codes** 8615 8616For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8617 8618| **ID**| **Error Message** | 8619|-----------| ------------------------------------------------------------ | 8620| 14800000 | Inner error. | 8621| 14800011 | Database corrupted. | 8622| 14800014 | Already closed. | 8623| 14800023 | SQLite: Access permission denied. | 8624| 14800024 | SQLite: The database file is locked. | 8625| 14800026 | SQLite: The database is out of memory. | 8626| 14800027 | SQLite: Attempt to write a readonly database. | 8627| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8628| 14800029 | SQLite: The database is full. | 8629 8630**Example** 8631 8632```ts 8633if(store != undefined) { 8634 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 8635 transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => { 8636 transaction.commit(); 8637 }).catch((e: BusinessError) => { 8638 transaction.rollback(); 8639 console.error(`execute sql failed, code is ${e.code},message is ${e.message}`); 8640 }); 8641 }).catch((err: BusinessError) => { 8642 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 8643 }); 8644} 8645 8646``` 8647 8648### insert<sup>14+</sup> 8649 8650insert(table: string, values: ValuesBucket, conflict?: ConflictResolution): Promise<number> 8651 8652Inserts a row of data into a table. 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. 8653 8654**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8655 8656**Parameters** 8657 8658| Name | Type | Mandatory| Description | 8659| -------- | ------------------------------------------- | ---- | -------------------------- | 8660| table | string | Yes | Name of the target table. | 8661| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 8662| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**. | 8663 8664**Return value** 8665 8666| Type | Description | 8667| --------------------- | ------------------------------------------------- | 8668| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 8669 8670**Error codes** 8671 8672For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8673 8674| **ID**| **Error Message** | 8675|-----------| ------------------------------------------------------------ | 8676| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8677| 14800000 | Inner error. | 8678| 14800011 | Database corrupted. | 8679| 14800014 | Already closed. | 8680| 14800021 | SQLite: Generic error. | 8681| 14800023 | SQLite: Access permission denied. | 8682| 14800024 | SQLite: The database file is locked. | 8683| 14800025 | SQLite: A table in the database is locked. | 8684| 14800026 | SQLite: The database is out of memory. | 8685| 14800027 | SQLite: Attempt to write a readonly database. | 8686| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8687| 14800029 | SQLite: The database is full. | 8688| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8689| 14800033 | SQLite: Data type mismatch. | 8690| 14800047 | The WAL file size exceeds the default limit. | 8691 8692**Example** 8693 8694```ts 8695let value1 = "Lisa"; 8696let value2 = 18; 8697let value3 = 100.5; 8698let value4 = new Uint8Array([1, 2, 3, 4, 5]); 8699 8700// You can use either of the following: 8701const valueBucket1: relationalStore.ValuesBucket = { 8702 'NAME': value1, 8703 'AGE': value2, 8704 'SALARY': value3, 8705 'CODES': value4, 8706}; 8707const valueBucket2: relationalStore.ValuesBucket = { 8708 NAME: value1, 8709 AGE: value2, 8710 SALARY: value3, 8711 CODES: value4, 8712}; 8713const valueBucket3: relationalStore.ValuesBucket = { 8714 "NAME": value1, 8715 "AGE": value2, 8716 "SALARY": value3, 8717 "CODES": value4, 8718}; 8719 8720if(store != undefined) { 8721 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 8722 transaction.insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => { 8723 transaction.commit(); 8724 console.info(`Insert is successful, rowId = ${rowId}`); 8725 }).catch((e: BusinessError) => { 8726 transaction.rollback(); 8727 console.error(`Insert is failed, code is ${e.code},message is ${e.message}`); 8728 }); 8729 }).catch((err: BusinessError) => { 8730 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 8731 }); 8732} 8733``` 8734 8735### insertSync<sup>14+</sup> 8736 8737insertSync(table: string, values: ValuesBucket | sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution): number 8738 8739Inserts a row of data into a table. 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. 8740 8741**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8742 8743**Parameters** 8744 8745| Name | Type | Mandatory| Description | 8746| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 8747| table | string | Yes | Name of the target table. | 8748| values | [ValuesBucket](#valuesbucket) \| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | Yes | Row of data to insert. | 8749| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 8750 8751**Return value** 8752 8753| Type | Description | 8754| ------ | ------------------------------------ | 8755| number | If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 8756 8757**Error codes** 8758 8759For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8760 8761| **ID**| **Error Message** | 8762| ------------ | ------------------------------------------------------------ | 8763| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8764| 14800000 | Inner error. | 8765| 14800011 | Database corrupted. | 8766| 14800014 | Already closed. | 8767| 14800021 | SQLite: Generic error. | 8768| 14800023 | SQLite: Access permission denied. | 8769| 14800024 | SQLite: The database file is locked. | 8770| 14800025 | SQLite: A table in the database is locked. | 8771| 14800026 | SQLite: The database is out of memory. | 8772| 14800027 | SQLite: Attempt to write a readonly database. | 8773| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8774| 14800029 | SQLite: The database is full. | 8775| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8776| 14800033 | SQLite: Data type mismatch. | 8777| 14800047 | The WAL file size exceeds the default limit. | 8778 8779**Example** 8780 8781```ts 8782let value1 = "Lisa"; 8783let value2 = 18; 8784let value3 = 100.5; 8785let value4 = new Uint8Array([1, 2, 3, 4, 5]); 8786 8787// You can use either of the following: 8788const valueBucket1: relationalStore.ValuesBucket = { 8789 'NAME': value1, 8790 'AGE': value2, 8791 'SALARY': value3, 8792 'CODES': value4, 8793}; 8794const valueBucket2: relationalStore.ValuesBucket = { 8795 NAME: value1, 8796 AGE: value2, 8797 SALARY: value3, 8798 CODES: value4, 8799}; 8800const valueBucket3: relationalStore.ValuesBucket = { 8801 "NAME": value1, 8802 "AGE": value2, 8803 "SALARY": value3, 8804 "CODES": value4, 8805}; 8806 8807if(store != undefined) { 8808 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 8809 try { 8810 let rowId: number = (transaction as relationalStore.Transaction).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 8811 transaction.commit(); 8812 console.info(`Insert is successful, rowId = ${rowId}`); 8813 } catch (e: BusinessError) { 8814 transaction.rollback(); 8815 console.error(`Insert is failed, code is ${e.code},message is ${e.message}`); 8816 }; 8817 }).catch((err: BusinessError) => { 8818 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 8819 }); 8820} 8821``` 8822 8823### batchInsert<sup>14+</sup> 8824 8825batchInsert(table: string, values: Array<ValuesBucket>): Promise<number> 8826 8827Inserts a batch of data into a table. This API uses a promise to return the result. 8828 8829**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8830 8831**Parameters** 8832 8833| Name| Type | Mandatory| Description | 8834| ------ | ------------------------------------------ | ---- | ---------------------------- | 8835| table | string | Yes | Name of the target table. | 8836| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 8837 8838**Return value** 8839 8840| Type | Description | 8841| --------------------- | ----------------------------------------------------------- | 8842| Promise<number> | Promise used to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 8843 8844**Error codes** 8845 8846For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8847 8848| **ID**| **Error Message** | 8849|-----------| ------------------------------------------------------------ | 8850| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8851| 14800000 | Inner error. | 8852| 14800011 | Database corrupted. | 8853| 14800014 | Already closed. | 8854| 14800021 | SQLite: Generic error. | 8855| 14800023 | SQLite: Access permission denied. | 8856| 14800024 | SQLite: The database file is locked. | 8857| 14800025 | SQLite: A table in the database is locked. | 8858| 14800026 | SQLite: The database is out of memory. | 8859| 14800027 | SQLite: Attempt to write a readonly database. | 8860| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8861| 14800029 | SQLite: The database is full. | 8862| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8863| 14800033 | SQLite: Data type mismatch. | 8864| 14800047 | The WAL file size exceeds the default limit. | 8865 8866**Example** 8867 8868```ts 8869let value1 = "Lisa"; 8870let value2 = 18; 8871let value3 = 100.5; 8872let value4 = new Uint8Array([1, 2, 3, 4, 5]); 8873let value5 = "Jack"; 8874let value6 = 19; 8875let value7 = 101.5; 8876let value8 = new Uint8Array([6, 7, 8, 9, 10]); 8877let value9 = "Tom"; 8878let value10 = 20; 8879let value11 = 102.5; 8880let value12 = new Uint8Array([11, 12, 13, 14, 15]); 8881 8882const valueBucket1: relationalStore.ValuesBucket = { 8883 'NAME': value1, 8884 'AGE': value2, 8885 'SALARY': value3, 8886 'CODES': value4, 8887}; 8888const valueBucket2: relationalStore.ValuesBucket = { 8889 'NAME': value5, 8890 'AGE': value6, 8891 'SALARY': value7, 8892 'CODES': value8, 8893}; 8894const valueBucket3: relationalStore.ValuesBucket = { 8895 'NAME': value9, 8896 'AGE': value10, 8897 'SALARY': value11, 8898 'CODES': value12, 8899}; 8900 8901let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 8902if(store != undefined) { 8903 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 8904 transaction.batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => { 8905 transaction.commit(); 8906 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 8907 }).catch((e: BusinessError) => { 8908 transaction.rollback(); 8909 console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`); 8910 }); 8911 }).catch((err: BusinessError) => { 8912 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 8913 }); 8914} 8915``` 8916 8917### batchInsertSync<sup>14+</sup> 8918 8919batchInsertSync(table: string, values: Array<ValuesBucket>): number 8920 8921Inserts a batch of data into a table. This API returns the result synchronously. 8922 8923**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8924 8925**Parameters** 8926 8927| Name| Type | Mandatory| Description | 8928| ------ | ------------------------------------------ | ---- | ---------------------------- | 8929| table | string | Yes | Name of the target table. | 8930| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 8931 8932**Return value** 8933 8934| Type | Description | 8935| ------ | ---------------------------------------------- | 8936| number | If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 8937 8938**Error codes** 8939 8940For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8941 8942| **ID**| **Error Message** | 8943| ------------ | ------------------------------------------------------------ | 8944| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8945| 14800000 | Inner error. | 8946| 14800011 | Database corrupted. | 8947| 14800014 | Already closed. | 8948| 14800021 | SQLite: Generic error. | 8949| 14800023 | SQLite: Access permission denied. | 8950| 14800024 | SQLite: The database file is locked. | 8951| 14800025 | SQLite: A table in the database is locked. | 8952| 14800026 | SQLite: The database is out of memory. | 8953| 14800027 | SQLite: Attempt to write a readonly database. | 8954| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8955| 14800029 | SQLite: The database is full. | 8956| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8957| 14800033 | SQLite: Data type mismatch. | 8958| 14800047 | The WAL file size exceeds the default limit. | 8959 8960**Example** 8961 8962```ts 8963let value1 = "Lisa"; 8964let value2 = 18; 8965let value3 = 100.5; 8966let value4 = new Uint8Array([1, 2, 3, 4, 5]); 8967let value5 = "Jack"; 8968let value6 = 19; 8969let value7 = 101.5; 8970let value8 = new Uint8Array([6, 7, 8, 9, 10]); 8971let value9 = "Tom"; 8972let value10 = 20; 8973let value11 = 102.5; 8974let value12 = new Uint8Array([11, 12, 13, 14, 15]); 8975 8976const valueBucket1: relationalStore.ValuesBucket = { 8977 'NAME': value1, 8978 'AGE': value2, 8979 'SALARY': value3, 8980 'CODES': value4, 8981}; 8982const valueBucket2: relationalStore.ValuesBucket = { 8983 'NAME': value5, 8984 'AGE': value6, 8985 'SALARY': value7, 8986 'CODES': value8, 8987}; 8988const valueBucket3: relationalStore.ValuesBucket = { 8989 'NAME': value9, 8990 'AGE': value10, 8991 'SALARY': value11, 8992 'CODES': value12, 8993}; 8994 8995let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 8996if(store != undefined) { 8997 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 8998 try { 8999 let insertNum: number = (transaction as relationalStore.Transaction).batchInsertSync("EMPLOYEE", valueBuckets); 9000 transaction.commit(); 9001 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 9002 } catch (e) { 9003 transaction.rollback(); 9004 console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`); 9005 }; 9006 }).catch((err: BusinessError) => { 9007 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9008 }); 9009} 9010``` 9011 9012### update<sup>14+</sup> 9013 9014update(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): Promise<number> 9015 9016Updates data based on the specified **RdbPredicates** 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. 9017 9018**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9019 9020**Parameters** 9021 9022| Name | Type | Mandatory| Description | 9023| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 9024| values | [ValuesBucket](#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.| 9025| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 9026| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**. | 9027 9028**Return value** 9029 9030| Type | Description | 9031| --------------------- | ----------------------------------------- | 9032| Promise<number> | Promise used to return the number of rows updated.| 9033 9034**Error codes** 9035 9036For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 9037 9038| **ID**| **Error Message** | 9039|-----------| ------------------------------------------------------------ | 9040| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9041| 14800000 | Inner error. | 9042| 14800011 | Database corrupted. | 9043| 14800014 | Already closed. | 9044| 14800021 | SQLite: Generic error. | 9045| 14800023 | SQLite: Access permission denied. | 9046| 14800024 | SQLite: The database file is locked. | 9047| 14800025 | SQLite: A table in the database is locked. | 9048| 14800026 | SQLite: The database is out of memory. | 9049| 14800027 | SQLite: Attempt to write a readonly database. | 9050| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9051| 14800029 | SQLite: The database is full. | 9052| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9053| 14800033 | SQLite: Data type mismatch. | 9054| 14800047 | The WAL file size exceeds the default limit. | 9055 9056**Example** 9057 9058```ts 9059let value1 = "Rose"; 9060let value2 = 22; 9061let value3 = 200.5; 9062let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9063 9064// You can use either of the following: 9065const valueBucket1: relationalStore.ValuesBucket = { 9066 'NAME': value1, 9067 'AGE': value2, 9068 'SALARY': value3, 9069 'CODES': value4, 9070}; 9071const valueBucket2: relationalStore.ValuesBucket = { 9072 NAME: value1, 9073 AGE: value2, 9074 SALARY: value3, 9075 CODES: value4, 9076}; 9077const valueBucket3: relationalStore.ValuesBucket = { 9078 "NAME": value1, 9079 "AGE": value2, 9080 "SALARY": value3, 9081 "CODES": value4, 9082}; 9083 9084let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 9085predicates.equalTo("NAME", "Lisa"); 9086 9087if(store != undefined) { 9088 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9089 transaction.update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => { 9090 transaction.commit(); 9091 console.info(`Updated row count: ${rows}`); 9092 }).catch((e: BusinessError) => { 9093 transaction.rollback(); 9094 console.error(`Updated failed, code is ${e.code},message is ${e.message}`); 9095 }); 9096 }).catch((err: BusinessError) => { 9097 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9098 }); 9099} 9100``` 9101 9102### updateSync<sup>14+</sup> 9103 9104updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): number 9105 9106Updates data in the database based on the specified **RdbPredicates** instance. 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. 9107 9108**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9109 9110**Parameters** 9111 9112| Name | Type | Mandatory| Description | 9113| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 9114| values | [ValuesBucket](#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.| 9115| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 9116| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 9117 9118**Return value** 9119 9120| Type | Description | 9121| ------ | ------------------ | 9122| number | return the number of rows updated.| 9123 9124**Error codes** 9125 9126For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 9127 9128| **ID**| **Error Message** | 9129| ------------ | ------------------------------------------------------------ | 9130| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9131| 14800000 | Inner error. | 9132| 14800011 | Database corrupted. | 9133| 14800014 | Already closed. | 9134| 14800021 | SQLite: Generic error. | 9135| 14800023 | SQLite: Access permission denied. | 9136| 14800024 | SQLite: The database file is locked. | 9137| 14800025 | SQLite: A table in the database is locked. | 9138| 14800026 | SQLite: The database is out of memory. | 9139| 14800027 | SQLite: Attempt to write a readonly database. | 9140| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9141| 14800029 | SQLite: The database is full. | 9142| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9143| 14800033 | SQLite: Data type mismatch. | 9144| 14800047 | The WAL file size exceeds the default limit. | 9145 9146**Example** 9147 9148```ts 9149let value1 = "Rose"; 9150let value2 = 22; 9151let value3 = 200.5; 9152let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9153 9154// You can use either of the following: 9155const valueBucket1: relationalStore.ValuesBucket = { 9156 'NAME': value1, 9157 'AGE': value2, 9158 'SALARY': value3, 9159 'CODES': value4, 9160}; 9161const valueBucket2: relationalStore.ValuesBucket = { 9162 NAME: value1, 9163 AGE: value2, 9164 SALARY: value3, 9165 CODES: value4, 9166}; 9167const valueBucket3: relationalStore.ValuesBucket = { 9168 "NAME": value1, 9169 "AGE": value2, 9170 "SALARY": value3, 9171 "CODES": value4, 9172}; 9173 9174let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 9175predicates.equalTo("NAME", "Lisa"); 9176 9177if(store != undefined) { 9178 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9179 try { 9180 let rows: Number = (transaction as relationalStore.Transaction).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 9181 transaction.commit(); 9182 console.info(`Updated row count: ${rows}`); 9183 } catch (e) { 9184 transaction.rollback(); 9185 console.error(`Updated failed, code is ${e.code},message is ${e.message}`); 9186 }; 9187 }).catch((err: BusinessError) => { 9188 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9189 }); 9190} 9191``` 9192 9193### delete<sup>14+</sup> 9194 9195delete(predicates: RdbPredicates):Promise<number> 9196 9197Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result. 9198 9199**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9200 9201**Parameters** 9202 9203| Name | Type | Mandatory| Description | 9204| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 9205| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 9206 9207**Return value** 9208 9209| Type | Description | 9210| --------------------- | ------------------------------- | 9211| Promise<number> | Promise used to return the number of rows deleted.| 9212 9213**Error codes** 9214 9215For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 9216 9217| **ID**| **Error Message** | 9218|-----------| ------------------------------------------------------------ | 9219| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9220| 14800000 | Inner error. | 9221| 14800011 | Database corrupted. | 9222| 14800014 | Already closed. | 9223| 14800021 | SQLite: Generic error. | 9224| 14800023 | SQLite: Access permission denied. | 9225| 14800024 | SQLite: The database file is locked. | 9226| 14800025 | SQLite: A table in the database is locked. | 9227| 14800026 | SQLite: The database is out of memory. | 9228| 14800027 | SQLite: Attempt to write a readonly database. | 9229| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9230| 14800029 | SQLite: The database is full. | 9231| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9232| 14800033 | SQLite: Data type mismatch. | 9233| 14800047 | The WAL file size exceeds the default limit. | 9234 9235**Example** 9236 9237```ts 9238let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 9239predicates.equalTo("NAME", "Lisa"); 9240 9241if(store != undefined) { 9242 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9243 transaction.delete(predicates).then((rows: Number) => { 9244 transaction.commit(); 9245 console.info(`Delete rows: ${rows}`); 9246 }).catch((e: BusinessError) => { 9247 transaction.rollback(); 9248 console.error(`Delete failed, code is ${e.code},message is ${e.message}`); 9249 }); 9250 }).catch((err: BusinessError) => { 9251 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9252 }); 9253} 9254``` 9255 9256### deleteSync<sup>14+</sup> 9257 9258deleteSync(predicates: RdbPredicates): number 9259 9260Deletes data from the database based on the specified **RdbPredicates** object. 9261 9262**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9263 9264**Parameters** 9265 9266| Name | Type | Mandatory| Description | 9267| ---------- | ------------------------------- | ---- | --------------------------------------- | 9268| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 9269 9270**Return value** 9271 9272| Type | Description | 9273| ------ | ------------------ | 9274| number | return the number of rows updated.| 9275 9276**Error codes** 9277 9278For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 9279 9280| **ID**| **Error Message** | 9281| ------------ | ------------------------------------------------------------ | 9282| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9283| 14800000 | Inner error. | 9284| 14800011 | Database corrupted. | 9285| 14800014 | Already closed. | 9286| 14800021 | SQLite: Generic error. | 9287| 14800023 | SQLite: Access permission denied. | 9288| 14800024 | SQLite: The database file is locked. | 9289| 14800025 | SQLite: A table in the database is locked. | 9290| 14800026 | SQLite: The database is out of memory. | 9291| 14800027 | SQLite: Attempt to write a readonly database. | 9292| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9293| 14800029 | SQLite: The database is full. | 9294| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9295| 14800033 | SQLite: Data type mismatch. | 9296| 14800047 | The WAL file size exceeds the default limit. | 9297 9298**Example** 9299 9300```ts 9301let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 9302predicates.equalTo("NAME", "Lisa"); 9303 9304if(store != undefined) { 9305 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9306 try { 9307 let rows: Number = (transaction as relationalStore.Transaction).deleteSync(predicates); 9308 transaction.commit(); 9309 console.info(`Delete rows: ${rows}`); 9310 } catch (e) { 9311 transaction.rollback(); 9312 console.error(`Delete failed, code is ${e.code},message is ${e.message}`); 9313 }; 9314 }).catch((err: BusinessError) => { 9315 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9316 }); 9317} 9318``` 9319 9320### query<sup>14+</sup> 9321 9322query(predicates: RdbPredicates, columns?: Array<string>): Promise<ResultSet> 9323 9324Queries 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. 9325 9326**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9327 9328**Parameters** 9329 9330| Name | Type | Mandatory| Description | 9331| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 9332| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 9333| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 9334 9335**Error codes** 9336 9337For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 9338 9339| **ID**| **Error Message** | 9340|-----------| ------------------------------------------------------------ | 9341| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9342| 14800000 | Inner error. | 9343| 14800011 | Database corrupted. | 9344| 14800014 | Already closed. | 9345| 14800021 | SQLite: Generic error. | 9346| 14800023 | SQLite: Access permission denied. | 9347| 14800024 | SQLite: The database file is locked. | 9348| 14800026 | SQLite: The database is out of memory. | 9349| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9350| 14800047 | The WAL file size exceeds the default limit. | 9351 9352**Return value** 9353 9354| Type | Description | 9355| ------------------------------------------------------- | -------------------------------------------------- | 9356| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 9357 9358**Example** 9359 9360```ts 9361let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 9362predicates.equalTo("NAME", "Rose"); 9363 9364if(store != undefined) { 9365 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9366 transaction.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 9367 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 9368 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 9369 while (resultSet.goToNextRow()) { 9370 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 9371 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 9372 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 9373 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 9374 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 9375 } 9376 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 9377 resultSet.close(); 9378 transaction.commit(); 9379 }).catch((e: BusinessError) => { 9380 transaction.rollback(); 9381 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 9382 }); 9383 }).catch((err: BusinessError) => { 9384 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9385 }); 9386} 9387``` 9388 9389### querySync<sup>14+</sup> 9390 9391querySync(predicates: RdbPredicates, columns?: Array<string>): ResultSet 9392 9393Queries data in a database based on specified conditions. This API returns the result synchronously. If complex logic and a large number of loops are involved in the operations on the **resultSet** obtained by **querySync()**, the freeze problem may occur. You are advised to perform this operation in the [taskpool](../apis-arkts/js-apis-taskpool.md) thread. 9394 9395**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9396 9397**Parameters** 9398 9399| Name | Type | Mandatory| Description | 9400| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ | 9401| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 9402| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns. <br>Default value: null.| 9403 9404**Error codes** 9405 9406For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 9407 9408| **ID**| **Error Message** | 9409| ------------ | ------------------------------------------------------------ | 9410| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9411| 14800000 | Inner error. | 9412| 14800011 | Database corrupted. | 9413| 14800014 | Already closed. | 9414| 14800021 | SQLite: Generic error. | 9415| 14800023 | SQLite: Access permission denied. | 9416| 14800024 | SQLite: The database file is locked. | 9417| 14800025 | SQLite: A table in the database is locked. | 9418| 14800026 | SQLite: The database is out of memory. | 9419| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9420| 14800047 | The WAL file size exceeds the default limit. | 9421 9422**Return value** 9423 9424| Type | Description | 9425| ----------------------- | ----------------------------------- | 9426| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 9427 9428**Example** 9429 9430```ts 9431let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 9432predicates.equalTo("NAME", "Rose"); 9433 9434if(store != undefined) { 9435 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9436 try { 9437 let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); 9438 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 9439 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 9440 while (resultSet.goToNextRow()) { 9441 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 9442 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 9443 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 9444 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 9445 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 9446 } 9447 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 9448 resultSet.close(); 9449 transaction.commit(); 9450 } catch (e) { 9451 transaction.rollback(); 9452 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 9453 }; 9454 }).catch((err: BusinessError) => { 9455 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9456 }); 9457} 9458``` 9459 9460### querySql<sup>14+</sup> 9461 9462querySql(sql: string, args?: Array<ValueType>): Promise<ResultSet> 9463 9464Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. This API uses a promise to return the result. 9465 9466**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9467 9468**Parameters** 9469 9470| Name | Type | Mandatory| Description | 9471| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 9472| sql | string | Yes | SQL statement to run. | 9473| args | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank.| 9474 9475**Return value** 9476 9477| Type | Description | 9478| ------------------------------------------------------- | -------------------------------------------------- | 9479| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 9480 9481**Error codes** 9482 9483For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 9484 9485| **ID**| **Error Message** | 9486|-----------| ------------------------------------------------------------ | 9487| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9488| 14800000 | Inner error. | 9489| 14800011 | Database corrupted. | 9490| 14800014 | Already closed. | 9491| 14800021 | SQLite: Generic error. | 9492| 14800023 | SQLite: Access permission denied. | 9493| 14800024 | SQLite: The database file is locked. | 9494| 14800025 | SQLite: A table in the database is locked. | 9495| 14800026 | SQLite: The database is out of memory. | 9496| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9497| 14800047 | The WAL file size exceeds the default limit. | 9498 9499**Example** 9500 9501```ts 9502if(store != undefined) { 9503 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9504 transaction.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then((resultSet: relationalStore.ResultSet) => { 9505 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 9506 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 9507 while (resultSet.goToNextRow()) { 9508 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 9509 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 9510 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 9511 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 9512 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 9513 } 9514 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 9515 resultSet.close(); 9516 transaction.commit(); 9517 }).catch((e: BusinessError) => { 9518 transaction.rollback(); 9519 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 9520 }); 9521 }).catch((err: BusinessError) => { 9522 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9523 }); 9524} 9525``` 9526 9527### querySqlSync<sup>14+</sup> 9528 9529querySqlSync(sql: string, args?: Array<ValueType>): ResultSet 9530 9531Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. If complex logic and a large number of loops are involved in the operations on the **resultSet** obtained by **querySync()**, the freeze problem may occur. You are advised to perform this operation in the [taskpool](../apis-arkts/js-apis-taskpool.md) thread. 9532 9533**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9534 9535**Parameters** 9536 9537| Name | Type | Mandatory| Description | 9538| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 9539| sql | string | Yes | SQL statement to run. | 9540| args | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank. <br>Default value: null.| 9541 9542**Return value** 9543 9544| Type | Description | 9545| ----------------------- | ----------------------------------- | 9546| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 9547 9548**Error codes** 9549 9550For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 9551 9552| **ID**| **Error Message** | 9553| ------------ | ------------------------------------------------------------ | 9554| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9555| 14800000 | Inner error. | 9556| 14800011 | Database corrupted. | 9557| 14800014 | Already closed. | 9558| 14800021 | SQLite: Generic error. | 9559| 14800023 | SQLite: Access permission denied. | 9560| 14800024 | SQLite: The database file is locked. | 9561| 14800025 | SQLite: A table in the database is locked. | 9562| 14800026 | SQLite: The database is out of memory. | 9563| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9564| 14800047 | The WAL file size exceeds the default limit. | 9565 9566**Example** 9567 9568```ts 9569if(store != undefined) { 9570 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9571 try { 9572 let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'"); 9573 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 9574 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 9575 while (resultSet.goToNextRow()) { 9576 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 9577 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 9578 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 9579 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 9580 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 9581 } 9582 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 9583 resultSet.close(); 9584 transaction.commit(); 9585 } catch (e) { 9586 transaction.rollback(); 9587 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 9588 }; 9589 }).catch((err: BusinessError) => { 9590 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9591 }); 9592} 9593``` 9594 9595### execute<sup>14+</sup> 9596 9597execute(sql: string, args?: Array<ValueType>): Promise<ValueType> 9598 9599Executes an SQL statement that contains specified arguments. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses a promise to return a value of the ValueType type. 9600 9601This API can be used to add, delete, and modify data, run SQL statements of the PRAGMA syntax, and create, delete, and modify a table. The type of the return value varies, depending on the execution result. 9602 9603This API does not support query, database attachment, and transaction operations. You can use [querySql](#querysql14) or [query](#query14) to query data, and use [attach](#attach12) to attach a database. 9604 9605Statements separated by semicolons (\;) are not supported. 9606 9607**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9608 9609**Parameters** 9610 9611| Name | Type | Mandatory| Description | 9612| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 9613| sql | string | Yes | SQL statement to run. | 9614| args | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank.| 9615 9616**Return value** 9617 9618| Type | Description | 9619| ------------------- | ------------------------- | 9620| Promise<[ValueType](#valuetype)> | Promise used to return the SQL execution result.| 9621 9622**Error codes** 9623 9624For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 9625 9626| **ID**| **Error Message** | 9627|-----------| ------------------------------------------------------------ | 9628| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9629| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 9630| 14800000 | Inner error. | 9631| 14800011 | Database corrupted. | 9632| 14800014 | Already closed. | 9633| 14800021 | SQLite: Generic error. | 9634| 14800023 | SQLite: Access permission denied. | 9635| 14800024 | SQLite: The database file is locked. | 9636| 14800025 | SQLite: A table in the database is locked. | 9637| 14800026 | SQLite: The database is out of memory. | 9638| 14800027 | SQLite: Attempt to write a readonly database. | 9639| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9640| 14800029 | SQLite: The database is full. | 9641| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9642| 14800033 | SQLite: Data type mismatch. | 9643| 14800047 | The WAL file size exceeds the default limit. | 9644 9645**Example** 9646 9647```ts 9648// Delete all data from the table. 9649if(store != undefined) { 9650 const SQL_DELETE_TABLE = 'DELETE FROM test'; 9651 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9652 transaction.execute(SQL_DELETE_TABLE).then((data) => { 9653 transaction.commit(); 9654 console.info(`delete result: ${data}`); 9655 }).catch((e: BusinessError) => { 9656 transaction.rollback(); 9657 console.error(`delete failed, code is ${e.code}, message is ${e.message}`); 9658 }); 9659 }).catch((err: BusinessError) => { 9660 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9661 }); 9662} 9663``` 9664 9665### executeSync<sup>14+</sup> 9666 9667executeSync(sql: string, args?: Array<ValueType>): ValueType 9668 9669Executes an SQL statement that contains specified arguments. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API returns a value of theValueType type. 9670 9671This API can be used to add, delete, and modify data, run SQL statements of the PRAGMA syntax, and create, delete, and modify a table. The type of the return value varies, depending on the execution result. 9672 9673This API does not support query, database attachment, and transaction operations. You can use [querySql](#querysql14) or [query](#query14) to query data, and use [attach](#attach12) to attach a database. 9674 9675Statements separated by semicolons (\;) are not supported. 9676 9677**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9678 9679**Parameters** 9680 9681| Name| Type | Mandatory| Description | 9682| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 9683| sql | string | Yes | SQL statement to run. | 9684| args | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If this parameter is left blank or set to **null** or **undefined**, the SQL statement is complete. <br>Default value: null.| 9685 9686**Return value** 9687 9688| Type | Description | 9689| ----------------------- | ------------------- | 9690| [ValueType](#valuetype) | SQL execution result.| 9691 9692**Error codes** 9693 9694For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 9695 9696| **ID**| **Error Message** | 9697| ------------ | ------------------------------------------------------------ | 9698| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9699| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 9700| 14800000 | Inner error. | 9701| 14800011 | Database corrupted. | 9702| 14800014 | Already closed. | 9703| 14800021 | SQLite: Generic error. | 9704| 14800023 | SQLite: Access permission denied. | 9705| 14800024 | SQLite: The database file is locked. | 9706| 14800025 | SQLite: A table in the database is locked. | 9707| 14800026 | SQLite: The database is out of memory. | 9708| 14800027 | SQLite: Attempt to write a readonly database. | 9709| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9710| 14800029 | SQLite: The database is full. | 9711| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9712| 14800033 | SQLite: Data type mismatch. | 9713| 14800047 | The WAL file size exceeds the default limit. | 9714 9715**Example** 9716 9717```ts 9718// Delete all data from the table. 9719if(store != undefined) { 9720 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9721 const SQL_DELETE_TABLE = 'DELETE FROM test'; 9722 try { 9723 let data = (transaction as relationalStore.Transaction).executeSync(SQL_DELETE_TABLE); 9724 transaction.commit(); 9725 console.info(`delete result: ${data}`); 9726 } catch (e) { 9727 transaction.rollback(); 9728 console.error(`delete failed, code is ${e.code}, message is ${e.message}`); 9729 }; 9730 }).catch((err: BusinessError) => { 9731 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9732 }); 9733} 9734``` 9735