1# @ohos.data.relationalStore (RDB Store) 2 3The relational database (RDB) store manages data based on relational models. It provides a complete mechanism for managing local databases based on the underlying SQLite. To satisfy different needs in complicated scenarios, the RDB store offers APIs for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements. It also allows sendable data to be obtained by using [ResultSet.getSendableRow](#getsendablerow12) and transferred across threads. 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 7The application may be suspended if a large amount of data is queried. To prevent this problem, 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 19> **NOTE** 20> 21> 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. 22 23## Modules to Import 24 25```ts 26import { relationalStore } from '@kit.ArkData'; 27``` 28 29## relationalStore.getRdbStore 30 31getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback<RdbStore>): void 32 33Obtains 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. 34 35If error code 14800011 is returned when this API is used to obtain an encrypted RDB store, check the value of **encrypt** in **StoreConfig**. The encrypted RDB store can be obtained successfully when **encrypt** is **true**. 36 37Currently, **getRdbStore()** does not support multi-thread concurrent operations. 38 39**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 40 41**Parameters** 42 43| Name | Type | Mandatory| Description | 44| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | 45| 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).| 46| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 47| callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes | Callback used to return the RDB store obtained. | 48 49**Error codes** 50 51For 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). 52 53| **ID**| **Error Message** | 54|-----------|---------| 55| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 56| 14800000 | Inner error. | 57| 14800010 | Invalid database path. | 58| 14800011 | Database corrupted. | 59| 14801001 | Only supported in stage mode. | 60| 14801002 | The data group id is not valid. | 61| 14800017 | Config changed. | 62| 14800021 | SQLite: Generic error. | 63| 14800022 | SQLite: Callback routine requested an abort. | 64| 14800023 | SQLite: Access permission denied. | 65| 14800027 | SQLite: Attempt to write a readonly database. | 66| 14800028 | SQLite: Some kind of disk I/O error occurred. | 67| 14800029 | SQLite: The database is full. | 68| 14800030 | SQLite: Unable to open the database file. | 69 70**Example** 71 72FA model: 73 74<!--code_no_check_fa--> 75```js 76import { featureAbility } from '@kit.AbilityKit'; 77import { BusinessError } from '@kit.BasicServicesKit'; 78 79let store: relationalStore.RdbStore | undefined = undefined; 80let context = featureAbility.getContext(); 81 82const STORE_CONFIG: relationalStore.StoreConfig = { 83 name: "RdbTest.db", 84 securityLevel: relationalStore.SecurityLevel.S3 85}; 86 87relationalStore.getRdbStore(context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 88 store = rdbStore; 89 if (err) { 90 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 91 return; 92 } 93 console.info('Get RdbStore successfully.'); 94}) 95``` 96 97Stage model: 98 99```ts 100import { UIAbility } from '@kit.AbilityKit'; 101import { window } from '@kit.ArkUI'; 102import { BusinessError } from '@kit.BasicServicesKit'; 103 104let store: relationalStore.RdbStore | undefined = undefined; 105 106class EntryAbility extends UIAbility { 107 onWindowStageCreate(windowStage: window.WindowStage) { 108 const STORE_CONFIG: relationalStore.StoreConfig = { 109 name: "RdbTest.db", 110 securityLevel: relationalStore.SecurityLevel.S3 111 }; 112 113 relationalStore.getRdbStore(this.context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 114 store = rdbStore; 115 if (err) { 116 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 117 return; 118 } 119 console.info('Get RdbStore successfully.'); 120 }) 121 } 122} 123``` 124 125## relationalStore.getRdbStore 126 127getRdbStore(context: Context, config: StoreConfig): Promise<RdbStore> 128 129Obtains 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. 130 131If error code 14800011 is returned when this API is used to obtain an encrypted RDB store, check the value of **encrypt** in **StoreConfig**. The encrypted RDB store can be obtained successfully when **encrypt** is **true**. 132 133Currently, **getRdbStore()** does not support multi-thread concurrent operations. 134 135**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 136 137**Parameters** 138 139| Name | Type | Mandatory| Description | 140| ------- | -------------------------------- | ---- | ------------------------------------------------------------ | 141| 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).| 142| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 143 144**Return value** 145 146| Type | Description | 147| ----------------------------------------- | --------------------------------- | 148| Promise<[RdbStore](#rdbstore)> | Promise used to return the **RdbStore** object obtained.| 149 150**Error codes** 151 152For 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). 153 154| **ID**| **Error Message** | 155|-----------| ------------------------------------------------------------ | 156| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 157| 14800000 | Inner error. | 158| 14800010 | Invalid database path. | 159| 14800011 | Database corrupted. | 160| 14801001 | Only supported in stage mode. | 161| 14801002 | The data group id is not valid. | 162| 14800017 | Config changed. | 163| 14800021 | SQLite: Generic error. | 164| 14800027 | SQLite: Attempt to write a readonly database. | 165| 14800028 | SQLite: Some kind of disk I/O error occurred. | 166| 14800029 | SQLite: The database is full. | 167| 14800030 | SQLite: Unable to open the database file. | 168 169**Example** 170 171FA model: 172 173<!--code_no_check_fa--> 174```js 175import { featureAbility } from '@kit.AbilityKit'; 176import { BusinessError } from '@kit.BasicServicesKit'; 177 178let store: relationalStore.RdbStore | undefined = undefined; 179let context = featureAbility.getContext(); 180 181const STORE_CONFIG: relationalStore.StoreConfig = { 182 name: "RdbTest.db", 183 securityLevel: relationalStore.SecurityLevel.S3 184}; 185 186relationalStore.getRdbStore(context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 187 store = rdbStore; 188 console.info('Get RdbStore successfully.') 189}).catch((err: BusinessError) => { 190 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 191}) 192``` 193 194Stage model: 195 196```ts 197import { UIAbility } from '@kit.AbilityKit'; 198import { window } from '@kit.ArkUI'; 199import { BusinessError } from '@kit.BasicServicesKit'; 200 201let store: relationalStore.RdbStore | undefined = undefined; 202 203class EntryAbility extends UIAbility { 204 onWindowStageCreate(windowStage: window.WindowStage) { 205 const STORE_CONFIG: relationalStore.StoreConfig = { 206 name: "RdbTest.db", 207 securityLevel: relationalStore.SecurityLevel.S3 208 }; 209 210 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 211 store = rdbStore; 212 console.info('Get RdbStore successfully.') 213 }).catch((err: BusinessError) => { 214 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 215 }) 216 } 217} 218``` 219 220## relationalStore.deleteRdbStore 221 222deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void 223 224Deletes an RDB store. This API uses an asynchronous callback to return the result. 225 226After the deletion, you are advised to set the database object to null. If a customized path is set in [StoreConfig](#storeconfig) when an RDB store is created, using this API cannot delete the RDB store. Use [deleteRdbStore<sup>10+</sup>](#relationalstoredeleterdbstore10) instead. 227 228**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 229 230**Parameters** 231 232| Name | Type | Mandatory| Description | 233| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 234| 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).| 235| name | string | Yes | Name of the RDB store to delete. | 236| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 237 238**Error codes** 239 240For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 241 242| **ID**| **Error Message** | 243|-----------|---------------------------------------| 244| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 245| 14800000 | Inner error. | 246| 14800010 | Failed to open or delete database by invalid database path. | 247 248**Example** 249 250FA model: 251 252<!--code_no_check_fa--> 253```js 254import { featureAbility } from '@kit.AbilityKit'; 255import { BusinessError } from '@kit.BasicServicesKit'; 256 257let store: relationalStore.RdbStore | undefined = undefined; 258let context = featureAbility.getContext(); 259 260relationalStore.deleteRdbStore(context, "RdbTest.db", (err: BusinessError) => { 261 if (err) { 262 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 263 return; 264 } 265 store = undefined; 266 console.info('Delete RdbStore successfully.'); 267}) 268``` 269 270Stage model: 271 272```ts 273import { UIAbility } from '@kit.AbilityKit'; 274import { window } from '@kit.ArkUI'; 275import { BusinessError } from '@kit.BasicServicesKit'; 276 277let store: relationalStore.RdbStore | undefined = undefined; 278 279class EntryAbility extends UIAbility { 280 onWindowStageCreate(windowStage: window.WindowStage){ 281 relationalStore.deleteRdbStore(this.context, "RdbTest.db", (err: BusinessError) => { 282 if (err) { 283 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 284 return; 285 } 286 store = undefined; 287 console.info('Delete RdbStore successfully.'); 288 }) 289 } 290} 291``` 292 293## relationalStore.deleteRdbStore 294 295deleteRdbStore(context: Context, name: string): Promise<void> 296 297Deletes an RDB store. This API uses a promise to return the result. 298 299After the deletion, you are advised to set the database object to null. If a customized path is set in [StoreConfig](#storeconfig) when an RDB store is created, using this API cannot delete the RDB store. Use [deleteRdbStore<sup>10+</sup>](#relationalstoredeleterdbstore10-1) instead. 300 301**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 302 303**Parameters** 304 305| Name | Type | Mandatory| Description | 306| ------- | ------- | ---- | ------------------------------------------------------------ | 307| 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).| 308| name | string | Yes | Name of the RDB store to delete. | 309 310**Return value** 311 312| Type | Description | 313| ------------------- | ------------------------- | 314| Promise<void> | Promise that returns no value.| 315 316**Error codes** 317 318For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 319 320| **ID**| **Error Message** | 321|-----------|----------------------------------------------------------------------------------| 322| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 323| 14800000 | Inner error. | 324| 14800010 | Invalid database path. | 325 326**Example** 327 328FA model: 329 330<!--code_no_check_fa--> 331```js 332import { featureAbility } from '@kit.AbilityKit'; 333import { BusinessError } from '@kit.BasicServicesKit'; 334 335let store: relationalStore.RdbStore | undefined = undefined; 336let context = featureAbility.getContext(); 337 338relationalStore.deleteRdbStore(context, "RdbTest.db").then(()=>{ 339 store = undefined; 340 console.info('Delete RdbStore successfully.'); 341}).catch((err: BusinessError) => { 342 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 343}) 344``` 345 346Stage model: 347 348```ts 349import { UIAbility } from '@kit.AbilityKit'; 350import { window } from '@kit.ArkUI'; 351import { BusinessError } from '@kit.BasicServicesKit'; 352 353let store: relationalStore.RdbStore | undefined = undefined; 354 355class EntryAbility extends UIAbility { 356 onWindowStageCreate(windowStage: window.WindowStage){ 357 relationalStore.deleteRdbStore(this.context, "RdbTest.db").then(()=>{ 358 store = undefined; 359 console.info('Delete RdbStore successfully.'); 360 }).catch((err: BusinessError) => { 361 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 362 }) 363 } 364} 365``` 366 367## relationalStore.deleteRdbStore<sup>10+</sup> 368 369deleteRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback\<void>): void 370 371Deletes an RDB store. This API uses an asynchronous callback to return the result. 372 373After 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). 374 375**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 376 377**Parameters** 378 379| Name | Type | Mandatory| Description | 380| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 381| 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).| 382| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 383| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 384 385**Error codes** 386 387For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 388 389| **ID**| **Error Message** | 390|-----------|----------| 391| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 392| 14800000 | Inner error. | 393| 14800010 | Failed to open or delete database by invalid database path. | 394| 14801001 | Only supported in stage mode. | 395| 14801002 | The data group id is not valid. | 396 397**Example** 398 399FA model: 400 401<!--code_no_check_fa--> 402```js 403import { featureAbility } from '@kit.AbilityKit'; 404import { BusinessError } from '@kit.BasicServicesKit'; 405 406let store: relationalStore.RdbStore | undefined = undefined; 407let context = featureAbility.getContext(); 408 409const STORE_CONFIG: relationalStore.StoreConfig = { 410 name: "RdbTest.db", 411 securityLevel: relationalStore.SecurityLevel.S3 412}; 413 414relationalStore.deleteRdbStore(context, STORE_CONFIG, (err: BusinessError) => { 415 if (err) { 416 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 417 return; 418 } 419 store = undefined; 420 console.info('Delete RdbStore successfully.'); 421}) 422``` 423 424Stage model: 425 426```ts 427import { UIAbility } from '@kit.AbilityKit'; 428import { window } from '@kit.ArkUI'; 429import { BusinessError } from '@kit.BasicServicesKit'; 430 431let store: relationalStore.RdbStore | undefined = undefined; 432 433class EntryAbility extends UIAbility { 434 onWindowStageCreate(windowStage: window.WindowStage){ 435 const STORE_CONFIG: relationalStore.StoreConfig = { 436 name: "RdbTest.db", 437 securityLevel: relationalStore.SecurityLevel.S3 438 }; 439 relationalStore.deleteRdbStore(this.context, STORE_CONFIG, (err: BusinessError) => { 440 if (err) { 441 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 442 return; 443 } 444 store = undefined; 445 console.info('Delete RdbStore successfully.'); 446 }) 447 } 448} 449``` 450 451## relationalStore.deleteRdbStore<sup>10+</sup> 452 453deleteRdbStore(context: Context, config: StoreConfig): Promise\<void> 454 455Deletes an RDB store. This API uses a promise to return the result. 456 457After 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). 458 459**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 460 461**Parameters** 462 463| Name | Type | Mandatory| Description | 464| ------- | --------------------------- | ---- | ------------------------------------------------------------ | 465| 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).| 466| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 467 468**Return value** 469 470| Type | Description | 471| ------------------- | ------------------------- | 472| Promise<void> | Promise that returns no value.| 473 474**Error codes** 475 476For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 477 478| **ID**| **Error Message** | 479|-----------|---------------------| 480| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 481| 801 | Capability not supported. | 482| 14800000 | Inner error. | 483| 14800010 | Invalid database path. | 484| 14801001 | Only supported in stage mode. | 485| 14801002 | The data group id is not valid. | 486 487 488**Example** 489 490FA model: 491 492<!--code_no_check_fa--> 493```js 494import { featureAbility } from "@kit.AbilityKit"; 495import { BusinessError } from '@kit.BasicServicesKit'; 496 497let store: relationalStore.RdbStore | undefined = undefined; 498let context = featureAbility.getContext(); 499 500const STORE_CONFIG: relationalStore.StoreConfig = { 501 name: "RdbTest.db", 502 securityLevel: relationalStore.SecurityLevel.S3 503}; 504 505relationalStore.deleteRdbStore(context, STORE_CONFIG).then(()=>{ 506 store = undefined; 507 console.info('Delete RdbStore successfully.'); 508}).catch((err: BusinessError) => { 509 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 510}) 511``` 512 513Stage model: 514 515```ts 516import { UIAbility } from '@kit.AbilityKit'; 517import { window } from '@kit.ArkUI'; 518import { BusinessError } from '@kit.BasicServicesKit'; 519 520let store: relationalStore.RdbStore | undefined = undefined; 521 522class EntryAbility extends UIAbility { 523 onWindowStageCreate(windowStage: window.WindowStage){ 524 const STORE_CONFIG: relationalStore.StoreConfig = { 525 name: "RdbTest.db", 526 securityLevel: relationalStore.SecurityLevel.S3 527 }; 528 relationalStore.deleteRdbStore(this.context, STORE_CONFIG).then(()=>{ 529 store = undefined; 530 console.info('Delete RdbStore successfully.'); 531 }).catch((err: BusinessError) => { 532 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 533 }) 534 } 535} 536``` 537 538## StoreConfig 539 540Defines the RDB store configuration. 541 542| Name | Type | Mandatory| Description | 543| ------------- | ------------- | ---- | --------------------------------------------------------- | 544| name | string | Yes | Database file name, which is the unique identifier of the database.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 545| securityLevel | [SecurityLevel](#securitylevel) | Yes | Security level of the RDB store.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 546| 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| 547| dataGroupId<sup>10+</sup> | string | No| Application group ID, which needs to be obtained from AppGallery. This parameter is not supported currently.<br>**Model restriction**: This attribute can be used only in the stage model.<br>This parameter is supported since API version 10. The **RdbStore** instance is created in the sandbox directory corresponding to the specified **dataGroupId**. 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| 548| 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| 549| 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| 550| allowRebuild<sup>12+</sup> | boolean | No| Whether auto rebuild is allowed when the RDB store is corrupted. The default value is **false**.<br>The value **true** means auto rebuild is allowed.<br>The value **false** means the opposite.<br>This parameter is supported since API version 12.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 551| isReadOnly<sup>12+</sup> | boolean | No| Whether the RDB store is read-only. The default value is **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| 552| pluginLibs<sup>12+</sup> | Array\<string> | No| Dynamic libraries with capabilities such as Full-Text Search (FTS).<br>**Constraints**: The maximum number of dynamic libraries is 16. If the number of dynamic library names exceeds 16, the RDB store fails to be opened and an error is returned. The dynamic library must be in the sandbox directory or system directory of the application. If the dynamic library cannot be loaded, the RDB store fails to be opened and an error is returned.<br>The dynamic library name must be a complete path. For example, **[context.bundleCodeDir+ "/libs/arm64/" + libtokenizer.so]**, where **context.bundleCodeDir** is the application sandbox path, **/libs/arm64/** indicates the subdirectory, and **libtokenizer.so** is the dynamic library name. If this parameter is left blank, dynamic libraries are not loaded by default.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 553 554## SecurityLevel 555 556Enumerates the RDB store security levels. Use the enum name rather than the enum value. 557 558> **NOTE** 559> 560> 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 the [Cross-Device Data Sync Mechanism](../../database/access-control-by-device-and-data-level.md#access-control-mechanism-in-cross-device-sync). 561 562**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 563 564| Name| Value | Description | 565| ---- | ---- | ------------------------------------------------------------ | 566| 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.| 567| 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.| 568| 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.| 569| 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.| 570 571## AssetStatus<sup>10+</sup> 572 573Enumerates the asset statuses. Use the enum name rather than the enum value. 574 575**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 576 577| Name | Value | Description | 578| ------------------------------- | --- | -------------- | 579| ASSET_NORMAL | 1 | The asset is in normal status. | 580| ASSET_INSERT | 2 | The asset is to be inserted to the cloud.| 581| ASSET_UPDATE | 3 | The asset is to be updated to the cloud.| 582| ASSET_DELETE | 4 | The asset is to be deleted from the cloud.| 583| ASSET_ABNORMAL | 5 | The asset is in abnormal status. | 584| ASSET_DOWNLOADING | 6 | The asset is being downloaded to a local device.| 585 586## Asset<sup>10+</sup> 587 588Defines information about an asset (such as a document, image, and video). 589 590**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 591 592| Name | Type | Mandatory | Description | 593| ----------- | --------------------------- | --- | ------------ | 594| name | string | Yes | Asset name. | 595| uri | string | Yes | Asset URI, which is an absolute path in the system. | 596| path | string | Yes | Application sandbox path of the asset. | 597| createTime | string | Yes | Time when the asset was created. | 598| modifyTime | string | Yes | Time when the asset was last modified.| 599| size | string | Yes | Size of the asset. | 600| status | [AssetStatus](#assetstatus10) | No | Asset status. The default value is **ASSET_NORMAL**. | 601 602## Assets<sup>10+</sup> 603 604type Assets = Asset[] 605 606Defines an array of the [Asset](#asset10) type. 607 608**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 609 610| Type | Description | 611| ------- | -------------------- | 612| [Asset](#asset10)[] | Array of assets. | 613 614## ValueType 615 616type ValueType = null | number | string | boolean | Uint8Array | Asset | Assets | Float32Array | bigint 617 618Enumerates the types of the value in a KV pair. The type varies with the parameter function. 619 620**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 621 622| Type | Description | 623| ------- | -------------------- | 624| null<sup>10+</sup> | Null. | 625| number | Number. | 626| string | String. | 627| boolean | Boolean.| 628| Uint8Array<sup>10+</sup> | Uint8 array. | 629| Asset<sup>10+</sup> | [Asset](#asset10).<br>If the field type is **Asset**, the type in the SQL statement for creating a table must be **ASSET**.| 630| Assets<sup>10+</sup> | [Assets](#assets10).<br>If the field type is **Assets**, the type in the SQL statement for creating a table must be **ASSETS**.| 631| 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)**.| 632| 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.| 633 634## ValuesBucket 635 636type ValuesBucket = Record<string, ValueType> 637 638Defines the data in the form of a KV pair, which cannot be transferred across threads. 639 640**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 641 642| Type | Description | 643| ---------------- | ---------------------------- | 644| 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).| 645 646## PRIKeyType<sup>10+</sup> 647 648type PRIKeyType = number | string 649 650Enumerates the types of the primary key in a row of a database table. 651 652**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 653 654| Type | Description | 655| ---------------- | ---------------------------------- | 656| number | The primary key is a number.| 657| string | The primary key is a string.| 658 659## UTCTime<sup>10+</sup> 660 661type UTCTime = Date 662 663Represents the data type of the UTC time. 664 665**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 666 667| Type| Description | 668| ---- | --------------- | 669| Date | UTC time.| 670 671## ModifyTime<sup>10+</sup> 672 673type ModifyTime = Map<PRIKeyType, UTCTime> 674 675Represents the data type of the primary key and modification time of a database table. 676 677**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 678 679| Type | Description | 680| ------------------------------------------------------- | ------------------------------------------------------------ | 681| 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.| 682 683## SyncMode 684 685Enumerates the database sync modes. Use the enum name rather than the enum value. 686 687| Name | Value | Description | 688| -------------- | ---- | ---------------------------------- | 689| SYNC_MODE_PUSH | 0 | Push data from a local device to a remote device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 690| SYNC_MODE_PULL | 1 | Pull data from a remote device to a local device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 691| SYNC_MODE_TIME_FIRST<sup>10+</sup> | 4 | Synchronize with the data with the latest modification time.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 692| SYNC_MODE_NATIVE_FIRST<sup>10+</sup> | 5 | Synchronize data from a local device to the cloud.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 693| SYNC_MODE_CLOUD_FIRST<sup>10+</sup> | 6 | Synchronize data from the cloud to a local device.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 694 695## Origin<sup>11+</sup> 696 697Enumerates the data sources. Use the enum name rather than the enum value. 698 699**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 700 701| Name | Value | Description | 702| -------------- | ---- | ---------------------------------- | 703| LOCAL | 0 | Local data. | 704| CLOUD | 1 | Cloud data. | 705| REMOTE | 2 | Remote device data.| 706 707## Field<sup>11+</sup> 708 709Enumerates the special fields used in predicates. Use the enum name rather than the enum value. 710 711**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 712 713| Name | Value | Description | 714| -------------- | ---- | ---------------------------------- | 715| CURSOR_FIELD | '#_cursor' | Field name to be searched based on the cursor.| 716| ORIGIN_FIELD | '#_origin' | Data source to be searched based on the cursor. | 717| 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.| 718| 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.| 719| 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.| 720| 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.| 721| SHARING_RESOURCE_FIELD | '#_sharing_resource_field' | Resource shared. It fills in the result set returned when the shared resource is searched.| 722 723## SubscribeType 724 725Enumerates the subscription types. Use the enum name rather than the enum value. 726 727| Name | Value | Description | 728| --------------------- | ---- | ------------------ | 729| SUBSCRIBE_TYPE_REMOTE | 0 | Subscribe to remote data changes.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 730| SUBSCRIBE_TYPE_CLOUD<sup>10+</sup> | 1 | Subscribe to cloud data changes.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 731| SUBSCRIBE_TYPE_CLOUD_DETAILS<sup>10+</sup> | 2 | Subscribe to cloud data change details.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 732| SUBSCRIBE_TYPE_LOCAL_DETAILS<sup>12+</sup> | 3 | Subscribe to details of the local data change.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 733 734## RebuildType<sup>12+</sup> 735 736Enumerates the RDB store rebuild types. Use the enum name rather than the enum value. 737 738**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 739 740| Name | Value | Description | 741| ------- | ---- | ---------------------------------------- | 742| NONE | 0 | The RDB store is not rebuilt. | 743| REBUILT | 1 | An empty RDB store is built.| 744| REPAIRED | 2 | The RDB store is repaired, with undamaged data restored. <!--RP2-->Currently, this value is available only to a [vector database](js-apis-data-relationalStore-sys.md#storeconfig).<!--RP2End-->| 745 746## ChangeType<sup>10+</sup> 747 748Enumerates data change types. Use the enum name rather than the enum value. 749 750**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 751 752| Name | Value | Description | 753| -------------------------- | --- | -------------------------- | 754| DATA_CHANGE | 0 | Data change. | 755| ASSET_CHANGE | 1 | Asset change.| 756 757## ChangeInfo<sup>10+</sup> 758 759Represents the detail information about the device-cloud sync process. 760 761**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 762 763| Name | Type | Mandatory| Description | 764| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ | 765| table | string | Yes | Name of the table with data changes. | 766| type | [ChangeType](#changetype10) | Yes | Type of the data changed, which can be data or asset. | 767| 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.| 768| 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.| 769| 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.| 770 771## DistributedType<sup>10+</sup> 772 773Enumerates the distributed table types. Use the enum name rather than the enum value. 774 775| Name | Value | Description | 776| ------------------ | --- | -------------------------------------------------------------------------------------------------- | 777| DISTRIBUTED_DEVICE | 0 | Distributed database table between devices.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 778| DISTRIBUTED_CLOUD | 1 | Distributed database table between the device and the cloud.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 779 780## DistributedConfig<sup>10+</sup> 781 782Defines the configuration of the distributed mode of tables. 783 784**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 785 786| Name | Type | Mandatory| Description | 787| -------- | ------- | ---- | ------------------------------------------------------------ | 788| 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.| 789 790## ConflictResolution<sup>10+</sup> 791 792Defines the resolution to use when a conflict occurs during data insertion or modification. Use the enum name rather than the enum value. 793 794**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 795 796| Name | Value | Description | 797| -------------------- | ---- | ------------------------------------------------------------ | 798| ON_CONFLICT_NONE | 0 | No operation is performed.| 799| ON_CONFLICT_ROLLBACK | 1 | Abort the SQL statement and roll back the current transaction. | 800| 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.| 801| 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.| 802| ON_CONFLICT_IGNORE | 4 | Skip the rows that contain constraint violations and continue to process the subsequent rows of the SQL statement.| 803| 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.| 804 805## Progress<sup>10+</sup> 806 807Enumerates the stages in the device-cloud sync progress. Use the enum name rather than the enum value. 808 809**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 810 811| Name | Value | Description | 812| ---------------- | ---- | ------------------------ | 813| SYNC_BEGIN | 0 | The device-cloud sync starts. | 814| SYNC_IN_PROGRESS | 1 | The device-cloud sync is in progress.| 815| SYNC_FINISH | 2 | The device-cloud sync is complete.| 816 817## Statistic<sup>10+</sup> 818 819Represents the device-cloud sync statistics information. 820 821**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 822 823| Name | Type | Mandatory| Description | 824| ---------- | ------ | ---- | ---------------------------------------- | 825| total | number | Yes | Total number of rows to be synchronized between the device and cloud in the database table. | 826| successful | number | Yes | Number of rows that are successfully synchronized between the device and cloud in the database table. | 827| failed | number | Yes | Number of rows that failed to be synchronized between the device and cloud in the database table. | 828| remained | number | Yes | Number of rows that are not executed for device-cloud sync in the database table.| 829 830## TableDetails<sup>10+</sup> 831 832Represents the upload and download statistics of device-cloud sync tasks. 833 834**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 835 836| Name | Type | Mandatory| Description | 837| -------- | ------------------------- | ---- | ------------------------------------------ | 838| upload | [Statistic](#statistic10) | Yes | Statistics of the device-cloud upload tasks.| 839| download | [Statistic](#statistic10) | Yes | Statistics of the device-cloud download tasks.| 840 841## ProgressCode<sup>10+</sup> 842 843Enumerates the device-cloud sync states. Use the enum name rather than the enum value. 844 845**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 846 847| Name | Value | Description | 848| --------------------- | ---- | ------------------------------------------------------------ | 849| SUCCESS | 0 | The device-cloud sync is successful. | 850| UNKNOWN_ERROR | 1 | An unknown error occurs during device-cloud sync. | 851| NETWORK_ERROR | 2 | A network error occurs during device-cloud sync. | 852| CLOUD_DISABLED | 3 | The cloud is unavailable. | 853| 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.| 854| 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.| 855| NO_SPACE_FOR_ASSET | 6 | The remaining cloud space is less than the size of the data to be synchronized. | 856| BLOCKED_BY_NETWORK_STRATEGY<sup>12+</sup> | 7 | The device-cloud sync is blocked due to the network strategy. | 857 858## ProgressDetails<sup>10+</sup> 859 860Represents the statistics of the overall device-cloud sync (upload and download) tasks. 861 862**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 863 864| Name | Type | Mandatory| Description | 865| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | 866| schedule | [Progress](#progress10) | Yes | Device-cloud sync progress. | 867| code | [ProgressCode](#progresscode10) | Yes | Device-cloud sync state. | 868| 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.| 869 870## SqlExecutionInfo<sup>12+</sup> 871 872Represents statistics about SQL statements executed by the database. 873 874**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 875 876| Name | Type | Read-Only| Optional |Description | 877| -------- | ------------------------------------------------- | ---- | ---- | -------------------------------------------------------- | 878| 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. | 879| totalTime<sup>12+</sup> | number | Yes | No | Total time used to execute the SQL statements, in μs. | 880| waitTime<sup>12+</sup> | number | Yes | No | Time used to obtain the handle, in μs. | 881| prepareTime<sup>12+</sup> | number | Yes | No | Time used to get the SQL statements ready and bind parameters, in μs. | 882| executeTime<sup>12+</sup> | number | Yes | No | Total time used to execute the SQL statements, in μs.| 883 884## RdbPredicates 885 886Defines 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. Data of the Sendable type cannot be passed across threads. 887 888### constructor 889 890constructor(name: string) 891 892A constructor used to create an **RdbPredicates** object. 893 894**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 895 896**Parameters** 897 898| Name| Type | Mandatory| Description | 899| ------ | ------ | ---- | ------------ | 900| name | string | Yes | Database table name.| 901 902**Error codes** 903 904For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 905 906| **ID**| **Error Message** | 907| --------- |----------------------------------------------------------------------------------------------------------------| 908| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 909 910**Example** 911 912```ts 913let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 914``` 915 916### inDevices 917 918inDevices(devices: Array<string>): RdbPredicates 919 920Sets an **RdbPredicates** object to specify the remote devices to connect during the distributed database sync. 921 922> **NOTE** 923> 924> **devices** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 925If **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. 926 927**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 928 929**Parameters** 930 931| Name | Type | Mandatory| Description | 932| ------- | ------------------- | ---- | -------------------------- | 933| devices | Array<string> | Yes | IDs of the remote devices in the same network.| 934 935**Return value** 936 937| Type | Description | 938| ------------------------------------ | -------------------------- | 939| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 940 941**Error codes** 942 943For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 944 945| **ID**| **Error Message** | 946| --------- |----------------------------------------------------------------------------------------------------------------| 947| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 948 949**Example** 950 951```ts 952import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 953import { BusinessError } from '@kit.BasicServicesKit'; 954 955let dmInstance: distributedDeviceManager.DeviceManager; 956let deviceIds: Array<string> = []; 957 958try { 959 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 960 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 961 for (let i = 0; i < devices.length; i++) { 962 deviceIds[i] = devices[i].networkId!; 963 } 964} catch (err) { 965 let code = (err as BusinessError).code; 966 let message = (err as BusinessError).message 967 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 968} 969 970let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 971predicates.inDevices(deviceIds); 972``` 973 974### inAllDevices 975 976inAllDevices(): RdbPredicates 977 978Sets an **RdbPredicates** instance to specify all remote devices to connect during the distributed database sync. 979 980 981**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 982 983**Return value** 984 985| Type | Description | 986| ------------------------------------ | -------------------------- | 987| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 988 989**Example** 990 991```ts 992let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 993predicates.inAllDevices(); 994``` 995 996### equalTo 997 998equalTo(field: string, value: ValueType): RdbPredicates 999 1000Sets an **RdbPredicates** object to match the fields in the specified column that are equal to the given value. 1001 1002**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1003 1004**Parameters** 1005 1006| Name| Type | Mandatory| Description | 1007| ------ | ----------------------- | ---- | ---------------------- | 1008| field | string | Yes | Column name in the database table. | 1009| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1010 1011**Return value** 1012 1013| Type | Description | 1014| ------------------------------------ | -------------------------- | 1015| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1016 1017**Error codes** 1018 1019For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1020 1021| **ID**| **Error Message** | 1022| --------- |----------------------------------------------------------------------------------------------------------------| 1023| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1024 1025**Example** 1026 1027```ts 1028// Locate data of Lisa in the EMPLOYEE table. 1029let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1030predicates.equalTo("NAME", "Lisa"); 1031``` 1032 1033 1034### notEqualTo 1035 1036notEqualTo(field: string, value: ValueType): RdbPredicates 1037 1038Sets an **RdbPredicates** object to match the fields in the specified column that are not equal to the given value. 1039 1040**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1041 1042**Parameters** 1043 1044| Name| Type | Mandatory| Description | 1045| ------ | ----------------------- | ---- | ---------------------- | 1046| field | string | Yes | Column name in the database table. | 1047| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1048 1049**Return value** 1050 1051| Type | Description | 1052| ------------------------------------ | -------------------------- | 1053| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1054 1055**Error codes** 1056 1057For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1058 1059| **ID**| **Error Message** | 1060| --------- |----------------------------------------------------------------------------------------------------------------| 1061| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1062 1063**Example** 1064 1065```ts 1066// Locate data of the employees whose name is not Lisa in the table. 1067let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1068predicates.notEqualTo("NAME", "Lisa"); 1069``` 1070 1071 1072### beginWrap 1073 1074beginWrap(): RdbPredicates 1075 1076Adds a left parenthesis to the **RdbPredicates**. 1077 1078**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1079 1080**Return value** 1081 1082| Type | Description | 1083| ------------------------------------ | ------------------------- | 1084| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.| 1085 1086**Example** 1087 1088```ts 1089let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1090predicates.equalTo("NAME", "Lisa") 1091 .beginWrap() 1092 .equalTo("AGE", 18) 1093 .or() 1094 .equalTo("SALARY", 200.5) 1095 .endWrap() 1096``` 1097 1098### endWrap 1099 1100endWrap(): RdbPredicates 1101 1102Adds a right parenthesis to the **RdbPredicates**. 1103 1104**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1105 1106**Return value** 1107 1108| Type | Description | 1109| ------------------------------------ | ------------------------- | 1110| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.| 1111 1112**Example** 1113 1114```ts 1115let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1116predicates.equalTo("NAME", "Lisa") 1117 .beginWrap() 1118 .equalTo("AGE", 18) 1119 .or() 1120 .equalTo("SALARY", 200.5) 1121 .endWrap() 1122``` 1123 1124### or 1125 1126or(): RdbPredicates 1127 1128Adds the OR condition to the **RdbPredicates**. 1129 1130**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1131 1132**Return value** 1133 1134| Type | Description | 1135| ------------------------------------ | ------------------------- | 1136| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.| 1137 1138**Example** 1139 1140```ts 1141// Locate the employees named Lisa or Rose in the table. 1142let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1143predicates.equalTo("NAME", "Lisa") 1144 .or() 1145 .equalTo("NAME", "Rose") 1146``` 1147 1148### and 1149 1150and(): RdbPredicates 1151 1152Adds the AND condition to the **RdbPredicates**. 1153 1154**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1155 1156**Return value** 1157 1158| Type | Description | 1159| ------------------------------------ | ------------------------- | 1160| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.| 1161 1162**Example** 1163 1164```ts 1165// Locate the field with name of Lisa and salary of 200.5 in the table. 1166let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1167predicates.equalTo("NAME", "Lisa") 1168 .and() 1169 .equalTo("SALARY", 200.5) 1170``` 1171 1172### contains 1173 1174contains(field: string, value: string): RdbPredicates 1175 1176Sets an **RdbPredicates** object to match the fields in the specified column that contain the given value. 1177 1178**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1179 1180**Parameters** 1181 1182| Name| Type | Mandatory| Description | 1183| ------ | ------ | ---- | ---------------------- | 1184| field | string | Yes | Column name in the database table. | 1185| value | string | Yes | Value to match the **RdbPredicates**.| 1186 1187**Return value** 1188 1189| Type | Description | 1190| ------------------------------------ | -------------------------- | 1191| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1192 1193**Error codes** 1194 1195For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1196 1197| **ID**| **Error Message** | 1198| --------- |----------------------------------------------------------------------------------------------------------------| 1199| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1200 1201**Example** 1202 1203```ts 1204// Locate data of the employees whose name contains os, for example, Rose, in the table. 1205let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1206predicates.contains("NAME", "os"); 1207``` 1208 1209### beginsWith 1210 1211beginsWith(field: string, value: string): RdbPredicates 1212 1213Sets an **RdbPredicates** object to match the fields in the specified column that begin with the given value. 1214 1215**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1216 1217**Parameters** 1218 1219| Name| Type | Mandatory| Description | 1220| ------ | ------ | ---- | ---------------------- | 1221| field | string | Yes | Column name in the database table. | 1222| value | string | Yes | Value to match the **RdbPredicates**.| 1223 1224**Return value** 1225 1226| Type | Description | 1227| ------------------------------------ | -------------------------- | 1228| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1229 1230**Error codes** 1231 1232For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1233 1234| **ID**| **Error Message** | 1235| --------- |----------------------------------------------------------------------------------------------------------------| 1236| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1237 1238**Example** 1239 1240```ts 1241// Locate data of the employees whose name begins with Li, for example, Lisa, in the table. 1242let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1243predicates.beginsWith("NAME", "Li"); 1244``` 1245 1246### endsWith 1247 1248endsWith(field: string, value: string): RdbPredicates 1249 1250Sets an **RdbPredicates** object to match the fields in the specified column that end with the given value. 1251 1252**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1253 1254**Parameters** 1255 1256| Name| Type | Mandatory| Description | 1257| ------ | ------ | ---- | ---------------------- | 1258| field | string | Yes | Column name in the database table. | 1259| value | string | Yes | Value to match the **RdbPredicates**.| 1260 1261**Return value** 1262 1263| Type | Description | 1264| ------------------------------------ | -------------------------- | 1265| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1266 1267**Error codes** 1268 1269For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1270 1271| **ID**| **Error Message** | 1272| --------- |----------------------------------------------------------------------------------------------------------------| 1273| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1274 1275**Example** 1276 1277```ts 1278// Locate data of the employees whose name ends with se, for example, Rose, in the table. 1279let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1280predicates.endsWith("NAME", "se"); 1281``` 1282 1283### isNull 1284 1285isNull(field: string): RdbPredicates 1286 1287Sets an **RdbPredicates** object to match the fields in the specified column that are **null**. 1288 1289**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1290 1291**Parameters** 1292 1293| Name| Type | Mandatory| Description | 1294| ------ | ------ | ---- | ------------------ | 1295| field | string | Yes | Column name in the database table.| 1296 1297**Return value** 1298 1299| Type | Description | 1300| ------------------------------------ | -------------------------- | 1301| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1302 1303**Error codes** 1304 1305For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1306 1307| **ID**| **Error Message** | 1308| --------- |----------------------------------------------------------------------------------------------------------------| 1309| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1310 1311**Example** 1312 1313```ts 1314let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1315predicates.isNull("NAME"); 1316``` 1317 1318### isNotNull 1319 1320isNotNull(field: string): RdbPredicates 1321 1322Sets an **RdbPredicates** object to match the fields in the specified column that are not **null**. 1323 1324**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1325 1326**Parameters** 1327 1328| Name| Type | Mandatory| Description | 1329| ------ | ------ | ---- | ------------------ | 1330| field | string | Yes | Column name in the database table.| 1331 1332**Return value** 1333 1334| Type | Description | 1335| ------------------------------------ | -------------------------- | 1336| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1337 1338**Error codes** 1339 1340For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1341 1342| **ID**| **Error Message** | 1343| --------- |----------------------------------------------------------------------------------------------------------------| 1344| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1345 1346**Example** 1347 1348```ts 1349let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1350predicates.isNotNull("NAME"); 1351``` 1352 1353### like 1354 1355like(field: string, value: string): RdbPredicates 1356 1357Sets an **RdbPredicates** object to match the fields in the specified column that are similar to the given value. 1358 1359**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1360 1361**Parameters** 1362 1363| Name| Type | Mandatory| Description | 1364| ------ | ------ | ---- | ---------------------- | 1365| field | string | Yes | Column name in the database table. | 1366| value | string | Yes | Value to match the **RdbPredicates**.| 1367 1368**Return value** 1369 1370| Type | Description | 1371| ------------------------------------ | -------------------------- | 1372| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1373 1374**Error codes** 1375 1376For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1377 1378| **ID**| **Error Message** | 1379| --------- |----------------------------------------------------------------------------------------------------------------| 1380| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1381 1382**Example** 1383 1384```ts 1385// Locate data of the employees whose name is similar to os in the table, for example, Rose. 1386let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1387predicates.like("NAME", "%os%"); 1388``` 1389 1390### glob 1391 1392glob(field: string, value: string): RdbPredicates 1393 1394Sets an **RdbPredicates** object to locate the fields in the specified column that match the given string. 1395 1396**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1397 1398**Parameters** 1399 1400| Name| Type | Mandatory| Description | 1401| ------ | ------ | ---- | ------------------------------------------------------------ | 1402| field | string | Yes | Column name in the database table. | 1403| 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.| 1404 1405**Return value** 1406 1407| Type | Description | 1408| ------------------------------------ | -------------------------- | 1409| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1410 1411**Error codes** 1412 1413For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1414 1415| **ID**| **Error Message** | 1416| --------- |----------------------------------------------------------------------------------------------------------------| 1417| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1418 1419**Example** 1420 1421```ts 1422// Locate data of the employees whose name matches the "?h*g" string in the table. 1423let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1424predicates.glob("NAME", "?h*g"); 1425``` 1426 1427### between 1428 1429between(field: string, low: ValueType, high: ValueType): RdbPredicates 1430 1431Sets an **RdbPredicates** object to match the fields in the specified column that are within the given range (including the min. and max. values). 1432 1433**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1434 1435**Parameters** 1436 1437| Name| Type | Mandatory| Description | 1438| ------ | ----------------------- | ---- | -------------------------- | 1439| field | string | Yes | Column name in the database table. | 1440| low | [ValueType](#valuetype) | Yes | Minimum value to match. | 1441| high | [ValueType](#valuetype) | Yes | Maximum value to match.| 1442 1443**Return value** 1444 1445| Type | Description | 1446| ------------------------------------ | -------------------------- | 1447| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1448 1449**Error codes** 1450 1451For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1452 1453| **ID**| **Error Message** | 1454| --------- |----------------------------------------------------------------------------------------------------------------| 1455| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1456 1457**Example** 1458 1459```ts 1460// Locate data of the employees with age between 10 and 50 (including 10 and 50) in the table. 1461let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1462predicates.between("AGE", 10, 50); 1463``` 1464 1465### notBetween 1466 1467notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates 1468 1469Sets an **RdbPredicates** object to match the fields in the specified column that are out of the given range (excluding the min. and max. values). 1470 1471**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1472 1473**Parameters** 1474 1475| Name| Type | Mandatory| Description | 1476| ------ | ----------------------- | ---- | -------------------------- | 1477| field | string | Yes | Column name in the database table. | 1478| low | [ValueType](#valuetype) | Yes | Minimum value to match. | 1479| high | [ValueType](#valuetype) | Yes | Maximum value to match.| 1480 1481**Return value** 1482 1483| Type | Description | 1484| ------------------------------------ | -------------------------- | 1485| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1486 1487**Error codes** 1488 1489For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1490 1491| **ID**| **Error Message** | 1492| --------- |----------------------------------------------------------------------------------------------------------------| 1493| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1494 1495**Example** 1496 1497```ts 1498// Locate data of the employees who are younger than 10 or older than 50 in the table. 1499let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1500predicates.notBetween("AGE", 10, 50); 1501``` 1502 1503### greaterThan 1504 1505greaterThan(field: string, value: ValueType): RdbPredicates 1506 1507Sets an **RdbPredicates** object to match the fields in the specified column that are greater than the given value. 1508 1509**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1510 1511**Parameters** 1512 1513| Name| Type | Mandatory| Description | 1514| ------ | ----------------------- | ---- | ---------------------- | 1515| field | string | Yes | Column name in the database table. | 1516| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1517 1518**Return value** 1519 1520| Type | Description | 1521| ------------------------------------ | -------------------------- | 1522| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1523 1524**Error codes** 1525 1526For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1527 1528| **ID**| **Error Message** | 1529| --------- |----------------------------------------------------------------------------------------------------------------| 1530| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1531 1532**Example** 1533 1534```ts 1535// Locate data of the employees who are older than 18 in the table. 1536let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1537predicates.greaterThan("AGE", 18); 1538``` 1539 1540### lessThan 1541 1542lessThan(field: string, value: ValueType): RdbPredicates 1543 1544Sets an **RdbPredicates** object to match the fields in the specified column that are less than the given value. 1545 1546**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1547 1548**Parameters** 1549 1550| Name| Type | Mandatory| Description | 1551| ------ | ----------------------- | ---- | ---------------------- | 1552| field | string | Yes | Column name in the database table. | 1553| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1554 1555**Return value** 1556 1557| Type | Description | 1558| ------------------------------------ | -------------------------- | 1559| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1560 1561**Error codes** 1562 1563For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1564 1565| **ID**| **Error Message** | 1566| --------- |----------------------------------------------------------------------------------------------------------------| 1567| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1568 1569**Example** 1570 1571```ts 1572// Locate data of the employees who are younger than 20 in the table. 1573let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1574predicates.lessThan("AGE", 20); 1575``` 1576 1577### greaterThanOrEqualTo 1578 1579greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1580 1581Sets an **RdbPredicates** object to match the fields in the specified column that are greater than or equal to the given value. 1582 1583**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1584 1585**Parameters** 1586 1587| Name| Type | Mandatory| Description | 1588| ------ | ----------------------- | ---- | ---------------------- | 1589| field | string | Yes | Column name in the database table. | 1590| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1591 1592**Return value** 1593 1594| Type | Description | 1595| ------------------------------------ | -------------------------- | 1596| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1597 1598**Error codes** 1599 1600For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1601 1602| **ID**| **Error Message** | 1603| --------- |----------------------------------------------------------------------------------------------------------------| 1604| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1605 1606**Example** 1607 1608```ts 1609// Locate data of the employees who are 18 or older in the table. 1610let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1611predicates.greaterThanOrEqualTo("AGE", 18); 1612``` 1613 1614### lessThanOrEqualTo 1615 1616lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1617 1618Sets an **RdbPredicates** object to match the fields in the specified column that are less than or equal to the given value. 1619 1620**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1621 1622**Parameters** 1623 1624| Name| Type | Mandatory| Description | 1625| ------ | ----------------------- | ---- | ---------------------- | 1626| field | string | Yes | Column name in the database table. | 1627| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1628 1629**Return value** 1630 1631| Type | Description | 1632| ------------------------------------ | -------------------------- | 1633| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1634 1635**Error codes** 1636 1637For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1638 1639| **ID**| **Error Message** | 1640| --------- |----------------------------------------------------------------------------------------------------------------| 1641| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1642 1643**Example** 1644 1645```ts 1646// Locate data of the employees who are 20 or younger in the table. 1647let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1648predicates.lessThanOrEqualTo("AGE", 20); 1649``` 1650 1651### orderByAsc 1652 1653orderByAsc(field: string): RdbPredicates 1654 1655Sets an **RdbPredicates** object to sort the fields in the specified column in ascending order. 1656 1657**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1658 1659**Parameters** 1660 1661| Name| Type | Mandatory| Description | 1662| ------ | ------ | ---- | ------------------ | 1663| field | string | Yes | Column name in the database table.| 1664 1665**Return value** 1666 1667| Type | Description | 1668| ------------------------------------ | -------------------------- | 1669| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1670 1671**Error codes** 1672 1673For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1674 1675| **ID**| **Error Message** | 1676| --------- |----------------------------------------------------------------------------------------------------------------| 1677| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1678 1679**Example** 1680 1681```ts 1682let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1683predicates.orderByAsc("NAME"); 1684``` 1685 1686### orderByDesc 1687 1688orderByDesc(field: string): RdbPredicates 1689 1690Sets an **RdbPredicates** object to sort the fields in the specified column in descending order. 1691 1692**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1693 1694**Parameters** 1695 1696| Name| Type | Mandatory| Description | 1697| ------ | ------ | ---- | ------------------ | 1698| field | string | Yes | Column name in the database table.| 1699 1700**Return value** 1701 1702| Type | Description | 1703| ------------------------------------ | -------------------------- | 1704| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1705 1706**Error codes** 1707 1708For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1709 1710| **ID**| **Error Message** | 1711| --------- |----------------------------------------------------------------------------------------------------------------| 1712| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1713 1714**Example** 1715 1716```ts 1717let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1718predicates.orderByDesc("AGE"); 1719``` 1720 1721### distinct 1722 1723distinct(): RdbPredicates 1724 1725Sets an **RdbPredicates** object to filter out duplicate records. 1726 1727**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1728 1729**Return value** 1730 1731| Type | Description | 1732| ------------------------------------ | ------------------------------ | 1733| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.| 1734 1735**Example** 1736 1737```ts 1738let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1739predicates.equalTo("NAME", "Rose").distinct(); 1740``` 1741 1742### limitAs 1743 1744limitAs(value: number): RdbPredicates 1745 1746Sets an **RdbPredicates** object to specify the maximum number of records. 1747 1748**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1749 1750**Parameters** 1751 1752| Name| Type | Mandatory| Description | 1753| ------ | ------ | ---- | ---------------- | 1754| value | number | Yes | Maximum number of records.| 1755 1756**Return value** 1757 1758| Type | Description | 1759| ------------------------------------ | ------------------------------------ | 1760| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.| 1761 1762**Error codes** 1763 1764For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1765 1766| **ID**| **Error Message** | 1767| --------- |--------------------------| 1768| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1769 1770**Example** 1771 1772```ts 1773let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1774predicates.equalTo("NAME", "Rose").limitAs(3); 1775``` 1776 1777### offsetAs 1778 1779offsetAs(rowOffset: number): RdbPredicates 1780 1781Sets an **RdbPredicates** object to specify the start position of the returned result. 1782 1783**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1784 1785**Parameters** 1786 1787| Name | Type | Mandatory| Description | 1788| --------- | ------ | ---- | ---------------------------------- | 1789| rowOffset | number | Yes | Number of rows to offset from the beginning. The value is a positive integer.| 1790 1791**Return value** 1792 1793| Type | Description | 1794| ------------------------------------ | ------------------------------------ | 1795| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.| 1796 1797**Error codes** 1798 1799For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1800 1801| **ID**| **Error Message** | 1802| --------- |----------------------------------------------------------------------------------------------------------------| 1803| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1804 1805**Example** 1806 1807```ts 1808let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1809predicates.equalTo("NAME", "Rose").offsetAs(3); 1810``` 1811 1812### groupBy 1813 1814groupBy(fields: Array<string>): RdbPredicates 1815 1816Sets an **RdbPredicates** object to group rows that have the same value into summary rows. 1817 1818**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1819 1820**Parameters** 1821 1822| Name| Type | Mandatory| Description | 1823| ------ | ------------------- | ---- | -------------------- | 1824| fields | Array<string> | Yes | Names of columns to group.| 1825 1826**Return value** 1827 1828| Type | Description | 1829| ------------------------------------ | ---------------------- | 1830| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.| 1831 1832**Error codes** 1833 1834For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1835 1836| **ID**| **Error Message** | 1837| --------- |----------------------------------------------------------------------------------------------------------------| 1838| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1839 1840**Example** 1841 1842```ts 1843let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1844predicates.groupBy(["AGE", "NAME"]); 1845``` 1846 1847### indexedBy 1848 1849indexedBy(field: string): RdbPredicates 1850 1851Sets an **RdbPredicates** object to specify the index column. 1852 1853**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1854 1855**Parameters** 1856 1857| Name| Type | Mandatory| Description | 1858| ------ | ------ | ---- | -------------- | 1859| field | string | Yes | Name of the index column.| 1860 1861**Return value** 1862 1863 1864| Type | Description | 1865| ------------------------------------ | ------------------------------------- | 1866| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.| 1867 1868**Error codes** 1869 1870For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1871 1872| **ID**| **Error Message** | 1873| --------- |----------------------------------------------------------------------------------------------------------------| 1874| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1875 1876**Example** 1877 1878```ts 1879let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1880predicates.indexedBy("SALARY"); 1881``` 1882 1883### in 1884 1885in(field: string, value: Array<ValueType>): RdbPredicates 1886 1887Sets an **RdbPredicates** object to match the fields in the specified column that are in the given range. 1888 1889**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1890 1891**Parameters** 1892 1893| Name| Type | Mandatory| Description | 1894| ------ | ------------------------------------ | ---- | --------------------------------------- | 1895| field | string | Yes | Column name in the database table. | 1896| value | Array<[ValueType](#valuetype)> | Yes | Array of **ValueType**s to match.| 1897 1898**Return value** 1899 1900| Type | Description | 1901| ------------------------------------ | -------------------------- | 1902| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1903 1904**Error codes** 1905 1906For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1907 1908| **ID**| **Error Message** | 1909| --------- |----------------------------------------------------------------------------------------------------------------| 1910| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1911 1912**Example** 1913 1914```ts 1915// Locate data of the employees with age of [18, 20] in the table. 1916let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1917predicates.in("AGE", [18, 20]); 1918``` 1919 1920### notIn 1921 1922notIn(field: string, value: Array<ValueType>): RdbPredicates 1923 1924Sets an **RdbPredicates** object to match the fields in the specified column that are out of the given range. 1925 1926**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1927 1928**Parameters** 1929 1930| Name| Type | Mandatory| Description | 1931| ------ | ------------------------------------ | ---- | ------------------------------------- | 1932| field | string | Yes | Column name in the database table. | 1933| value | Array<[ValueType](#valuetype)> | Yes | Array of **ValueType**s to match.| 1934 1935**Return value** 1936 1937| Type | Description | 1938| ------------------------------------ | -------------------------- | 1939| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1940 1941**Error codes** 1942 1943For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1944 1945| **ID**| **Error Message** | 1946| --------- |----------------------------------------------------------------------------------------------------------------| 1947| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1948 1949**Example** 1950 1951```ts 1952// Locate data of all the employees except Lisa and Rose in the table. 1953let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1954predicates.notIn("NAME", ["Lisa", "Rose"]); 1955``` 1956 1957### notContains<sup>12+</sup> 1958 1959notContains(field: string, value: string): RdbPredicates 1960 1961Sets an **RdbPredicates** object to match the fields in the specified column that do not contain the given value. 1962 1963**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1964 1965**Parameters** 1966 1967| Name| Type | Mandatory| Description | 1968| ------ | ------ | ---- | ---------------------- | 1969| field | string | Yes | Column name in the database table. | 1970| value | string | Yes | Value to match the **RdbPredicates**.| 1971 1972**Return value** 1973 1974| Type | Description | 1975| ------------------------------- | -------------------------- | 1976| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1977 1978**Error codes** 1979 1980For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1981 1982| **ID**| **Error Message** | 1983| --------- |----------------------------------------------------------------------------------------------------------------| 1984| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1985 1986**Example** 1987 1988```ts 1989// Match the fields that do not contain "os" in the NAME column of the data table, for example, Lisa in the list. 1990let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1991predicates.notContains("NAME", "os"); 1992``` 1993 1994### notLike<sup>12+</sup> 1995 1996notLike(field: string, value: string): RdbPredicates 1997 1998Sets an **RdbPredicates** object to match the fields in the specified column that are not similar to the given value. 1999 2000**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2001 2002**Parameters** 2003 2004| Name| Type | Mandatory| Description | 2005| ------ | ------ | ---- | ---------------------- | 2006| field | string | Yes | Column name in the database table. | 2007| value | string | Yes | Value to match the **RdbPredicates**.| 2008 2009**Return value** 2010 2011| Type | Description | 2012| ------------------------------- | -------------------------- | 2013| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2014 2015**Error codes** 2016 2017For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2018 2019| **ID**| **Error Message** | 2020| --------- |----------------------------------------------------------------------------------------------------------------| 2021| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2022 2023**Example** 2024 2025```ts 2026// Match the fields that are not "os" in the NAME column of the data table, for example, Rose in the list. 2027let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2028predicates.notLike("NAME", "os"); 2029``` 2030 2031 2032 2033## RdbStore 2034 2035Provides APIs to manage an RDB store. 2036 2037Before using the APIs of this class, use [executeSql](#executesql) to initialize the database table structure and related data. 2038 2039### Properties 2040 2041**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2042 2043| Name | Type | Read-Only | Optional | Description | 2044| ------------ | ----------- | ---- | -------------------------------- | -------------------------------- | 2045| version<sup>10+</sup> | number | No| No | RDB store version, which is an integer greater than 0. | 2046| rebuilt<sup>12+</sup> | [RebuildType](#rebuildtype12) | Yes| No| Whether the RDB store has been rebuilt or repaired.| 2047 2048**Error codes** 2049 2050For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 2051 2052| **ID**| **Error Message** | 2053|-----------| ------------------------------------------------------------ | 2054| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2055| 801 | Capability not supported. | 2056| 14800000 | Inner error. | 2057| 14800014 | Already closed. | 2058| 14800015 | The database does not respond. | 2059| 14800021 | SQLite: Generic error. | 2060| 14800023 | SQLite: Access permission denied. | 2061| 14800024 | SQLite: The database file is locked. | 2062| 14800025 | SQLite: A table in the database is locked. | 2063| 14800026 | SQLite: The database is out of memory. | 2064| 14800027 | SQLite: Attempt to write a readonly database. | 2065| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2066| 14800029 | SQLite: The database is full. | 2067| 14800030 | SQLite: Unable to open the database file. | 2068 2069**Example** 2070 2071```ts 2072// Set the RDB store version. 2073if(store != undefined) { 2074 (store as relationalStore.RdbStore).version = 3; 2075 // Obtain the RDB store version. 2076 console.info(`RdbStore version is ${store.version}`); 2077 // Whether the RDB store has been rebuilt. 2078 console.info(`RdbStore rebuilt is ${store.rebuilt}`); 2079} 2080``` 2081 2082### insert 2083 2084insert(table: string, values: ValuesBucket, callback: AsyncCallback<number>):void 2085 2086Inserts 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. 2087 2088**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2089 2090**Parameters** 2091 2092| Name | Type | Mandatory| Description | 2093| -------- | ----------------------------- | ---- | ---------------------------------------------------------- | 2094| table | string | Yes | Name of the target table. | 2095| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2096| 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.| 2097 2098**Error codes** 2099 2100For 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). 2101 2102| **ID**| **Error Message** | 2103|-----------| ------------------------------------------------------------ | 2104| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2105| 14800000 | Inner error. | 2106| 14800011 | Database corrupted. | 2107| 14800014 | Already closed. | 2108| 14800015 | The database does not respond. | 2109| 14800021 | SQLite: Generic error. | 2110| 14800022 | SQLite: Callback routine requested an abort. | 2111| 14800023 | SQLite: Access permission denied. | 2112| 14800024 | SQLite: The database file is locked. | 2113| 14800025 | SQLite: A table in the database is locked. | 2114| 14800026 | SQLite: The database is out of memory. | 2115| 14800027 | SQLite: Attempt to write a readonly database. | 2116| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2117| 14800029 | SQLite: The database is full. | 2118| 14800030 | SQLite: Unable to open the database file. | 2119| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2120| 14800032 | SQLite: Abort due to constraint violation. | 2121| 14800033 | SQLite: Data type mismatch. | 2122| 14800034 | SQLite: Library used incorrectly. | 2123| 14800047 | The WAL file size exceeds the default limit. | 2124 2125**Example** 2126 2127```ts 2128let value1 = "Lisa"; 2129let value2 = 18; 2130let value3 = 100.5; 2131let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2132 2133// You can use either of the following: 2134const valueBucket1: relationalStore.ValuesBucket = { 2135 'NAME': value1, 2136 'AGE': value2, 2137 'SALARY': value3, 2138 'CODES': value4, 2139}; 2140const valueBucket2: relationalStore.ValuesBucket = { 2141 NAME: value1, 2142 AGE: value2, 2143 SALARY: value3, 2144 CODES: value4, 2145}; 2146const valueBucket3: relationalStore.ValuesBucket = { 2147 "NAME": value1, 2148 "AGE": value2, 2149 "SALARY": value3, 2150 "CODES": value4, 2151}; 2152 2153if(store != undefined) { 2154 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, (err: BusinessError, rowId: number) => { 2155 if (err) { 2156 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2157 return; 2158 } 2159 console.info(`Insert is successful, rowId = ${rowId}`); 2160 }) 2161} 2162``` 2163 2164### insert<sup>10+</sup> 2165 2166insert(table: string, values: ValuesBucket, conflict: ConflictResolution, callback: AsyncCallback<number>):void 2167 2168Inserts 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. 2169 2170**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2171 2172**Parameters** 2173 2174| Name | Type | Mandatory| Description | 2175| -------- | ------------------------------------------- | ---- | ---------------------------------------------------------- | 2176| table | string | Yes | Name of the target table. | 2177| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2178| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 2179| 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.| 2180 2181**Error codes** 2182 2183For 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). 2184 2185| **ID**| **Error Message** | 2186|-----------| ---------------------------------------------------- | 2187| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2188| 14800000 | Inner error. | 2189| 14800011 | Database corrupted. | 2190| 14800014 | Already closed. | 2191| 14800015 | The database does not respond. | 2192| 14800021 | SQLite: Generic error. | 2193| 14800022 | SQLite: Callback routine requested an abort. | 2194| 14800023 | SQLite: Access permission denied. | 2195| 14800024 | SQLite: The database file is locked. | 2196| 14800025 | SQLite: A table in the database is locked. | 2197| 14800026 | SQLite: The database is out of memory. | 2198| 14800027 | SQLite: Attempt to write a readonly database. | 2199| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2200| 14800029 | SQLite: The database is full. | 2201| 14800030 | SQLite: Unable to open the database file. | 2202| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2203| 14800032 | SQLite: Abort due to constraint violation. | 2204| 14800033 | SQLite: Data type mismatch. | 2205| 14800034 | SQLite: Library used incorrectly. | 2206| 14800047 | The WAL file size exceeds the default limit. | 2207 2208**Example** 2209 2210```ts 2211let value1 = "Lisa"; 2212let value2 = 18; 2213let value3 = 100.5; 2214let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2215 2216// You can use either of the following: 2217const valueBucket1: relationalStore.ValuesBucket = { 2218 'NAME': value1, 2219 'AGE': value2, 2220 'SALARY': value3, 2221 'CODES': value4, 2222}; 2223const valueBucket2: relationalStore.ValuesBucket = { 2224 NAME: value1, 2225 AGE: value2, 2226 SALARY: value3, 2227 CODES: value4, 2228}; 2229const valueBucket3: relationalStore.ValuesBucket = { 2230 "NAME": value1, 2231 "AGE": value2, 2232 "SALARY": value3, 2233 "CODES": value4, 2234}; 2235 2236if(store != undefined) { 2237 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, 2238 (err: BusinessError, rowId: number) => { 2239 if (err) { 2240 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2241 return; 2242 } 2243 console.info(`Insert is successful, rowId = ${rowId}`); 2244 }) 2245} 2246``` 2247 2248### insert 2249 2250insert(table: string, values: ValuesBucket):Promise<number> 2251 2252Inserts 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. 2253 2254**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2255 2256**Parameters** 2257 2258| Name| Type | Mandatory| Description | 2259| ------ | ----------------------------- | ---- | -------------------------- | 2260| table | string | Yes | Name of the target table. | 2261| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 2262 2263**Return value** 2264 2265| Type | Description | 2266| --------------------- | ------------------------------------------------- | 2267| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2268 2269**Error codes** 2270 2271For 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). 2272 2273| **ID**| **Error Message** | 2274|-----------| ------------------------------------------------------------ | 2275| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2276| 14800000 | Inner error. | 2277| 14800011 | Database corrupted. | 2278| 14800014 | Already closed. | 2279| 14800015 | The database does not respond. | 2280| 14800021 | SQLite: Generic error. | 2281| 14800022 | SQLite: Callback routine requested an abort. | 2282| 14800023 | SQLite: Access permission denied. | 2283| 14800024 | SQLite: The database file is locked. | 2284| 14800025 | SQLite: A table in the database is locked. | 2285| 14800026 | SQLite: The database is out of memory. | 2286| 14800027 | SQLite: Attempt to write a readonly database. | 2287| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2288| 14800029 | SQLite: The database is full. | 2289| 14800030 | SQLite: Unable to open the database file. | 2290| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2291| 14800032 | SQLite: Abort due to constraint violation. | 2292| 14800033 | SQLite: Data type mismatch. | 2293| 14800034 | SQLite: Library used incorrectly. | 2294| 14800047 | The WAL file size exceeds the default limit. | 2295 2296**Example** 2297 2298```ts 2299import { BusinessError } from '@kit.BasicServicesKit'; 2300 2301let value1 = "Lisa"; 2302let value2 = 18; 2303let value3 = 100.5; 2304let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2305 2306// You can use either of the following: 2307const valueBucket1: relationalStore.ValuesBucket = { 2308 'NAME': value1, 2309 'AGE': value2, 2310 'SALARY': value3, 2311 'CODES': value4, 2312}; 2313const valueBucket2: relationalStore.ValuesBucket = { 2314 NAME: value1, 2315 AGE: value2, 2316 SALARY: value3, 2317 CODES: value4, 2318}; 2319const valueBucket3: relationalStore.ValuesBucket = { 2320 "NAME": value1, 2321 "AGE": value2, 2322 "SALARY": value3, 2323 "CODES": value4, 2324}; 2325 2326if(store != undefined) { 2327 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1).then((rowId: number) => { 2328 console.info(`Insert is successful, rowId = ${rowId}`); 2329 }).catch((err: BusinessError) => { 2330 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2331 }) 2332} 2333``` 2334 2335### insert<sup>10+</sup> 2336 2337insert(table: string, values: ValuesBucket, conflict: ConflictResolution):Promise<number> 2338 2339Inserts 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. 2340 2341**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2342 2343**Parameters** 2344 2345| Name | Type | Mandatory| Description | 2346| -------- | ------------------------------------------- | ---- | -------------------------- | 2347| table | string | Yes | Name of the target table. | 2348| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 2349| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 2350 2351**Return value** 2352 2353| Type | Description | 2354| --------------------- | ------------------------------------------------- | 2355| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2356 2357**Error codes** 2358 2359For 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). 2360 2361| **ID**| **Error Message** | 2362|-----------| ------------------------------------------------------------ | 2363| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2364| 14800000 | Inner error. | 2365| 14800011 | Database corrupted. | 2366| 14800014 | Already closed. | 2367| 14800015 | The database does not respond. | 2368| 14800021 | SQLite: Generic error. | 2369| 14800022 | SQLite: Callback routine requested an abort. | 2370| 14800023 | SQLite: Access permission denied. | 2371| 14800024 | SQLite: The database file is locked. | 2372| 14800025 | SQLite: A table in the database is locked. | 2373| 14800026 | SQLite: The database is out of memory. | 2374| 14800027 | SQLite: Attempt to write a readonly database. | 2375| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2376| 14800029 | SQLite: The database is full. | 2377| 14800030 | SQLite: Unable to open the database file. | 2378| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2379| 14800032 | SQLite: Abort due to constraint violation. | 2380| 14800033 | SQLite: Data type mismatch. | 2381| 14800034 | SQLite: Library used incorrectly. | 2382| 14800047 | The WAL file size exceeds the default limit. | 2383 2384**Example** 2385 2386```ts 2387import { BusinessError } from '@kit.BasicServicesKit'; 2388 2389let value1 = "Lisa"; 2390let value2 = 18; 2391let value3 = 100.5; 2392let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2393 2394// You can use either of the following: 2395const valueBucket1: relationalStore.ValuesBucket = { 2396 'NAME': value1, 2397 'AGE': value2, 2398 'SALARY': value3, 2399 'CODES': value4, 2400}; 2401const valueBucket2: relationalStore.ValuesBucket = { 2402 NAME: value1, 2403 AGE: value2, 2404 SALARY: value3, 2405 CODES: value4, 2406}; 2407const valueBucket3: relationalStore.ValuesBucket = { 2408 "NAME": value1, 2409 "AGE": value2, 2410 "SALARY": value3, 2411 "CODES": value4, 2412}; 2413 2414if(store != undefined) { 2415 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => { 2416 console.info(`Insert is successful, rowId = ${rowId}`); 2417 }).catch((err: BusinessError) => { 2418 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2419 }) 2420} 2421``` 2422 2423### insertSync<sup>12+</sup> 2424 2425insertSync(table: string, values: ValuesBucket, conflict?: ConflictResolution):number 2426 2427Inserts 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. 2428 2429**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2430 2431**Parameters** 2432 2433| Name | Type | Mandatory| Description | 2434| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 2435| table | string | Yes | Name of the target table. | 2436| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2437| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. The default value is **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 2438 2439**Return value** 2440 2441| Type | Description | 2442| ------ | ------------------------------------ | 2443| number | If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2444 2445**Error codes** 2446 2447For 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). 2448 2449| **ID**| **Error Message** | 2450| ------------ | ------------------------------------------------------------ | 2451| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2452| 14800000 | Inner error. | 2453| 14800011 | Database corrupted. | 2454| 14800014 | Already closed. | 2455| 14800015 | The database does not respond. | 2456| 14800021 | SQLite: Generic error. | 2457| 14800022 | SQLite: Callback routine requested an abort. | 2458| 14800023 | SQLite: Access permission denied. | 2459| 14800024 | SQLite: The database file is locked. | 2460| 14800025 | SQLite: A table in the database is locked. | 2461| 14800026 | SQLite: The database is out of memory. | 2462| 14800027 | SQLite: Attempt to write a readonly database. | 2463| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2464| 14800029 | SQLite: The database is full. | 2465| 14800030 | SQLite: Unable to open the database file. | 2466| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2467| 14800032 | SQLite: Abort due to constraint violation. | 2468| 14800033 | SQLite: Data type mismatch. | 2469| 14800034 | SQLite: Library used incorrectly. | 2470| 14800047 | The WAL file size exceeds the default limit. | 2471 2472**Example** 2473 2474```ts 2475import { BusinessError } from '@kit.BasicServicesKit'; 2476 2477let value1 = "Lisa"; 2478let value2 = 18; 2479let value3 = 100.5; 2480let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2481 2482// You can use either of the following: 2483const valueBucket1: relationalStore.ValuesBucket = { 2484 'NAME': value1, 2485 'AGE': value2, 2486 'SALARY': value3, 2487 'CODES': value4, 2488}; 2489const valueBucket2: relationalStore.ValuesBucket = { 2490 NAME: value1, 2491 AGE: value2, 2492 SALARY: value3, 2493 CODES: value4, 2494}; 2495const valueBucket3: relationalStore.ValuesBucket = { 2496 "NAME": value1, 2497 "AGE": value2, 2498 "SALARY": value3, 2499 "CODES": value4, 2500}; 2501 2502if(store != undefined) { 2503 try { 2504 let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 2505 console.info(`Insert is successful, rowId = ${rowId}`); 2506 } catch (error) { 2507 console.error(`Insert is failed, code is ${error.code},message is ${error.message}`); 2508 } 2509} 2510``` 2511 2512### insertSync<sup>12+</sup> 2513 2514insertSync(table: string, values: sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution):number 2515 2516Inserts 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. 2517 2518**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2519 2520**Parameters** 2521 2522| Name | Type | Mandatory| Description | 2523| -------- | ---------------------------------------------------------------------------------------------- | ---- | ------------------------------------------------------------------------------- | 2524| table | string | Yes | Name of the target table. | 2525| values | [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | Yes | Sendable data to insert. | 2526| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. The default value is **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 2527 2528**Return value** 2529 2530| Type | Description | 2531| ------ | ------------------------------------ | 2532| number | If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2533 2534**Error codes** 2535 2536For 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). 2537 2538| **ID**| **Error Message** | 2539| ------------ | ------------------------------------------------------------ | 2540| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2541| 14800000 | Inner error. | 2542| 14800011 | Database corrupted. | 2543| 14800014 | Already closed. | 2544| 14800015 | The database does not respond. | 2545| 14800021 | SQLite: Generic error. | 2546| 14800022 | SQLite: Callback routine requested an abort. | 2547| 14800023 | SQLite: Access permission denied. | 2548| 14800024 | SQLite: The database file is locked. | 2549| 14800025 | SQLite: A table in the database is locked. | 2550| 14800026 | SQLite: The database is out of memory. | 2551| 14800027 | SQLite: Attempt to write a readonly database. | 2552| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2553| 14800029 | SQLite: The database is full. | 2554| 14800030 | SQLite: Unable to open the database file. | 2555| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2556| 14800032 | SQLite: Abort due to constraint violation. | 2557| 14800033 | SQLite: Data type mismatch. | 2558| 14800034 | SQLite: Library used incorrectly. | 2559| 14800047 | The WAL file size exceeds the default limit. | 2560 2561**Example** 2562 2563```ts 2564import { sendableRelationalStore } from '@kit.ArkData'; 2565 2566const valuesBucket: relationalStore.ValuesBucket = { 2567 "NAME": 'hangman', 2568 "AGE": 18, 2569 "SALARY": 100.5, 2570 "CODES": new Uint8Array([1,2,3]), 2571}; 2572const sendableValuesBucket = sendableRelationalStore.toSendableValuesBucket(valuesBucket); 2573 2574if(store != undefined) { 2575 try { 2576 let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", sendableValuesBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 2577 console.info(`Insert is successful, rowId = ${rowId}`); 2578 } catch (error) { 2579 console.error(`Insert is failed, code is ${error.code},message is ${error.message}`); 2580 } 2581} 2582``` 2583 2584### batchInsert 2585 2586batchInsert(table: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>):void 2587 2588Batch inserts data into a table. This API uses an asynchronous callback to return the result. 2589 2590**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2591 2592**Parameters** 2593 2594| Name | Type | Mandatory| Description | 2595| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ | 2596| table | string | Yes | Name of the target table. | 2597| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert. | 2598| 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.| 2599 2600**Error codes** 2601 2602For 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). 2603 2604| **ID**| **Error Message** | 2605|-----------| ------------------------------------------------------------ | 2606| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2607| 14800000 | Inner error. | 2608| 14800011 | Database corrupted. | 2609| 14800014 | Already closed. | 2610| 14800015 | The database does not respond. | 2611| 14800021 | SQLite: Generic error. | 2612| 14800022 | SQLite: Callback routine requested an abort. | 2613| 14800023 | SQLite: Access permission denied. | 2614| 14800024 | SQLite: The database file is locked. | 2615| 14800025 | SQLite: A table in the database is locked. | 2616| 14800026 | SQLite: The database is out of memory. | 2617| 14800027 | SQLite: Attempt to write a readonly database. | 2618| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2619| 14800029 | SQLite: The database is full. | 2620| 14800030 | SQLite: Unable to open the database file. | 2621| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2622| 14800032 | SQLite: Abort due to constraint violation. | 2623| 14800033 | SQLite: Data type mismatch. | 2624| 14800034 | SQLite: Library used incorrectly. | 2625| 14800047 | The WAL file size exceeds the default limit. | 2626 2627**Example** 2628 2629```ts 2630 2631let value1 = "Lisa"; 2632let value2 = 18; 2633let value3 = 100.5; 2634let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2635let value5 = "Jack"; 2636let value6 = 19; 2637let value7 = 101.5; 2638let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2639let value9 = "Tom"; 2640let value10 = 20; 2641let value11 = 102.5; 2642let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2643 2644const valueBucket1: relationalStore.ValuesBucket = { 2645 'NAME': value1, 2646 'AGE': value2, 2647 'SALARY': value3, 2648 'CODES': value4, 2649}; 2650const valueBucket2: relationalStore.ValuesBucket = { 2651 'NAME': value5, 2652 'AGE': value6, 2653 'SALARY': value7, 2654 'CODES': value8, 2655}; 2656const valueBucket3: relationalStore.ValuesBucket = { 2657 'NAME': value9, 2658 'AGE': value10, 2659 'SALARY': value11, 2660 'CODES': value12, 2661}; 2662 2663let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2664if(store != undefined) { 2665 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets, (err, insertNum) => { 2666 if (err) { 2667 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2668 return; 2669 } 2670 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2671 }) 2672} 2673``` 2674 2675### batchInsert 2676 2677batchInsert(table: string, values: Array<ValuesBucket>):Promise<number> 2678 2679Batch inserts data into a table. This API uses a promise to return the result. 2680 2681**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2682 2683**Parameters** 2684 2685| Name| Type | Mandatory| Description | 2686| ------ | ------------------------------------------ | ---- | ---------------------------- | 2687| table | string | Yes | Name of the target table. | 2688| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 2689 2690**Return value** 2691 2692| Type | Description | 2693| --------------------- | ----------------------------------------------------------- | 2694| 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.| 2695 2696**Error codes** 2697 2698For 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). 2699 2700| **ID**| **Error Message** | 2701|-----------| ------------------------------------------------------------ | 2702| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2703| 14800000 | Inner error. | 2704| 14800011 | Database corrupted. | 2705| 14800014 | Already closed. | 2706| 14800015 | The database does not respond. | 2707| 14800021 | SQLite: Generic error. | 2708| 14800022 | SQLite: Callback routine requested an abort. | 2709| 14800023 | SQLite: Access permission denied. | 2710| 14800024 | SQLite: The database file is locked. | 2711| 14800025 | SQLite: A table in the database is locked. | 2712| 14800026 | SQLite: The database is out of memory. | 2713| 14800027 | SQLite: Attempt to write a readonly database. | 2714| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2715| 14800029 | SQLite: The database is full. | 2716| 14800030 | SQLite: Unable to open the database file. | 2717| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2718| 14800032 | SQLite: Abort due to constraint violation. | 2719| 14800033 | SQLite: Data type mismatch. | 2720| 14800034 | SQLite: Library used incorrectly. | 2721| 14800047 | The WAL file size exceeds the default limit. | 2722 2723**Example** 2724 2725```ts 2726import { BusinessError } from '@kit.BasicServicesKit'; 2727 2728let value1 = "Lisa"; 2729let value2 = 18; 2730let value3 = 100.5; 2731let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2732let value5 = "Jack"; 2733let value6 = 19; 2734let value7 = 101.5; 2735let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2736let value9 = "Tom"; 2737let value10 = 20; 2738let value11 = 102.5; 2739let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2740 2741const valueBucket1: relationalStore.ValuesBucket = { 2742 'NAME': value1, 2743 'AGE': value2, 2744 'SALARY': value3, 2745 'CODES': value4, 2746}; 2747const valueBucket2: relationalStore.ValuesBucket = { 2748 'NAME': value5, 2749 'AGE': value6, 2750 'SALARY': value7, 2751 'CODES': value8, 2752}; 2753const valueBucket3: relationalStore.ValuesBucket = { 2754 'NAME': value9, 2755 'AGE': value10, 2756 'SALARY': value11, 2757 'CODES': value12, 2758}; 2759 2760let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2761if(store != undefined) { 2762 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => { 2763 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2764 }).catch((err: BusinessError) => { 2765 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2766 }) 2767} 2768``` 2769 2770### batchInsertSync<sup>12+</sup> 2771 2772batchInsertSync(table: string, values: Array<ValuesBucket>):number 2773 2774Inserts a row of data into a table. 2775 2776**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2777 2778**Parameters** 2779 2780| Name| Type | Mandatory| Description | 2781| ------ | ------------------------------------------ | ---- | ---------------------------- | 2782| table | string | Yes | Name of the target table. | 2783| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 2784 2785**Return value** 2786 2787| Type | Description | 2788| ------ | ---------------------------------------------- | 2789| number | If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 2790 2791**Error codes** 2792 2793For 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). 2794 2795| **ID**| **Error Message** | 2796| ------------ | ------------------------------------------------------------ | 2797| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2798| 14800000 | Inner error. | 2799| 14800011 | Database corrupted. | 2800| 14800014 | Already closed. | 2801| 14800015 | The database does not respond. | 2802| 14800021 | SQLite: Generic error. | 2803| 14800022 | SQLite: Callback routine requested an abort. | 2804| 14800023 | SQLite: Access permission denied. | 2805| 14800024 | SQLite: The database file is locked. | 2806| 14800025 | SQLite: A table in the database is locked. | 2807| 14800026 | SQLite: The database is out of memory. | 2808| 14800027 | SQLite: Attempt to write a readonly database. | 2809| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2810| 14800029 | SQLite: The database is full. | 2811| 14800030 | SQLite: Unable to open the database file. | 2812| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2813| 14800032 | SQLite: Abort due to constraint violation. | 2814| 14800033 | SQLite: Data type mismatch. | 2815| 14800034 | SQLite: Library used incorrectly. | 2816| 14800047 | The WAL file size exceeds the default limit. | 2817 2818**Example** 2819 2820```ts 2821import { BusinessError } from '@kit.BasicServicesKit'; 2822 2823let value1 = "Lisa"; 2824let value2 = 18; 2825let value3 = 100.5; 2826let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2827let value5 = "Jack"; 2828let value6 = 19; 2829let value7 = 101.5; 2830let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2831let value9 = "Tom"; 2832let value10 = 20; 2833let value11 = 102.5; 2834let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2835 2836const valueBucket1: relationalStore.ValuesBucket = { 2837 'NAME': value1, 2838 'AGE': value2, 2839 'SALARY': value3, 2840 'CODES': value4, 2841}; 2842const valueBucket2: relationalStore.ValuesBucket = { 2843 'NAME': value5, 2844 'AGE': value6, 2845 'SALARY': value7, 2846 'CODES': value8, 2847}; 2848const valueBucket3: relationalStore.ValuesBucket = { 2849 'NAME': value9, 2850 'AGE': value10, 2851 'SALARY': value11, 2852 'CODES': value12, 2853}; 2854 2855let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2856if(store != undefined) { 2857 try { 2858 let insertNum: number = (store as relationalStore.RdbStore).batchInsertSync("EMPLOYEE", valueBuckets); 2859 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2860 } catch (err) { 2861 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2862 } 2863} 2864``` 2865 2866### update 2867 2868update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback<number>):void 2869 2870Updates 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. 2871 2872**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2873 2874**Parameters** 2875 2876| Name | Type | Mandatory| Description | 2877| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 2878| 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.| 2879| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 2880| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows updated. | 2881 2882**Error codes** 2883 2884For 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). 2885 2886| **ID**| **Error Message** | 2887|-----------| ------------------------------------------------------------ | 2888| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2889| 14800000 | Inner error. | 2890| 14800011 | Database corrupted. | 2891| 14800014 | Already closed. | 2892| 14800015 | The database does not respond. | 2893| 14800021 | SQLite: Generic error. | 2894| 14800022 | SQLite: Callback routine requested an abort. | 2895| 14800023 | SQLite: Access permission denied. | 2896| 14800024 | SQLite: The database file is locked. | 2897| 14800025 | SQLite: A table in the database is locked. | 2898| 14800026 | SQLite: The database is out of memory. | 2899| 14800027 | SQLite: Attempt to write a readonly database. | 2900| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2901| 14800029 | SQLite: The database is full. | 2902| 14800030 | SQLite: Unable to open the database file. | 2903| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2904| 14800032 | SQLite: Abort due to constraint violation. | 2905| 14800033 | SQLite: Data type mismatch. | 2906| 14800034 | SQLite: Library used incorrectly. | 2907| 14800047 | The WAL file size exceeds the default limit. | 2908 2909**Example** 2910 2911```ts 2912 2913let value1 = "Rose"; 2914let value2 = 22; 2915let value3 = 200.5; 2916let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2917 2918// You can use either of the following: 2919const valueBucket1: relationalStore.ValuesBucket = { 2920 'NAME': value1, 2921 'AGE': value2, 2922 'SALARY': value3, 2923 'CODES': value4, 2924}; 2925const valueBucket2: relationalStore.ValuesBucket = { 2926 NAME: value1, 2927 AGE: value2, 2928 SALARY: value3, 2929 CODES: value4, 2930}; 2931const valueBucket3: relationalStore.ValuesBucket = { 2932 "NAME": value1, 2933 "AGE": value2, 2934 "SALARY": value3, 2935 "CODES": value4, 2936}; 2937 2938let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2939predicates.equalTo("NAME", "Lisa"); 2940if(store != undefined) { 2941 (store as relationalStore.RdbStore).update(valueBucket1, predicates,(err, rows) => { 2942 if (err) { 2943 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 2944 return; 2945 } 2946 console.info(`Updated row count: ${rows}`); 2947 }) 2948} 2949``` 2950 2951### update<sup>10+</sup> 2952 2953update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution, callback: AsyncCallback<number>):void 2954 2955Updates 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. 2956 2957**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2958 2959**Parameters** 2960 2961| Name | Type | Mandatory| Description | 2962| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 2963| 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.| 2964| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 2965| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 2966| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows updated. | 2967 2968**Error codes** 2969 2970For 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). 2971 2972| **ID**| **Error Message** | 2973|-----------| ------------------------------------------------------------ | 2974| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2975| 14800000 | Inner error. | 2976| 14800011 | Database corrupted. | 2977| 14800014 | Already closed. | 2978| 14800015 | The database does not respond. | 2979| 14800021 | SQLite: Generic error. | 2980| 14800022 | SQLite: Callback routine requested an abort. | 2981| 14800023 | SQLite: Access permission denied. | 2982| 14800024 | SQLite: The database file is locked. | 2983| 14800025 | SQLite: A table in the database is locked. | 2984| 14800026 | SQLite: The database is out of memory. | 2985| 14800027 | SQLite: Attempt to write a readonly database. | 2986| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2987| 14800029 | SQLite: The database is full. | 2988| 14800030 | SQLite: Unable to open the database file. | 2989| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2990| 14800032 | SQLite: Abort due to constraint violation. | 2991| 14800033 | SQLite: Data type mismatch. | 2992| 14800034 | SQLite: Library used incorrectly. | 2993| 14800047 | The WAL file size exceeds the default limit. | 2994 2995**Example** 2996 2997```ts 2998 2999let value1 = "Rose"; 3000let value2 = 22; 3001let value3 = 200.5; 3002let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3003 3004// You can use either of the following: 3005const valueBucket1: relationalStore.ValuesBucket = { 3006 'NAME': value1, 3007 'AGE': value2, 3008 'SALARY': value3, 3009 'CODES': value4, 3010}; 3011const valueBucket2: relationalStore.ValuesBucket = { 3012 NAME: value1, 3013 AGE: value2, 3014 SALARY: value3, 3015 CODES: value4, 3016}; 3017const valueBucket3: relationalStore.ValuesBucket = { 3018 "NAME": value1, 3019 "AGE": value2, 3020 "SALARY": value3, 3021 "CODES": value4, 3022}; 3023 3024let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3025predicates.equalTo("NAME", "Lisa"); 3026if(store != undefined) { 3027 (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, (err, rows) => { 3028 if (err) { 3029 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3030 return; 3031 } 3032 console.info(`Updated row count: ${rows}`); 3033 }) 3034} 3035``` 3036 3037### update 3038 3039update(values: ValuesBucket, predicates: RdbPredicates):Promise<number> 3040 3041Updates 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. 3042 3043**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3044 3045**Parameters** 3046 3047| Name | Type | Mandatory| Description | 3048| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 3049| 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.| 3050| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3051 3052**Return value** 3053 3054| Type | Description | 3055| --------------------- | ----------------------------------------- | 3056| Promise<number> | Promise used to return the number of rows updated.| 3057 3058**Error codes** 3059 3060For 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). 3061 3062| **ID**| **Error Message** | 3063|-----------| ------------------------------------------------------------ | 3064| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3065| 14800000 | Inner error. | 3066| 14800011 | Database corrupted. | 3067| 14800014 | Already closed. | 3068| 14800015 | The database does not respond. | 3069| 14800021 | SQLite: Generic error. | 3070| 14800022 | SQLite: Callback routine requested an abort. | 3071| 14800023 | SQLite: Access permission denied. | 3072| 14800024 | SQLite: The database file is locked. | 3073| 14800025 | SQLite: A table in the database is locked. | 3074| 14800026 | SQLite: The database is out of memory. | 3075| 14800027 | SQLite: Attempt to write a readonly database. | 3076| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3077| 14800029 | SQLite: The database is full. | 3078| 14800030 | SQLite: Unable to open the database file. | 3079| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3080| 14800032 | SQLite: Abort due to constraint violation. | 3081| 14800033 | SQLite: Data type mismatch. | 3082| 14800034 | SQLite: Library used incorrectly. | 3083| 14800047 | The WAL file size exceeds the default limit. | 3084 3085**Example** 3086 3087```ts 3088import { BusinessError } from '@kit.BasicServicesKit'; 3089 3090let value1 = "Rose"; 3091let value2 = 22; 3092let value3 = 200.5; 3093let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3094 3095// You can use either of the following: 3096const valueBucket1: relationalStore.ValuesBucket = { 3097 'NAME': value1, 3098 'AGE': value2, 3099 'SALARY': value3, 3100 'CODES': value4, 3101}; 3102const valueBucket2: relationalStore.ValuesBucket = { 3103 NAME: value1, 3104 AGE: value2, 3105 SALARY: value3, 3106 CODES: value4, 3107}; 3108const valueBucket3: relationalStore.ValuesBucket = { 3109 "NAME": value1, 3110 "AGE": value2, 3111 "SALARY": value3, 3112 "CODES": value4, 3113}; 3114 3115let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3116predicates.equalTo("NAME", "Lisa"); 3117if(store != undefined) { 3118 (store as relationalStore.RdbStore).update(valueBucket1, predicates).then(async (rows: Number) => { 3119 console.info(`Updated row count: ${rows}`); 3120 }).catch((err: BusinessError) => { 3121 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3122 }) 3123} 3124``` 3125 3126### update<sup>10+</sup> 3127 3128update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution):Promise<number> 3129 3130Updates 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. 3131 3132**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3133 3134**Parameters** 3135 3136| Name | Type | Mandatory| Description | 3137| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3138| 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.| 3139| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3140| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 3141 3142**Return value** 3143 3144| Type | Description | 3145| --------------------- | ----------------------------------------- | 3146| Promise<number> | Promise used to return the number of rows updated.| 3147 3148**Error codes** 3149 3150For 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). 3151 3152| **ID**| **Error Message** | 3153|-----------| ------------------------------------------------------------ | 3154| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3155| 14800000 | Inner error. | 3156| 14800011 | Database corrupted. | 3157| 14800014 | Already closed. | 3158| 14800015 | The database does not respond. | 3159| 14800021 | SQLite: Generic error. | 3160| 14800022 | SQLite: Callback routine requested an abort. | 3161| 14800023 | SQLite: Access permission denied. | 3162| 14800024 | SQLite: The database file is locked. | 3163| 14800025 | SQLite: A table in the database is locked. | 3164| 14800026 | SQLite: The database is out of memory. | 3165| 14800027 | SQLite: Attempt to write a readonly database. | 3166| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3167| 14800029 | SQLite: The database is full. | 3168| 14800030 | SQLite: Unable to open the database file. | 3169| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3170| 14800032 | SQLite: Abort due to constraint violation. | 3171| 14800033 | SQLite: Data type mismatch. | 3172| 14800034 | SQLite: Library used incorrectly. | 3173| 14800047 | The WAL file size exceeds the default limit. | 3174 3175**Example** 3176 3177```ts 3178import { BusinessError } from '@kit.BasicServicesKit'; 3179 3180let value1 = "Rose"; 3181let value2 = 22; 3182let value3 = 200.5; 3183let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3184 3185// You can use either of the following: 3186const valueBucket1: relationalStore.ValuesBucket = { 3187 'NAME': value1, 3188 'AGE': value2, 3189 'SALARY': value3, 3190 'CODES': value4, 3191}; 3192const valueBucket2: relationalStore.ValuesBucket = { 3193 NAME: value1, 3194 AGE: value2, 3195 SALARY: value3, 3196 CODES: value4, 3197}; 3198const valueBucket3: relationalStore.ValuesBucket = { 3199 "NAME": value1, 3200 "AGE": value2, 3201 "SALARY": value3, 3202 "CODES": value4, 3203}; 3204 3205let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3206predicates.equalTo("NAME", "Lisa"); 3207if(store != undefined) { 3208 (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => { 3209 console.info(`Updated row count: ${rows}`); 3210 }).catch((err: BusinessError) => { 3211 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3212 }) 3213} 3214``` 3215 3216### updateSync<sup>12+</sup> 3217 3218updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution):number 3219 3220Updates 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. 3221 3222**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3223 3224**Parameters** 3225 3226| Name | Type | Mandatory| Description | 3227| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3228| 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.| 3229| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3230| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. The default value is **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 3231 3232**Return value** 3233 3234| Type | Description | 3235| ------ | ------------------ | 3236| number | return the number of rows updated.| 3237 3238**Error codes** 3239 3240For 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). 3241 3242| **ID**| **Error Message** | 3243| ------------ | ------------------------------------------------------------ | 3244| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3245| 14800000 | Inner error. | 3246| 14800011 | Database corrupted. | 3247| 14800014 | Already closed. | 3248| 14800015 | The database does not respond. | 3249| 14800021 | SQLite: Generic error. | 3250| 14800022 | SQLite: Callback routine requested an abort. | 3251| 14800023 | SQLite: Access permission denied. | 3252| 14800024 | SQLite: The database file is locked. | 3253| 14800025 | SQLite: A table in the database is locked. | 3254| 14800026 | SQLite: The database is out of memory. | 3255| 14800027 | SQLite: Attempt to write a readonly database. | 3256| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3257| 14800029 | SQLite: The database is full. | 3258| 14800030 | SQLite: Unable to open the database file. | 3259| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3260| 14800032 | SQLite: Abort due to constraint violation. | 3261| 14800033 | SQLite: Data type mismatch. | 3262| 14800034 | SQLite: Library used incorrectly. | 3263| 14800047 | The WAL file size exceeds the default limit. | 3264 3265**Example** 3266 3267```ts 3268import { BusinessError } from '@kit.BasicServicesKit'; 3269 3270let value1 = "Rose"; 3271let value2 = 22; 3272let value3 = 200.5; 3273let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3274 3275// You can use either of the following: 3276const valueBucket1: relationalStore.ValuesBucket = { 3277 'NAME': value1, 3278 'AGE': value2, 3279 'SALARY': value3, 3280 'CODES': value4, 3281}; 3282const valueBucket2: relationalStore.ValuesBucket = { 3283 NAME: value1, 3284 AGE: value2, 3285 SALARY: value3, 3286 CODES: value4, 3287}; 3288const valueBucket3: relationalStore.ValuesBucket = { 3289 "NAME": value1, 3290 "AGE": value2, 3291 "SALARY": value3, 3292 "CODES": value4, 3293}; 3294 3295let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3296predicates.equalTo("NAME", "Lisa"); 3297if(store != undefined) { 3298 try { 3299 let rows: Number = (store as relationalStore.RdbStore).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 3300 console.info(`Updated row count: ${rows}`); 3301 } catch (error) { 3302 console.error(`Updated failed, code is ${error.code},message is ${error.message}`); 3303 } 3304} 3305``` 3306 3307### delete 3308 3309delete(predicates: RdbPredicates, callback: AsyncCallback<number>):void 3310 3311Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result. 3312 3313**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3314 3315**Parameters** 3316 3317| Name | Type | Mandatory| Description | 3318| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 3319| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 3320| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows deleted. | 3321 3322**Error codes** 3323 3324For 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). 3325 3326| **ID**| **Error Message** | 3327|-----------| ------------------------------------------------------------ | 3328| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3329| 14800000 | Inner error. | 3330| 14800011 | Database corrupted. | 3331| 14800014 | Already closed. | 3332| 14800015 | The database does not respond. | 3333| 14800021 | SQLite: Generic error. | 3334| 14800022 | SQLite: Callback routine requested an abort. | 3335| 14800023 | SQLite: Access permission denied. | 3336| 14800024 | SQLite: The database file is locked. | 3337| 14800025 | SQLite: A table in the database is locked. | 3338| 14800026 | SQLite: The database is out of memory. | 3339| 14800027 | SQLite: Attempt to write a readonly database. | 3340| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3341| 14800029 | SQLite: The database is full. | 3342| 14800030 | SQLite: Unable to open the database file. | 3343| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3344| 14800032 | SQLite: Abort due to constraint violation. | 3345| 14800033 | SQLite: Data type mismatch. | 3346| 14800034 | SQLite: Library used incorrectly. | 3347| 14800047 | The WAL file size exceeds the default limit. | 3348 3349**Example** 3350 3351```ts 3352let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3353predicates.equalTo("NAME", "Lisa"); 3354if(store != undefined) { 3355 (store as relationalStore.RdbStore).delete(predicates, (err, rows) => { 3356 if (err) { 3357 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3358 return; 3359 } 3360 console.info(`Delete rows: ${rows}`); 3361 }) 3362} 3363``` 3364 3365### delete 3366 3367delete(predicates: RdbPredicates):Promise<number> 3368 3369Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result. 3370 3371**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3372 3373**Parameters** 3374 3375| Name | Type | Mandatory| Description | 3376| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 3377| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 3378 3379**Return value** 3380 3381| Type | Description | 3382| --------------------- | ------------------------------- | 3383| Promise<number> | Promise used to return the number of rows deleted.| 3384 3385**Error codes** 3386 3387For 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). 3388 3389| **ID**| **Error Message** | 3390|-----------| ------------------------------------------------------------ | 3391| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3392| 14800000 | Inner error. | 3393| 14800011 | Database corrupted. | 3394| 14800014 | Already closed. | 3395| 14800015 | The database does not respond. | 3396| 14800021 | SQLite: Generic error. | 3397| 14800022 | SQLite: Callback routine requested an abort. | 3398| 14800023 | SQLite: Access permission denied. | 3399| 14800024 | SQLite: The database file is locked. | 3400| 14800025 | SQLite: A table in the database is locked. | 3401| 14800026 | SQLite: The database is out of memory. | 3402| 14800027 | SQLite: Attempt to write a readonly database. | 3403| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3404| 14800029 | SQLite: The database is full. | 3405| 14800030 | SQLite: Unable to open the database file. | 3406| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3407| 14800032 | SQLite: Abort due to constraint violation. | 3408| 14800033 | SQLite: Data type mismatch. | 3409| 14800034 | SQLite: Library used incorrectly. | 3410| 14800047 | The WAL file size exceeds the default limit. | 3411 3412**Example** 3413 3414```ts 3415import { BusinessError } from '@kit.BasicServicesKit'; 3416 3417let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3418predicates.equalTo("NAME", "Lisa"); 3419if(store != undefined) { 3420 (store as relationalStore.RdbStore).delete(predicates).then((rows: Number) => { 3421 console.info(`Delete rows: ${rows}`); 3422 }).catch((err: BusinessError) => { 3423 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3424 }) 3425} 3426``` 3427 3428### deleteSync<sup>12+</sup> 3429 3430deleteSync(predicates: RdbPredicates):number 3431 3432Deletes data from the RDB store based on the specified **RdbPredicates** object. 3433 3434**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3435 3436**Parameters** 3437 3438| Name | Type | Mandatory| Description | 3439| ---------- | ------------------------------- | ---- | --------------------------------------- | 3440| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 3441 3442**Return value** 3443 3444| Type | Description | 3445| ------ | ------------------ | 3446| number | return the number of rows updated.| 3447 3448**Error codes** 3449 3450For 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). 3451 3452| **ID**| **Error Message** | 3453| ------------ | ------------------------------------------------------------ | 3454| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3455| 14800000 | Inner error. | 3456| 14800011 | Database corrupted. | 3457| 14800014 | Already closed. | 3458| 14800015 | The database does not respond. | 3459| 14800021 | SQLite: Generic error. | 3460| 14800022 | SQLite: Callback routine requested an abort. | 3461| 14800023 | SQLite: Access permission denied. | 3462| 14800024 | SQLite: The database file is locked. | 3463| 14800025 | SQLite: A table in the database is locked. | 3464| 14800026 | SQLite: The database is out of memory. | 3465| 14800027 | SQLite: Attempt to write a readonly database. | 3466| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3467| 14800029 | SQLite: The database is full. | 3468| 14800030 | SQLite: Unable to open the database file. | 3469| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3470| 14800032 | SQLite: Abort due to constraint violation. | 3471| 14800033 | SQLite: Data type mismatch. | 3472| 14800034 | SQLite: Library used incorrectly. | 3473| 14800047 | The WAL file size exceeds the default limit. | 3474 3475**Example** 3476 3477```ts 3478import { BusinessError } from '@kit.BasicServicesKit'; 3479 3480let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3481predicates.equalTo("NAME", "Lisa"); 3482if(store != undefined) { 3483 try { 3484 let rows: Number = (store as relationalStore.RdbStore).deleteSync(predicates) 3485 console.info(`Delete rows: ${rows}`); 3486 } catch (err) { 3487 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3488 } 3489} 3490``` 3491 3492### query<sup>10+</sup> 3493 3494query(predicates: RdbPredicates, callback: AsyncCallback<ResultSet>):void 3495 3496Queries 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. 3497 3498**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3499 3500**Parameters** 3501 3502| Name | Type | Mandatory| Description | 3503| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 3504| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3505| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3506 3507**Error codes** 3508 3509For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3510 3511| **ID**| **Error Message** | 3512|-----------| ------------------------------------------------------------ | 3513| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3514| 14800000 | Inner error. | 3515| 14800014 | Already closed. | 3516| 14800015 | The database does not respond. | 3517 3518**Example** 3519 3520```ts 3521let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3522predicates.equalTo("NAME", "Rose"); 3523if(store != undefined) { 3524 (store as relationalStore.RdbStore).query(predicates, (err, resultSet) => { 3525 if (err) { 3526 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3527 return; 3528 } 3529 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3530 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3531 while (resultSet.goToNextRow()) { 3532 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3533 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3534 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3535 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3536 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3537 } 3538 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3539 resultSet.close(); 3540 }) 3541} 3542``` 3543 3544### query 3545 3546query(predicates: RdbPredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>):void 3547 3548Queries 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. 3549 3550**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3551 3552**Parameters** 3553 3554| Name | Type | Mandatory| Description | 3555| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 3556| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3557| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | 3558| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3559 3560**Error codes** 3561 3562For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3563 3564| **ID**| **Error Message** | 3565|-----------| ------------------------------------------------------------ | 3566| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3567| 14800000 | Inner error. | 3568| 14800014 | Already closed. | 3569| 14800015 | The database does not respond. | 3570 3571**Example** 3572 3573```ts 3574let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3575predicates.equalTo("NAME", "Rose"); 3576if(store != undefined) { 3577 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], (err, resultSet) => { 3578 if (err) { 3579 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3580 return; 3581 } 3582 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3583 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3584 while (resultSet.goToNextRow()) { 3585 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3586 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3587 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3588 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3589 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3590 } 3591 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3592 resultSet.close(); 3593 }) 3594} 3595``` 3596 3597### query 3598 3599query(predicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> 3600 3601Queries 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. 3602 3603**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3604 3605**Parameters** 3606 3607| Name | Type | Mandatory| Description | 3608| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 3609| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3610| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 3611 3612**Error codes** 3613 3614For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3615 3616| **ID**| **Error Message** | 3617|-----------| ------------------------------------------------------------ | 3618| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3619| 14800000 | Inner error. | 3620| 14800014 | Already closed. | 3621| 14800015 | The database does not respond. | 3622 3623**Return value** 3624 3625| Type | Description | 3626| ------------------------------------------------------- | -------------------------------------------------- | 3627| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3628 3629**Example** 3630 3631```ts 3632import { BusinessError } from '@kit.BasicServicesKit'; 3633 3634let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3635predicates.equalTo("NAME", "Rose"); 3636if(store != undefined) { 3637 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 3638 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3639 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3640 while (resultSet.goToNextRow()) { 3641 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3642 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3643 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3644 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3645 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3646 } 3647 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3648 resultSet.close(); 3649 }).catch((err: BusinessError) => { 3650 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3651 }) 3652} 3653``` 3654 3655### querySync<sup>12+</sup> 3656 3657querySync(predicates: RdbPredicates, columns?: Array<string>):ResultSet 3658 3659Queries data in the RDB store based on specified **RdbPredicates** instance. 3660 3661**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3662 3663**Parameters** 3664 3665| Name | Type | Mandatory| Description | 3666| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ | 3667| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3668| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns. This parameter is left blank by default.| 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**Return value** 3682 3683| Type | Description | 3684| ----------------------- | ----------------------------------- | 3685| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 3686 3687**Example** 3688 3689```ts 3690import { BusinessError } from '@kit.BasicServicesKit'; 3691 3692let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3693predicates.equalTo("NAME", "Rose"); 3694if(store != undefined) { 3695 try { 3696 let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); 3697 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3698 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3699 while (resultSet.goToNextRow()) { 3700 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3701 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3702 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3703 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3704 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3705 } 3706 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3707 resultSet.close(); 3708 } catch (err) { 3709 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3710 } 3711} 3712``` 3713 3714### remoteQuery 3715 3716remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string> , callback: AsyncCallback<ResultSet>): void 3717 3718Queries data from the RDB store of a remote device based on specified conditions. This API uses an asynchronous callback to return the result. 3719 3720> **NOTE** 3721> 3722> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 3723 3724**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3725 3726**Parameters** 3727 3728| Name | Type | Mandatory| Description | 3729| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- | 3730| device | string | Yes | ID of the remote device. | 3731| table | string | Yes | Name of the target table. | 3732| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3733| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | 3734| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3735 3736**Error codes** 3737 3738For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3739 3740| **ID**| **Error Message** | 3741|-----------| ------------------------------------------------------------ | 3742| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3743| 801 | Capability not supported. | 3744| 14800000 | Inner error. | 3745| 14800014 | Already closed. | 3746 3747**Example** 3748 3749```ts 3750import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 3751import { BusinessError } from '@kit.BasicServicesKit'; 3752 3753let dmInstance: distributedDeviceManager.DeviceManager; 3754let deviceId: string | undefined = undefined; 3755 3756try { 3757 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 3758 let devices = dmInstance.getAvailableDeviceListSync(); 3759 if(deviceId != undefined) { 3760 deviceId = devices[0].networkId; 3761 } 3762} catch (err) { 3763 let code = (err as BusinessError).code; 3764 let message = (err as BusinessError).message; 3765 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 3766} 3767 3768let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 3769predicates.greaterThan("id", 0); 3770if(store != undefined && deviceId != undefined) { 3771 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 3772 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3773 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3774 while (resultSet.goToNextRow()) { 3775 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3776 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3777 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3778 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3779 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3780 } 3781 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3782 resultSet.close(); 3783 }).catch((err: BusinessError) => { 3784 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 3785 }) 3786} 3787``` 3788 3789### remoteQuery 3790 3791remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string>): Promise<ResultSet> 3792 3793Queries data from the RDB store of a remote device based on specified conditions. This API uses a promise to return the result. 3794 3795> **NOTE** 3796> 3797> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 3798 3799**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3800 3801**Parameters** 3802 3803| Name | Type | Mandatory| Description | 3804| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 3805| device | string | Yes | ID of the remote device. | 3806| table | string | Yes | Name of the target table. | 3807| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3808| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns.| 3809 3810**Return value** 3811 3812| Type | Description | 3813| ------------------------------------------------------------ | -------------------------------------------------- | 3814| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3815 3816**Error codes** 3817 3818For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3819 3820| **ID**| **Error Message** | 3821|-----------| ------------------------------------------------------------ | 3822| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3823| 801 | Capability not supported. | 3824| 14800000 | Inner error. | 3825| 14800014 | Already closed. | 3826 3827**Example** 3828 3829```ts 3830import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 3831import { BusinessError } from '@kit.BasicServicesKit'; 3832 3833let dmInstance: distributedDeviceManager.DeviceManager; 3834let deviceId: string | undefined = undefined; 3835 3836try { 3837 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 3838 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 3839 if(devices != undefined) { 3840 deviceId = devices[0].networkId; 3841 } 3842} catch (err) { 3843 let code = (err as BusinessError).code; 3844 let message = (err as BusinessError).message; 3845 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 3846} 3847 3848let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 3849predicates.greaterThan("id", 0); 3850if(store != undefined && deviceId != undefined) { 3851 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 3852 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3853 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3854 while (resultSet.goToNextRow()) { 3855 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3856 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3857 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3858 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3859 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3860 } 3861 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3862 resultSet.close(); 3863 }).catch((err: BusinessError) => { 3864 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 3865 }) 3866} 3867``` 3868 3869### querySql<sup>10+</sup> 3870 3871querySql(sql: string, callback: AsyncCallback<ResultSet>):void 3872 3873Queries data using the specified SQL statement. This API uses an asynchronous callback to return the result. 3874 3875**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3876 3877**Parameters** 3878 3879| Name | Type | Mandatory| Description | 3880| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | 3881| sql | string | Yes | SQL statement to run. | 3882| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned. | 3883 3884**Error codes** 3885 3886For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3887 3888| **ID**| **Error Message** | 3889|-----------| ------------------------------------------------------------ | 3890| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3891| 14800000 | Inner error. | 3892| 14800014 | Already closed. | 3893| 14800015 | The database does not respond. | 3894 3895**Example** 3896 3897```ts 3898if(store != undefined) { 3899 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'", (err, resultSet) => { 3900 if (err) { 3901 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3902 return; 3903 } 3904 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3905 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3906 while (resultSet.goToNextRow()) { 3907 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3908 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3909 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3910 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3911 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3912 } 3913 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3914 resultSet.close(); 3915 }) 3916} 3917``` 3918 3919### querySql 3920 3921querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void 3922 3923Queries data using the specified SQL statement. This API uses an asynchronous callback to return the result. 3924 3925**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3926 3927**Parameters** 3928 3929| Name | Type | Mandatory| Description | 3930| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | 3931| sql | string | Yes | SQL statement to run. | 3932| 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.| 3933| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned. | 3934 3935**Error codes** 3936 3937For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3938 3939| **ID**| **Error Message** | 3940|-----------| ------------------------------------------------------------ | 3941| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3942| 14800000 | Inner error. | 3943| 14800014 | Already closed. | 3944| 14800015 | The database does not respond. | 3945 3946**Example** 3947 3948```ts 3949if(store != undefined) { 3950 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], (err, resultSet) => { 3951 if (err) { 3952 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3953 return; 3954 } 3955 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3956 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3957 while (resultSet.goToNextRow()) { 3958 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3959 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3960 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3961 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3962 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3963 } 3964 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3965 resultSet.close(); 3966 }) 3967} 3968``` 3969 3970### querySql 3971 3972querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> 3973 3974Queries data using the specified SQL statement. This API uses a promise to return the result. 3975 3976**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3977 3978**Parameters** 3979 3980| Name | Type | Mandatory| Description | 3981| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 3982| sql | string | Yes | SQL statement to run. | 3983| 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.| 3984 3985**Return value** 3986 3987| Type | Description | 3988| ------------------------------------------------------- | -------------------------------------------------- | 3989| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3990 3991**Error codes** 3992 3993For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3994 3995| **ID**| **Error Message** | 3996|-----------| ------------------------------------------------------------ | 3997| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3998| 14800000 | Inner error. | 3999| 14800014 | Already closed. | 4000| 14800015 | The database does not respond. | 4001 4002**Example** 4003 4004```ts 4005import { BusinessError } from '@kit.BasicServicesKit'; 4006 4007if(store != undefined) { 4008 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then((resultSet: relationalStore.ResultSet) => { 4009 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4010 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4011 while (resultSet.goToNextRow()) { 4012 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4013 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4014 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4015 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4016 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4017 } 4018 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4019 resultSet.close(); 4020 }).catch((err: BusinessError) => { 4021 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4022 }) 4023} 4024``` 4025 4026### querySqlSync<sup>12+</sup> 4027 4028querySqlSync(sql: string, bindArgs?: Array<ValueType>):ResultSet 4029 4030Executes the SQL statement to query data in this RDB store. 4031 4032**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4033 4034**Parameters** 4035 4036| Name | Type | Mandatory| Description | 4037| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4038| sql | string | Yes | SQL statement to run. | 4039| 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. This parameter is left blank by default.| 4040 4041**Return value** 4042 4043| Type | Description | 4044| ----------------------- | ----------------------------------- | 4045| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 4046 4047**Error codes** 4048 4049For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4050 4051| **ID**| **Error Message** | 4052| ------------ | ------------------------------------------------------------ | 4053| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4054| 14800000 | Inner error. | 4055| 14800014 | Already closed. | 4056| 14800015 | The database does not respond. | 4057 4058**Example** 4059 4060```ts 4061import { BusinessError } from '@kit.BasicServicesKit'; 4062 4063let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 4064predicates.equalTo("NAME", "Rose"); 4065if(store != undefined) { 4066 try { 4067 let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'"); 4068 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4069 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4070 while (resultSet.goToNextRow()) { 4071 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4072 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4073 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4074 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4075 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4076 } 4077 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4078 resultSet.close(); 4079 } catch (err) { 4080 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4081 } 4082} 4083``` 4084 4085### executeSql<sup>10+</sup> 4086 4087executeSql(sql: string, callback: AsyncCallback<void>):void 4088 4089Executes an SQL statement that contains specified arguments but returns no value. This API uses an asynchronous callback to return the result. 4090 4091This 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). 4092 4093Statements separated by semicolons (;) are not supported. 4094 4095**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4096 4097**Parameters** 4098 4099| Name | Type | Mandatory| Description | 4100| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4101| sql | string | Yes | SQL statement to run. | 4102| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4103 4104**Error codes** 4105 4106For 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). 4107 4108| **ID**| **Error Message** | 4109|-----------| ------------------------------------------------------------ | 4110| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4111| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4112| 14800000 | Inner error. | 4113| 14800011 | Database corrupted. | 4114| 14800014 | Already closed. | 4115| 14800015 | The database does not respond. | 4116| 14800021 | SQLite: Generic error. | 4117| 14800022 | SQLite: Callback routine requested an abort. | 4118| 14800023 | SQLite: Access permission denied. | 4119| 14800024 | SQLite: The database file is locked. | 4120| 14800025 | SQLite: A table in the database is locked. | 4121| 14800026 | SQLite: The database is out of memory. | 4122| 14800027 | SQLite: Attempt to write a readonly database. | 4123| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4124| 14800029 | SQLite: The database is full. | 4125| 14800030 | SQLite: Unable to open the database file. | 4126| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4127| 14800032 | SQLite: Abort due to constraint violation. | 4128| 14800033 | SQLite: Data type mismatch. | 4129| 14800034 | SQLite: Library used incorrectly. | 4130| 14800047 | The WAL file size exceeds the default limit. | 4131 4132**Example** 4133 4134```ts 4135const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" 4136if(store != undefined) { 4137 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, (err) => { 4138 if (err) { 4139 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4140 return; 4141 } 4142 console.info('Delete table done.'); 4143 }) 4144} 4145``` 4146 4147### executeSql 4148 4149executeSql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<void>):void 4150 4151Executes an SQL statement that contains specified arguments but returns no value. This API uses an asynchronous callback to return the result. 4152 4153This 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). 4154 4155Statements separated by semicolons (;) are not supported. 4156 4157**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4158 4159**Parameters** 4160 4161| Name | Type | Mandatory| Description | 4162| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4163| sql | string | Yes | SQL statement to run. | 4164| 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.| 4165| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4166 4167**Error codes** 4168 4169For 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). 4170 4171| **ID**| **Error Message** | 4172|-----------| ------------------------------------------------------------ | 4173| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4174| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4175| 14800000 | Inner error. | 4176| 14800011 | Database corrupted. | 4177| 14800014 | Already closed. | 4178| 14800015 | The database does not respond. | 4179| 14800021 | SQLite: Generic error. | 4180| 14800022 | SQLite: Callback routine requested an abort. | 4181| 14800023 | SQLite: Access permission denied. | 4182| 14800024 | SQLite: The database file is locked. | 4183| 14800025 | SQLite: A table in the database is locked. | 4184| 14800026 | SQLite: The database is out of memory. | 4185| 14800027 | SQLite: Attempt to write a readonly database. | 4186| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4187| 14800029 | SQLite: The database is full. | 4188| 14800030 | SQLite: Unable to open the database file. | 4189| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4190| 14800032 | SQLite: Abort due to constraint violation. | 4191| 14800033 | SQLite: Data type mismatch. | 4192| 14800034 | SQLite: Library used incorrectly. | 4193| 14800047 | The WAL file size exceeds the default limit. | 4194 4195**Example** 4196 4197```ts 4198const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?" 4199if(store != undefined) { 4200 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, ['zhangsan'], (err) => { 4201 if (err) { 4202 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4203 return; 4204 } 4205 console.info('Delete table done.'); 4206 }) 4207} 4208``` 4209 4210### executeSql 4211 4212executeSql(sql: string, bindArgs?: Array<ValueType>):Promise<void> 4213 4214Executes an SQL statement that contains specified arguments but returns no value. This API uses a promise to return the result. 4215 4216This 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). 4217 4218Statements separated by semicolons (;) are not supported. 4219 4220**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4221 4222**Parameters** 4223 4224| Name | Type | Mandatory| Description | 4225| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4226| sql | string | Yes | SQL statement to run. | 4227| 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.| 4228 4229**Return value** 4230 4231| Type | Description | 4232| ------------------- | ------------------------- | 4233| Promise<void> | Promise that returns no value.| 4234 4235**Error codes** 4236 4237For 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). 4238 4239| **ID**| **Error Message** | 4240|-----------| ------------------------------------------------------------ | 4241| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4242| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4243| 14800000 | Inner error. | 4244| 14800011 | Database corrupted. | 4245| 14800014 | Already closed. | 4246| 14800015 | The database does not respond. | 4247| 14800021 | SQLite: Generic error. | 4248| 14800022 | SQLite: Callback routine requested an abort. | 4249| 14800023 | SQLite: Access permission denied. | 4250| 14800024 | SQLite: The database file is locked. | 4251| 14800025 | SQLite: A table in the database is locked. | 4252| 14800026 | SQLite: The database is out of memory. | 4253| 14800027 | SQLite: Attempt to write a readonly database. | 4254| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4255| 14800029 | SQLite: The database is full. | 4256| 14800030 | SQLite: Unable to open the database file. | 4257| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4258| 14800032 | SQLite: Abort due to constraint violation. | 4259| 14800033 | SQLite: Data type mismatch. | 4260| 14800034 | SQLite: Library used incorrectly. | 4261| 14800047 | The WAL file size exceeds the default limit. | 4262 4263**Example** 4264 4265```ts 4266import { BusinessError } from '@kit.BasicServicesKit'; 4267 4268const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" 4269if(store != undefined) { 4270 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE).then(() => { 4271 console.info('Delete table done.'); 4272 }).catch((err: BusinessError) => { 4273 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4274 }) 4275} 4276``` 4277 4278 4279### execute<sup>12+</sup> 4280 4281execute(sql: string, args?: Array<ValueType>):Promise<ValueType> 4282 4283Executes an SQL statement that contains the specified parameters. This API uses a promise to return the result. 4284 4285This 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. 4286 4287This 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). 4288 4289Statements separated by semicolons (;) are not supported. 4290 4291**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4292 4293**Parameters** 4294 4295| Name | Type | Mandatory| Description | 4296| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4297| sql | string | Yes | SQL statement to run. | 4298| 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.| 4299 4300**Return value** 4301 4302| Type | Description | 4303| ------------------- | ------------------------- | 4304| Promise<[ValueType](#valuetype)> | Promise used to return the SQL execution result.| 4305 4306**Error codes** 4307 4308For 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). 4309 4310| **ID**| **Error Message** | 4311|-----------| ------------------------------------------------------------ | 4312| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4313| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4314| 14800000 | Inner error. | 4315| 14800011 | Database corrupted. | 4316| 14800014 | Already closed. | 4317| 14800015 | The database does not respond. | 4318| 14800021 | SQLite: Generic error. | 4319| 14800022 | SQLite: Callback routine requested an abort. | 4320| 14800023 | SQLite: Access permission denied. | 4321| 14800024 | SQLite: The database file is locked. | 4322| 14800025 | SQLite: A table in the database is locked. | 4323| 14800026 | SQLite: The database is out of memory. | 4324| 14800027 | SQLite: Attempt to write a readonly database. | 4325| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4326| 14800029 | SQLite: The database is full. | 4327| 14800030 | SQLite: Unable to open the database file. | 4328| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4329| 14800032 | SQLite: Abort due to constraint violation. | 4330| 14800033 | SQLite: Data type mismatch. | 4331| 14800034 | SQLite: Library used incorrectly. | 4332| 14800047 | The WAL file size exceeds the default limit. | 4333 4334**Example** 4335 4336```ts 4337import { BusinessError } from '@kit.BasicServicesKit'; 4338 4339// Check the RDB store integrity. 4340if(store != undefined) { 4341 const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check'; 4342 (store as relationalStore.RdbStore).execute(SQL_CHECK_INTEGRITY).then((data) => { 4343 console.info(`check result: ${data}`); 4344 }).catch((err: BusinessError) => { 4345 console.error(`check failed, code is ${err.code}, message is ${err.message}`); 4346 }) 4347} 4348 4349// Delete all data from the table. 4350if(store != undefined) { 4351 const SQL_DELETE_TABLE = 'DELETE FROM test'; 4352 (store as relationalStore.RdbStore).execute(SQL_DELETE_TABLE).then((data) => { 4353 console.info(`delete result: ${data}`); 4354 }).catch((err: BusinessError) => { 4355 console.error(`delete failed, code is ${err.code}, message is ${err.message}`); 4356 }) 4357} 4358 4359// Delete a table. 4360if(store != undefined) { 4361 const SQL_DROP_TABLE = 'DROP TABLE test'; 4362 (store as relationalStore.RdbStore).execute(SQL_DROP_TABLE).then((data) => { 4363 console.info(`drop result: ${data}`); 4364 }).catch((err: BusinessError) => { 4365 console.error(`drop failed, code is ${err.code}, message is ${err.message}`); 4366 }) 4367} 4368``` 4369 4370### execute<sup>12+</sup> 4371 4372execute(sql: string, txId: number, args?: Array<ValueType>): Promise<ValueType> 4373 4374Executes an SQL statement that contains the specified parameters. This API uses a promise to return the result. 4375 4376<!--RP1--> 4377This API can be used only for a [vector database](js-apis-data-relationalStore-sys.md#storeconfig).<!--RP1End--> 4378 4379This 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). 4380 4381Statements separated by semicolons (;) are not supported. 4382 4383**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4384 4385**Parameters** 4386 4387| Name | Type | Mandatory| Description | 4388| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4389| sql | string | Yes | SQL statement to run. | 4390| 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. | 4391| 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.| 4392 4393**Return value** 4394 4395| Type | Description | 4396| ------------------- | ------------------------- | 4397| Promise<[ValueType](#valuetype)> | Promise that returns **null**.| 4398 4399**Error codes** 4400 4401For 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). 4402 4403| **ID**| **Error Message** | 4404|-----------| ------------------------------------------------------------ | 4405| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4406| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4407| 14800000 | Inner error. | 4408| 14800011 | Database corrupted. | 4409| 14800014 | Already closed. | 4410| 14800015 | The database does not respond. | 4411| 14800021 | SQLite: Generic error. | 4412| 14800022 | SQLite: Callback routine requested an abort. | 4413| 14800023 | SQLite: Access permission denied. | 4414| 14800024 | SQLite: The database file is locked. | 4415| 14800025 | SQLite: A table in the database is locked. | 4416| 14800026 | SQLite: The database is out of memory. | 4417| 14800027 | SQLite: Attempt to write a readonly database. | 4418| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4419| 14800029 | SQLite: The database is full. | 4420| 14800030 | SQLite: Unable to open the database file. | 4421| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4422| 14800032 | SQLite: Abort due to constraint violation. | 4423| 14800033 | SQLite: Data type mismatch. | 4424| 14800034 | SQLite: Library used incorrectly. | 4425| 14800047 | The WAL file size exceeds the default limit. | 4426 4427**Example** 4428 4429```ts 4430import { BusinessError } from '@kit.BasicServicesKit'; 4431if(store != null) { 4432 let txId : number; 4433 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 4434 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 4435 .then(() => { 4436 (store as relationalStore.RdbStore).commit(txId); 4437 }) 4438 .catch((err: BusinessError) => { 4439 (store as relationalStore.RdbStore).rollback(txId) 4440 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 4441 }); 4442 }); 4443} 4444``` 4445 4446### executeSync<sup>12+</sup> 4447 4448executeSync(sql: string, args?: Array<ValueType>): ValueType 4449 4450Executes an SQL statement containing the specified parameters. The return value type is ValueType. 4451 4452You can use this API to add, delete, or modify a row of data with SQL statements of the PRAGMA syntax, and create, delete, or modify a table. The type of the return value is determined by the execution result. 4453 4454This 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). 4455 4456Statements separated by semicolons (;) are not supported. 4457 4458**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4459 4460**Parameters** 4461 4462| Name| Type | Mandatory| Description | 4463| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 4464| sql | string | Yes | SQL statement to run. | 4465| 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. This parameter is left blank by default.| 4466 4467**Return value** 4468 4469| Type | Description | 4470| ----------------------- | ------------------- | 4471| [ValueType](#valuetype) | SQL execution result.| 4472 4473**Error codes** 4474 4475For 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). 4476 4477| **ID**| **Error Message** | 4478| ------------ | ------------------------------------------------------------ | 4479| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4480| 14800000 | Inner error. | 4481| 14800011 | Database corrupted. | 4482| 14800014 | Already closed. | 4483| 14800015 | The database does not respond. | 4484| 14800021 | SQLite: Generic error. | 4485| 14800022 | SQLite: Callback routine requested an abort. | 4486| 14800023 | SQLite: Access permission denied. | 4487| 14800024 | SQLite: The database file is locked. | 4488| 14800025 | SQLite: A table in the database is locked. | 4489| 14800026 | SQLite: The database is out of memory. | 4490| 14800027 | SQLite: Attempt to write a readonly database. | 4491| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4492| 14800029 | SQLite: The database is full. | 4493| 14800030 | SQLite: Unable to open the database file. | 4494| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4495| 14800032 | SQLite: Abort due to constraint violation. | 4496| 14800033 | SQLite: Data type mismatch. | 4497| 14800034 | SQLite: Library used incorrectly. | 4498| 14800047 | The WAL file size exceeds the default limit. | 4499 4500**Example** 4501 4502```ts 4503import { BusinessError } from '@kit.BasicServicesKit'; 4504 4505// Check the RDB store integrity. 4506if(store != undefined) { 4507 const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check'; 4508 try { 4509 let data = (store as relationalStore.RdbStore).executeSync(SQL_CHECK_INTEGRITY) 4510 console.info(`check result: ${data}`); 4511 } catch (err) { 4512 console.error(`check failed, code is ${err.code}, message is ${err.message}`); 4513 } 4514} 4515 4516// Delete all data from the table. 4517if(store != undefined) { 4518 const SQL_DELETE_TABLE = 'DELETE FROM test'; 4519 try { 4520 let data = (store as relationalStore.RdbStore).executeSync(SQL_DELETE_TABLE) 4521 console.info(`delete result: ${data}`); 4522 } catch (err) { 4523 console.error(`delete failed, code is ${err.code}, message is ${err.message}`); 4524 } 4525} 4526 4527// Delete a table. 4528if(store != undefined) { 4529 const SQL_DROP_TABLE = 'DROP TABLE test'; 4530 try { 4531 let data = (store as relationalStore.RdbStore).executeSync(SQL_DROP_TABLE) 4532 console.info(`drop result: ${data}`); 4533 } catch (err) { 4534 console.error(`drop failed, code is ${err.code}, message is ${err.message}`); 4535 } 4536} 4537``` 4538 4539### getModifyTime<sup>10+</sup> 4540 4541getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[], callback: AsyncCallback<ModifyTime>): void 4542 4543Obtains the last modification time of the data in a table. This API uses an asynchronous callback to return the result. 4544 4545**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4546 4547**Parameters** 4548 4549| Name | Type | Mandatory| Description | 4550| ----------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 4551| table | string | Yes | Name of the database table to query. | 4552| columnName | string | Yes | Column name of the database table to query. | 4553| 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.| 4554| callback | AsyncCallback<[ModifyTime](#modifytime10)> | Yes | Callback used to return the result. If the operation is successful, the **ModifyTime** object is returned.| 4555 4556**Error codes** 4557 4558For 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). 4559 4560| **ID**| **Error Message** | 4561|-----------| ------------------------------------------------------------ | 4562| 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. | 4563| 801 | Capability not supported. | 4564| 14800000 | Inner error. | 4565| 14800011 | Database corrupted. | 4566| 14800014 | Already closed. | 4567| 14800015 | The database does not respond. | 4568| 14800021 | SQLite: Generic error. | 4569| 14800022 | SQLite: Callback routine requested an abort. | 4570| 14800023 | SQLite: Access permission denied. | 4571| 14800024 | SQLite: The database file is locked. | 4572| 14800025 | SQLite: A table in the database is locked. | 4573| 14800026 | SQLite: The database is out of memory. | 4574| 14800027 | SQLite: Attempt to write a readonly database. | 4575| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4576| 14800029 | SQLite: The database is full. | 4577| 14800030 | SQLite: Unable to open the database file. | 4578| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4579| 14800032 | SQLite: Abort due to constraint violation. | 4580| 14800033 | SQLite: Data type mismatch. | 4581| 14800034 | SQLite: Library used incorrectly. | 4582 4583**Example** 4584 4585```ts 4586let PRIKey = [1, 4, 2, 3]; 4587if(store != undefined) { 4588 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey, (err, modifyTime: relationalStore.ModifyTime) => { 4589 if (err) { 4590 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 4591 return; 4592 } 4593 let size = modifyTime.size; 4594 }); 4595} 4596``` 4597 4598### getModifyTime<sup>10+</sup> 4599 4600getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[]): Promise<ModifyTime> 4601 4602Obtains the last modification time of the data in a table. This API uses a promise to return the result. 4603 4604**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4605 4606**Parameters** 4607 4608| Name | Type | Mandatory| Description | 4609| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ | 4610| table | string | Yes | Name of the database table to query. | 4611| columnName | string | Yes | Column name of the database table to query. | 4612| 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.| 4613 4614**Return value** 4615 4616| Type | Description | 4617| ------------------------------------------ | --------------------------------------------------------- | 4618| Promise<[ModifyTime](#modifytime10)> | Promise used to return the **ModifyTime** object.| 4619 4620**Error codes** 4621 4622For 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). 4623 4624| **ID**| **Error Message** | 4625|-----------| ------------------------------------------------------------ | 4626| 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. | 4627| 801 | Capability not supported. | 4628| 14800000 | Inner error. | 4629| 14800011 | Database corrupted. | 4630| 14800014 | Already closed. | 4631| 14800015 | The database does not respond. | 4632| 14800021 | SQLite: Generic error. | 4633| 14800022 | SQLite: Callback routine requested an abort. | 4634| 14800023 | SQLite: Access permission denied. | 4635| 14800024 | SQLite: The database file is locked. | 4636| 14800025 | SQLite: A table in the database is locked. | 4637| 14800026 | SQLite: The database is out of memory. | 4638| 14800027 | SQLite: Attempt to write a readonly database. | 4639| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4640| 14800029 | SQLite: The database is full. | 4641| 14800030 | SQLite: Unable to open the database file. | 4642| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4643| 14800032 | SQLite: Abort due to constraint violation. | 4644| 14800033 | SQLite: Data type mismatch. | 4645| 14800034 | SQLite: Library used incorrectly. | 4646 4647**Example** 4648 4649```ts 4650import { BusinessError } from '@kit.BasicServicesKit'; 4651 4652let PRIKey = [1, 2, 3]; 4653if(store != undefined) { 4654 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey) 4655 .then((modifyTime: relationalStore.ModifyTime) => { 4656 let size = modifyTime.size; 4657 }) 4658 .catch((err: BusinessError) => { 4659 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 4660 }); 4661} 4662``` 4663 4664### beginTransaction 4665 4666beginTransaction():void 4667 4668Starts the transaction before executing an SQL statement. 4669This API does not allow nested transactions and cannot be used across processes or threads. 4670 4671**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4672 4673**Error codes** 4674 4675For 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). 4676 4677| **ID**| **Error Message** | 4678|-----------| ------------------------------------------------------------ | 4679| 401 | Parameter error. The store must not be nullptr. | 4680| 14800000 | Inner error. | 4681| 14800011 | Database corrupted. | 4682| 14800014 | Already closed. | 4683| 14800015 | The database does not respond. | 4684| 14800021 | SQLite: Generic error. | 4685| 14800022 | SQLite: Callback routine requested an abort. | 4686| 14800023 | SQLite: Access permission denied. | 4687| 14800024 | SQLite: The database file is locked. | 4688| 14800025 | SQLite: A table in the database is locked. | 4689| 14800026 | SQLite: The database is out of memory. | 4690| 14800027 | SQLite: Attempt to write a readonly database. | 4691| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4692| 14800029 | SQLite: The database is full. | 4693| 14800030 | SQLite: Unable to open the database file. | 4694| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4695| 14800032 | SQLite: Abort due to constraint violation. | 4696| 14800033 | SQLite: Data type mismatch. | 4697| 14800034 | SQLite: Library used incorrectly. | 4698| 14800047 | The WAL file size exceeds the default limit. | 4699 4700**Example** 4701 4702```ts 4703 4704let value1 = "Lisa"; 4705let value2 = 18; 4706let value3 = 100.5; 4707let value4 = new Uint8Array([1, 2, 3]); 4708 4709if(store != undefined) { 4710 (store as relationalStore.RdbStore).beginTransaction(); 4711 const valueBucket: relationalStore.ValuesBucket = { 4712 'NAME': value1, 4713 'AGE': value2, 4714 'SALARY': value3, 4715 'CODES': value4, 4716 }; 4717 (store as relationalStore.RdbStore).insert("test", valueBucket); 4718 (store as relationalStore.RdbStore).commit(); 4719} 4720``` 4721 4722### beginTrans<sup>12+</sup> 4723 4724beginTrans(): Promise<number> 4725 4726Begins the transaction before executing the SQL statement. This API uses a promise to return the result. 4727 4728Different from [beginTransaction](#begintransaction), this API returns a transaction ID. [execute](#execute12-1) can specify the transaction ID to isolate different transactions. 4729 4730<!--RP1--> 4731This API can be used only for a [vector database](js-apis-data-relationalStore-sys.md#storeconfig).<!--RP1End--> 4732 4733**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4734 4735**Return value** 4736 4737| Type | Description | 4738| ------------------- | ------------------------- | 4739| Promise<number> | Promise used to return the transaction ID.| 4740 4741**Error codes** 4742 4743For 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). 4744 4745| **ID**| **Error Message** | 4746|-----------| ------------------------------------------------------------ | 4747| 401 | Parameter error. The store must not be nullptr. | 4748| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4749| 14800000 | Inner error. | 4750| 14800011 | Database corrupted. | 4751| 14800014 | Already closed. | 4752| 14800015 | The database does not respond. | 4753| 14800021 | SQLite: Generic error. | 4754| 14800022 | SQLite: Callback routine requested an abort. | 4755| 14800023 | SQLite: Access permission denied. | 4756| 14800024 | SQLite: The database file is locked. | 4757| 14800025 | SQLite: A table in the database is locked. | 4758| 14800026 | SQLite: The database is out of memory. | 4759| 14800027 | SQLite: Attempt to write a readonly database. | 4760| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4761| 14800029 | SQLite: The database is full. | 4762| 14800030 | SQLite: Unable to open the database file. | 4763| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4764| 14800032 | SQLite: Abort due to constraint violation. | 4765| 14800033 | SQLite: Data type mismatch. | 4766| 14800034 | SQLite: Library used incorrectly. | 4767| 14800047 | The WAL file size exceeds the default limit. | 4768 4769**Example** 4770 4771```ts 4772import { BusinessError } from '@kit.BasicServicesKit'; 4773if(store != null) { 4774 let txId : number; 4775 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 4776 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 4777 .then(() => { 4778 (store as relationalStore.RdbStore).commit(txId); 4779 }) 4780 .catch((err: BusinessError) => { 4781 (store as relationalStore.RdbStore).rollback(txId) 4782 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 4783 }); 4784 }); 4785} 4786``` 4787 4788### commit 4789 4790commit():void 4791 4792Commits the executed SQL statements. 4793This API does not allow nested transactions and cannot be used across processes or threads. 4794 4795**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4796 4797**Error codes** 4798 4799For 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). 4800 4801| **ID**| **Error Message** | 4802|-----------| ------------------------------------------------------------ | 4803| 401 | Parameter error. The store must not be nullptr. | 4804| 14800000 | Inner error. | 4805| 14800011 | Database corrupted. | 4806| 14800014 | Already closed. | 4807| 14800015 | The database does not respond. | 4808| 14800021 | SQLite: Generic error. | 4809| 14800022 | SQLite: Callback routine requested an abort. | 4810| 14800023 | SQLite: Access permission denied. | 4811| 14800024 | SQLite: The database file is locked. | 4812| 14800025 | SQLite: A table in the database is locked. | 4813| 14800026 | SQLite: The database is out of memory. | 4814| 14800027 | SQLite: Attempt to write a readonly database. | 4815| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4816| 14800029 | SQLite: The database is full. | 4817| 14800030 | SQLite: Unable to open the database file. | 4818| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4819| 14800032 | SQLite: Abort due to constraint violation. | 4820| 14800033 | SQLite: Data type mismatch. | 4821| 14800034 | SQLite: Library used incorrectly. | 4822 4823**Example** 4824 4825```ts 4826 4827let value1 = "Lisa"; 4828let value2 = 18; 4829let value3 = 100.5; 4830let value4 = new Uint8Array([1, 2, 3]); 4831 4832if(store != undefined) { 4833 (store as relationalStore.RdbStore).beginTransaction(); 4834 const valueBucket: relationalStore.ValuesBucket = { 4835 'NAME': value1, 4836 'AGE': value2, 4837 'SALARY': value3, 4838 'CODES': value4, 4839 }; 4840 (store as relationalStore.RdbStore).insert("test", valueBucket); 4841 (store as relationalStore.RdbStore).commit(); 4842} 4843``` 4844 4845### commit<sup>12+</sup> 4846 4847commit(txId : number):Promise<void> 4848 4849Commits the executed SQL statements. This API must be used with [beginTrans](#begintrans12). 4850 4851<!--RP1--> 4852This API can be used only for a [vector database](js-apis-data-relationalStore-sys.md#storeconfig).<!--RP1End--> 4853 4854**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4855 4856**Parameters** 4857 4858| Name | Type | Mandatory| Description | 4859| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4860| txId | number | Yes | Transaction ID obtained via [beginTrans](#begintrans12). | 4861 4862**Return value** 4863 4864| Type | Description | 4865| ------------------- | ------------------------- | 4866| Promise<void> | Promise that returns no value.| 4867 4868**Error codes** 4869 4870For 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). 4871 4872| **ID**| **Error Message** | 4873|-----------| ------------------------------------------------------------ | 4874| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4875| 14800000 | Inner error. | 4876| 14800011 | Database corrupted. | 4877| 14800014 | Already closed. | 4878| 14800015 | The database does not respond. | 4879| 14800021 | SQLite: Generic error. | 4880| 14800022 | SQLite: Callback routine requested an abort. | 4881| 14800023 | SQLite: Access permission denied. | 4882| 14800024 | SQLite: The database file is locked. | 4883| 14800025 | SQLite: A table in the database is locked. | 4884| 14800026 | SQLite: The database is out of memory. | 4885| 14800027 | SQLite: Attempt to write a readonly database. | 4886| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4887| 14800029 | SQLite: The database is full. | 4888| 14800030 | SQLite: Unable to open the database file. | 4889| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4890| 14800032 | SQLite: Abort due to constraint violation. | 4891| 14800033 | SQLite: Data type mismatch. | 4892| 14800034 | SQLite: Library used incorrectly. | 4893 4894**Example** 4895 4896```ts 4897import { BusinessError } from '@kit.BasicServicesKit'; 4898if(store != null) { 4899 let txId : number; 4900 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 4901 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 4902 .then(() => { 4903 (store as relationalStore.RdbStore).commit(txId); 4904 }) 4905 .catch((err: BusinessError) => { 4906 (store as relationalStore.RdbStore).rollback(txId) 4907 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 4908 }); 4909 }); 4910} 4911``` 4912 4913### rollBack 4914 4915rollBack():void 4916 4917Rolls back the SQL statements that have been executed. 4918This API does not allow nested transactions and cannot be used across processes or threads. 4919 4920**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4921 4922**Error codes** 4923 4924For 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). 4925 4926| **ID**| **Error Message** | 4927|-----------| ------------------------------------------------------------ | 4928| 401 | Parameter error. The store must not be nullptr. | 4929| 14800000 | Inner error. | 4930| 14800011 | Database corrupted. | 4931| 14800014 | Already closed. | 4932| 14800015 | The database does not respond. | 4933| 14800021 | SQLite: Generic error. | 4934| 14800022 | SQLite: Callback routine requested an abort. | 4935| 14800023 | SQLite: Access permission denied. | 4936| 14800024 | SQLite: The database file is locked. | 4937| 14800025 | SQLite: A table in the database is locked. | 4938| 14800026 | SQLite: The database is out of memory. | 4939| 14800027 | SQLite: Attempt to write a readonly database. | 4940| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4941| 14800029 | SQLite: The database is full. | 4942| 14800030 | SQLite: Unable to open the database file. | 4943| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4944| 14800032 | SQLite: Abort due to constraint violation. | 4945| 14800033 | SQLite: Data type mismatch. | 4946| 14800034 | SQLite: Library used incorrectly. | 4947 4948**Example** 4949 4950```ts 4951import { BusinessError } from '@kit.BasicServicesKit'; 4952 4953let value1 = "Lisa"; 4954let value2 = 18; 4955let value3 = 100.5; 4956let value4 = new Uint8Array([1, 2, 3]); 4957 4958if(store != undefined) { 4959 try { 4960 (store as relationalStore.RdbStore).beginTransaction() 4961 const valueBucket: relationalStore.ValuesBucket = { 4962 'NAME': value1, 4963 'AGE': value2, 4964 'SALARY': value3, 4965 'CODES': value4, 4966 }; 4967 (store as relationalStore.RdbStore).insert("test", valueBucket); 4968 (store as relationalStore.RdbStore).commit(); 4969 } catch (err) { 4970 let code = (err as BusinessError).code; 4971 let message = (err as BusinessError).message 4972 console.error(`Transaction failed, code is ${code},message is ${message}`); 4973 (store as relationalStore.RdbStore).rollBack(); 4974 } 4975} 4976``` 4977 4978### rollback<sup>12+</sup> 4979 4980rollback(txId : number):Promise<void> 4981 4982Rolls back the executed SQL statements. This API must be used with [beginTrans](#begintrans12). 4983 4984<!--RP1--> 4985This API can be used only for a [vector database](js-apis-data-relationalStore-sys.md#storeconfig).<!--RP1End--> 4986 4987**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4988 4989**Parameters** 4990 4991| Name | Type | Mandatory| Description | 4992| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4993| txId | number | Yes | Transaction ID obtained via [beginTrans](#begintrans12). | 4994 4995**Return value** 4996 4997| Type | Description | 4998| ------------------- | ------------------------- | 4999| Promise<void> | Promise that returns no value.| 5000 5001**Error codes** 5002 5003For 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). 5004 5005| **ID**| **Error Message** | 5006|-----------| ------------------------------------------------------------ | 5007| 401 | Parameter error. The store must not be nullptr. | 5008| 14800000 | Inner error. | 5009| 14800011 | Database corrupted. | 5010| 14800014 | Already closed. | 5011| 14800015 | The database does not respond. | 5012| 14800021 | SQLite: Generic error. | 5013| 14800022 | SQLite: Callback routine requested an abort. | 5014| 14800023 | SQLite: Access permission denied. | 5015| 14800024 | SQLite: The database file is locked. | 5016| 14800025 | SQLite: A table in the database is locked. | 5017| 14800026 | SQLite: The database is out of memory. | 5018| 14800027 | SQLite: Attempt to write a readonly database. | 5019| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5020| 14800029 | SQLite: The database is full. | 5021| 14800030 | SQLite: Unable to open the database file. | 5022| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5023| 14800032 | SQLite: Abort due to constraint violation. | 5024| 14800033 | SQLite: Data type mismatch. | 5025| 14800034 | SQLite: Library used incorrectly. | 5026 5027**Example** 5028 5029```ts 5030import { BusinessError } from '@kit.BasicServicesKit'; 5031if(store != null) { 5032 let txId : number; 5033 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 5034 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 5035 .then(() => { 5036 (store as relationalStore.RdbStore).commit(txId); 5037 }) 5038 .catch((err: BusinessError) => { 5039 (store as relationalStore.RdbStore).rollback(txId) 5040 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 5041 }); 5042 }); 5043} 5044``` 5045 5046### backup 5047 5048backup(destName:string, callback: AsyncCallback<void>):void 5049 5050Backs up an RDB store. This API uses an asynchronous callback to return the result. 5051 5052**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5053 5054**Parameters** 5055 5056| Name | Type | Mandatory| Description | 5057| -------- | ------------------------- | ---- | ------------------------ | 5058| destName | string | Yes | Name of the RDB store backup file.| 5059| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5060 5061**Error codes** 5062 5063For 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). 5064 5065| **ID**| **Error Message** | 5066|-----------| ------------------------------------------------------------ | 5067| 401 | Parameter error. The store must not be nullptr. | 5068| 14800000 | Inner error. | 5069| 14800010 | Invalid database path. | 5070| 14800011 | Database corrupted. | 5071| 14800014 | Already closed. | 5072| 14800015 | The database does not respond. | 5073| 14800021 | SQLite: Generic error. | 5074| 14800022 | SQLite: Callback routine requested an abort. | 5075| 14800023 | SQLite: Access permission denied. | 5076| 14800024 | SQLite: The database file is locked. | 5077| 14800025 | SQLite: A table in the database is locked. | 5078| 14800026 | SQLite: The database is out of memory. | 5079| 14800027 | SQLite: Attempt to write a readonly database. | 5080| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5081| 14800029 | SQLite: The database is full. | 5082| 14800030 | SQLite: Unable to open the database file. | 5083| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5084| 14800032 | SQLite: Abort due to constraint violation. | 5085| 14800033 | SQLite: Data type mismatch. | 5086| 14800034 | SQLite: Library used incorrectly. | 5087 5088**Example** 5089 5090```ts 5091if(store != undefined) { 5092 (store as relationalStore.RdbStore).backup("dbBackup.db", (err) => { 5093 if (err) { 5094 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 5095 return; 5096 } 5097 console.info('Backup success.'); 5098 }) 5099} 5100``` 5101 5102### backup 5103 5104backup(destName:string): Promise<void> 5105 5106Backs up an RDB store. This API uses a promise to return the result. 5107 5108**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5109 5110**Parameters** 5111 5112| Name | Type | Mandatory| Description | 5113| -------- | ------ | ---- | ------------------------ | 5114| destName | string | Yes | Name of the RDB store backup file.| 5115 5116**Return value** 5117 5118| Type | Description | 5119| ------------------- | ------------------------- | 5120| Promise<void> | Promise that returns no value.| 5121 5122**Error codes** 5123 5124For 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). 5125 5126| **ID**| **Error Message** | 5127|-----------| ------------------------------------------------------------ | 5128| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5129| 14800000 | Inner error. | 5130| 14800011 | Database corrupted. | 5131| 14800014 | Already closed. | 5132| 14800015 | The database does not respond. | 5133| 14800021 | SQLite: Generic error. | 5134| 14800022 | SQLite: Callback routine requested an abort. | 5135| 14800023 | SQLite: Access permission denied. | 5136| 14800024 | SQLite: The database file is locked. | 5137| 14800025 | SQLite: A table in the database is locked. | 5138| 14800026 | SQLite: The database is out of memory. | 5139| 14800027 | SQLite: Attempt to write a readonly database. | 5140| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5141| 14800029 | SQLite: The database is full. | 5142| 14800030 | SQLite: Unable to open the database file. | 5143| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5144| 14800032 | SQLite: Abort due to constraint violation. | 5145| 14800033 | SQLite: Data type mismatch. | 5146| 14800034 | SQLite: Library used incorrectly. | 5147 5148**Example** 5149 5150```ts 5151import { BusinessError } from '@kit.BasicServicesKit'; 5152 5153if(store != undefined) { 5154 let promiseBackup = (store as relationalStore.RdbStore).backup("dbBackup.db"); 5155 promiseBackup.then(() => { 5156 console.info('Backup success.'); 5157 }).catch((err: BusinessError) => { 5158 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 5159 }) 5160} 5161``` 5162 5163### restore 5164 5165restore(srcName:string, callback: AsyncCallback<void>):void 5166 5167Restores an RDB store from a backup file. This API uses an asynchronous callback to return the result. 5168 5169**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5170 5171**Parameters** 5172 5173| Name | Type | Mandatory| Description | 5174| -------- | ------------------------- | ---- | ------------------------ | 5175| srcName | string | Yes | Name of the RDB store backup file.| 5176| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5177 5178**Error codes** 5179 5180For 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). 5181 5182| **ID**| **Error Message** | 5183|-----------| ------------------------------------------------------------ | 5184| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5185| 14800000 | Inner error. | 5186| 14800011 | Database corrupted. | 5187| 14800014 | Already closed. | 5188| 14800015 | The database does not respond. | 5189| 14800021 | SQLite: Generic error. | 5190| 14800022 | SQLite: Callback routine requested an abort. | 5191| 14800023 | SQLite: Access permission denied. | 5192| 14800024 | SQLite: The database file is locked. | 5193| 14800025 | SQLite: A table in the database is locked. | 5194| 14800026 | SQLite: The database is out of memory. | 5195| 14800027 | SQLite: Attempt to write a readonly database. | 5196| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5197| 14800029 | SQLite: The database is full. | 5198| 14800030 | SQLite: Unable to open the database file. | 5199| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5200| 14800032 | SQLite: Abort due to constraint violation. | 5201| 14800033 | SQLite: Data type mismatch. | 5202| 14800034 | SQLite: Library used incorrectly. | 5203 5204**Example** 5205 5206```ts 5207if(store != undefined) { 5208 (store as relationalStore.RdbStore).restore("dbBackup.db", (err) => { 5209 if (err) { 5210 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 5211 return; 5212 } 5213 console.info('Restore success.'); 5214 }) 5215} 5216``` 5217 5218### restore 5219 5220restore(srcName:string): Promise<void> 5221 5222Restores an RDB store from a backup file. This API uses a promise to return the result. 5223 5224**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5225 5226**Parameters** 5227 5228| Name | Type | Mandatory| Description | 5229| ------- | ------ | ---- | ------------------------ | 5230| srcName | string | Yes | Name of the RDB store backup file.| 5231 5232**Return value** 5233 5234| Type | Description | 5235| ------------------- | ------------------------- | 5236| Promise<void> | Promise that returns no value.| 5237 5238**Error codes** 5239 5240For 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). 5241 5242| **ID**| **Error Message** | 5243|-----------| ------------------------------------------------------------ | 5244| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5245| 14800000 | Inner error. | 5246| 14800011 | Database corrupted. | 5247| 14800014 | Already closed. | 5248| 14800015 | The database does not respond. | 5249| 14800021 | SQLite: Generic error. | 5250| 14800022 | SQLite: Callback routine requested an abort. | 5251| 14800023 | SQLite: Access permission denied. | 5252| 14800024 | SQLite: The database file is locked. | 5253| 14800025 | SQLite: A table in the database is locked. | 5254| 14800026 | SQLite: The database is out of memory. | 5255| 14800027 | SQLite: Attempt to write a readonly database. | 5256| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5257| 14800029 | SQLite: The database is full. | 5258| 14800030 | SQLite: Unable to open the database file. | 5259| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5260| 14800032 | SQLite: Abort due to constraint violation. | 5261| 14800033 | SQLite: Data type mismatch. | 5262| 14800034 | SQLite: Library used incorrectly. | 5263 5264**Example** 5265 5266```ts 5267import { BusinessError } from '@kit.BasicServicesKit'; 5268 5269if(store != undefined) { 5270 let promiseRestore = (store as relationalStore.RdbStore).restore("dbBackup.db"); 5271 promiseRestore.then(() => { 5272 console.info('Restore success.'); 5273 }).catch((err: BusinessError) => { 5274 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 5275 }) 5276} 5277``` 5278 5279### setDistributedTables 5280 5281setDistributedTables(tables: Array<string>, callback: AsyncCallback<void>): void 5282 5283Sets distributed tables. This API uses an asynchronous callback to return the result. 5284 5285**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5286 5287**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5288 5289**Parameters** 5290 5291| Name | Type | Mandatory| Description | 5292| -------- | ------------------------- | ---- | ---------------------- | 5293| tables | Array<string> | Yes | Names of the distributed tables to set.| 5294| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 5295 5296**Error codes** 5297 5298For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5299 5300| **ID**| **Error Message** | 5301|-----------| ------------------------------------------------------------ | 5302| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5303| 801 | Capability not supported. | 5304| 14800000 | Inner error. | 5305| 14800014 | Already closed. | 5306 5307**Example** 5308 5309```ts 5310if(store != undefined) { 5311 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], (err) => { 5312 if (err) { 5313 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5314 return; 5315 } 5316 console.info('SetDistributedTables successfully.'); 5317 }) 5318} 5319``` 5320 5321### setDistributedTables 5322 5323 setDistributedTables(tables: Array<string>): Promise<void> 5324 5325Sets distributed tables. This API uses a promise to return the result. 5326 5327**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5328 5329**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5330 5331**Parameters** 5332 5333| Name| Type | Mandatory| Description | 5334| ------ | ------------------------ | ---- | ------------------------ | 5335| tables | ArrayArray<string> | Yes | Names of the distributed tables to set.| 5336 5337**Return value** 5338 5339| Type | Description | 5340| ------------------- | ------------------------- | 5341| Promise<void> | Promise that returns no value.| 5342 5343**Error codes** 5344 5345For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5346 5347| **ID**| **Error Message** | 5348|-----------| ------------------------------------------------------------ | 5349| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5350| 801 | Capability not supported. | 5351| 14800000 | Inner error. | 5352| 14800014 | Already closed. | 5353 5354**Example** 5355 5356```ts 5357import { BusinessError } from '@kit.BasicServicesKit'; 5358 5359if(store != undefined) { 5360 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"]).then(() => { 5361 console.info('SetDistributedTables successfully.'); 5362 }).catch((err: BusinessError) => { 5363 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5364 }) 5365} 5366``` 5367 5368### setDistributedTables<sup>10+</sup> 5369 5370setDistributedTables(tables: Array<string>, type: DistributedType, callback: AsyncCallback<void>): void 5371 5372Sets distributed tables. This API uses an asynchronous callback to return the result. 5373 5374**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5375 5376**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5377 5378**Parameters** 5379 5380| Name | Type | Mandatory| Description | 5381| -------- | ------------------------------------- | ---- | ---------------------------- | 5382| tables | Array<string> | Yes | Names of the distributed tables to set.| 5383| type | [DistributedType](#distributedtype10) | Yes | Distributed type of the tables. | 5384| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5385 5386**Error codes** 5387 5388For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5389 5390| **ID**| **Error Message** | 5391|-----------| ------------------------------------------------------------ | 5392| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5393| 801 | Capability not supported. | 5394| 14800000 | Inner error. | 5395| 14800014 | Already closed. | 5396| 14800051 | The type of the distributed table does not match. | 5397 5398**Example** 5399 5400```ts 5401if(store != undefined) { 5402 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, (err) => { 5403 if (err) { 5404 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5405 return; 5406 } 5407 console.info('SetDistributedTables successfully.'); 5408 }) 5409} 5410``` 5411 5412### setDistributedTables<sup>10+</sup> 5413 5414setDistributedTables(tables: Array<string>, type: DistributedType, config: DistributedConfig, callback: AsyncCallback<void>): void 5415 5416Sets distributed tables. This API uses an asynchronous callback to return the result. 5417 5418**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5419 5420**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5421 5422**Parameters** 5423 5424| Name | Type | Mandatory | Description | 5425| -------- | ----------------------------------- | --- | --------------- | 5426| tables | Array<string> | Yes | Names of the distributed tables to set. | 5427| type | [DistributedType](#distributedtype10) | Yes | Distributed type of the tables.| 5428| config | [DistributedConfig](#distributedconfig10) | Yes| Configuration of the distributed mode.| 5429| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 5430 5431**Error codes** 5432 5433For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5434 5435| **ID**| **Error Message** | 5436|-----------| ------------------------------------------------------------ | 5437| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5438| 801 | Capability not supported. | 5439| 14800000 | Inner error. | 5440| 14800014 | Already closed. | 5441| 14800051 | The type of the distributed table does not match. | 5442 5443**Example** 5444 5445```ts 5446if(store != undefined) { 5447 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 5448 autoSync: true 5449 }, (err) => { 5450 if (err) { 5451 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5452 return; 5453 } 5454 console.info('SetDistributedTables successfully.'); 5455 }) 5456} 5457``` 5458 5459### setDistributedTables<sup>10+</sup> 5460 5461 setDistributedTables(tables: Array<string>, type?: DistributedType, config?: DistributedConfig): Promise<void> 5462 5463Sets distributed tables. This API uses a promise to return the result. 5464 5465**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5466 5467**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5468 5469**Parameters** 5470 5471| Name| Type | Mandatory| Description | 5472| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ | 5473| tables | Array<string> | Yes | Names of the distributed tables to set. | 5474| type | [DistributedType](#distributedtype10) | No | Distributed type of the tables. The default value is **relationalStore.DistributedType.DISTRIBUTED_DEVICE**.| 5475| 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.| 5476 5477**Return value** 5478 5479| Type | Description | 5480| ------------------- | ------------------------- | 5481| Promise<void> | Promise that returns no value.| 5482 5483**Error codes** 5484 5485For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5486 5487| **ID**| **Error Message** | 5488|-----------| ------------------------------------------------------------ | 5489| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5490| 801 | Capability not supported. | 5491| 14800000 | Inner error. | 5492| 14800014 | Already closed. | 5493| 14800051 | The type of the distributed table does not match. | 5494 5495**Example** 5496 5497```ts 5498import { BusinessError } from '@kit.BasicServicesKit'; 5499 5500if(store != undefined) { 5501 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 5502 autoSync: true 5503 }).then(() => { 5504 console.info('SetDistributedTables successfully.'); 5505 }).catch((err: BusinessError) => { 5506 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5507 }) 5508} 5509``` 5510 5511### obtainDistributedTableName 5512 5513obtainDistributedTableName(device: string, table: string, callback: AsyncCallback<string>): void 5514 5515Obtains 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. 5516 5517> **NOTE** 5518> 5519> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 5520 5521**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5522 5523**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5524 5525**Parameters** 5526 5527| Name | Type | Mandatory| Description | 5528| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 5529| device | string | Yes | ID of the remote device. | 5530| table | string | Yes | Local table name of the remote device. | 5531| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| 5532 5533**Error codes** 5534 5535For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5536 5537| **ID**| **Error Message** | 5538|-----------| ------------------------------------------------------------ | 5539| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5540| 801 | Capability not supported. | 5541| 14800000 | Inner error. | 5542| 14800014 | Already closed. | 5543 5544**Example** 5545 5546```ts 5547import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5548import { BusinessError } from '@kit.BasicServicesKit'; 5549 5550let dmInstance: distributedDeviceManager.DeviceManager; 5551let deviceId: string | undefined = undefined; 5552 5553try { 5554 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5555 let devices = dmInstance.getAvailableDeviceListSync(); 5556 deviceId = devices[0].networkId; 5557} catch (err) { 5558 let code = (err as BusinessError).code; 5559 let message = (err as BusinessError).message 5560 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5561} 5562 5563if(store != undefined && deviceId != undefined) { 5564 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE", (err, tableName) => { 5565 if (err) { 5566 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 5567 return; 5568 } 5569 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 5570 }) 5571} 5572``` 5573 5574### obtainDistributedTableName 5575 5576 obtainDistributedTableName(device: string, table: string): Promise<string> 5577 5578Obtains 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. 5579 5580> **NOTE** 5581> 5582> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 5583 5584**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5585 5586**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5587 5588**Parameters** 5589 5590| Name| Type | Mandatory| Description | 5591| ------ | ------ | ---- | -------------------- | 5592| device | string | Yes | ID of the remote device. | 5593| table | string | Yes | Local table name of the remote device.| 5594 5595**Return value** 5596 5597| Type | Description | 5598| --------------------- | ----------------------------------------------------- | 5599| Promise<string> | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| 5600 5601**Error codes** 5602 5603For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5604 5605| **ID**| **Error Message** | 5606|-----------| ------------------------------------------------------------ | 5607| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5608| 801 | Capability not supported. | 5609| 14800000 | Inner error. | 5610| 14800014 | Already closed. | 5611 5612**Example** 5613 5614```ts 5615import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5616import { BusinessError } from '@kit.BasicServicesKit'; 5617 5618let dmInstance: distributedDeviceManager.DeviceManager; 5619let deviceId: string | undefined = undefined; 5620 5621try { 5622 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5623 let devices = dmInstance.getAvailableDeviceListSync(); 5624 deviceId = devices[0].networkId; 5625} catch (err) { 5626 let code = (err as BusinessError).code; 5627 let message = (err as BusinessError).message 5628 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5629} 5630 5631if(store != undefined && deviceId != undefined) { 5632 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE").then((tableName: string) => { 5633 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 5634 }).catch((err: BusinessError) => { 5635 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 5636 }) 5637} 5638``` 5639 5640### sync 5641 5642sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void 5643 5644Synchronizes data between devices. This API uses an asynchronous callback to return the result. 5645 5646**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5647 5648**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5649 5650**Parameters** 5651 5652| Name | Type | Mandatory| Description | 5653| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ | 5654| mode | [SyncMode](#syncmode) | Yes | Data sync mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**. | 5655| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | 5656| 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. | 5657 5658**Error codes** 5659 5660For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5661 5662| **ID**| **Error Message** | 5663|-----------| ------------------------------------------------------------ | 5664| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5665| 801 | Capability not supported. | 5666| 14800000 | Inner error. | 5667| 14800014 | Already closed. | 5668 5669**Example** 5670 5671```ts 5672import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5673import { BusinessError } from '@kit.BasicServicesKit'; 5674 5675let dmInstance: distributedDeviceManager.DeviceManager; 5676let deviceIds: Array<string> = []; 5677 5678try { 5679 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5680 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 5681 for (let i = 0; i < devices.length; i++) { 5682 deviceIds[i] = devices[i].networkId!; 5683 } 5684} catch (err) { 5685 let code = (err as BusinessError).code; 5686 let message = (err as BusinessError).message 5687 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5688} 5689 5690let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 5691predicates.inDevices(deviceIds); 5692if(store != undefined) { 5693 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, (err, result) => { 5694 if (err) { 5695 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 5696 return; 5697 } 5698 console.info('Sync done.'); 5699 for (let i = 0; i < result.length; i++) { 5700 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 5701 } 5702 }) 5703} 5704``` 5705 5706### sync 5707 5708 sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>> 5709 5710Synchronizes data between devices. This API uses a promise to return the result. 5711 5712**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5713 5714**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5715 5716**Parameters** 5717 5718| Name | Type | Mandatory| Description | 5719| ---------- | ------------------------------------ | ---- | ------------------------------ | 5720| mode | [SyncMode](#syncmode) | Yes | Data sync mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**.| 5721| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | 5722 5723**Return value** 5724 5725| Type | Description | 5726| -------------------------------------------- | ------------------------------------------------------------ | 5727| 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.| 5728 5729**Error codes** 5730 5731For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5732 5733| **ID**| **Error Message** | 5734|-----------| ------------------------------------------------------------ | 5735| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5736| 801 | Capability not supported. | 5737| 14800000 | Inner error. | 5738| 14800014 | Already closed. | 5739 5740**Example** 5741 5742```ts 5743import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5744import { BusinessError } from '@kit.BasicServicesKit'; 5745 5746let dmInstance: distributedDeviceManager.DeviceManager; 5747let deviceIds: Array<string> = []; 5748 5749try { 5750 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5751 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 5752 for (let i = 0; i < devices.length; i++) { 5753 deviceIds[i] = devices[i].networkId!; 5754 } 5755} catch (err) { 5756 let code = (err as BusinessError).code; 5757 let message = (err as BusinessError).message 5758 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5759} 5760 5761let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 5762predicates.inDevices(deviceIds); 5763if(store != undefined) { 5764 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates).then((result: Object[][]) => { 5765 console.info('Sync done.'); 5766 for (let i = 0; i < result.length; i++) { 5767 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 5768 } 5769 }).catch((err: BusinessError) => { 5770 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 5771 }) 5772} 5773``` 5774 5775### cloudSync<sup>10+</sup> 5776 5777cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 5778 5779Manually 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. 5780 5781**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 5782 5783**Parameters** 5784 5785| Name | Type | Mandatory| Description | 5786| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 5787| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 5788| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details. | 5789| callback | AsyncCallback<void> | Yes | Callback used to send the sync result to the caller.| 5790 5791**Error codes** 5792 5793For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5794 5795| **ID**| **Error Message** | 5796|-----------|-------| 5797| 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. | 5798| 801 | Capability not supported. | 5799| 14800014 | Already closed. | 5800 5801**Example** 5802 5803```ts 5804if(store != undefined) { 5805 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetails) => { 5806 console.info(`Progess: ${progressDetails}`); 5807 }, (err) => { 5808 if (err) { 5809 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 5810 return; 5811 } 5812 console.info('Cloud sync succeeded'); 5813 }); 5814} 5815``` 5816 5817### cloudSync<sup>10+</sup> 5818 5819cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>): Promise<void> 5820 5821Manually 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. 5822 5823**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 5824 5825**Parameters** 5826 5827| Name | Type | Mandatory| Description | 5828| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 5829| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 5830| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details.| 5831 5832**Return value** 5833 5834| Type | Description | 5835| ------------------- | --------------------------------------- | 5836| Promise<void> | Promise used to send the sync result.| 5837 5838**Error codes** 5839 5840For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5841 5842| **ID**| **Error Message** | 5843|-----------|------------------| 5844| 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. | 5845| 801 | Capability not supported. | 5846| 14800014 | Already closed. | 5847 5848**Example** 5849 5850```ts 5851import { BusinessError } from '@kit.BasicServicesKit'; 5852 5853if(store != undefined) { 5854 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetail: relationalStore.ProgressDetails) => { 5855 console.info(`progress: ${progressDetail}`); 5856 }).then(() => { 5857 console.info('Cloud sync succeeded'); 5858 }).catch((err: BusinessError) => { 5859 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 5860 }); 5861} 5862``` 5863 5864### cloudSync<sup>10+</sup> 5865 5866cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 5867 5868Manually 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. 5869 5870**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 5871 5872**Parameters** 5873 5874| Name | Type | Mandatory| Description | 5875| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 5876| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 5877| tables | string[] | Yes | Name of the table to synchronize. | 5878| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details. | 5879| callback | AsyncCallback<void> | Yes | Callback used to send the sync result to the caller.| 5880 5881**Error codes** 5882 5883For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5884 5885| **ID**| **Error Message** | 5886|-----------|-------| 5887| 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.| 5888| 801 | Capability not supported. | 5889| 14800014 | Already closed. | 5890 5891**Example** 5892 5893```ts 5894const tables = ["table1", "table2"]; 5895 5896if(store != undefined) { 5897 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => { 5898 console.info(`Progess: ${progressDetail}`); 5899 }, (err) => { 5900 if (err) { 5901 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 5902 return; 5903 } 5904 console.info('Cloud sync succeeded'); 5905 }); 5906}; 5907``` 5908 5909### cloudSync<sup>10+</sup> 5910 5911cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>): Promise<void> 5912 5913Manually 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. 5914 5915**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 5916 5917**Parameters** 5918 5919| Name | Type | Mandatory| Description | 5920| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 5921| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 5922| tables | string[] | Yes | Name of the table to synchronize. | 5923| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details.| 5924 5925**Return value** 5926 5927| Type | Description | 5928| ------------------- | --------------------------------------- | 5929| Promise<void> | Promise used to send the sync result.| 5930 5931**Error codes** 5932 5933For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5934 5935| **ID**| **Error Message** | 5936|-----------|---------------| 5937| 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 | 5938| 801 | Capability not supported. | 5939| 14800014 | Already closed. | 5940 5941**Example** 5942 5943```ts 5944import { BusinessError } from '@kit.BasicServicesKit'; 5945 5946const tables = ["table1", "table2"]; 5947 5948if(store != undefined) { 5949 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => { 5950 console.info(`progress: ${progressDetail}`); 5951 }).then(() => { 5952 console.info('Cloud sync succeeded'); 5953 }).catch((err: BusinessError) => { 5954 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 5955 }); 5956}; 5957``` 5958 5959### on('dataChange') 5960 5961on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 5962 5963Subscribes to data changes of specified devices. When the data of the specified devices changes, a callback is invoked to return the data change. 5964 5965**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5966 5967**Parameters** 5968 5969| Name | Type | Mandatory| Description | 5970| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 5971| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 5972| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe. | 5973| 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. | 5974 5975**Error codes** 5976 5977For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5978 5979| **ID**| **Error Message** | 5980|-----------|-------------| 5981| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5982| 801 | Capability not supported. | 5983| 14800014 | Already closed. | 5984 5985**Example** 5986 5987```ts 5988import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5989import { BusinessError } from '@kit.BasicServicesKit'; 5990 5991let storeObserver = (devices: Array<string>) => { 5992 if (devices != undefined) { 5993 for (let i = 0; i < devices.length; i++) { 5994 console.info(`device= ${devices[i]} data changed`); 5995 } 5996 } 5997} 5998 5999try { 6000 if (store != undefined) { 6001 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) 6002 } 6003} catch (err) { 6004 let code = (err as BusinessError).code; 6005 let message = (err as BusinessError).message 6006 console.error(`Register observer failed, code is ${code},message is ${message}`); 6007} 6008``` 6009 6010### on('dataChange')<sup>10+</sup> 6011 6012on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 6013 6014Subscribes to data changes of specified devices. A callback is called when data in a distributed or local RDB store changes. 6015 6016**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6017 6018**Parameters** 6019 6020| Name | Type | Mandatory| Description | 6021| -------- | ----------------------------------- | ---- | ------------------------------------------- | 6022| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6023| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe.| 6024| 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.| 6025 6026**Error codes** 6027 6028For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6029 6030| **ID**| **Error Message** | 6031|-----------|-------------| 6032| 202 | Permission verification failed, application which is not a system application uses system API. | 6033| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6034| 801 | Capability not supported. | 6035| 14800014 | Already closed. | 6036 6037Example 1: **type** is **SUBSCRIBE_TYPE_REMOTE**. 6038 6039```ts 6040import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6041import { BusinessError } from '@kit.BasicServicesKit'; 6042 6043let storeObserver = (devices: Array<string>) => { 6044 if (devices != undefined) { 6045 for (let i = 0; i < devices.length; i++) { 6046 console.info(`device= ${devices[i]} data changed`); 6047 } 6048 } 6049} 6050 6051try { 6052 if(store != undefined) { 6053 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6054 } 6055} catch (err) { 6056 let code = (err as BusinessError).code; 6057 let message = (err as BusinessError).message; 6058 console.error(`Register observer failed, code is ${code},message is ${message}`); 6059} 6060``` 6061 6062Example 2: **type** is **SUBSCRIBE_TYPE_LOCAL_DETAILS**. 6063 6064```ts 6065import { BusinessError } from '@kit.BasicServicesKit'; 6066 6067let changeInfos = (changeInfos: Array<relationalStore.ChangeInfo>) => { 6068 for (let i = 0; i < changeInfos.length; i++) { 6069 console.info(`changeInfos = ${changeInfos[i]}`); 6070 } 6071} 6072 6073try { 6074 if(store != undefined) { 6075 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_LOCAL_DETAILS, changeInfos); 6076 } 6077} catch (err) { 6078 let code = (err as BusinessError).code; 6079 let message = (err as BusinessError).message; 6080 console.error(`on dataChange fail, code is ${code},message is ${message}`); 6081} 6082 6083let value1 = "Lisa"; 6084let value2 = 18; 6085let value3 = 100.5; 6086let value4 = new Uint8Array([1, 2, 3]); 6087 6088try { 6089 const valueBucket: relationalStore.ValuesBucket = { 6090 'name': value1, 6091 'age': value2, 6092 'salary': value3, 6093 'blobType': value4, 6094 }; 6095 6096 if(store != undefined) { 6097 (store as relationalStore.RdbStore).insert('test', valueBucket); 6098 } 6099} catch (err) { 6100 let code = (err as BusinessError).code; 6101 let message = (err as BusinessError).message; 6102 console.error(`insert fail, code is ${code},message is ${message}`); 6103} 6104``` 6105 6106### on<sup>10+</sup> 6107 6108on(event: string, interProcess: boolean, observer: Callback\<void>): void 6109 6110Subscribes to process events. This callback is invoked by [emit](#emit10). 6111 6112**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6113 6114**Parameters** 6115 6116| Name | Type | Mandatory| Description | 6117| ------------ | --------------- | ---- | ------------------------------------------------------------ | 6118| event | string | Yes | Event name to observe. | 6119| 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.| 6120| observer | Callback\<void> | Yes | Callback used to return the result. | 6121 6122**Error codes** 6123 6124For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6125 6126| **ID**| **Error Message** | 6127|-----------|-------------| 6128| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6129| 801 | Capability not supported. | 6130| 14800000 | Inner error. | 6131| 14800014 | Already closed. | 6132| 14800050 | Failed to obtain subscription service. | 6133 6134**Example** 6135 6136```ts 6137import { BusinessError } from '@kit.BasicServicesKit'; 6138 6139let storeObserver = () => { 6140 console.info(`storeObserver`); 6141} 6142 6143try { 6144 if(store != undefined) { 6145 (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver); 6146 } 6147} catch (err) { 6148 let code = (err as BusinessError).code; 6149 let message = (err as BusinessError).message 6150 console.error(`Register observer failed, code is ${code},message is ${message}`); 6151} 6152``` 6153 6154### on('autoSyncProgress')<sup>11+</sup> 6155 6156on(event: 'autoSyncProgress', progress: Callback<ProgressDetails>): void 6157 6158Subscribes 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. 6159 6160**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6161 6162**Parameters** 6163 6164| Name | Type | Mandatory| Description | 6165| ------------ |---------------------------------| ---- |-----------------------------------| 6166| event | string | Yes | Event type. The value is **'autoSyncProgress'**, which indicates the auto sync progress.| 6167| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to return the auto sync progress. | 6168 6169**Error codes** 6170 6171For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6172 6173| **ID**| **Error Message** | 6174|-----------|--------| 6175| 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. | 6176| 801 | Capability not supported. | 6177| 14800014 | Already closed. | 6178 6179**Example** 6180 6181```ts 6182import { BusinessError } from '@kit.BasicServicesKit'; 6183 6184let progressDetail = (progressDetail: relationalStore.ProgressDetails) => { 6185 console.info(`progress: ${progressDetail}`); 6186} 6187 6188try { 6189 if(store != undefined) { 6190 (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail) 6191 } 6192} catch (err) { 6193 let code = (err as BusinessError).code; 6194 let message = (err as BusinessError).message 6195 console.error(`Register observer failed, code is ${code},message is ${message}`); 6196} 6197``` 6198 6199### on('statistics')<sup>12+</sup> 6200 6201on(event: 'statistics', observer: Callback<SqlExecutionInfo>): void 6202 6203Subscribes to SQL statistics. 6204 6205**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6206 6207**Parameters** 6208 6209| Name | Type | Mandatory| Description | 6210| ------------ |---------------------------------| ---- |-----------------------------------| 6211| event | string | Yes | Event type. The value is **statistics**, which indicates the statistics of the SQL execution time.| 6212| observer | Callback<[SqlExecutionInfo](#sqlexecutioninfo12)> | Yes | Callback used to return the statistics about the SQL execution time in the database. | 6213 6214**Error codes** 6215 6216For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6217 6218| **ID**| **Error Message** | 6219|-----------|--------| 6220| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 6221| 801 | Capability not supported. | 6222| 14800000 | Inner error. | 6223| 14800014 | Already closed. | 6224 6225**Example** 6226 6227```ts 6228import { BusinessError } from '@kit.BasicServicesKit'; 6229 6230let sqlExecutionInfo = (sqlExecutionInfo: relationalStore.SqlExecutionInfo) => { 6231 console.info(`sql: ${sqlExecutionInfo.sql[0]}`); 6232 console.info(`totalTime: ${sqlExecutionInfo.totalTime}`); 6233 console.info(`waitTime: ${sqlExecutionInfo.waitTime}`); 6234 console.info(`prepareTime: ${sqlExecutionInfo.prepareTime}`); 6235 console.info(`executeTime: ${sqlExecutionInfo.executeTime}`); 6236} 6237 6238try { 6239 if(store != undefined) { 6240 (store as relationalStore.RdbStore).on('statistics', sqlExecutionInfo); 6241 } 6242} catch (err) { 6243 let code = (err as BusinessError).code; 6244 let message = (err as BusinessError).message; 6245 console.error(`Register observer failed, code is ${code},message is ${message}`); 6246} 6247 6248try { 6249 let value1 = "Lisa"; 6250 let value2 = 18; 6251 let value3 = 100.5; 6252 let value4 = new Uint8Array([1, 2, 3, 4, 5]); 6253 6254 const valueBucket: relationalStore.ValuesBucket = { 6255 'NAME': value1, 6256 'AGE': value2, 6257 'SALARY': value3, 6258 'CODES': value4, 6259 }; 6260 if(store != undefined) { 6261 (store as relationalStore.RdbStore).insert('test', valueBucket); 6262 } 6263} catch (err) { 6264 console.error(`insert fail, code:${err.code}, message: ${err.message}`); 6265} 6266``` 6267 6268### off('dataChange') 6269 6270off(event:'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 6271 6272Unsubscribes from data changes of the specified devices. 6273 6274**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6275 6276**Parameters** 6277 6278| Name | Type | Mandatory| Description | 6279| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6280| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6281| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe. | 6282| observer | Callback<Array<string>> | Yes | Callback to unregister. Array<string> holds the IDs of the peer devices whose data is changed.| 6283 6284**Error codes** 6285 6286For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6287 6288| **ID**| **Error Message** | 6289|-----------|-------------| 6290| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6291| 801 | Capability not supported. | 6292| 14800014 | Already closed. | 6293 6294**Example** 6295 6296```ts 6297import { BusinessError } from '@kit.BasicServicesKit'; 6298 6299let storeObserver = (devices: Array<string>) => { 6300 if (devices != undefined) { 6301 for (let i = 0; i < devices.length; i++) { 6302 console.info(`device= ${devices[i]} data changed`); 6303 } 6304 } 6305} 6306 6307try { 6308 if (store != undefined) { 6309 // The Lambda expression cannot be used here. 6310 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) 6311 } 6312} catch (err) { 6313 let code = (err as BusinessError).code; 6314 let message = (err as BusinessError).message 6315 console.error(`Register observer failed, code is ${code},message is ${message}`); 6316} 6317 6318try { 6319 if(store != undefined) { 6320 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6321 } 6322} catch (err) { 6323 let code = (err as BusinessError).code; 6324 let message = (err as BusinessError).message 6325 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6326} 6327``` 6328 6329### off('dataChange')<sup>10+</sup> 6330 6331off(event:'dataChange', type: SubscribeType, observer?: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 6332 6333Unsubscribes from data changes of this RDB store. 6334 6335**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6336 6337**Parameters** 6338 6339| Name | Type | Mandatory| Description | 6340| -------- | ---------------------------------- | ---- | ------------------------------------------ | 6341| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6342| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe. | 6343| 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**.| 6344 6345**Error codes** 6346 6347For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6348 6349| **ID**| **Error Message** | 6350|-----------|-------------| 6351| 202 | Permission verification failed, application which is not a system application uses system API. | 6352| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6353| 801 | Capability not supported. | 6354| 14800014 | Already closed. | 6355 6356**Example** 6357 6358```ts 6359import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6360import { BusinessError } from '@kit.BasicServicesKit'; 6361 6362let storeObserver = (devices: Array<string>) => { 6363 if (devices != undefined) { 6364 for (let i = 0; i < devices.length; i++) { 6365 console.info(`device= ${devices[i]} data changed`); 6366 } 6367 } 6368} 6369 6370try { 6371 if(store != undefined) { 6372 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6373 } 6374} catch (err) { 6375 let code = (err as BusinessError).code; 6376 let message = (err as BusinessError).message; 6377 console.error(`Register observer failed, code is ${code},message is ${message}`); 6378} 6379 6380try { 6381 if(store != undefined) { 6382 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6383 } 6384} catch (err) { 6385 let code = (err as BusinessError).code; 6386 let message = (err as BusinessError).message 6387 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6388} 6389``` 6390 6391### off<sup>10+</sup> 6392 6393off(event: string, interProcess: boolean, observer?: Callback\<void>): void 6394 6395Unsubscribes from process events. 6396 6397**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6398 6399**Parameters** 6400 6401| Name | Type | Mandatory| Description | 6402| ------------ | --------------- | ---- | ------------------------------------------------------------ | 6403| event | string | Yes | Name of the event. | 6404| 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.| 6405| observer | Callback\<void> | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 6406 6407**Error codes** 6408 6409For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6410 6411| **ID**| **Error Message** | 6412| ------------ | -------------------------------------- | 6413| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6414| 801 | Capability not supported. | 6415| 14800000 | Inner error. | 6416| 14800014 | Already closed. | 6417| 14800050 | Failed to obtain subscription service. | 6418 6419**Example** 6420 6421```ts 6422import { BusinessError } from '@kit.BasicServicesKit'; 6423 6424let storeObserver = () => { 6425 console.info(`storeObserver`); 6426} 6427 6428try { 6429 if(store != undefined) { 6430 (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver); 6431 } 6432} catch (err) { 6433 let code = (err as BusinessError).code; 6434 let message = (err as BusinessError).message 6435 console.error(`Register observer failed, code is ${code},message is ${message}`); 6436} 6437 6438try { 6439 if(store != undefined) { 6440 (store as relationalStore.RdbStore).off('storeObserver', false, storeObserver); 6441 } 6442} catch (err) { 6443 let code = (err as BusinessError).code; 6444 let message = (err as BusinessError).message 6445 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6446} 6447``` 6448 6449### off('autoSyncProgress')<sup>11+</sup> 6450 6451off(event: 'autoSyncProgress', progress?: Callback<ProgressDetails>): void 6452 6453Unsubscribes from the auto sync progress. 6454 6455**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6456 6457**Parameters** 6458 6459| Name | Type | Mandatory| Description | 6460| ------------ |---------------------------------| ---- |------------------------------------------------------------------| 6461| event | string | Yes | Event type. The value is **'autoSyncProgress'**, which indicates the auto sync progress. | 6462| 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.| 6463 6464**Error codes** 6465 6466For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6467 6468| **ID**| **Error Message** | 6469| ------------ |--------------------| 6470| 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. | 6471| 801 | Capability not supported. | 6472| 14800014 | Already closed. | 6473 6474**Example** 6475 6476```ts 6477import { BusinessError } from '@kit.BasicServicesKit'; 6478 6479let progressDetail = (progressDetail: relationalStore.ProgressDetails) => { 6480 console.info(`progress: ${progressDetail}`); 6481} 6482 6483try { 6484 if(store != undefined) { 6485 (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail) 6486 } 6487} catch (err) { 6488 let code = (err as BusinessError).code; 6489 let message = (err as BusinessError).message 6490 console.error(`Register observer failed, code is ${code},message is ${message}`); 6491} 6492 6493try { 6494 if(store != undefined) { 6495 (store as relationalStore.RdbStore).off('autoSyncProgress', progressDetail); 6496 } 6497} catch (err) { 6498 let code = (err as BusinessError).code; 6499 let message = (err as BusinessError).message; 6500 console.error(`Unregister failed, code is ${code},message is ${message}`); 6501} 6502``` 6503 6504### off('statistics')<sup>12+</sup> 6505 6506off(event: 'statistics', observer?: Callback<SqlExecutionInfo>): void 6507 6508Unsubscribes from SQL statistics. 6509 6510**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6511 6512**Parameters** 6513 6514| Name | Type | Mandatory| Description | 6515| ------------ |---------------------------------| ---- |-----------------------------------| 6516| event | string | Yes | Event type. The value is **'statistics'**, which indicates the statistics of the SQL execution time.| 6517| observer | Callback<[SqlExecutionInfo](#sqlexecutioninfo12)> | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 6518 6519 6520**Error codes** 6521 6522For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6523 6524| **ID**| **Error Message** | 6525|-----------|--------| 6526| 401 | Parameter error. | 6527| 801 | Capability not supported. | 6528| 14800000 | Inner error. | 6529| 14800014 | Already closed. | 6530 6531```ts 6532import { BusinessError } from '@kit.BasicServicesKit'; 6533 6534try { 6535 if(store != undefined) { 6536 (store as relationalStore.RdbStore).off('statistics'); 6537 } 6538} catch (err) { 6539 let code = (err as BusinessError).code; 6540 let message = (err as BusinessError).message; 6541 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6542} 6543``` 6544 6545### emit<sup>10+</sup> 6546 6547emit(event: string): void 6548 6549Triggers the inter-process or intra-process event listener registered in [on](#on10). 6550 6551**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6552 6553**Parameters** 6554 6555| Name| Type | Mandatory| Description | 6556| ------ | ------ | ---- | -------------------- | 6557| event | string | Yes | Name of the event.| 6558 6559**Error codes** 6560 6561For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6562 6563| **ID**| **Error Message** | 6564| --------- |---------------------------------------------------------------------------------------------------------------| 6565| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6566| 801 | Capability not supported. | 6567| 14800000 | Inner error. | 6568| 14800014 | Already closed. | 6569| 14800050 | Failed to obtain subscription service. | 6570 6571 6572**Example** 6573 6574```ts 6575if(store != undefined) { 6576 (store as relationalStore.RdbStore).emit('storeObserver'); 6577} 6578``` 6579 6580### cleanDirtyData<sup>11+</sup> 6581 6582cleanDirtyData(table: string, cursor: number, callback: AsyncCallback<void>): void 6583 6584Clears 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. 6585 6586**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6587 6588**Parameters** 6589 6590| Name | Type | Mandatory| Description | 6591| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6592| table | string | Yes | Name of the table in the RDB store. | 6593| 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. | 6594| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 6595 6596**Error codes** 6597 6598For 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). 6599 6600| **ID**| **Error Message** | 6601|-----------|---------------| 6602| 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. | 6603| 801 | Capability not supported. | 6604| 14800000 | Inner error. | 6605| 14800011 | Database corrupted. | 6606| 14800014 | Already closed. | 6607| 14800015 | The database does not respond. | 6608| 14800021 | SQLite: Generic error. | 6609| 14800022 | SQLite: Callback routine requested an abort. | 6610| 14800023 | SQLite: Access permission denied. | 6611| 14800024 | SQLite: The database file is locked. | 6612| 14800025 | SQLite: A table in the database is locked. | 6613| 14800026 | SQLite: The database is out of memory. | 6614| 14800027 | SQLite: Attempt to write a readonly database. | 6615| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6616| 14800029 | SQLite: The database is full. | 6617| 14800030 | SQLite: Unable to open the database file. | 6618| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6619| 14800032 | SQLite: Abort due to constraint violation. | 6620| 14800033 | SQLite: Data type mismatch. | 6621| 14800034 | SQLite: Library used incorrectly. | 6622 6623**Example** 6624 6625```ts 6626if(store != undefined) { 6627 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100, (err) => { 6628 if (err) { 6629 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 6630 return; 6631 } 6632 console.info('clean dirty data succeeded'); 6633 }) 6634} 6635``` 6636 6637### cleanDirtyData<sup>11+</sup> 6638 6639cleanDirtyData(table: string, callback: AsyncCallback<void>): void 6640 6641Clears all dirty data from the local device. The dirty data is the data that has been deleted from the cloud. 6642 6643**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6644 6645**Parameters** 6646 6647| Name | Type | Mandatory| Description | 6648| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6649| table | string | Yes | Name of the table in the RDB store.| 6650| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 6651 6652**Error codes** 6653 6654For 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). 6655 6656| **ID**| **Error Message** | 6657|-----------|---------| 6658| 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. | 6659| 801 | Capability not supported. | 6660| 14800000 | Inner error. | 6661| 14800011 | Database corrupted. | 6662| 14800014 | Already closed. | 6663| 14800015 | The database does not respond. | 6664| 14800021 | SQLite: Generic error. | 6665| 14800022 | SQLite: Callback routine requested an abort. | 6666| 14800023 | SQLite: Access permission denied. | 6667| 14800024 | SQLite: The database file is locked. | 6668| 14800025 | SQLite: A table in the database is locked. | 6669| 14800026 | SQLite: The database is out of memory. | 6670| 14800027 | SQLite: Attempt to write a readonly database. | 6671| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6672| 14800029 | SQLite: The database is full. | 6673| 14800030 | SQLite: Unable to open the database file. | 6674| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6675| 14800032 | SQLite: Abort due to constraint violation. | 6676| 14800033 | SQLite: Data type mismatch. | 6677| 14800034 | SQLite: Library used incorrectly. | 6678 6679**Example** 6680 6681```ts 6682if(store != undefined) { 6683 (store as relationalStore.RdbStore).cleanDirtyData('test_table', (err) => { 6684 if (err) { 6685 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 6686 return; 6687 } 6688 console.info('clean dirty data succeeded'); 6689 }) 6690} 6691``` 6692 6693### cleanDirtyData<sup>11+</sup> 6694 6695cleanDirtyData(table: string, cursor?: number): Promise<void> 6696 6697Clears 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. 6698 6699**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6700 6701**Parameters** 6702 6703| Name | Type | Mandatory| Description | 6704| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6705| table | string | Yes | Name of the table in the RDB store. | 6706| 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.| 6707 6708**Return value** 6709| Name | Description | 6710| -------- | ------------------------------------------------- | 6711| Promise\<void> | Promise that returns no value. | 6712 6713**Error codes** 6714 6715For 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). 6716 6717| **ID**| **Error Message** | 6718|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 6719| 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. | 6720| 801 | Capability not supported. | 6721| 14800000 | Inner error. | 6722| 14800011 | Database corrupted. | 6723| 14800014 | Already closed. | 6724| 14800015 | The database does not respond. | 6725| 14800021 | SQLite: Generic error. | 6726| 14800022 | SQLite: Callback routine requested an abort. | 6727| 14800023 | SQLite: Access permission denied. | 6728| 14800024 | SQLite: The database file is locked. | 6729| 14800025 | SQLite: A table in the database is locked. | 6730| 14800026 | SQLite: The database is out of memory. | 6731| 14800027 | SQLite: Attempt to write a readonly database. | 6732| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6733| 14800029 | SQLite: The database is full. | 6734| 14800030 | SQLite: Unable to open the database file. | 6735| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6736| 14800032 | SQLite: Abort due to constraint violation. | 6737| 14800033 | SQLite: Data type mismatch. | 6738| 14800034 | SQLite: Library used incorrectly. | 6739 6740**Example** 6741 6742```ts 6743import { BusinessError } from '@kit.BasicServicesKit'; 6744 6745if(store != undefined) { 6746 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100).then(() => { 6747 console.info('clean dirty data succeeded'); 6748 }).catch ((err: BusinessError) => { 6749 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 6750 }) 6751} 6752``` 6753 6754### attach<sup>12+</sup> 6755 6756attach(fullPath: string, attachName: string, waitTime?: number) : Promise<number> 6757 6758Attaches an RDB store to this RDB store so that the data in the attached RDB store can be directly accessed using the SQL statement. 6759 6760The 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. 6761 6762Before 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. 6763 6764The **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. 6765 6766**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6767 6768**Parameters** 6769 6770| Name | Type | Mandatory | Description | 6771| ----------- | ------ | --- | ------------ | 6772| fullPath | string | Yes | Path of the database file to attach.| 6773| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 6774| waitTime | number | No | Maximum time period (in seconds) allowed for attaching the database file. <br>Value range: 1 to 300<br>Default value: 2| 6775 6776**Return value** 6777 6778| Type | Description | 6779| ---------------- | ---------------------------- | 6780| Promise<number> | Promise used to return the number of attached RDB stores.| 6781 6782**Error codes** 6783 6784For 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). 6785 6786| **ID**| **Error Message** | 6787|-----------| ------------------------------------------------------------ | 6788| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6789| 801 | Capability not supported. | 6790| 14800000 | Inner error. | 6791| 14800010 | Invalid database path. | 6792| 14800011 | Database corrupted. | 6793| 14800014 | Already closed. | 6794| 14800015 | The database does not respond. | 6795| 14800016 | The database is already attached. | 6796| 14800021 | SQLite: Generic error. | 6797| 14800022 | SQLite: Callback routine requested an abort. | 6798| 14800023 | SQLite: Access permission denied. | 6799| 14800024 | SQLite: The database file is locked. | 6800| 14800025 | SQLite: A table in the database is locked. | 6801| 14800026 | SQLite: The database is out of memory. | 6802| 14800027 | SQLite: Attempt to write a readonly database. | 6803| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6804| 14800029 | SQLite: The database is full. | 6805| 14800030 | SQLite: Unable to open the database file. | 6806| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6807| 14800032 | SQLite: Abort due to constraint violation. | 6808| 14800033 | SQLite: Data type mismatch. | 6809| 14800034 | SQLite: Library used incorrectly. | 6810 6811**Example** 6812 6813```ts 6814// Attach a non-encrypted RDB store to a non-encrypted RDB store. 6815import { BusinessError } from '@kit.BasicServicesKit'; 6816 6817if(store != undefined) { 6818 (store as relationalStore.RdbStore).attach("/path/rdbstore1.db", "attachDB").then((number: number) => { 6819 console.info('attach succeeded'); 6820 }).catch ((err: BusinessError) => { 6821 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 6822 }) 6823} 6824``` 6825 6826### attach<sup>12+</sup> 6827 6828attach(context: Context, config: StoreConfig, attachName: string, waitTime?: number) : Promise<number> 6829 6830Attaches an RDB store to this RDB store so that the data in the attached RDB store can be directly accessed using the SQL statement. 6831 6832This 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 the non-WAL mode, which may affect the performance. 6833 6834Before 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. 6835 6836The **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. 6837 6838**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6839 6840**Parameters** 6841 6842| Name | Type | Mandatory | Description | 6843| ----------- | ------ | --- | ------------ | 6844| 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).| 6845| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store to attach. | 6846| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 6847| waitTime | number | No | Maximum time period (in seconds) allowed for attaching the database file. <br>Value range: 1 to 300<br>Default value: 2| 6848 6849**Return value** 6850 6851| Type | Description | 6852| ---------------- | ---------------------------- | 6853| Promise<number> | Promise used to return the number of attached RDB stores.| 6854 6855**Error codes** 6856 6857For 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). 6858 6859| **ID**| **Error Message** | 6860|-----------| ------------------------------------------------------------ | 6861| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6862| 801 | Capability not supported. | 6863| 14800000 | Inner error. | 6864| 14800010 | Invalid database path. | 6865| 14800011 | Database corrupted. | 6866| 14800014 | Already closed. | 6867| 14800015 | The database does not respond. | 6868| 14800016 | The database is already attached. | 6869| 14801001 | Only supported in stage mode. | 6870| 14801002 | The data group id is not valid. | 6871| 14800021 | SQLite: Generic error. | 6872| 14800022 | SQLite: Callback routine requested an abort. | 6873| 14800023 | SQLite: Access permission denied. | 6874| 14800024 | SQLite: The database file is locked. | 6875| 14800025 | SQLite: A table in the database is locked. | 6876| 14800026 | SQLite: The database is out of memory. | 6877| 14800027 | SQLite: Attempt to write a readonly database. | 6878| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6879| 14800029 | SQLite: The database is full. | 6880| 14800030 | SQLite: Unable to open the database file. | 6881| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6882| 14800032 | SQLite: Abort due to constraint violation. | 6883| 14800033 | SQLite: Data type mismatch. | 6884| 14800034 | SQLite: Library used incorrectly. | 6885 6886Example 1: Attach a non-encrypted RDB store to a non-encrypted RDB store. 6887 6888```ts 6889import { BusinessError } from '@kit.BasicServicesKit'; 6890 6891let attachStore: relationalStore.RdbStore | undefined = undefined; 6892 6893const STORE_CONFIG1: relationalStore.StoreConfig = { 6894 name: "rdbstore1.db", 6895 securityLevel: relationalStore.SecurityLevel.S3, 6896} 6897 6898relationalStore.getRdbStore(this.context, STORE_CONFIG1).then(async (rdbStore: relationalStore.RdbStore) => { 6899 attachStore = rdbStore; 6900 console.info('Get RdbStore successfully.') 6901}).catch((err: BusinessError) => { 6902 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 6903}) 6904 6905if(store != undefined) { 6906 (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG1, "attachDB").then((number: number) => { 6907 console.info(`attach succeeded, number is ${number}`); 6908 }).catch ((err: BusinessError) => { 6909 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 6910 }) 6911} 6912``` 6913 6914Example 2: Attach an encrypted RDB store to a non-encrypted RDB store. 6915 6916```ts 6917import { BusinessError } from '@kit.BasicServicesKit'; 6918 6919let attachStore: relationalStore.RdbStore | undefined = undefined; 6920 6921 6922const STORE_CONFIG2: relationalStore.StoreConfig = { 6923 name: "rdbstore2.db", 6924 encrypt: true, 6925 securityLevel: relationalStore.SecurityLevel.S3, 6926} 6927 6928relationalStore.getRdbStore(this.context, STORE_CONFIG2).then(async (rdbStore: relationalStore.RdbStore) => { 6929 attachStore = rdbStore; 6930 console.info('Get RdbStore successfully.') 6931}).catch((err: BusinessError) => { 6932 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 6933}) 6934 6935if(store != undefined) { 6936 (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG2, "attachDB2", 10).then((number: number) => { 6937 console.info(`attach succeeded, number is ${number}`); 6938 }).catch ((err: BusinessError) => { 6939 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 6940 }) 6941} 6942``` 6943 6944### detach<sup>12+</sup> 6945 6946detach(attachName: string, waitTime?: number) : Promise<number> 6947 6948Detaches an RDB store from this RDB store. 6949 6950After all attached RDB stores are detached, the RDB is switched to the WAL mode. 6951 6952Before 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. 6953 6954**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6955 6956**Parameters** 6957 6958| Name | Type | Mandatory | Description | 6959| ----------- | ------ | --- | ------------ | 6960| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 6961| waitTime | number | No | Maximum time period (in seconds) allowed for detaching the RDB store. <br>Value range: 1 to 300<br>Default value: 2| 6962 6963**Return value** 6964 6965| Type | Description | 6966| ---------------- | ---------------------------- | 6967| Promise<number> | Promise used to return the number of remaining attached RDB stores.| 6968 6969**Error codes** 6970 6971For 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). 6972 6973| **ID**| **Error Message** | 6974|-----------|------------------------| 6975| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6976| 14800000 | Inner error. | 6977| 14800011 | Database corrupted. | 6978| 14800014 | Already closed. | 6979| 14800015 | The database does not respond. | 6980| 14800021 | SQLite: Generic error. | 6981| 14800022 | SQLite: Callback routine requested an abort. | 6982| 14800023 | SQLite: Access permission denied. | 6983| 14800024 | SQLite: The database file is locked. | 6984| 14800025 | SQLite: A table in the database is locked. | 6985| 14800026 | SQLite: The database is out of memory. | 6986| 14800027 | SQLite: Attempt to write a readonly database. | 6987| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6988| 14800029 | SQLite: The database is full. | 6989| 14800030 | SQLite: Unable to open the database file. | 6990| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6991| 14800032 | SQLite: Abort due to constraint violation. | 6992| 14800033 | SQLite: Data type mismatch. | 6993| 14800034 | SQLite: Library used incorrectly. | 6994 6995**Example** 6996 6997```ts 6998import { BusinessError } from '@kit.BasicServicesKit'; 6999 7000if(store != undefined) { 7001 (store as relationalStore.RdbStore).detach("attachDB").then((number: number) => { 7002 console.info(`detach succeeded, number is ${number}`); 7003 }).catch ((err: BusinessError) => { 7004 console.error(`detach failed, code is ${err.code},message is ${err.message}`); 7005 }) 7006} 7007``` 7008 7009### lockRow<sup>12+</sup> 7010 7011lockRow(predicates: RdbPredicates):Promise<void> 7012 7013Locks data in this RDB store. This API uses a promise to return the result. The locked data is blocked from device-cloud sync. 7014 7015This 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. 7016This 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. 7017This API cannot be used for deleted data. 7018 7019**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7020 7021**Parameters** 7022 7023| Name | Type | Mandatory| Description | 7024| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 7025| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions for locking data.| 7026 7027**Return value** 7028 7029| Type | Description | 7030| --------------------- | ------------------------------- | 7031| Promise<void> | Promise that returns no value. | 7032 7033**Error codes** 7034 7035For 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). 7036 7037| **ID**| **Error Message** | 7038|-----------|----------------------------------------------------------------------------------------------| 7039| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7040| 14800000 | Inner error. | 7041| 14800011 | Database corrupted. | 7042| 14800014 | Already closed. | 7043| 14800015 | The database does not respond. | 7044| 14800018 | No data meets the condition. | 7045| 14800021 | SQLite: Generic error. | 7046| 14800022 | SQLite: Callback routine requested an abort. | 7047| 14800023 | SQLite: Access permission denied. | 7048| 14800024 | SQLite: The database file is locked. | 7049| 14800025 | SQLite: A table in the database is locked. | 7050| 14800026 | SQLite: The database is out of memory. | 7051| 14800027 | SQLite: Attempt to write a readonly database. | 7052| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7053| 14800029 | SQLite: The database is full. | 7054| 14800030 | SQLite: Unable to open the database file. | 7055| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7056| 14800032 | SQLite: Abort due to constraint violation. | 7057| 14800033 | SQLite: Data type mismatch. | 7058| 14800034 | SQLite: Library used incorrectly. | 7059 7060**Example** 7061 7062```ts 7063import { BusinessError } from '@kit.BasicServicesKit'; 7064 7065let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7066predicates.equalTo("NAME", "Lisa"); 7067if(store != undefined) { 7068 (store as relationalStore.RdbStore).lockRow(predicates).then(() => { 7069 console.info(`Lock success`); 7070 }).catch((err: BusinessError) => { 7071 console.error(`Lock failed, code is ${err.code},message is ${err.message}`); 7072 }) 7073} 7074``` 7075 7076### unlockRow<sup>12+</sup> 7077 7078unlockRow(predicates: RdbPredicates):Promise<void> 7079 7080Unlocks data in this RDB store. This API uses a promise to return the result. 7081 7082This 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. 7083This 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. 7084This API cannot be used for deleted data. 7085 7086**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7087 7088**Parameters** 7089 7090| Name | Type | Mandatory| Description | 7091| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 7092| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions for unlocking data.| 7093 7094**Return value** 7095 7096| Type | Description | 7097| --------------------- | ------------------------------- | 7098| Promise<void> | Promise that returns no value. | 7099 7100**Error codes** 7101 7102For 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). 7103 7104| **ID**| **Error Message** | 7105|-----------| ------------------------------------------------------------ | 7106| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7107| 14800000 | Inner error. | 7108| 14800011 | Database corrupted. | 7109| 14800014 | Already closed. | 7110| 14800015 | The database does not respond. | 7111| 14800018 | No data meets the condition. | 7112| 14800021 | SQLite: Generic error. | 7113| 14800022 | SQLite: Callback routine requested an abort. | 7114| 14800023 | SQLite: Access permission denied. | 7115| 14800024 | SQLite: The database file is locked. | 7116| 14800025 | SQLite: A table in the database is locked. | 7117| 14800026 | SQLite: The database is out of memory. | 7118| 14800027 | SQLite: Attempt to write a readonly database. | 7119| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7120| 14800029 | SQLite: The database is full. | 7121| 14800030 | SQLite: Unable to open the database file. | 7122| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7123| 14800032 | SQLite: Abort due to constraint violation. | 7124| 14800033 | SQLite: Data type mismatch. | 7125| 14800034 | SQLite: Library used incorrectly. | 7126 7127**Example** 7128 7129```ts 7130import { BusinessError } from '@kit.BasicServicesKit'; 7131 7132let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7133predicates.equalTo("NAME", "Lisa"); 7134if(store != undefined) { 7135 (store as relationalStore.RdbStore).unlockRow(predicates).then(() => { 7136 console.info(`Unlock success`); 7137 }).catch((err: BusinessError) => { 7138 console.error(`Unlock failed, code is ${err.code},message is ${err.message}`); 7139 }) 7140} 7141``` 7142 7143### queryLockedRow<sup>12+</sup> 7144 7145queryLockedRow(predicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> 7146 7147Queries the locked data in this RDB store. This API uses a promise to return the result. 7148Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 7149 7150**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7151 7152**Parameters** 7153 7154| Name | Type | Mandatory| Description | 7155| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 7156| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 7157| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 7158 7159**Error codes** 7160 7161For 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). 7162 7163| **ID**| **Error Message** | 7164|-----------| ------------------------------------------------------------ | 7165| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7166| 14800000 | Inner error. | 7167| 14800011 | Database corrupted. | 7168| 14800014 | Already closed. | 7169| 14800015 | The database does not respond. | 7170| 14800021 | SQLite: Generic error. | 7171| 14800022 | SQLite: Callback routine requested an abort. | 7172| 14800023 | SQLite: Access permission denied. | 7173| 14800024 | SQLite: The database file is locked. | 7174| 14800025 | SQLite: A table in the database is locked. | 7175| 14800026 | SQLite: The database is out of memory. | 7176| 14800027 | SQLite: Attempt to write a readonly database. | 7177| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7178| 14800029 | SQLite: The database is full. | 7179| 14800030 | SQLite: Unable to open the database file. | 7180| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7181| 14800032 | SQLite: Abort due to constraint violation. | 7182| 14800033 | SQLite: Data type mismatch. | 7183| 14800034 | SQLite: Library used incorrectly. | 7184 7185**Return value** 7186 7187| Type | Description | 7188| ------------------------------------------------------- | -------------------------------------------------- | 7189| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 7190 7191**Example** 7192 7193```ts 7194import { BusinessError } from '@kit.BasicServicesKit'; 7195 7196let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7197predicates.equalTo("NAME", "Rose"); 7198if(store != undefined) { 7199 (store as relationalStore.RdbStore).queryLockedRow(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 7200 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 7201 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 7202 while (resultSet.goToNextRow()) { 7203 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 7204 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 7205 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 7206 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 7207 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 7208 } 7209 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 7210 resultSet.close(); 7211 }).catch((err: BusinessError) => { 7212 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 7213 }) 7214} 7215``` 7216### close<sup>12+</sup> 7217 7218close(): Promise<void> 7219 7220Closes this RDB store. This API uses a promise to return the result. 7221 7222**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7223 7224**Return value** 7225 7226| Type | Description | 7227| ------------------- | ------------- | 7228| Promise<void> | Promise used to| 7229 7230**Error codes** 7231 7232For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 7233 7234| **ID**| **Error Message** | 7235| ------------ | ----------------------------------------------- | 7236| 401 | Parameter error. The store must not be nullptr. | 7237| 14800000 | Inner error. | 7238 7239**Example** 7240 7241```ts 7242import { BusinessError } from '@kit.BasicServicesKit'; 7243 7244if(store != undefined) { 7245 (store as relationalStore.RdbStore).close().then(() => { 7246 console.info(`close succeeded`); 7247 }).catch ((err: BusinessError) => { 7248 console.error(`close failed, code is ${err.code},message is ${err.message}`); 7249 }) 7250} 7251``` 7252 7253## ResultSet 7254 7255Provides APIs to access the **resultSet** object returned by **query()**. 7256 7257### Usage 7258 7259Obtain the **resultSet** object first. 7260 7261**Example** 7262 7263<!--code_no_check--> 7264```ts 7265let resultSet: relationalStore.ResultSet | undefined = undefined; 7266let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7267predicates.equalTo("AGE", 18); 7268if(store != undefined) { 7269 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((result: relationalStore.ResultSet) => { 7270 resultSet = result; 7271 console.info(`resultSet columnNames: ${resultSet.columnNames}`); 7272 console.info(`resultSet columnCount: ${resultSet.columnCount}`); 7273 }); 7274} 7275``` 7276 7277### Properties 7278 7279**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7280 7281| Name | Type | Mandatory| Description | 7282| ------------ | ------------------- | ---- | -------------------------------- | 7283| columnNames | Array<string> | Yes | Names of all columns in the result set. | 7284| columnCount | number | Yes | Number of columns in the result set. | 7285| rowCount | number | Yes | Number of rows in the result set. | 7286| rowIndex | number | Yes | Index of the current row in the result set. | 7287| isAtFirstRow | boolean | Yes | Whether the cursor is in the first row of the result set. | 7288| isAtLastRow | boolean | Yes | Whether the cursor is in the last row of the result set. | 7289| isEnded | boolean | Yes | Whether the cursor is after the last row of the result set.| 7290| isStarted | boolean | Yes | Whether the cursor has been moved. | 7291| isClosed | boolean | Yes | Whether the result set is closed. | 7292 7293### getColumnIndex 7294 7295getColumnIndex(columnName: string): number 7296 7297Obtains the column index based on the column name. 7298 7299**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7300 7301**Parameters** 7302 7303| Name | Type | Mandatory| Description | 7304| ---------- | ------ | ---- | -------------------------- | 7305| columnName | string | Yes | Column name.| 7306 7307**Return value** 7308 7309| Type | Description | 7310| ------ | ------------------ | 7311| number | Column index obtained.| 7312 7313**Error codes** 7314 7315For 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). 7316 7317| **ID**| **Error Message** | 7318|-----------| ------------------------------------------------------------ | 7319| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7320| 14800000 | Inner error. | 7321| 14800011 | Database corrupted. | 7322| 14800013 | Column out of bounds. | 7323| 14800014 | Already closed. | 7324| 14800019 | The SQL must be a query statement. | 7325| 14800021 | SQLite: Generic error. | 7326| 14800022 | SQLite: Callback routine requested an abort. | 7327| 14800023 | SQLite: Access permission denied. | 7328| 14800024 | SQLite: The database file is locked. | 7329| 14800025 | SQLite: A table in the database is locked. | 7330| 14800026 | SQLite: The database is out of memory. | 7331| 14800027 | SQLite: Attempt to write a readonly database. | 7332| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7333| 14800029 | SQLite: The database is full. | 7334| 14800030 | SQLite: Unable to open the database file. | 7335| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7336| 14800032 | SQLite: Abort due to constraint violation. | 7337| 14800033 | SQLite: Data type mismatch. | 7338| 14800034 | SQLite: Library used incorrectly. | 7339 7340**Example** 7341 7342```ts 7343if(resultSet != undefined) { 7344 const id = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("ID")); 7345 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 7346 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 7347 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 7348} 7349``` 7350 7351### getColumnName 7352 7353getColumnName(columnIndex: number): string 7354 7355Obtains the column name based on the specified column index. 7356 7357**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7358 7359**Parameters** 7360 7361| Name | Type | Mandatory| Description | 7362| ----------- | ------ | ---- | -------------------------- | 7363| columnIndex | number | Yes | Column index.| 7364 7365**Return value** 7366 7367| Type | Description | 7368| ------ | ------------------ | 7369| string | Column name obtained.| 7370 7371**Error codes** 7372 7373For 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). 7374 7375| **ID**| **Error Message** | 7376|-----------| ------------------------------------------------------------ | 7377| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7378| 14800000 | Inner error. | 7379| 14800011 | Database corrupted. | 7380| 14800013 | Column out of bounds. | 7381| 14800014 | Already closed. | 7382| 14800019 | The SQL must be a query statement. | 7383| 14800021 | SQLite: Generic error. | 7384| 14800022 | SQLite: Callback routine requested an abort. | 7385| 14800023 | SQLite: Access permission denied. | 7386| 14800024 | SQLite: The database file is locked. | 7387| 14800025 | SQLite: A table in the database is locked. | 7388| 14800026 | SQLite: The database is out of memory. | 7389| 14800027 | SQLite: Attempt to write a readonly database. | 7390| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7391| 14800029 | SQLite: The database is full. | 7392| 14800030 | SQLite: Unable to open the database file. | 7393| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7394| 14800032 | SQLite: Abort due to constraint violation. | 7395| 14800033 | SQLite: Data type mismatch. | 7396| 14800034 | SQLite: Library used incorrectly. | 7397 7398**Example** 7399 7400```ts 7401if(resultSet != undefined) { 7402 const id = (resultSet as relationalStore.ResultSet).getColumnName(0); 7403 const name = (resultSet as relationalStore.ResultSet).getColumnName(1); 7404 const age = (resultSet as relationalStore.ResultSet).getColumnName(2); 7405} 7406``` 7407 7408### goTo 7409 7410goTo(offset:number): boolean 7411 7412Moves the cursor to the row based on the specified offset. 7413 7414**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7415 7416**Parameters** 7417 7418| Name| Type | Mandatory| Description | 7419| ------ | ------ | ---- | ---------------------------- | 7420| offset | number | Yes | Offset relative to the current position.| 7421 7422**Return value** 7423 7424| Type | Description | 7425| ------- | --------------------------------------------- | 7426| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7427 7428**Error codes** 7429 7430For 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). 7431 7432| **ID**| **Error Message** | 7433|-----------| ------------------------------------------------------------ | 7434| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7435| 14800000 | Inner error. | 7436| 14800011 | Database corrupted. | 7437| 14800012 | Row out of bounds. | 7438| 14800014 | Already closed. | 7439| 14800019 | The SQL must be a query statement. | 7440| 14800021 | SQLite: Generic error. | 7441| 14800022 | SQLite: Callback routine requested an abort. | 7442| 14800023 | SQLite: Access permission denied. | 7443| 14800024 | SQLite: The database file is locked. | 7444| 14800025 | SQLite: A table in the database is locked. | 7445| 14800026 | SQLite: The database is out of memory. | 7446| 14800027 | SQLite: Attempt to write a readonly database. | 7447| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7448| 14800029 | SQLite: The database is full. | 7449| 14800030 | SQLite: Unable to open the database file. | 7450| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7451| 14800032 | SQLite: Abort due to constraint violation. | 7452| 14800033 | SQLite: Data type mismatch. | 7453| 14800034 | SQLite: Library used incorrectly. | 7454 7455**Example** 7456 7457```ts 7458if(resultSet != undefined) { 7459 (resultSet as relationalStore.ResultSet).goTo(1); 7460} 7461``` 7462 7463### goToRow 7464 7465goToRow(position: number): boolean 7466 7467Moves to the specified row in the result set. 7468 7469**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7470 7471**Parameters** 7472 7473| Name | Type | Mandatory| Description | 7474| -------- | ------ | ---- | ------------------------ | 7475| position | number | Yes | Destination position to move to.| 7476 7477**Return value** 7478 7479| Type | Description | 7480| ------- | --------------------------------------------- | 7481| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7482 7483**Error codes** 7484 7485For 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). 7486 7487| **ID**| **Error Message** | 7488|-----------| ------------------------------------------------------------ | 7489| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7490| 14800000 | Inner error. | 7491| 14800011 | Database corrupted. | 7492| 14800012 | Row out of bounds. | 7493| 14800014 | Already closed. | 7494| 14800019 | The SQL must be a query statement. | 7495| 14800021 | SQLite: Generic error. | 7496| 14800022 | SQLite: Callback routine requested an abort. | 7497| 14800023 | SQLite: Access permission denied. | 7498| 14800024 | SQLite: The database file is locked. | 7499| 14800025 | SQLite: A table in the database is locked. | 7500| 14800026 | SQLite: The database is out of memory. | 7501| 14800027 | SQLite: Attempt to write a readonly database. | 7502| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7503| 14800029 | SQLite: The database is full. | 7504| 14800030 | SQLite: Unable to open the database file. | 7505| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7506| 14800032 | SQLite: Abort due to constraint violation. | 7507| 14800033 | SQLite: Data type mismatch. | 7508| 14800034 | SQLite: Library used incorrectly. | 7509 7510**Example** 7511 7512```ts 7513if(resultSet != undefined) { 7514 (resultSet as relationalStore.ResultSet).goToRow(5); 7515} 7516``` 7517 7518### goToFirstRow 7519 7520goToFirstRow(): boolean 7521 7522 7523Moves to the first row of the result set. 7524 7525**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7526 7527**Return value** 7528 7529| Type | Description | 7530| ------- | --------------------------------------------- | 7531| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7532 7533**Error codes** 7534 7535For 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). 7536 7537| **ID**| **Error Message** | 7538|-----------| ------------------------------------------------------------ | 7539| 14800000 | Inner error. | 7540| 14800011 | Database corrupted. | 7541| 14800012 | Row out of bounds. | 7542| 14800014 | Already closed. | 7543| 14800019 | The SQL must be a query statement. | 7544| 14800021 | SQLite: Generic error. | 7545| 14800022 | SQLite: Callback routine requested an abort. | 7546| 14800023 | SQLite: Access permission denied. | 7547| 14800024 | SQLite: The database file is locked. | 7548| 14800025 | SQLite: A table in the database is locked. | 7549| 14800026 | SQLite: The database is out of memory. | 7550| 14800027 | SQLite: Attempt to write a readonly database. | 7551| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7552| 14800029 | SQLite: The database is full. | 7553| 14800030 | SQLite: Unable to open the database file. | 7554| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7555| 14800032 | SQLite: Abort due to constraint violation. | 7556| 14800033 | SQLite: Data type mismatch. | 7557| 14800034 | SQLite: Library used incorrectly. | 7558 7559**Example** 7560 7561```ts 7562if(resultSet != undefined) { 7563 (resultSet as relationalStore.ResultSet).goToFirstRow(); 7564} 7565``` 7566 7567### goToLastRow 7568 7569goToLastRow(): boolean 7570 7571Moves to the last row of the result set. 7572 7573**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7574 7575**Return value** 7576 7577| Type | Description | 7578| ------- | --------------------------------------------- | 7579| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7580 7581**Error codes** 7582 7583For 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). 7584 7585| **ID**| **Error Message** | 7586|-----------| ------------------------------------------------------------ | 7587| 14800000 | Inner error. | 7588| 14800011 | Database corrupted. | 7589| 14800012 | Row out of bounds. | 7590| 14800014 | Already closed. | 7591| 14800019 | The SQL must be a query statement. | 7592| 14800021 | SQLite: Generic error. | 7593| 14800022 | SQLite: Callback routine requested an abort. | 7594| 14800023 | SQLite: Access permission denied. | 7595| 14800024 | SQLite: The database file is locked. | 7596| 14800025 | SQLite: A table in the database is locked. | 7597| 14800026 | SQLite: The database is out of memory. | 7598| 14800027 | SQLite: Attempt to write a readonly database. | 7599| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7600| 14800029 | SQLite: The database is full. | 7601| 14800030 | SQLite: Unable to open the database file. | 7602| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7603| 14800032 | SQLite: Abort due to constraint violation. | 7604| 14800033 | SQLite: Data type mismatch. | 7605| 14800034 | SQLite: Library used incorrectly. | 7606 7607**Example** 7608 7609```ts 7610if(resultSet != undefined) { 7611 (resultSet as relationalStore.ResultSet).goToLastRow(); 7612} 7613``` 7614 7615### goToNextRow 7616 7617goToNextRow(): boolean 7618 7619Moves to the next row in the result set. 7620 7621**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7622 7623**Return value** 7624 7625| Type | Description | 7626| ------- | --------------------------------------------- | 7627| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7628 7629**Error codes** 7630 7631For 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). 7632 7633| **ID**| **Error Message** | 7634|-----------| ------------------------------------------------------------ | 7635| 14800000 | Inner error. | 7636| 14800011 | Database corrupted. | 7637| 14800012 | Row out of bounds. | 7638| 14800014 | Already closed. | 7639| 14800019 | The SQL must be a query statement. | 7640| 14800021 | SQLite: Generic error. | 7641| 14800022 | SQLite: Callback routine requested an abort. | 7642| 14800023 | SQLite: Access permission denied. | 7643| 14800024 | SQLite: The database file is locked. | 7644| 14800025 | SQLite: A table in the database is locked. | 7645| 14800026 | SQLite: The database is out of memory. | 7646| 14800027 | SQLite: Attempt to write a readonly database. | 7647| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7648| 14800029 | SQLite: The database is full. | 7649| 14800030 | SQLite: Unable to open the database file. | 7650| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7651| 14800032 | SQLite: Abort due to constraint violation. | 7652| 14800033 | SQLite: Data type mismatch. | 7653| 14800034 | SQLite: Library used incorrectly. | 7654 7655**Example** 7656 7657```ts 7658if(resultSet != undefined) { 7659 (resultSet as relationalStore.ResultSet).goToNextRow(); 7660} 7661``` 7662 7663### goToPreviousRow 7664 7665goToPreviousRow(): boolean 7666 7667Moves to the previous row in the result set. 7668 7669**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7670 7671**Return value** 7672 7673| Type | Description | 7674| ------- | --------------------------------------------- | 7675| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7676 7677**Error codes** 7678 7679For 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). 7680 7681| **ID**| **Error Message** | 7682|-----------| ------------------------------------------------------------ | 7683| 14800000 | Inner error. | 7684| 14800011 | Database corrupted. | 7685| 14800012 | Row out of bounds. | 7686| 14800014 | Already closed. | 7687| 14800019 | The SQL must be a query statement. | 7688| 14800021 | SQLite: Generic error. | 7689| 14800022 | SQLite: Callback routine requested an abort. | 7690| 14800023 | SQLite: Access permission denied. | 7691| 14800024 | SQLite: The database file is locked. | 7692| 14800025 | SQLite: A table in the database is locked. | 7693| 14800026 | SQLite: The database is out of memory. | 7694| 14800027 | SQLite: Attempt to write a readonly database. | 7695| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7696| 14800029 | SQLite: The database is full. | 7697| 14800030 | SQLite: Unable to open the database file. | 7698| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7699| 14800032 | SQLite: Abort due to constraint violation. | 7700| 14800033 | SQLite: Data type mismatch. | 7701| 14800034 | SQLite: Library used incorrectly. | 7702 7703**Example** 7704 7705```ts 7706if(resultSet != undefined) { 7707 (resultSet as relationalStore.ResultSet).goToPreviousRow(); 7708} 7709``` 7710 7711### getValue<sup>12+</sup> 7712 7713getValue(columnIndex: number): ValueType 7714 7715Obtains 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. 7716 7717**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7718 7719**Parameters** 7720 7721| Name | Type | Mandatory| Description | 7722| ----------- | ------ | ---- | ----------------------- | 7723| columnIndex | number | Yes | Index of the target column, starting from 0.| 7724 7725**Return value** 7726 7727| Type | Description | 7728| ---------- | -------------------------------- | 7729| [ValueType](#valuetype) | Value obtained. | 7730 7731**Error codes** 7732 7733For 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). 7734 7735| **ID**| **Error Message** | 7736|-----------|---------| 7737| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7738| 14800000 | Inner error. | 7739| 14800011 | Database corrupted. | 7740| 14800012 | Row out of bounds. | 7741| 14800013 | Column out of bounds. | 7742| 14800014 | Already closed. | 7743| 14800021 | SQLite: Generic error. | 7744| 14800022 | SQLite: Callback routine requested an abort. | 7745| 14800023 | SQLite: Access permission denied. | 7746| 14800024 | SQLite: The database file is locked. | 7747| 14800025 | SQLite: A table in the database is locked. | 7748| 14800026 | SQLite: The database is out of memory. | 7749| 14800027 | SQLite: Attempt to write a readonly database. | 7750| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7751| 14800029 | SQLite: The database is full. | 7752| 14800030 | SQLite: Unable to open the database file. | 7753| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7754| 14800032 | SQLite: Abort due to constraint violation. | 7755| 14800033 | SQLite: Data type mismatch. | 7756| 14800034 | SQLite: Library used incorrectly. | 7757 7758**Example** 7759 7760```ts 7761if(resultSet != undefined) { 7762 const codes = (resultSet as relationalStore.ResultSet).getValue((resultSet as relationalStore.ResultSet).getColumnIndex("BIGINT_COLUMN")); 7763} 7764``` 7765 7766### getBlob 7767 7768getBlob(columnIndex: number): Uint8Array 7769 7770 7771Obtains 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. 7772 7773**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7774 7775**Parameters** 7776 7777| Name | Type | Mandatory| Description | 7778| ----------- | ------ | ---- | ----------------------- | 7779| columnIndex | number | Yes | Index of the target column, starting from 0.| 7780 7781**Return value** 7782 7783| Type | Description | 7784| ---------- | -------------------------------- | 7785| Uint8Array | Value obtained.| 7786 7787**Error codes** 7788 7789For 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). 7790 7791| **ID**| **Error Message** | 7792|-----------| ------------------------------------------------------------ | 7793| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7794| 14800000 | Inner error. | 7795| 14800011 | Database corrupted. | 7796| 14800012 | Row out of bounds. | 7797| 14800013 | Column out of bounds. | 7798| 14800014 | Already closed. | 7799| 14800021 | SQLite: Generic error. | 7800| 14800022 | SQLite: Callback routine requested an abort. | 7801| 14800023 | SQLite: Access permission denied. | 7802| 14800024 | SQLite: The database file is locked. | 7803| 14800025 | SQLite: A table in the database is locked. | 7804| 14800026 | SQLite: The database is out of memory. | 7805| 14800027 | SQLite: Attempt to write a readonly database. | 7806| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7807| 14800029 | SQLite: The database is full. | 7808| 14800030 | SQLite: Unable to open the database file. | 7809| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7810| 14800032 | SQLite: Abort due to constraint violation. | 7811| 14800033 | SQLite: Data type mismatch. | 7812| 14800034 | SQLite: Library used incorrectly. | 7813 7814**Example** 7815 7816```ts 7817if(resultSet != undefined) { 7818 const codes = (resultSet as relationalStore.ResultSet).getBlob((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 7819} 7820``` 7821 7822### getString 7823 7824getString(columnIndex: number): string 7825 7826Obtains 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. 7827 7828**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7829 7830**Parameters** 7831 7832| Name | Type | Mandatory| Description | 7833| ----------- | ------ | ---- | ----------------------- | 7834| columnIndex | number | Yes | Index of the target column, starting from 0.| 7835 7836**Return value** 7837 7838| Type | Description | 7839| ------ | ---------------------------- | 7840| string | String obtained.| 7841 7842**Error codes** 7843 7844For 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). 7845 7846| **ID**| **Error Message** | 7847|-----------| ------------------------------------------------------------ | 7848| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7849| 14800000 | Inner error. | 7850| 14800011 | Database corrupted. | 7851| 14800012 | Row out of bounds. | 7852| 14800013 | Column out of bounds. | 7853| 14800014 | Already closed. | 7854| 14800021 | SQLite: Generic error. | 7855| 14800022 | SQLite: Callback routine requested an abort. | 7856| 14800023 | SQLite: Access permission denied. | 7857| 14800024 | SQLite: The database file is locked. | 7858| 14800025 | SQLite: A table in the database is locked. | 7859| 14800026 | SQLite: The database is out of memory. | 7860| 14800027 | SQLite: Attempt to write a readonly database. | 7861| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7862| 14800029 | SQLite: The database is full. | 7863| 14800030 | SQLite: Unable to open the database file. | 7864| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7865| 14800032 | SQLite: Abort due to constraint violation. | 7866| 14800033 | SQLite: Data type mismatch. | 7867| 14800034 | SQLite: Library used incorrectly. | 7868 7869**Example** 7870 7871```ts 7872if(resultSet != undefined) { 7873 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 7874} 7875``` 7876 7877### getLong 7878 7879getLong(columnIndex: number): number 7880 7881Obtains 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. 7882 7883**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7884 7885**Parameters** 7886 7887| Name | Type | Mandatory| Description | 7888| ----------- | ------ | ---- | ----------------------- | 7889| columnIndex | number | Yes | Index of the target column, starting from 0.| 7890 7891**Return value** 7892 7893| Type | Description | 7894| ------ | ------------------------------------------------------------ | 7895| 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).| 7896 7897**Error codes** 7898 7899For 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). 7900 7901| **ID**| **Error Message** | 7902|-----------| ------------------------------------------------------------ | 7903| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7904| 14800000 | Inner error. | 7905| 14800011 | Database corrupted. | 7906| 14800012 | Row out of bounds. | 7907| 14800013 | Column out of bounds. | 7908| 14800014 | Already closed. | 7909| 14800021 | SQLite: Generic error. | 7910| 14800022 | SQLite: Callback routine requested an abort. | 7911| 14800023 | SQLite: Access permission denied. | 7912| 14800024 | SQLite: The database file is locked. | 7913| 14800025 | SQLite: A table in the database is locked. | 7914| 14800026 | SQLite: The database is out of memory. | 7915| 14800027 | SQLite: Attempt to write a readonly database. | 7916| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7917| 14800029 | SQLite: The database is full. | 7918| 14800030 | SQLite: Unable to open the database file. | 7919| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7920| 14800032 | SQLite: Abort due to constraint violation. | 7921| 14800033 | SQLite: Data type mismatch. | 7922| 14800034 | SQLite: Library used incorrectly. | 7923 7924**Example** 7925 7926```ts 7927if(resultSet != undefined) { 7928 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 7929 } 7930``` 7931 7932### getDouble 7933 7934getDouble(columnIndex: number): number 7935 7936Obtains 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. 7937 7938**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7939 7940**Parameters** 7941 7942| Name | Type | Mandatory| Description | 7943| ----------- | ------ | ---- | ----------------------- | 7944| columnIndex | number | Yes | Index of the target column, starting from 0.| 7945 7946**Return value** 7947 7948| Type | Description | 7949| ------ | ---------------------------- | 7950| number | Returns the value obtained.| 7951 7952**Error codes** 7953 7954For 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). 7955 7956| **ID**| **Error Message** | 7957|-----------| ------------------------------------------------------------ | 7958| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7959| 14800000 | Inner error. | 7960| 14800011 | Database corrupted. | 7961| 14800012 | Row out of bounds. | 7962| 14800013 | Column out of bounds. | 7963| 14800014 | Already closed. | 7964| 14800021 | SQLite: Generic error. | 7965| 14800022 | SQLite: Callback routine requested an abort. | 7966| 14800023 | SQLite: Access permission denied. | 7967| 14800024 | SQLite: The database file is locked. | 7968| 14800025 | SQLite: A table in the database is locked. | 7969| 14800026 | SQLite: The database is out of memory. | 7970| 14800027 | SQLite: Attempt to write a readonly database. | 7971| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7972| 14800029 | SQLite: The database is full. | 7973| 14800030 | SQLite: Unable to open the database file. | 7974| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7975| 14800032 | SQLite: Abort due to constraint violation. | 7976| 14800033 | SQLite: Data type mismatch. | 7977| 14800034 | SQLite: Library used incorrectly. | 7978 7979**Example** 7980 7981```ts 7982if(resultSet != undefined) { 7983 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 7984} 7985``` 7986 7987### getAsset<sup>10+</sup> 7988 7989getAsset(columnIndex: number): Asset 7990 7991Obtains 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. 7992 7993**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7994 7995**Parameters** 7996 7997| Name | Type | Mandatory | Description | 7998| ----------- | ------ | --- | ------------ | 7999| columnIndex | number | Yes | Index of the target column, starting from 0.| 8000 8001**Return value** 8002 8003| Type | Description | 8004| --------------- | -------------------------- | 8005| [Asset](#asset10) | Returns the value obtained.| 8006 8007**Error codes** 8008 8009For 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). 8010 8011| **ID**| **Error Message** | 8012|-----------| ------------------------------------------------------------ | 8013| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8014| 14800000 | Inner error. | 8015| 14800011 | Database corrupted. | 8016| 14800012 | Row out of bounds. | 8017| 14800013 | Column out of bounds. | 8018| 14800014 | Already closed. | 8019| 14800021 | SQLite: Generic error. | 8020| 14800022 | SQLite: Callback routine requested an abort. | 8021| 14800023 | SQLite: Access permission denied. | 8022| 14800024 | SQLite: The database file is locked. | 8023| 14800025 | SQLite: A table in the database is locked. | 8024| 14800026 | SQLite: The database is out of memory. | 8025| 14800027 | SQLite: Attempt to write a readonly database. | 8026| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8027| 14800029 | SQLite: The database is full. | 8028| 14800030 | SQLite: Unable to open the database file. | 8029| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8030| 14800032 | SQLite: Abort due to constraint violation. | 8031| 14800033 | SQLite: Data type mismatch. | 8032| 14800034 | SQLite: Library used incorrectly. | 8033 8034**Example** 8035 8036```ts 8037if(resultSet != undefined) { 8038 const doc = (resultSet as relationalStore.ResultSet).getAsset((resultSet as relationalStore.ResultSet).getColumnIndex("DOC")); 8039} 8040``` 8041 8042### getAssets<sup>10+</sup> 8043 8044getAssets(columnIndex: number): Assets 8045 8046Obtains 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. 8047 8048**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8049 8050**Parameters** 8051 8052| Name | Type | Mandatory | Description | 8053| ----------- | ------ | --- | ------------ | 8054| columnIndex | number | Yes | Index of the target column, starting from 0.| 8055 8056**Return value** 8057 8058| Type | Description | 8059| ---------------- | ---------------------------- | 8060| [Assets](#assets10)| Returns the value obtained.| 8061 8062**Error codes** 8063 8064For 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). 8065 8066| **ID**| **Error Message** | 8067|-----------| ------------------------------------------------------------ | 8068| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8069| 14800000 | Inner error. | 8070| 14800011 | Database corrupted. | 8071| 14800012 | Row out of bounds. | 8072| 14800013 | Column out of bounds. | 8073| 14800014 | Already closed. | 8074| 14800021 | SQLite: Generic error. | 8075| 14800022 | SQLite: Callback routine requested an abort. | 8076| 14800023 | SQLite: Access permission denied. | 8077| 14800024 | SQLite: The database file is locked. | 8078| 14800025 | SQLite: A table in the database is locked. | 8079| 14800026 | SQLite: The database is out of memory. | 8080| 14800027 | SQLite: Attempt to write a readonly database. | 8081| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8082| 14800029 | SQLite: The database is full. | 8083| 14800030 | SQLite: Unable to open the database file. | 8084| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8085| 14800032 | SQLite: Abort due to constraint violation. | 8086| 14800033 | SQLite: Data type mismatch. | 8087| 14800034 | SQLite: Library used incorrectly. | 8088 8089**Example** 8090 8091```ts 8092if(resultSet != undefined) { 8093 const docs = (resultSet as relationalStore.ResultSet).getAssets((resultSet as relationalStore.ResultSet).getColumnIndex("DOCS")); 8094} 8095``` 8096 8097### getRow<sup>11+</sup> 8098 8099getRow(): ValuesBucket 8100 8101Obtains the data in the current row. 8102 8103**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8104 8105**Return value** 8106 8107| Type | Description | 8108| ---------------- | ---------------------------- | 8109| [ValuesBucket](#valuesbucket) | Data obtained.| 8110 8111**Error codes** 8112 8113For 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). 8114 8115| **ID**| **Error Message** | 8116|-----------| ------------------------------------------------------------ | 8117| 14800000 | Inner error. | 8118| 14800011 | Database corrupted. | 8119| 14800012 | Row out of bounds. | 8120| 14800013 | Column out of bounds. | 8121| 14800014 | Already closed. | 8122| 14800021 | SQLite: Generic error. | 8123| 14800022 | SQLite: Callback routine requested an abort. | 8124| 14800023 | SQLite: Access permission denied. | 8125| 14800024 | SQLite: The database file is locked. | 8126| 14800025 | SQLite: A table in the database is locked. | 8127| 14800026 | SQLite: The database is out of memory. | 8128| 14800027 | SQLite: Attempt to write a readonly database. | 8129| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8130| 14800029 | SQLite: The database is full. | 8131| 14800030 | SQLite: Unable to open the database file. | 8132| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8133| 14800032 | SQLite: Abort due to constraint violation. | 8134| 14800033 | SQLite: Data type mismatch. | 8135| 14800034 | SQLite: Library used incorrectly. | 8136 8137**Example** 8138 8139```ts 8140if(resultSet != undefined) { 8141 const row = (resultSet as relationalStore.ResultSet).getRow(); 8142} 8143``` 8144 8145### getSendableRow<sup>12+</sup> 8146 8147getSendableRow(): sendableRelationalStore.ValuesBucket 8148 8149Obtains the Sendable data from the current row. The data obtained is used for cross-thread transfer. 8150 8151**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8152 8153**Return value** 8154 8155| Type | Description | 8156| ---------------------------------------------------------------------------------------------- | ---------------------------------------------- | 8157| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | Sendable data obtained for cross-thread transfer.| 8158 8159**Error codes** 8160 8161For 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). 8162 8163| **ID**| **Error Message** | 8164| ------------ | --------------------------------------------- | 8165| 14800000 | Inner error. | 8166| 14800011 | Database corrupted. | 8167| 14800012 | Row out of bounds. | 8168| 14800013 | Column out of bounds. | 8169| 14800014 | Already closed. | 8170| 14800021 | SQLite: Generic error. | 8171| 14800022 | SQLite: Callback routine requested an abort. | 8172| 14800023 | SQLite: Access permission denied. | 8173| 14800024 | SQLite: The database file is locked. | 8174| 14800025 | SQLite: A table in the database is locked. | 8175| 14800026 | SQLite: The database is out of memory. | 8176| 14800027 | SQLite: Attempt to write a readonly database. | 8177| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8178| 14800029 | SQLite: The database is full. | 8179| 14800030 | SQLite: Unable to open the database file. | 8180| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8181| 14800032 | SQLite: Abort due to constraint violation. | 8182| 14800033 | SQLite: Data type mismatch. | 8183| 14800034 | SQLite: Library used incorrectly. | 8184 8185**Example** 8186 8187```ts 8188import { taskpool } from '@kit.ArkTS'; 8189import type ctx from '@ohos.app.ability.common'; 8190import { sendableRelationalStore } from '@kit.ArkData'; 8191 8192@Concurrent 8193async function getDataByName(name: string, context: ctx.UIAbilityContext) { 8194 const STORE_CONFIG: relationalStore.StoreConfig = { 8195 name: "RdbTest.db", 8196 securityLevel: relationalStore.SecurityLevel.S3 8197 }; 8198 const store = await relationalStore.getRdbStore(context, STORE_CONFIG); 8199 const predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 8200 predicates.equalTo("NAME", name); 8201 const resultSet = store.querySync(predicates); 8202 8203 if (resultSet.rowCount > 0) { 8204 resultSet.goToFirstRow(); 8205 const sendableValuesBucket = resultSet.getSendableRow(); 8206 return sendableValuesBucket; 8207 } else { 8208 return null; 8209 } 8210} 8211 8212const task = new taskpool.Task(getDataByName, 'Lisa', this.context); 8213const sendableValuesBucket = await taskpool.execute(task) as sendableRelationalStore.ValuesBucket; 8214 8215if (sendableValuesBucket) { 8216 const columnCount = sendableValuesBucket.size; 8217 const age = sendableValuesBucket.get('age'); 8218 const name = sendableValuesBucket.get('name'); 8219 console.info(`Query data in taskpool succeeded, name is "${name}", age is "${age}"`) 8220} 8221``` 8222 8223### isColumnNull 8224 8225isColumnNull(columnIndex: number): boolean 8226 8227Checks whether the value in the specified column is null. 8228 8229**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8230 8231**Parameters** 8232 8233| Name | Type | Mandatory| Description | 8234| ----------- | ------ | ---- | ----------------------- | 8235| columnIndex | number | Yes | Index of the target column, starting from 0.| 8236 8237**Return value** 8238 8239| Type | Description | 8240| ------- | --------------------------------------------------------- | 8241| boolean | Returns **true** if the value is null; returns **false** otherwise.| 8242 8243**Error codes** 8244 8245For 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). 8246 8247| **ID**| **Error Message** | 8248|-----------| ------------------------------------------------------- | 8249| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8250| 14800000 | Inner error. | 8251| 14800011 | Database corrupted. | 8252| 14800012 | Row out of bounds. | 8253| 14800013 | Column out of bounds. | 8254| 14800014 | Already closed. | 8255| 14800021 | SQLite: Generic error. | 8256| 14800022 | SQLite: Callback routine requested an abort. | 8257| 14800023 | SQLite: Access permission denied. | 8258| 14800024 | SQLite: The database file is locked. | 8259| 14800025 | SQLite: A table in the database is locked. | 8260| 14800026 | SQLite: The database is out of memory. | 8261| 14800027 | SQLite: Attempt to write a readonly database. | 8262| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8263| 14800029 | SQLite: The database is full. | 8264| 14800030 | SQLite: Unable to open the database file. | 8265| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8266| 14800032 | SQLite: Abort due to constraint violation. | 8267| 14800033 | SQLite: Data type mismatch. | 8268| 14800034 | SQLite: Library used incorrectly. | 8269 8270**Example** 8271 8272```ts 8273if(resultSet != undefined) { 8274 const isColumnNull = (resultSet as relationalStore.ResultSet).isColumnNull((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 8275} 8276``` 8277 8278### close 8279 8280close(): void 8281 8282Closes this **resultSet** to release memory. If the **resultSet** is not closed, FD or memory leaks may occur. 8283 8284**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8285 8286**Example** 8287 8288```ts 8289if(resultSet != undefined) { 8290 (resultSet as relationalStore.ResultSet).close(); 8291} 8292``` 8293 8294**Error codes** 8295 8296For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 8297 8298| **ID**| **Error Message** | 8299|-----------| ------------------------------------------------------------ | 8300| 14800000 | Inner error. | 8301| 14800012 | Row out of bounds. | 8302