1# @ohos.data.relationalStore (RDB Store) 2 3The relational database (RDB) store manages data based on relational models. The **relationalStore** module provides a complete mechanism for managing local databases based on the underlying SQLite. You can use the APIs to perform operations such as adding, deleting, modifying, and querying data, and directly run SQL statements. You can also use [ResultSet.getSendableRow](#getsendablerow12) to obtain sendable data for cross-thread transmission. 4 5To ensure successful data access, limit the size of a data record to 2 MB. If a data record exceeds 2 MB, it can be inserted successfully but cannot be read. 6 7Querying data from a large amount of data may take time or even cause application suspension. In this case, you can perform batch operations. For details, see [Batch Database Operations](../../arkts-utils/batch-database-operations-guide.md). Moreover, observe the following: 8- The number of data records to be queried at a time should not exceed 5000. 9- Use [TaskPool](../apis-arkts/js-apis-taskpool.md) if there is a large amount of data needs to be queried. 10- Keep concatenated SQL statements as concise as possible. 11- Query data in batches. 12 13The **relationalStore** module provides the following functionalities: 14 15- [RdbPredicates](#rdbpredicates): provides APIs for creating predicates. The predicates represent the properties, characteristics, or relationships between data entities in an RDB store and are used to define data operation conditions. 16- [RdbStore](#rdbstore): provides APIs for managing data in an RDB store. 17- [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store. 18- [Transaction](#transaction14): provides APIs for managing transactions. 19 20> **NOTE** 21> 22> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 23 24## Modules to Import 25 26```ts 27import { relationalStore } from '@kit.ArkData'; 28``` 29 30## relationalStore.getRdbStore 31 32getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback<RdbStore>): void 33 34Obtains an RdbStore instance. You can set the **config** parameter as required and use **RdbStore** APIs to perform data operations. This API uses an asynchronous callback to return the result. 35 36If no database file exists in the corresponding sandbox directory, a database file is created. For details, see [StoreConfig](#storeconfig). If a database file exists in the corresponding directory, the existing database file is opened. 37 38When creating a database, you should consider whether to configure the [encrypt](#storeconfig) parameter. Once the database is created, you are not allowed to change this parameter. 39 40| Encryption Type When the RDB Store Is Opened | Encryption Type When the RDB Store Is Created | Behavior| 41| ------- | -------------------------------- | ---- | 42| Not encrypt| Encrypt | The RDB store is opened in encrypted mode. | 43| Encrypt| Not encrypt | The RDB store is opened in non-encrypted mode. | 44 45Currently, **getRdbStore()** does not support multi-thread concurrent operations. 46 47**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 48 49**Parameters** 50 51| Name | Type | Mandatory| Description | 52| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | 53| 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).| 54| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 55| callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes | Callback used to return the RdbStore instance obtained. | 56 57**Error codes** 58 59For 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). 60 61| **ID**| **Error Message** | 62|-----------|---------| 63| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 64| 14800000 | Inner error. | 65| 14800010 | Failed to open or delete the database by an invalid database path. | 66| 14800011 | Failed to open the database because it is corrupted. | 67| 14801001 | The operation is supported in the stage model only. | 68| 14801002 | Invalid data group ID. | 69| 14800017 | StoreConfig is changed. | 70| 14800020 | The secret key is corrupted or lost. | 71| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 72| 14800022 | SQLite: Callback routine requested an abort. | 73| 14800023 | SQLite: Access permission denied. | 74| 14800027 | SQLite: Attempt to write a readonly database. | 75| 14800028 | SQLite: Some kind of disk I/O error occurred. | 76| 14800029 | SQLite: The database is full. | 77| 14800030 | SQLite: Unable to open the database file. | 78 79**Example** 80 81FA model: 82 83<!--code_no_check_fa--> 84```js 85import { featureAbility } from '@kit.AbilityKit'; 86import { BusinessError } from '@kit.BasicServicesKit'; 87 88let store: relationalStore.RdbStore | undefined = undefined; 89let context = featureAbility.getContext(); 90 91const STORE_CONFIG: relationalStore.StoreConfig = { 92 name: "RdbTest.db", 93 securityLevel: relationalStore.SecurityLevel.S3 94}; 95 96relationalStore.getRdbStore(context, STORE_CONFIG, async (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 97 if (err) { 98 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 99 return; 100 } 101 console.info('Get RdbStore successfully.'); 102 store = rdbStore; 103 // Perform subsequent operations after the rdbStore instance is successfully obtained. 104}); 105``` 106 107Stage model: 108 109```ts 110import { UIAbility } from '@kit.AbilityKit'; 111import { window } from '@kit.ArkUI'; 112import { BusinessError } from '@kit.BasicServicesKit'; 113 114let store: relationalStore.RdbStore | undefined = undefined; 115 116class EntryAbility extends UIAbility { 117 onWindowStageCreate(windowStage: window.WindowStage) { 118 const STORE_CONFIG: relationalStore.StoreConfig = { 119 name: "RdbTest.db", 120 securityLevel: relationalStore.SecurityLevel.S3 121 }; 122 123 relationalStore.getRdbStore(this.context, STORE_CONFIG, async (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 124 if (err) { 125 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 126 return; 127 } 128 console.info('Get RdbStore successfully.'); 129 store = rdbStore; 130 // Perform subsequent operations after the rdbStore instance is successfully obtained. 131 }); 132 } 133} 134``` 135 136## relationalStore.getRdbStore 137 138getRdbStore(context: Context, config: StoreConfig): Promise<RdbStore> 139 140Obtains an RdbStore instance. You can set the **config** parameter as required and use **RdbStore** APIs to perform data operations. This API uses a promise to return the result. 141 142If no database file exists in the corresponding sandbox directory, a database file is created. For details, see [StoreConfig](#storeconfig). If a database file exists in the corresponding directory, the existing database file is opened. 143 144When creating a database, you should consider whether to configure the [encrypt](#storeconfig) parameter. Once the database is created, you are not allowed to change this parameter. 145 146| Encryption Type When the RDB Store Is Opened | Encryption Type When the RDB Store Is Created | Behavior| 147| ------- | -------------------------------- | ---- | 148| Not encrypt| Encrypt | The RDB store is opened in encrypted mode. | 149| Encrypt| Not encrypt | The RDB store is opened in non-encrypted mode. | 150 151Currently, **getRdbStore()** does not support multi-thread concurrent operations. 152 153**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 154 155**Parameters** 156 157| Name | Type | Mandatory| Description | 158| ------- | -------------------------------- | ---- | ------------------------------------------------------------ | 159| 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).| 160| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 161 162**Return value** 163 164| Type | Description | 165| ----------------------------------------- | --------------------------------- | 166| Promise<[RdbStore](#rdbstore)> | Promise used to return the **RdbStore** object obtained.| 167 168**Error codes** 169 170For 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). 171 172| **ID**| **Error Message** | 173|-----------| ------------------------------------------------------------ | 174| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 175| 14800000 | Inner error. | 176| 14800010 | Failed to open or delete the database by an invalid database path. | 177| 14800011 | Failed to open the database because it is corrupted. | 178| 14801001 | The operation is supported in the stage model only. | 179| 14801002 | Invalid data group ID. | 180| 14800017 | StoreConfig is changed. | 181| 14800020 | The secret key is corrupted or lost. | 182| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 183| 14800022 | SQLite: Callback routine requested an abort. | 184| 14800023 | SQLite: Access permission denied. | 185| 14800027 | SQLite: Attempt to write a readonly database. | 186| 14800028 | SQLite: Some kind of disk I/O error occurred. | 187| 14800029 | SQLite: The database is full. | 188| 14800030 | SQLite: Unable to open the database file. | 189 190**Example** 191 192FA model: 193 194<!--code_no_check_fa--> 195```js 196import { featureAbility } from '@kit.AbilityKit'; 197import { BusinessError } from '@kit.BasicServicesKit'; 198 199let store: relationalStore.RdbStore | undefined = undefined; 200let context = featureAbility.getContext(); 201 202const STORE_CONFIG: relationalStore.StoreConfig = { 203 name: "RdbTest.db", 204 securityLevel: relationalStore.SecurityLevel.S3 205}; 206 207relationalStore.getRdbStore(context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 208 store = rdbStore; 209 console.info('Get RdbStore successfully.'); 210}).catch((err: BusinessError) => { 211 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 212}); 213``` 214 215Stage model: 216 217```ts 218import { UIAbility } from '@kit.AbilityKit'; 219import { window } from '@kit.ArkUI'; 220import { BusinessError } from '@kit.BasicServicesKit'; 221 222let store: relationalStore.RdbStore | undefined = undefined; 223 224class EntryAbility extends UIAbility { 225 onWindowStageCreate(windowStage: window.WindowStage) { 226 const STORE_CONFIG: relationalStore.StoreConfig = { 227 name: "RdbTest.db", 228 securityLevel: relationalStore.SecurityLevel.S3 229 }; 230 231 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 232 store = rdbStore; 233 console.info('Get RdbStore successfully.'); 234 }).catch((err: BusinessError) => { 235 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 236 }); 237 } 238} 239``` 240 241## relationalStore.deleteRdbStore 242 243deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void 244 245Deletes an RDB store. This API uses an asynchronous callback to return the result. 246 247After the deletion, you are advised to set the database object to null. If a custom path is set in [StoreConfig](#storeconfig) when an RDB store is created, using this API cannot delete the RDB store. Use [deleteRdbStore](#relationalstoredeleterdbstore10) instead. 248 249Before calling **deleteRdbStore**, ensure that the **RdbStore** and **ResultSet** of the vector store have been closed. 250 251**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 252 253**Parameters** 254 255| Name | Type | Mandatory| Description | 256| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 257| 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).| 258| name | string | Yes | Name of the RDB store to delete. | 259| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 260 261**Error codes** 262 263For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 264 265| **ID**| **Error Message** | 266|-----------|---------------------------------------| 267| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 268| 14800000 | Inner error. | 269| 14800010 | Failed to open or delete the database by an invalid database path. | 270 271**Example** 272 273FA model: 274 275<!--code_no_check_fa--> 276```js 277import { featureAbility } from '@kit.AbilityKit'; 278import { BusinessError } from '@kit.BasicServicesKit'; 279 280let store: relationalStore.RdbStore | undefined = undefined; 281let context = featureAbility.getContext(); 282 283relationalStore.deleteRdbStore(context, "RdbTest.db", (err: BusinessError) => { 284 if (err) { 285 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 286 return; 287 } 288 store = undefined; 289 console.info('Delete RdbStore successfully.'); 290}); 291``` 292 293Stage model: 294 295```ts 296import { UIAbility } from '@kit.AbilityKit'; 297import { window } from '@kit.ArkUI'; 298import { BusinessError } from '@kit.BasicServicesKit'; 299 300let store: relationalStore.RdbStore | undefined = undefined; 301 302class EntryAbility extends UIAbility { 303 onWindowStageCreate(windowStage: window.WindowStage) { 304 relationalStore.deleteRdbStore(this.context, "RdbTest.db", (err: BusinessError) => { 305 if (err) { 306 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 307 return; 308 } 309 store = undefined; 310 console.info('Delete RdbStore successfully.'); 311 }); 312 } 313} 314``` 315 316## relationalStore.deleteRdbStore 317 318deleteRdbStore(context: Context, name: string): Promise<void> 319 320Deletes an RDB store. This API uses a promise to return the result. 321 322After the deletion, you are advised to set the database object to null. If a custom path is set in [StoreConfig](#storeconfig) when an RDB store is created, using this API cannot delete the RDB store. Use [deleteRdbStore](#relationalstoredeleterdbstore10-1) instead. 323 324Before calling **deleteRdbStore**, ensure that the **RdbStore** and **ResultSet** of the vector store have been closed. 325 326**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 327 328**Parameters** 329 330| Name | Type | Mandatory| Description | 331| ------- | ------- | ---- | ------------------------------------------------------------ | 332| 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).| 333| name | string | Yes | Name of the RDB store to delete. | 334 335**Return value** 336 337| Type | Description | 338| ------------------- | ------------------------- | 339| Promise<void> | Promise that returns no value.| 340 341**Error codes** 342 343For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 344 345| **ID**| **Error Message** | 346|-----------|----------------------------------------------------------------------------------| 347| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 348| 14800000 | Inner error. | 349| 14800010 | Failed to open or delete the database by an invalid database path. | 350 351**Example** 352 353FA model: 354 355<!--code_no_check_fa--> 356```js 357import { featureAbility } from '@kit.AbilityKit'; 358import { BusinessError } from '@kit.BasicServicesKit'; 359 360let store: relationalStore.RdbStore | undefined = undefined; 361let context = featureAbility.getContext(); 362 363relationalStore.deleteRdbStore(context, "RdbTest.db").then(() => { 364 store = undefined; 365 console.info('Delete RdbStore successfully.'); 366}).catch((err: BusinessError) => { 367 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 368}); 369``` 370 371Stage model: 372 373```ts 374import { UIAbility } from '@kit.AbilityKit'; 375import { window } from '@kit.ArkUI'; 376import { BusinessError } from '@kit.BasicServicesKit'; 377 378let store: relationalStore.RdbStore | undefined = undefined; 379 380class EntryAbility extends UIAbility { 381 onWindowStageCreate(windowStage: window.WindowStage) { 382 relationalStore.deleteRdbStore(this.context, "RdbTest.db").then(() => { 383 store = undefined; 384 console.info('Delete RdbStore successfully.'); 385 }).catch((err: BusinessError) => { 386 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 387 }); 388 } 389} 390``` 391 392## relationalStore.deleteRdbStore<sup>10+</sup> 393 394deleteRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback\<void>): void 395 396Deletes an RDB store. This API uses an asynchronous callback to return the result. 397 398After 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). 399 400Before calling **deleteRdbStore**, ensure that the **RdbStore** and **ResultSet** of the vector store have been closed. 401 402**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 403 404**Parameters** 405 406| Name | Type | Mandatory| Description | 407| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 408| 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).| 409| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 410| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 411 412**Error codes** 413 414For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 415 416| **ID**| **Error Message** | 417|-----------|----------| 418| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 419| 14800000 | Inner error. | 420| 14800010 | Failed to open or delete the database by an invalid database path. | 421| 14801001 | The operation is supported in the stage model only. | 422| 14801002 | Invalid data group ID. | 423 424**Example** 425 426FA model: 427 428<!--code_no_check_fa--> 429```js 430import { featureAbility } from '@kit.AbilityKit'; 431import { BusinessError } from '@kit.BasicServicesKit'; 432 433let store: relationalStore.RdbStore | undefined = undefined; 434let context = featureAbility.getContext(); 435 436const STORE_CONFIG: relationalStore.StoreConfig = { 437 name: "RdbTest.db", 438 securityLevel: relationalStore.SecurityLevel.S3 439}; 440 441relationalStore.deleteRdbStore(context, STORE_CONFIG, (err: BusinessError) => { 442 if (err) { 443 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 444 return; 445 } 446 store = undefined; 447 console.info('Delete RdbStore successfully.'); 448}); 449``` 450 451Stage model: 452 453```ts 454import { UIAbility } from '@kit.AbilityKit'; 455import { window } from '@kit.ArkUI'; 456import { BusinessError } from '@kit.BasicServicesKit'; 457 458let store: relationalStore.RdbStore | undefined = undefined; 459 460class EntryAbility extends UIAbility { 461 onWindowStageCreate(windowStage: window.WindowStage) { 462 const STORE_CONFIG: relationalStore.StoreConfig = { 463 name: "RdbTest.db", 464 securityLevel: relationalStore.SecurityLevel.S3 465 }; 466 relationalStore.deleteRdbStore(this.context, STORE_CONFIG, (err: BusinessError) => { 467 if (err) { 468 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 469 return; 470 } 471 store = undefined; 472 console.info('Delete RdbStore successfully.'); 473 }); 474 } 475} 476``` 477 478## relationalStore.deleteRdbStore<sup>10+</sup> 479 480deleteRdbStore(context: Context, config: StoreConfig): Promise\<void> 481 482Deletes an RDB store. This API uses a promise to return the result. 483 484After 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). 485 486Before calling **deleteRdbStore**, ensure that the **RdbStore** and **ResultSet** of the vector store have been closed. 487 488**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 489 490**Parameters** 491 492| Name | Type | Mandatory| Description | 493| ------- | --------------------------- | ---- | ------------------------------------------------------------ | 494| 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).| 495| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 496 497**Return value** 498 499| Type | Description | 500| ------------------- | ------------------------- | 501| Promise<void> | Promise that returns no value.| 502 503**Error codes** 504 505For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 506 507| **ID**| **Error Message** | 508|-----------|---------------------| 509| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 510| 801 | Capability not supported. | 511| 14800000 | Inner error. | 512| 14800010 | Failed to open or delete the database by an invalid database path. | 513| 14801001 | The operation is supported in the stage model only. | 514| 14801002 | Invalid data group ID. | 515 516**Example** 517 518FA model: 519 520<!--code_no_check_fa--> 521```js 522import { featureAbility } from "@kit.AbilityKit"; 523import { BusinessError } from '@kit.BasicServicesKit'; 524 525let store: relationalStore.RdbStore | undefined = undefined; 526let context = featureAbility.getContext(); 527 528const STORE_CONFIG: relationalStore.StoreConfig = { 529 name: "RdbTest.db", 530 securityLevel: relationalStore.SecurityLevel.S3 531}; 532 533relationalStore.deleteRdbStore(context, STORE_CONFIG).then(() => { 534 store = undefined; 535 console.info('Delete RdbStore successfully.'); 536}).catch((err: BusinessError) => { 537 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 538}); 539``` 540 541Stage model: 542 543```ts 544import { UIAbility } from '@kit.AbilityKit'; 545import { window } from '@kit.ArkUI'; 546import { BusinessError } from '@kit.BasicServicesKit'; 547 548let store: relationalStore.RdbStore | undefined = undefined; 549 550class EntryAbility extends UIAbility { 551 onWindowStageCreate(windowStage: window.WindowStage) { 552 const STORE_CONFIG: relationalStore.StoreConfig = { 553 name: "RdbTest.db", 554 securityLevel: relationalStore.SecurityLevel.S3 555 }; 556 relationalStore.deleteRdbStore(this.context, STORE_CONFIG).then(() => { 557 store = undefined; 558 console.info('Delete RdbStore successfully.'); 559 }).catch((err: BusinessError) => { 560 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 561 }); 562 } 563} 564``` 565## relationalStore.isVectorSupported<sup>18+</sup> 566 567isVectorSupported(): boolean 568 569Checks whether the system supports vector stores. 570 571**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 572 573**Return value** 574 575| Type | Description | 576| ------- | ------------------------------------------------- | 577| boolean | Returns **true** if the system supports vector stores; returns **false** otherwise.| 578 579**Example** 580 581``` 582let result = relationalStore.isVectorSupported(); 583``` 584 585## relationalStore.isTokenizerSupported<sup>18+</sup> 586 587isTokenizerSupported(tokenizer: Tokenizer): boolean 588 589Checks whether the specified tokenizer is supported. This API returns the result synchronously. 590 591This API returns **true** if the specified tokenizer is supported; returns **false** otherwise. 592 593**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 594 595**Parameters** 596 597| Name | Type | Mandatory| Description | 598| ------- | --------------------- | ---- | ------------------------------------------------------------ | 599| tokenizer | [Tokenizer](#tokenizer17) | Yes | Tokenizer to check.| 600 601**Return value** 602 603| Type | Description | 604| ------------------- | ------------------------- | 605| boolean | Returns **true** if the specified tokenizer is supported; returns **false** otherwise.| 606 607**Error codes** 608 609For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 610 611| **ID**| **Error Message** | 612|-----------|---------------------| 613| 401 | Parameter error. Possible causes: Incorrect parameter types. | 614 615 616**Example** 617 618```ts 619import { relationalStore } from '@kit.ArkData'; // Import the relationalStore module. 620 621let customType = relationalStore.Tokenizer.CUSTOM_TOKENIZER; 622let customTypeSupported = relationalStore.isTokenizerSupported(customType); 623console.info("custom tokenizer supported on current platform: " + customTypeSupported); 624``` 625 626## StoreConfig 627 628Defines the RDB store configuration. 629 630| Name | Type | Mandatory| Description | 631| ------------- | ------------- | ---- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 632| name | string | Yes | Database file name, which is the unique identifier of the database.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 633| securityLevel | [SecurityLevel](#securitylevel) | Yes | Security level of the RDB store.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 634| encrypt | boolean | No | Whether to encrypt the RDB store.<br> **true**: encrypt the RDB store.<br> **false** (default): not encrypt the RDB store.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 635| dataGroupId<sup>10+</sup> | string | No| Application group ID. <!--RP1-->Currently, this parameter is not supported.<!--RP1End--><br>**Model restriction**: This parameter can be used only in the stage model.<br>This parameter is supported since API version 10. If **dataGroupId** is specified, the **RdbStore** instance will be created in the sandbox directory of the specified **dataGroupId**. However, the encrypted RDB store in this sandbox directory does not support multi-process access. If this parameter is left blank, the **RdbStore** instance will be created in the sandbox directory of the application by default.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 636| 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. Since API version 18, if the **rootDir** parameter is also configured, the RDB store in the following directory will be opened or deleted: rootDir + "/" + customDir + "/" + name.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 637| rootDir<sup>18+</sup> | string | No| Root path of the database.<br>This parameter is supported since API version 18. The database in the **rootDir** + "/" + **customDir** directory will be opened or deleted. The database opened is read-only. Writing data to a read-only database will trigger error 801. If this parameter is set when you want to open or delete an RDB store, ensure that the database file exists in the corresponding path and the caller has the read permission. Otherwise, error 14800010 will be returned.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 638| 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. <br>Default value: **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 | 639| allowRebuild<sup>12+</sup> | boolean | No| Whether to automatically delete the RDB store and create an empty table in the case of an exception.<br>**true**: delete the RDB store and create an empty table in the case of an exception.<br>**false** (default): not delete the RDB store in the case of an exception.<br>This parameter is supported since API version 12.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 640| isReadOnly<sup>12+</sup> | boolean | No| Whether the RDB store is read-only.<br>**true**: The RDB store is read-only. Writing data to the RDB store will result in error code 801.<br>**false** (default): The RDB store is readable and writeable.<br>This parameter is supported since API version 12.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 641| pluginLibs<sup>12+</sup> | Array\<string> | No| Dynamic libraries with capabilities such as Full-Text Search (FTS).<br>**Constraints**<br>1. The maximum number of dynamic library names is 16. If the number of dynamic library names exceeds 16, the library fails to be opened and an error is returned.<br>2. The dynamic libraries must be those in the sandbox directory or system directory of the application. If a dynamic library fails to be loaded, the RDB store cannot be opened and an error will be returned.<br>3. The dynamic library name must be a complete path that can be loaded by SQLite.<br>Example: [context.bundleCodeDir + "/libs/arm64/" + libtokenizer.so], where **context.bundleCodeDir** indicates the application sandbox path, **/libs/arm64/** is the subdirectory, **libtokenizer.so** indicates the file name of the dynamic library. If this parameter is left blank, dynamic libraries are not loaded by default.<br>4. The dynamic library must contain all its dependencies to prevent the failure caused by the lack of dependencies.<br>For example, in an NDK project, the default compilation parameters are used to build **libtokenizer.so**, which depends on the C++ standard library. When the dynamic library is loaded, **libc++_shared.so** is linked by mistake because the namespace is different from that during compilation. As a result, the **__emutls_get_address** symbol cannot be found. To solve this problem, you need to statically link the C++ standard library during compilation. For details, see [NDK Project Building Overview](../../napi/build-with-ndk-overview.md).<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 642| cryptoParam<sup>14+</sup> | [CryptoParam](#cryptoparam14) | No| Custom encryption parameters.<br>If this parameter is left empty, the default encryption parameters are used. For details, see default values of [CryptoParam](#cryptoparam14).<br>This parameter is valid only when **encrypt** is **true**.<br>This parameter is supported since API version 14.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 643| vector<sup>18+</sup> | boolean | No| Whether the RDB store is a vector store. The value **true** means the RDB store is a vector store, and the value **false** means the opposite.<br>Default value: **false**.<br>The vector store is ideal for storing and managing high-dimensional vector data, while the relational database is optimal for storing and processing structured data.<br>Before calling **deleteRdbStore**, ensure that the **RdbStore** and **ResultSet** of the vector store have been closed.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 644| tokenizer<sup>17+</sup> | [Tokenizer](#tokenizer17) | No| Type of the tokenizer to be used for FTS.<br>If this parameter is left blank, English tokenization is supported if FTS does not support Chinese or multi-language tokenization.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 645| persist<sup>18+</sup> | boolean | No| Whether to persist the RDB store. The value **true** means to persist the RDB store; **false** means the opposite (using an in-memory database). <br>Default value: **true**.<br>An in-memory database does not support encryption, backup, restore, cross-process access, and distributed capabilities, with the **securityLevel** property ignored.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 646| enableSemanticIndex<sup>20+</sup> | boolean | No| Whether to enable the semantic index processing feature for the database. The value **true** means to enable the semantic index processing feature; **false** means the opposite. The default value is **false**.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 647 648## SecurityLevel 649 650Enumerates the RDB store security levels. Use the enum name rather than the enum value. You cannot change the security level of an RDB store from a higher level to a lower one. 651 652> **NOTE** 653> 654> To perform data sync operations, the RDB store security level must be lower than or equal to that of the peer device. For details, see [Access Control Mechanism in Cross-Device Sync](../../database/sync-app-data-across-devices-overview.md#access-control-mechanism-in-cross-device-sync). 655 656**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 657 658| Name| Value | Description | 659| ---- | ---- | ------------------------------------------------------------ | 660| 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.| 661| 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.| 662| 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.| 663| 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.| 664 665## CryptoParam<sup>14+</sup> 666 667Represents the configuration of database encryption parameters. This parameter is valid only when **encrypt** in **StoreConfig** is **true**. 668 669**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 670 671| Name | Type | Mandatory| Description | 672| ------------- | ------ | ---- | ------------------------------------------------------------ | 673| encryptionKey | Uint8Array | Yes | Key used for database encryption and decryption.<br>If this parameter is not specified, the RDB store generates a key, saves the key, and uses the key to open the database file.<br>If the key is not required, you need to set the key to 0s.| 674| iterationCount | number | No| Number of iterations of the PBKDF2 algorithm used in the RDB store. The value is an integer. <br>Default value: **10000**.<br>The value must be an integer greater than 0. If it is not an integer, the value is rounded down.<br>If this parameter is not specified or is set to **0**, the default value **10000** and the default encryption algorithm **AES_256_GCM** are used.| 675| encryptionAlgo | [EncryptionAlgo](#encryptionalgo14) | No| Algorithm used for database encryption and decryption. <br>Default value: **AES_256_GCM**.| 676| hmacAlgo | [HmacAlgo](#hmacalgo14) | No| HMAC algorithm used for database encryption and decryption. <br>Default value: **SHA256**.| 677| kdfAlgo | [KdfAlgo](#kdfalgo14) | No| PBKDF2 algorithm used for database encryption and decryption. <br>Default value: the same as the HMAC algorithm used.| 678| cryptoPageSize | number | No| Page size used for database encryption and decryption. <br>Default value: **1024** bytes.<br>The value must be an integer within the range of 1024 to 65536 and must be 2<sup>n</sup>. If the specified value is not an integer, the value is rounded down.| 679 680## EncryptionAlgo<sup>14+</sup> 681 682Enumerates the database encryption algorithms. Use the enum name rather than the enum value. 683 684**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 685 686| Name| Value | Description| 687| ---- | ---- | ---- | 688| AES_256_GCM | 0 | AES_256_GCM. | 689| AES_256_CBC | 1 | AES_256_CBC. | 690 691## HmacAlgo<sup>14+</sup> 692 693Enumerates the HMAC algorithms for the database. Use the enum name rather than the enum value. 694 695**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 696 697| Name| Value | Description| 698| ---- | ---- | ---- | 699| SHA1 | 0 | HMAC_SHA1. | 700| SHA256 | 1 | HMAC_SHA256. | 701| SHA512 | 2 | HMAC_SHA512. | 702 703## KdfAlgo<sup>14+</sup> 704 705Enumerates the PBKDF2 algorithms for the database. Use the enum name rather than the enum value. 706 707**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 708 709| Name| Value | Description| 710| ---- | ---- | ---- | 711| KDF_SHA1 | 0 | PBKDF2_HMAC_SHA1. | 712| KDF_SHA256 | 1 | PBKDF2_HMAC_SHA256. | 713| KDF_SHA512 | 2 | PBKDF2_HMAC_SHA512. | 714 715## Tokenizer<sup>17+</sup> 716 717Enumerates tokenizers that can be used for FTS. Use the enum name rather than the enum value. 718 719**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 720 721| Name | Value | Description | 722| ------------------------------- | --- | -------------- | 723| NONE_TOKENIZER | 0 | No tokenizer is used. | 724| ICU_TOKENIZER | 1 | The ICU tokenizer is used, which supports Chinese and multiple languages. If the ICU tokenizer is used, you can set the language to use, for example, **zh_CN** for Chinese and **tr_TR** for Turkish. For details about the supported languages, see [ICU tokenizer](https://gitee.com/openharmony/third_party_icu/blob/master/icu4c/source/data/lang/en.txt). For details about the language abbreviations, see [locales](https://gitee.com/openharmony/third_party_icu/tree/master/icu4c/source/data/locales).| 725| CUSTOM_TOKENIZER<sup>18+</sup> | 2 | A custom tokenizer is used. Chinese (simplified and traditional), English, and Arabic numerals are supported. Compared with **ICU_TOKENIZER**, **CUSTOM_TOKENIZER** has advantages in tokenization accuracy and resident memory usage.| 726 727The table creation statement varies with the tokenizer in use. 728 729**Example** 730 731The following is an example of the table creation statement when **ICU_TOKENIZER** is used: 732 733```ts 734import { relationalStore } from '@kit.ArkData'; // Import the relationalStore module. 735import { UIAbility } from '@kit.AbilityKit'; 736import { BusinessError } from '@kit.BasicServicesKit'; 737import { window } from '@kit.ArkUI'; 738 739// In this example, Ability is used to obtain an RdbStore instance in the stage model. You can use other implementations as required. 740class EntryAbility extends UIAbility { 741 async onWindowStageCreate(windowStage: window.WindowStage) { 742 let store: relationalStore.RdbStore | undefined = undefined; 743 const STORE_CONFIG: relationalStore.StoreConfig = { 744 name: "MyStore.db", 745 securityLevel: relationalStore.SecurityLevel.S3, 746 tokenizer: relationalStore.Tokenizer.ICU_TOKENIZER 747 }; 748 store = await relationalStore.getRdbStore(this.context, STORE_CONFIG); 749 750 const SQL_CREATE_TABLE = "CREATE VIRTUAL TABLE example USING fts4(name, content, tokenize=icu zh_CN)"; 751 if (store != undefined) { 752 (store as relationalStore.RdbStore).executeSql(SQL_CREATE_TABLE, (err) => { 753 if (err) { 754 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 755 return; 756 } 757 console.info('create virtual table done.'); 758 }); 759 } 760 } 761} 762``` 763 764The following is an example of the table creation statement when **CUSTOM_TOKENIZER** is used: 765 766```ts 767import { relationalStore } from '@kit.ArkData'; // Import the relationalStore module. 768import { UIAbility } from '@kit.AbilityKit'; 769import { BusinessError } from '@kit.BasicServicesKit'; 770import { window } from '@kit.ArkUI'; 771 772// In this example, Ability is used to obtain an RdbStore instance in the stage model. You can use other implementations as required. 773class EntryAbility extends UIAbility { 774 async onWindowStageCreate(windowStage: window.WindowStage) { 775 let store: relationalStore.RdbStore | undefined = undefined; 776 const STORE_CONFIG: relationalStore.StoreConfig = { 777 name: "MyStore.db", 778 securityLevel: relationalStore.SecurityLevel.S3, 779 tokenizer: relationalStore.Tokenizer.CUSTOM_TOKENIZER 780 }; 781 store = await relationalStore.getRdbStore(this.context, STORE_CONFIG); 782 783 const SQL_CREATE_TABLE = "CREATE VIRTUAL TABLE example USING fts5(name, content, tokenize='customtokenizer')"; 784 if (store != undefined) { 785 (store as relationalStore.RdbStore).executeSql(SQL_CREATE_TABLE, (err) => { 786 if (err) { 787 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 788 return; 789 } 790 console.info('create virtual table done.'); 791 }); 792 } 793 } 794} 795``` 796 797## AssetStatus<sup>10+</sup> 798 799Enumerates the asset statuses. Use the enum name rather than the enum value. 800 801**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 802 803| Name | Value | Description | 804| ------------------------------- | --- | -------------- | 805| ASSET_NORMAL | 1 | The asset is in normal status. | 806| ASSET_INSERT | 2 | The asset is to be inserted to the cloud.| 807| ASSET_UPDATE | 3 | The asset is to be updated to the cloud.| 808| ASSET_DELETE | 4 | The asset is to be deleted from the cloud.| 809| ASSET_ABNORMAL | 5 | The asset is in abnormal status. | 810| ASSET_DOWNLOADING | 6 | The asset is being downloaded to a local device.| 811 812## Asset<sup>10+</sup> 813 814Defines information about an asset (such as a document, image, and video). 815 816**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 817 818| Name | Type | Mandatory | Description | 819| ----------- | --------------------------- | --- | ------------ | 820| name | string | Yes | Asset name. | 821| uri | string | Yes | Asset URI, which is an absolute path in the system. | 822| path | string | Yes | Application sandbox path of the asset. | 823| createTime | string | Yes | Time when the asset was created. | 824| modifyTime | string | Yes | Time when the asset was last modified.| 825| size | string | Yes | Size of the asset. | 826| status | [AssetStatus](#assetstatus10) | No | Asset status. <br>Default value: **ASSET_NORMAL**. | 827 828## Assets<sup>10+</sup> 829 830type Assets = Asset[] 831 832Defines an array of the [Asset](#asset10) type. 833 834**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 835 836| Type | Description | 837| ------- | -------------------- | 838| [Asset](#asset10)[] | Array of assets. | 839 840## ValueType 841 842type ValueType = null | number | string | boolean | Uint8Array | Asset | Assets | Float32Array | bigint 843 844Enumerates the types of the value in a KV pair. The type varies with the parameter usage. 845 846**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 847 848| Type | Description | 849| ------- | -------------------- | 850| null<sup>10+</sup> | Null. | 851| number | Number. | 852| string | String. | 853| boolean | Boolean.| 854| Uint8Array<sup>10+</sup> | Uint8 array. | 855| Asset<sup>10+</sup> | [Asset](#asset10).<br>If the value type is Asset, the type in the SQL statement for creating a table must be ASSET.| 856| Assets<sup>10+</sup> | [Assets](#assets10).<br>If the value type is Assets, the type in the SQL statement for creating a table must be ASSETS.| 857| 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).| 858| 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.| 859 860## ValuesBucket 861 862type ValuesBucket = Record<string, ValueType> 863 864Defines the data in the form of a KV pair. **ValuesBucket** cannot be passed across threads using Sendable. 865 866**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 867 868| Type | Description | 869| ---------------- | ---------------------------- | 870| 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).| 871 872## PRIKeyType<sup>10+</sup> 873 874type PRIKeyType = number | string 875 876Enumerates the types of the primary key in a row of a database table. 877 878**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 879 880| Type | Description | 881| ---------------- | ---------------------------------- | 882| number | The primary key is a number.| 883| string | The primary key is a string.| 884 885## UTCTime<sup>10+</sup> 886 887type UTCTime = Date 888 889Represents the data type of the UTC time. 890 891**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 892 893| Type| Description | 894| ---- | --------------- | 895| Date | UTC time.| 896 897## ModifyTime<sup>10+</sup> 898 899type ModifyTime = Map<PRIKeyType, UTCTime> 900 901Represents the data type of the primary key and modification time of a database table. 902 903**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 904 905| Type | Description | 906| ------------------------------------------------------- | ------------------------------------------------------------ | 907| 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.| 908 909## SyncMode 910 911Enumerates the database sync modes. Use the enum name rather than the enum value. 912 913| Name | Value | Description | 914| -------------- | ---- | ---------------------------------- | 915| SYNC_MODE_PUSH | 0 | Push data from a local device to a remote device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 916| SYNC_MODE_PULL | 1 | Pull data from a remote device to a local device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 917| SYNC_MODE_TIME_FIRST<sup>10+</sup> | 4 | Synchronize with the data with the latest modification time.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 918| SYNC_MODE_NATIVE_FIRST<sup>10+</sup> | 5 | Synchronize data from a local device to the cloud.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 919| SYNC_MODE_CLOUD_FIRST<sup>10+</sup> | 6 | Synchronize data from the cloud to a local device.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 920 921## Origin<sup>11+</sup> 922 923Enumerates the data sources. Use the enum name rather than the enum value. 924 925**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 926 927| Name | Value | Description | 928| -------------- | ---- | ---------------------------------- | 929| LOCAL | 0 | Local data. | 930| CLOUD | 1 | Cloud data. | 931| REMOTE | 2 | Remote device data.| 932 933## Field<sup>11+</sup> 934 935Enumerates the special fields used in predicates. Use the enum name rather than the enum value. 936 937**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 938 939| Name | Value | Description | 940| -------------- | ---- | ---------------------------------- | 941| CURSOR_FIELD | '#_cursor' | Field name to be searched based on the cursor.| 942| ORIGIN_FIELD | '#_origin' | Data source to be searched based on the cursor. | 943| 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.| 944| 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.| 945| 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.| 946| 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.| 947| SHARING_RESOURCE_FIELD | '#_sharing_resource_field' | Resource shared. It fills in the result set returned when the shared resource is searched.| 948 949## SubscribeType 950 951Enumerates the subscription types. Use the enum name rather than the enum value. 952 953| Name | Value | Description | 954| --------------------- | ---- | ------------------ | 955| SUBSCRIBE_TYPE_REMOTE | 0 | Subscribe to remote data changes.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 956| SUBSCRIBE_TYPE_CLOUD<sup>10+</sup> | 1 | Subscribe to cloud data changes.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 957| SUBSCRIBE_TYPE_CLOUD_DETAILS<sup>10+</sup> | 2 | Subscribe to cloud data change details.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 958| SUBSCRIBE_TYPE_LOCAL_DETAILS<sup>12+</sup> | 3 | Subscribe to details of the local data change.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 959 960## RebuildType<sup>12+</sup> 961 962Enumerates the RDB store rebuild types. Use the enum name rather than the enum value. 963 964**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 965 966| Name | Value | Description | 967| ------- | ---- |----------------------------------------------------------------------------------------------------------------| 968| NONE | 0 | The RDB store is not rebuilt. | 969| REBUILT | 1 | Create an empty database to rebuild the RDB store. You need to create tables and restore data. | 970| REPAIRED | 2 | Restore uncorrupted data of the RDB store. Only [vector stores](#storeconfig) support this feature.| 971 972## ChangeType<sup>10+</sup> 973 974Enumerates data change types. Use the enum name rather than the enum value. 975 976**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 977 978| Name | Value | Description | 979| -------------------------- | --- | -------------------------- | 980| DATA_CHANGE | 0 | Data change. | 981| ASSET_CHANGE | 1 | Asset change.| 982 983## ChangeInfo<sup>10+</sup> 984 985Represents the detail information about the device-cloud sync process. 986 987**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 988 989| Name | Type | Mandatory| Description | 990| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ | 991| table | string | Yes | Name of the table with data changes. | 992| type | [ChangeType](#changetype10) | Yes | Type of the data changed, which can be data or asset. | 993| 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.| 994| 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.| 995| 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.| 996 997## DistributedType<sup>10+</sup> 998 999Enumerates the distributed table types. Use the enum name rather than the enum value. 1000 1001| Name | Value | Description | 1002| ------------------ | --- | -------------------------------------------------------------------------------------------------- | 1003| DISTRIBUTED_DEVICE | 0 | Distributed database table between devices.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 1004| DISTRIBUTED_CLOUD | 1 | Distributed database table between the device and the cloud.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 1005 1006## DistributedConfig<sup>10+</sup> 1007 1008Defines the configuration of the distributed mode of tables. 1009 1010**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1011 1012| Name | Type | Mandatory| Description | 1013| -------- | ------- | ---- | ------------------------------------------------------------ | 1014| 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.| 1015| asyncDownloadAsset<sup>18+</sup> | boolean | No| Whether to download assets synchronously or asynchronously when device-cloud sync is being performed for the current RDB store. The value **true** means to use an asynchronous task to download assets after all data is downloaded. The value **false** means to downloaded assets synchronously. <br>Default value: **false**.| 1016| enableCloud<sup>18+</sup> | boolean | No| Whether to enable device-cloud sync for this RDB store. The value **true** means to enable device-cloud sync; the value **false** means the opposite. <br>Default value: **true**| 1017 1018## ConflictResolution<sup>10+</sup> 1019 1020Defines the resolution to use when a conflict occurs during data insertion or modification. Use the enum name rather than the enum value. 1021 1022**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1023 1024| Name | Value | Description | 1025| -------------------- | ---- | ------------------------------------------------------------ | 1026| ON_CONFLICT_NONE | 0 | No operation is performed.| 1027| ON_CONFLICT_ROLLBACK | 1 | Abort the SQL statement and roll back the current transaction. | 1028| 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.| 1029| 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.| 1030| ON_CONFLICT_IGNORE | 4 | Skip the rows that contain constraint violations and continue to process the subsequent rows of the SQL statement.| 1031| 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.| 1032 1033## Progress<sup>10+</sup> 1034 1035Enumerates the stages in the device-cloud sync progress. Use the enum name rather than the enum value. 1036 1037**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1038 1039| Name | Value | Description | 1040| ---------------- | ---- | ------------------------ | 1041| SYNC_BEGIN | 0 | The device-cloud sync starts. | 1042| SYNC_IN_PROGRESS | 1 | The device-cloud sync is in progress.| 1043| SYNC_FINISH | 2 | The device-cloud sync is complete.| 1044 1045## Statistic<sup>10+</sup> 1046 1047Represents the device-cloud sync statistics information. 1048 1049**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1050 1051| Name | Type | Mandatory| Description | 1052| ---------- | ------ | ---- | ---------------------------------------- | 1053| total | number | Yes | Total number of rows to be synchronized between the device and cloud in the database table. | 1054| successful | number | Yes | Number of rows that are successfully synchronized between the device and cloud in the database table. | 1055| failed | number | Yes | Number of rows that failed to be synchronized between the device and cloud in the database table. | 1056| remained | number | Yes | Number of rows that are not executed for device-cloud sync in the database table.| 1057 1058## TableDetails<sup>10+</sup> 1059 1060Represents the upload and download statistics of device-cloud sync tasks. 1061 1062**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1063 1064| Name | Type | Mandatory| Description | 1065| -------- | ------------------------- | ---- | ------------------------------------------ | 1066| upload | [Statistic](#statistic10) | Yes | Statistics of the device-cloud upload tasks.| 1067| download | [Statistic](#statistic10) | Yes | Statistics of the device-cloud download tasks.| 1068 1069## ProgressCode<sup>10+</sup> 1070 1071Enumerates the device-cloud sync states. Use the enum name rather than the enum value. 1072 1073**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1074 1075| Name | Value | Description | 1076| --------------------- | ---- | ------------------------------------------------------------ | 1077| SUCCESS | 0 | The device-cloud sync is successful. | 1078| UNKNOWN_ERROR | 1 | An unknown error occurs during device-cloud sync. | 1079| NETWORK_ERROR | 2 | A network error occurs during device-cloud sync. | 1080| CLOUD_DISABLED | 3 | The cloud is unavailable. | 1081| 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.| 1082| 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.| 1083| NO_SPACE_FOR_ASSET | 6 | The remaining cloud space is less than the size of the data to be synchronized. | 1084| BLOCKED_BY_NETWORK_STRATEGY<sup>12+</sup> | 7 | The device-cloud sync is blocked due to the network strategy. | 1085 1086## ProgressDetails<sup>10+</sup> 1087 1088Represents the statistics of the overall device-cloud sync (upload and download) tasks. 1089 1090**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1091 1092| Name | Type | Mandatory| Description | 1093| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | 1094| schedule | [Progress](#progress10) | Yes | Device-cloud sync progress. | 1095| code | [ProgressCode](#progresscode10) | Yes | Device-cloud sync state. | 1096| 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.| 1097 1098## SqlExecutionInfo<sup>12+</sup> 1099 1100Represents statistics about SQL statements executed by the database. 1101 1102**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1103 1104| Name | Type | Read-Only| Optional |Description | 1105| -------- | ------------------------------------------------- | ---- | ---- | -------------------------------------------------------- | 1106| 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. | 1107| totalTime<sup>12+</sup> | number | Yes | No | Total time used to execute the SQL statements, in μs. | 1108| waitTime<sup>12+</sup> | number | Yes | No | Time used to obtain the handle, in μs. | 1109| prepareTime<sup>12+</sup> | number | Yes | No | Time used to get the SQL statements ready and bind parameters, in μs. | 1110| executeTime<sup>12+</sup> | number | Yes | No | Total time used to execute the SQL statements, in μs.| 1111 1112## ExceptionMessage<sup>20+</sup> 1113 1114Represents an exception message about the SQL statement executed by the database. 1115 1116**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1117 1118| Name | Type | Read-Only| Optional |Description | 1119| -------- | ------------------------------------------------- | ---- | ---- | -------------------------------------------------------- | 1120| code<sup>20+</sup> | number | Yes | No | Error code returned by the executed SQL statement. For details about the values and meanings, see [SQLite Error Codes](https://www.sqlite.org/rescode.html).| 1121| messgae<sup>20+</sup> | string | Yes | No | Exception message returned by the executed SQL statement. | 1122| sql<sup>20+</sup> | string | Yes | No | SQL statement that reports the error. | 1123 1124## TransactionType<sup>14+</sup> 1125 1126Enumerates the types of transaction objects that can be created. Use the enum name rather than the enum value. 1127 1128**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1129 1130| Name | Value | Description | 1131| ---------------- | ---- | ------------------------ | 1132| DEFERRED | 0 | Deferred transaction object. When a deferred transaction object is created, automatic commit is disabled and no transaction will start. A read or write transaction starts only when the first read or write operation is performed. | 1133| IMMEDIATE | 1 | Immediate transaction object. When an immediate transaction object is created, a write transaction starts. If there is any uncommitted write transaction, the transaction object cannot be created and error 14800024 is returned.| 1134| EXCLUSIVE | 2 | Exclusive transaction object. In WAL mode, the exclusive transaction object is the same as the immediate transaction object. In other log modes, this type of transaction can prevent the database from being read by other connections during the transaction.| 1135 1136## TransactionOptions<sup>14+</sup> 1137 1138Represents the configuration of a transaction object. 1139 1140**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1141 1142| Name | Type | Mandatory| Description | 1143| ------------- | ------------- | ---- | --------------------------------------------------------- | 1144| transactionType | [TransactionType](#transactiontype14) | No | Transaction object type. <br>Default value: **DEFERRED**. | 1145 1146## ColumnType<sup>18+</sup> 1147 1148Enumerates the types of the column data. Use the enum name rather than the enum value. 1149 1150**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1151 1152| Name | Value | Description | 1153| ------------- | ---- | ------------------------------------------------------------ | 1154| NULL | 0 | NULL. | 1155| INTEGER | 1 | 64-bit integer. <br>The column can hold 8-bit (including Boolean values), 16-bit, 32-bit, and 64-bit integers. For the 64-bit integer greater than 2^53 or less than -2^53, use [getString](#getstring) to convert it into a string.| 1156| REAL | 2 | Floating-point number. | 1157| TEXT | 3 | String. | 1158| BLOB | 4 | Uint8Array. | 1159| ASSET | 5 | [Asset](#asset10). | 1160| ASSETS | 6 | [Assets](#assets10). | 1161| FLOAT_VECTOR | 7 | Float32Array. | 1162| UNLIMITED_INT | 8 | bigint. | 1163 1164## RdbPredicates 1165 1166Provides APIs for creating the predicates (condition) for RDB store operations. This class determines whether the conditional expression for the RDB store is true or false. Multiple predicates statements can be concatenated by using **and()** by default. **RdbPredicates** cannot be passed across threads using Sendable. 1167 1168### constructor 1169 1170constructor(name: string) 1171 1172A constructor used to create an **RdbPredicates** object. 1173 1174**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1175 1176**Parameters** 1177 1178| Name| Type | Mandatory| Description | 1179| ------ | ------ | ---- | ------------ | 1180| name | string | Yes | Database table name.| 1181 1182**Error codes** 1183 1184For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1185 1186| **ID**| **Error Message** | 1187| --------- |----------------------------------------------------------------------------------------------------------------| 1188| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1189 1190**Example** 1191 1192```ts 1193let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1194``` 1195 1196### inDevices 1197 1198inDevices(devices: Array<string>): RdbPredicates 1199 1200Creates an **RdbPredicates** object to specify the remote devices to connect during the distributed database sync. 1201 1202> **NOTE** 1203> 1204> **devices** can be obtained by using [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 1205When calling **sync()**, you need to call **inDevices** to specify the devices. If **inDevices** is not used, data will be synced to all devices on the network by default. 1206 1207**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1208 1209**Parameters** 1210 1211| Name | Type | Mandatory| Description | 1212| ------- | ------------------- | ---- | -------------------------- | 1213| devices | Array<string> | Yes | IDs of the remote devices to connect.| 1214 1215**Return value** 1216 1217| Type | Description | 1218| ------------------------------------ | -------------------------- | 1219| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1220 1221**Error codes** 1222 1223For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1224 1225| **ID**| **Error Message** | 1226| --------- |----------------------------------------------------------------------------------------------------------------| 1227| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1228 1229**Example** 1230 1231```ts 1232import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 1233import { BusinessError } from '@kit.BasicServicesKit'; 1234 1235let dmInstance: distributedDeviceManager.DeviceManager; 1236let deviceIds: Array<string> = []; 1237 1238try { 1239 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 1240 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 1241 for (let i = 0; i < devices.length; i++) { 1242 deviceIds[i] = devices[i].networkId!; 1243 } 1244} catch (err) { 1245 let code = (err as BusinessError).code; 1246 let message = (err as BusinessError).message; 1247 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 1248} 1249 1250let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1251predicates.inDevices(deviceIds); 1252``` 1253 1254### inAllDevices 1255 1256inAllDevices(): RdbPredicates 1257 1258Creates an **RdbPredicates** object to specify all remote devices to connect during the distributed database sync. 1259 1260 1261**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1262 1263**Return value** 1264 1265| Type | Description | 1266| ------------------------------------ | -------------------------- | 1267| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1268 1269**Example** 1270 1271```ts 1272let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1273predicates.inAllDevices(); 1274``` 1275 1276### equalTo 1277 1278equalTo(field: string, value: ValueType): RdbPredicates 1279 1280Creates an **RdbPredicates** object to search for the records in the specified column that are equal to the given value. 1281 1282**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1283 1284**Parameters** 1285 1286| Name| Type | Mandatory| Description | 1287| ------ | ----------------------- | ---- | ---------------------- | 1288| field | string | Yes | Column name in the database table. | 1289| value | [ValueType](#valuetype) | Yes | Value to match.| 1290 1291**Return value** 1292 1293| Type | Description | 1294| ------------------------------------ | -------------------------- | 1295| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1296 1297**Error codes** 1298 1299For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1300 1301| **ID**| **Error Message** | 1302| --------- |----------------------------------------------------------------------------------------------------------------| 1303| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1304 1305**Example** 1306 1307```ts 1308// Find all the records in the NAME column where the value is Lisa. 1309let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1310predicates.equalTo("NAME", "Lisa"); 1311``` 1312 1313 1314### notEqualTo 1315 1316notEqualTo(field: string, value: ValueType): RdbPredicates 1317 1318Creates an **RdbPredicates** object to search for the records in the specified column that are not equal to the given value. 1319 1320**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1321 1322**Parameters** 1323 1324| Name| Type | Mandatory| Description | 1325| ------ | ----------------------- | ---- | ---------------------- | 1326| field | string | Yes | Column name in the database table. | 1327| value | [ValueType](#valuetype) | Yes | Value to match.| 1328 1329**Return value** 1330 1331| Type | Description | 1332| ------------------------------------ | -------------------------- | 1333| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1334 1335**Error codes** 1336 1337For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1338 1339| **ID**| **Error Message** | 1340| --------- |----------------------------------------------------------------------------------------------------------------| 1341| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1342 1343**Example** 1344 1345```ts 1346// Find all the records in the NAME column where the value is not Lisa. 1347let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1348predicates.notEqualTo("NAME", "Lisa"); 1349``` 1350 1351 1352### beginWrap 1353 1354beginWrap(): RdbPredicates 1355 1356Creates an **RdbPredicates** object to add a left parenthesis. 1357 1358**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1359 1360**Return value** 1361 1362| Type | Description | 1363| ------------------------------------ | ------------------------- | 1364| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1365 1366**Example** 1367 1368```ts 1369let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1370predicates.equalTo("NAME", "Lisa") 1371 .beginWrap() 1372 .equalTo("AGE", 18) 1373 .or() 1374 .equalTo("SALARY", 200.5) 1375 .endWrap(); 1376``` 1377 1378### endWrap 1379 1380endWrap(): RdbPredicates 1381 1382Creates an **RdbPredicates** object to add a right parenthesis. 1383 1384**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1385 1386**Return value** 1387 1388| Type | Description | 1389| ------------------------------------ | ------------------------- | 1390| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1391 1392**Example** 1393 1394```ts 1395let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1396predicates.equalTo("NAME", "Lisa") 1397 .beginWrap() 1398 .equalTo("AGE", 18) 1399 .or() 1400 .equalTo("SALARY", 200.5) 1401 .endWrap(); 1402``` 1403 1404### or 1405 1406or(): RdbPredicates 1407 1408Creates an **RdbPredicates** object to add the OR condition. 1409 1410**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1411 1412**Return value** 1413 1414| Type | Description | 1415| ------------------------------------ | ------------------------- | 1416| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1417 1418**Example** 1419 1420```ts 1421// Find all records in the NAME column where the value is Lisa or Rose. 1422let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1423predicates.equalTo("NAME", "Lisa") 1424 .or() 1425 .equalTo("NAME", "Rose"); 1426``` 1427 1428### and 1429 1430and(): RdbPredicates 1431 1432Creates an **RdbPredicates** object to add the AND condition. 1433 1434**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1435 1436**Return value** 1437 1438| Type | Description | 1439| ------------------------------------ | ------------------------- | 1440| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1441 1442**Example** 1443 1444```ts 1445// Find the records in the EMPLOYEE table where the NAME column is Lisa and the SALARY column is 200.5. 1446let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1447predicates.equalTo("NAME", "Lisa") 1448 .and() 1449 .equalTo("SALARY", 200.5); 1450``` 1451 1452### contains 1453 1454contains(field: string, value: string): RdbPredicates 1455 1456Creates an **RdbPredicates** object to search for the records in the specified column that contain the given value. 1457 1458**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1459 1460**Parameters** 1461 1462| Name| Type | Mandatory| Description | 1463| ------ | ------ | ---- | ---------------------- | 1464| field | string | Yes | Column name in the database table. | 1465| value | string | Yes | Value to match.| 1466 1467**Return value** 1468 1469| Type | Description | 1470| ------------------------------------ | -------------------------- | 1471| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1472 1473**Error codes** 1474 1475For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1476 1477| **ID**| **Error Message** | 1478| --------- |----------------------------------------------------------------------------------------------------------------| 1479| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1480 1481**Example** 1482 1483```ts 1484// Find all the records that contain the string 'os' in the NAME column. 1485let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1486predicates.contains("NAME", "os"); 1487``` 1488 1489### beginsWith 1490 1491beginsWith(field: string, value: string): RdbPredicates 1492 1493Creates an **RdbPredicates** object to search for the records in the specified column that begin with the given value. 1494 1495**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1496 1497**Parameters** 1498 1499| Name| Type | Mandatory| Description | 1500| ------ | ------ | ---- | ---------------------- | 1501| field | string | Yes | Column name in the database table. | 1502| value | string | Yes | Value to match.| 1503 1504**Return value** 1505 1506| Type | Description | 1507| ------------------------------------ | -------------------------- | 1508| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1509 1510**Error codes** 1511 1512For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1513 1514| **ID**| **Error Message** | 1515| --------- |----------------------------------------------------------------------------------------------------------------| 1516| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1517 1518**Example** 1519 1520```ts 1521// Find all the records that start with "Li" in the NAME column, for example, Lisa. 1522let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1523predicates.beginsWith("NAME", "Li"); 1524``` 1525 1526### endsWith 1527 1528endsWith(field: string, value: string): RdbPredicates 1529 1530Creates an **RdbPredicates** object to search for the records in the specified column that end with the given value. 1531 1532**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1533 1534**Parameters** 1535 1536| Name| Type | Mandatory| Description | 1537| ------ | ------ | ---- | ---------------------- | 1538| field | string | Yes | Column name in the database table. | 1539| value | string | Yes | Value to match.| 1540 1541**Return value** 1542 1543| Type | Description | 1544| ------------------------------------ | -------------------------- | 1545| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1546 1547**Error codes** 1548 1549For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1550 1551| **ID**| **Error Message** | 1552| --------- |----------------------------------------------------------------------------------------------------------------| 1553| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1554 1555**Example** 1556 1557```ts 1558// Find all the records that end with "se" in the NAME column, for example, Rose. 1559let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1560predicates.endsWith("NAME", "se"); 1561``` 1562 1563### isNull 1564 1565isNull(field: string): RdbPredicates 1566 1567Creates an **RdbPredicates** object to search for the records in the specified column that are **null**. 1568 1569**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1570 1571**Parameters** 1572 1573| Name| Type | Mandatory| Description | 1574| ------ | ------ | ---- | ------------------ | 1575| field | string | Yes | Column name in the database table.| 1576 1577**Return value** 1578 1579| Type | Description | 1580| ------------------------------------ | -------------------------- | 1581| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1582 1583**Error codes** 1584 1585For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1586 1587| **ID**| **Error Message** | 1588| --------- |----------------------------------------------------------------------------------------------------------------| 1589| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1590 1591**Example** 1592 1593```ts 1594let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1595predicates.isNull("NAME"); 1596``` 1597 1598### isNotNull 1599 1600isNotNull(field: string): RdbPredicates 1601 1602Creates an **RdbPredicates** object to search for the records in the specified column that are not **null**. 1603 1604**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1605 1606**Parameters** 1607 1608| Name| Type | Mandatory| Description | 1609| ------ | ------ | ---- | ------------------ | 1610| field | string | Yes | Column name in the database table.| 1611 1612**Return value** 1613 1614| Type | Description | 1615| ------------------------------------ | -------------------------- | 1616| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1617 1618**Error codes** 1619 1620For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1621 1622| **ID**| **Error Message** | 1623| --------- |----------------------------------------------------------------------------------------------------------------| 1624| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1625 1626**Example** 1627 1628```ts 1629let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1630predicates.isNotNull("NAME"); 1631``` 1632 1633### like 1634 1635like(field: string, value: string): RdbPredicates 1636 1637Creates an **RdbPredicates** object to search for the records in the specified column that are similar to the given value. 1638 1639**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1640 1641**Parameters** 1642 1643| Name| Type | Mandatory| Description | 1644| ------ | ------ | ---- | ---------------------- | 1645| field | string | Yes | Column name in the database table. | 1646| value | string | Yes | Value to match.| 1647 1648**Return value** 1649 1650| Type | Description | 1651| ------------------------------------ | -------------------------- | 1652| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1653 1654**Error codes** 1655 1656For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1657 1658| **ID**| **Error Message** | 1659| --------- |----------------------------------------------------------------------------------------------------------------| 1660| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1661 1662**Example** 1663 1664```ts 1665// Find all the records that are similar to "os" in the NAME column, for example, Rose. 1666let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1667predicates.like("NAME", "%os%"); 1668``` 1669 1670### glob 1671 1672glob(field: string, value: string): RdbPredicates 1673 1674Creates an **RdbPredicates** object to search for the records in the specified column that match the given string. 1675 1676**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1677 1678**Parameters** 1679 1680| Name| Type | Mandatory| Description | 1681| ------ | ------ | ---- | ------------------------------------------------------------ | 1682| field | string | Yes | Column name in the database table. | 1683| value | string | Yes | Value to match.<br><br>Wildcards are supported. * indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character.| 1684 1685**Return value** 1686 1687| Type | Description | 1688| ------------------------------------ | -------------------------- | 1689| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1690 1691**Error codes** 1692 1693For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1694 1695| **ID**| **Error Message** | 1696| --------- |----------------------------------------------------------------------------------------------------------------| 1697| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1698 1699**Example** 1700 1701```ts 1702// Find the strings that match "?h*g" in the NAME column. 1703let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1704predicates.glob("NAME", "?h*g"); 1705``` 1706 1707### between 1708 1709between(field: string, low: ValueType, high: ValueType): RdbPredicates 1710 1711Creates an **RdbPredicates** object to search for the records that are within the given range (including the min. and max. values) in the specified column. 1712 1713**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1714 1715**Parameters** 1716 1717| Name| Type | Mandatory| Description | 1718| ------ | ----------------------- | ---- | -------------------------- | 1719| field | string | Yes | Column name in the database table. | 1720| low | [ValueType](#valuetype) | Yes | Minimum value of the range to set. | 1721| high | [ValueType](#valuetype) | Yes | Maximum value of the range to set.| 1722 1723**Return value** 1724 1725| Type | Description | 1726| ------------------------------------ | -------------------------- | 1727| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1728 1729**Error codes** 1730 1731For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1732 1733| **ID**| **Error Message** | 1734| --------- |----------------------------------------------------------------------------------------------------------------| 1735| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1736 1737**Example** 1738 1739```ts 1740// Find the records that are greater than or equal to 10 and less than or equal to 50 in the AGE column. 1741let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1742predicates.between("AGE", 10, 50); 1743``` 1744 1745### notBetween 1746 1747notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates 1748 1749Creates an **RdbPredicates** object to search for the records that are out of the given range (excluding the min. and max. values) in the specified column. 1750 1751**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1752 1753**Parameters** 1754 1755| Name| Type | Mandatory| Description | 1756| ------ | ----------------------- | ---- | -------------------------- | 1757| field | string | Yes | Column name in the database table. | 1758| low | [ValueType](#valuetype) | Yes | Minimum value of the range to set. | 1759| high | [ValueType](#valuetype) | Yes | Maximum value of the range to set.| 1760 1761**Return value** 1762 1763| Type | Description | 1764| ------------------------------------ | -------------------------- | 1765| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1766 1767**Error codes** 1768 1769For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1770 1771| **ID**| **Error Message** | 1772| --------- |----------------------------------------------------------------------------------------------------------------| 1773| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1774 1775**Example** 1776 1777```ts 1778// Find the records that are less than 10 or greater than 50 in the AGE column. 1779let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1780predicates.notBetween("AGE", 10, 50); 1781``` 1782 1783### greaterThan 1784 1785greaterThan(field: string, value: ValueType): RdbPredicates 1786 1787Creates an **RdbPredicates** object to search for the records that are greater than the given value in the specified column. 1788 1789**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1790 1791**Parameters** 1792 1793| Name| Type | Mandatory| Description | 1794| ------ | ----------------------- | ---- | ---------------------- | 1795| field | string | Yes | Column name in the database table. | 1796| value | [ValueType](#valuetype) | Yes | Value to match.| 1797 1798**Return value** 1799 1800| Type | Description | 1801| ------------------------------------ | -------------------------- | 1802| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1803 1804**Error codes** 1805 1806For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1807 1808| **ID**| **Error Message** | 1809| --------- |----------------------------------------------------------------------------------------------------------------| 1810| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1811 1812**Example** 1813 1814```ts 1815// Find all the records that are greater than 18 in the AGE column. 1816let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1817predicates.greaterThan("AGE", 18); 1818``` 1819 1820### lessThan 1821 1822lessThan(field: string, value: ValueType): RdbPredicates 1823 1824Creates an **RdbPredicates** object to search for the records that are less than the given value in the specified column. 1825 1826**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1827 1828**Parameters** 1829 1830| Name| Type | Mandatory| Description | 1831| ------ | ----------------------- | ---- | ---------------------- | 1832| field | string | Yes | Column name in the database table. | 1833| value | [ValueType](#valuetype) | Yes | Value to match.| 1834 1835**Return value** 1836 1837| Type | Description | 1838| ------------------------------------ | -------------------------- | 1839| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1840 1841**Error codes** 1842 1843For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1844 1845| **ID**| **Error Message** | 1846| --------- |----------------------------------------------------------------------------------------------------------------| 1847| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1848 1849**Example** 1850 1851```ts 1852// Find all the records that are less than 20 in the AGE column. 1853let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1854predicates.lessThan("AGE", 20); 1855``` 1856 1857### greaterThanOrEqualTo 1858 1859greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1860 1861Creates an **RdbPredicates** object to search for the records that are greater than or equal to the given value in the specified column. 1862 1863**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1864 1865**Parameters** 1866 1867| Name| Type | Mandatory| Description | 1868| ------ | ----------------------- | ---- | ---------------------- | 1869| field | string | Yes | Column name in the database table. | 1870| value | [ValueType](#valuetype) | Yes | Value to match.| 1871 1872**Return value** 1873 1874| Type | Description | 1875| ------------------------------------ | -------------------------- | 1876| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1877 1878**Error codes** 1879 1880For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1881 1882| **ID**| **Error Message** | 1883| --------- |----------------------------------------------------------------------------------------------------------------| 1884| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1885 1886**Example** 1887 1888```ts 1889// Find all the records that are greater than or equal to 18 in the AGE column. 1890let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1891predicates.greaterThanOrEqualTo("AGE", 18); 1892``` 1893 1894### lessThanOrEqualTo 1895 1896lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1897 1898Creates an **RdbPredicates** object to search for the records that are less than or equal to the given value in the specified column. 1899 1900**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1901 1902**Parameters** 1903 1904| Name| Type | Mandatory| Description | 1905| ------ | ----------------------- | ---- | ---------------------- | 1906| field | string | Yes | Column name in the database table. | 1907| value | [ValueType](#valuetype) | Yes | Value to match.| 1908 1909**Return value** 1910 1911| Type | Description | 1912| ------------------------------------ | -------------------------- | 1913| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1914 1915**Error codes** 1916 1917For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1918 1919| **ID**| **Error Message** | 1920| --------- |----------------------------------------------------------------------------------------------------------------| 1921| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1922 1923**Example** 1924 1925```ts 1926// Find all the records that are less than or equal to 20 in the AGE column. 1927let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1928predicates.lessThanOrEqualTo("AGE", 20); 1929``` 1930 1931### orderByAsc 1932 1933orderByAsc(field: string): RdbPredicates 1934 1935Creates an **RdbPredicates** object to sort the records in the specified column in ascending order. 1936 1937**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1938 1939**Parameters** 1940 1941| Name| Type | Mandatory| Description | 1942| ------ | ------ | ---- | ------------------ | 1943| field | string | Yes | Column name in the database table.| 1944 1945**Return value** 1946 1947| Type | Description | 1948| ------------------------------------ | -------------------------- | 1949| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1950 1951**Error codes** 1952 1953For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1954 1955| **ID**| **Error Message** | 1956| --------- |----------------------------------------------------------------------------------------------------------------| 1957| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1958 1959**Example** 1960 1961```ts 1962let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1963predicates.orderByAsc("NAME"); 1964``` 1965 1966### orderByDesc 1967 1968orderByDesc(field: string): RdbPredicates 1969 1970Creates an **RdbPredicates** object to sort the records in the specified column in descending order. 1971 1972**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1973 1974**Parameters** 1975 1976| Name| Type | Mandatory| Description | 1977| ------ | ------ | ---- | ------------------ | 1978| field | string | Yes | Column name in the database table.| 1979 1980**Return value** 1981 1982| Type | Description | 1983| ------------------------------------ | -------------------------- | 1984| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1985 1986**Error codes** 1987 1988For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1989 1990| **ID**| **Error Message** | 1991| --------- |----------------------------------------------------------------------------------------------------------------| 1992| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1993 1994**Example** 1995 1996```ts 1997let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1998predicates.orderByDesc("AGE"); 1999``` 2000 2001### distinct 2002 2003distinct(): RdbPredicates 2004 2005Creates an **RdbPredicates** object to filter out duplicate records. 2006 2007**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2008 2009**Return value** 2010 2011| Type | Description | 2012| ------------------------------------ | ------------------------------ | 2013| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.| 2014 2015**Example** 2016 2017```ts 2018let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2019predicates.equalTo("NAME", "Rose").distinct(); // Deduplicate result sets whose NAME is Rose. 2020``` 2021 2022### limitAs 2023 2024limitAs(value: number): RdbPredicates 2025 2026Creates an **RdbPredicates** object to limit the number of data records. 2027 2028**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2029 2030**Parameters** 2031 2032| Name| Type | Mandatory| Description | 2033| ------ | ------ | ---- | ---------------- | 2034| value | number | Yes | Maximum number of data records. The value should be a positive integer. If a value less than or equal to **0** is specified, the number of records is not limited.| 2035 2036**Return value** 2037 2038| Type | Description | 2039| ------------------------------------ | ------------------------------------ | 2040| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.| 2041 2042**Error codes** 2043 2044For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2045 2046| **ID**| **Error Message** | 2047| --------- |--------------------------| 2048| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2049 2050**Example** 2051 2052```ts 2053let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2054predicates.equalTo("NAME", "Rose").limitAs(3); 2055``` 2056 2057### offsetAs 2058 2059offsetAs(rowOffset: number): RdbPredicates 2060 2061Creates an **RdbPredicates** object to set the start position of the query result. This API must be used together with **limitAs**. Otherwise, no result will be returned. To query all rows after the specified offset, pass in a parameter less than or equal to **0** in **limitAs**. 2062 2063**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2064 2065**Parameters** 2066 2067| Name | Type | Mandatory| Description | 2068| --------- | ------ | ---- | ---------------------------------- | 2069| rowOffset | number | Yes | Start position of the query result. By default, the start position is the beginning of the result set. If **rowOffset** is a negative number, the start position is the beginning of the result set. If **rowOffset** exceeds the end of the result set, the query result is empty.| 2070 2071**Return value** 2072 2073| Type | Description | 2074| ------------------------------------ | ------------------------------------ | 2075| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the query result.| 2076 2077**Error codes** 2078 2079For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2080 2081| **ID**| **Error Message** | 2082| --------- |----------------------------------------------------------------------------------------------------------------| 2083| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2084 2085**Example** 2086 2087```ts 2088let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2089predicates.equalTo("NAME", "Rose").limitAs(-1).offsetAs(3); 2090``` 2091 2092### groupBy 2093 2094groupBy(fields: Array<string>): RdbPredicates 2095 2096Creates an **RdbPredicates** object to group the query results based on the specified columns. 2097 2098**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2099 2100**Parameters** 2101 2102| Name| Type | Mandatory| Description | 2103| ------ | ------------------- | ---- | -------------------- | 2104| fields | Array<string> | Yes | Names of columns to group.| 2105 2106**Return value** 2107 2108| Type | Description | 2109| ------------------------------------ | ---------------------- | 2110| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2111 2112**Error codes** 2113 2114For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2115 2116| **ID**| **Error Message** | 2117| --------- |----------------------------------------------------------------------------------------------------------------| 2118| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2119 2120**Example** 2121 2122```ts 2123let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2124predicates.groupBy(["AGE", "NAME"]); 2125``` 2126 2127### indexedBy 2128 2129indexedBy(field: string): RdbPredicates 2130 2131Creates an **RdbPredicates** object to specify the index column. 2132 2133**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2134 2135**Parameters** 2136 2137| Name| Type | Mandatory| Description | 2138| ------ | ------ | ---- | -------------- | 2139| field | string | Yes | Name of the index column.| 2140 2141**Return value** 2142 2143 2144| Type | Description | 2145| ------------------------------------ | ------------------------------------- | 2146| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2147 2148**Error codes** 2149 2150For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2151 2152| **ID**| **Error Message** | 2153| --------- |----------------------------------------------------------------------------------------------------------------| 2154| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2155 2156**Example** 2157 2158```ts 2159let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2160predicates.indexedBy("SALARY"); 2161``` 2162 2163### in 2164 2165in(field: string, value: Array<ValueType>): RdbPredicates 2166 2167Creates an **RdbPredicates** object to search for the records that are in the given range in the specified column. 2168 2169**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2170 2171**Parameters** 2172 2173| Name| Type | Mandatory| Description | 2174| ------ | ------------------------------------ | ---- | --------------------------------------- | 2175| field | string | Yes | Column name in the database table. | 2176| value | Array<[ValueType](#valuetype)> | Yes | Array of **ValueType**s to match.| 2177 2178**Return value** 2179 2180| Type | Description | 2181| ------------------------------------ | -------------------------- | 2182| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2183 2184**Error codes** 2185 2186For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2187 2188| **ID**| **Error Message** | 2189| --------- |----------------------------------------------------------------------------------------------------------------| 2190| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2191 2192**Example** 2193 2194```ts 2195// Find records that are within [18, 20] in the AGE column. 2196let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2197predicates.in("AGE", [18, 20]); 2198``` 2199 2200### notIn 2201 2202notIn(field: string, value: Array<ValueType>): RdbPredicates 2203 2204Creates an **RdbPredicates** object to search for the records that are out of the given range in the specified column. 2205 2206**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2207 2208**Parameters** 2209 2210| Name| Type | Mandatory| Description | 2211| ------ | ------------------------------------ | ---- | ------------------------------------- | 2212| field | string | Yes | Column name in the database table. | 2213| value | Array<[ValueType](#valuetype)> | Yes | Array of **ValueType**s to match.| 2214 2215**Return value** 2216 2217| Type | Description | 2218| ------------------------------------ | -------------------------- | 2219| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2220 2221**Error codes** 2222 2223For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2224 2225| **ID**| **Error Message** | 2226| --------- |----------------------------------------------------------------------------------------------------------------| 2227| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2228 2229**Example** 2230 2231```ts 2232// Find the records that are not within [Lisa, Rose] in the NAME column. 2233let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2234predicates.notIn("NAME", ["Lisa", "Rose"]); 2235``` 2236 2237### notContains<sup>12+</sup> 2238 2239notContains(field: string, value: string): RdbPredicates 2240 2241Creates an **RdbPredicates** object to search for the records that do not contain the given value in the specified column. 2242 2243**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2244 2245**Parameters** 2246 2247| Name| Type | Mandatory| Description | 2248| ------ | ------ | ---- | ---------------------- | 2249| field | string | Yes | Column name in the database table. | 2250| value | string | Yes | Value to match.| 2251 2252**Return value** 2253 2254| Type | Description | 2255| ------------------------------- | -------------------------- | 2256| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2257 2258**Error codes** 2259 2260For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2261 2262| **ID**| **Error Message** | 2263| --------- |----------------------------------------------------------------------------------------------------------------| 2264| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2265 2266**Example** 2267 2268```ts 2269// Find the records that do not contain the string "os" in the NAME column, for example, Lisa. 2270let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2271predicates.notContains("NAME", "os"); 2272``` 2273 2274### notLike<sup>12+</sup> 2275 2276notLike(field: string, value: string): RdbPredicates 2277 2278Creates an **RdbPredicates** object to search for the records that are not similar to the given value in the specified column. 2279 2280**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2281 2282**Parameters** 2283 2284| Name| Type | Mandatory| Description | 2285| ------ | ------ | ---- | ---------------------- | 2286| field | string | Yes | Column name in the database table. | 2287| value | string | Yes | Value to match.| 2288 2289**Return value** 2290 2291| Type | Description | 2292| ------------------------------- | -------------------------- | 2293| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2294 2295**Error codes** 2296 2297For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2298 2299| **ID**| **Error Message** | 2300| --------- |----------------------------------------------------------------------------------------------------------------| 2301| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2302 2303**Example** 2304 2305```ts 2306// Find the records that are not "os" in the NAME column, for example, Rose. 2307let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2308predicates.notLike("NAME", "os"); 2309``` 2310 2311### having<sup>20+</sup> 2312 2313having(conditions:string, args?: Array\<ValueType>): RdbPredicates 2314 2315Filters for group data that meets the conditions. 2316 2317**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2318 2319**Parameters** 2320 2321| Name| Type | Mandatory| Description | 2322| ------ | ------ | ---- | ---------------------- | 2323| conditions | string | Yes | Condition used to filter the data obtained using [groupBy](#groupby). This parameter cannot be empty and must be used with [groupBy](#groupby).| 2324| args | Array<[ValueType](#valuetype)> | No | Parameters used in **conditions**, which replace the placeholder in the conditional statement. If this parameter is not specified, the default value is an empty array.| 2325 2326**Return value** 2327 2328| Type | Description | 2329| ------------------------------- | -------------------------- | 2330| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2331 2332**Error codes** 2333 2334For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2335 2336| **ID**| **Error Message** | 2337| --------- |----------------------------------------------------------------------------------------------------------------| 2338| 14800001 | Invalid args. Possible causes: 1. conditions are empty; 2. missing GROUP BY clause. | 2339 2340**Example 1:** 2341 2342```ts 2343// Pass a complete condition. 2344let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2345predicates.groupBy(["AGE"]); 2346predicates.having("NAME = zhangsan"); 2347``` 2348**Example 2:** 2349 2350```ts 2351// Use placeholders in the condition and pass values to args to replace the placeholders. 2352let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2353predicates.groupBy(["AGE"]); 2354predicates.having("NAME = ?", ["zhangsan"]); 2355``` 2356 2357## RdbStore 2358 2359Provides APIs for managing data in an RDB store. 2360 2361Before using the APIs of this class, use [executeSql](#executesql) to initialize the database table structure and related data. 2362 2363### Properties 2364 2365**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2366 2367| Name | Type | Read-Only | Optional| Description | 2368| ------------ | ----------- | ---- | -------------------------------- | -------------------------------- | 2369| version<sup>10+</sup> | number | No| No | RDB store version, which is an integer greater than 0. | 2370| rebuilt<sup>12+</sup> | [RebuildType](#rebuildtype12) | Yes| No| Whether the RDB store has been rebuilt or repaired.| 2371 2372**Error codes** 2373 2374For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 2375 2376| **ID**| **Error Message** | 2377|-----------| ------------------------------------------------------------ | 2378| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2379| 801 | Capability not supported. | 2380| 14800000 | Inner error. | 2381| 14800014 | The RdbStore or ResultSet is already closed. | 2382| 14800015 | The database does not respond. | 2383| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 2384| 14800023 | SQLite: Access permission denied. | 2385| 14800024 | SQLite: The database file is locked. | 2386| 14800025 | SQLite: A table in the database is locked. | 2387| 14800026 | SQLite: The database is out of memory. | 2388| 14800027 | SQLite: Attempt to write a readonly database. | 2389| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2390| 14800029 | SQLite: The database is full. | 2391| 14800030 | SQLite: Unable to open the database file. | 2392 2393**Example** 2394 2395```ts 2396// Set the RDB store version. 2397import { UIAbility } from '@kit.AbilityKit'; 2398import { BusinessError } from '@kit.BasicServicesKit'; 2399import { window } from '@kit.ArkUI'; 2400 2401let store: relationalStore.RdbStore | undefined = undefined; 2402 2403class EntryAbility extends UIAbility { 2404 onWindowStageCreate(windowStage: window.WindowStage) { 2405 const STORE_CONFIG: relationalStore.StoreConfig = { 2406 name: "RdbTest.db", 2407 securityLevel: relationalStore.SecurityLevel.S3 2408 }; 2409 const SQL_CREATE_TABLE = 'CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB, IDENTITY UNLIMITED INT, ASSETDATA ASSET, ASSETSDATA ASSETS, FLOATARRAY floatvector(128))'; 2410 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 2411 store = rdbStore; 2412 await (store as relationalStore.RdbStore).executeSql(SQL_CREATE_TABLE); 2413 console.info('Get RdbStore successfully.'); 2414 }).catch((err: BusinessError) => { 2415 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 2416 }); 2417 2418 // Set the RDB store version. 2419 if (store != undefined) { 2420 (store as relationalStore.RdbStore).version = 3; 2421 // Obtain the RDB store version. 2422 console.info(`RdbStore version is ${store.version}`); 2423 // Whether the RDB store has been rebuilt. 2424 console.info(`RdbStore rebuilt is ${store.rebuilt}`); 2425 } 2426 } 2427} 2428``` 2429 2430### insert 2431 2432insert(table: string, values: ValuesBucket, callback: AsyncCallback<number>):void 2433 2434Inserts 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. 2435 2436**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2437 2438**Parameters** 2439 2440| Name | Type | Mandatory| Description | 2441| -------- | ----------------------------- | ---- | ---------------------------------------------------------- | 2442| table | string | Yes | Name of the target table. | 2443| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2444| 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.| 2445 2446**Error codes** 2447 2448For 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). 2449 2450| **ID**| **Error Message** | 2451|-----------| ------------------------------------------------------------ | 2452| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2453| 14800000 | Inner error. | 2454| 14800011 | Failed to open the database because it is corrupted. | 2455| 14800014 | The RdbStore or ResultSet is already closed. | 2456| 14800015 | The database does not respond. | 2457| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 2458| 14800022 | SQLite: Callback routine requested an abort. | 2459| 14800023 | SQLite: Access permission denied. | 2460| 14800024 | SQLite: The database file is locked. | 2461| 14800025 | SQLite: A table in the database is locked. | 2462| 14800026 | SQLite: The database is out of memory. | 2463| 14800027 | SQLite: Attempt to write a readonly database. | 2464| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2465| 14800029 | SQLite: The database is full. | 2466| 14800030 | SQLite: Unable to open the database file. | 2467| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2468| 14800032 | SQLite: Abort due to constraint violation. | 2469| 14800033 | SQLite: Data type mismatch. | 2470| 14800034 | SQLite: Library used incorrectly. | 2471| 14800047 | The WAL file size exceeds the default limit. | 2472 2473**Example** 2474 2475```ts 2476let value1 = "Lisa"; 2477let value2 = 18; 2478let value3 = 100.5; 2479let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2480 2481// You can use either of the following: 2482const valueBucket1: relationalStore.ValuesBucket = { 2483 'NAME': value1, 2484 'AGE': value2, 2485 'SALARY': value3, 2486 'CODES': value4 2487}; 2488const valueBucket2: relationalStore.ValuesBucket = { 2489 NAME: value1, 2490 AGE: value2, 2491 SALARY: value3, 2492 CODES: value4 2493}; 2494const valueBucket3: relationalStore.ValuesBucket = { 2495 "NAME": value1, 2496 "AGE": value2, 2497 "SALARY": value3, 2498 "CODES": value4 2499}; 2500 2501if (store != undefined) { 2502 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, (err: BusinessError, rowId: number) => { 2503 if (err) { 2504 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2505 return; 2506 } 2507 console.info(`Insert is successful, rowId = ${rowId}`); 2508 }); 2509} 2510``` 2511 2512### insert<sup>10+</sup> 2513 2514insert(table: string, values: ValuesBucket, conflict: ConflictResolution, callback: AsyncCallback<number>):void 2515 2516Inserts 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. 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 | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2526| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 2527| 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.| 2528 2529**Error codes** 2530 2531For 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). 2532 2533| **ID**| **Error Message** | 2534|-----------| ---------------------------------------------------- | 2535| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2536| 14800000 | Inner error. | 2537| 14800011 | Failed to open the database because it is corrupted. | 2538| 14800014 | The RdbStore or ResultSet is already closed. | 2539| 14800015 | The database does not respond. | 2540| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 2541| 14800022 | SQLite: Callback routine requested an abort. | 2542| 14800023 | SQLite: Access permission denied. | 2543| 14800024 | SQLite: The database file is locked. | 2544| 14800025 | SQLite: A table in the database is locked. | 2545| 14800026 | SQLite: The database is out of memory. | 2546| 14800027 | SQLite: Attempt to write a readonly database. | 2547| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2548| 14800029 | SQLite: The database is full. | 2549| 14800030 | SQLite: Unable to open the database file. | 2550| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2551| 14800032 | SQLite: Abort due to constraint violation. | 2552| 14800033 | SQLite: Data type mismatch. | 2553| 14800034 | SQLite: Library used incorrectly. | 2554| 14800047 | The WAL file size exceeds the default limit. | 2555 2556**Example** 2557 2558```ts 2559let value1 = "Lisa"; 2560let value2 = 18; 2561let value3 = 100.5; 2562let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2563 2564// You can use either of the following: 2565const valueBucket1: relationalStore.ValuesBucket = { 2566 'NAME': value1, 2567 'AGE': value2, 2568 'SALARY': value3, 2569 'CODES': value4 2570}; 2571const valueBucket2: relationalStore.ValuesBucket = { 2572 NAME: value1, 2573 AGE: value2, 2574 SALARY: value3, 2575 CODES: value4 2576}; 2577const valueBucket3: relationalStore.ValuesBucket = { 2578 "NAME": value1, 2579 "AGE": value2, 2580 "SALARY": value3, 2581 "CODES": value4 2582}; 2583 2584if (store != undefined) { 2585 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, 2586 (err: BusinessError, rowId: number) => { 2587 if (err) { 2588 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2589 return; 2590 } 2591 console.info(`Insert is successful, rowId = ${rowId}`); 2592 }); 2593} 2594``` 2595 2596### insert 2597 2598insert(table: string, values: ValuesBucket):Promise<number> 2599 2600Inserts 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. 2601 2602**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2603 2604**Parameters** 2605 2606| Name| Type | Mandatory| Description | 2607| ------ | ----------------------------- | ---- | -------------------------- | 2608| table | string | Yes | Name of the target table. | 2609| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 2610 2611**Return value** 2612 2613| Type | Description | 2614| --------------------- | ------------------------------------------------- | 2615| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2616 2617**Error codes** 2618 2619For 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). 2620 2621| **ID**| **Error Message** | 2622|-----------| ------------------------------------------------------------ | 2623| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2624| 14800000 | Inner error. | 2625| 14800011 | Failed to open the database because it is corrupted. | 2626| 14800014 | The RdbStore or ResultSet is already closed. | 2627| 14800015 | The database does not respond. | 2628| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 2629| 14800022 | SQLite: Callback routine requested an abort. | 2630| 14800023 | SQLite: Access permission denied. | 2631| 14800024 | SQLite: The database file is locked. | 2632| 14800025 | SQLite: A table in the database is locked. | 2633| 14800026 | SQLite: The database is out of memory. | 2634| 14800027 | SQLite: Attempt to write a readonly database. | 2635| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2636| 14800029 | SQLite: The database is full. | 2637| 14800030 | SQLite: Unable to open the database file. | 2638| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2639| 14800032 | SQLite: Abort due to constraint violation. | 2640| 14800033 | SQLite: Data type mismatch. | 2641| 14800034 | SQLite: Library used incorrectly. | 2642| 14800047 | The WAL file size exceeds the default limit. | 2643 2644**Example** 2645 2646```ts 2647import { BusinessError } from '@kit.BasicServicesKit'; 2648 2649let value1 = "Lisa"; 2650let value2 = 18; 2651let value3 = 100.5; 2652let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2653 2654// You can use either of the following: 2655const valueBucket1: relationalStore.ValuesBucket = { 2656 'NAME': value1, 2657 'AGE': value2, 2658 'SALARY': value3, 2659 'CODES': value4 2660}; 2661const valueBucket2: relationalStore.ValuesBucket = { 2662 NAME: value1, 2663 AGE: value2, 2664 SALARY: value3, 2665 CODES: value4 2666}; 2667const valueBucket3: relationalStore.ValuesBucket = { 2668 "NAME": value1, 2669 "AGE": value2, 2670 "SALARY": value3, 2671 "CODES": value4 2672}; 2673 2674if (store != undefined) { 2675 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1).then((rowId: number) => { 2676 console.info(`Insert is successful, rowId = ${rowId}`); 2677 }).catch((err: BusinessError) => { 2678 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2679 }); 2680} 2681``` 2682 2683### insert<sup>10+</sup> 2684 2685insert(table: string, values: ValuesBucket, conflict: ConflictResolution):Promise<number> 2686 2687Inserts 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. 2688 2689**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2690 2691**Parameters** 2692 2693| Name | Type | Mandatory| Description | 2694| -------- | ------------------------------------------- | ---- | -------------------------- | 2695| table | string | Yes | Name of the target table. | 2696| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 2697| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 2698 2699**Return value** 2700 2701| Type | Description | 2702| --------------------- | ------------------------------------------------- | 2703| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2704 2705**Error codes** 2706 2707For 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). 2708 2709| **ID**| **Error Message** | 2710|-----------| ------------------------------------------------------------ | 2711| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2712| 14800000 | Inner error. | 2713| 14800011 | Failed to open the database because it is corrupted. | 2714| 14800014 | The RdbStore or ResultSet is already closed. | 2715| 14800015 | The database does not respond. | 2716| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 2717| 14800022 | SQLite: Callback routine requested an abort. | 2718| 14800023 | SQLite: Access permission denied. | 2719| 14800024 | SQLite: The database file is locked. | 2720| 14800025 | SQLite: A table in the database is locked. | 2721| 14800026 | SQLite: The database is out of memory. | 2722| 14800027 | SQLite: Attempt to write a readonly database. | 2723| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2724| 14800029 | SQLite: The database is full. | 2725| 14800030 | SQLite: Unable to open the database file. | 2726| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2727| 14800032 | SQLite: Abort due to constraint violation. | 2728| 14800033 | SQLite: Data type mismatch. | 2729| 14800034 | SQLite: Library used incorrectly. | 2730| 14800047 | The WAL file size exceeds the default limit. | 2731 2732**Example** 2733 2734```ts 2735import { BusinessError } from '@kit.BasicServicesKit'; 2736 2737let value1 = "Lisa"; 2738let value2 = 18; 2739let value3 = 100.5; 2740let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2741 2742// You can use either of the following: 2743const valueBucket1: relationalStore.ValuesBucket = { 2744 'NAME': value1, 2745 'AGE': value2, 2746 'SALARY': value3, 2747 'CODES': value4 2748}; 2749const valueBucket2: relationalStore.ValuesBucket = { 2750 NAME: value1, 2751 AGE: value2, 2752 SALARY: value3, 2753 CODES: value4 2754}; 2755const valueBucket3: relationalStore.ValuesBucket = { 2756 "NAME": value1, 2757 "AGE": value2, 2758 "SALARY": value3, 2759 "CODES": value4 2760}; 2761 2762if (store != undefined) { 2763 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => { 2764 console.info(`Insert is successful, rowId = ${rowId}`); 2765 }).catch((err: BusinessError) => { 2766 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2767 }); 2768} 2769``` 2770 2771### insertSync<sup>12+</sup> 2772 2773insertSync(table: string, values: ValuesBucket, conflict?: ConflictResolution):number 2774 2775Inserts 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. 2776 2777**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2778 2779**Parameters** 2780 2781| Name | Type | Mandatory| Description | 2782| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 2783| table | string | Yes | Name of the target table. | 2784| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2785| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 2786 2787**Return value** 2788 2789| Type | Description | 2790| ------ | ------------------------------------ | 2791| number | If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2792 2793**Error codes** 2794 2795For 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). 2796 2797| **ID**| **Error Message** | 2798| ------------ | ------------------------------------------------------------ | 2799| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2800| 14800000 | Inner error. | 2801| 14800011 | Failed to open the database because it is corrupted. | 2802| 14800014 | The RdbStore or ResultSet is already closed. | 2803| 14800015 | The database does not respond. | 2804| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 2805| 14800022 | SQLite: Callback routine requested an abort. | 2806| 14800023 | SQLite: Access permission denied. | 2807| 14800024 | SQLite: The database file is locked. | 2808| 14800025 | SQLite: A table in the database is locked. | 2809| 14800026 | SQLite: The database is out of memory. | 2810| 14800027 | SQLite: Attempt to write a readonly database. | 2811| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2812| 14800029 | SQLite: The database is full. | 2813| 14800030 | SQLite: Unable to open the database file. | 2814| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2815| 14800032 | SQLite: Abort due to constraint violation. | 2816| 14800033 | SQLite: Data type mismatch. | 2817| 14800034 | SQLite: Library used incorrectly. | 2818| 14800047 | The WAL file size exceeds the default limit. | 2819 2820**Example** 2821 2822```ts 2823import { BusinessError } from '@kit.BasicServicesKit'; 2824 2825let value1 = "Lisa"; 2826let value2 = 18; 2827let value3 = 100.5; 2828let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2829 2830// You can use either of the following: 2831const valueBucket1: relationalStore.ValuesBucket = { 2832 'NAME': value1, 2833 'AGE': value2, 2834 'SALARY': value3, 2835 'CODES': value4 2836}; 2837const valueBucket2: relationalStore.ValuesBucket = { 2838 NAME: value1, 2839 AGE: value2, 2840 SALARY: value3, 2841 CODES: value4 2842}; 2843const valueBucket3: relationalStore.ValuesBucket = { 2844 "NAME": value1, 2845 "AGE": value2, 2846 "SALARY": value3, 2847 "CODES": value4 2848}; 2849 2850if (store != undefined) { 2851 try { 2852 let rowId: number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 2853 console.info(`Insert is successful, rowId = ${rowId}`); 2854 } catch (error) { 2855 console.error(`Insert is failed, code is ${error.code},message is ${error.message}`); 2856 } 2857} 2858``` 2859 2860### insertSync<sup>12+</sup> 2861 2862insertSync(table: string, values: sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution):number 2863 2864Inserts 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. 2865 2866**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2867 2868**Parameters** 2869 2870| Name | Type | Mandatory| Description | 2871| -------- | ---------------------------------------------------------------------------------------------- | ---- | ------------------------------------------------------------------------------- | 2872| table | string | Yes | Name of the target table. | 2873| values | [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | Yes | Sendable data to insert. | 2874| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 2875 2876**Return value** 2877 2878| Type | Description | 2879| ------ | ------------------------------------ | 2880| number | If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 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 | Failed to open the database because it is corrupted. | 2891| 14800014 | The RdbStore or ResultSet is already closed. | 2892| 14800015 | The database does not respond. | 2893| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 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 2912import { sendableRelationalStore } from '@kit.ArkData'; 2913 2914const valuesBucket: relationalStore.ValuesBucket = { 2915 "NAME": 'hangman', 2916 "AGE": 18, 2917 "SALARY": 100.5, 2918 "CODES": new Uint8Array([1, 2, 3]) 2919}; 2920const sendableValuesBucket = sendableRelationalStore.toSendableValuesBucket(valuesBucket); 2921 2922if (store != undefined) { 2923 try { 2924 let rowId: number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", sendableValuesBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 2925 console.info(`Insert is successful, rowId = ${rowId}`); 2926 } catch (error) { 2927 console.error(`Insert is failed, code is ${error.code},message is ${error.message}`); 2928 } 2929} 2930``` 2931 2932### batchInsert 2933 2934batchInsert(table: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>):void 2935 2936Inserts a batch of data into a table. This API uses an asynchronous callback to return the result. 2937 2938Since API version 20, this API is supported in [vector store](#storeconfig). 2939 2940**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2941 2942**Parameters** 2943 2944| Name | Type | Mandatory| Description | 2945| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ | 2946| table | string | Yes | Name of the target table. | 2947| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert. | 2948| 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.| 2949 2950**Error codes** 2951 2952For 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). 2953 2954| **ID**| **Error Message** | 2955|-----------| ------------------------------------------------------------ | 2956| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2957| 14800000 | Inner error. | 2958| 14800011 | Failed to open the database because it is corrupted. | 2959| 14800014 | The RdbStore or ResultSet is already closed. | 2960| 14800015 | The database does not respond. | 2961| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 2962| 14800022 | SQLite: Callback routine requested an abort. | 2963| 14800023 | SQLite: Access permission denied. | 2964| 14800024 | SQLite: The database file is locked. | 2965| 14800025 | SQLite: A table in the database is locked. | 2966| 14800026 | SQLite: The database is out of memory. | 2967| 14800027 | SQLite: Attempt to write a readonly database. | 2968| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2969| 14800029 | SQLite: The database is full. | 2970| 14800030 | SQLite: Unable to open the database file. | 2971| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2972| 14800032 | SQLite: Abort due to constraint violation. | 2973| 14800033 | SQLite: Data type mismatch. | 2974| 14800034 | SQLite: Library used incorrectly. | 2975| 14800047 | The WAL file size exceeds the default limit. | 2976 2977**Example** 2978 2979```ts 2980let value1 = "Lisa"; 2981let value2 = 18; 2982let value3 = 100.5; 2983let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2984let value5 = "Jack"; 2985let value6 = 19; 2986let value7 = 101.5; 2987let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2988let value9 = "Tom"; 2989let value10 = 20; 2990let value11 = 102.5; 2991let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2992 2993const valueBucket1: relationalStore.ValuesBucket = { 2994 'NAME': value1, 2995 'AGE': value2, 2996 'SALARY': value3, 2997 'CODES': value4 2998}; 2999const valueBucket2: relationalStore.ValuesBucket = { 3000 'NAME': value5, 3001 'AGE': value6, 3002 'SALARY': value7, 3003 'CODES': value8 3004}; 3005const valueBucket3: relationalStore.ValuesBucket = { 3006 'NAME': value9, 3007 'AGE': value10, 3008 'SALARY': value11, 3009 'CODES': value12 3010}; 3011 3012let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 3013if (store != undefined) { 3014 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets, (err, insertNum) => { 3015 if (err) { 3016 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 3017 return; 3018 } 3019 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 3020 }) 3021} 3022``` 3023 3024### batchInsert 3025 3026batchInsert(table: string, values: Array<ValuesBucket>):Promise<number> 3027 3028Inserts a batch of data into a table. This API uses a promise to return the result. 3029 3030Since API version 20, this API is supported in [vector store](#storeconfig). 3031 3032**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3033 3034**Parameters** 3035 3036| Name| Type | Mandatory| Description | 3037| ------ | ------------------------------------------ | ---- | ---------------------------- | 3038| table | string | Yes | Name of the target table. | 3039| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 3040 3041**Return value** 3042 3043| Type | Description | 3044| --------------------- | ----------------------------------------------------------- | 3045| 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.| 3046 3047**Error codes** 3048 3049For 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). 3050 3051| **ID**| **Error Message** | 3052|-----------| ------------------------------------------------------------ | 3053| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3054| 14800000 | Inner error. | 3055| 14800011 | Failed to open the database because it is corrupted. | 3056| 14800014 | The RdbStore or ResultSet is already closed. | 3057| 14800015 | The database does not respond. | 3058| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 3059| 14800022 | SQLite: Callback routine requested an abort. | 3060| 14800023 | SQLite: Access permission denied. | 3061| 14800024 | SQLite: The database file is locked. | 3062| 14800025 | SQLite: A table in the database is locked. | 3063| 14800026 | SQLite: The database is out of memory. | 3064| 14800027 | SQLite: Attempt to write a readonly database. | 3065| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3066| 14800029 | SQLite: The database is full. | 3067| 14800030 | SQLite: Unable to open the database file. | 3068| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3069| 14800032 | SQLite: Abort due to constraint violation. | 3070| 14800033 | SQLite: Data type mismatch. | 3071| 14800034 | SQLite: Library used incorrectly. | 3072| 14800047 | The WAL file size exceeds the default limit. | 3073 3074**Example** 3075 3076RDB store: 3077 3078```ts 3079import { BusinessError } from '@kit.BasicServicesKit'; 3080 3081let value1 = "Lisa"; 3082let value2 = 18; 3083let value3 = 100.5; 3084let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3085let value5 = "Jack"; 3086let value6 = 19; 3087let value7 = 101.5; 3088let value8 = new Uint8Array([6, 7, 8, 9, 10]); 3089let value9 = "Tom"; 3090let value10 = 20; 3091let value11 = 102.5; 3092let value12 = new Uint8Array([11, 12, 13, 14, 15]); 3093 3094const valueBucket1: relationalStore.ValuesBucket = { 3095 'NAME': value1, 3096 'AGE': value2, 3097 'SALARY': value3, 3098 'CODES': value4 3099}; 3100const valueBucket2: relationalStore.ValuesBucket = { 3101 'NAME': value5, 3102 'AGE': value6, 3103 'SALARY': value7, 3104 'CODES': value8 3105}; 3106const valueBucket3: relationalStore.ValuesBucket = { 3107 'NAME': value9, 3108 'AGE': value10, 3109 'SALARY': value11, 3110 'CODES': value12 3111}; 3112 3113let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 3114if (store != undefined) { 3115 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => { 3116 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 3117 }).catch((err: BusinessError) => { 3118 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 3119 }) 3120} 3121``` 3122 3123Vector store: 3124 3125```ts 3126let createSql = "CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY AUTOINCREMENT, data1 floatvector(2));"; 3127await store!.execute(createSql, 0, undefined); // Create a relational table. The second parameter 0 indicates that explicit transactions are not enabled, and the third parameter undefined indicates that the SQL statement does not use parameter binding. 3128let floatVector = Float32Array.from([1.2, 2.3]); 3129let valueBucketArray = new Array<relationalStore.ValuesBucket>(); 3130for (let i = 0; i < 100; i++) { // Construct a BucketArray for writing. 3131 const row : relationalStore.ValuesBucket = { 3132 "id" : i, 3133 "data1" : floatVector, 3134 } 3135 valueBucketArray.push(row); 3136} 3137await store!.batchInsert ("test", valueBucketArray); // Execute batched writes. 3138``` 3139 3140### batchInsertSync<sup>12+</sup> 3141 3142batchInsertSync(table: string, values: Array<ValuesBucket>):number 3143 3144Inserts a batch of data into a table. 3145 3146**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3147 3148**Parameters** 3149 3150| Name| Type | Mandatory| Description | 3151| ------ | ------------------------------------------ | ---- | ---------------------------- | 3152| table | string | Yes | Name of the target table. | 3153| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 3154 3155**Return value** 3156 3157| Type | Description | 3158| ------ | ---------------------------------------------- | 3159| number | If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 3160 3161**Error codes** 3162 3163For 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). 3164 3165| **ID**| **Error Message** | 3166| ------------ | ------------------------------------------------------------ | 3167| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3168| 14800000 | Inner error. | 3169| 14800011 | Failed to open the database because it is corrupted. | 3170| 14800014 | The RdbStore or ResultSet is already closed. | 3171| 14800015 | The database does not respond. | 3172| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 3173| 14800022 | SQLite: Callback routine requested an abort. | 3174| 14800023 | SQLite: Access permission denied. | 3175| 14800024 | SQLite: The database file is locked. | 3176| 14800025 | SQLite: A table in the database is locked. | 3177| 14800026 | SQLite: The database is out of memory. | 3178| 14800027 | SQLite: Attempt to write a readonly database. | 3179| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3180| 14800029 | SQLite: The database is full. | 3181| 14800030 | SQLite: Unable to open the database file. | 3182| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3183| 14800032 | SQLite: Abort due to constraint violation. | 3184| 14800033 | SQLite: Data type mismatch. | 3185| 14800034 | SQLite: Library used incorrectly. | 3186| 14800047 | The WAL file size exceeds the default limit. | 3187 3188**Example** 3189 3190```ts 3191import { BusinessError } from '@kit.BasicServicesKit'; 3192 3193let value1 = "Lisa"; 3194let value2 = 18; 3195let value3 = 100.5; 3196let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3197let value5 = "Jack"; 3198let value6 = 19; 3199let value7 = 101.5; 3200let value8 = new Uint8Array([6, 7, 8, 9, 10]); 3201let value9 = "Tom"; 3202let value10 = 20; 3203let value11 = 102.5; 3204let value12 = new Uint8Array([11, 12, 13, 14, 15]); 3205 3206const valueBucket1: relationalStore.ValuesBucket = { 3207 'NAME': value1, 3208 'AGE': value2, 3209 'SALARY': value3, 3210 'CODES': value4 3211}; 3212const valueBucket2: relationalStore.ValuesBucket = { 3213 'NAME': value5, 3214 'AGE': value6, 3215 'SALARY': value7, 3216 'CODES': value8 3217}; 3218const valueBucket3: relationalStore.ValuesBucket = { 3219 'NAME': value9, 3220 'AGE': value10, 3221 'SALARY': value11, 3222 'CODES': value12 3223}; 3224 3225let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 3226if (store != undefined) { 3227 try { 3228 let insertNum: number = (store as relationalStore.RdbStore).batchInsertSync("EMPLOYEE", valueBuckets); 3229 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 3230 } catch (err) { 3231 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 3232 } 3233} 3234``` 3235 3236### batchInsertWithConflictResolution<sup>18+</sup> 3237 3238batchInsertWithConflictResolution(table: string, values: Array<ValuesBucket>, conflict: ConflictResolution): Promise<number> 3239 3240Inserts a batch of data into a table. This API uses a promise to return the result. 3241 3242**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3243 3244**Parameters** 3245 3246| Name| Type | Mandatory| Description | 3247| ------ | ------------------------------------------ | ---- | ---------------------------- | 3248| table | string | Yes | Name of the target table. | 3249| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 3250| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 3251 3252**Return value** 3253 3254| Type | Description | 3255| ------ | ---------------------------------------------- | 3256| Promise<number> | Promise used to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 3257 3258**Error codes** 3259 3260For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 3261 3262| **ID**| **Error Message** | 3263| ------------ | ------------------------------------------------------------ | 3264| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3265| 14800000 | Inner error. | 3266| 14800011 | Failed to open the database because it is corrupted. | 3267| 14800014 | The RdbStore or ResultSet is already closed. | 3268| 14800015 | The database does not respond. | 3269| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 3270| 14800022 | SQLite: Callback routine requested an abort. | 3271| 14800023 | SQLite: Access permission denied. | 3272| 14800024 | SQLite: The database file is locked. | 3273| 14800025 | SQLite: A table in the database is locked. | 3274| 14800026 | SQLite: The database is out of memory. | 3275| 14800027 | SQLite: Attempt to write a readonly database. | 3276| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3277| 14800029 | SQLite: The database is full. | 3278| 14800030 | SQLite: Unable to open the database file. | 3279| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3280| 14800032 | SQLite: Abort due to constraint violation. | 3281| 14800033 | SQLite: Data type mismatch. | 3282| 14800034 | SQLite: Library used incorrectly. | 3283| 14800047 | The WAL file size exceeds the default limit. | 3284 3285**Example** 3286 3287```ts 3288import { BusinessError } from '@kit.BasicServicesKit'; 3289 3290let value1 = "Lisa"; 3291let value2 = 18; 3292let value3 = 100.5; 3293let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3294let value5 = "Jack"; 3295let value6 = 19; 3296let value7 = 101.5; 3297let value8 = new Uint8Array([6, 7, 8, 9, 10]); 3298let value9 = "Tom"; 3299let value10 = 20; 3300let value11 = 102.5; 3301let value12 = new Uint8Array([11, 12, 13, 14, 15]); 3302 3303const valueBucket1: relationalStore.ValuesBucket = { 3304 'NAME': value1, 3305 'AGE': value2, 3306 'SALARY': value3, 3307 'CODES': value4 3308}; 3309const valueBucket2: relationalStore.ValuesBucket = { 3310 'NAME': value5, 3311 'AGE': value6, 3312 'SALARY': value7, 3313 'CODES': value8 3314}; 3315const valueBucket3: relationalStore.ValuesBucket = { 3316 'NAME': value9, 3317 'AGE': value10, 3318 'SALARY': value11, 3319 'CODES': value12 3320}; 3321 3322let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 3323if (store != undefined) { 3324 (store as relationalStore.RdbStore).batchInsertWithConflictResolution("EMPLOYEE", valueBuckets, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((insertNum: number) => { 3325 console.info(`batchInsert is successful, insertNum = ${insertNum}`); 3326 }).catch((err: BusinessError) => { 3327 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 3328 }); 3329} 3330``` 3331 3332### batchInsertWithConflictResolutionSync<sup>18+</sup> 3333 3334batchInsertWithConflictResolutionSync(table: string, values: Array<ValuesBucket>, conflict: ConflictResolution): number 3335 3336Inserts a batch of data into a table with conflict resolutions. 3337 3338**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3339 3340**Parameters** 3341 3342| Name| Type | Mandatory| Description | 3343| ------ | ------------------------------------------ | ---- | ---------------------------- | 3344| table | string | Yes | Name of the target table. | 3345| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 3346| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 3347 3348**Return value** 3349 3350| Type | Description | 3351| ------ | ---------------------------------------------- | 3352| number | If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 3353 3354**Error codes** 3355 3356For 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). 3357 3358| **ID**| **Error Message** | 3359| ------------ | ------------------------------------------------------------ | 3360| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3361| 14800000 | Inner error. | 3362| 14800011 | Failed to open the database because it is corrupted. | 3363| 14800014 | The RdbStore or ResultSet is already closed. | 3364| 14800015 | The database does not respond. | 3365| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 3366| 14800022 | SQLite: Callback routine requested an abort. | 3367| 14800023 | SQLite: Access permission denied. | 3368| 14800024 | SQLite: The database file is locked. | 3369| 14800025 | SQLite: A table in the database is locked. | 3370| 14800026 | SQLite: The database is out of memory. | 3371| 14800027 | SQLite: Attempt to write a readonly database. | 3372| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3373| 14800029 | SQLite: The database is full. | 3374| 14800030 | SQLite: Unable to open the database file. | 3375| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3376| 14800032 | SQLite: Abort due to constraint violation. | 3377| 14800033 | SQLite: Data type mismatch. | 3378| 14800034 | SQLite: Library used incorrectly. | 3379| 14800047 | The WAL file size exceeds the default limit. | 3380 3381**Example** 3382 3383```ts 3384import { BusinessError } from '@kit.BasicServicesKit'; 3385 3386let value1 = "Lisa"; 3387let value2 = 18; 3388let value3 = 100.5; 3389let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3390let value5 = "Jack"; 3391let value6 = 19; 3392let value7 = 101.5; 3393let value8 = new Uint8Array([6, 7, 8, 9, 10]); 3394let value9 = "Tom"; 3395let value10 = 20; 3396let value11 = 102.5; 3397let value12 = new Uint8Array([11, 12, 13, 14, 15]); 3398 3399const valueBucket1: relationalStore.ValuesBucket = { 3400 'NAME': value1, 3401 'AGE': value2, 3402 'SALARY': value3, 3403 'CODES': value4 3404}; 3405const valueBucket2: relationalStore.ValuesBucket = { 3406 'NAME': value5, 3407 'AGE': value6, 3408 'SALARY': value7, 3409 'CODES': value8 3410}; 3411const valueBucket3: relationalStore.ValuesBucket = { 3412 'NAME': value9, 3413 'AGE': value10, 3414 'SALARY': value11, 3415 'CODES': value12 3416}; 3417 3418let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 3419if (store != undefined) { 3420 try { 3421 let insertNum: number = (store as relationalStore.RdbStore).batchInsertWithConflictResolutionSync("EMPLOYEE", valueBuckets, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 3422 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 3423 } catch (err) { 3424 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 3425 } 3426} 3427``` 3428 3429### update 3430 3431update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback<number>):void 3432 3433Updates 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. 3434 3435**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3436 3437**Parameters** 3438 3439| Name | Type | Mandatory| Description | 3440| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 3441| 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.| 3442| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3443| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows updated. | 3444 3445**Error codes** 3446 3447For 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). 3448 3449| **ID**| **Error Message** | 3450|-----------| ------------------------------------------------------------ | 3451| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3452| 14800000 | Inner error. | 3453| 14800011 | Failed to open the database because it is corrupted. | 3454| 14800014 | The RdbStore or ResultSet is already closed. | 3455| 14800015 | The database does not respond. | 3456| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 3457| 14800022 | SQLite: Callback routine requested an abort. | 3458| 14800023 | SQLite: Access permission denied. | 3459| 14800024 | SQLite: The database file is locked. | 3460| 14800025 | SQLite: A table in the database is locked. | 3461| 14800026 | SQLite: The database is out of memory. | 3462| 14800027 | SQLite: Attempt to write a readonly database. | 3463| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3464| 14800029 | SQLite: The database is full. | 3465| 14800030 | SQLite: Unable to open the database file. | 3466| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3467| 14800032 | SQLite: Abort due to constraint violation. | 3468| 14800033 | SQLite: Data type mismatch. | 3469| 14800034 | SQLite: Library used incorrectly. | 3470| 14800047 | The WAL file size exceeds the default limit. | 3471 3472**Example** 3473 3474```ts 3475let value1 = "Rose"; 3476let value2 = 22; 3477let value3 = 200.5; 3478let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3479 3480// You can use either of the following: 3481const valueBucket1: relationalStore.ValuesBucket = { 3482 'NAME': value1, 3483 'AGE': value2, 3484 'SALARY': value3, 3485 'CODES': value4 3486}; 3487const valueBucket2: relationalStore.ValuesBucket = { 3488 NAME: value1, 3489 AGE: value2, 3490 SALARY: value3, 3491 CODES: value4 3492}; 3493const valueBucket3: relationalStore.ValuesBucket = { 3494 "NAME": value1, 3495 "AGE": value2, 3496 "SALARY": value3, 3497 "CODES": value4 3498}; 3499 3500let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3501predicates.equalTo("NAME", "Lisa"); 3502if (store != undefined) { 3503 (store as relationalStore.RdbStore).update(valueBucket1, predicates, (err, rows) => { 3504 if (err) { 3505 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3506 return; 3507 } 3508 console.info(`Updated row count: ${rows}`); 3509 }); 3510} 3511``` 3512 3513### update<sup>10+</sup> 3514 3515update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution, callback: AsyncCallback<number>):void 3516 3517Updates 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. 3518 3519**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3520 3521**Parameters** 3522 3523| Name | Type | Mandatory| Description | 3524| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3525| 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.| 3526| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3527| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 3528| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows updated. | 3529 3530**Error codes** 3531 3532For 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). 3533 3534| **ID**| **Error Message** | 3535|-----------| ------------------------------------------------------------ | 3536| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3537| 14800000 | Inner error. | 3538| 14800011 | Failed to open the database because it is corrupted. | 3539| 14800014 | The RdbStore or ResultSet is already closed. | 3540| 14800015 | The database does not respond. | 3541| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 3542| 14800022 | SQLite: Callback routine requested an abort. | 3543| 14800023 | SQLite: Access permission denied. | 3544| 14800024 | SQLite: The database file is locked. | 3545| 14800025 | SQLite: A table in the database is locked. | 3546| 14800026 | SQLite: The database is out of memory. | 3547| 14800027 | SQLite: Attempt to write a readonly database. | 3548| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3549| 14800029 | SQLite: The database is full. | 3550| 14800030 | SQLite: Unable to open the database file. | 3551| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3552| 14800032 | SQLite: Abort due to constraint violation. | 3553| 14800033 | SQLite: Data type mismatch. | 3554| 14800034 | SQLite: Library used incorrectly. | 3555| 14800047 | The WAL file size exceeds the default limit. | 3556 3557**Example** 3558 3559```ts 3560let value1 = "Rose"; 3561let value2 = 22; 3562let value3 = 200.5; 3563let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3564 3565// You can use either of the following: 3566const valueBucket1: relationalStore.ValuesBucket = { 3567 'NAME': value1, 3568 'AGE': value2, 3569 'SALARY': value3, 3570 'CODES': value4 3571}; 3572const valueBucket2: relationalStore.ValuesBucket = { 3573 NAME: value1, 3574 AGE: value2, 3575 SALARY: value3, 3576 CODES: value4 3577}; 3578const valueBucket3: relationalStore.ValuesBucket = { 3579 "NAME": value1, 3580 "AGE": value2, 3581 "SALARY": value3, 3582 "CODES": value4 3583}; 3584 3585let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3586predicates.equalTo("NAME", "Lisa"); 3587if (store != undefined) { 3588 (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, (err, rows) => { 3589 if (err) { 3590 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3591 return; 3592 } 3593 console.info(`Updated row count: ${rows}`); 3594 }); 3595} 3596``` 3597 3598### update 3599 3600update(values: ValuesBucket, predicates: RdbPredicates):Promise<number> 3601 3602Updates 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. 3603 3604**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3605 3606**Parameters** 3607 3608| Name | Type | Mandatory| Description | 3609| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 3610| 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.| 3611| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3612 3613**Return value** 3614 3615| Type | Description | 3616| --------------------- | ----------------------------------------- | 3617| Promise<number> | Promise used to return the number of rows updated.| 3618 3619**Error codes** 3620 3621For 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). 3622 3623| **ID**| **Error Message** | 3624|-----------| ------------------------------------------------------------ | 3625| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3626| 14800000 | Inner error. | 3627| 14800011 | Failed to open the database because it is corrupted. | 3628| 14800014 | The RdbStore or ResultSet is already closed. | 3629| 14800015 | The database does not respond. | 3630| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 3631| 14800022 | SQLite: Callback routine requested an abort. | 3632| 14800023 | SQLite: Access permission denied. | 3633| 14800024 | SQLite: The database file is locked. | 3634| 14800025 | SQLite: A table in the database is locked. | 3635| 14800026 | SQLite: The database is out of memory. | 3636| 14800027 | SQLite: Attempt to write a readonly database. | 3637| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3638| 14800029 | SQLite: The database is full. | 3639| 14800030 | SQLite: Unable to open the database file. | 3640| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3641| 14800032 | SQLite: Abort due to constraint violation. | 3642| 14800033 | SQLite: Data type mismatch. | 3643| 14800034 | SQLite: Library used incorrectly. | 3644| 14800047 | The WAL file size exceeds the default limit. | 3645 3646**Example** 3647 3648```ts 3649import { BusinessError } from '@kit.BasicServicesKit'; 3650 3651let value1 = "Rose"; 3652let value2 = 22; 3653let value3 = 200.5; 3654let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3655 3656// You can use either of the following: 3657const valueBucket1: relationalStore.ValuesBucket = { 3658 'NAME': value1, 3659 'AGE': value2, 3660 'SALARY': value3, 3661 'CODES': value4 3662}; 3663const valueBucket2: relationalStore.ValuesBucket = { 3664 NAME: value1, 3665 AGE: value2, 3666 SALARY: value3, 3667 CODES: value4 3668}; 3669const valueBucket3: relationalStore.ValuesBucket = { 3670 "NAME": value1, 3671 "AGE": value2, 3672 "SALARY": value3, 3673 "CODES": value4 3674}; 3675 3676let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3677predicates.equalTo("NAME", "Lisa"); 3678if (store != undefined) { 3679 (store as relationalStore.RdbStore).update(valueBucket1, predicates).then(async (rows: Number) => { 3680 console.info(`Updated row count: ${rows}`); 3681 }).catch((err: BusinessError) => { 3682 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3683 }); 3684} 3685``` 3686 3687### update<sup>10+</sup> 3688 3689update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution):Promise<number> 3690 3691Updates 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. 3692 3693**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3694 3695**Parameters** 3696 3697| Name | Type | Mandatory| Description | 3698| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3699| 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.| 3700| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3701| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 3702 3703**Return value** 3704 3705| Type | Description | 3706| --------------------- | ----------------------------------------- | 3707| Promise<number> | Promise used to return the number of rows updated.| 3708 3709**Error codes** 3710 3711For 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). 3712 3713| **ID**| **Error Message** | 3714|-----------| ------------------------------------------------------------ | 3715| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3716| 14800000 | Inner error. | 3717| 14800011 | Failed to open the database because it is corrupted. | 3718| 14800014 | The RdbStore or ResultSet is already closed. | 3719| 14800015 | The database does not respond. | 3720| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 3721| 14800022 | SQLite: Callback routine requested an abort. | 3722| 14800023 | SQLite: Access permission denied. | 3723| 14800024 | SQLite: The database file is locked. | 3724| 14800025 | SQLite: A table in the database is locked. | 3725| 14800026 | SQLite: The database is out of memory. | 3726| 14800027 | SQLite: Attempt to write a readonly database. | 3727| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3728| 14800029 | SQLite: The database is full. | 3729| 14800030 | SQLite: Unable to open the database file. | 3730| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3731| 14800032 | SQLite: Abort due to constraint violation. | 3732| 14800033 | SQLite: Data type mismatch. | 3733| 14800034 | SQLite: Library used incorrectly. | 3734| 14800047 | The WAL file size exceeds the default limit. | 3735 3736**Example** 3737 3738```ts 3739import { BusinessError } from '@kit.BasicServicesKit'; 3740 3741let value1 = "Rose"; 3742let value2 = 22; 3743let value3 = 200.5; 3744let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3745 3746// You can use either of the following: 3747const valueBucket1: relationalStore.ValuesBucket = { 3748 'NAME': value1, 3749 'AGE': value2, 3750 'SALARY': value3, 3751 'CODES': value4 3752}; 3753const valueBucket2: relationalStore.ValuesBucket = { 3754 NAME: value1, 3755 AGE: value2, 3756 SALARY: value3, 3757 CODES: value4 3758}; 3759const valueBucket3: relationalStore.ValuesBucket = { 3760 "NAME": value1, 3761 "AGE": value2, 3762 "SALARY": value3, 3763 "CODES": value4 3764}; 3765 3766let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3767predicates.equalTo("NAME", "Lisa"); 3768if (store != undefined) { 3769 (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => { 3770 console.info(`Updated row count: ${rows}`); 3771 }).catch((err: BusinessError) => { 3772 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3773 }); 3774} 3775``` 3776 3777### updateSync<sup>12+</sup> 3778 3779updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution):number 3780 3781Updates data in the database based on the specified **RdbPredicates** instance. Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 3782 3783**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3784 3785**Parameters** 3786 3787| Name | Type | Mandatory| Description | 3788| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3789| 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.| 3790| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3791| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 3792 3793**Return value** 3794 3795| Type | Description | 3796| ------ | ------------------ | 3797| number | Number of rows updated.| 3798 3799**Error codes** 3800 3801For 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). 3802 3803| **ID**| **Error Message** | 3804| ------------ | ------------------------------------------------------------ | 3805| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3806| 14800000 | Inner error. | 3807| 14800011 | Failed to open the database because it is corrupted. | 3808| 14800014 | The RdbStore or ResultSet is already closed. | 3809| 14800015 | The database does not respond. | 3810| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 3811| 14800022 | SQLite: Callback routine requested an abort. | 3812| 14800023 | SQLite: Access permission denied. | 3813| 14800024 | SQLite: The database file is locked. | 3814| 14800025 | SQLite: A table in the database is locked. | 3815| 14800026 | SQLite: The database is out of memory. | 3816| 14800027 | SQLite: Attempt to write a readonly database. | 3817| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3818| 14800029 | SQLite: The database is full. | 3819| 14800030 | SQLite: Unable to open the database file. | 3820| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3821| 14800032 | SQLite: Abort due to constraint violation. | 3822| 14800033 | SQLite: Data type mismatch. | 3823| 14800034 | SQLite: Library used incorrectly. | 3824| 14800047 | The WAL file size exceeds the default limit. | 3825 3826**Example** 3827 3828```ts 3829import { BusinessError } from '@kit.BasicServicesKit'; 3830 3831let value1 = "Rose"; 3832let value2 = 22; 3833let value3 = 200.5; 3834let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3835 3836// You can use either of the following: 3837const valueBucket1: relationalStore.ValuesBucket = { 3838 'NAME': value1, 3839 'AGE': value2, 3840 'SALARY': value3, 3841 'CODES': value4 3842}; 3843const valueBucket2: relationalStore.ValuesBucket = { 3844 NAME: value1, 3845 AGE: value2, 3846 SALARY: value3, 3847 CODES: value4 3848}; 3849const valueBucket3: relationalStore.ValuesBucket = { 3850 "NAME": value1, 3851 "AGE": value2, 3852 "SALARY": value3, 3853 "CODES": value4 3854}; 3855 3856let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3857predicates.equalTo("NAME", "Lisa"); 3858if (store != undefined) { 3859 try { 3860 let rows: Number = (store as relationalStore.RdbStore).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 3861 console.info(`Updated row count: ${rows}`); 3862 } catch (error) { 3863 console.error(`Updated failed, code is ${error.code},message is ${error.message}`); 3864 } 3865} 3866``` 3867 3868### delete 3869 3870delete(predicates: RdbPredicates, callback: AsyncCallback<number>):void 3871 3872Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result. 3873 3874**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3875 3876**Parameters** 3877 3878| Name | Type | Mandatory| Description | 3879| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 3880| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 3881| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows deleted.| 3882 3883**Error codes** 3884 3885For 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). 3886 3887| **ID**| **Error Message** | 3888|-----------| ------------------------------------------------------------ | 3889| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3890| 14800000 | Inner error. | 3891| 14800011 | Failed to open the database because it is corrupted. | 3892| 14800014 | The RdbStore or ResultSet is already closed. | 3893| 14800015 | The database does not respond. | 3894| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 3895| 14800022 | SQLite: Callback routine requested an abort. | 3896| 14800023 | SQLite: Access permission denied. | 3897| 14800024 | SQLite: The database file is locked. | 3898| 14800025 | SQLite: A table in the database is locked. | 3899| 14800026 | SQLite: The database is out of memory. | 3900| 14800027 | SQLite: Attempt to write a readonly database. | 3901| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3902| 14800029 | SQLite: The database is full. | 3903| 14800030 | SQLite: Unable to open the database file. | 3904| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3905| 14800032 | SQLite: Abort due to constraint violation. | 3906| 14800033 | SQLite: Data type mismatch. | 3907| 14800034 | SQLite: Library used incorrectly. | 3908| 14800047 | The WAL file size exceeds the default limit. | 3909 3910**Example** 3911 3912```ts 3913let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3914predicates.equalTo("NAME", "Lisa"); 3915if (store != undefined) { 3916 (store as relationalStore.RdbStore).delete(predicates, (err, rows) => { 3917 if (err) { 3918 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3919 return; 3920 } 3921 console.info(`Delete rows: ${rows}`); 3922 }); 3923} 3924``` 3925 3926### delete 3927 3928delete(predicates: RdbPredicates):Promise<number> 3929 3930Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result. 3931 3932**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3933 3934**Parameters** 3935 3936| Name | Type | Mandatory| Description | 3937| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 3938| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 3939 3940**Return value** 3941 3942| Type | Description | 3943| --------------------- | ------------------------------- | 3944| Promise<number> | Promise used to return the number of rows deleted.| 3945 3946**Error codes** 3947 3948For 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). 3949 3950| **ID**| **Error Message** | 3951|-----------| ------------------------------------------------------------ | 3952| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3953| 14800000 | Inner error. | 3954| 14800011 | Failed to open the database because it is corrupted. | 3955| 14800014 | The RdbStore or ResultSet is already closed. | 3956| 14800015 | The database does not respond. | 3957| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 3958| 14800022 | SQLite: Callback routine requested an abort. | 3959| 14800023 | SQLite: Access permission denied. | 3960| 14800024 | SQLite: The database file is locked. | 3961| 14800025 | SQLite: A table in the database is locked. | 3962| 14800026 | SQLite: The database is out of memory. | 3963| 14800027 | SQLite: Attempt to write a readonly database. | 3964| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3965| 14800029 | SQLite: The database is full. | 3966| 14800030 | SQLite: Unable to open the database file. | 3967| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3968| 14800032 | SQLite: Abort due to constraint violation. | 3969| 14800033 | SQLite: Data type mismatch. | 3970| 14800034 | SQLite: Library used incorrectly. | 3971| 14800047 | The WAL file size exceeds the default limit. | 3972 3973**Example** 3974 3975```ts 3976import { BusinessError } from '@kit.BasicServicesKit'; 3977 3978let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3979predicates.equalTo("NAME", "Lisa"); 3980if (store != undefined) { 3981 (store as relationalStore.RdbStore).delete(predicates).then((rows: Number) => { 3982 console.info(`Delete rows: ${rows}`); 3983 }).catch((err: BusinessError) => { 3984 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3985 }); 3986} 3987``` 3988 3989### deleteSync<sup>12+</sup> 3990 3991deleteSync(predicates: RdbPredicates):number 3992 3993Deletes data from the database based on the specified **RdbPredicates** object. 3994 3995**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3996 3997**Parameters** 3998 3999| Name | Type | Mandatory| Description | 4000| ---------- | ------------------------------- | ---- | --------------------------------------- | 4001| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 4002 4003**Return value** 4004 4005| Type | Description | 4006| ------ | ------------------ | 4007| number | Number of rows deleted.| 4008 4009**Error codes** 4010 4011For 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). 4012 4013| **ID**| **Error Message** | 4014| ------------ | ------------------------------------------------------------ | 4015| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4016| 14800000 | Inner error. | 4017| 14800011 | Failed to open the database because it is corrupted. | 4018| 14800014 | The RdbStore or ResultSet is already closed. | 4019| 14800015 | The database does not respond. | 4020| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 4021| 14800022 | SQLite: Callback routine requested an abort. | 4022| 14800023 | SQLite: Access permission denied. | 4023| 14800024 | SQLite: The database file is locked. | 4024| 14800025 | SQLite: A table in the database is locked. | 4025| 14800026 | SQLite: The database is out of memory. | 4026| 14800027 | SQLite: Attempt to write a readonly database. | 4027| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4028| 14800029 | SQLite: The database is full. | 4029| 14800030 | SQLite: Unable to open the database file. | 4030| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4031| 14800032 | SQLite: Abort due to constraint violation. | 4032| 14800033 | SQLite: Data type mismatch. | 4033| 14800034 | SQLite: Library used incorrectly. | 4034| 14800047 | The WAL file size exceeds the default limit. | 4035 4036**Example** 4037 4038```ts 4039import { BusinessError } from '@kit.BasicServicesKit'; 4040 4041let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 4042predicates.equalTo("NAME", "Lisa"); 4043if (store != undefined) { 4044 try { 4045 let rows: Number = (store as relationalStore.RdbStore).deleteSync(predicates); 4046 console.info(`Delete rows: ${rows}`); 4047 } catch (err) { 4048 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 4049 } 4050} 4051``` 4052 4053### query<sup>10+</sup> 4054 4055query(predicates: RdbPredicates, callback: AsyncCallback<ResultSet>):void 4056 4057Queries 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. 4058 4059**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4060 4061**Parameters** 4062 4063| Name | Type | Mandatory| Description | 4064| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 4065| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 4066| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 4067 4068**Error codes** 4069 4070For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4071 4072| **ID**| **Error Message** | 4073|-----------| ------------------------------------------------------------ | 4074| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4075| 14800000 | Inner error. | 4076| 14800014 | The RdbStore or ResultSet is already closed. | 4077| 14800015 | The database does not respond. | 4078 4079**Example** 4080 4081```ts 4082let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 4083predicates.equalTo("NAME", "Rose"); 4084if (store != undefined) { 4085 (store as relationalStore.RdbStore).query(predicates, async (err, resultSet) => { 4086 if (err) { 4087 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4088 return; 4089 } 4090 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4091 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4092 while (resultSet.goToNextRow()) { 4093 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4094 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4095 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4096 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4097 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4098 } 4099 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4100 resultSet.close(); 4101 }); 4102} 4103``` 4104 4105### query 4106 4107query(predicates: RdbPredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>):void 4108 4109Queries 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. 4110 4111**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4112 4113**Parameters** 4114 4115| Name | Type | Mandatory| Description | 4116| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 4117| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 4118| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | 4119| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 4120 4121**Error codes** 4122 4123For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4124 4125| **ID**| **Error Message** | 4126|-----------| ------------------------------------------------------------ | 4127| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4128| 14800000 | Inner error. | 4129| 14800014 | The RdbStore or ResultSet is already closed. | 4130| 14800015 | The database does not respond. | 4131 4132**Example** 4133 4134```ts 4135let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 4136predicates.equalTo("NAME", "Rose"); 4137if (store != undefined) { 4138 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], async (err, resultSet) => { 4139 if (err) { 4140 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4141 return; 4142 } 4143 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4144 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4145 while (resultSet.goToNextRow()) { 4146 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4147 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4148 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4149 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4150 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4151 } 4152 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4153 resultSet.close(); 4154 }); 4155} 4156``` 4157 4158### query 4159 4160query(predicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> 4161 4162Queries 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. 4163 4164**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4165 4166**Parameters** 4167 4168| Name | Type | Mandatory| Description | 4169| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 4170| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 4171| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 4172 4173**Error codes** 4174 4175For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4176 4177| **ID**| **Error Message** | 4178|-----------| ------------------------------------------------------------ | 4179| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4180| 14800000 | Inner error. | 4181| 14800014 | The RdbStore or ResultSet is already closed. | 4182| 14800015 | The database does not respond. | 4183 4184**Return value** 4185 4186| Type | Description | 4187| ------------------------------------------------------- | -------------------------------------------------- | 4188| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 4189 4190**Example** 4191 4192```ts 4193import { BusinessError } from '@kit.BasicServicesKit'; 4194 4195let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 4196predicates.equalTo("NAME", "Rose"); 4197if (store != undefined) { 4198 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then(async (resultSet: relationalStore.ResultSet) => { 4199 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4200 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4201 while (resultSet.goToNextRow()) { 4202 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4203 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4204 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4205 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4206 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4207 } 4208 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4209 resultSet.close(); 4210 }).catch((err: BusinessError) => { 4211 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4212 }); 4213} 4214``` 4215 4216### querySync<sup>12+</sup> 4217 4218querySync(predicates: RdbPredicates, columns?: Array<string>):ResultSet 4219 4220Queries data in a database based on specified conditions. This API returns the result synchronously. If complex logic and a large number of loops are involved in the operations on the **resultSet** obtained by **querySync()**, the freeze problem may occur. You are advised to perform this operation in the [taskpool](../apis-arkts/js-apis-taskpool.md) thread. 4221 4222**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4223 4224**Parameters** 4225 4226| Name | Type | Mandatory| Description | 4227| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ | 4228| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 4229| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns. <br>Default value: null.| 4230 4231**Error codes** 4232 4233For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4234 4235| **ID**| **Error Message** | 4236| ------------ | ------------------------------------------------------------ | 4237| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4238| 14800000 | Inner error. | 4239| 14800014 | The RdbStore or ResultSet is already closed. | 4240| 14800015 | The database does not respond. | 4241 4242**Return value** 4243 4244| Type | Description | 4245| ----------------------- | ----------------------------------- | 4246| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 4247 4248**Example** 4249 4250```ts 4251import { BusinessError } from '@kit.BasicServicesKit'; 4252 4253let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 4254predicates.equalTo("NAME", "Rose"); 4255if (store != undefined) { 4256 try { 4257 let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); 4258 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4259 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4260 while (resultSet.goToNextRow()) { 4261 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4262 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4263 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4264 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4265 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4266 } 4267 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4268 resultSet.close(); 4269 } catch (err) { 4270 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4271 } 4272} 4273``` 4274 4275### remoteQuery 4276 4277remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string> , callback: AsyncCallback<ResultSet>): void 4278 4279Queries data from the RDB store of a remote device based on specified conditions. This API uses an asynchronous callback to return the result. 4280 4281> **NOTE** 4282> 4283> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 4284 4285**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4286 4287**Parameters** 4288 4289| Name | Type | Mandatory| Description | 4290| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- | 4291| device | string | Yes | ID of the remote device. | 4292| table | string | Yes | Name of the target table. | 4293| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 4294| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | 4295| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 4296 4297**Error codes** 4298 4299For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4300 4301| **ID**| **Error Message** | 4302|-----------| ------------------------------------------------------------ | 4303| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4304| 801 | Capability not supported. | 4305| 14800000 | Inner error. | 4306| 14800014 | The RdbStore or ResultSet is already closed. | 4307 4308**Example** 4309 4310```ts 4311import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 4312import { BusinessError } from '@kit.BasicServicesKit'; 4313 4314let dmInstance: distributedDeviceManager.DeviceManager; 4315let deviceId: string | undefined = undefined; 4316 4317try { 4318 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 4319 let devices = dmInstance.getAvailableDeviceListSync(); 4320 if (deviceId != undefined) { 4321 deviceId = devices[0].networkId; 4322 } 4323} catch (err) { 4324 let code = (err as BusinessError).code; 4325 let message = (err as BusinessError).message; 4326 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 4327} 4328 4329let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 4330predicates.greaterThan("id", 0); 4331if (store != undefined && deviceId != undefined) { 4332 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then(async (resultSet: relationalStore.ResultSet) => { 4333 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4334 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4335 while (resultSet.goToNextRow()) { 4336 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4337 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4338 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4339 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4340 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4341 } 4342 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4343 resultSet.close(); 4344 }).catch((err: BusinessError) => { 4345 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 4346 }); 4347} 4348``` 4349 4350### remoteQuery 4351 4352remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string>): Promise<ResultSet> 4353 4354Queries data from the RDB store of a remote device based on specified conditions. This API uses a promise to return the result. 4355 4356> **NOTE** 4357> 4358> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 4359 4360**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4361 4362**Parameters** 4363 4364| Name | Type | Mandatory| Description | 4365| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 4366| device | string | Yes | ID of the remote device. | 4367| table | string | Yes | Name of the target table. | 4368| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 4369| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns.| 4370 4371**Return value** 4372 4373| Type | Description | 4374| ------------------------------------------------------------ | -------------------------------------------------- | 4375| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 4376 4377**Error codes** 4378 4379For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4380 4381| **ID**| **Error Message** | 4382|-----------| ------------------------------------------------------------ | 4383| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4384| 801 | Capability not supported. | 4385| 14800000 | Inner error. | 4386| 14800014 | The RdbStore or ResultSet is already closed. | 4387 4388**Example** 4389 4390```ts 4391import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 4392import { BusinessError } from '@kit.BasicServicesKit'; 4393 4394let dmInstance: distributedDeviceManager.DeviceManager; 4395let deviceId: string | undefined = undefined; 4396 4397try { 4398 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 4399 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 4400 if (devices != undefined) { 4401 deviceId = devices[0].networkId; 4402 } 4403} catch (err) { 4404 let code = (err as BusinessError).code; 4405 let message = (err as BusinessError).message; 4406 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 4407} 4408 4409let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 4410predicates.greaterThan("id", 0); 4411if (store != undefined && deviceId != undefined) { 4412 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then(async (resultSet: relationalStore.ResultSet) => { 4413 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4414 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4415 while (resultSet.goToNextRow()) { 4416 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4417 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4418 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4419 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4420 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4421 } 4422 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4423 resultSet.close(); 4424 }).catch((err: BusinessError) => { 4425 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 4426 }); 4427} 4428``` 4429 4430### querySql<sup>10+</sup> 4431 4432querySql(sql: string, callback: AsyncCallback<ResultSet>):void 4433 4434Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. This API uses an asynchronous callback to return the result. 4435 4436This API is supported in [vector store](#storeconfig). For details about the supported syntax, see [Specifications](../../database/data-persistence-by-vector-store.md#specifications). 4437 4438Aggregate functions cannot be nested. 4439 4440**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4441 4442**Parameters** 4443 4444| Name | Type | Mandatory| Description | 4445| -------- | -------------------------------------------- | ---- |---------------------------------------| 4446| sql | string | Yes | SQL statement to run. | 4447| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 4448 4449**Error codes** 4450 4451For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4452 4453| **ID**| **Error Message** | 4454|-----------| ------------------------------------------------------------ | 4455| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4456| 14800000 | Inner error. | 4457| 14800014 | The RdbStore or ResultSet is already closed. | 4458| 14800015 | The database does not respond. | 4459 4460**Example** 4461 4462RDB store: 4463 4464```ts 4465if (store != undefined) { 4466 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'", async (err, resultSet) => { 4467 if (err) { 4468 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4469 return; 4470 } 4471 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4472 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4473 while (resultSet.goToNextRow()) { 4474 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4475 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4476 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4477 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4478 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4479 } 4480 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4481 resultSet.close(); 4482 }); 4483} 4484``` 4485 4486Vector store: 4487 4488```ts 4489// <-> means to calculate vector similarity, and <=> means to calculate the cosine distance. 4490const querySql = "select id, repr <-> '[1.5,5.6]' as distance from test ORDER BY repr <-> '[1.5,5.6]' limit 10 offset 1;"; 4491let resultSet = await store.querySql(querySql); 4492 4493// Aggregate query. GROUP BY supports multiple columns. 4494const querySql1 = "select id, repr from test group by id, repr having max(repr<=>'[1.5,5.6]');"; 4495let resultSet1 = await store.querySql(querySql1); 4496 4497// Subquery. A maximum of 32 nested layers are supported. 4498const querySql2 = "select * from test where id in (select id from test1)"; 4499let resultSet2 = await store.querySql(querySql2); 4500``` 4501 4502### querySql 4503 4504querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void 4505 4506Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. This API uses an asynchronous callback to return the result. 4507 4508This API is supported in [vector store](#storeconfig). For details about the supported syntax, see [Specifications](../../database/data-persistence-by-vector-store.md#specifications). 4509 4510Aggregate functions cannot be nested. 4511 4512**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4513 4514**Parameters** 4515 4516| Name | Type | Mandatory| Description | 4517| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | 4518| sql | string | Yes | SQL statement to run. | 4519| 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.| 4520| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned. | 4521 4522**Error codes** 4523 4524For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4525 4526| **ID**| **Error Message** | 4527|-----------| ------------------------------------------------------------ | 4528| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4529| 14800000 | Inner error. | 4530| 14800014 | The RdbStore or ResultSet is already closed. | 4531| 14800015 | The database does not respond. | 4532 4533**Example** 4534 4535```ts 4536if (store != undefined) { 4537 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], async (err, resultSet) => { 4538 if (err) { 4539 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4540 return; 4541 } 4542 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4543 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4544 while (resultSet.goToNextRow()) { 4545 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4546 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4547 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4548 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4549 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4550 } 4551 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4552 resultSet.close(); 4553 }); 4554} 4555``` 4556 4557### querySql 4558 4559querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> 4560 4561Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. This API uses a promise to return the result. 4562 4563This API is supported in [vector store](#storeconfig). For details about the supported syntax, see [Specifications](../../database/data-persistence-by-vector-store.md#specifications). 4564 4565Aggregate functions cannot be nested. 4566 4567**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4568 4569**Parameters** 4570 4571| Name | Type | Mandatory| Description | 4572| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4573| sql | string | Yes | SQL statement to run. | 4574| 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.| 4575 4576**Return value** 4577 4578| Type | Description | 4579| ------------------------------------------------------- | -------------------------------------------------- | 4580| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 4581 4582**Error codes** 4583 4584For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4585 4586| **ID**| **Error Message** | 4587|-----------| ------------------------------------------------------------ | 4588| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4589| 14800000 | Inner error. | 4590| 14800014 | The RdbStore or ResultSet is already closed. | 4591| 14800015 | The database does not respond. | 4592 4593**Example** 4594 4595RDB store: 4596 4597```ts 4598import { BusinessError } from '@kit.BasicServicesKit'; 4599 4600if (store != undefined) { 4601 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then(async (resultSet: relationalStore.ResultSet) => { 4602 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4603 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4604 while (resultSet.goToNextRow()) { 4605 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4606 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4607 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4608 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4609 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4610 } 4611 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4612 resultSet.close(); 4613 }).catch((err: BusinessError) => { 4614 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4615 }); 4616} 4617``` 4618 4619Vector store: 4620 4621```ts 4622// Query the top 10 records with ID of 1 and the similarity to [1.5, 2.5] is less than 0.5, and sort them in ascending order by similarity. 4623const querySql = "select id, repr <-> ? as distance from test where id = ? and repr <-> ? < 0.5 ORDER BY repr <-> ? limit 10;"; 4624const vectorValue: Float32Array = new Float32Array([1.5, 2.5]); 4625let resultSet = await store.querySql(querySql, [vectorValue, 1, vectorValue, vectorValue]); 4626``` 4627 4628### querySqlSync<sup>12+</sup> 4629 4630querySqlSync(sql: string, bindArgs?: Array<ValueType>):ResultSet 4631 4632Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. If complex logic and a large number of loops are involved in the operations on the **resultSet** obtained by **querySync()**, the freeze problem may occur. You are advised to perform this operation in the [taskpool](../apis-arkts/js-apis-taskpool.md) thread. 4633 4634**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4635 4636**Parameters** 4637 4638| Name | Type | Mandatory| Description | 4639| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4640| sql | string | Yes | SQL statement to run. | 4641| 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. <br>Default value: null.| 4642 4643**Return value** 4644 4645| Type | Description | 4646| ----------------------- | ----------------------------------- | 4647| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 4648 4649**Error codes** 4650 4651For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4652 4653| **ID**| **Error Message** | 4654| ------------ | ------------------------------------------------------------ | 4655| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4656| 14800000 | Inner error. | 4657| 14800014 | The RdbStore or ResultSet is already closed. | 4658| 14800015 | The database does not respond. | 4659 4660**Example** 4661 4662```ts 4663import { BusinessError } from '@kit.BasicServicesKit'; 4664 4665if (store != undefined) { 4666 try { 4667 let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'"); 4668 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4669 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4670 while (resultSet.goToNextRow()) { 4671 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4672 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4673 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4674 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4675 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4676 } 4677 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4678 resultSet.close(); 4679 } catch (err) { 4680 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4681 } 4682} 4683``` 4684 4685### executeSql<sup>10+</sup> 4686 4687executeSql(sql: string, callback: AsyncCallback<void>):void 4688 4689Executes an SQL statement that contains specified arguments but returns no value. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses an asynchronous callback to return the result. 4690 4691This 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). 4692 4693Statements separated by semicolons (\;) are not supported. 4694 4695**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4696 4697**Parameters** 4698 4699| Name | Type | Mandatory| Description | 4700| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4701| sql | string | Yes | SQL statement to run. | 4702| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4703 4704**Error codes** 4705 4706For 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). 4707 4708| **ID**| **Error Message** | 4709|-----------| ------------------------------------------------------------ | 4710| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4711| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4712| 14800000 | Inner error. | 4713| 14800011 | Failed to open the database because it is corrupted. | 4714| 14800014 | The RdbStore or ResultSet is already closed. | 4715| 14800015 | The database does not respond. | 4716| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 4717| 14800022 | SQLite: Callback routine requested an abort. | 4718| 14800023 | SQLite: Access permission denied. | 4719| 14800024 | SQLite: The database file is locked. | 4720| 14800025 | SQLite: A table in the database is locked. | 4721| 14800026 | SQLite: The database is out of memory. | 4722| 14800027 | SQLite: Attempt to write a readonly database. | 4723| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4724| 14800029 | SQLite: The database is full. | 4725| 14800030 | SQLite: Unable to open the database file. | 4726| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4727| 14800032 | SQLite: Abort due to constraint violation. | 4728| 14800033 | SQLite: Data type mismatch. | 4729| 14800034 | SQLite: Library used incorrectly. | 4730| 14800047 | The WAL file size exceeds the default limit. | 4731 4732**Example** 4733 4734```ts 4735const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"; 4736if (store != undefined) { 4737 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, (err) => { 4738 if (err) { 4739 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4740 return; 4741 } 4742 console.info('Delete table done.'); 4743 }); 4744} 4745``` 4746 4747### executeSql 4748 4749executeSql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<void>):void 4750 4751Executes an SQL statement that contains specified arguments but returns no value. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses an asynchronous callback to return the result. 4752 4753This 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). 4754 4755Statements separated by semicolons (\;) are not supported. 4756 4757**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4758 4759**Parameters** 4760 4761| Name | Type | Mandatory| Description | 4762| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4763| sql | string | Yes | SQL statement to run. | 4764| 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.| 4765| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4766 4767**Error codes** 4768 4769For 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). 4770 4771| **ID**| **Error Message** | 4772|-----------| ------------------------------------------------------------ | 4773| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4774| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4775| 14800000 | Inner error. | 4776| 14800011 | Failed to open the database because it is corrupted. | 4777| 14800014 | The RdbStore or ResultSet is already closed. | 4778| 14800015 | The database does not respond. | 4779| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 4780| 14800022 | SQLite: Callback routine requested an abort. | 4781| 14800023 | SQLite: Access permission denied. | 4782| 14800024 | SQLite: The database file is locked. | 4783| 14800025 | SQLite: A table in the database is locked. | 4784| 14800026 | SQLite: The database is out of memory. | 4785| 14800027 | SQLite: Attempt to write a readonly database. | 4786| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4787| 14800029 | SQLite: The database is full. | 4788| 14800030 | SQLite: Unable to open the database file. | 4789| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4790| 14800032 | SQLite: Abort due to constraint violation. | 4791| 14800033 | SQLite: Data type mismatch. | 4792| 14800034 | SQLite: Library used incorrectly. | 4793| 14800047 | The WAL file size exceeds the default limit. | 4794 4795**Example** 4796 4797```ts 4798const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?"; 4799if (store != undefined) { 4800 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, ['zhangsan'], (err) => { 4801 if (err) { 4802 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4803 return; 4804 } 4805 console.info('Delete table done.'); 4806 }); 4807} 4808``` 4809 4810### executeSql 4811 4812executeSql(sql: string, bindArgs?: Array<ValueType>):Promise<void> 4813 4814Executes an SQL statement that contains specified arguments but returns no value. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses a promise to return the result. 4815 4816This 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). 4817 4818Statements separated by semicolons (\;) are not supported. 4819 4820**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4821 4822**Parameters** 4823 4824| Name | Type | Mandatory| Description | 4825| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4826| sql | string | Yes | SQL statement to run. | 4827| 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.| 4828 4829**Return value** 4830 4831| Type | Description | 4832| ------------------- | ------------------------- | 4833| Promise<void> | Promise that returns no value.| 4834 4835**Error codes** 4836 4837For 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). 4838 4839| **ID**| **Error Message** | 4840|-----------| ------------------------------------------------------------ | 4841| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4842| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4843| 14800000 | Inner error. | 4844| 14800011 | Failed to open the database because it is corrupted. | 4845| 14800014 | The RdbStore or ResultSet is already closed. | 4846| 14800015 | The database does not respond. | 4847| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 4848| 14800022 | SQLite: Callback routine requested an abort. | 4849| 14800023 | SQLite: Access permission denied. | 4850| 14800024 | SQLite: The database file is locked. | 4851| 14800025 | SQLite: A table in the database is locked. | 4852| 14800026 | SQLite: The database is out of memory. | 4853| 14800027 | SQLite: Attempt to write a readonly database. | 4854| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4855| 14800029 | SQLite: The database is full. | 4856| 14800030 | SQLite: Unable to open the database file. | 4857| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4858| 14800032 | SQLite: Abort due to constraint violation. | 4859| 14800033 | SQLite: Data type mismatch. | 4860| 14800034 | SQLite: Library used incorrectly. | 4861| 14800047 | The WAL file size exceeds the default limit. | 4862 4863**Example** 4864 4865```ts 4866import { BusinessError } from '@kit.BasicServicesKit'; 4867 4868const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"; 4869if (store != undefined) { 4870 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE).then(() => { 4871 console.info('Delete table done.'); 4872 }).catch((err: BusinessError) => { 4873 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4874 }); 4875} 4876``` 4877 4878### execute<sup>12+</sup> 4879 4880execute(sql: string, args?: Array<ValueType>):Promise<ValueType> 4881 4882Executes an SQL statement that contains specified arguments. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses a promise to return a value of the ValueType type. 4883 4884This 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. 4885 4886This 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). 4887 4888When this API is used to insert data originating from a subquery to a vector store, full-field insertion is supported, but partial-field insertion is not yet supported. 4889 4890Statements separated by semicolons (\;) are not supported. 4891 4892**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4893 4894**Parameters** 4895 4896| Name | Type | Mandatory| Description | 4897| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4898| sql | string | Yes | SQL statement to run. | 4899| 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.| 4900 4901**Return value** 4902 4903| Type | Description | 4904| ------------------- | ------------------------- | 4905| Promise<[ValueType](#valuetype)> | Promise used to return the SQL execution result.| 4906 4907**Error codes** 4908 4909For 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). 4910 4911| **ID**| **Error Message** | 4912|-----------| ------------------------------------------------------------ | 4913| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4914| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4915| 14800000 | Inner error. | 4916| 14800011 | Failed to open the database because it is corrupted. | 4917| 14800014 | The RdbStore or ResultSet is already closed. | 4918| 14800015 | The database does not respond. | 4919| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 4920| 14800022 | SQLite: Callback routine requested an abort. | 4921| 14800023 | SQLite: Access permission denied. | 4922| 14800024 | SQLite: The database file is locked. | 4923| 14800025 | SQLite: A table in the database is locked. | 4924| 14800026 | SQLite: The database is out of memory. | 4925| 14800027 | SQLite: Attempt to write a readonly database. | 4926| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4927| 14800029 | SQLite: The database is full. | 4928| 14800030 | SQLite: Unable to open the database file. | 4929| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4930| 14800032 | SQLite: Abort due to constraint violation. | 4931| 14800033 | SQLite: Data type mismatch. | 4932| 14800034 | SQLite: Library used incorrectly. | 4933| 14800047 | The WAL file size exceeds the default limit. | 4934 4935**Example** 4936 4937RDB store: 4938 4939```ts 4940import { BusinessError } from '@kit.BasicServicesKit'; 4941 4942// Check the RDB store integrity. 4943if (store != undefined) { 4944 const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check'; 4945 (store as relationalStore.RdbStore).execute(SQL_CHECK_INTEGRITY).then((data) => { 4946 console.info(`check result: ${data}`); 4947 }).catch((err: BusinessError) => { 4948 console.error(`check failed, code is ${err.code}, message is ${err.message}`); 4949 }); 4950} 4951 4952// Delete all data from the table. 4953if (store != undefined) { 4954 const SQL_DELETE_TABLE = 'DELETE FROM test'; 4955 (store as relationalStore.RdbStore).execute(SQL_DELETE_TABLE).then((data) => { 4956 console.info(`delete result: ${data}`); 4957 }).catch((err: BusinessError) => { 4958 console.error(`delete failed, code is ${err.code}, message is ${err.message}`); 4959 }); 4960} 4961 4962// Delete a table. 4963if (store != undefined) { 4964 const SQL_DROP_TABLE = 'DROP TABLE test'; 4965 (store as relationalStore.RdbStore).execute(SQL_DROP_TABLE).then((data) => { 4966 console.info(`drop result: ${data}`); 4967 }).catch((err: BusinessError) => { 4968 console.error(`drop failed, code is ${err.code}, message is ${err.message}`); 4969 }); 4970} 4971``` 4972 4973Vector store: 4974 4975```ts 4976// FLOATVECTOR(2) is a vector property with a dimension of 2. The subsequent repr operation should be performed based on this dimension. 4977let createSql = "CREATE TABLE test (ID INTEGER PRIMARY KEY,REPR FLOATVECTOR(2));"; 4978// Create a table. 4979await store!.execute(createSql); 4980// Insert data using parameter binding. 4981let insertSql = "insert into test VALUES(?, ?);"; 4982const vectorValue: Float32Array = Float32Array.from([1.5, 6.6]); 4983await store!.execute(insertSql, [0, vectorValue]); 4984// Execute without using bound parameters. 4985await store!.execute("insert into test values(1, '[3.5, 1.8]');"); 4986``` 4987 4988### execute<sup>12+</sup> 4989 4990execute(sql: string, txId: number, args?: Array<ValueType>): Promise<ValueType> 4991 4992Executes an SQL statement that contains specified arguments. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses a promise to return the result. 4993 4994This API supports only [vector stores](#storeconfig). When this API is used to insert data originating from a subquery, full-field insertion is supported, but partial-field insertion is not yet supported. 4995 4996This API does not support data query. To query data, use [querySql](#querysql10). 4997 4998Statements separated by semicolons (\;) are not supported. 4999 5000**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5001 5002**Parameters** 5003 5004| Name | Type | Mandatory| Description | 5005| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 5006| sql | string | Yes | SQL statement to run. | 5007| 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. | 5008| 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 parameter statement is considered complete.| 5009 5010**Return value** 5011 5012| Type | Description | 5013| ------------------- | ------------------------- | 5014| Promise<[ValueType](#valuetype)> | Promise that returns **null**.| 5015 5016**Error codes** 5017 5018For 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). 5019 5020| **ID**| **Error Message** | 5021|-----------| ------------------------------------------------------------ | 5022| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5023| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 5024| 14800000 | Inner error. | 5025| 14800011 | Failed to open the database because it is corrupted. | 5026| 14800014 | The RdbStore or ResultSet is already closed. | 5027| 14800015 | The database does not respond. | 5028| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5029| 14800022 | SQLite: Callback routine requested an abort. | 5030| 14800023 | SQLite: Access permission denied. | 5031| 14800024 | SQLite: The database file is locked. | 5032| 14800025 | SQLite: A table in the database is locked. | 5033| 14800026 | SQLite: The database is out of memory. | 5034| 14800027 | SQLite: Attempt to write a readonly database. | 5035| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5036| 14800029 | SQLite: The database is full. | 5037| 14800030 | SQLite: Unable to open the database file. | 5038| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5039| 14800032 | SQLite: Abort due to constraint violation. | 5040| 14800033 | SQLite: Data type mismatch. | 5041| 14800034 | SQLite: Library used incorrectly. | 5042| 14800047 | The WAL file size exceeds the default limit. | 5043 5044**Example** 5045 5046```ts 5047import { BusinessError } from '@kit.BasicServicesKit'; 5048if (store != null) { 5049 let txId: number; 5050 (store as relationalStore.RdbStore).beginTrans().then((txId: number) => { 5051 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 5052 .then(() => { 5053 (store as relationalStore.RdbStore).commit(txId); 5054 }) 5055 .catch((err: BusinessError) => { 5056 (store as relationalStore.RdbStore).rollback(txId); 5057 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 5058 }); 5059 }); 5060} 5061``` 5062 5063### executeSync<sup>12+</sup> 5064 5065executeSync(sql: string, args?: Array<ValueType>): ValueType 5066 5067Executes an SQL statement that contains specified arguments. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API returns a value of theValueType type. 5068 5069This 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. 5070 5071This 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). 5072 5073Statements separated by semicolons (\;) are not supported. 5074 5075**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5076 5077**Parameters** 5078 5079| Name| Type | Mandatory| Description | 5080| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 5081| sql | string | Yes | SQL statement to run. | 5082| args | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If this parameter is left blank or set to **null** or **undefined**, the SQL statement is complete. <br>Default value: null.| 5083 5084**Return value** 5085 5086| Type | Description | 5087| ----------------------- | ------------------- | 5088| [ValueType](#valuetype) | SQL execution result.| 5089 5090**Error codes** 5091 5092For 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). 5093 5094| **ID**| **Error Message** | 5095| ------------ | ------------------------------------------------------------ | 5096| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5097| 14800000 | Inner error. | 5098| 14800011 | Failed to open the database because it is corrupted. | 5099| 14800014 | The RdbStore or ResultSet is already closed. | 5100| 14800015 | The database does not respond. | 5101| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5102| 14800022 | SQLite: Callback routine requested an abort. | 5103| 14800023 | SQLite: Access permission denied. | 5104| 14800024 | SQLite: The database file is locked. | 5105| 14800025 | SQLite: A table in the database is locked. | 5106| 14800026 | SQLite: The database is out of memory. | 5107| 14800027 | SQLite: Attempt to write a readonly database. | 5108| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5109| 14800029 | SQLite: The database is full. | 5110| 14800030 | SQLite: Unable to open the database file. | 5111| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5112| 14800032 | SQLite: Abort due to constraint violation. | 5113| 14800033 | SQLite: Data type mismatch. | 5114| 14800034 | SQLite: Library used incorrectly. | 5115| 14800047 | The WAL file size exceeds the default limit. | 5116 5117**Example** 5118 5119```ts 5120import { BusinessError } from '@kit.BasicServicesKit'; 5121 5122// Check the RDB store integrity. 5123if (store != undefined) { 5124 const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check'; 5125 try { 5126 let data = (store as relationalStore.RdbStore).executeSync(SQL_CHECK_INTEGRITY); 5127 console.info(`check result: ${data}`); 5128 } catch (err) { 5129 console.error(`check failed, code is ${err.code}, message is ${err.message}`); 5130 } 5131} 5132 5133// Delete all data from the table. 5134if (store != undefined) { 5135 const SQL_DELETE_TABLE = 'DELETE FROM test'; 5136 try { 5137 let data = (store as relationalStore.RdbStore).executeSync(SQL_DELETE_TABLE); 5138 console.info(`delete result: ${data}`); 5139 } catch (err) { 5140 console.error(`delete failed, code is ${err.code}, message is ${err.message}`); 5141 } 5142} 5143 5144// Delete a table. 5145if (store != undefined) { 5146 const SQL_DROP_TABLE = 'DROP TABLE test'; 5147 try { 5148 let data = (store as relationalStore.RdbStore).executeSync(SQL_DROP_TABLE); 5149 console.info(`drop result: ${data}`); 5150 } catch (err) { 5151 console.error(`drop failed, code is ${err.code}, message is ${err.message}`); 5152 } 5153} 5154``` 5155 5156### getModifyTime<sup>10+</sup> 5157 5158getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[], callback: AsyncCallback<ModifyTime>): void 5159 5160Obtains the last modification time of the data in a table. This API uses an asynchronous callback to return the result. 5161 5162**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5163 5164**Parameters** 5165 5166| Name | Type | Mandatory| Description | 5167| ----------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 5168| table | string | Yes | Name of the database table to query. | 5169| columnName | string | Yes | Column name of the database table to query. | 5170| 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.| 5171| callback | AsyncCallback<[ModifyTime](#modifytime10)> | Yes | Callback used to return the result. If the operation is successful, the **ModifyTime** object is returned.| 5172 5173**Error codes** 5174 5175For 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). 5176 5177| **ID**| **Error Message** | 5178|-----------| ------------------------------------------------------------ | 5179| 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. | 5180| 801 | Capability not supported. | 5181| 14800000 | Inner error. | 5182| 14800011 | Failed to open the database because it is corrupted. | 5183| 14800014 | The RdbStore or ResultSet is already closed. | 5184| 14800015 | The database does not respond. | 5185| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5186| 14800022 | SQLite: Callback routine requested an abort. | 5187| 14800023 | SQLite: Access permission denied. | 5188| 14800024 | SQLite: The database file is locked. | 5189| 14800025 | SQLite: A table in the database is locked. | 5190| 14800026 | SQLite: The database is out of memory. | 5191| 14800027 | SQLite: Attempt to write a readonly database. | 5192| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5193| 14800029 | SQLite: The database is full. | 5194| 14800030 | SQLite: Unable to open the database file. | 5195| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5196| 14800032 | SQLite: Abort due to constraint violation. | 5197| 14800033 | SQLite: Data type mismatch. | 5198| 14800034 | SQLite: Library used incorrectly. | 5199 5200**Example** 5201 5202```ts 5203let PRIKey = [1, 4, 2, 3]; 5204if (store != undefined) { 5205 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey, (err, modifyTime: relationalStore.ModifyTime) => { 5206 if (err) { 5207 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 5208 return; 5209 } 5210 let size = modifyTime.size; 5211 }); 5212} 5213``` 5214 5215### getModifyTime<sup>10+</sup> 5216 5217getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[]): Promise<ModifyTime> 5218 5219Obtains the last modification time of the data in a table. This API uses a promise to return the result. 5220 5221**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5222 5223**Parameters** 5224 5225| Name | Type | Mandatory| Description | 5226| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ | 5227| table | string | Yes | Name of the database table to query. | 5228| columnName | string | Yes | Column name of the database table to query. | 5229| 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.| 5230 5231**Return value** 5232 5233| Type | Description | 5234| ------------------------------------------ | --------------------------------------------------------- | 5235| Promise<[ModifyTime](#modifytime10)> | Promise used to return the **ModifyTime** object.| 5236 5237**Error codes** 5238 5239For 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). 5240 5241| **ID**| **Error Message** | 5242|-----------| ------------------------------------------------------------ | 5243| 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. | 5244| 801 | Capability not supported. | 5245| 14800000 | Inner error. | 5246| 14800011 | Failed to open the database because it is corrupted. | 5247| 14800014 | The RdbStore or ResultSet is already closed. | 5248| 14800015 | The database does not respond. | 5249| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 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 5269let PRIKey = [1, 2, 3]; 5270if (store != undefined) { 5271 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey) 5272 .then((modifyTime: relationalStore.ModifyTime) => { 5273 let size = modifyTime.size; 5274 }) 5275 .catch((err: BusinessError) => { 5276 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 5277 }); 5278} 5279``` 5280 5281### beginTransaction 5282 5283beginTransaction():void 5284 5285Begins a transaction before executing an SQL statement. 5286This API does not allow nested transactions and cannot be used across processes or threads. 5287 5288**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5289 5290**Error codes** 5291 5292For 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). 5293 5294| **ID**| **Error Message** | 5295|-----------| ------------------------------------------------------------ | 5296| 401 | Parameter error. The store must not be nullptr. | 5297| 14800000 | Inner error. | 5298| 14800011 | Failed to open the database because it is corrupted. | 5299| 14800014 | The RdbStore or ResultSet is already closed. | 5300| 14800015 | The database does not respond. | 5301| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5302| 14800022 | SQLite: Callback routine requested an abort. | 5303| 14800023 | SQLite: Access permission denied. | 5304| 14800024 | SQLite: The database file is locked. | 5305| 14800025 | SQLite: A table in the database is locked. | 5306| 14800026 | SQLite: The database is out of memory. | 5307| 14800027 | SQLite: Attempt to write a readonly database. | 5308| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5309| 14800029 | SQLite: The database is full. | 5310| 14800030 | SQLite: Unable to open the database file. | 5311| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5312| 14800032 | SQLite: Abort due to constraint violation. | 5313| 14800033 | SQLite: Data type mismatch. | 5314| 14800034 | SQLite: Library used incorrectly. | 5315| 14800047 | The WAL file size exceeds the default limit. | 5316 5317**Example** 5318 5319```ts 5320let value1 = "Lisa"; 5321let value2 = 18; 5322let value3 = 100.5; 5323let value4 = new Uint8Array([1, 2, 3]); 5324 5325if (store != undefined) { 5326 (store as relationalStore.RdbStore).beginTransaction(); 5327 const valueBucket: relationalStore.ValuesBucket = { 5328 'NAME': value1, 5329 'AGE': value2, 5330 'SALARY': value3, 5331 'CODES': value4 5332 }; 5333 (store as relationalStore.RdbStore).insert("test", valueBucket); 5334 (store as relationalStore.RdbStore).commit(); 5335} 5336``` 5337 5338### beginTrans<sup>12+</sup> 5339 5340beginTrans(): Promise<number> 5341 5342Begins a transaction before executing the SQL statement. This API uses a promise to return the result. 5343 5344Different from [beginTransaction](#begintransaction), this API returns a transaction ID. [execute](#execute12-1) can specify the transaction ID to isolate different transactions. 5345 5346This API supports only [vector stores](#storeconfig). 5347 5348**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5349 5350**Return value** 5351 5352| Type | Description | 5353| ------------------- | ------------------------- | 5354| Promise<number> | Promise used to return the transaction ID.| 5355 5356**Error codes** 5357 5358For 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). 5359 5360| **ID**| **Error Message** | 5361|-----------| ------------------------------------------------------------ | 5362| 401 | Parameter error. The store must not be nullptr. | 5363| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 5364| 14800000 | Inner error. | 5365| 14800011 | Failed to open the database because it is corrupted. | 5366| 14800014 | The RdbStore or ResultSet is already closed. | 5367| 14800015 | The database does not respond. | 5368| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5369| 14800022 | SQLite: Callback routine requested an abort. | 5370| 14800023 | SQLite: Access permission denied. | 5371| 14800024 | SQLite: The database file is locked. | 5372| 14800025 | SQLite: A table in the database is locked. | 5373| 14800026 | SQLite: The database is out of memory. | 5374| 14800027 | SQLite: Attempt to write a readonly database. | 5375| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5376| 14800029 | SQLite: The database is full. | 5377| 14800030 | SQLite: Unable to open the database file. | 5378| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5379| 14800032 | SQLite: Abort due to constraint violation. | 5380| 14800033 | SQLite: Data type mismatch. | 5381| 14800034 | SQLite: Library used incorrectly. | 5382| 14800047 | The WAL file size exceeds the default limit. | 5383 5384**Example** 5385 5386```ts 5387import { BusinessError } from '@kit.BasicServicesKit'; 5388if (store != null) { 5389 let txId: number; 5390 (store as relationalStore.RdbStore).beginTrans().then((txId: number) => { 5391 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 5392 .then(() => { 5393 (store as relationalStore.RdbStore).commit(txId); 5394 }) 5395 .catch((err: BusinessError) => { 5396 (store as relationalStore.RdbStore).rollback(txId); 5397 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 5398 }); 5399 }); 5400} 5401``` 5402 5403### createTransaction<sup>14+</sup> 5404 5405createTransaction(options?: TransactionOptions): Promise<Transaction> 5406 5407Creates a transaction object and starts a transaction. This API uses a promise to return the result. 5408 5409Different from [beginTransaction](#begintransaction), **createTransaction()** returns a transaction object, which is isolated from other transaction objects. When a transaction object is used to insert, delete, or update data, these changes cannot be detected by [on ('dataChange')](#ondatachange). 5410 5411A store supports a maximum of four transaction objects at a time. If the number of transaction objects exceeds the upper limit, error 14800015 is returned. In this case, check whether transaction objects are being held too long or whether there are too many concurrent transactions. If the problem cannot be solved through these optimizations, you are advised to create transaction objects after existing transactions are released. 5412 5413You are advised to use **createTransaction** instead of **beginTransaction**. 5414 5415**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5416 5417**Parameters** 5418 5419| Name | Type | Mandatory| Description | 5420| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ | 5421| options | [TransactionOptions](#transactionoptions14) | No | Configuration of the transaction object to create. | 5422 5423**Return value** 5424 5425| Type | Description | 5426| ------------------- | ------------------------- | 5427| Promise<[Transaction](#transaction14)> | Promise used to return the transaction object created.| 5428 5429**Error codes** 5430 5431For 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). 5432 5433| **ID**| **Error Message** | 5434|-----------| ------------------------------------------------------------ | 5435| 14800000 | Inner error. | 5436| 14800011 | Failed to open the database because it is corrupted. | 5437| 14800014 | The RdbStore or ResultSet is already closed. | 5438| 14800015 | The database is busy. | 5439| 14800023 | SQLite: Access permission denied. | 5440| 14800024 | SQLite: The database file is locked. | 5441| 14800026 | SQLite: The database is out of memory. | 5442| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5443| 14800029 | SQLite: The database is full. | 5444| 14800030 | SQLite: Unable to open the database file. | 5445 5446**Example** 5447 5448```ts 5449import { BusinessError } from '@kit.BasicServicesKit'; 5450 5451if (store != undefined) { 5452 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 5453 transaction.execute("DELETE FROM test WHERE age = ? OR age = ?", [21, 20]).then(() => { 5454 transaction.commit(); 5455 }).catch((e: BusinessError) => { 5456 transaction.rollback(); 5457 console.error(`execute sql failed, code is ${e.code},message is ${e.message}`); 5458 }); 5459 }).catch((err: BusinessError) => { 5460 console.error(`createTransaction faided, code is ${err.code},message is ${err.message}`); 5461 }); 5462} 5463``` 5464 5465### commit 5466 5467commit():void 5468 5469Commits the executed SQL statement. This API must be used with [beginTransaction](#begintransaction). 5470This API does not allow nested transactions and cannot be used across processes or threads. 5471 5472**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5473 5474**Error codes** 5475 5476For 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). 5477 5478| **ID**| **Error Message** | 5479|-----------| ------------------------------------------------------------ | 5480| 401 | Parameter error. The store must not be nullptr. | 5481| 14800000 | Inner error. | 5482| 14800011 | Failed to open the database because it is corrupted. | 5483| 14800014 | The RdbStore or ResultSet is already closed. | 5484| 14800015 | The database does not respond. | 5485| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5486| 14800022 | SQLite: Callback routine requested an abort. | 5487| 14800023 | SQLite: Access permission denied. | 5488| 14800024 | SQLite: The database file is locked. | 5489| 14800025 | SQLite: A table in the database is locked. | 5490| 14800026 | SQLite: The database is out of memory. | 5491| 14800027 | SQLite: Attempt to write a readonly database. | 5492| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5493| 14800029 | SQLite: The database is full. | 5494| 14800030 | SQLite: Unable to open the database file. | 5495| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5496| 14800032 | SQLite: Abort due to constraint violation. | 5497| 14800033 | SQLite: Data type mismatch. | 5498| 14800034 | SQLite: Library used incorrectly. | 5499 5500**Example** 5501 5502```ts 5503let value1 = "Lisa"; 5504let value2 = 18; 5505let value3 = 100.5; 5506let value4 = new Uint8Array([1, 2, 3]); 5507 5508if (store != undefined) { 5509 (store as relationalStore.RdbStore).beginTransaction(); 5510 const valueBucket: relationalStore.ValuesBucket = { 5511 'NAME': value1, 5512 'AGE': value2, 5513 'SALARY': value3, 5514 'CODES': value4 5515 }; 5516 (store as relationalStore.RdbStore).insert("test", valueBucket); 5517 (store as relationalStore.RdbStore).commit(); 5518} 5519``` 5520 5521### commit<sup>12+</sup> 5522 5523commit(txId : number):Promise<void> 5524 5525Commits the executed SQL statement. This API must be used with [beginTrans](#begintrans12). 5526 5527This API supports only [vector stores](#storeconfig). 5528 5529**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5530 5531**Parameters** 5532 5533| Name | Type | Mandatory| Description | 5534| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 5535| txId | number | Yes | Transaction ID obtained via [beginTrans](#begintrans12). | 5536 5537**Return value** 5538 5539| Type | Description | 5540| ------------------- | ------------------------- | 5541| Promise<void> | Promise that returns no value.| 5542 5543**Error codes** 5544 5545For 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). 5546 5547| **ID**| **Error Message** | 5548|-----------| ------------------------------------------------------------ | 5549| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5550| 14800000 | Inner error. | 5551| 14800011 | Failed to open the database because it is corrupted. | 5552| 14800014 | The RdbStore or ResultSet is already closed. | 5553| 14800015 | The database does not respond. | 5554| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5555| 14800022 | SQLite: Callback routine requested an abort. | 5556| 14800023 | SQLite: Access permission denied. | 5557| 14800024 | SQLite: The database file is locked. | 5558| 14800025 | SQLite: A table in the database is locked. | 5559| 14800026 | SQLite: The database is out of memory. | 5560| 14800027 | SQLite: Attempt to write a readonly database. | 5561| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5562| 14800029 | SQLite: The database is full. | 5563| 14800030 | SQLite: Unable to open the database file. | 5564| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5565| 14800032 | SQLite: Abort due to constraint violation. | 5566| 14800033 | SQLite: Data type mismatch. | 5567| 14800034 | SQLite: Library used incorrectly. | 5568 5569**Example** 5570 5571```ts 5572import { BusinessError } from '@kit.BasicServicesKit'; 5573if (store != null) { 5574 let txId: number; 5575 (store as relationalStore.RdbStore).beginTrans().then((txId: number) => { 5576 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 5577 .then(() => { 5578 (store as relationalStore.RdbStore).commit(txId); 5579 }) 5580 .catch((err: BusinessError) => { 5581 (store as relationalStore.RdbStore).rollback(txId); 5582 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 5583 }); 5584 }); 5585} 5586``` 5587 5588### rollBack 5589 5590rollBack():void 5591 5592Rolls back the executed SQL statement. 5593This API does not allow nested transactions and cannot be used across processes or threads. 5594 5595**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5596 5597**Error codes** 5598 5599For 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). 5600 5601| **ID**| **Error Message** | 5602|-----------| ------------------------------------------------------------ | 5603| 401 | Parameter error. The store must not be nullptr. | 5604| 14800000 | Inner error. | 5605| 14800011 | Failed to open the database because it is corrupted. | 5606| 14800014 | The RdbStore or ResultSet is already closed. | 5607| 14800015 | The database does not respond. | 5608| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5609| 14800022 | SQLite: Callback routine requested an abort. | 5610| 14800023 | SQLite: Access permission denied. | 5611| 14800024 | SQLite: The database file is locked. | 5612| 14800025 | SQLite: A table in the database is locked. | 5613| 14800026 | SQLite: The database is out of memory. | 5614| 14800027 | SQLite: Attempt to write a readonly database. | 5615| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5616| 14800029 | SQLite: The database is full. | 5617| 14800030 | SQLite: Unable to open the database file. | 5618| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5619| 14800032 | SQLite: Abort due to constraint violation. | 5620| 14800033 | SQLite: Data type mismatch. | 5621| 14800034 | SQLite: Library used incorrectly. | 5622 5623**Example** 5624 5625```ts 5626import { BusinessError } from '@kit.BasicServicesKit'; 5627 5628let value1 = "Lisa"; 5629let value2 = 18; 5630let value3 = 100.5; 5631let value4 = new Uint8Array([1, 2, 3]); 5632 5633if (store != undefined) { 5634 try { 5635 (store as relationalStore.RdbStore).beginTransaction(); 5636 const valueBucket: relationalStore.ValuesBucket = { 5637 'NAME': value1, 5638 'AGE': value2, 5639 'SALARY': value3, 5640 'CODES': value4 5641 }; 5642 (store as relationalStore.RdbStore).insert("test", valueBucket); 5643 (store as relationalStore.RdbStore).commit(); 5644 } catch (err) { 5645 let code = (err as BusinessError).code; 5646 let message = (err as BusinessError).message; 5647 console.error(`Transaction failed, code is ${code},message is ${message}`); 5648 (store as relationalStore.RdbStore).rollBack(); 5649 } 5650} 5651``` 5652 5653### rollback<sup>12+</sup> 5654 5655rollback(txId : number):Promise<void> 5656 5657Rolls back the executed SQL statement. This API must be used with [beginTrans](#begintrans12). 5658 5659This API supports only [vector stores](#storeconfig). 5660 5661**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5662 5663**Parameters** 5664 5665| Name | Type | Mandatory| Description | 5666| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 5667| txId | number | Yes | Transaction ID obtained via [beginTrans](#begintrans12). | 5668 5669**Return value** 5670 5671| Type | Description | 5672| ------------------- | ------------------------- | 5673| Promise<void> | Promise that returns no value.| 5674 5675**Error codes** 5676 5677For 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). 5678 5679| **ID**| **Error Message** | 5680|-----------| ------------------------------------------------------------ | 5681| 401 | Parameter error. The store must not be nullptr. | 5682| 14800000 | Inner error. | 5683| 14800011 | Failed to open the database because it is corrupted. | 5684| 14800014 | The RdbStore or ResultSet is already closed. | 5685| 14800015 | The database does not respond. | 5686| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5687| 14800022 | SQLite: Callback routine requested an abort. | 5688| 14800023 | SQLite: Access permission denied. | 5689| 14800024 | SQLite: The database file is locked. | 5690| 14800025 | SQLite: A table in the database is locked. | 5691| 14800026 | SQLite: The database is out of memory. | 5692| 14800027 | SQLite: Attempt to write a readonly database. | 5693| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5694| 14800029 | SQLite: The database is full. | 5695| 14800030 | SQLite: Unable to open the database file. | 5696| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5697| 14800032 | SQLite: Abort due to constraint violation. | 5698| 14800033 | SQLite: Data type mismatch. | 5699| 14800034 | SQLite: Library used incorrectly. | 5700 5701**Example** 5702 5703```ts 5704import { BusinessError } from '@kit.BasicServicesKit'; 5705if (store != null) { 5706 let txId: number; 5707 (store as relationalStore.RdbStore).beginTrans().then((txId: number) => { 5708 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 5709 .then(() => { 5710 (store as relationalStore.RdbStore).commit(txId); 5711 }) 5712 .catch((err: BusinessError) => { 5713 (store as relationalStore.RdbStore).rollback(txId); 5714 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 5715 }); 5716 }); 5717} 5718``` 5719 5720### backup 5721 5722backup(destName:string, callback: AsyncCallback<void>):void 5723 5724Backs up an RDB store. This API uses an asynchronous callback to return the result. 5725 5726This API is supported in the [vector store](#storeconfig) only. 5727 5728**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5729 5730**Parameters** 5731 5732| Name | Type | Mandatory| Description | 5733| -------- | ------------------------- | ---- | ------------------------ | 5734| destName | string | Yes | Name of the RDB store backup file.| 5735| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5736 5737**Error codes** 5738 5739For 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). 5740 5741| **ID**| **Error Message** | 5742|-----------| ------------------------------------------------------------ | 5743| 401 | Parameter error. The store must not be nullptr. | 5744| 14800000 | Inner error. | 5745| 14800010 | Failed to open or delete the database by an invalid database path. | 5746| 14800011 | Failed to open the database because it is corrupted. | 5747| 14800014 | The RdbStore or ResultSet is already closed. | 5748| 14800015 | The database does not respond. | 5749| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5750| 14800022 | SQLite: Callback routine requested an abort. | 5751| 14800023 | SQLite: Access permission denied. | 5752| 14800024 | SQLite: The database file is locked. | 5753| 14800025 | SQLite: A table in the database is locked. | 5754| 14800026 | SQLite: The database is out of memory. | 5755| 14800027 | SQLite: Attempt to write a readonly database. | 5756| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5757| 14800029 | SQLite: The database is full. | 5758| 14800030 | SQLite: Unable to open the database file. | 5759| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5760| 14800032 | SQLite: Abort due to constraint violation. | 5761| 14800033 | SQLite: Data type mismatch. | 5762| 14800034 | SQLite: Library used incorrectly. | 5763 5764**Example** 5765 5766```ts 5767if (store != undefined) { 5768 (store as relationalStore.RdbStore).backup("dbBackup.db", (err) => { 5769 if (err) { 5770 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 5771 return; 5772 } 5773 console.info('Backup success.'); 5774 }); 5775} 5776``` 5777 5778### backup 5779 5780backup(destName:string): Promise<void> 5781 5782Backs up an RDB store. This API uses a promise to return the result. 5783 5784This API is supported in the [vector store](#storeconfig) only. 5785 5786**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5787 5788**Parameters** 5789 5790| Name | Type | Mandatory| Description | 5791| -------- | ------ | ---- | ------------------------ | 5792| destName | string | Yes | Name of the RDB store backup file.| 5793 5794**Return value** 5795 5796| Type | Description | 5797| ------------------- | ------------------------- | 5798| Promise<void> | Promise that returns no value.| 5799 5800**Error codes** 5801 5802For 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). 5803 5804| **ID**| **Error Message** | 5805|-----------| ------------------------------------------------------------ | 5806| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5807| 14800000 | Inner error. | 5808| 14800011 | Failed to open the database because it is corrupted. | 5809| 14800014 | The RdbStore or ResultSet is already closed. | 5810| 14800015 | The database does not respond. | 5811| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5812| 14800022 | SQLite: Callback routine requested an abort. | 5813| 14800023 | SQLite: Access permission denied. | 5814| 14800024 | SQLite: The database file is locked. | 5815| 14800025 | SQLite: A table in the database is locked. | 5816| 14800026 | SQLite: The database is out of memory. | 5817| 14800027 | SQLite: Attempt to write a readonly database. | 5818| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5819| 14800029 | SQLite: The database is full. | 5820| 14800030 | SQLite: Unable to open the database file. | 5821| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5822| 14800032 | SQLite: Abort due to constraint violation. | 5823| 14800033 | SQLite: Data type mismatch. | 5824| 14800034 | SQLite: Library used incorrectly. | 5825 5826**Example** 5827 5828```ts 5829import { BusinessError } from '@kit.BasicServicesKit'; 5830 5831if (store != undefined) { 5832 let promiseBackup = (store as relationalStore.RdbStore).backup("dbBackup.db"); 5833 promiseBackup.then(() => { 5834 console.info('Backup success.'); 5835 }).catch((err: BusinessError) => { 5836 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 5837 }); 5838} 5839``` 5840 5841### restore 5842 5843restore(srcName:string, callback: AsyncCallback<void>):void 5844 5845Restores an RDB store from a backup file. This API uses an asynchronous callback to return the result. 5846 5847This API is supported in the [vector store](#storeconfig) only. 5848 5849**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5850 5851**Parameters** 5852 5853| Name | Type | Mandatory| Description | 5854| -------- | ------------------------- | ---- | ------------------------ | 5855| srcName | string | Yes | Name of the RDB store backup file.| 5856| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5857 5858**Error codes** 5859 5860For 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). 5861 5862| **ID**| **Error Message** | 5863|-----------| ------------------------------------------------------------ | 5864| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5865| 14800000 | Inner error. | 5866| 14800011 | Failed to open the database because it is corrupted. | 5867| 14800014 | The RdbStore or ResultSet is already closed. | 5868| 14800015 | The database does not respond. | 5869| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5870| 14800022 | SQLite: Callback routine requested an abort. | 5871| 14800023 | SQLite: Access permission denied. | 5872| 14800024 | SQLite: The database file is locked. | 5873| 14800025 | SQLite: A table in the database is locked. | 5874| 14800026 | SQLite: The database is out of memory. | 5875| 14800027 | SQLite: Attempt to write a readonly database. | 5876| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5877| 14800029 | SQLite: The database is full. | 5878| 14800030 | SQLite: Unable to open the database file. | 5879| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5880| 14800032 | SQLite: Abort due to constraint violation. | 5881| 14800033 | SQLite: Data type mismatch. | 5882| 14800034 | SQLite: Library used incorrectly. | 5883 5884**Example** 5885 5886```ts 5887if (store != undefined) { 5888 (store as relationalStore.RdbStore).restore("dbBackup.db", (err) => { 5889 if (err) { 5890 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 5891 return; 5892 } 5893 console.info('Restore success.'); 5894 }); 5895} 5896``` 5897 5898### restore 5899 5900restore(srcName:string): Promise<void> 5901 5902Restores an RDB store from a backup file. This API uses a promise to return the result. 5903 5904This API is supported in the [vector store](#storeconfig) only. 5905 5906**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5907 5908**Parameters** 5909 5910| Name | Type | Mandatory| Description | 5911| ------- | ------ | ---- | ------------------------ | 5912| srcName | string | Yes | Name of the RDB store backup file.| 5913 5914**Return value** 5915 5916| Type | Description | 5917| ------------------- | ------------------------- | 5918| Promise<void> | Promise that returns no value.| 5919 5920**Error codes** 5921 5922For 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). 5923 5924| **ID**| **Error Message** | 5925|-----------| ------------------------------------------------------------ | 5926| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5927| 14800000 | Inner error. | 5928| 14800011 | Failed to open the database because it is corrupted. | 5929| 14800014 | The RdbStore or ResultSet is already closed. | 5930| 14800015 | The database does not respond. | 5931| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 5932| 14800022 | SQLite: Callback routine requested an abort. | 5933| 14800023 | SQLite: Access permission denied. | 5934| 14800024 | SQLite: The database file is locked. | 5935| 14800025 | SQLite: A table in the database is locked. | 5936| 14800026 | SQLite: The database is out of memory. | 5937| 14800027 | SQLite: Attempt to write a readonly database. | 5938| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5939| 14800029 | SQLite: The database is full. | 5940| 14800030 | SQLite: Unable to open the database file. | 5941| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5942| 14800032 | SQLite: Abort due to constraint violation. | 5943| 14800033 | SQLite: Data type mismatch. | 5944| 14800034 | SQLite: Library used incorrectly. | 5945 5946**Example** 5947 5948```ts 5949import { BusinessError } from '@kit.BasicServicesKit'; 5950 5951if (store != undefined) { 5952 let promiseRestore = (store as relationalStore.RdbStore).restore("dbBackup.db"); 5953 promiseRestore.then(() => { 5954 console.info('Restore success.'); 5955 }).catch((err: BusinessError) => { 5956 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 5957 }); 5958} 5959``` 5960 5961### setDistributedTables 5962 5963setDistributedTables(tables: Array<string>, callback: AsyncCallback<void>): void 5964 5965Sets distributed tables. This API uses an asynchronous callback to return the result. 5966 5967**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5968 5969**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5970 5971**Parameters** 5972 5973| Name | Type | Mandatory| Description | 5974| -------- | ------------------------- | ---- | ---------------------- | 5975| tables | Array<string> | Yes | Names of the distributed tables to set.| 5976| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 5977 5978**Error codes** 5979 5980For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5981 5982| **ID**| **Error Message** | 5983|-----------| ------------------------------------------------------------ | 5984| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5985| 801 | Capability not supported. | 5986| 14800000 | Inner error. | 5987| 14800014 | The RdbStore or ResultSet is already closed. | 5988 5989**Example** 5990 5991```ts 5992if (store != undefined) { 5993 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], (err) => { 5994 if (err) { 5995 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5996 return; 5997 } 5998 console.info('SetDistributedTables successfully.'); 5999 }); 6000} 6001``` 6002 6003### setDistributedTables 6004 6005 setDistributedTables(tables: Array<string>): Promise<void> 6006 6007Sets distributed tables. This API uses a promise to return the result. 6008 6009**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 6010 6011**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6012 6013**Parameters** 6014 6015| Name| Type | Mandatory| Description | 6016| ------ | ------------------------ | ---- | ------------------------ | 6017| tables | Array<string> | Yes | Names of the distributed tables to set.| 6018 6019**Return value** 6020 6021| Type | Description | 6022| ------------------- | ------------------------- | 6023| Promise<void> | Promise that returns no value.| 6024 6025**Error codes** 6026 6027For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6028 6029| **ID**| **Error Message** | 6030|-----------| ------------------------------------------------------------ | 6031| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6032| 801 | Capability not supported. | 6033| 14800000 | Inner error. | 6034| 14800014 | The RdbStore or ResultSet is already closed. | 6035 6036**Example** 6037 6038```ts 6039import { BusinessError } from '@kit.BasicServicesKit'; 6040 6041if (store != undefined) { 6042 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"]).then(() => { 6043 console.info('SetDistributedTables successfully.'); 6044 }).catch((err: BusinessError) => { 6045 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 6046 }); 6047} 6048``` 6049 6050### setDistributedTables<sup>10+</sup> 6051 6052setDistributedTables(tables: Array<string>, type: DistributedType, callback: AsyncCallback<void>): void 6053 6054Sets distributed tables. This API uses an asynchronous callback to return the result. 6055 6056**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 6057 6058**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6059 6060**Parameters** 6061 6062| Name | Type | Mandatory| Description | 6063| -------- | ------------------------------------- | ---- | ---------------------------- | 6064| tables | Array<string> | Yes | Names of the distributed tables to set. | 6065| type | [DistributedType](#distributedtype10) | Yes | Distributed type of the tables. | 6066| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 6067 6068**Error codes** 6069 6070For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6071 6072| **ID**| **Error Message** | 6073|-----------| ------------------------------------------------------------ | 6074| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6075| 801 | Capability not supported. | 6076| 14800000 | Inner error. | 6077| 14800014 | The RdbStore or ResultSet is already closed. | 6078| 14800051 | The type of the distributed table does not match. | 6079 6080**Example** 6081 6082```ts 6083if (store != undefined) { 6084 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, (err) => { 6085 if (err) { 6086 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 6087 return; 6088 } 6089 console.info('SetDistributedTables successfully.'); 6090 }); 6091} 6092``` 6093 6094### setDistributedTables<sup>10+</sup> 6095 6096setDistributedTables(tables: Array<string>, type: DistributedType, config: DistributedConfig, callback: AsyncCallback<void>): void 6097 6098Sets distributed tables. This API uses an asynchronous callback to return the result. 6099 6100**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 6101 6102**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6103 6104**Parameters** 6105 6106| Name | Type | Mandatory | Description | 6107| -------- | ----------------------------------- | --- |-----------------| 6108| tables | Array<string> | Yes | Names of the distributed tables to set. | 6109| type | [DistributedType](#distributedtype10) | Yes | Distributed type of the tables. | 6110| config | [DistributedConfig](#distributedconfig10) | Yes| Configuration of the distributed mode. | 6111| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 6112 6113**Error codes** 6114 6115For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6116 6117| **ID**| **Error Message** | 6118|-----------| ------------------------------------------------------------ | 6119| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6120| 801 | Capability not supported. | 6121| 14800000 | Inner error. | 6122| 14800014 | The RdbStore or ResultSet is already closed. | 6123| 14800051 | The type of the distributed table does not match. | 6124 6125**Example** 6126 6127```ts 6128if (store != undefined) { 6129 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 6130 autoSync: true 6131 }, (err) => { 6132 if (err) { 6133 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 6134 return; 6135 } 6136 console.info('SetDistributedTables successfully.'); 6137 }); 6138} 6139``` 6140 6141### setDistributedTables<sup>10+</sup> 6142 6143 setDistributedTables(tables: Array<string>, type?: DistributedType, config?: DistributedConfig): Promise<void> 6144 6145Sets distributed tables. This API uses a promise to return the result. 6146 6147**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 6148 6149**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6150 6151**Parameters** 6152 6153| Name| Type | Mandatory| Description | 6154| ------ | ----------------------------------------- | ---- |-----------------------------------------------------------------| 6155| tables | Array<string> | Yes | Names of the distributed tables to set. | 6156| type | [DistributedType](#distributedtype10) | No | Distributed type of the tables. <br>Default value: **relationalStore.DistributedType.DISTRIBUTED_DEVICE**.| 6157| 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. | 6158 6159**Return value** 6160 6161| Type | Description | 6162| ------------------- | ------------------------- | 6163| Promise<void> | Promise that returns no value.| 6164 6165**Error codes** 6166 6167For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6168 6169| **ID**| **Error Message** | 6170|-----------| ------------------------------------------------------------ | 6171| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6172| 801 | Capability not supported. | 6173| 14800000 | Inner error. | 6174| 14800014 | The RdbStore or ResultSet is already closed. | 6175| 14800051 | The type of the distributed table does not match. | 6176 6177**Example** 6178 6179```ts 6180import { BusinessError } from '@kit.BasicServicesKit'; 6181 6182if (store != undefined) { 6183 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 6184 autoSync: true 6185 }).then(() => { 6186 console.info('SetDistributedTables successfully.'); 6187 }).catch((err: BusinessError) => { 6188 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 6189 }); 6190} 6191``` 6192 6193### obtainDistributedTableName 6194 6195obtainDistributedTableName(device: string, table: string, callback: AsyncCallback<string>): void 6196 6197Obtains 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. 6198 6199> **NOTE** 6200> 6201> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 6202 6203**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 6204 6205**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6206 6207**Parameters** 6208 6209| Name | Type | Mandatory| Description | 6210| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 6211| device | string | Yes | ID of the remote device. | 6212| table | string | Yes | Local table name of the remote device. | 6213| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| 6214 6215**Error codes** 6216 6217For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6218 6219| **ID**| **Error Message** | 6220|-----------| ------------------------------------------------------------ | 6221| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6222| 801 | Capability not supported. | 6223| 14800000 | Inner error. | 6224| 14800014 | The RdbStore or ResultSet is already closed. | 6225 6226**Example** 6227 6228```ts 6229import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6230import { BusinessError } from '@kit.BasicServicesKit'; 6231 6232let dmInstance: distributedDeviceManager.DeviceManager; 6233let deviceId: string | undefined = undefined; 6234 6235try { 6236 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 6237 let devices = dmInstance.getAvailableDeviceListSync(); 6238 deviceId = devices[0].networkId; 6239} catch (err) { 6240 let code = (err as BusinessError).code; 6241 let message = (err as BusinessError).message; 6242 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 6243} 6244 6245if (store != undefined && deviceId != undefined) { 6246 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE", (err, tableName) => { 6247 if (err) { 6248 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 6249 return; 6250 } 6251 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 6252 }); 6253} 6254``` 6255 6256### obtainDistributedTableName 6257 6258 obtainDistributedTableName(device: string, table: string): Promise<string> 6259 6260Obtains 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. 6261 6262> **NOTE** 6263> 6264> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 6265 6266**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 6267 6268**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6269 6270**Parameters** 6271 6272| Name| Type | Mandatory| Description | 6273| ------ | ------ | ---- | -------------------- | 6274| device | string | Yes | ID of the remote device. | 6275| table | string | Yes | Local table name of the remote device.| 6276 6277**Return value** 6278 6279| Type | Description | 6280| --------------------- | ----------------------------------------------------- | 6281| Promise<string> | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| 6282 6283**Error codes** 6284 6285For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6286 6287| **ID**| **Error Message** | 6288|-----------| ------------------------------------------------------------ | 6289| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6290| 801 | Capability not supported. | 6291| 14800000 | Inner error. | 6292| 14800014 | The RdbStore or ResultSet is already closed. | 6293 6294**Example** 6295 6296```ts 6297import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6298import { BusinessError } from '@kit.BasicServicesKit'; 6299 6300let dmInstance: distributedDeviceManager.DeviceManager; 6301let deviceId: string | undefined = undefined; 6302 6303try { 6304 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 6305 let devices = dmInstance.getAvailableDeviceListSync(); 6306 deviceId = devices[0].networkId; 6307} catch (err) { 6308 let code = (err as BusinessError).code; 6309 let message = (err as BusinessError).message; 6310 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 6311} 6312 6313if (store != undefined && deviceId != undefined) { 6314 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE").then((tableName: string) => { 6315 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 6316 }).catch((err: BusinessError) => { 6317 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 6318 }); 6319} 6320``` 6321 6322### sync 6323 6324sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void 6325 6326Synchronizes data between devices. This API uses an asynchronous callback to return the result. 6327 6328**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 6329 6330**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6331 6332**Parameters** 6333 6334| Name | Type | Mandatory| Description | 6335| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ | 6336| mode | [SyncMode](#syncmode) | Yes | Data sync mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**. | 6337| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | 6338| 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. | 6339 6340**Error codes** 6341 6342For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6343 6344| **ID**| **Error Message** | 6345|-----------| ------------------------------------------------------------ | 6346| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6347| 801 | Capability not supported. | 6348| 14800000 | Inner error. | 6349| 14800014 | The RdbStore or ResultSet is already closed. | 6350 6351**Example** 6352 6353```ts 6354import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6355import { BusinessError } from '@kit.BasicServicesKit'; 6356 6357let dmInstance: distributedDeviceManager.DeviceManager; 6358let deviceIds: Array<string> = []; 6359 6360try { 6361 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 6362 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 6363 for (let i = 0; i < devices.length; i++) { 6364 deviceIds[i] = devices[i].networkId!; 6365 } 6366} catch (err) { 6367 let code = (err as BusinessError).code; 6368 let message = (err as BusinessError).message; 6369 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 6370} 6371 6372let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 6373predicates.inDevices(deviceIds); 6374if (store != undefined) { 6375 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, (err, result) => { 6376 if (err) { 6377 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 6378 return; 6379 } 6380 console.info('Sync done.'); 6381 for (let i = 0; i < result.length; i++) { 6382 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 6383 } 6384 }); 6385} 6386``` 6387 6388### sync 6389 6390 sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>> 6391 6392Synchronizes data between devices. This API uses a promise to return the result. 6393 6394**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 6395 6396**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6397 6398**Parameters** 6399 6400| Name | Type | Mandatory| Description | 6401| ---------- | ------------------------------------ | ---- | ------------------------------ | 6402| mode | [SyncMode](#syncmode) | Yes | Data sync mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**.| 6403| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | 6404 6405**Return value** 6406 6407| Type | Description | 6408| -------------------------------------------- | ------------------------------------------------------------ | 6409| 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. | 6410 6411**Error codes** 6412 6413For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6414 6415| **ID**| **Error Message** | 6416|-----------| ------------------------------------------------------------ | 6417| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6418| 801 | Capability not supported. | 6419| 14800000 | Inner error. | 6420| 14800014 | The RdbStore or ResultSet is already closed. | 6421 6422**Example** 6423 6424```ts 6425import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6426import { BusinessError } from '@kit.BasicServicesKit'; 6427 6428let dmInstance: distributedDeviceManager.DeviceManager; 6429let deviceIds: Array<string> = []; 6430 6431try { 6432 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 6433 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 6434 for (let i = 0; i < devices.length; i++) { 6435 deviceIds[i] = devices[i].networkId!; 6436 } 6437} catch (err) { 6438 let code = (err as BusinessError).code; 6439 let message = (err as BusinessError).message; 6440 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 6441} 6442 6443let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 6444predicates.inDevices(deviceIds); 6445if (store != undefined) { 6446 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates).then((result: Object[][]) => { 6447 console.info('Sync done.'); 6448 for (let i = 0; i < result.length; i++) { 6449 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 6450 } 6451 }).catch((err: BusinessError) => { 6452 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 6453 }); 6454} 6455``` 6456 6457### cloudSync<sup>10+</sup> 6458 6459cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 6460 6461Manually 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. 6462 6463**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6464 6465**Parameters** 6466 6467| Name | Type | Mandatory| Description | 6468| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6469| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 6470| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details. | 6471| callback | AsyncCallback<void> | Yes | Callback used to send the sync result to the caller.| 6472 6473**Error codes** 6474 6475For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6476 6477| **ID**| **Error Message** | 6478|-----------|-------| 6479| 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. | 6480| 801 | Capability not supported. | 6481| 14800014 | The RdbStore or ResultSet is already closed. | 6482 6483**Example** 6484 6485```ts 6486if (store != undefined) { 6487 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetails) => { 6488 console.info(`Progess: ${progressDetails}`); 6489 }, (err) => { 6490 if (err) { 6491 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 6492 return; 6493 } 6494 console.info('Cloud sync succeeded'); 6495 }); 6496} 6497``` 6498 6499### cloudSync<sup>10+</sup> 6500 6501cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>): Promise<void> 6502 6503Manually 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. 6504 6505**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6506 6507**Parameters** 6508 6509| Name | Type | Mandatory| Description | 6510| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 6511| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 6512| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details.| 6513 6514**Return value** 6515 6516| Type | Description | 6517| ------------------- | --------------------------------------- | 6518| Promise<void> | Promise used to send the sync result.| 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. 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. | 6527| 801 | Capability not supported. | 6528| 14800014 | The RdbStore or ResultSet is already closed. | 6529 6530**Example** 6531 6532```ts 6533import { BusinessError } from '@kit.BasicServicesKit'; 6534 6535if (store != undefined) { 6536 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetail: relationalStore.ProgressDetails) => { 6537 console.info(`progress: ${progressDetail}`); 6538 }).then(() => { 6539 console.info('Cloud sync succeeded'); 6540 }).catch((err: BusinessError) => { 6541 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 6542 }); 6543} 6544``` 6545 6546### cloudSync<sup>10+</sup> 6547 6548cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 6549 6550Manually 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. 6551 6552**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6553 6554**Parameters** 6555 6556| Name | Type | Mandatory| Description | 6557| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6558| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 6559| tables | string[] | Yes | Name of the table to synchronize. | 6560| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details. | 6561| callback | AsyncCallback<void> | Yes | Callback used to send the sync result to the caller.| 6562 6563**Error codes** 6564 6565For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6566 6567| **ID**| **Error Message** | 6568|-----------|-------| 6569| 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.| 6570| 801 | Capability not supported. | 6571| 14800014 | The RdbStore or ResultSet is already closed. | 6572 6573**Example** 6574 6575```ts 6576const tables = ["table1", "table2"]; 6577 6578if (store != undefined) { 6579 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => { 6580 console.info(`Progess: ${progressDetail}`); 6581 }, (err) => { 6582 if (err) { 6583 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 6584 return; 6585 } 6586 console.info('Cloud sync succeeded'); 6587 }); 6588}; 6589``` 6590 6591### cloudSync<sup>10+</sup> 6592 6593cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>): Promise<void> 6594 6595Manually 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. 6596 6597**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6598 6599**Parameters** 6600 6601| Name | Type | Mandatory| Description | 6602| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 6603| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 6604| tables | string[] | Yes | Name of the table to synchronize. | 6605| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details.| 6606 6607**Return value** 6608 6609| Type | Description | 6610| ------------------- | --------------------------------------- | 6611| Promise<void> | Promise used to send the sync result.| 6612 6613**Error codes** 6614 6615For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6616 6617| **ID**| **Error Message** | 6618|-----------|---------------| 6619| 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 | 6620| 801 | Capability not supported. | 6621| 14800014 | The RdbStore or ResultSet is already closed. | 6622 6623**Example** 6624 6625```ts 6626import { BusinessError } from '@kit.BasicServicesKit'; 6627 6628const tables = ["table1", "table2"]; 6629 6630if (store != undefined) { 6631 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => { 6632 console.info(`progress: ${progressDetail}`); 6633 }).then(() => { 6634 console.info('Cloud sync succeeded'); 6635 }).catch((err: BusinessError) => { 6636 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 6637 }); 6638}; 6639``` 6640 6641### on('dataChange') 6642 6643on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 6644 6645Subscribes to data changes of this RDB store. The registered callback will be called when data in a distributed RDB store changes. 6646 6647**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6648 6649**Parameters** 6650 6651| Name | Type | Mandatory| Description | 6652| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6653| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6654| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe. | 6655| 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.| 6656 6657**Error codes** 6658 6659For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6660 6661| **ID**| **Error Message** | 6662|-----------|-------------| 6663| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6664| 801 | Capability not supported. | 6665| 14800014 | The RdbStore or ResultSet is already closed. | 6666 6667**Example** 6668 6669```ts 6670import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6671import { BusinessError } from '@kit.BasicServicesKit'; 6672 6673let storeObserver = (devices: Array<string>) => { 6674 if (devices != undefined) { 6675 for (let i = 0; i < devices.length; i++) { 6676 console.info(`device= ${devices[i]} data changed`); 6677 } 6678 } 6679}; 6680 6681try { 6682 if (store != undefined) { 6683 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6684 } 6685} catch (err) { 6686 let code = (err as BusinessError).code; 6687 let message = (err as BusinessError).message; 6688 console.error(`Register observer failed, code is ${code},message is ${message}`); 6689} 6690``` 6691 6692### on('dataChange')<sup>10+</sup> 6693 6694on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 6695 6696Subscribes to data changes of this RDB store. The registered callback will be called when data in a distributed or local RDB store changes. 6697 6698**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6699 6700**Parameters** 6701 6702| Name | Type | Mandatory| Description | 6703| -------- | ----------------------------------- | ---- | ------------------------------------------- | 6704| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6705| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe.| 6706| 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.| 6707 6708**Error codes** 6709 6710For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6711 6712| **ID**| **Error Message** | 6713|-----------|-------------| 6714| 202 | Permission verification failed, application which is not a system application uses system API. | 6715| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6716| 801 | Capability not supported. | 6717| 14800014 | The RdbStore or ResultSet is already closed. | 6718 6719Example 1: **type** is **SUBSCRIBE_TYPE_REMOTE**. 6720 6721```ts 6722import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6723import { BusinessError } from '@kit.BasicServicesKit'; 6724 6725let storeObserver = (devices: Array<string>) => { 6726 if (devices != undefined) { 6727 for (let i = 0; i < devices.length; i++) { 6728 console.info(`device= ${devices[i]} data changed`); 6729 } 6730 } 6731}; 6732 6733try { 6734 if (store != undefined) { 6735 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6736 } 6737} catch (err) { 6738 let code = (err as BusinessError).code; 6739 let message = (err as BusinessError).message; 6740 console.error(`Register observer failed, code is ${code},message is ${message}`); 6741} 6742``` 6743 6744Example 2: **type** is **SUBSCRIBE_TYPE_LOCAL_DETAILS**. 6745 6746```ts 6747import { BusinessError } from '@kit.BasicServicesKit'; 6748 6749let changeInfos = (changeInfos: Array<relationalStore.ChangeInfo>) => { 6750 for (let i = 0; i < changeInfos.length; i++) { 6751 console.info(`changeInfos = ${changeInfos[i]}`); 6752 } 6753}; 6754 6755try { 6756 if (store != undefined) { 6757 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_LOCAL_DETAILS, changeInfos); 6758 } 6759} catch (err) { 6760 let code = (err as BusinessError).code; 6761 let message = (err as BusinessError).message; 6762 console.error(`on dataChange fail, code is ${code},message is ${message}`); 6763} 6764 6765let value1 = "Lisa"; 6766let value2 = 18; 6767let value3 = 100.5; 6768let value4 = new Uint8Array([1, 2, 3]); 6769 6770try { 6771 const valueBucket: relationalStore.ValuesBucket = { 6772 'name': value1, 6773 'age': value2, 6774 'salary': value3, 6775 'blobType': value4 6776 }; 6777 6778 if (store != undefined) { 6779 (store as relationalStore.RdbStore).insert('test', valueBucket); 6780 } 6781} catch (err) { 6782 let code = (err as BusinessError).code; 6783 let message = (err as BusinessError).message; 6784 console.error(`insert fail, code is ${code},message is ${message}`); 6785} 6786``` 6787 6788### on<sup>10+</sup> 6789 6790on(event: string, interProcess: boolean, observer: Callback\<void>): void 6791 6792Subscribes to process events. This callback is invoked by [emit](#emit10). 6793 6794**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6795 6796**Parameters** 6797 6798| Name | Type | Mandatory| Description | 6799| ------------ | --------------- | ---- | ------------------------------------------------------------ | 6800| event | string | Yes | Event type, which must match the event type in **emit**. | 6801| 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.| 6802| observer | Callback\<void> | Yes | Callback used to return the result. | 6803 6804**Error codes** 6805 6806For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6807 6808| **ID**| **Error Message** | 6809|-----------|-------------| 6810| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6811| 801 | Capability not supported. | 6812| 14800000 | Inner error. | 6813| 14800014 | The RdbStore or ResultSet is already closed. | 6814| 14800050 | Failed to obtain the subscription service. | 6815 6816**Example** 6817 6818```ts 6819import { BusinessError } from '@kit.BasicServicesKit'; 6820 6821let storeObserver = () => { 6822 console.info(`storeObserver`); 6823}; 6824 6825try { 6826 if (store != undefined) { 6827 (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver); 6828 } 6829} catch (err) { 6830 let code = (err as BusinessError).code; 6831 let message = (err as BusinessError).message; 6832 console.error(`Register observer failed, code is ${code},message is ${message}`); 6833} 6834``` 6835 6836### on('autoSyncProgress')<sup>11+</sup> 6837 6838on(event: 'autoSyncProgress', progress: Callback<ProgressDetails>): void 6839 6840Subscribes 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. 6841 6842**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6843 6844**Parameters** 6845 6846| Name | Type | Mandatory| Description | 6847| ------------ |---------------------------------| ---- |-----------------------------------| 6848| event | string | Yes | Event type. The value is **'autoSyncProgress'**, which indicates the auto sync progress.| 6849| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to return the result. | 6850 6851**Error codes** 6852 6853For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6854 6855| **ID**| **Error Message** | 6856|-----------|--------| 6857| 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. | 6858| 801 | Capability not supported. | 6859| 14800014 | The RdbStore or ResultSet is already closed. | 6860 6861**Example** 6862 6863```ts 6864import { BusinessError } from '@kit.BasicServicesKit'; 6865 6866let progressDetail = (progressDetail: relationalStore.ProgressDetails) => { 6867 console.info(`progress: ${progressDetail}`); 6868}; 6869 6870try { 6871 if (store != undefined) { 6872 (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail); 6873 } 6874} catch (err) { 6875 let code = (err as BusinessError).code; 6876 let message = (err as BusinessError).message; 6877 console.error(`Register observer failed, code is ${code},message is ${message}`); 6878} 6879``` 6880 6881### on('statistics')<sup>12+</sup> 6882 6883on(event: 'statistics', observer: Callback<SqlExecutionInfo>): void 6884 6885Subscribes to SQL statistics. 6886 6887**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6888 6889**Parameters** 6890 6891| Name | Type | Mandatory| Description | 6892| ------------ |---------------------------------| ---- |-----------------------------------| 6893| event | string | Yes | Event type. The value is **'statistics'**, which indicates the statistics of the SQL execution time.| 6894| observer | Callback<[SqlExecutionInfo](#sqlexecutioninfo12)> | Yes | Callback used to return the statistics about the SQL execution time in the database. | 6895 6896**Error codes** 6897 6898For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6899 6900| **ID**| **Error Message** | 6901|-----------|--------| 6902| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 6903| 801 | Capability not supported. | 6904| 14800000 | Inner error. | 6905| 14800014 | The RdbStore or ResultSet is already closed. | 6906 6907**Example** 6908 6909```ts 6910import { BusinessError } from '@kit.BasicServicesKit'; 6911 6912let sqlExecutionInfo = (sqlExecutionInfo: relationalStore.SqlExecutionInfo) => { 6913 console.info(`sql: ${sqlExecutionInfo.sql[0]}`); 6914 console.info(`totalTime: ${sqlExecutionInfo.totalTime}`); 6915 console.info(`waitTime: ${sqlExecutionInfo.waitTime}`); 6916 console.info(`prepareTime: ${sqlExecutionInfo.prepareTime}`); 6917 console.info(`executeTime: ${sqlExecutionInfo.executeTime}`); 6918}; 6919 6920try { 6921 if (store != undefined) { 6922 (store as relationalStore.RdbStore).on('statistics', sqlExecutionInfo); 6923 } 6924} catch (err) { 6925 let code = (err as BusinessError).code; 6926 let message = (err as BusinessError).message; 6927 console.error(`Register observer failed, code is ${code},message is ${message}`); 6928} 6929 6930try { 6931 let value1 = "Lisa"; 6932 let value2 = 18; 6933 let value3 = 100.5; 6934 let value4 = new Uint8Array([1, 2, 3, 4, 5]); 6935 6936 const valueBucket: relationalStore.ValuesBucket = { 6937 'NAME': value1, 6938 'AGE': value2, 6939 'SALARY': value3, 6940 'CODES': value4 6941 }; 6942 if (store != undefined) { 6943 (store as relationalStore.RdbStore).insert('test', valueBucket); 6944 } 6945} catch (err) { 6946 console.error(`insert fail, code:${err.code}, message: ${err.message}`); 6947} 6948``` 6949 6950### on('sqliteErrorOccurred')<sup>20+</sup> 6951 6952on(event: 'sqliteErrorOccurred', observer: Callback<ExceptionMessage>): void 6953 6954Subscribes to the error logs generated when SQL statements are executed. 6955 6956**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6957 6958**Parameters** 6959 6960| Name | Type | Mandatory| Description | 6961| ------------ |---------------------------------| ---- |-----------------------------------| 6962| event | string | Yes | Name of the event to be subscribed to, with the value fixed at **sqliteErrorOccurred**. It records the error logs generated when SQL statements are executed.| 6963| observer | Callback<[ExceptionMessage](#exceptionmessage20)> | Yes | Callback used to return the result. | 6964 6965**Error codes** 6966 6967For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6968 6969| **ID**| **Error Message** | 6970|-----------|--------| 6971| 801 | Capability not supported. | 6972| 14800014 | The RdbStore or ResultSet is already closed. | 6973 6974**Example** 6975 6976```ts 6977import { BusinessError } from '@kit.BasicServicesKit'; 6978 6979async test() 6980{ 6981 try { 6982 if (store != undefined) { 6983 let exceptionMessage: relationalStore.ExceptionMessage; 6984 store.on('sqliteErrorOccurred', exceptionMessage => { 6985 let sqliteCode = exceptionMessage.code; 6986 let sqliteMessage = exceptionMessage.message; 6987 let errSQL = exceptionMessage.sql; 6988 console.info(`error log is ${sqliteCode}, errMessage is ${sqliteMessage}, errSQL is ${errSQL}`); 6989 }) 6990 } 6991 } catch (err) { 6992 let code = (err as BusinessError).code; 6993 let message = (err as BusinessError).message; 6994 console.error(`Register observer failed, code is ${code},message is ${message}`); 6995 } 6996 const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + 6997 "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL)"; 6998 try { 6999 let value = new Uint8Array([1, 2, 3, 4, 5]); 7000 const valueBucket: relationalStore.ValuesBucket = { 7001 'name': "Lisa", 7002 'age': 18, 7003 'salary': 100.5, 7004 'codes': value, 7005 }; 7006 await store.executeSql(CREATE_TABLE_TEST); 7007 if (store != undefined) { 7008 (store as relationalStore.RdbStore).insert('test', valueBucket); 7009 } 7010 } catch (err) { 7011 console.error(`Insert fail, code:${err.code}, message: ${err.message}`); 7012 } 7013} 7014``` 7015 7016### off('dataChange') 7017 7018off(event:'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 7019 7020Unsubscribes from data changes of the specified devices. 7021 7022**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7023 7024**Parameters** 7025 7026| Name | Type | Mandatory| Description | 7027| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7028| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 7029| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe. | 7030| observer | Callback<Array<string>> | Yes | Callback to unregister. **Array\<string>** holds the IDs of the peer devices whose data is changed.| 7031 7032**Error codes** 7033 7034For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 7035 7036| **ID**| **Error Message** | 7037|-----------|-------------| 7038| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7039| 801 | Capability not supported. | 7040| 14800014 | The RdbStore or ResultSet is already closed. | 7041 7042**Example** 7043 7044```ts 7045import { BusinessError } from '@kit.BasicServicesKit'; 7046 7047let storeObserver = (devices: Array<string>) => { 7048 if (devices != undefined) { 7049 for (let i = 0; i < devices.length; i++) { 7050 console.info(`device= ${devices[i]} data changed`); 7051 } 7052 } 7053}; 7054 7055try { 7056 if (store != undefined) { 7057 // The Lambda expression cannot be used here. 7058 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 7059 } 7060} catch (err) { 7061 let code = (err as BusinessError).code; 7062 let message = (err as BusinessError).message; 7063 console.error(`Register observer failed, code is ${code},message is ${message}`); 7064} 7065 7066try { 7067 if (store != undefined) { 7068 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 7069 } 7070} catch (err) { 7071 let code = (err as BusinessError).code; 7072 let message = (err as BusinessError).message; 7073 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 7074} 7075``` 7076 7077### off('dataChange')<sup>10+</sup> 7078 7079off(event:'dataChange', type: SubscribeType, observer?: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 7080 7081Unsubscribes from data changes of this RDB store. 7082 7083**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7084 7085**Parameters** 7086 7087| Name | Type | Mandatory| Description | 7088| -------- | ---------------------------------- | ---- | ------------------------------------------ | 7089| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 7090| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe. | 7091| 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**.| 7092 7093**Error codes** 7094 7095For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 7096 7097| **ID**| **Error Message** | 7098|-----------|-------------| 7099| 202 | Permission verification failed, application which is not a system application uses system API. | 7100| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7101| 801 | Capability not supported. | 7102| 14800014 | The RdbStore or ResultSet is already closed. | 7103 7104**Example** 7105 7106```ts 7107import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 7108import { BusinessError } from '@kit.BasicServicesKit'; 7109 7110let storeObserver = (devices: Array<string>) => { 7111 if (devices != undefined) { 7112 for (let i = 0; i < devices.length; i++) { 7113 console.info(`device= ${devices[i]} data changed`); 7114 } 7115 } 7116}; 7117 7118try { 7119 if (store != undefined) { 7120 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 7121 } 7122} catch (err) { 7123 let code = (err as BusinessError).code; 7124 let message = (err as BusinessError).message; 7125 console.error(`Register observer failed, code is ${code},message is ${message}`); 7126} 7127 7128try { 7129 if (store != undefined) { 7130 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 7131 } 7132} catch (err) { 7133 let code = (err as BusinessError).code; 7134 let message = (err as BusinessError).message; 7135 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 7136} 7137``` 7138 7139### off<sup>10+</sup> 7140 7141off(event: string, interProcess: boolean, observer?: Callback\<void>): void 7142 7143Unsubscribes from process events. 7144 7145**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7146 7147**Parameters** 7148 7149| Name | Type | Mandatory| Description | 7150| ------------ | --------------- | ---- | ------------------------------------------------------------ | 7151| event | string | Yes | Event name, which must match the event type in **on()**.| 7152| 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.| 7153| observer | Callback\<void> | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 7154 7155**Error codes** 7156 7157For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 7158 7159| **ID**| **Error Message** | 7160| ------------ | -------------------------------------- | 7161| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7162| 801 | Capability not supported. | 7163| 14800000 | Inner error. | 7164| 14800014 | The RdbStore or ResultSet is already closed. | 7165| 14800050 | Failed to obtain the subscription service. | 7166 7167**Example** 7168 7169```ts 7170import { BusinessError } from '@kit.BasicServicesKit'; 7171 7172let storeObserver = () => { 7173 console.info(`storeObserver`); 7174}; 7175 7176try { 7177 if (store != undefined) { 7178 (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver); 7179 } 7180} catch (err) { 7181 let code = (err as BusinessError).code; 7182 let message = (err as BusinessError).message; 7183 console.error(`Register observer failed, code is ${code},message is ${message}`); 7184} 7185 7186try { 7187 if (store != undefined) { 7188 (store as relationalStore.RdbStore).off('storeObserver', false, storeObserver); 7189 } 7190} catch (err) { 7191 let code = (err as BusinessError).code; 7192 let message = (err as BusinessError).message; 7193 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 7194} 7195``` 7196 7197### off('autoSyncProgress')<sup>11+</sup> 7198 7199off(event: 'autoSyncProgress', progress?: Callback<ProgressDetails>): void 7200 7201Unsubscribes from the auto sync progress. 7202 7203**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7204 7205**Parameters** 7206 7207| Name | Type | Mandatory| Description | 7208| ------------ |---------------------------------| ---- |------------------------------------------------------------------| 7209| event | string | Yes | Event type. The value is **'autoSyncProgress'**, which indicates the auto sync progress. | 7210| 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.| 7211 7212**Error codes** 7213 7214For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 7215 7216| **ID**| **Error Message** | 7217| ------------ |--------------------| 7218| 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. | 7219| 801 | Capability not supported. | 7220| 14800014 | The RdbStore or ResultSet is already closed. | 7221 7222**Example** 7223 7224```ts 7225import { BusinessError } from '@kit.BasicServicesKit'; 7226 7227let progressDetail = (progressDetail: relationalStore.ProgressDetails) => { 7228 console.info(`progress: ${progressDetail}`); 7229}; 7230 7231try { 7232 if (store != undefined) { 7233 (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail); 7234 } 7235} catch (err) { 7236 let code = (err as BusinessError).code; 7237 let message = (err as BusinessError).message; 7238 console.error(`Register observer failed, code is ${code},message is ${message}`); 7239} 7240 7241try { 7242 if (store != undefined) { 7243 (store as relationalStore.RdbStore).off('autoSyncProgress', progressDetail); 7244 } 7245} catch (err) { 7246 let code = (err as BusinessError).code; 7247 let message = (err as BusinessError).message; 7248 console.error(`Unregister failed, code is ${code},message is ${message}`); 7249} 7250``` 7251 7252### off('statistics')<sup>12+</sup> 7253 7254off(event: 'statistics', observer?: Callback<SqlExecutionInfo>): void 7255 7256Unsubscribes from SQL statistics. 7257 7258**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7259 7260**Parameters** 7261 7262| Name | Type | Mandatory| Description | 7263| ------------ |---------------------------------| ---- |-----------------------------------| 7264| event | string | Yes | Event type. The value is **'statistics'**, which indicates the statistics of the SQL execution time.| 7265| observer | Callback<[SqlExecutionInfo](#sqlexecutioninfo12)> | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 7266 7267 7268**Error codes** 7269 7270For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 7271 7272| **ID**| **Error Message** | 7273|-----------|--------| 7274| 401 | Parameter error. | 7275| 801 | Capability not supported. | 7276| 14800000 | Inner error. | 7277| 14800014 | The RdbStore or ResultSet is already closed. | 7278 7279```ts 7280import { BusinessError } from '@kit.BasicServicesKit'; 7281 7282try { 7283 if (store != undefined) { 7284 (store as relationalStore.RdbStore).off('statistics'); 7285 } 7286} catch (err) { 7287 let code = (err as BusinessError).code; 7288 let message = (err as BusinessError).message; 7289 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 7290} 7291``` 7292 7293### off('sqliteErrorOccurred')<sup>20+</sup> 7294 7295off(event: 'sqliteErrorOccurred', observer: Callback<ExceptionMessage>): void 7296 7297Unsubscribes from error logs generated during SQL statement execution. 7298 7299**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7300 7301**Parameters** 7302 7303| Name | Type | Mandatory| Description | 7304| ------------ |---------------------------------| ---- |-----------------------------------| 7305| event | string | Yes | Name of the event to be unsubscribed from, with the value fixed at **sqliteErrorOccurred**. It records the error logs generated when SQL statements are executed.| 7306| observer | Callback<[ExceptionMessage](#exceptionmessage20)> | Yes | Callback used to return the result. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 7307 7308**Error codes** 7309 7310For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 7311 7312| **ID**| **Error Message** | 7313|-----------|--------| 7314| 801 | Capability not supported. | 7315| 14800014 | The RdbStore or ResultSet is already closed. | 7316 7317**Example** 7318 7319```ts 7320import { BusinessError } from '@kit.BasicServicesKit'; 7321 7322try { 7323 if (store != undefined) { 7324 (store as relationalStore.RdbStore).off('sqliteErrorOccurred'); 7325 } 7326} catch (err) { 7327 let code = (err as BusinessError).code; 7328 let message = (err as BusinessError).message; 7329 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 7330} 7331``` 7332 7333 7334### emit<sup>10+</sup> 7335 7336emit(event: string): void 7337 7338Triggers the inter-process or intra-process event listener registered in [on](#on10). 7339 7340**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7341 7342**Parameters** 7343 7344| Name| Type | Mandatory| Description | 7345| ------ | ------ | ---- | -------------------- | 7346| event | string | Yes | Event name. Custom event names are allowed. However, the customized event name cannot be duplicate with the existing event names [dataChange](#ondatachange), [autoSyncProgress](#onautosyncprogress11), and [statistics](#onstatistics12).| 7347 7348**Error codes** 7349 7350For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 7351 7352| **ID**| **Error Message** | 7353| --------- |---------------------------------------------------------------------------------------------------------------| 7354| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7355| 801 | Capability not supported. | 7356| 14800000 | Inner error. | 7357| 14800014 | The RdbStore or ResultSet is already closed. | 7358| 14800050 | Failed to obtain the subscription service. | 7359 7360 7361**Example** 7362 7363```ts 7364if (store != undefined) { 7365 (store as relationalStore.RdbStore).emit('storeObserver'); 7366} 7367``` 7368 7369### cleanDirtyData<sup>11+</sup> 7370 7371cleanDirtyData(table: string, cursor: number, callback: AsyncCallback<void>): void 7372 7373Clears 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. 7374 7375**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 7376 7377**Parameters** 7378 7379| Name | Type | Mandatory| Description | 7380| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 7381| table | string | Yes | Name of the table in the RDB store. | 7382| 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. | 7383| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 7384 7385**Error codes** 7386 7387For 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). 7388 7389| **ID**| **Error Message** | 7390|-----------|---------------| 7391| 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. | 7392| 801 | Capability not supported. | 7393| 14800000 | Inner error. | 7394| 14800011 | Failed to open the database because it is corrupted. | 7395| 14800014 | The RdbStore or ResultSet is already closed. | 7396| 14800015 | The database does not respond. | 7397| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 7398| 14800022 | SQLite: Callback routine requested an abort. | 7399| 14800023 | SQLite: Access permission denied. | 7400| 14800024 | SQLite: The database file is locked. | 7401| 14800025 | SQLite: A table in the database is locked. | 7402| 14800026 | SQLite: The database is out of memory. | 7403| 14800027 | SQLite: Attempt to write a readonly database. | 7404| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7405| 14800029 | SQLite: The database is full. | 7406| 14800030 | SQLite: Unable to open the database file. | 7407| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7408| 14800032 | SQLite: Abort due to constraint violation. | 7409| 14800033 | SQLite: Data type mismatch. | 7410| 14800034 | SQLite: Library used incorrectly. | 7411 7412**Example** 7413 7414```ts 7415if (store != undefined) { 7416 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100, (err) => { 7417 if (err) { 7418 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 7419 return; 7420 } 7421 console.info('clean dirty data succeeded'); 7422 }); 7423} 7424``` 7425 7426### cleanDirtyData<sup>11+</sup> 7427 7428cleanDirtyData(table: string, callback: AsyncCallback<void>): void 7429 7430Clears all dirty data from the local device. The dirty data is the data that has been deleted from the cloud. 7431 7432**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 7433 7434**Parameters** 7435 7436| Name | Type | Mandatory| Description | 7437| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 7438| table | string | Yes | Name of the table in the RDB store.| 7439| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 7440 7441**Error codes** 7442 7443For 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). 7444 7445| **ID**| **Error Message** | 7446|-----------|---------| 7447| 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. | 7448| 801 | Capability not supported. | 7449| 14800000 | Inner error. | 7450| 14800011 | Failed to open the database because it is corrupted. | 7451| 14800014 | The RdbStore or ResultSet is already closed. | 7452| 14800015 | The database does not respond. | 7453| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 7454| 14800022 | SQLite: Callback routine requested an abort. | 7455| 14800023 | SQLite: Access permission denied. | 7456| 14800024 | SQLite: The database file is locked. | 7457| 14800025 | SQLite: A table in the database is locked. | 7458| 14800026 | SQLite: The database is out of memory. | 7459| 14800027 | SQLite: Attempt to write a readonly database. | 7460| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7461| 14800029 | SQLite: The database is full. | 7462| 14800030 | SQLite: Unable to open the database file. | 7463| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7464| 14800032 | SQLite: Abort due to constraint violation. | 7465| 14800033 | SQLite: Data type mismatch. | 7466| 14800034 | SQLite: Library used incorrectly. | 7467 7468**Example** 7469 7470```ts 7471if (store != undefined) { 7472 (store as relationalStore.RdbStore).cleanDirtyData('test_table', (err) => { 7473 if (err) { 7474 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 7475 return; 7476 } 7477 console.info('clean dirty data succeeded'); 7478 }); 7479} 7480``` 7481 7482### cleanDirtyData<sup>11+</sup> 7483 7484cleanDirtyData(table: string, cursor?: number): Promise<void> 7485 7486Clears 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. 7487 7488**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 7489 7490**Parameters** 7491 7492| Name | Type | Mandatory| Description | 7493| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 7494| table | string | Yes | Name of the table in the RDB store. | 7495| 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.| 7496 7497**Return value** 7498| Name | Description | 7499| -------- | ------------------------------------------------- | 7500| Promise\<void> | Promise that returns no value. | 7501 7502**Error codes** 7503 7504For 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). 7505 7506| **ID**| **Error Message** | 7507|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 7508| 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. | 7509| 801 | Capability not supported. | 7510| 14800000 | Inner error. | 7511| 14800011 | Failed to open the database because it is corrupted. | 7512| 14800014 | The RdbStore or ResultSet is already closed. | 7513| 14800015 | The database does not respond. | 7514| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 7515| 14800022 | SQLite: Callback routine requested an abort. | 7516| 14800023 | SQLite: Access permission denied. | 7517| 14800024 | SQLite: The database file is locked. | 7518| 14800025 | SQLite: A table in the database is locked. | 7519| 14800026 | SQLite: The database is out of memory. | 7520| 14800027 | SQLite: Attempt to write a readonly database. | 7521| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7522| 14800029 | SQLite: The database is full. | 7523| 14800030 | SQLite: Unable to open the database file. | 7524| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7525| 14800032 | SQLite: Abort due to constraint violation. | 7526| 14800033 | SQLite: Data type mismatch. | 7527| 14800034 | SQLite: Library used incorrectly. | 7528 7529**Example** 7530 7531```ts 7532import { BusinessError } from '@kit.BasicServicesKit'; 7533 7534if (store != undefined) { 7535 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100).then(() => { 7536 console.info('clean dirty data succeeded'); 7537 }).catch((err: BusinessError) => { 7538 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 7539 }); 7540} 7541``` 7542 7543### attach<sup>12+</sup> 7544 7545attach(fullPath: string, attachName: string, waitTime?: number) : Promise<number> 7546 7547Attaches an RDB store to this RDB store so that the data in the attached RDB store can be directly accessed using the SQL statement. 7548 7549The 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. 7550 7551Before the RDB store is switched to non-WAL mode, ensure that all **ResultSet**s are closed and all write operations are complete. Otherwise, error 14800015 will be reported. 7552 7553The **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. 7554 7555**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7556 7557**Parameters** 7558 7559| Name | Type | Mandatory | Description | 7560| ----------- | ------ | --- | ------------ | 7561| fullPath | string | Yes | Path of the database file to attach.| 7562| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 7563| waitTime | number | No | Maximum time period (in seconds) allowed for attaching the database file. <br>Value range: 1 to 300<br>Default value: 2| 7564 7565**Return value** 7566 7567| Type | Description | 7568| ---------------- | ---------------------------- | 7569| Promise<number> | Promise used to return the number of attached RDB stores.| 7570 7571**Error codes** 7572 7573For 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). 7574 7575| **ID**| **Error Message** | 7576|-----------| ------------------------------------------------------------ | 7577| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7578| 801 | Capability not supported. | 7579| 14800000 | Inner error. | 7580| 14800010 | Failed to open or delete the database by an invalid database path. | 7581| 14800011 | Failed to open the database because it is corrupted. | 7582| 14800014 | The RdbStore or ResultSet is already closed. | 7583| 14800015 | The database does not respond. | 7584| 14800016 | The database alias already exists. | 7585| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 7586| 14800022 | SQLite: Callback routine requested an abort. | 7587| 14800023 | SQLite: Access permission denied. | 7588| 14800024 | SQLite: The database file is locked. | 7589| 14800025 | SQLite: A table in the database is locked. | 7590| 14800026 | SQLite: The database is out of memory. | 7591| 14800027 | SQLite: Attempt to write a readonly database. | 7592| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7593| 14800029 | SQLite: The database is full. | 7594| 14800030 | SQLite: Unable to open the database file. | 7595| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7596| 14800032 | SQLite: Abort due to constraint violation. | 7597| 14800033 | SQLite: Data type mismatch. | 7598| 14800034 | SQLite: Library used incorrectly. | 7599 7600**Example** 7601 7602```ts 7603// Attach a non-encrypted RDB store to a non-encrypted RDB store. 7604import { BusinessError } from '@kit.BasicServicesKit'; 7605 7606if (store != undefined) { 7607 (store as relationalStore.RdbStore).attach("/path/rdbstore1.db", "attachDB").then((number: number) => { 7608 console.info('attach succeeded'); 7609 }).catch((err: BusinessError) => { 7610 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 7611 }); 7612} 7613``` 7614 7615### attach<sup>12+</sup> 7616 7617attach(context: Context, config: StoreConfig, attachName: string, waitTime?: number) : Promise<number> 7618 7619Attaches an RDB store to this RDB store so that the data in the attached RDB store can be directly accessed using the SQL statement. 7620 7621This 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. 7622 7623Before the RDB store is switched to non-WAL mode, ensure that all **ResultSet**s are closed and all write operations are complete. Otherwise, error 14800015 will be reported. 7624 7625The **attach** API cannot be called concurrently. Concurrent calls may cause the system to become unresponsive and trigger 14800015. If this occurs, try to call **attach()** again later. In addition, when an encrypted database is attached, the database may fail to be decrypted due to concurrency and error 14800011 is reported. In this case, explicitly specify encryption parameters and try again. 7626 7627**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7628 7629**Parameters** 7630 7631| Name | Type | Mandatory | Description | 7632| ----------- | ------ | --- | ------------ | 7633| 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).| 7634| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 7635| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 7636| waitTime | number | No | Maximum time period (in seconds) allowed for attaching the database file. <br>Value range: 1 to 300<br>Default value: 2| 7637 7638**Return value** 7639 7640| Type | Description | 7641| ---------------- | ---------------------------- | 7642| Promise<number> | Promise used to return the number of attached RDB stores.| 7643 7644**Error codes** 7645 7646For 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). 7647 7648| **ID**| **Error Message** | 7649|-----------| ------------------------------------------------------------ | 7650| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7651| 801 | Capability not supported. | 7652| 14800000 | Inner error. | 7653| 14800010 | Failed to open or delete the database by an invalid database path. | 7654| 14800011 | Failed to open the database because it is corrupted. | 7655| 14800014 | The RdbStore or ResultSet is already closed. | 7656| 14800015 | The database does not respond. | 7657| 14800016 | The database alias already exists. | 7658| 14801001 | The operation is supported in the stage model only. | 7659| 14801002 | Invalid data group ID. | 7660| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 7661| 14800022 | SQLite: Callback routine requested an abort. | 7662| 14800023 | SQLite: Access permission denied. | 7663| 14800024 | SQLite: The database file is locked. | 7664| 14800025 | SQLite: A table in the database is locked. | 7665| 14800026 | SQLite: The database is out of memory. | 7666| 14800027 | SQLite: Attempt to write a readonly database. | 7667| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7668| 14800029 | SQLite: The database is full. | 7669| 14800030 | SQLite: Unable to open the database file. | 7670| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7671| 14800032 | SQLite: Abort due to constraint violation. | 7672| 14800033 | SQLite: Data type mismatch. | 7673| 14800034 | SQLite: Library used incorrectly. | 7674 7675Example 1: Attach a non-encrypted RDB store to a non-encrypted RDB store. 7676 7677```ts 7678import { BusinessError } from '@kit.BasicServicesKit'; 7679 7680let attachStore: relationalStore.RdbStore | undefined = undefined; 7681 7682const STORE_CONFIG1: relationalStore.StoreConfig = { 7683 name: "rdbstore1.db", 7684 securityLevel: relationalStore.SecurityLevel.S3 7685}; 7686 7687relationalStore.getRdbStore(this.context, STORE_CONFIG1).then(async (rdbStore: relationalStore.RdbStore) => { 7688 attachStore = rdbStore; 7689 console.info('Get RdbStore successfully.'); 7690}).catch((err: BusinessError) => { 7691 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 7692}); 7693 7694if (store != undefined) { 7695 (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG1, "attachDB").then((number: number) => { 7696 console.info(`attach succeeded, number is ${number}`); 7697 }).catch((err: BusinessError) => { 7698 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 7699 }); 7700} 7701``` 7702 7703Example 2: Attach an encrypted RDB store to a non-encrypted RDB store. 7704 7705```ts 7706import { BusinessError } from '@kit.BasicServicesKit'; 7707 7708let attachStore: relationalStore.RdbStore | undefined = undefined; 7709 7710const STORE_CONFIG2: relationalStore.StoreConfig = { 7711 name: "rdbstore2.db", 7712 encrypt: true, 7713 securityLevel: relationalStore.SecurityLevel.S3 7714}; 7715 7716relationalStore.getRdbStore(this.context, STORE_CONFIG2).then(async (rdbStore: relationalStore.RdbStore) => { 7717 attachStore = rdbStore; 7718 console.info('Get RdbStore successfully.'); 7719}).catch((err: BusinessError) => { 7720 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 7721}); 7722 7723if (store != undefined) { 7724 (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG2, "attachDB2", 10).then((number: number) => { 7725 console.info(`attach succeeded, number is ${number}`); 7726 }).catch((err: BusinessError) => { 7727 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 7728 }); 7729} 7730``` 7731 7732### detach<sup>12+</sup> 7733 7734detach(attachName: string, waitTime?: number) : Promise<number> 7735 7736Detaches an RDB store from this RDB store. 7737 7738After all attached RDB stores are detached, the RDB is switched to the WAL mode. 7739 7740Before 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. 7741 7742**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7743 7744**Parameters** 7745 7746| Name | Type | Mandatory | Description | 7747| ----------- | ------ | --- | ------------ | 7748| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 7749| waitTime | number | No | Maximum time period (in seconds) allowed for detaching the RDB store. <br>Value range: 1 to 300<br>Default value: 2| 7750 7751**Return value** 7752 7753| Type | Description | 7754| ---------------- | ---------------------------- | 7755| Promise<number> | Promise used to return the number of remaining attached RDB stores.| 7756 7757**Error codes** 7758 7759For 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). 7760 7761| **ID**| **Error Message** | 7762|-----------|------------------------| 7763| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7764| 14800000 | Inner error. | 7765| 14800011 | Failed to open the database because it is corrupted. | 7766| 14800014 | The RdbStore or ResultSet is already closed. | 7767| 14800015 | The database does not respond. | 7768| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 7769| 14800022 | SQLite: Callback routine requested an abort. | 7770| 14800023 | SQLite: Access permission denied. | 7771| 14800024 | SQLite: The database file is locked. | 7772| 14800025 | SQLite: A table in the database is locked. | 7773| 14800026 | SQLite: The database is out of memory. | 7774| 14800027 | SQLite: Attempt to write a readonly database. | 7775| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7776| 14800029 | SQLite: The database is full. | 7777| 14800030 | SQLite: Unable to open the database file. | 7778| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7779| 14800032 | SQLite: Abort due to constraint violation. | 7780| 14800033 | SQLite: Data type mismatch. | 7781| 14800034 | SQLite: Library used incorrectly. | 7782 7783**Example** 7784 7785```ts 7786import { BusinessError } from '@kit.BasicServicesKit'; 7787 7788if (store != undefined) { 7789 (store as relationalStore.RdbStore).detach("attachDB").then((number: number) => { 7790 console.info(`detach succeeded, number is ${number}`); 7791 }).catch((err: BusinessError) => { 7792 console.error(`detach failed, code is ${err.code},message is ${err.message}`); 7793 }); 7794} 7795``` 7796 7797### lockRow<sup>12+</sup> 7798 7799lockRow(predicates: RdbPredicates):Promise<void> 7800 7801Locks data in this RDB store. This API uses a promise to return the result. The locked data is blocked from device-cloud sync. 7802 7803This 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. 7804This 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. 7805This API cannot be used for deleted data. 7806 7807**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7808 7809**Parameters** 7810 7811| Name | Type | Mandatory| Description | 7812| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 7813| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions for locking data.| 7814 7815**Return value** 7816 7817| Type | Description | 7818| --------------------- | ------------------------------- | 7819| Promise<void> | Promise that returns no value. | 7820 7821**Error codes** 7822 7823For 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). 7824 7825| **ID**| **Error Message** | 7826|-----------|----------------------------------------------------------------------------------------------| 7827| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7828| 14800000 | Inner error. | 7829| 14800011 | Failed to open the database because it is corrupted. | 7830| 14800014 | The RdbStore or ResultSet is already closed. | 7831| 14800015 | The database does not respond. | 7832| 14800018 | No data meets the condition. | 7833| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 7834| 14800022 | SQLite: Callback routine requested an abort. | 7835| 14800023 | SQLite: Access permission denied. | 7836| 14800024 | SQLite: The database file is locked. | 7837| 14800025 | SQLite: A table in the database is locked. | 7838| 14800026 | SQLite: The database is out of memory. | 7839| 14800027 | SQLite: Attempt to write a readonly database. | 7840| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7841| 14800029 | SQLite: The database is full. | 7842| 14800030 | SQLite: Unable to open the database file. | 7843| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7844| 14800032 | SQLite: Abort due to constraint violation. | 7845| 14800033 | SQLite: Data type mismatch. | 7846| 14800034 | SQLite: Library used incorrectly. | 7847 7848**Example** 7849 7850```ts 7851import { BusinessError } from '@kit.BasicServicesKit'; 7852 7853let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7854predicates.equalTo("NAME", "Lisa"); 7855if (store != undefined) { 7856 (store as relationalStore.RdbStore).lockRow(predicates).then(() => { 7857 console.info(`Lock success`); 7858 }).catch((err: BusinessError) => { 7859 console.error(`Lock failed, code is ${err.code},message is ${err.message}`); 7860 }); 7861} 7862``` 7863 7864### unlockRow<sup>12+</sup> 7865 7866unlockRow(predicates: RdbPredicates):Promise<void> 7867 7868Unlocks data in this RDB store. This API uses a promise to return the result. 7869 7870This 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. 7871This 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. 7872This API cannot be used for deleted data. 7873 7874**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7875 7876**Parameters** 7877 7878| Name | Type | Mandatory| Description | 7879| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 7880| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions for locking data.| 7881 7882**Return value** 7883 7884| Type | Description | 7885| --------------------- | ------------------------------- | 7886| Promise<void> | Promise that returns no value. | 7887 7888**Error codes** 7889 7890For 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). 7891 7892| **ID**| **Error Message** | 7893|-----------| ------------------------------------------------------------ | 7894| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7895| 14800000 | Inner error. | 7896| 14800011 | Failed to open the database because it is corrupted. | 7897| 14800014 | The RdbStore or ResultSet is already closed. | 7898| 14800015 | The database does not respond. | 7899| 14800018 | No data meets the condition. | 7900| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 7901| 14800022 | SQLite: Callback routine requested an abort. | 7902| 14800023 | SQLite: Access permission denied. | 7903| 14800024 | SQLite: The database file is locked. | 7904| 14800025 | SQLite: A table in the database is locked. | 7905| 14800026 | SQLite: The database is out of memory. | 7906| 14800027 | SQLite: Attempt to write a readonly database. | 7907| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7908| 14800029 | SQLite: The database is full. | 7909| 14800030 | SQLite: Unable to open the database file. | 7910| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7911| 14800032 | SQLite: Abort due to constraint violation. | 7912| 14800033 | SQLite: Data type mismatch. | 7913| 14800034 | SQLite: Library used incorrectly. | 7914 7915**Example** 7916 7917```ts 7918import { BusinessError } from '@kit.BasicServicesKit'; 7919 7920let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7921predicates.equalTo("NAME", "Lisa"); 7922if (store != undefined) { 7923 (store as relationalStore.RdbStore).unlockRow(predicates).then(() => { 7924 console.info(`Unlock success`); 7925 }).catch((err: BusinessError) => { 7926 console.error(`Unlock failed, code is ${err.code},message is ${err.message}`); 7927 }); 7928} 7929``` 7930 7931### queryLockedRow<sup>12+</sup> 7932 7933queryLockedRow(predicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> 7934 7935Queries the locked data in this RDB store. This API uses a promise to return the result. 7936Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 7937 7938**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7939 7940**Parameters** 7941 7942| Name | Type | Mandatory| Description | 7943| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 7944| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 7945| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 7946 7947**Error codes** 7948 7949For 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). 7950 7951| **ID**| **Error Message** | 7952|-----------| ------------------------------------------------------------ | 7953| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7954| 14800000 | Inner error. | 7955| 14800011 | Failed to open the database because it is corrupted. | 7956| 14800014 | The RdbStore or ResultSet is already closed. | 7957| 14800015 | The database does not respond. | 7958| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 7959| 14800022 | SQLite: Callback routine requested an abort. | 7960| 14800023 | SQLite: Access permission denied. | 7961| 14800024 | SQLite: The database file is locked. | 7962| 14800025 | SQLite: A table in the database is locked. | 7963| 14800026 | SQLite: The database is out of memory. | 7964| 14800027 | SQLite: Attempt to write a readonly database. | 7965| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7966| 14800029 | SQLite: The database is full. | 7967| 14800030 | SQLite: Unable to open the database file. | 7968| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7969| 14800032 | SQLite: Abort due to constraint violation. | 7970| 14800033 | SQLite: Data type mismatch. | 7971| 14800034 | SQLite: Library used incorrectly. | 7972 7973**Return value** 7974 7975| Type | Description | 7976| ------------------------------------------------------- | -------------------------------------------------- | 7977| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 7978 7979**Example** 7980 7981```ts 7982import { BusinessError } from '@kit.BasicServicesKit'; 7983 7984let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7985predicates.equalTo("NAME", "Rose"); 7986if (store != undefined) { 7987 (store as relationalStore.RdbStore).queryLockedRow(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then(async (resultSet: relationalStore.ResultSet) => { 7988 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 7989 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 7990 while (resultSet.goToNextRow()) { 7991 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 7992 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 7993 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 7994 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 7995 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 7996 } 7997 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 7998 resultSet.close(); 7999 }).catch((err: BusinessError) => { 8000 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 8001 }); 8002} 8003``` 8004### close<sup>12+</sup> 8005 8006close(): Promise<void> 8007 8008Closes this RDB store. This API uses a promise to return the result. 8009 8010**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8011 8012**Return value** 8013 8014| Type | Description | 8015| ------------------- | ------------- | 8016| Promise<void> | Promise that returns no value.| 8017 8018**Error codes** 8019 8020For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 8021 8022| **ID**| **Error Message** | 8023| ------------ | ----------------------------------------------- | 8024| 401 | Parameter error. The store must not be nullptr. | 8025| 14800000 | Inner error. | 8026 8027**Example** 8028 8029```ts 8030import { BusinessError } from '@kit.BasicServicesKit'; 8031 8032if (store != undefined) { 8033 (store as relationalStore.RdbStore).close().then(() => { 8034 console.info(`close succeeded`); 8035 }).catch((err: BusinessError) => { 8036 console.error(`close failed, code is ${err.code},message is ${err.message}`); 8037 }); 8038} 8039``` 8040 8041## ResultSet 8042 8043Provides APIs to access the **resultSet** object returned by **query()**. 8044 8045For the following APIs, you should use either [query](#query14), [querySql](#querysql14), [remoteQuery](#remotequery-1), or [queryLockedRow](#querylockedrow12) to obtain the **ResultSet** instance first, and then use this instance to call the corresponding method. 8046 8047### Properties 8048 8049**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8050 8051| Name | Type | Mandatory| Description | 8052| ------------ | ------------------- | ---- | -------------------------------- | 8053| columnNames | Array<string> | Yes | Names of all columns in the result set. | 8054| columnCount | number | Yes | Number of columns in the result set. | 8055| rowCount | number | Yes | Number of rows in the result set. | 8056| rowIndex | number | Yes | Index of the current row in the result set. <br>Default value: **-1**. The index position starts from **0**.| 8057| isAtFirstRow | boolean | Yes | Whether the result set pointer is in the first row (the row index is **0**). The value **true** means the result set pointer is in the first row.| 8058| isAtLastRow | boolean | Yes | Whether the result set pointer is in the last row. The value **true** means the pointer is in the last row.| 8059| isEnded | boolean | Yes | Whether the result set pointer is after the last row. The value **true** means the pointer is after the last row.| 8060| isStarted | boolean | Yes | Whether the result set pointer is moved. The value **true** means the pointer is moved. | 8061| isClosed | boolean | Yes | Whether the result set is closed. The value **true** means the result set is closed. | 8062 8063### getColumnIndex 8064 8065getColumnIndex(columnName: string): number 8066 8067Obtains the column index based on the column name. 8068 8069**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8070 8071**Parameters** 8072 8073| Name | Type | Mandatory| Description | 8074| ---------- | ------ | ---- | -------------------------- | 8075| columnName | string | Yes | Column name.| 8076 8077**Return value** 8078 8079| Type | Description | 8080| ------ | ------------------ | 8081| number | Column index obtained.| 8082 8083**Error codes** 8084 8085For 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). 8086 8087| **ID**| **Error Message** | 8088|-----------| ------------------------------------------------------------ | 8089| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8090| 14800000 | Inner error. | 8091| 14800011 | Failed to open the database because it is corrupted. | 8092| 14800013 | Resultset is empty or column index is out of bounds. | 8093| 14800014 | The RdbStore or ResultSet is already closed. | 8094| 14800019 | The SQL must be a query statement. | 8095| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8096| 14800022 | SQLite: Callback routine requested an abort. | 8097| 14800023 | SQLite: Access permission denied. | 8098| 14800024 | SQLite: The database file is locked. | 8099| 14800025 | SQLite: A table in the database is locked. | 8100| 14800026 | SQLite: The database is out of memory. | 8101| 14800027 | SQLite: Attempt to write a readonly database. | 8102| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8103| 14800029 | SQLite: The database is full. | 8104| 14800030 | SQLite: Unable to open the database file. | 8105| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8106| 14800032 | SQLite: Abort due to constraint violation. | 8107| 14800033 | SQLite: Data type mismatch. | 8108| 14800034 | SQLite: Library used incorrectly. | 8109 8110**Example** 8111 8112```ts 8113if (resultSet != undefined) { 8114 const id = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("ID")); 8115 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 8116 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 8117 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 8118} 8119``` 8120 8121### getColumnName 8122 8123getColumnName(columnIndex: number): string 8124 8125Obtains the column name based on the specified column index. 8126 8127**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8128 8129**Parameters** 8130 8131| Name | Type | Mandatory| Description | 8132| ----------- | ------ | ---- | -------------------------- | 8133| columnIndex | number | Yes | Column index.| 8134 8135**Return value** 8136 8137| Type | Description | 8138| ------ | ------------------ | 8139| string | Column name obtained.| 8140 8141**Error codes** 8142 8143For 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). 8144 8145| **ID**| **Error Message** | 8146|-----------| ------------------------------------------------------------ | 8147| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8148| 14800000 | Inner error. | 8149| 14800011 | Failed to open the database because it is corrupted. | 8150| 14800013 | Resultset is empty or column index is out of bounds. | 8151| 14800014 | The RdbStore or ResultSet is already closed. | 8152| 14800019 | The SQL must be a query statement. | 8153| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8154| 14800022 | SQLite: Callback routine requested an abort. | 8155| 14800023 | SQLite: Access permission denied. | 8156| 14800024 | SQLite: The database file is locked. | 8157| 14800025 | SQLite: A table in the database is locked. | 8158| 14800026 | SQLite: The database is out of memory. | 8159| 14800027 | SQLite: Attempt to write a readonly database. | 8160| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8161| 14800029 | SQLite: The database is full. | 8162| 14800030 | SQLite: Unable to open the database file. | 8163| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8164| 14800032 | SQLite: Abort due to constraint violation. | 8165| 14800033 | SQLite: Data type mismatch. | 8166| 14800034 | SQLite: Library used incorrectly. | 8167 8168**Example** 8169 8170```ts 8171if (resultSet != undefined) { 8172 const id = (resultSet as relationalStore.ResultSet).getColumnName(0); 8173 const name = (resultSet as relationalStore.ResultSet).getColumnName(1); 8174 const age = (resultSet as relationalStore.ResultSet).getColumnName(2); 8175} 8176``` 8177 8178### getColumnType<sup>18+</sup> 8179 8180getColumnType(columnIdentifier: number | string): Promise\<ColumnType> 8181 8182Obtains the column data type based on the specified column index or column name. This API uses a promise to return the result. 8183 8184**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8185 8186**Parameters** 8187 8188| Name | Type | Mandatory| Description | 8189| ---------------- | ---------------- | ---- | ------------------------------------------------------------ | 8190| columnIdentifier | number \| string | Yes | Index or name of column in a result set. The index must be a non-negative integer and cannot exceed the length of **columnNames**. The column name must be a name in **columnNames**.| 8191 8192**Return value** 8193 8194| Type | Description | 8195| ------------------------------------ | ----------------------------------- | 8196| Promise<[ColumnType](#columntype18)> | Promise used to return the data type obtained.| 8197 8198**Error codes** 8199 8200For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 8201 8202| **ID**| **Error Message** | 8203| ------------ | ------------------------------------------------------------ | 8204| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8205| 14800000 | Inner error. | 8206| 14800011 | Failed to open the database because it is corrupted. | 8207| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8208| 14800013 | Resultset is empty or column index is out of bounds. | 8209| 14800014 | The RdbStore or ResultSet is already closed. | 8210| 14800019 | The SQL must be a query statement. | 8211| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8212| 14800022 | SQLite: Callback routine requested an abort. | 8213| 14800023 | SQLite: Access permission denied. | 8214| 14800024 | SQLite: The database file is locked. | 8215| 14800025 | SQLite: A table in the database is locked. | 8216| 14800026 | SQLite: The database is out of memory. | 8217| 14800027 | SQLite: Attempt to write a readonly database. | 8218| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8219| 14800029 | SQLite: The database is full. | 8220| 14800030 | SQLite: Unable to open the database file. | 8221| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8222| 14800032 | SQLite: Abort due to constraint violation. | 8223| 14800033 | SQLite: Data type mismatch. | 8224| 14800034 | SQLite: Library used incorrectly. | 8225 8226**Example** 8227 8228```ts 8229if (resultSet != undefined) { 8230 let idType = await (resultSet as relationalStore.ResultSet).getColumnType("ID") as relationalStore.ColumnType; 8231 let nameType = await (resultSet as relationalStore.ResultSet).getColumnType("NAME") as relationalStore.ColumnType; 8232 let ageType = await (resultSet as relationalStore.ResultSet).getColumnType("AGE") as relationalStore.ColumnType; 8233 let salaryType = await (resultSet as relationalStore.ResultSet).getColumnType("SALARY") as relationalStore.ColumnType; 8234 let codesType = await (resultSet as relationalStore.ResultSet).getColumnType("CODES") as relationalStore.ColumnType; 8235 let identityType = await (resultSet as relationalStore.ResultSet).getColumnType(5) as relationalStore.ColumnType; 8236 let assetDataType = await (resultSet as relationalStore.ResultSet).getColumnType(6) as relationalStore.ColumnType; 8237 let assetsDataType = await (resultSet as relationalStore.ResultSet).getColumnType(7) as relationalStore.ColumnType; 8238 let floatArrayType = await (resultSet as relationalStore.ResultSet).getColumnType(8) as relationalStore.ColumnType; 8239} 8240``` 8241 8242### getColumnTypeSync<sup>18+</sup> 8243 8244getColumnTypeSync(columnIdentifier: number | string): ColumnType 8245 8246Obtains the column data type based on the specified column index or column name. This API returns the result synchronously. 8247 8248**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8249 8250**Parameters** 8251 8252| Name | Type | Mandatory| Description | 8253| ---------------- | ---------------- | ---- | ------------------------------------------------------------ | 8254| columnIdentifier | number \| string | Yes | Index or name of column in a result set. The index must be a non-negative integer and cannot exceed the length of **columnNames**. The column name must be a name in **columnNames**.| 8255 8256**Return value** 8257 8258| Type | Description | 8259| --------------------------- | ---------------------- | 8260| [ColumnType](#columntype18) | Data type obtained.| 8261 8262**Error codes** 8263 8264For 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). 8265 8266| **ID**| **Error Message** | 8267| ------------ | ------------------------------------------------------------ | 8268| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8269| 14800000 | Inner error. | 8270| 14800011 | Failed to open the database because it is corrupted. | 8271| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8272| 14800013 | Resultset is empty or column index is out of bounds. | 8273| 14800014 | The RdbStore or ResultSet is already closed. | 8274| 14800019 | The SQL must be a query statement. | 8275| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8276| 14800022 | SQLite: Callback routine requested an abort. | 8277| 14800023 | SQLite: Access permission denied. | 8278| 14800024 | SQLite: The database file is locked. | 8279| 14800025 | SQLite: A table in the database is locked. | 8280| 14800026 | SQLite: The database is out of memory. | 8281| 14800027 | SQLite: Attempt to write a readonly database. | 8282| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8283| 14800029 | SQLite: The database is full. | 8284| 14800030 | SQLite: Unable to open the database file. | 8285| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8286| 14800032 | SQLite: Abort due to constraint violation. | 8287| 14800033 | SQLite: Data type mismatch. | 8288| 14800034 | SQLite: Library used incorrectly. | 8289 8290**Example** 8291 8292```ts 8293if (resultSet != undefined) { 8294 let idType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("ID") as relationalStore.ColumnType; 8295 let nameType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("NAME") as relationalStore.ColumnType; 8296 let ageType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("AGE") as relationalStore.ColumnType; 8297 let salaryType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("SALARY") as relationalStore.ColumnType; 8298 let codesType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("CODES") as relationalStore.ColumnType; 8299 let identityType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(5) as relationalStore.ColumnType; 8300 let assetDataType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(6) as relationalStore.ColumnType; 8301 let assetsDataType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(7) as relationalStore.ColumnType; 8302 let floatArrayType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(8) as relationalStore.ColumnType; 8303} 8304``` 8305 8306### goTo 8307 8308goTo(offset:number): boolean 8309 8310Moves the result set pointer based on the offset specified. 8311 8312**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8313 8314**Parameters** 8315 8316| Name| Type | Mandatory| Description | 8317| ------ | ------ | ---- | ---------------------------- | 8318| offset | number | Yes | Offset relative to the position of the current result set pointer. A positive value means to move the pointer backward, and a negative value means to move the pointer forward.| 8319 8320**Return value** 8321 8322| Type | Description | 8323| ------- | --------------------------------------------- | 8324| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 8325 8326**Error codes** 8327 8328For 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). 8329 8330| **ID**| **Error Message** | 8331|-----------| ------------------------------------------------------------ | 8332| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8333| 14800000 | Inner error. | 8334| 14800011 | Failed to open the database because it is corrupted. | 8335| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8336| 14800014 | The RdbStore or ResultSet is already closed. | 8337| 14800019 | The SQL must be a query statement. | 8338| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8339| 14800022 | SQLite: Callback routine requested an abort. | 8340| 14800023 | SQLite: Access permission denied. | 8341| 14800024 | SQLite: The database file is locked. | 8342| 14800025 | SQLite: A table in the database is locked. | 8343| 14800026 | SQLite: The database is out of memory. | 8344| 14800027 | SQLite: Attempt to write a readonly database. | 8345| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8346| 14800029 | SQLite: The database is full. | 8347| 14800030 | SQLite: Unable to open the database file. | 8348| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8349| 14800032 | SQLite: Abort due to constraint violation. | 8350| 14800033 | SQLite: Data type mismatch. | 8351| 14800034 | SQLite: Library used incorrectly. | 8352 8353**Example** 8354 8355```ts 8356if (resultSet != undefined) { 8357 (resultSet as relationalStore.ResultSet).goTo(1); 8358} 8359``` 8360 8361### goToRow 8362 8363goToRow(position: number): boolean 8364 8365Moves to the specified row in the result set. 8366 8367**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8368 8369**Parameters** 8370 8371| Name | Type | Mandatory| Description | 8372| -------- | ------ | ---- | ------------------------ | 8373| position | number | Yes | Destination position to move to.| 8374 8375**Return value** 8376 8377| Type | Description | 8378| ------- | --------------------------------------------- | 8379| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 8380 8381**Error codes** 8382 8383For 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). 8384 8385| **ID**| **Error Message** | 8386|-----------| ------------------------------------------------------------ | 8387| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8388| 14800000 | Inner error. | 8389| 14800011 | Failed to open the database because it is corrupted. | 8390| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8391| 14800014 | The RdbStore or ResultSet is already closed. | 8392| 14800019 | The SQL must be a query statement. | 8393| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8394| 14800022 | SQLite: Callback routine requested an abort. | 8395| 14800023 | SQLite: Access permission denied. | 8396| 14800024 | SQLite: The database file is locked. | 8397| 14800025 | SQLite: A table in the database is locked. | 8398| 14800026 | SQLite: The database is out of memory. | 8399| 14800027 | SQLite: Attempt to write a readonly database. | 8400| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8401| 14800029 | SQLite: The database is full. | 8402| 14800030 | SQLite: Unable to open the database file. | 8403| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8404| 14800032 | SQLite: Abort due to constraint violation. | 8405| 14800033 | SQLite: Data type mismatch. | 8406| 14800034 | SQLite: Library used incorrectly. | 8407 8408**Example** 8409 8410```ts 8411if (resultSet != undefined) { 8412 (resultSet as relationalStore.ResultSet).goToRow(5); 8413} 8414``` 8415 8416### goToFirstRow 8417 8418goToFirstRow(): boolean 8419 8420 8421Moves to the first row of the result set. 8422 8423**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8424 8425**Return value** 8426 8427| Type | Description | 8428| ------- | --------------------------------------------- | 8429| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 8430 8431**Error codes** 8432 8433For 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). 8434 8435| **ID**| **Error Message** | 8436|-----------| ------------------------------------------------------------ | 8437| 14800000 | Inner error. | 8438| 14800011 | Failed to open the database because it is corrupted. | 8439| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8440| 14800014 | The RdbStore or ResultSet is already closed. | 8441| 14800019 | The SQL must be a query statement. | 8442| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8443| 14800022 | SQLite: Callback routine requested an abort. | 8444| 14800023 | SQLite: Access permission denied. | 8445| 14800024 | SQLite: The database file is locked. | 8446| 14800025 | SQLite: A table in the database is locked. | 8447| 14800026 | SQLite: The database is out of memory. | 8448| 14800027 | SQLite: Attempt to write a readonly database. | 8449| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8450| 14800029 | SQLite: The database is full. | 8451| 14800030 | SQLite: Unable to open the database file. | 8452| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8453| 14800032 | SQLite: Abort due to constraint violation. | 8454| 14800033 | SQLite: Data type mismatch. | 8455| 14800034 | SQLite: Library used incorrectly. | 8456 8457**Example** 8458 8459```ts 8460if (resultSet != undefined) { 8461 (resultSet as relationalStore.ResultSet).goToFirstRow(); 8462} 8463``` 8464 8465### goToLastRow 8466 8467goToLastRow(): boolean 8468 8469Moves to the last row of the result set. 8470 8471**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8472 8473**Return value** 8474 8475| Type | Description | 8476| ------- | --------------------------------------------- | 8477| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 8478 8479**Error codes** 8480 8481For 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). 8482 8483| **ID**| **Error Message** | 8484|-----------| ------------------------------------------------------------ | 8485| 14800000 | Inner error. | 8486| 14800011 | Failed to open the database because it is corrupted. | 8487| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8488| 14800014 | The RdbStore or ResultSet is already closed. | 8489| 14800019 | The SQL must be a query statement. | 8490| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8491| 14800022 | SQLite: Callback routine requested an abort. | 8492| 14800023 | SQLite: Access permission denied. | 8493| 14800024 | SQLite: The database file is locked. | 8494| 14800025 | SQLite: A table in the database is locked. | 8495| 14800026 | SQLite: The database is out of memory. | 8496| 14800027 | SQLite: Attempt to write a readonly database. | 8497| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8498| 14800029 | SQLite: The database is full. | 8499| 14800030 | SQLite: Unable to open the database file. | 8500| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8501| 14800032 | SQLite: Abort due to constraint violation. | 8502| 14800033 | SQLite: Data type mismatch. | 8503| 14800034 | SQLite: Library used incorrectly. | 8504 8505**Example** 8506 8507```ts 8508if (resultSet != undefined) { 8509 (resultSet as relationalStore.ResultSet).goToLastRow(); 8510} 8511``` 8512 8513### goToNextRow 8514 8515goToNextRow(): boolean 8516 8517Moves to the next row in the result set. 8518 8519**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8520 8521**Return value** 8522 8523| Type | Description | 8524| ------- | --------------------------------------------- | 8525| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 8526 8527**Error codes** 8528 8529For 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). 8530 8531| **ID**| **Error Message** | 8532|-----------| ------------------------------------------------------------ | 8533| 14800000 | Inner error. | 8534| 14800011 | Failed to open the database because it is corrupted. | 8535| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8536| 14800014 | The RdbStore or ResultSet is already closed. | 8537| 14800019 | The SQL must be a query statement. | 8538| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8539| 14800022 | SQLite: Callback routine requested an abort. | 8540| 14800023 | SQLite: Access permission denied. | 8541| 14800024 | SQLite: The database file is locked. | 8542| 14800025 | SQLite: A table in the database is locked. | 8543| 14800026 | SQLite: The database is out of memory. | 8544| 14800027 | SQLite: Attempt to write a readonly database. | 8545| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8546| 14800029 | SQLite: The database is full. | 8547| 14800030 | SQLite: Unable to open the database file. | 8548| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8549| 14800032 | SQLite: Abort due to constraint violation. | 8550| 14800033 | SQLite: Data type mismatch. | 8551| 14800034 | SQLite: Library used incorrectly. | 8552 8553**Example** 8554 8555```ts 8556if (resultSet != undefined) { 8557 (resultSet as relationalStore.ResultSet).goToNextRow(); 8558} 8559``` 8560 8561### goToPreviousRow 8562 8563goToPreviousRow(): boolean 8564 8565Moves to the previous row in the result set. 8566 8567**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8568 8569**Return value** 8570 8571| Type | Description | 8572| ------- | --------------------------------------------- | 8573| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 8574 8575**Error codes** 8576 8577For 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). 8578 8579| **ID**| **Error Message** | 8580|-----------| ------------------------------------------------------------ | 8581| 14800000 | Inner error. | 8582| 14800011 | Failed to open the database because it is corrupted. | 8583| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8584| 14800014 | The RdbStore or ResultSet is already closed. | 8585| 14800019 | The SQL must be a query statement. | 8586| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8587| 14800022 | SQLite: Callback routine requested an abort. | 8588| 14800023 | SQLite: Access permission denied. | 8589| 14800024 | SQLite: The database file is locked. | 8590| 14800025 | SQLite: A table in the database is locked. | 8591| 14800026 | SQLite: The database is out of memory. | 8592| 14800027 | SQLite: Attempt to write a readonly database. | 8593| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8594| 14800029 | SQLite: The database is full. | 8595| 14800030 | SQLite: Unable to open the database file. | 8596| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8597| 14800032 | SQLite: Abort due to constraint violation. | 8598| 14800033 | SQLite: Data type mismatch. | 8599| 14800034 | SQLite: Library used incorrectly. | 8600 8601**Example** 8602 8603```ts 8604if (resultSet != undefined) { 8605 (resultSet as relationalStore.ResultSet).goToPreviousRow(); 8606} 8607``` 8608 8609### getValue<sup>12+</sup> 8610 8611getValue(columnIndex: number): ValueType 8612 8613Obtains 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. 8614 8615**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8616 8617**Parameters** 8618 8619| Name | Type | Mandatory| Description | 8620| ----------- | ------ | ---- | ----------------------- | 8621| columnIndex | number | Yes | Index of the target column, starting from 0.| 8622 8623**Return value** 8624 8625| Type | Description | 8626| ---------- | -------------------------------- | 8627| [ValueType](#valuetype) | Values of the specified type.| 8628 8629**Error codes** 8630 8631For 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). 8632 8633| **ID**| **Error Message** | 8634|-----------|---------| 8635| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8636| 14800000 | Inner error. | 8637| 14800011 | Failed to open the database because it is corrupted. | 8638| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8639| 14800013 | Resultset is empty or column index is out of bounds. | 8640| 14800014 | The RdbStore or ResultSet is already closed. | 8641| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8642| 14800022 | SQLite: Callback routine requested an abort. | 8643| 14800023 | SQLite: Access permission denied. | 8644| 14800024 | SQLite: The database file is locked. | 8645| 14800025 | SQLite: A table in the database is locked. | 8646| 14800026 | SQLite: The database is out of memory. | 8647| 14800027 | SQLite: Attempt to write a readonly database. | 8648| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8649| 14800029 | SQLite: The database is full. | 8650| 14800030 | SQLite: Unable to open the database file. | 8651| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8652| 14800032 | SQLite: Abort due to constraint violation. | 8653| 14800033 | SQLite: Data type mismatch. | 8654| 14800034 | SQLite: Library used incorrectly. | 8655 8656**Example** 8657 8658```ts 8659if (resultSet != undefined) { 8660 const codes = (resultSet as relationalStore.ResultSet).getValue((resultSet as relationalStore.ResultSet).getColumnIndex("BIGINT_COLUMN")); 8661} 8662``` 8663 8664### getBlob 8665 8666getBlob(columnIndex: number): Uint8Array 8667 8668 8669Obtains 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. 8670 8671**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8672 8673**Parameters** 8674 8675| Name | Type | Mandatory| Description | 8676| ----------- | ------ | ---- | ----------------------- | 8677| columnIndex | number | Yes | Index of the target column, starting from 0.| 8678 8679**Return value** 8680 8681| Type | Description | 8682| ---------- | -------------------------------- | 8683| Uint8Array | Value obtained.| 8684 8685**Error codes** 8686 8687For 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). 8688 8689| **ID**| **Error Message** | 8690|-----------| ------------------------------------------------------------ | 8691| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8692| 14800000 | Inner error. | 8693| 14800011 | Failed to open the database because it is corrupted. | 8694| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8695| 14800013 | Resultset is empty or column index is out of bounds. | 8696| 14800014 | The RdbStore or ResultSet is already closed. | 8697| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8698| 14800022 | SQLite: Callback routine requested an abort. | 8699| 14800023 | SQLite: Access permission denied. | 8700| 14800024 | SQLite: The database file is locked. | 8701| 14800025 | SQLite: A table in the database is locked. | 8702| 14800026 | SQLite: The database is out of memory. | 8703| 14800027 | SQLite: Attempt to write a readonly database. | 8704| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8705| 14800029 | SQLite: The database is full. | 8706| 14800030 | SQLite: Unable to open the database file. | 8707| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8708| 14800032 | SQLite: Abort due to constraint violation. | 8709| 14800033 | SQLite: Data type mismatch. | 8710| 14800034 | SQLite: Library used incorrectly. | 8711 8712**Example** 8713 8714```ts 8715if (resultSet != undefined) { 8716 const codes = (resultSet as relationalStore.ResultSet).getBlob((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 8717} 8718``` 8719 8720### getString 8721 8722getString(columnIndex: number): string 8723 8724Obtains the value from the specified column and current row, and returns it in the form of a string.<br>If the type of the value in the specified column is INTEGER, DOUBLE, TEXT, or BLOB, a string will be returned. If the value type is INTEGER and the column is empty, an empty string will be returned. If the value is of any other type, **14800000** will be returned. If the value in the current column is of the DOUBLE type, the precision may be lost. You are advised to use [getDouble](#getdouble) to obtain the value. 8725 8726**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8727 8728**Parameters** 8729 8730| Name | Type | Mandatory| Description | 8731| ----------- | ------ | ---- | ----------------------- | 8732| columnIndex | number | Yes | Index of the target column, starting from 0.| 8733 8734**Return value** 8735 8736| Type | Description | 8737| ------ | ---------------------------- | 8738| string | String obtained.| 8739 8740**Error codes** 8741 8742For 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). 8743 8744| **ID**| **Error Message** | 8745|-----------| ------------------------------------------------------------ | 8746| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8747| 14800000 | Inner error. | 8748| 14800011 | Failed to open the database because it is corrupted. | 8749| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8750| 14800013 | Resultset is empty or column index is out of bounds. | 8751| 14800014 | The RdbStore or ResultSet is already closed. | 8752| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8753| 14800022 | SQLite: Callback routine requested an abort. | 8754| 14800023 | SQLite: Access permission denied. | 8755| 14800024 | SQLite: The database file is locked. | 8756| 14800025 | SQLite: A table in the database is locked. | 8757| 14800026 | SQLite: The database is out of memory. | 8758| 14800027 | SQLite: Attempt to write a readonly database. | 8759| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8760| 14800029 | SQLite: The database is full. | 8761| 14800030 | SQLite: Unable to open the database file. | 8762| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8763| 14800032 | SQLite: Abort due to constraint violation. | 8764| 14800033 | SQLite: Data type mismatch. | 8765| 14800034 | SQLite: Library used incorrectly. | 8766 8767**Example** 8768 8769```ts 8770if (resultSet != undefined) { 8771 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 8772} 8773``` 8774 8775### getLong 8776 8777getLong(columnIndex: number): number 8778 8779Obtains 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. 8780 8781**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8782 8783**Parameters** 8784 8785| Name | Type | Mandatory| Description | 8786| ----------- | ------ | ---- | ----------------------- | 8787| columnIndex | number | Yes | Index of the target column, starting from 0.| 8788 8789**Return value** 8790 8791| Type | Description | 8792| ------ | ------------------------------------------------------------ | 8793| 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).| 8794 8795**Error codes** 8796 8797For 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). 8798 8799| **ID**| **Error Message** | 8800|-----------| ------------------------------------------------------------ | 8801| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8802| 14800000 | Inner error. | 8803| 14800011 | Failed to open the database because it is corrupted. | 8804| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8805| 14800013 | Resultset is empty or column index is out of bounds. | 8806| 14800014 | The RdbStore or ResultSet is already closed. | 8807| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8808| 14800022 | SQLite: Callback routine requested an abort. | 8809| 14800023 | SQLite: Access permission denied. | 8810| 14800024 | SQLite: The database file is locked. | 8811| 14800025 | SQLite: A table in the database is locked. | 8812| 14800026 | SQLite: The database is out of memory. | 8813| 14800027 | SQLite: Attempt to write a readonly database. | 8814| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8815| 14800029 | SQLite: The database is full. | 8816| 14800030 | SQLite: Unable to open the database file. | 8817| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8818| 14800032 | SQLite: Abort due to constraint violation. | 8819| 14800033 | SQLite: Data type mismatch. | 8820| 14800034 | SQLite: Library used incorrectly. | 8821 8822**Example** 8823 8824```ts 8825if (resultSet != undefined) { 8826 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 8827} 8828``` 8829 8830### getDouble 8831 8832getDouble(columnIndex: number): number 8833 8834Obtains 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. 8835 8836**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8837 8838**Parameters** 8839 8840| Name | Type | Mandatory| Description | 8841| ----------- | ------ | ---- | ----------------------- | 8842| columnIndex | number | Yes | Index of the target column, starting from 0.| 8843 8844**Return value** 8845 8846| Type | Description | 8847| ------ | ---------------------------- | 8848| number | Returns the value obtained.| 8849 8850**Error codes** 8851 8852For 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). 8853 8854| **ID**| **Error Message** | 8855|-----------| ------------------------------------------------------------ | 8856| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8857| 14800000 | Inner error. | 8858| 14800011 | Failed to open the database because it is corrupted. | 8859| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8860| 14800013 | Resultset is empty or column index is out of bounds. | 8861| 14800014 | The RdbStore or ResultSet is already closed. | 8862| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8863| 14800022 | SQLite: Callback routine requested an abort. | 8864| 14800023 | SQLite: Access permission denied. | 8865| 14800024 | SQLite: The database file is locked. | 8866| 14800025 | SQLite: A table in the database is locked. | 8867| 14800026 | SQLite: The database is out of memory. | 8868| 14800027 | SQLite: Attempt to write a readonly database. | 8869| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8870| 14800029 | SQLite: The database is full. | 8871| 14800030 | SQLite: Unable to open the database file. | 8872| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8873| 14800032 | SQLite: Abort due to constraint violation. | 8874| 14800033 | SQLite: Data type mismatch. | 8875| 14800034 | SQLite: Library used incorrectly. | 8876 8877**Example** 8878 8879```ts 8880if (resultSet != undefined) { 8881 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 8882} 8883``` 8884 8885### getAsset<sup>10+</sup> 8886 8887getAsset(columnIndex: number): Asset 8888 8889Obtains 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. 8890 8891**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8892 8893**Parameters** 8894 8895| Name | Type | Mandatory | Description | 8896| ----------- | ------ | --- | ------------ | 8897| columnIndex | number | Yes | Index of the target column, starting from 0.| 8898 8899**Return value** 8900 8901| Type | Description | 8902| --------------- | -------------------------- | 8903| [Asset](#asset10) | Returns the value obtained.| 8904 8905**Error codes** 8906 8907For 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). 8908 8909| **ID**| **Error Message** | 8910|-----------| ------------------------------------------------------------ | 8911| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8912| 14800000 | Inner error. | 8913| 14800011 | Failed to open the database because it is corrupted. | 8914| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8915| 14800013 | Resultset is empty or column index is out of bounds. | 8916| 14800014 | The RdbStore or ResultSet is already closed. | 8917| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8918| 14800022 | SQLite: Callback routine requested an abort. | 8919| 14800023 | SQLite: Access permission denied. | 8920| 14800024 | SQLite: The database file is locked. | 8921| 14800025 | SQLite: A table in the database is locked. | 8922| 14800026 | SQLite: The database is out of memory. | 8923| 14800027 | SQLite: Attempt to write a readonly database. | 8924| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8925| 14800029 | SQLite: The database is full. | 8926| 14800030 | SQLite: Unable to open the database file. | 8927| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8928| 14800032 | SQLite: Abort due to constraint violation. | 8929| 14800033 | SQLite: Data type mismatch. | 8930| 14800034 | SQLite: Library used incorrectly. | 8931 8932**Example** 8933 8934```ts 8935if (resultSet != undefined) { 8936 const doc = (resultSet as relationalStore.ResultSet).getAsset((resultSet as relationalStore.ResultSet).getColumnIndex("DOC")); 8937} 8938``` 8939 8940### getAssets<sup>10+</sup> 8941 8942getAssets(columnIndex: number): Assets 8943 8944Obtains the value from the specified column and current row, and returns the value obtained 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. 8945 8946**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8947 8948**Parameters** 8949 8950| Name | Type | Mandatory | Description | 8951| ----------- | ------ | --- | ------------ | 8952| columnIndex | number | Yes | Index of the target column, starting from 0.| 8953 8954**Return value** 8955 8956| Type | Description | 8957| ---------------- | ---------------------------- | 8958| [Assets](#assets10)| Returns the value obtained.| 8959 8960**Error codes** 8961 8962For 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). 8963 8964| **ID**| **Error Message** | 8965|-----------| ------------------------------------------------------------ | 8966| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8967| 14800000 | Inner error. | 8968| 14800011 | Failed to open the database because it is corrupted. | 8969| 14800012 | ResultSet is empty or pointer index is out of bounds. | 8970| 14800013 | Resultset is empty or column index is out of bounds. | 8971| 14800014 | The RdbStore or ResultSet is already closed. | 8972| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 8973| 14800022 | SQLite: Callback routine requested an abort. | 8974| 14800023 | SQLite: Access permission denied. | 8975| 14800024 | SQLite: The database file is locked. | 8976| 14800025 | SQLite: A table in the database is locked. | 8977| 14800026 | SQLite: The database is out of memory. | 8978| 14800027 | SQLite: Attempt to write a readonly database. | 8979| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8980| 14800029 | SQLite: The database is full. | 8981| 14800030 | SQLite: Unable to open the database file. | 8982| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8983| 14800032 | SQLite: Abort due to constraint violation. | 8984| 14800033 | SQLite: Data type mismatch. | 8985| 14800034 | SQLite: Library used incorrectly. | 8986 8987**Example** 8988 8989```ts 8990if (resultSet != undefined) { 8991 const docs = (resultSet as relationalStore.ResultSet).getAssets((resultSet as relationalStore.ResultSet).getColumnIndex("DOCS")); 8992} 8993``` 8994 8995### getRow<sup>11+</sup> 8996 8997getRow(): ValuesBucket 8998 8999Obtains the data in the current row. 9000 9001**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9002 9003**Return value** 9004 9005| Type | Description | 9006| ---------------- | ---------------------------- | 9007| [ValuesBucket](#valuesbucket) | Data obtained.| 9008 9009**Error codes** 9010 9011For 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). 9012 9013| **ID**| **Error Message** | 9014|-----------| ------------------------------------------------------------ | 9015| 14800000 | Inner error. | 9016| 14800011 | Failed to open the database because it is corrupted. | 9017| 14800012 | ResultSet is empty or pointer index is out of bounds. | 9018| 14800013 | Resultset is empty or column index is out of bounds. | 9019| 14800014 | The RdbStore or ResultSet is already closed. | 9020| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 9021| 14800022 | SQLite: Callback routine requested an abort. | 9022| 14800023 | SQLite: Access permission denied. | 9023| 14800024 | SQLite: The database file is locked. | 9024| 14800025 | SQLite: A table in the database is locked. | 9025| 14800026 | SQLite: The database is out of memory. | 9026| 14800027 | SQLite: Attempt to write a readonly database. | 9027| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9028| 14800029 | SQLite: The database is full. | 9029| 14800030 | SQLite: Unable to open the database file. | 9030| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9031| 14800032 | SQLite: Abort due to constraint violation. | 9032| 14800033 | SQLite: Data type mismatch. | 9033| 14800034 | SQLite: Library used incorrectly. | 9034 9035**Example** 9036 9037```ts 9038if (resultSet != undefined) { 9039 const row = (resultSet as relationalStore.ResultSet).getRow(); 9040} 9041``` 9042 9043### getRows<sup>18+</sup> 9044 9045getRows(maxCount: number, position?: number): Promise<Array\<ValuesBucket>> 9046 9047Obtains a specified amount of data from the result set. This API uses a promise to return the result. Do not call this API concurrently with other APIs of [ResultSet](#resultset). Otherwise, unexpected data may be obtained. 9048 9049**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9050 9051**Parameters** 9052 9053| Name | Type | Mandatory| Description | 9054| ----------- | ------ | ---- | ----------------------- | 9055| maxCount | number | Yes | Number of rows to obtain. The value is a positive integer. If the value is not a positive integer, error 401 will be thrown.| 9056| position | number | No | Start position for obtaining data from the result set. The value is a non-negative integer. If this parameter is not specified, data is obtained from the current row of the result set (by default, it is the first row of the result set when data is obtained for the first time). If it is not a non-negative integer, error code 401 will be thrown.| 9057 9058 9059**Return value** 9060 9061| Type | Description | 9062| ---------------- | ---------------------------- | 9063| Promise<Array<[ValuesBucket](#valuesbucket)>> | Promise used to return **maxCount** rows of data obtained. If the number of remaining records is less than **maxCount**, the remaining records are returned. Returning an empty array indicates that the end of the result set is reached.| 9064 9065**Error codes** 9066 9067For 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). 9068 9069| **ID**| **Error Message** | 9070|-----------| ------------------------------------------------------------ | 9071| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9072| 14800000 | Inner error. | 9073| 14800011 | Failed to open the database because it is corrupted. | 9074| 14800012 | ResultSet is empty or pointer index is out of bounds. | 9075| 14800013 | Resultset is empty or column index is out of bounds. | 9076| 14800014 | The RdbStore or ResultSet is already closed. | 9077| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 9078| 14800022 | SQLite: Callback routine requested an abort. | 9079| 14800023 | SQLite: Access permission denied. | 9080| 14800024 | SQLite: The database file is locked. | 9081| 14800025 | SQLite: A table in the database is locked. | 9082| 14800026 | SQLite: The database is out of memory. | 9083| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9084| 14800029 | SQLite: The database is full. | 9085| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9086| 14800032 | SQLite: Abort due to constraint violation. | 9087| 14800033 | SQLite: Data type mismatch. | 9088 9089**Example** 9090 9091```ts 9092// Obtain 100 rows of data. 9093async function proccessRows(resultSet: relationalStore.ResultSet) { 9094 // Example 1: Specify only maxCount. 9095 if (resultSet != undefined) { 9096 let rows: Array<relationalStore.ValuesBucket>; 9097 let maxCount: number = 50; 9098 // Obtain data from the current row of the result set. By default, the first fetch starts from the first row of the current result set. Subsequent fetches start from the row following the last row retrieved. 9099 // getRows automatically moves the current row of the result set to the row following the last row retrieved by the previous getRows call. You do not need to use APIs such as goToFirstRow and goToNextRow. 9100 while ((rows = await (resultSet as relationalStore.ResultSet).getRows(maxCount)).length != 0) { 9101 console.info(JSON.stringify(rows[0])); 9102 } 9103 } 9104 9105 // Example 2: Specify maxCount and position. 9106 if (resultSet != undefined) { 9107 let rows: Array<relationalStore.ValuesBucket>; 9108 let maxCount: number = 50; 9109 let position: number = 50; 9110 while ((rows = await (resultSet as relationalStore.ResultSet).getRows(maxCount, position)).length != 0) { 9111 console.info(JSON.stringify(rows[0])); 9112 position += rows.length; 9113 } 9114 } 9115} 9116``` 9117 9118### getSendableRow<sup>12+</sup> 9119 9120getSendableRow(): sendableRelationalStore.ValuesBucket 9121 9122Obtains the sendable data from the current row. The sendable data can be passed across threads. 9123 9124**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9125 9126**Return value** 9127 9128| Type | Description | 9129| ---------------------------------------------------------------------------------------------- | -------------------------------------------- | 9130| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | Sendable data obtained for cross-thread transfer.| 9131 9132**Error codes** 9133 9134For 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). 9135 9136| **ID**| **Error Message** | 9137| ------------ | --------------------------------------------- | 9138| 14800000 | Inner error. | 9139| 14800011 | Failed to open the database because it is corrupted. | 9140| 14800012 | ResultSet is empty or pointer index is out of bounds. | 9141| 14800013 | Resultset is empty or column index is out of bounds. | 9142| 14800014 | The RdbStore or ResultSet is already closed. | 9143| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 9144| 14800022 | SQLite: Callback routine requested an abort. | 9145| 14800023 | SQLite: Access permission denied. | 9146| 14800024 | SQLite: The database file is locked. | 9147| 14800025 | SQLite: A table in the database is locked. | 9148| 14800026 | SQLite: The database is out of memory. | 9149| 14800027 | SQLite: Attempt to write a readonly database. | 9150| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9151| 14800029 | SQLite: The database is full. | 9152| 14800030 | SQLite: Unable to open the database file. | 9153| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9154| 14800032 | SQLite: Abort due to constraint violation. | 9155| 14800033 | SQLite: Data type mismatch. | 9156| 14800034 | SQLite: Library used incorrectly. | 9157 9158**Example** 9159 9160<!--code_no_check--> 9161```ts 9162import { window } from '@kit.ArkUI'; 9163import { UIAbility } from '@kit.AbilityKit'; 9164import { relationalStore } from '@kit.ArkData'; 9165import { taskpool } from '@kit.ArkTS'; 9166import type ctx from '@ohos.app.ability.common'; 9167import { sendableRelationalStore } from '@kit.ArkData'; 9168 9169@Concurrent 9170async function getDataByName(name: string, context: ctx.UIAbilityContext) { 9171 const STORE_CONFIG: relationalStore.StoreConfig = { 9172 name: "RdbTest.db", 9173 securityLevel: relationalStore.SecurityLevel.S3 9174 }; 9175 const store = await relationalStore.getRdbStore(context, STORE_CONFIG); 9176 const predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 9177 predicates.equalTo("NAME", name); 9178 const resultSet = store.querySync(predicates); 9179 9180 if (resultSet.rowCount > 0) { 9181 resultSet.goToFirstRow(); 9182 const sendableValuesBucket = resultSet.getSendableRow(); 9183 return sendableValuesBucket; 9184 } else { 9185 return null; 9186 } 9187} 9188 9189export default class EntryAbility extends UIAbility { 9190 async onWindowStageCreate(windowStage: window.WindowStage) { 9191 const task = new taskpool.Task(getDataByName, 'Lisa', this.context); 9192 const sendableValuesBucket = await taskpool.execute(task) as sendableRelationalStore.ValuesBucket; 9193 9194 if (sendableValuesBucket) { 9195 const columnCount = sendableValuesBucket.size; 9196 const age = sendableValuesBucket.get('age'); 9197 const name = sendableValuesBucket.get('name'); 9198 console.info(`Query data in taskpool succeeded, name is "${name}", age is "${age}"`); 9199 } 9200 } 9201} 9202``` 9203 9204### isColumnNull 9205 9206isColumnNull(columnIndex: number): boolean 9207 9208Checks whether the value in the specified column is null. 9209 9210**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9211 9212**Parameters** 9213 9214| Name | Type | Mandatory| Description | 9215| ----------- | ------ | ---- | ----------------------- | 9216| columnIndex | number | Yes | Index of the target column, starting from 0.| 9217 9218**Return value** 9219 9220| Type | Description | 9221| ------- | --------------------------------------------------------- | 9222| boolean | Returns **true** if the value is null; returns **false** otherwise.| 9223 9224**Error codes** 9225 9226For 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). 9227 9228| **ID**| **Error Message** | 9229|-----------| ------------------------------------------------------- | 9230| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9231| 14800000 | Inner error. | 9232| 14800011 | Failed to open the database because it is corrupted. | 9233| 14800012 | ResultSet is empty or pointer index is out of bounds. | 9234| 14800013 | Resultset is empty or column index is out of bounds. | 9235| 14800014 | The RdbStore or ResultSet is already closed. | 9236| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 9237| 14800022 | SQLite: Callback routine requested an abort. | 9238| 14800023 | SQLite: Access permission denied. | 9239| 14800024 | SQLite: The database file is locked. | 9240| 14800025 | SQLite: A table in the database is locked. | 9241| 14800026 | SQLite: The database is out of memory. | 9242| 14800027 | SQLite: Attempt to write a readonly database. | 9243| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9244| 14800029 | SQLite: The database is full. | 9245| 14800030 | SQLite: Unable to open the database file. | 9246| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9247| 14800032 | SQLite: Abort due to constraint violation. | 9248| 14800033 | SQLite: Data type mismatch. | 9249| 14800034 | SQLite: Library used incorrectly. | 9250 9251**Example** 9252 9253```ts 9254if (resultSet != undefined) { 9255 const isColumnNull = (resultSet as relationalStore.ResultSet).isColumnNull((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 9256} 9257``` 9258 9259### close 9260 9261close(): void 9262 9263Closes this **resultSet** to release memory. If the **resultSet** is not closed, FD or memory leaks may occur. 9264 9265**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9266 9267**Example** 9268 9269```ts 9270if (resultSet != undefined) { 9271 (resultSet as relationalStore.ResultSet).close(); 9272} 9273``` 9274 9275**Error codes** 9276 9277For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 9278 9279| **ID**| **Error Message** | 9280|-----------| ------------------------------------------------------------ | 9281| 14800000 | Inner error. | 9282| 14800012 | ResultSet is empty or pointer index is out of bounds. | 9283 9284## Transaction<sup>14+</sup> 9285 9286Provides API for managing databases in transaction mode. A transaction object is created by using [createTransaction](#createtransaction14). Operations on different transaction objects are isolated. For details about the transaction types, see [TransactionType](#transactiontype14). 9287 9288Currently, an RDB store supports only one write transaction at a time. If the current [RdbStore](#rdbstore) has a write transaction that is not released, creating an **IMMEDIATE** or **EXCLUSIVE** transaction object will return error 14800024. If a **DEFERRED** transaction object is created, error 14800024 may be returned when it is used to invoke a write operation for the first time. After a write transaction is created using **IMMEDIATE** or **EXCLUSIVE**, or a **DEFERRED** transaction is upgraded to a write transaction, write operations in the [RdbStore](#rdbstore) will also return error 14800024. 9289 9290When the number of concurrent transactions is large and the write transaction duration is long, the frequency of returning error 14800024 may increase. You can reduce the occurrence of error 14800024 by shortening the transaction duration or by handling the error 14800024 through retries. 9291 9292**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9293 9294**Example** 9295 9296```ts 9297import { UIAbility } from '@kit.AbilityKit'; 9298import { BusinessError } from '@kit.BasicServicesKit'; 9299import { window } from '@kit.ArkUI'; 9300 9301let store: relationalStore.RdbStore | undefined = undefined; 9302 9303class EntryAbility extends UIAbility { 9304 async onWindowStageCreate(windowStage: window.WindowStage) { 9305 const STORE_CONFIG: relationalStore.StoreConfig = { 9306 name: "RdbTest.db", 9307 securityLevel: relationalStore.SecurityLevel.S3 9308 }; 9309 9310 await relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 9311 store = rdbStore; 9312 console.info('Get RdbStore successfully.'); 9313 }).catch((err: BusinessError) => { 9314 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 9315 }); 9316 9317 if (store != undefined) { 9318 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9319 console.info(`createTransaction success`); 9320 // Perform subsequent operations after the transaction instance is successfully obtained. 9321 }).catch((err: BusinessError) => { 9322 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9323 }); 9324 } 9325 } 9326} 9327``` 9328 9329### commit<sup>14+</sup> 9330 9331commit(): Promise<void> 9332 9333Commits the executed SQL statements. When using asynchronous APIs to execute SQL statements, ensure that **commit()** is called after the asynchronous API execution is completed. Otherwise, the SQL operations may be lost. After **commit()** is called, the transaction object and the created **ResultSet** object will be closed. 9334 9335**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9336 9337**Return value** 9338 9339| Type | Description | 9340| ------------------- | ------------------------- | 9341| Promise<void> | Promise that returns no value.| 9342 9343**Error codes** 9344 9345For 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). 9346 9347| **ID**| **Error Message** | 9348|-----------| ------------------------------------------------------------ | 9349| 14800000 | Inner error. | 9350| 14800011 | Failed to open the database because it is corrupted. | 9351| 14800014 | The RdbStore or ResultSet is already closed. | 9352| 14800023 | SQLite: Access permission denied. | 9353| 14800024 | SQLite: The database file is locked. | 9354| 14800026 | SQLite: The database is out of memory. | 9355| 14800027 | SQLite: Attempt to write a readonly database. | 9356| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9357| 14800029 | SQLite: The database is full. | 9358 9359**Example** 9360 9361```ts 9362let value1 = "Lisa"; 9363let value2 = 18; 9364let value3 = 100.5; 9365let value4 = new Uint8Array([1, 2, 3]); 9366 9367if (store != undefined) { 9368 const valueBucket: relationalStore.ValuesBucket = { 9369 'NAME': value1, 9370 'AGE': value2, 9371 'SALARY': value3, 9372 'CODES': value4 9373 }; 9374 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9375 transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => { 9376 transaction.commit(); 9377 }).catch((e: BusinessError) => { 9378 transaction.rollback(); 9379 console.error(`execute sql failed, code is ${e.code},message is ${e.message}`); 9380 }); 9381 }).catch((err: BusinessError) => { 9382 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9383 }); 9384} 9385``` 9386 9387### rollback<sup>14+</sup> 9388 9389rollback(): Promise<void> 9390 9391Rolls back the executed SQL statement. After **rollback()** is called, the transaction object and the created **ResultSet** object will be closed. 9392 9393**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9394 9395**Return value** 9396 9397| Type | Description | 9398| ------------------- | ------------------------- | 9399| Promise<void> | Promise that returns no value.| 9400 9401**Error codes** 9402 9403For 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). 9404 9405| **ID**| **Error Message** | 9406|-----------| ------------------------------------------------------------ | 9407| 14800000 | Inner error. | 9408| 14800011 | Failed to open the database because it is corrupted. | 9409| 14800014 | The RdbStore or ResultSet is already closed. | 9410| 14800023 | SQLite: Access permission denied. | 9411| 14800024 | SQLite: The database file is locked. | 9412| 14800026 | SQLite: The database is out of memory. | 9413| 14800027 | SQLite: Attempt to write a readonly database. | 9414| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9415| 14800029 | SQLite: The database is full. | 9416 9417**Example** 9418 9419```ts 9420if (store != undefined) { 9421 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9422 transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => { 9423 transaction.commit(); 9424 }).catch((e: BusinessError) => { 9425 transaction.rollback(); 9426 console.error(`execute sql failed, code is ${e.code},message is ${e.message}`); 9427 }); 9428 }).catch((err: BusinessError) => { 9429 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9430 }); 9431} 9432``` 9433 9434### insert<sup>14+</sup> 9435 9436insert(table: string, values: ValuesBucket, conflict?: ConflictResolution): Promise<number> 9437 9438Inserts 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. 9439 9440**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9441 9442**Parameters** 9443 9444| Name | Type | Mandatory| Description | 9445| -------- | ------------------------------------------- | ---- | -------------------------- | 9446| table | string | Yes | Name of the target table. | 9447| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 9448| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**. | 9449 9450**Return value** 9451 9452| Type | Description | 9453| --------------------- | ------------------------------------------------- | 9454| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 9455 9456**Error codes** 9457 9458For 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). 9459 9460| **ID**| **Error Message** | 9461|-----------| ------------------------------------------------------------ | 9462| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9463| 14800000 | Inner error. | 9464| 14800011 | Failed to open the database because it is corrupted. | 9465| 14800014 | The RdbStore or ResultSet is already closed. | 9466| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 9467| 14800023 | SQLite: Access permission denied. | 9468| 14800024 | SQLite: The database file is locked. | 9469| 14800025 | SQLite: A table in the database is locked. | 9470| 14800026 | SQLite: The database is out of memory. | 9471| 14800027 | SQLite: Attempt to write a readonly database. | 9472| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9473| 14800029 | SQLite: The database is full. | 9474| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9475| 14800033 | SQLite: Data type mismatch. | 9476| 14800047 | The WAL file size exceeds the default limit. | 9477 9478**Example** 9479 9480```ts 9481let value1 = "Lisa"; 9482let value2 = 18; 9483let value3 = 100.5; 9484let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9485 9486// You can use either of the following: 9487const valueBucket1: relationalStore.ValuesBucket = { 9488 'NAME': value1, 9489 'AGE': value2, 9490 'SALARY': value3, 9491 'CODES': value4 9492}; 9493const valueBucket2: relationalStore.ValuesBucket = { 9494 NAME: value1, 9495 AGE: value2, 9496 SALARY: value3, 9497 CODES: value4 9498}; 9499const valueBucket3: relationalStore.ValuesBucket = { 9500 "NAME": value1, 9501 "AGE": value2, 9502 "SALARY": value3, 9503 "CODES": value4 9504}; 9505 9506if (store != undefined) { 9507 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9508 transaction.insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => { 9509 transaction.commit(); 9510 console.info(`Insert is successful, rowId = ${rowId}`); 9511 }).catch((e: BusinessError) => { 9512 transaction.rollback(); 9513 console.error(`Insert is failed, code is ${e.code},message is ${e.message}`); 9514 }); 9515 }).catch((err: BusinessError) => { 9516 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9517 }); 9518} 9519``` 9520 9521### insertSync<sup>14+</sup> 9522 9523insertSync(table: string, values: ValuesBucket | sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution): number 9524 9525Inserts 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. 9526 9527**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9528 9529**Parameters** 9530 9531| Name | Type | Mandatory| Description | 9532| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 9533| table | string | Yes | Name of the target table. | 9534| values | [ValuesBucket](#valuesbucket) \| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | Yes | Row of data to insert. | 9535| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 9536 9537**Return value** 9538 9539| Type | Description | 9540| ------ | ------------------------------------ | 9541| number | If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 9542 9543**Error codes** 9544 9545For 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). 9546 9547| **ID**| **Error Message** | 9548| ------------ | ------------------------------------------------------------ | 9549| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9550| 14800000 | Inner error. | 9551| 14800011 | Failed to open the database because it is corrupted. | 9552| 14800014 | The RdbStore or ResultSet is already closed. | 9553| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 9554| 14800023 | SQLite: Access permission denied. | 9555| 14800024 | SQLite: The database file is locked. | 9556| 14800025 | SQLite: A table in the database is locked. | 9557| 14800026 | SQLite: The database is out of memory. | 9558| 14800027 | SQLite: Attempt to write a readonly database. | 9559| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9560| 14800029 | SQLite: The database is full. | 9561| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9562| 14800033 | SQLite: Data type mismatch. | 9563| 14800047 | The WAL file size exceeds the default limit. | 9564 9565**Example** 9566 9567```ts 9568let value1 = "Lisa"; 9569let value2 = 18; 9570let value3 = 100.5; 9571let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9572 9573// You can use either of the following: 9574const valueBucket1: relationalStore.ValuesBucket = { 9575 'NAME': value1, 9576 'AGE': value2, 9577 'SALARY': value3, 9578 'CODES': value4 9579}; 9580const valueBucket2: relationalStore.ValuesBucket = { 9581 NAME: value1, 9582 AGE: value2, 9583 SALARY: value3, 9584 CODES: value4 9585}; 9586const valueBucket3: relationalStore.ValuesBucket = { 9587 "NAME": value1, 9588 "AGE": value2, 9589 "SALARY": value3, 9590 "CODES": value4 9591}; 9592 9593if (store != undefined) { 9594 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9595 try { 9596 let rowId: number = (transaction as relationalStore.Transaction).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 9597 transaction.commit(); 9598 console.info(`Insert is successful, rowId = ${rowId}`); 9599 } catch (e) { 9600 transaction.rollback(); 9601 console.error(`Insert is failed, code is ${e.code},message is ${e.message}`); 9602 }; 9603 }).catch((err: BusinessError) => { 9604 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9605 }); 9606} 9607``` 9608 9609### batchInsert<sup>14+</sup> 9610 9611batchInsert(table: string, values: Array<ValuesBucket>): Promise<number> 9612 9613Inserts a batch of data into a table. This API uses a promise to return the result. 9614 9615**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9616 9617**Parameters** 9618 9619| Name| Type | Mandatory| Description | 9620| ------ | ------------------------------------------ | ---- | ---------------------------- | 9621| table | string | Yes | Name of the target table. | 9622| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 9623 9624**Return value** 9625 9626| Type | Description | 9627| --------------------- | ----------------------------------------------------------- | 9628| 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.| 9629 9630**Error codes** 9631 9632For 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). 9633 9634| **ID**| **Error Message** | 9635|-----------| ------------------------------------------------------------ | 9636| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9637| 14800000 | Inner error. | 9638| 14800011 | Failed to open the database because it is corrupted. | 9639| 14800014 | The RdbStore or ResultSet is already closed. | 9640| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 9641| 14800023 | SQLite: Access permission denied. | 9642| 14800024 | SQLite: The database file is locked. | 9643| 14800025 | SQLite: A table in the database is locked. | 9644| 14800026 | SQLite: The database is out of memory. | 9645| 14800027 | SQLite: Attempt to write a readonly database. | 9646| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9647| 14800029 | SQLite: The database is full. | 9648| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9649| 14800033 | SQLite: Data type mismatch. | 9650| 14800047 | The WAL file size exceeds the default limit. | 9651 9652**Example** 9653 9654```ts 9655let value1 = "Lisa"; 9656let value2 = 18; 9657let value3 = 100.5; 9658let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9659let value5 = "Jack"; 9660let value6 = 19; 9661let value7 = 101.5; 9662let value8 = new Uint8Array([6, 7, 8, 9, 10]); 9663let value9 = "Tom"; 9664let value10 = 20; 9665let value11 = 102.5; 9666let value12 = new Uint8Array([11, 12, 13, 14, 15]); 9667 9668const valueBucket1: relationalStore.ValuesBucket = { 9669 'NAME': value1, 9670 'AGE': value2, 9671 'SALARY': value3, 9672 'CODES': value4 9673}; 9674const valueBucket2: relationalStore.ValuesBucket = { 9675 'NAME': value5, 9676 'AGE': value6, 9677 'SALARY': value7, 9678 'CODES': value8 9679}; 9680const valueBucket3: relationalStore.ValuesBucket = { 9681 'NAME': value9, 9682 'AGE': value10, 9683 'SALARY': value11, 9684 'CODES': value12 9685}; 9686 9687let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 9688if (store != undefined) { 9689 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9690 transaction.batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => { 9691 transaction.commit(); 9692 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 9693 }).catch((e: BusinessError) => { 9694 transaction.rollback(); 9695 console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`); 9696 }); 9697 }).catch((err: BusinessError) => { 9698 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9699 }); 9700} 9701``` 9702 9703### batchInsertSync<sup>14+</sup> 9704 9705batchInsertSync(table: string, values: Array<ValuesBucket>): number 9706 9707Inserts a batch of data into a table. This API returns the result synchronously. 9708 9709**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9710 9711**Parameters** 9712 9713| Name| Type | Mandatory| Description | 9714| ------ | ------------------------------------------ | ---- | ---------------------------- | 9715| table | string | Yes | Name of the target table. | 9716| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 9717 9718**Return value** 9719 9720| Type | Description | 9721| ------ | ---------------------------------------------- | 9722| number | If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 9723 9724**Error codes** 9725 9726For 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). 9727 9728| **ID**| **Error Message** | 9729| ------------ | ------------------------------------------------------------ | 9730| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9731| 14800000 | Inner error. | 9732| 14800011 | Failed to open the database because it is corrupted. | 9733| 14800014 | The RdbStore or ResultSet is already closed. | 9734| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 9735| 14800023 | SQLite: Access permission denied. | 9736| 14800024 | SQLite: The database file is locked. | 9737| 14800025 | SQLite: A table in the database is locked. | 9738| 14800026 | SQLite: The database is out of memory. | 9739| 14800027 | SQLite: Attempt to write a readonly database. | 9740| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9741| 14800029 | SQLite: The database is full. | 9742| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9743| 14800033 | SQLite: Data type mismatch. | 9744| 14800047 | The WAL file size exceeds the default limit. | 9745 9746**Example** 9747 9748```ts 9749let value1 = "Lisa"; 9750let value2 = 18; 9751let value3 = 100.5; 9752let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9753let value5 = "Jack"; 9754let value6 = 19; 9755let value7 = 101.5; 9756let value8 = new Uint8Array([6, 7, 8, 9, 10]); 9757let value9 = "Tom"; 9758let value10 = 20; 9759let value11 = 102.5; 9760let value12 = new Uint8Array([11, 12, 13, 14, 15]); 9761 9762const valueBucket1: relationalStore.ValuesBucket = { 9763 'NAME': value1, 9764 'AGE': value2, 9765 'SALARY': value3, 9766 'CODES': value4 9767}; 9768const valueBucket2: relationalStore.ValuesBucket = { 9769 'NAME': value5, 9770 'AGE': value6, 9771 'SALARY': value7, 9772 'CODES': value8 9773}; 9774const valueBucket3: relationalStore.ValuesBucket = { 9775 'NAME': value9, 9776 'AGE': value10, 9777 'SALARY': value11, 9778 'CODES': value12 9779}; 9780 9781let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 9782if (store != undefined) { 9783 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9784 try { 9785 let insertNum: number = (transaction as relationalStore.Transaction).batchInsertSync("EMPLOYEE", valueBuckets); 9786 transaction.commit(); 9787 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 9788 } catch (e) { 9789 transaction.rollback(); 9790 console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`); 9791 }; 9792 }).catch((err: BusinessError) => { 9793 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9794 }); 9795} 9796``` 9797 9798### batchInsertWithConflictResolution<sup>18+</sup> 9799 9800batchInsertWithConflictResolution(table: string, values: Array<ValuesBucket>, conflict: ConflictResolution): Promise<number> 9801 9802Inserts a batch of data into a table with conflict resolutions. This API uses a promise to return the result. 9803 9804**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9805 9806**Parameters** 9807 9808| Name| Type | Mandatory| Description | 9809| ------ | ------------------------------------------ | ---- | ---------------------------- | 9810| table | string | Yes | Name of the target table. | 9811| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 9812| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. If **ON_CONFLICT_ROLLBACK** is used, the transaction will be rolled back when a conflict occurs.| 9813 9814**Return value** 9815 9816| Type | Description | 9817| --------------------- | ----------------------------------------------------------- | 9818| 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.| 9819 9820**Error codes** 9821 9822For 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). 9823 9824| **ID**| **Error Message** | 9825|-----------| ------------------------------------------------------------ | 9826| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9827| 14800000 | Inner error. | 9828| 14800011 | Failed to open the database because it is corrupted. | 9829| 14800014 | The RdbStore or ResultSet is already closed. | 9830| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 9831| 14800022 | SQLite: Callback routine requested an abort. | 9832| 14800023 | SQLite: Access permission denied. | 9833| 14800024 | SQLite: The database file is locked. | 9834| 14800025 | SQLite: A table in the database is locked. | 9835| 14800026 | SQLite: The database is out of memory. | 9836| 14800027 | SQLite: Attempt to write a readonly database. | 9837| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9838| 14800029 | SQLite: The database is full. | 9839| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9840| 14800032 | SQLite: Abort due to constraint violation. | 9841| 14800033 | SQLite: Data type mismatch. | 9842| 14800034 | SQLite: Library used incorrectly. | 9843| 14800047 | The WAL file size exceeds the default limit. | 9844 9845**Example** 9846 9847```ts 9848let value1 = "Lisa"; 9849let value2 = 18; 9850let value3 = 100.5; 9851let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9852let value5 = "Jack"; 9853let value6 = 19; 9854let value7 = 101.5; 9855let value8 = new Uint8Array([6, 7, 8, 9, 10]); 9856let value9 = "Tom"; 9857let value10 = 20; 9858let value11 = 102.5; 9859let value12 = new Uint8Array([11, 12, 13, 14, 15]); 9860 9861const valueBucket1: relationalStore.ValuesBucket = { 9862 'NAME': value1, 9863 'AGE': value2, 9864 'SALARY': value3, 9865 'CODES': value4 9866}; 9867const valueBucket2: relationalStore.ValuesBucket = { 9868 'NAME': value5, 9869 'AGE': value6, 9870 'SALARY': value7, 9871 'CODES': value8 9872}; 9873const valueBucket3: relationalStore.ValuesBucket = { 9874 'NAME': value9, 9875 'AGE': value10, 9876 'SALARY': value11, 9877 'CODES': value12 9878}; 9879 9880let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 9881if (store != undefined) { 9882 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9883 transaction.batchInsertWithConflictResolution("EMPLOYEE", valueBuckets, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((insertNum: number) => { 9884 transaction.commit(); 9885 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 9886 }).catch((e: BusinessError) => { 9887 transaction.rollback(); 9888 console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`); 9889 }); 9890 }).catch((err: BusinessError) => { 9891 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9892 }); 9893} 9894``` 9895 9896### batchInsertWithConflictResolutionSync<sup>18+</sup> 9897 9898batchInsertWithConflictResolutionSync(table: string, values: Array<ValuesBucket>, conflict: ConflictResolution): number 9899 9900Inserts a batch of data into a table with conflict resolutions. 9901 9902**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9903 9904**Parameters** 9905 9906| Name| Type | Mandatory| Description | 9907| ------ | ------------------------------------------ | ---- | ---------------------------- | 9908| table | string | Yes | Name of the target table. | 9909| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 9910| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. If **ON_CONFLICT_ROLLBACK** is used, the transaction will be rolled back when a conflict occurs.| 9911 9912**Return value** 9913 9914| Type | Description | 9915| ------ | ---------------------------------------------- | 9916| number | If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 9917 9918**Error codes** 9919 9920For 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). 9921 9922| **ID**| **Error Message** | 9923| ------------ | ------------------------------------------------------------ | 9924| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9925| 14800000 | Inner error. | 9926| 14800011 | Failed to open the database because it is corrupted. | 9927| 14800014 | The RdbStore or ResultSet is already closed. | 9928| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 9929| 14800022 | SQLite: Callback routine requested an abort. | 9930| 14800023 | SQLite: Access permission denied. | 9931| 14800024 | SQLite: The database file is locked. | 9932| 14800025 | SQLite: A table in the database is locked. | 9933| 14800026 | SQLite: The database is out of memory. | 9934| 14800027 | SQLite: Attempt to write a readonly database. | 9935| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9936| 14800029 | SQLite: The database is full. | 9937| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9938| 14800032 | SQLite: Abort due to constraint violation. | 9939| 14800033 | SQLite: Data type mismatch. | 9940| 14800034 | SQLite: Library used incorrectly. | 9941| 14800047 | The WAL file size exceeds the default limit. | 9942 9943**Example** 9944 9945```ts 9946let value1 = "Lisa"; 9947let value2 = 18; 9948let value3 = 100.5; 9949let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9950let value5 = "Jack"; 9951let value6 = 19; 9952let value7 = 101.5; 9953let value8 = new Uint8Array([6, 7, 8, 9, 10]); 9954let value9 = "Tom"; 9955let value10 = 20; 9956let value11 = 102.5; 9957let value12 = new Uint8Array([11, 12, 13, 14, 15]); 9958 9959const valueBucket1: relationalStore.ValuesBucket = { 9960 'NAME': value1, 9961 'AGE': value2, 9962 'SALARY': value3, 9963 'CODES': value4 9964}; 9965const valueBucket2: relationalStore.ValuesBucket = { 9966 'NAME': value5, 9967 'AGE': value6, 9968 'SALARY': value7, 9969 'CODES': value8 9970}; 9971const valueBucket3: relationalStore.ValuesBucket = { 9972 'NAME': value9, 9973 'AGE': value10, 9974 'SALARY': value11, 9975 'CODES': value12 9976}; 9977 9978let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 9979if (store != undefined) { 9980 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9981 try { 9982 let insertNum: number = (transaction as relationalStore.Transaction).batchInsertWithConflictResolutionSync("EMPLOYEE", valueBuckets, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 9983 transaction.commit(); 9984 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 9985 } catch (e) { 9986 transaction.rollback(); 9987 console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`); 9988 }; 9989 }).catch((err: BusinessError) => { 9990 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9991 }); 9992} 9993``` 9994 9995### update<sup>14+</sup> 9996 9997update(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): Promise<number> 9998 9999Updates 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. 10000 10001**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 10002 10003**Parameters** 10004 10005| Name | Type | Mandatory| Description | 10006| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 10007| 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.| 10008| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 10009| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**. | 10010 10011**Return value** 10012 10013| Type | Description | 10014| --------------------- | ----------------------------------------- | 10015| Promise<number> | Promise used to return the number of rows updated.| 10016 10017**Error codes** 10018 10019For 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). 10020 10021| **ID**| **Error Message** | 10022|-----------| ------------------------------------------------------------ | 10023| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10024| 14800000 | Inner error. | 10025| 14800011 | Failed to open the database because it is corrupted. | 10026| 14800014 | The RdbStore or ResultSet is already closed. | 10027| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 10028| 14800023 | SQLite: Access permission denied. | 10029| 14800024 | SQLite: The database file is locked. | 10030| 14800025 | SQLite: A table in the database is locked. | 10031| 14800026 | SQLite: The database is out of memory. | 10032| 14800027 | SQLite: Attempt to write a readonly database. | 10033| 14800028 | SQLite: Some kind of disk I/O error occurred. | 10034| 14800029 | SQLite: The database is full. | 10035| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 10036| 14800033 | SQLite: Data type mismatch. | 10037| 14800047 | The WAL file size exceeds the default limit. | 10038 10039**Example** 10040 10041```ts 10042let value1 = "Rose"; 10043let value2 = 22; 10044let value3 = 200.5; 10045let value4 = new Uint8Array([1, 2, 3, 4, 5]); 10046 10047// You can use either of the following: 10048const valueBucket1: relationalStore.ValuesBucket = { 10049 'NAME': value1, 10050 'AGE': value2, 10051 'SALARY': value3, 10052 'CODES': value4 10053}; 10054const valueBucket2: relationalStore.ValuesBucket = { 10055 NAME: value1, 10056 AGE: value2, 10057 SALARY: value3, 10058 CODES: value4 10059}; 10060const valueBucket3: relationalStore.ValuesBucket = { 10061 "NAME": value1, 10062 "AGE": value2, 10063 "SALARY": value3, 10064 "CODES": value4 10065}; 10066 10067let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 10068predicates.equalTo("NAME", "Lisa"); 10069 10070if (store != undefined) { 10071 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 10072 transaction.update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => { 10073 transaction.commit(); 10074 console.info(`Updated row count: ${rows}`); 10075 }).catch((e: BusinessError) => { 10076 transaction.rollback(); 10077 console.error(`Updated failed, code is ${e.code},message is ${e.message}`); 10078 }); 10079 }).catch((err: BusinessError) => { 10080 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 10081 }); 10082} 10083``` 10084 10085### updateSync<sup>14+</sup> 10086 10087updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): number 10088 10089Updates data in the database based on the specified **RdbPredicates** instance. Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 10090 10091**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 10092 10093**Parameters** 10094 10095| Name | Type | Mandatory| Description | 10096| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 10097| 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.| 10098| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 10099| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 10100 10101**Return value** 10102 10103| Type | Description | 10104| ------ | ------------------ | 10105| number | Number of rows updated.| 10106 10107**Error codes** 10108 10109For 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). 10110 10111| **ID**| **Error Message** | 10112| ------------ | ------------------------------------------------------------ | 10113| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10114| 14800000 | Inner error. | 10115| 14800011 | Failed to open the database because it is corrupted. | 10116| 14800014 | The RdbStore or ResultSet is already closed. | 10117| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 10118| 14800023 | SQLite: Access permission denied. | 10119| 14800024 | SQLite: The database file is locked. | 10120| 14800025 | SQLite: A table in the database is locked. | 10121| 14800026 | SQLite: The database is out of memory. | 10122| 14800027 | SQLite: Attempt to write a readonly database. | 10123| 14800028 | SQLite: Some kind of disk I/O error occurred. | 10124| 14800029 | SQLite: The database is full. | 10125| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 10126| 14800033 | SQLite: Data type mismatch. | 10127| 14800047 | The WAL file size exceeds the default limit. | 10128 10129**Example** 10130 10131```ts 10132let value1 = "Rose"; 10133let value2 = 22; 10134let value3 = 200.5; 10135let value4 = new Uint8Array([1, 2, 3, 4, 5]); 10136 10137// You can use either of the following: 10138const valueBucket1: relationalStore.ValuesBucket = { 10139 'NAME': value1, 10140 'AGE': value2, 10141 'SALARY': value3, 10142 'CODES': value4 10143}; 10144const valueBucket2: relationalStore.ValuesBucket = { 10145 NAME: value1, 10146 AGE: value2, 10147 SALARY: value3, 10148 CODES: value4 10149}; 10150const valueBucket3: relationalStore.ValuesBucket = { 10151 "NAME": value1, 10152 "AGE": value2, 10153 "SALARY": value3, 10154 "CODES": value4 10155}; 10156 10157let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 10158predicates.equalTo("NAME", "Lisa"); 10159 10160if (store != undefined) { 10161 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 10162 try { 10163 let rows: Number = (transaction as relationalStore.Transaction).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 10164 transaction.commit(); 10165 console.info(`Updated row count: ${rows}`); 10166 } catch (e) { 10167 transaction.rollback(); 10168 console.error(`Updated failed, code is ${e.code},message is ${e.message}`); 10169 }; 10170 }).catch((err: BusinessError) => { 10171 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 10172 }); 10173} 10174``` 10175 10176### delete<sup>14+</sup> 10177 10178delete(predicates: RdbPredicates):Promise<number> 10179 10180Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result. 10181 10182**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 10183 10184**Parameters** 10185 10186| Name | Type | Mandatory| Description | 10187| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 10188| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 10189 10190**Return value** 10191 10192| Type | Description | 10193| --------------------- | ------------------------------- | 10194| Promise<number> | Promise used to return the number of rows deleted.| 10195 10196**Error codes** 10197 10198For 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). 10199 10200| **ID**| **Error Message** | 10201|-----------| ------------------------------------------------------------ | 10202| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10203| 14800000 | Inner error. | 10204| 14800011 | Failed to open the database because it is corrupted. | 10205| 14800014 | The RdbStore or ResultSet is already closed. | 10206| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 10207| 14800023 | SQLite: Access permission denied. | 10208| 14800024 | SQLite: The database file is locked. | 10209| 14800025 | SQLite: A table in the database is locked. | 10210| 14800026 | SQLite: The database is out of memory. | 10211| 14800027 | SQLite: Attempt to write a readonly database. | 10212| 14800028 | SQLite: Some kind of disk I/O error occurred. | 10213| 14800029 | SQLite: The database is full. | 10214| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 10215| 14800033 | SQLite: Data type mismatch. | 10216| 14800047 | The WAL file size exceeds the default limit. | 10217 10218**Example** 10219 10220```ts 10221let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 10222predicates.equalTo("NAME", "Lisa"); 10223 10224if (store != undefined) { 10225 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 10226 transaction.delete(predicates).then((rows: Number) => { 10227 transaction.commit(); 10228 console.info(`Delete rows: ${rows}`); 10229 }).catch((e: BusinessError) => { 10230 transaction.rollback(); 10231 console.error(`Delete failed, code is ${e.code},message is ${e.message}`); 10232 }); 10233 }).catch((err: BusinessError) => { 10234 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 10235 }); 10236} 10237``` 10238 10239### deleteSync<sup>14+</sup> 10240 10241deleteSync(predicates: RdbPredicates): number 10242 10243Deletes data from the database based on the specified **RdbPredicates** object. 10244 10245**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 10246 10247**Parameters** 10248 10249| Name | Type | Mandatory| Description | 10250| ---------- | ------------------------------- | ---- | --------------------------------------- | 10251| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 10252 10253**Return value** 10254 10255| Type | Description | 10256| ------ | ------------------ | 10257| number | Number of rows updated.| 10258 10259**Error codes** 10260 10261For 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). 10262 10263| **ID**| **Error Message** | 10264| ------------ | ------------------------------------------------------------ | 10265| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10266| 14800000 | Inner error. | 10267| 14800011 | Failed to open the database because it is corrupted. | 10268| 14800014 | The RdbStore or ResultSet is already closed. | 10269| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 10270| 14800023 | SQLite: Access permission denied. | 10271| 14800024 | SQLite: The database file is locked. | 10272| 14800025 | SQLite: A table in the database is locked. | 10273| 14800026 | SQLite: The database is out of memory. | 10274| 14800027 | SQLite: Attempt to write a readonly database. | 10275| 14800028 | SQLite: Some kind of disk I/O error occurred. | 10276| 14800029 | SQLite: The database is full. | 10277| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 10278| 14800033 | SQLite: Data type mismatch. | 10279| 14800047 | The WAL file size exceeds the default limit. | 10280 10281**Example** 10282 10283```ts 10284let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 10285predicates.equalTo("NAME", "Lisa"); 10286 10287if (store != undefined) { 10288 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 10289 try { 10290 let rows: Number = (transaction as relationalStore.Transaction).deleteSync(predicates); 10291 transaction.commit(); 10292 console.info(`Delete rows: ${rows}`); 10293 } catch (e) { 10294 transaction.rollback(); 10295 console.error(`Delete failed, code is ${e.code},message is ${e.message}`); 10296 }; 10297 }).catch((err: BusinessError) => { 10298 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 10299 }); 10300} 10301``` 10302 10303### query<sup>14+</sup> 10304 10305query(predicates: RdbPredicates, columns?: Array<string>): Promise<ResultSet> 10306 10307Queries 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. 10308 10309**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 10310 10311**Parameters** 10312 10313| Name | Type | Mandatory| Description | 10314| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 10315| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 10316| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 10317 10318**Error codes** 10319 10320For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 10321 10322| **ID**| **Error Message** | 10323|-----------| ------------------------------------------------------------ | 10324| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10325| 14800000 | Inner error. | 10326| 14800011 | Failed to open the database because it is corrupted. | 10327| 14800014 | The RdbStore or ResultSet is already closed. | 10328| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 10329| 14800023 | SQLite: Access permission denied. | 10330| 14800024 | SQLite: The database file is locked. | 10331| 14800026 | SQLite: The database is out of memory. | 10332| 14800028 | SQLite: Some kind of disk I/O error occurred. | 10333| 14800047 | The WAL file size exceeds the default limit. | 10334 10335**Return value** 10336 10337| Type | Description | 10338| ------------------------------------------------------- | -------------------------------------------------- | 10339| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 10340 10341**Example** 10342 10343```ts 10344let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 10345predicates.equalTo("NAME", "Rose"); 10346 10347if (store != undefined) { 10348 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 10349 transaction.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then(async (resultSet: relationalStore.ResultSet) => { 10350 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 10351 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 10352 while (resultSet.goToNextRow()) { 10353 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 10354 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 10355 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 10356 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 10357 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 10358 } 10359 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 10360 resultSet.close(); 10361 transaction.commit(); 10362 }).catch((e: BusinessError) => { 10363 transaction.rollback(); 10364 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 10365 }); 10366 }).catch((err: BusinessError) => { 10367 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 10368 }); 10369} 10370``` 10371 10372### querySync<sup>14+</sup> 10373 10374querySync(predicates: RdbPredicates, columns?: Array<string>): ResultSet 10375 10376Queries data in a database based on specified conditions. This API returns the result synchronously. If complex logic and a large number of loops are involved in the operations on the **resultSet** obtained by **querySync()**, the freeze problem may occur. You are advised to perform this operation in the [taskpool](../apis-arkts/js-apis-taskpool.md) thread. 10377 10378**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 10379 10380**Parameters** 10381 10382| Name | Type | Mandatory| Description | 10383| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ | 10384| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 10385| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns. <br>Default value: null.| 10386 10387**Error codes** 10388 10389For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 10390 10391| **ID**| **Error Message** | 10392| ------------ | ------------------------------------------------------------ | 10393| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10394| 14800000 | Inner error. | 10395| 14800011 | Failed to open the database because it is corrupted. | 10396| 14800014 | The RdbStore or ResultSet is already closed. | 10397| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 10398| 14800023 | SQLite: Access permission denied. | 10399| 14800024 | SQLite: The database file is locked. | 10400| 14800025 | SQLite: A table in the database is locked. | 10401| 14800026 | SQLite: The database is out of memory. | 10402| 14800028 | SQLite: Some kind of disk I/O error occurred. | 10403| 14800047 | The WAL file size exceeds the default limit. | 10404 10405**Return value** 10406 10407| Type | Description | 10408| ----------------------- | ----------------------------------- | 10409| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 10410 10411**Example** 10412 10413```ts 10414let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 10415predicates.equalTo("NAME", "Rose"); 10416 10417if (store != undefined) { 10418 (store as relationalStore.RdbStore).createTransaction().then(async (transaction: relationalStore.Transaction) => { 10419 try { 10420 let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); 10421 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 10422 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 10423 while (resultSet.goToNextRow()) { 10424 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 10425 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 10426 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 10427 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 10428 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 10429 } 10430 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 10431 resultSet.close(); 10432 transaction.commit(); 10433 } catch (e) { 10434 transaction.rollback(); 10435 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 10436 }; 10437 }).catch((err: BusinessError) => { 10438 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 10439 }); 10440} 10441``` 10442 10443### querySql<sup>14+</sup> 10444 10445querySql(sql: string, args?: Array<ValueType>): Promise<ResultSet> 10446 10447Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. This API uses a promise to return the result. 10448 10449**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 10450 10451**Parameters** 10452 10453| Name | Type | Mandatory| Description | 10454| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 10455| sql | string | Yes | SQL statement to run. | 10456| 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.| 10457 10458**Return value** 10459 10460| Type | Description | 10461| ------------------------------------------------------- | -------------------------------------------------- | 10462| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 10463 10464**Error codes** 10465 10466For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 10467 10468| **ID**| **Error Message** | 10469|-----------| ------------------------------------------------------------ | 10470| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10471| 14800000 | Inner error. | 10472| 14800011 | Failed to open the database because it is corrupted. | 10473| 14800014 | The RdbStore or ResultSet is already closed. | 10474| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 10475| 14800023 | SQLite: Access permission denied. | 10476| 14800024 | SQLite: The database file is locked. | 10477| 14800025 | SQLite: A table in the database is locked. | 10478| 14800026 | SQLite: The database is out of memory. | 10479| 14800028 | SQLite: Some kind of disk I/O error occurred. | 10480| 14800047 | The WAL file size exceeds the default limit. | 10481 10482**Example** 10483 10484```ts 10485if (store != undefined) { 10486 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 10487 transaction.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then(async (resultSet: relationalStore.ResultSet) => { 10488 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 10489 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 10490 while (resultSet.goToNextRow()) { 10491 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 10492 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 10493 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 10494 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 10495 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 10496 } 10497 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 10498 resultSet.close(); 10499 transaction.commit(); 10500 }).catch((e: BusinessError) => { 10501 transaction.rollback(); 10502 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 10503 }); 10504 }).catch((err: BusinessError) => { 10505 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 10506 }); 10507} 10508``` 10509 10510### querySqlSync<sup>14+</sup> 10511 10512querySqlSync(sql: string, args?: Array<ValueType>): ResultSet 10513 10514Queries data in the RDB store using the specified SQL statement. The number of relational operators between expressions and operators in the SQL statement cannot exceed 1000. If complex logic and a large number of loops are involved in the operations on the **resultSet** obtained by **querySync()**, the freeze problem may occur. You are advised to perform this operation in the [taskpool](../apis-arkts/js-apis-taskpool.md) thread. 10515 10516**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 10517 10518**Parameters** 10519 10520| Name | Type | Mandatory| Description | 10521| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 10522| sql | string | Yes | SQL statement to run. | 10523| args | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank. <br>Default value: null.| 10524 10525**Return value** 10526 10527| Type | Description | 10528| ----------------------- | ----------------------------------- | 10529| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 10530 10531**Error codes** 10532 10533For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 10534 10535| **ID**| **Error Message** | 10536| ------------ | ------------------------------------------------------------ | 10537| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10538| 14800000 | Inner error. | 10539| 14800011 | Failed to open the database because it is corrupted. | 10540| 14800014 | The RdbStore or ResultSet is already closed. | 10541| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 10542| 14800023 | SQLite: Access permission denied. | 10543| 14800024 | SQLite: The database file is locked. | 10544| 14800025 | SQLite: A table in the database is locked. | 10545| 14800026 | SQLite: The database is out of memory. | 10546| 14800028 | SQLite: Some kind of disk I/O error occurred. | 10547| 14800047 | The WAL file size exceeds the default limit. | 10548 10549**Example** 10550 10551```ts 10552if (store != undefined) { 10553 (store as relationalStore.RdbStore).createTransaction().then(async (transaction: relationalStore.Transaction) => { 10554 try { 10555 let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'"); 10556 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 10557 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 10558 while (resultSet.goToNextRow()) { 10559 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 10560 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 10561 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 10562 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 10563 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 10564 } 10565 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 10566 resultSet.close(); 10567 transaction.commit(); 10568 } catch (e) { 10569 transaction.rollback(); 10570 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 10571 }; 10572 }).catch((err: BusinessError) => { 10573 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 10574 }); 10575} 10576``` 10577 10578### execute<sup>14+</sup> 10579 10580execute(sql: string, args?: Array<ValueType>): Promise<ValueType> 10581 10582Executes an SQL statement that contains specified arguments. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API uses a promise to return a value of the ValueType type. 10583 10584This 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. 10585 10586This API does not support query, database attachment, and transaction operations. You can use [querySql](#querysql14) or [query](#query14) to query data, and use [attach](#attach12) to attach a database. 10587 10588Statements separated by semicolons (\;) are not supported. 10589 10590**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 10591 10592**Parameters** 10593 10594| Name | Type | Mandatory| Description | 10595| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 10596| sql | string | Yes | SQL statement to run. | 10597| 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.| 10598 10599**Return value** 10600 10601| Type | Description | 10602| ------------------- | ------------------------- | 10603| Promise<[ValueType](#valuetype)> | Promise used to return the SQL execution result.| 10604 10605**Error codes** 10606 10607For 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). 10608 10609| **ID**| **Error Message** | 10610|-----------| ------------------------------------------------------------ | 10611| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10612| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 10613| 14800000 | Inner error. | 10614| 14800011 | Failed to open the database because it is corrupted. | 10615| 14800014 | The RdbStore or ResultSet is already closed. | 10616| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 10617| 14800023 | SQLite: Access permission denied. | 10618| 14800024 | SQLite: The database file is locked. | 10619| 14800025 | SQLite: A table in the database is locked. | 10620| 14800026 | SQLite: The database is out of memory. | 10621| 14800027 | SQLite: Attempt to write a readonly database. | 10622| 14800028 | SQLite: Some kind of disk I/O error occurred. | 10623| 14800029 | SQLite: The database is full. | 10624| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 10625| 14800033 | SQLite: Data type mismatch. | 10626| 14800047 | The WAL file size exceeds the default limit. | 10627 10628**Example** 10629 10630```ts 10631// Delete all data from the table. 10632if (store != undefined) { 10633 const SQL_DELETE_TABLE = 'DELETE FROM test'; 10634 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 10635 transaction.execute(SQL_DELETE_TABLE).then((data) => { 10636 transaction.commit(); 10637 console.info(`delete result: ${data}`); 10638 }).catch((e: BusinessError) => { 10639 transaction.rollback(); 10640 console.error(`delete failed, code is ${e.code}, message is ${e.message}`); 10641 }); 10642 }).catch((err: BusinessError) => { 10643 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 10644 }); 10645} 10646``` 10647 10648### executeSync<sup>14+</sup> 10649 10650executeSync(sql: string, args?: Array<ValueType>): ValueType 10651 10652Executes an SQL statement that contains specified arguments. The number of relational operators between expressions and operators in the statement cannot exceed 1000. This API returns a value of theValueType type. 10653 10654This 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. 10655 10656This API does not support query, database attachment, and transaction operations. You can use [querySql](#querysql14) or [query](#query14) to query data, and use [attach](#attach12) to attach a database. 10657 10658Statements separated by semicolons (\;) are not supported. 10659 10660**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 10661 10662**Parameters** 10663 10664| Name| Type | Mandatory| Description | 10665| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 10666| sql | string | Yes | SQL statement to run. | 10667| args | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If this parameter is left blank or set to **null** or **undefined**, the SQL statement is complete. <br>Default value: null.| 10668 10669**Return value** 10670 10671| Type | Description | 10672| ----------------------- | ------------------- | 10673| [ValueType](#valuetype) | SQL execution result.| 10674 10675**Error codes** 10676 10677For 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). 10678 10679| **ID**| **Error Message** | 10680| ------------ | ------------------------------------------------------------ | 10681| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 10682| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 10683| 14800000 | Inner error. | 10684| 14800011 | Failed to open the database because it is corrupted. | 10685| 14800014 | The RdbStore or ResultSet is already closed. | 10686| 14800021 | SQLite: Generic error. Possible causes: Insert failed or the updated data does not exist. | 10687| 14800023 | SQLite: Access permission denied. | 10688| 14800024 | SQLite: The database file is locked. | 10689| 14800025 | SQLite: A table in the database is locked. | 10690| 14800026 | SQLite: The database is out of memory. | 10691| 14800027 | SQLite: Attempt to write a readonly database. | 10692| 14800028 | SQLite: Some kind of disk I/O error occurred. | 10693| 14800029 | SQLite: The database is full. | 10694| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 10695| 14800033 | SQLite: Data type mismatch. | 10696| 14800047 | The WAL file size exceeds the default limit. | 10697 10698**Example** 10699 10700```ts 10701// Delete all data from the table. 10702if (store != undefined) { 10703 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 10704 const SQL_DELETE_TABLE = 'DELETE FROM test'; 10705 try { 10706 let data = (transaction as relationalStore.Transaction).executeSync(SQL_DELETE_TABLE); 10707 transaction.commit(); 10708 console.info(`delete result: ${data}`); 10709 } catch (e) { 10710 transaction.rollback(); 10711 console.error(`delete failed, code is ${e.code}, message is ${e.message}`); 10712 }; 10713 }).catch((err: BusinessError) => { 10714 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 10715 }); 10716} 10717```