1# @ohos.data.relationalStore (RDB Store) 2 3The relational database (RDB) store manages data based on relational models. The **relationalStore** module provides a complete mechanism for managing local databases based on the underlying SQLite. You can use the APIs to perform operations such as adding, deleting, modifying, and querying data, and directly run SQL statements. You can also use [ResultSet.getSendableRow](#getsendablerow12) to obtain sendable data for cross-thread transmission. 4 5The maximum size of a data record is 2 MB. If a data record exceeds 2 MB, it can be inserted successfully but cannot be read. 6 7Querying data from a large amount of data may take time or even cause application suspension. In this case, you can perform batch operations. For details, see [Batch Database Operations](../../arkts-utils/batch-database-operations-guide.md). Moreover, observe the following: 8- The number of data records to be queried at a time should not exceed 5000. 9- Use [TaskPool](../apis-arkts/js-apis-taskpool.md) if there is a large amount of data needs to be queried. 10- Keep concatenated SQL statements as concise as possible. 11- Query data in batches. 12 13The **relationalStore** module provides the following functionalities: 14 15- [RdbPredicates](#rdbpredicates): provides 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. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. 35 36The parameter [encrypt](#storeconfig) takes effect only when the RDB store is created for the first time, and cannot be modified. It is important to set this parameter correctly. 37 38| Encryption Type When the RDB Store Is Opened | Encryption Type When the RDB Store Is Created | Behavior| 39| ------- | -------------------------------- | ---- | 40| Not encrypt| Encrypt | The RDB store is opened in encrypted mode. | 41| Encrypt| Not encrypt | The RDB store is opened in non-encrypted mode. | 42 43Currently, **getRdbStore()** does not support multi-thread concurrent operations. 44 45**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 46 47**Parameters** 48 49| Name | Type | Mandatory| Description | 50| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | 51| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).| 52| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 53| callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes | Callback used to return the RdbStore instance obtained. | 54 55**Error codes** 56 57For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 58 59| **ID**| **Error Message** | 60|-----------|---------| 61| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 62| 14800000 | Inner error. | 63| 14800010 | Invalid database path. | 64| 14800011 | Database corrupted. | 65| 14801001 | The operation is supported in the stage model only. | 66| 14801002 | Invalid data group ID. | 67| 14800017 | Config changed. | 68| 14800020 | The secret key is corrupted or lost. | 69| 14800021 | SQLite: Generic error. | 70| 14800022 | SQLite: Callback routine requested an abort. | 71| 14800023 | SQLite: Access permission denied. | 72| 14800027 | SQLite: Attempt to write a readonly database. | 73| 14800028 | SQLite: Some kind of disk I/O error occurred. | 74| 14800029 | SQLite: The database is full. | 75| 14800030 | SQLite: Unable to open the database file. | 76 77**Example** 78 79FA model: 80 81<!--code_no_check_fa--> 82```js 83import { featureAbility } from '@kit.AbilityKit'; 84import { BusinessError } from '@kit.BasicServicesKit'; 85 86let store: relationalStore.RdbStore | undefined = undefined; 87let context = featureAbility.getContext(); 88 89const STORE_CONFIG: relationalStore.StoreConfig = { 90 name: "RdbTest.db", 91 securityLevel: relationalStore.SecurityLevel.S3 92}; 93 94relationalStore.getRdbStore(context, STORE_CONFIG, async (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 95 if (err) { 96 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 97 return; 98 } 99 console.info('Get RdbStore successfully.'); 100 store = rdbStore; 101 // Perform subsequent operations after the rdbStore instance is successfully obtained. 102}) 103``` 104 105Stage model: 106 107```ts 108import { UIAbility } from '@kit.AbilityKit'; 109import { window } from '@kit.ArkUI'; 110import { BusinessError } from '@kit.BasicServicesKit'; 111 112let store: relationalStore.RdbStore | undefined = undefined; 113 114class EntryAbility extends UIAbility { 115 onWindowStageCreate(windowStage: window.WindowStage) { 116 const STORE_CONFIG: relationalStore.StoreConfig = { 117 name: "RdbTest.db", 118 securityLevel: relationalStore.SecurityLevel.S3 119 }; 120 121 relationalStore.getRdbStore(this.context, STORE_CONFIG, async (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 122 if (err) { 123 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 124 return; 125 } 126 console.info('Get RdbStore successfully.'); 127 store = rdbStore; 128 // Perform subsequent operations after the rdbStore instance is successfully obtained. 129 }) 130 } 131} 132``` 133 134## relationalStore.getRdbStore 135 136getRdbStore(context: Context, config: StoreConfig): Promise<RdbStore> 137 138Obtains an RdbStore instance. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. 139 140The parameter [encrypt](#storeconfig) takes effect only when the RDB store is created for the first time, and cannot be modified. It is important to set this parameter correctly. 141 142| Encryption Type When the RDB Store Is Opened | Encryption Type When the RDB Store Is Created | Behavior| 143| ------- | -------------------------------- | ---- | 144| Not encrypt| Encrypt | The RDB store is opened in encrypted mode. | 145| Encrypt| Not encrypt | The RDB store is opened in non-encrypted mode. | 146 147Currently, **getRdbStore()** does not support multi-thread concurrent operations. 148 149**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 150 151**Parameters** 152 153| Name | Type | Mandatory| Description | 154| ------- | -------------------------------- | ---- | ------------------------------------------------------------ | 155| 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).| 156| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 157 158**Return value** 159 160| Type | Description | 161| ----------------------------------------- | --------------------------------- | 162| Promise<[RdbStore](#rdbstore)> | Promise used to return the **RdbStore** instance obtained.| 163 164**Error codes** 165 166For 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). 167 168| **ID**| **Error Message** | 169|-----------| ------------------------------------------------------------ | 170| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 171| 14800000 | Inner error. | 172| 14800010 | Invalid database path. | 173| 14800011 | Database corrupted. | 174| 14801001 | The operation is supported in the stage model only. | 175| 14801002 | Invalid data group ID. | 176| 14800017 | Config changed. | 177| 14800020 | The secret key is corrupted or lost. | 178| 14800021 | SQLite: Generic error. | 179| 14800022 | SQLite: Callback routine requested an abort. | 180| 14800023 | SQLite: Access permission denied. | 181| 14800027 | SQLite: Attempt to write a readonly database. | 182| 14800028 | SQLite: Some kind of disk I/O error occurred. | 183| 14800029 | SQLite: The database is full. | 184| 14800030 | SQLite: Unable to open the database file. | 185 186**Example** 187 188FA model: 189 190<!--code_no_check_fa--> 191```js 192import { featureAbility } from '@kit.AbilityKit'; 193import { BusinessError } from '@kit.BasicServicesKit'; 194 195let store: relationalStore.RdbStore | undefined = undefined; 196let context = featureAbility.getContext(); 197 198const STORE_CONFIG: relationalStore.StoreConfig = { 199 name: "RdbTest.db", 200 securityLevel: relationalStore.SecurityLevel.S3 201}; 202 203relationalStore.getRdbStore(context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 204 store = rdbStore; 205 console.info('Get RdbStore successfully.') 206}).catch((err: BusinessError) => { 207 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 208}) 209``` 210 211Stage model: 212 213```ts 214import { UIAbility } from '@kit.AbilityKit'; 215import { window } from '@kit.ArkUI'; 216import { BusinessError } from '@kit.BasicServicesKit'; 217 218let store: relationalStore.RdbStore | undefined = undefined; 219 220class EntryAbility extends UIAbility { 221 onWindowStageCreate(windowStage: window.WindowStage) { 222 const STORE_CONFIG: relationalStore.StoreConfig = { 223 name: "RdbTest.db", 224 securityLevel: relationalStore.SecurityLevel.S3 225 }; 226 227 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 228 store = rdbStore; 229 console.info('Get RdbStore successfully.') 230 }).catch((err: BusinessError) => { 231 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 232 }) 233 } 234} 235``` 236 237## relationalStore.deleteRdbStore 238 239deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void 240 241Deletes an RDB store. This API uses an asynchronous callback to return the result. 242 243After 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. 244 245**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 246 247**Parameters** 248 249| Name | Type | Mandatory| Description | 250| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 251| 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).| 252| name | string | Yes | Name of the RDB store to delete. | 253| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 254 255**Error codes** 256 257For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 258 259| **ID**| **Error Message** | 260|-----------|---------------------------------------| 261| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 262| 14800000 | Inner error. | 263| 14800010 | Failed to open or delete database by invalid database path. | 264 265**Example** 266 267FA model: 268 269<!--code_no_check_fa--> 270```js 271import { featureAbility } from '@kit.AbilityKit'; 272import { BusinessError } from '@kit.BasicServicesKit'; 273 274let store: relationalStore.RdbStore | undefined = undefined; 275let context = featureAbility.getContext(); 276 277relationalStore.deleteRdbStore(context, "RdbTest.db", (err: BusinessError) => { 278 if (err) { 279 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 280 return; 281 } 282 store = undefined; 283 console.info('Delete RdbStore successfully.'); 284}) 285``` 286 287Stage model: 288 289```ts 290import { UIAbility } from '@kit.AbilityKit'; 291import { window } from '@kit.ArkUI'; 292import { BusinessError } from '@kit.BasicServicesKit'; 293 294let store: relationalStore.RdbStore | undefined = undefined; 295 296class EntryAbility extends UIAbility { 297 onWindowStageCreate(windowStage: window.WindowStage){ 298 relationalStore.deleteRdbStore(this.context, "RdbTest.db", (err: BusinessError) => { 299 if (err) { 300 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 301 return; 302 } 303 store = undefined; 304 console.info('Delete RdbStore successfully.'); 305 }) 306 } 307} 308``` 309 310## relationalStore.deleteRdbStore 311 312deleteRdbStore(context: Context, name: string): Promise<void> 313 314Deletes an RDB store. This API uses a promise to return the result. 315 316After 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. 317 318**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 319 320**Parameters** 321 322| Name | Type | Mandatory| Description | 323| ------- | ------- | ---- | ------------------------------------------------------------ | 324| 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).| 325| name | string | Yes | Name of the RDB store to delete. | 326 327**Return value** 328 329| Type | Description | 330| ------------------- | ------------------------- | 331| Promise<void> | Promise that returns no value.| 332 333**Error codes** 334 335For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 336 337| **ID**| **Error Message** | 338|-----------|----------------------------------------------------------------------------------| 339| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 340| 14800000 | Inner error. | 341| 14800010 | Invalid database path. | 342 343**Example** 344 345FA model: 346 347<!--code_no_check_fa--> 348```js 349import { featureAbility } from '@kit.AbilityKit'; 350import { BusinessError } from '@kit.BasicServicesKit'; 351 352let store: relationalStore.RdbStore | undefined = undefined; 353let context = featureAbility.getContext(); 354 355relationalStore.deleteRdbStore(context, "RdbTest.db").then(()=>{ 356 store = undefined; 357 console.info('Delete RdbStore successfully.'); 358}).catch((err: BusinessError) => { 359 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 360}) 361``` 362 363Stage model: 364 365```ts 366import { UIAbility } from '@kit.AbilityKit'; 367import { window } from '@kit.ArkUI'; 368import { BusinessError } from '@kit.BasicServicesKit'; 369 370let store: relationalStore.RdbStore | undefined = undefined; 371 372class EntryAbility extends UIAbility { 373 onWindowStageCreate(windowStage: window.WindowStage){ 374 relationalStore.deleteRdbStore(this.context, "RdbTest.db").then(()=>{ 375 store = undefined; 376 console.info('Delete RdbStore successfully.'); 377 }).catch((err: BusinessError) => { 378 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 379 }) 380 } 381} 382``` 383 384## relationalStore.deleteRdbStore<sup>10+</sup> 385 386deleteRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback\<void>): void 387 388Deletes an RDB store. This API uses an asynchronous callback to return the result. 389 390After 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). 391 392**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 393 394**Parameters** 395 396| Name | Type | Mandatory| Description | 397| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 398| 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).| 399| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 400| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 401 402**Error codes** 403 404For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 405 406| **ID**| **Error Message** | 407|-----------|----------| 408| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 409| 14800000 | Inner error. | 410| 14800010 | Failed to open or delete database by invalid database path. | 411| 14801001 | The operation is supported in the stage model only. | 412| 14801002 | Invalid data group ID. | 413 414**Example** 415 416FA model: 417 418<!--code_no_check_fa--> 419```js 420import { featureAbility } from '@kit.AbilityKit'; 421import { BusinessError } from '@kit.BasicServicesKit'; 422 423let store: relationalStore.RdbStore | undefined = undefined; 424let context = featureAbility.getContext(); 425 426const STORE_CONFIG: relationalStore.StoreConfig = { 427 name: "RdbTest.db", 428 securityLevel: relationalStore.SecurityLevel.S3 429}; 430 431relationalStore.deleteRdbStore(context, STORE_CONFIG, (err: BusinessError) => { 432 if (err) { 433 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 434 return; 435 } 436 store = undefined; 437 console.info('Delete RdbStore successfully.'); 438}) 439``` 440 441Stage model: 442 443```ts 444import { UIAbility } from '@kit.AbilityKit'; 445import { window } from '@kit.ArkUI'; 446import { BusinessError } from '@kit.BasicServicesKit'; 447 448let store: relationalStore.RdbStore | undefined = undefined; 449 450class EntryAbility extends UIAbility { 451 onWindowStageCreate(windowStage: window.WindowStage){ 452 const STORE_CONFIG: relationalStore.StoreConfig = { 453 name: "RdbTest.db", 454 securityLevel: relationalStore.SecurityLevel.S3 455 }; 456 relationalStore.deleteRdbStore(this.context, STORE_CONFIG, (err: BusinessError) => { 457 if (err) { 458 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 459 return; 460 } 461 store = undefined; 462 console.info('Delete RdbStore successfully.'); 463 }) 464 } 465} 466``` 467 468## relationalStore.deleteRdbStore<sup>10+</sup> 469 470deleteRdbStore(context: Context, config: StoreConfig): Promise\<void> 471 472Deletes an RDB store. This API uses a promise to return the result. 473 474After 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). 475 476**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 477 478**Parameters** 479 480| Name | Type | Mandatory| Description | 481| ------- | --------------------------- | ---- | ------------------------------------------------------------ | 482| 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).| 483| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 484 485**Return value** 486 487| Type | Description | 488| ------------------- | ------------------------- | 489| Promise<void> | Promise that returns no value.| 490 491**Error codes** 492 493For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 494 495| **ID**| **Error Message** | 496|-----------|---------------------| 497| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 498| 801 | Capability not supported. | 499| 14800000 | Inner error. | 500| 14800010 | Invalid database path. | 501| 14801001 | The operation is supported in the stage model only. | 502| 14801002 | Invalid data group ID. | 503 504**Example** 505 506FA model: 507 508<!--code_no_check_fa--> 509```js 510import { featureAbility } from "@kit.AbilityKit"; 511import { BusinessError } from '@kit.BasicServicesKit'; 512 513let store: relationalStore.RdbStore | undefined = undefined; 514let context = featureAbility.getContext(); 515 516const STORE_CONFIG: relationalStore.StoreConfig = { 517 name: "RdbTest.db", 518 securityLevel: relationalStore.SecurityLevel.S3 519}; 520 521relationalStore.deleteRdbStore(context, STORE_CONFIG).then(()=>{ 522 store = undefined; 523 console.info('Delete RdbStore successfully.'); 524}).catch((err: BusinessError) => { 525 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 526}) 527``` 528 529Stage model: 530 531```ts 532import { UIAbility } from '@kit.AbilityKit'; 533import { window } from '@kit.ArkUI'; 534import { BusinessError } from '@kit.BasicServicesKit'; 535 536let store: relationalStore.RdbStore | undefined = undefined; 537 538class EntryAbility extends UIAbility { 539 onWindowStageCreate(windowStage: window.WindowStage){ 540 const STORE_CONFIG: relationalStore.StoreConfig = { 541 name: "RdbTest.db", 542 securityLevel: relationalStore.SecurityLevel.S3 543 }; 544 relationalStore.deleteRdbStore(this.context, STORE_CONFIG).then(()=>{ 545 store = undefined; 546 console.info('Delete RdbStore successfully.'); 547 }).catch((err: BusinessError) => { 548 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 549 }) 550 } 551} 552``` 553## relationalStore.isVectorSupported<sup>18+</sup> 554 555isVectorSupported(): boolean 556 557Checks whether the system supports vector stores. 558 559**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 560 561**Return value** 562 563| Type | Description | 564| ------- | ------------------------------------------------- | 565| boolean | Returns **true** if the system supports vector stores; returns **false** otherwise.| 566 567**Example** 568 569``` 570let result = relationalStore.isVectorSupported(); 571``` 572 573## relationalStore.isTokenizerSupported<sup>18+</sup> 574 575isTokenizerSupported(tokenizer: Tokenizer): boolean 576 577Checks whether the specified tokenizer is supported. This API returns the result synchronously. 578 579This API returns **true** if the specified tokenizer is supported; returns **false** otherwise. 580 581**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 582 583**Parameters** 584 585| Name | Type | Mandatory| Description | 586| ------- | --------------------- | ---- | ------------------------------------------------------------ | 587| tokenizer | [Tokenizer](#tokenizer18) | Yes | Tokenizer to check.| 588 589**Return value** 590 591| Type | Description | 592| ------------------- | ------------------------- | 593| boolean | Returns **true** if the specified tokenizer is supported; returns **false** otherwise.| 594 595**Error codes** 596 597For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 598 599| **ID**| **Error Message** | 600|-----------|---------------------| 601| 401 | Parameter error. Possible causes: Incorrect parameter types. | 602 603 604**Example** 605 606```ts 607import { relationalStore } from '@kit.ArkData'; // Import the relationalStore module. 608 609let customType = relationalStore.Tokenizer.CUSTOM_TOKENIZER; 610let customTypeSupported = relationalStore.isTokenizerSupported(customType); 611console.info("custom tokenizer supported on current platform: " + customTypeSupported); 612``` 613 614## StoreConfig 615 616Defines the RDB store configuration. 617 618| Name | Type | Mandatory| Description | 619| ------------- | ------------- | ---- | --------------------------------------------------------- | 620| name | string | Yes | Database file name, which is the unique identifier of the database.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 621| securityLevel | [SecurityLevel](#securitylevel) | Yes | Security level of the RDB store.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 622| 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| 623| 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| 624| 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| 625| 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| 626| 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| 627| 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| 628| 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| 629| 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| 630| 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| 631| 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; the value **false** means the opposite.<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>Currently, vector databases support [execute](#execute12-1), [querySql](#querysql-1), [beginTrans](#begintrans12), [commit](#commit12), [rollback](#rollback12), [backup](#backup), [restore](#restore), and [ResultSet](#resultset) APIs. Before calling **deleteRdbStore** to delete a vector store, ensure that the vector store is properly closed.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 632| tokenizer<sup>18+</sup> | [Tokenizer](#tokenizer18) | 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| 633 634## SecurityLevel 635 636Enumerates 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. 637 638> **NOTE** 639> 640> To perform data sync operations, the RDB store security level must be lower than or equal to that of the peer device. For details, see [Access Control Mechanism in Cross-Device Sync](../../database/access-control-by-device-and-data-level.md#access-control-mechanism-in-cross-device-sync). 641 642**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 643 644| Name| Value | Description | 645| ---- | ---- | ------------------------------------------------------------ | 646| 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.| 647| 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.| 648| 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.| 649| 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.| 650 651## CryptoParam<sup>14+</sup> 652 653Represents the configuration of database encryption parameters. This parameter is valid only when **encrypt** in **StoreConfig** is **true**. 654 655**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 656 657| Name | Type | Mandatory| Description | 658| ------------- | ------ | ---- | ------------------------------------------------------------ | 659| 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.| 660| 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.| 661| encryptionAlgo | [EncryptionAlgo](#encryptionalgo14) | No| Algorithm used for database encryption and decryption. <br>Default value: **AES_256_GCM**.| 662| hmacAlgo | [HmacAlgo](#hmacalgo14) | No| HMAC algorithm used for database encryption and decryption. <br>Default value: **SHA256**.| 663| kdfAlgo | [KdfAlgo](#kdfalgo14) | No| PBKDF2 algorithm used for database encryption and decryption. <br>Default value: the same as the HMAC algorithm used.| 664| 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.| 665 666## EncryptionAlgo<sup>14+</sup> 667 668Enumerates the database encryption algorithms. Use the enum name rather than the enum value. 669 670**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 671 672| Name| Value | Description| 673| ---- | ---- | ---- | 674| AES_256_GCM | 0 | AES_256_GCM. | 675| AES_256_CBC | 1 | AES_256_CBC. | 676 677## HmacAlgo<sup>14+</sup> 678 679Enumerates the HMAC algorithms for the database. Use the enum name rather than the enum value. 680 681**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 682 683| Name| Value | Description| 684| ---- | ---- | ---- | 685| SHA1 | 0 | HMAC_SHA1. | 686| SHA256 | 1 | HMAC_SHA256. | 687| SHA512 | 2 | HMAC_SHA512. | 688 689## KdfAlgo<sup>14+</sup> 690 691Enumerates the PBKDF2 algorithms for the database. Use the enum name rather than the enum value. 692 693**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 694 695| Name| Value | Description| 696| ---- | ---- | ---- | 697| KDF_SHA1 | 0 | PBKDF2_HMAC_SHA1. | 698| KDF_SHA256 | 1 | PBKDF2_HMAC_SHA256. | 699| KDF_SHA512 | 2 | PBKDF2_HMAC_SHA512. | 700 701## Tokenizer<sup>18+</sup> 702 703Enumerates tokenizers that can be used for FTS. Use the enum name rather than the enum value. 704 705**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 706 707| Name | Value | Description | 708| ------------------------------- | --- | -------------- | 709| NONE_TOKENIZER | 0 | No tokenizer is used. | 710| 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).| 711| CUSTOM_TOKENIZER | 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.| 712 713The table creation statement varies with the tokenizer in use. 714 715**Example** 716 717The following is an example of the table creation statement when **ICU_TOKENIZER** is used: 718 719```ts 720import { relationalStore } from '@kit.ArkData'; // Import the relationalStore module. 721import { UIAbility } from '@kit.AbilityKit'; 722import { BusinessError } from '@kit.BasicServicesKit'; 723import { window } from '@kit.ArkUI'; 724 725// In this example, Ability is used to obtain an RdbStore instance in the stage model. You can use other implementations as required. 726class EntryAbility extends UIAbility { 727 async onWindowStageCreate(windowStage: window.WindowStage) { 728 let store: relationalStore.RdbStore | undefined = undefined; 729 const STORE_CONFIG: relationalStore.StoreConfig = { 730 name: "MyStore.db", 731 securityLevel: relationalStore.SecurityLevel.S3, 732 tokenizer: relationalStore.Tokenizer.ICU_TOKENIZER 733 }; 734 store = await relationalStore.getRdbStore(this.context, STORE_CONFIG); 735 736 const SQL_CREATE_TABLE = "CREATE VIRTUAL TABLE example USING fts4(name, content, tokenize=icu zh_CN)" 737 if (store != undefined) { 738 (store as relationalStore.RdbStore).executeSql(SQL_CREATE_TABLE, (err) => { 739 if (err) { 740 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 741 return; 742 } 743 console.info('create virtual table done.'); 744 }) 745 } 746 } 747} 748``` 749 750The following is an example of the table creation statement when **CUSTOM_TOKENIZER** is used: 751 752```ts 753import { relationalStore } from '@kit.ArkData'; // Import the relationalStore module. 754import { UIAbility } from '@kit.AbilityKit'; 755import { BusinessError } from '@kit.BasicServicesKit'; 756import { window } from '@kit.ArkUI'; 757 758// In this example, Ability is used to obtain an RdbStore instance in the stage model. You can use other implementations as required. 759class EntryAbility extends UIAbility { 760 async onWindowStageCreate(windowStage: window.WindowStage) { 761 let store: relationalStore.RdbStore | undefined = undefined; 762 const STORE_CONFIG: relationalStore.StoreConfig = { 763 name: "MyStore.db", 764 securityLevel: relationalStore.SecurityLevel.S3, 765 tokenizer: relationalStore.Tokenizer.CUSTOM_TOKENIZER 766 }; 767 store = await relationalStore.getRdbStore(this.context, STORE_CONFIG); 768 769 const SQL_CREATE_TABLE = "CREATE VIRTUAL TABLE example USING fts5(name, content, tokenize='customtokenizer')" 770 if (store != undefined) { 771 (store as relationalStore.RdbStore).executeSql(SQL_CREATE_TABLE, (err) => { 772 if (err) { 773 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 774 return; 775 } 776 console.info('create virtual table done.'); 777 }) 778 } 779 } 780} 781``` 782 783## AssetStatus<sup>10+</sup> 784 785Enumerates the asset statuses. Use the enum name rather than the enum value. 786 787**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 788 789| Name | Value | Description | 790| ------------------------------- | --- | -------------- | 791| ASSET_NORMAL | 1 | The asset is in normal status. | 792| ASSET_INSERT | 2 | The asset is to be inserted to the cloud.| 793| ASSET_UPDATE | 3 | The asset is to be updated to the cloud.| 794| ASSET_DELETE | 4 | The asset is to be deleted from the cloud.| 795| ASSET_ABNORMAL | 5 | The asset is in abnormal status. | 796| ASSET_DOWNLOADING | 6 | The asset is being downloaded to a local device.| 797 798## Asset<sup>10+</sup> 799 800Defines information about an asset (such as a document, image, and video). 801 802**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 803 804| Name | Type | Mandatory | Description | 805| ----------- | --------------------------- | --- | ------------ | 806| name | string | Yes | Asset name. | 807| uri | string | Yes | Asset URI, which is an absolute path in the system. | 808| path | string | Yes | Application sandbox path of the asset. | 809| createTime | string | Yes | Time when the asset was created. | 810| modifyTime | string | Yes | Time when the asset was last modified.| 811| size | string | Yes | Size of the asset. | 812| status | [AssetStatus](#assetstatus10) | No | Asset status. <br>Default value: **ASSET_NORMAL**. | 813 814## Assets<sup>10+</sup> 815 816type Assets = Asset[] 817 818Defines an array of the [Asset](#asset10) type. 819 820**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 821 822| Type | Description | 823| ------- | -------------------- | 824| [Asset](#asset10)[] | Array of assets. | 825 826## ValueType 827 828type ValueType = null | number | string | boolean | Uint8Array | Asset | Assets | Float32Array | bigint 829 830Enumerates the types of the value in a KV pair. The type varies with the parameter usage. 831 832**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 833 834| Type | Description | 835| ------- | -------------------- | 836| null<sup>10+</sup> | Null. | 837| number | Number. | 838| string | String. | 839| boolean | Boolean.| 840| Uint8Array<sup>10+</sup> | Uint8 array. | 841| 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.| 842| 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.| 843| 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).| 844| 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.| 845 846## ValuesBucket 847 848type ValuesBucket = Record<string, ValueType> 849 850Defines the data in the form of a KV pair. **ValuesBucket** cannot be passed across threads. 851 852**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 853 854| Type | Description | 855| ---------------- | ---------------------------- | 856| 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).| 857 858## PRIKeyType<sup>10+</sup> 859 860type PRIKeyType = number | string 861 862Enumerates the types of the primary key in a row of a database table. 863 864**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 865 866| Type | Description | 867| ---------------- | ---------------------------------- | 868| number | The primary key is a number.| 869| string | The primary key is a string.| 870 871## UTCTime<sup>10+</sup> 872 873type UTCTime = Date 874 875Represents the data type of the UTC time. 876 877**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 878 879| Type| Description | 880| ---- | --------------- | 881| Date | UTC time.| 882 883## ModifyTime<sup>10+</sup> 884 885type ModifyTime = Map<PRIKeyType, UTCTime> 886 887Represents the data type of the primary key and modification time of a database table. 888 889**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 890 891| Type | Description | 892| ------------------------------------------------------- | ------------------------------------------------------------ | 893| 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.| 894 895## SyncMode 896 897Enumerates the database sync modes. Use the enum name rather than the enum value. 898 899| Name | Value | Description | 900| -------------- | ---- | ---------------------------------- | 901| SYNC_MODE_PUSH | 0 | Push data from a local device to a remote device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 902| SYNC_MODE_PULL | 1 | Pull data from a remote device to a local device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 903| SYNC_MODE_TIME_FIRST<sup>10+</sup> | 4 | Synchronize with the data with the latest modification time.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 904| SYNC_MODE_NATIVE_FIRST<sup>10+</sup> | 5 | Synchronize data from a local device to the cloud.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 905| SYNC_MODE_CLOUD_FIRST<sup>10+</sup> | 6 | Synchronize data from the cloud to a local device.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 906 907## Origin<sup>11+</sup> 908 909Enumerates the data sources. Use the enum name rather than the enum value. 910 911**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 912 913| Name | Value | Description | 914| -------------- | ---- | ---------------------------------- | 915| LOCAL | 0 | Local data. | 916| CLOUD | 1 | Cloud data. | 917| REMOTE | 2 | Remote device data.| 918 919## Field<sup>11+</sup> 920 921Enumerates the special fields used in predicates. Use the enum name rather than the enum value. 922 923**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 924 925| Name | Value | Description | 926| -------------- | ---- | ---------------------------------- | 927| CURSOR_FIELD | '#_cursor' | Field name to be searched based on the cursor.| 928| ORIGIN_FIELD | '#_origin' | Data source to be searched based on the cursor. | 929| 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.| 930| 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.| 931| 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.| 932| 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.| 933| SHARING_RESOURCE_FIELD | '#_sharing_resource_field' | Resource shared. It fills in the result set returned when the shared resource is searched.| 934 935## SubscribeType 936 937Enumerates the subscription types. Use the enum name rather than the enum value. 938 939| Name | Value | Description | 940| --------------------- | ---- | ------------------ | 941| SUBSCRIBE_TYPE_REMOTE | 0 | Subscribe to remote data changes.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 942| SUBSCRIBE_TYPE_CLOUD<sup>10+</sup> | 1 | Subscribe to cloud data changes.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 943| SUBSCRIBE_TYPE_CLOUD_DETAILS<sup>10+</sup> | 2 | Subscribe to cloud data change details.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 944| SUBSCRIBE_TYPE_LOCAL_DETAILS<sup>12+</sup> | 3 | Subscribe to details of the local data change.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 945 946## RebuildType<sup>12+</sup> 947 948Enumerates the RDB store rebuild types. Use the enum name rather than the enum value. 949 950**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 951 952| Name | Value | Description | 953| ------- | ---- |----------------------------------------------------------------------------------------------------------------| 954| NONE | 0 | The RDB store is not rebuilt. | 955| REBUILT | 1 | Create an empty database to rebuild the RDB store. You need to create tables and restore data. | 956| REPAIRED | 2 | Restore uncorrupted data of the RDB store. Only [vector stores](#storeconfig) support this feature.| 957 958## ChangeType<sup>10+</sup> 959 960Enumerates data change types. Use the enum name rather than the enum value. 961 962**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 963 964| Name | Value | Description | 965| -------------------------- | --- | -------------------------- | 966| DATA_CHANGE | 0 | Data change. | 967| ASSET_CHANGE | 1 | Asset change.| 968 969## ChangeInfo<sup>10+</sup> 970 971Represents the detail information about the device-cloud sync process. 972 973**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 974 975| Name | Type | Mandatory| Description | 976| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ | 977| table | string | Yes | Name of the table with data changes. | 978| type | [ChangeType](#changetype10) | Yes | Type of the data changed, which can be data or asset. | 979| 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.| 980| 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.| 981| 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.| 982 983## DistributedType<sup>10+</sup> 984 985Enumerates the distributed table types. Use the enum name rather than the enum value. 986 987| Name | Value | Description | 988| ------------------ | --- | -------------------------------------------------------------------------------------------------- | 989| DISTRIBUTED_DEVICE | 0 | Distributed database table between devices.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 990| DISTRIBUTED_CLOUD | 1 | Distributed database table between the device and the cloud.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 991 992## DistributedConfig<sup>10+</sup> 993 994Defines the configuration of the distributed mode of tables. 995 996**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 997 998| Name | Type | Mandatory| Description | 999| -------- | ------- | ---- | ------------------------------------------------------------ | 1000| 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.| 1001| 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**.| 1002 1003## ConflictResolution<sup>10+</sup> 1004 1005Defines the resolution to use when a conflict occurs during data insertion or modification. Use the enum name rather than the enum value. 1006 1007**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1008 1009| Name | Value | Description | 1010| -------------------- | ---- | ------------------------------------------------------------ | 1011| ON_CONFLICT_NONE | 0 | No operation is performed.| 1012| ON_CONFLICT_ROLLBACK | 1 | Abort the SQL statement and roll back the current transaction. | 1013| 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.| 1014| 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.| 1015| ON_CONFLICT_IGNORE | 4 | Skip the rows that contain constraint violations and continue to process the subsequent rows of the SQL statement.| 1016| 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.| 1017 1018## Progress<sup>10+</sup> 1019 1020Enumerates the stages in the device-cloud sync progress. Use the enum name rather than the enum value. 1021 1022**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1023 1024| Name | Value | Description | 1025| ---------------- | ---- | ------------------------ | 1026| SYNC_BEGIN | 0 | The device-cloud sync starts. | 1027| SYNC_IN_PROGRESS | 1 | The device-cloud sync is in progress.| 1028| SYNC_FINISH | 2 | The device-cloud sync is complete.| 1029 1030## Statistic<sup>10+</sup> 1031 1032Represents the device-cloud sync statistics information. 1033 1034**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1035 1036| Name | Type | Mandatory| Description | 1037| ---------- | ------ | ---- | ---------------------------------------- | 1038| total | number | Yes | Total number of rows to be synchronized between the device and cloud in the database table. | 1039| successful | number | Yes | Number of rows that are successfully synchronized between the device and cloud in the database table. | 1040| failed | number | Yes | Number of rows that failed to be synchronized between the device and cloud in the database table. | 1041| remained | number | Yes | Number of rows that are not executed for device-cloud sync in the database table.| 1042 1043## TableDetails<sup>10+</sup> 1044 1045Represents the upload and download statistics of device-cloud sync tasks. 1046 1047**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1048 1049| Name | Type | Mandatory| Description | 1050| -------- | ------------------------- | ---- | ------------------------------------------ | 1051| upload | [Statistic](#statistic10) | Yes | Statistics of the device-cloud upload tasks.| 1052| download | [Statistic](#statistic10) | Yes | Statistics of the device-cloud download tasks.| 1053 1054## ProgressCode<sup>10+</sup> 1055 1056Enumerates the device-cloud sync states. Use the enum name rather than the enum value. 1057 1058**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1059 1060| Name | Value | Description | 1061| --------------------- | ---- | ------------------------------------------------------------ | 1062| SUCCESS | 0 | The device-cloud sync is successful. | 1063| UNKNOWN_ERROR | 1 | An unknown error occurs during device-cloud sync. | 1064| NETWORK_ERROR | 2 | A network error occurs during device-cloud sync. | 1065| CLOUD_DISABLED | 3 | The cloud is unavailable. | 1066| 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.| 1067| 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.| 1068| NO_SPACE_FOR_ASSET | 6 | The remaining cloud space is less than the size of the data to be synchronized. | 1069| BLOCKED_BY_NETWORK_STRATEGY<sup>12+</sup> | 7 | The device-cloud sync is blocked due to the network strategy. | 1070 1071## ProgressDetails<sup>10+</sup> 1072 1073Represents the statistics of the overall device-cloud sync (upload and download) tasks. 1074 1075**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1076 1077| Name | Type | Mandatory| Description | 1078| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | 1079| schedule | [Progress](#progress10) | Yes | Device-cloud sync progress. | 1080| code | [ProgressCode](#progresscode10) | Yes | Device-cloud sync state. | 1081| 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.| 1082 1083## SqlExecutionInfo<sup>12+</sup> 1084 1085Represents statistics about SQL statements executed by the database. 1086 1087**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1088 1089| Name | Type | Read-Only| Optional |Description | 1090| -------- | ------------------------------------------------- | ---- | ---- | -------------------------------------------------------- | 1091| 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. | 1092| totalTime<sup>12+</sup> | number | Yes | No | Total time used to execute the SQL statements, in μs. | 1093| waitTime<sup>12+</sup> | number | Yes | No | Time used to obtain the handle, in μs. | 1094| prepareTime<sup>12+</sup> | number | Yes | No | Time used to get the SQL statements ready and bind parameters, in μs. | 1095| executeTime<sup>12+</sup> | number | Yes | No | Total time used to execute the SQL statements, in μs.| 1096 1097## TransactionType<sup>14+</sup> 1098 1099Enumerates the types of transaction objects that can be created. Use the enum name rather than the enum value. 1100 1101**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1102 1103| Name | Value | Description | 1104| ---------------- | ---- | ------------------------ | 1105| 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. | 1106| 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.| 1107| 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.| 1108 1109## TransactionOptions<sup>14+</sup> 1110 1111Represents the configuration of a transaction object. 1112 1113**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1114 1115| Name | Type | Mandatory| Description | 1116| ------------- | ------------- | ---- | --------------------------------------------------------- | 1117| transactionType | [TransactionType](#transactiontype14) | No | Transaction object type. <br>Default value: **DEFERRED**. | 1118 1119## RdbPredicates 1120 1121Provides 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. 1122 1123### constructor 1124 1125constructor(name: string) 1126 1127A constructor used to create an **RdbPredicates** object. 1128 1129**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1130 1131**Parameters** 1132 1133| Name| Type | Mandatory| Description | 1134| ------ | ------ | ---- | ------------ | 1135| name | string | Yes | Database table name.| 1136 1137**Error codes** 1138 1139For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1140 1141| **ID**| **Error Message** | 1142| --------- |----------------------------------------------------------------------------------------------------------------| 1143| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1144 1145**Example** 1146 1147```ts 1148let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1149``` 1150 1151### inDevices 1152 1153inDevices(devices: Array<string>): RdbPredicates 1154 1155Creates an **RdbPredicates** object to specify the remote devices to connect during the distributed database sync. 1156 1157> **NOTE** 1158> 1159> **devices** can be obtained by using [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 1160When 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. 1161 1162**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1163 1164**Parameters** 1165 1166| Name | Type | Mandatory| Description | 1167| ------- | ------------------- | ---- | -------------------------- | 1168| devices | Array<string> | Yes | IDs of the remote devices to connect.| 1169 1170**Return value** 1171 1172| Type | Description | 1173| ------------------------------------ | -------------------------- | 1174| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1175 1176**Error codes** 1177 1178For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1179 1180| **ID**| **Error Message** | 1181| --------- |----------------------------------------------------------------------------------------------------------------| 1182| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1183 1184**Example** 1185 1186```ts 1187import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 1188import { BusinessError } from '@kit.BasicServicesKit'; 1189 1190let dmInstance: distributedDeviceManager.DeviceManager; 1191let deviceIds: Array<string> = []; 1192 1193try { 1194 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 1195 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 1196 for (let i = 0; i < devices.length; i++) { 1197 deviceIds[i] = devices[i].networkId!; 1198 } 1199} catch (err) { 1200 let code = (err as BusinessError).code; 1201 let message = (err as BusinessError).message 1202 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 1203} 1204 1205let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1206predicates.inDevices(deviceIds); 1207``` 1208 1209### inAllDevices 1210 1211inAllDevices(): RdbPredicates 1212 1213Creates an **RdbPredicates** object to specify all remote devices to connect during the distributed database sync. 1214 1215 1216**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1217 1218**Return value** 1219 1220| Type | Description | 1221| ------------------------------------ | -------------------------- | 1222| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1223 1224**Example** 1225 1226```ts 1227let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1228predicates.inAllDevices(); 1229``` 1230 1231### equalTo 1232 1233equalTo(field: string, value: ValueType): RdbPredicates 1234 1235Creates an **RdbPredicates** object to search for the records in the specified column that are equal to the given value. 1236 1237**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1238 1239**Parameters** 1240 1241| Name| Type | Mandatory| Description | 1242| ------ | ----------------------- | ---- | ---------------------- | 1243| field | string | Yes | Column name in the database table. | 1244| value | [ValueType](#valuetype) | Yes | Value to match.| 1245 1246**Return value** 1247 1248| Type | Description | 1249| ------------------------------------ | -------------------------- | 1250| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1251 1252**Error codes** 1253 1254For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1255 1256| **ID**| **Error Message** | 1257| --------- |----------------------------------------------------------------------------------------------------------------| 1258| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1259 1260**Example** 1261 1262```ts 1263// Find all the records in the NAME column where the value is Lisa. 1264let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1265predicates.equalTo("NAME", "Lisa"); 1266``` 1267 1268 1269### notEqualTo 1270 1271notEqualTo(field: string, value: ValueType): RdbPredicates 1272 1273Creates an **RdbPredicates** object to search for the records in the specified column that are not equal to the given value. 1274 1275**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1276 1277**Parameters** 1278 1279| Name| Type | Mandatory| Description | 1280| ------ | ----------------------- | ---- | ---------------------- | 1281| field | string | Yes | Column name in the database table. | 1282| value | [ValueType](#valuetype) | Yes | Value to match.| 1283 1284**Return value** 1285 1286| Type | Description | 1287| ------------------------------------ | -------------------------- | 1288| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1289 1290**Error codes** 1291 1292For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1293 1294| **ID**| **Error Message** | 1295| --------- |----------------------------------------------------------------------------------------------------------------| 1296| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1297 1298**Example** 1299 1300```ts 1301// Find all the records in the NAME column where the value is not Lisa. 1302let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1303predicates.notEqualTo("NAME", "Lisa"); 1304``` 1305 1306 1307### beginWrap 1308 1309beginWrap(): RdbPredicates 1310 1311Creates an **RdbPredicates** object to add a left parenthesis. 1312 1313**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1314 1315**Return value** 1316 1317| Type | Description | 1318| ------------------------------------ | ------------------------- | 1319| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1320 1321**Example** 1322 1323```ts 1324let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1325predicates.equalTo("NAME", "Lisa") 1326 .beginWrap() 1327 .equalTo("AGE", 18) 1328 .or() 1329 .equalTo("SALARY", 200.5) 1330 .endWrap() 1331``` 1332 1333### endWrap 1334 1335endWrap(): RdbPredicates 1336 1337Creates an **RdbPredicates** object to add a right parenthesis. 1338 1339**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1340 1341**Return value** 1342 1343| Type | Description | 1344| ------------------------------------ | ------------------------- | 1345| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1346 1347**Example** 1348 1349```ts 1350let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1351predicates.equalTo("NAME", "Lisa") 1352 .beginWrap() 1353 .equalTo("AGE", 18) 1354 .or() 1355 .equalTo("SALARY", 200.5) 1356 .endWrap() 1357``` 1358 1359### or 1360 1361or(): RdbPredicates 1362 1363Creates an **RdbPredicates** object to add the OR condition. 1364 1365**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1366 1367**Return value** 1368 1369| Type | Description | 1370| ------------------------------------ | ------------------------- | 1371| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1372 1373**Example** 1374 1375```ts 1376// Find all records in the NAME column where the value is Lisa or Rose. 1377let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1378predicates.equalTo("NAME", "Lisa") 1379 .or() 1380 .equalTo("NAME", "Rose") 1381``` 1382 1383### and 1384 1385and(): RdbPredicates 1386 1387Creates an **RdbPredicates** object to add the AND condition. 1388 1389**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1390 1391**Return value** 1392 1393| Type | Description | 1394| ------------------------------------ | ------------------------- | 1395| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1396 1397**Example** 1398 1399```ts 1400// Find the records in the EMPLOYEE table where the NAME column is Lisa and the SALARY column is 200.5. 1401let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1402predicates.equalTo("NAME", "Lisa") 1403 .and() 1404 .equalTo("SALARY", 200.5) 1405``` 1406 1407### contains 1408 1409contains(field: string, value: string): RdbPredicates 1410 1411Creates an **RdbPredicates** object to search for the records in the specified column that contain the given value. 1412 1413**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1414 1415**Parameters** 1416 1417| Name| Type | Mandatory| Description | 1418| ------ | ------ | ---- | ---------------------- | 1419| field | string | Yes | Column name in the database table. | 1420| value | string | Yes | Value to match.| 1421 1422**Return value** 1423 1424| Type | Description | 1425| ------------------------------------ | -------------------------- | 1426| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1427 1428**Error codes** 1429 1430For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1431 1432| **ID**| **Error Message** | 1433| --------- |----------------------------------------------------------------------------------------------------------------| 1434| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1435 1436**Example** 1437 1438```ts 1439// Find all the records that contain the string 'os' in the NAME column. 1440let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1441predicates.contains("NAME", "os"); 1442``` 1443 1444### beginsWith 1445 1446beginsWith(field: string, value: string): RdbPredicates 1447 1448Creates an **RdbPredicates** object to search for the records in the specified column that begin with the given value. 1449 1450**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1451 1452**Parameters** 1453 1454| Name| Type | Mandatory| Description | 1455| ------ | ------ | ---- | ---------------------- | 1456| field | string | Yes | Column name in the database table. | 1457| value | string | Yes | Value to match.| 1458 1459**Return value** 1460 1461| Type | Description | 1462| ------------------------------------ | -------------------------- | 1463| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1464 1465**Error codes** 1466 1467For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1468 1469| **ID**| **Error Message** | 1470| --------- |----------------------------------------------------------------------------------------------------------------| 1471| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1472 1473**Example** 1474 1475```ts 1476// Find all the records that start with "Li" in the NAME column, for example, Lisa. 1477let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1478predicates.beginsWith("NAME", "Li"); 1479``` 1480 1481### endsWith 1482 1483endsWith(field: string, value: string): RdbPredicates 1484 1485Creates an **RdbPredicates** object to search for the records in the specified column that end with the given value. 1486 1487**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1488 1489**Parameters** 1490 1491| Name| Type | Mandatory| Description | 1492| ------ | ------ | ---- | ---------------------- | 1493| field | string | Yes | Column name in the database table. | 1494| value | string | Yes | Value to match.| 1495 1496**Return value** 1497 1498| Type | Description | 1499| ------------------------------------ | -------------------------- | 1500| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1501 1502**Error codes** 1503 1504For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1505 1506| **ID**| **Error Message** | 1507| --------- |----------------------------------------------------------------------------------------------------------------| 1508| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1509 1510**Example** 1511 1512```ts 1513// Find all the records that end with "se" in the NAME column, for example, Rose. 1514let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1515predicates.endsWith("NAME", "se"); 1516``` 1517 1518### isNull 1519 1520isNull(field: string): RdbPredicates 1521 1522Creates an **RdbPredicates** object to search for the records in the specified column that are **null**. 1523 1524**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1525 1526**Parameters** 1527 1528| Name| Type | Mandatory| Description | 1529| ------ | ------ | ---- | ------------------ | 1530| field | string | Yes | Column name in the database table.| 1531 1532**Return value** 1533 1534| Type | Description | 1535| ------------------------------------ | -------------------------- | 1536| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1537 1538**Error codes** 1539 1540For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1541 1542| **ID**| **Error Message** | 1543| --------- |----------------------------------------------------------------------------------------------------------------| 1544| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1545 1546**Example** 1547 1548```ts 1549let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1550predicates.isNull("NAME"); 1551``` 1552 1553### isNotNull 1554 1555isNotNull(field: string): RdbPredicates 1556 1557Creates an **RdbPredicates** object to search for the records in the specified column that are not **null**. 1558 1559**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1560 1561**Parameters** 1562 1563| Name| Type | Mandatory| Description | 1564| ------ | ------ | ---- | ------------------ | 1565| field | string | Yes | Column name in the database table.| 1566 1567**Return value** 1568 1569| Type | Description | 1570| ------------------------------------ | -------------------------- | 1571| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1572 1573**Error codes** 1574 1575For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1576 1577| **ID**| **Error Message** | 1578| --------- |----------------------------------------------------------------------------------------------------------------| 1579| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1580 1581**Example** 1582 1583```ts 1584let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1585predicates.isNotNull("NAME"); 1586``` 1587 1588### like 1589 1590like(field: string, value: string): RdbPredicates 1591 1592Creates an **RdbPredicates** object to search for the records in the specified column that are similar to the given value. 1593 1594**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1595 1596**Parameters** 1597 1598| Name| Type | Mandatory| Description | 1599| ------ | ------ | ---- | ---------------------- | 1600| field | string | Yes | Column name in the database table. | 1601| value | string | Yes | Value to match.| 1602 1603**Return value** 1604 1605| Type | Description | 1606| ------------------------------------ | -------------------------- | 1607| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1608 1609**Error codes** 1610 1611For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1612 1613| **ID**| **Error Message** | 1614| --------- |----------------------------------------------------------------------------------------------------------------| 1615| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1616 1617**Example** 1618 1619```ts 1620// Find all the records that are similar to "os" in the NAME column, for example, Rose. 1621let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1622predicates.like("NAME", "%os%"); 1623``` 1624 1625### glob 1626 1627glob(field: string, value: string): RdbPredicates 1628 1629Creates an **RdbPredicates** object to search for the records in the specified column that match the given string. 1630 1631**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1632 1633**Parameters** 1634 1635| Name| Type | Mandatory| Description | 1636| ------ | ------ | ---- | ------------------------------------------------------------ | 1637| field | string | Yes | Column name in the database table. | 1638| 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.| 1639 1640**Return value** 1641 1642| Type | Description | 1643| ------------------------------------ | -------------------------- | 1644| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1645 1646**Error codes** 1647 1648For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1649 1650| **ID**| **Error Message** | 1651| --------- |----------------------------------------------------------------------------------------------------------------| 1652| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1653 1654**Example** 1655 1656```ts 1657// Find the strings that match "?h*g" in the NAME column. 1658let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1659predicates.glob("NAME", "?h*g"); 1660``` 1661 1662### between 1663 1664between(field: string, low: ValueType, high: ValueType): RdbPredicates 1665 1666Creates an **RdbPredicates** object to search for the records that are within the given range (including the min. and max. values) in the specified column. 1667 1668**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1669 1670**Parameters** 1671 1672| Name| Type | Mandatory| Description | 1673| ------ | ----------------------- | ---- | -------------------------- | 1674| field | string | Yes | Column name in the database table. | 1675| low | [ValueType](#valuetype) | Yes | Minimum value of the range to set. | 1676| high | [ValueType](#valuetype) | Yes | Maximum value of the range to set.| 1677 1678**Return value** 1679 1680| Type | Description | 1681| ------------------------------------ | -------------------------- | 1682| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1683 1684**Error codes** 1685 1686For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1687 1688| **ID**| **Error Message** | 1689| --------- |----------------------------------------------------------------------------------------------------------------| 1690| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1691 1692**Example** 1693 1694```ts 1695// Find the records that are greater than or equal to 10 and less than or equal to 50 in the AGE column. 1696let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1697predicates.between("AGE", 10, 50); 1698``` 1699 1700### notBetween 1701 1702notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates 1703 1704Creates 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. 1705 1706**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1707 1708**Parameters** 1709 1710| Name| Type | Mandatory| Description | 1711| ------ | ----------------------- | ---- | -------------------------- | 1712| field | string | Yes | Column name in the database table. | 1713| low | [ValueType](#valuetype) | Yes | Minimum value of the range to set. | 1714| high | [ValueType](#valuetype) | Yes | Maximum value of the range to set.| 1715 1716**Return value** 1717 1718| Type | Description | 1719| ------------------------------------ | -------------------------- | 1720| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1721 1722**Error codes** 1723 1724For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1725 1726| **ID**| **Error Message** | 1727| --------- |----------------------------------------------------------------------------------------------------------------| 1728| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1729 1730**Example** 1731 1732```ts 1733// Find the records that are less than 10 or greater than 50 in the AGE column. 1734let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1735predicates.notBetween("AGE", 10, 50); 1736``` 1737 1738### greaterThan 1739 1740greaterThan(field: string, value: ValueType): RdbPredicates 1741 1742Creates an **RdbPredicates** object to search for the records that are greater than the given value in the specified column. 1743 1744**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1745 1746**Parameters** 1747 1748| Name| Type | Mandatory| Description | 1749| ------ | ----------------------- | ---- | ---------------------- | 1750| field | string | Yes | Column name in the database table. | 1751| value | [ValueType](#valuetype) | Yes | Value to match.| 1752 1753**Return value** 1754 1755| Type | Description | 1756| ------------------------------------ | -------------------------- | 1757| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1758 1759**Error codes** 1760 1761For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1762 1763| **ID**| **Error Message** | 1764| --------- |----------------------------------------------------------------------------------------------------------------| 1765| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1766 1767**Example** 1768 1769```ts 1770// Find all the records that are greater than 18 in the AGE column. 1771let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1772predicates.greaterThan("AGE", 18); 1773``` 1774 1775### lessThan 1776 1777lessThan(field: string, value: ValueType): RdbPredicates 1778 1779Creates an **RdbPredicates** object to search for the records that are less than the given value in the specified column. 1780 1781**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1782 1783**Parameters** 1784 1785| Name| Type | Mandatory| Description | 1786| ------ | ----------------------- | ---- | ---------------------- | 1787| field | string | Yes | Column name in the database table. | 1788| value | [ValueType](#valuetype) | Yes | Value to match.| 1789 1790**Return value** 1791 1792| Type | Description | 1793| ------------------------------------ | -------------------------- | 1794| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1795 1796**Error codes** 1797 1798For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1799 1800| **ID**| **Error Message** | 1801| --------- |----------------------------------------------------------------------------------------------------------------| 1802| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1803 1804**Example** 1805 1806```ts 1807// Find all the records that are less than 20 in the AGE column. 1808let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1809predicates.lessThan("AGE", 20); 1810``` 1811 1812### greaterThanOrEqualTo 1813 1814greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1815 1816Creates an **RdbPredicates** object to search for the records that are greater than or equal to the given value in the specified column. 1817 1818**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1819 1820**Parameters** 1821 1822| Name| Type | Mandatory| Description | 1823| ------ | ----------------------- | ---- | ---------------------- | 1824| field | string | Yes | Column name in the database table. | 1825| value | [ValueType](#valuetype) | Yes | Value to match.| 1826 1827**Return value** 1828 1829| Type | Description | 1830| ------------------------------------ | -------------------------- | 1831| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1832 1833**Error codes** 1834 1835For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1836 1837| **ID**| **Error Message** | 1838| --------- |----------------------------------------------------------------------------------------------------------------| 1839| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1840 1841**Example** 1842 1843```ts 1844// Find all the records that are greater than or equal to 18 in the AGE column. 1845let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1846predicates.greaterThanOrEqualTo("AGE", 18); 1847``` 1848 1849### lessThanOrEqualTo 1850 1851lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1852 1853Creates an **RdbPredicates** object to search for the records that are less than or equal to the given value in the specified column. 1854 1855**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1856 1857**Parameters** 1858 1859| Name| Type | Mandatory| Description | 1860| ------ | ----------------------- | ---- | ---------------------- | 1861| field | string | Yes | Column name in the database table. | 1862| value | [ValueType](#valuetype) | Yes | Value to match.| 1863 1864**Return value** 1865 1866| Type | Description | 1867| ------------------------------------ | -------------------------- | 1868| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1869 1870**Error codes** 1871 1872For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1873 1874| **ID**| **Error Message** | 1875| --------- |----------------------------------------------------------------------------------------------------------------| 1876| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1877 1878**Example** 1879 1880```ts 1881// Find all the records that are less than or equal to 20 in the AGE column. 1882let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1883predicates.lessThanOrEqualTo("AGE", 20); 1884``` 1885 1886### orderByAsc 1887 1888orderByAsc(field: string): RdbPredicates 1889 1890Creates an **RdbPredicates** object to sort the records in the specified column in ascending order. 1891 1892**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1893 1894**Parameters** 1895 1896| Name| Type | Mandatory| Description | 1897| ------ | ------ | ---- | ------------------ | 1898| field | string | Yes | Column name in the database table.| 1899 1900**Return value** 1901 1902| Type | Description | 1903| ------------------------------------ | -------------------------- | 1904| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1905 1906**Error codes** 1907 1908For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1909 1910| **ID**| **Error Message** | 1911| --------- |----------------------------------------------------------------------------------------------------------------| 1912| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1913 1914**Example** 1915 1916```ts 1917let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1918predicates.orderByAsc("NAME"); 1919``` 1920 1921### orderByDesc 1922 1923orderByDesc(field: string): RdbPredicates 1924 1925Creates an **RdbPredicates** object to sort the records in the specified column in descending order. 1926 1927**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1928 1929**Parameters** 1930 1931| Name| Type | Mandatory| Description | 1932| ------ | ------ | ---- | ------------------ | 1933| field | string | Yes | Column name in the database table.| 1934 1935**Return value** 1936 1937| Type | Description | 1938| ------------------------------------ | -------------------------- | 1939| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1940 1941**Error codes** 1942 1943For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1944 1945| **ID**| **Error Message** | 1946| --------- |----------------------------------------------------------------------------------------------------------------| 1947| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1948 1949**Example** 1950 1951```ts 1952let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1953predicates.orderByDesc("AGE"); 1954``` 1955 1956### distinct 1957 1958distinct(): RdbPredicates 1959 1960Creates an **RdbPredicates** object to filter out duplicate records. 1961 1962**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1963 1964**Return value** 1965 1966| Type | Description | 1967| ------------------------------------ | ------------------------------ | 1968| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.| 1969 1970**Example** 1971 1972```ts 1973let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1974predicates.equalTo("NAME", "Rose").distinct(); 1975``` 1976 1977### limitAs 1978 1979limitAs(value: number): RdbPredicates 1980 1981Creates an **RdbPredicates** object to limit the number of data records. 1982 1983**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1984 1985**Parameters** 1986 1987| Name| Type | Mandatory| Description | 1988| ------ | ------ | ---- | ---------------- | 1989| 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.| 1990 1991**Return value** 1992 1993| Type | Description | 1994| ------------------------------------ | ------------------------------------ | 1995| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.| 1996 1997**Error codes** 1998 1999For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2000 2001| **ID**| **Error Message** | 2002| --------- |--------------------------| 2003| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2004 2005**Example** 2006 2007```ts 2008let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2009predicates.equalTo("NAME", "Rose").limitAs(3); 2010``` 2011 2012### offsetAs 2013 2014offsetAs(rowOffset: number): RdbPredicates 2015 2016Creates 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 **-1** in **limitAs**. 2017 2018**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2019 2020**Parameters** 2021 2022| Name | Type | Mandatory| Description | 2023| --------- | ------ | ---- | ---------------------------------- | 2024| rowOffset | number | Yes | Start position to set. The value should be a positive integer. The start position of the result set is **0**. If a value less than or equal to **0** is specified, the query result is returned from the 0 index position.| 2025 2026**Return value** 2027 2028| Type | Description | 2029| ------------------------------------ | ------------------------------------ | 2030| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the query result.| 2031 2032**Error codes** 2033 2034For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2035 2036| **ID**| **Error Message** | 2037| --------- |----------------------------------------------------------------------------------------------------------------| 2038| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2039 2040**Example** 2041 2042```ts 2043let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2044predicates.equalTo("NAME", "Rose").limitAs(-1).offsetAs(3); 2045``` 2046 2047### groupBy 2048 2049groupBy(fields: Array<string>): RdbPredicates 2050 2051Creates an **RdbPredicates** object to group the query results based on the specified columns. 2052 2053**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2054 2055**Parameters** 2056 2057| Name| Type | Mandatory| Description | 2058| ------ | ------------------- | ---- | -------------------- | 2059| fields | Array<string> | Yes | Names of columns to group.| 2060 2061**Return value** 2062 2063| Type | Description | 2064| ------------------------------------ | ---------------------- | 2065| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2066 2067**Error codes** 2068 2069For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2070 2071| **ID**| **Error Message** | 2072| --------- |----------------------------------------------------------------------------------------------------------------| 2073| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2074 2075**Example** 2076 2077```ts 2078let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2079predicates.groupBy(["AGE", "NAME"]); 2080``` 2081 2082### indexedBy 2083 2084indexedBy(field: string): RdbPredicates 2085 2086Creates an **RdbPredicates** object to specify the index column. 2087 2088**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2089 2090**Parameters** 2091 2092| Name| Type | Mandatory| Description | 2093| ------ | ------ | ---- | -------------- | 2094| field | string | Yes | Name of the index column.| 2095 2096**Return value** 2097 2098 2099| Type | Description | 2100| ------------------------------------ | ------------------------------------- | 2101| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2102 2103**Error codes** 2104 2105For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2106 2107| **ID**| **Error Message** | 2108| --------- |----------------------------------------------------------------------------------------------------------------| 2109| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2110 2111**Example** 2112 2113```ts 2114let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2115predicates.indexedBy("SALARY"); 2116``` 2117 2118### in 2119 2120in(field: string, value: Array<ValueType>): RdbPredicates 2121 2122Creates an **RdbPredicates** object to search for the records that are in the given range in the specified column. 2123 2124**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2125 2126**Parameters** 2127 2128| Name| Type | Mandatory| Description | 2129| ------ | ------------------------------------ | ---- | --------------------------------------- | 2130| field | string | Yes | Column name in the database table. | 2131| value | Array<[ValueType](#valuetype)> | Yes | Array of **ValueType**s to match.| 2132 2133**Return value** 2134 2135| Type | Description | 2136| ------------------------------------ | -------------------------- | 2137| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2138 2139**Error codes** 2140 2141For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2142 2143| **ID**| **Error Message** | 2144| --------- |----------------------------------------------------------------------------------------------------------------| 2145| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2146 2147**Example** 2148 2149```ts 2150// Find records that are within [18, 20] in the AGE column. 2151let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2152predicates.in("AGE", [18, 20]); 2153``` 2154 2155### notIn 2156 2157notIn(field: string, value: Array<ValueType>): RdbPredicates 2158 2159Creates an **RdbPredicates** object to search for the records that are out of the given range in the specified column. 2160 2161**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2162 2163**Parameters** 2164 2165| Name| Type | Mandatory| Description | 2166| ------ | ------------------------------------ | ---- | ------------------------------------- | 2167| field | string | Yes | Column name in the database table. | 2168| value | Array<[ValueType](#valuetype)> | Yes | Array of **ValueType**s to match.| 2169 2170**Return value** 2171 2172| Type | Description | 2173| ------------------------------------ | -------------------------- | 2174| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2175 2176**Error codes** 2177 2178For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2179 2180| **ID**| **Error Message** | 2181| --------- |----------------------------------------------------------------------------------------------------------------| 2182| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2183 2184**Example** 2185 2186```ts 2187// Find the records that are not within [Lisa, Rose] in the NAME column. 2188let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2189predicates.notIn("NAME", ["Lisa", "Rose"]); 2190``` 2191 2192### notContains<sup>12+</sup> 2193 2194notContains(field: string, value: string): RdbPredicates 2195 2196Creates an **RdbPredicates** object to search for the records that do not contain the given value in the specified column. 2197 2198**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2199 2200**Parameters** 2201 2202| Name| Type | Mandatory| Description | 2203| ------ | ------ | ---- | ---------------------- | 2204| field | string | Yes | Column name in the database table. | 2205| value | string | Yes | Value to match.| 2206 2207**Return value** 2208 2209| Type | Description | 2210| ------------------------------- | -------------------------- | 2211| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2212 2213**Error codes** 2214 2215For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2216 2217| **ID**| **Error Message** | 2218| --------- |----------------------------------------------------------------------------------------------------------------| 2219| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2220 2221**Example** 2222 2223```ts 2224// Find the records that do not contain the string "os" in the NAME column, for example, Lisa. 2225let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2226predicates.notContains("NAME", "os"); 2227``` 2228 2229### notLike<sup>12+</sup> 2230 2231notLike(field: string, value: string): RdbPredicates 2232 2233Creates an **RdbPredicates** object to search for the records that are not similar to the given value in the specified column. 2234 2235**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2236 2237**Parameters** 2238 2239| Name| Type | Mandatory| Description | 2240| ------ | ------ | ---- | ---------------------- | 2241| field | string | Yes | Column name in the database table. | 2242| value | string | Yes | Value to match.| 2243 2244**Return value** 2245 2246| Type | Description | 2247| ------------------------------- | -------------------------- | 2248| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 2249 2250**Error codes** 2251 2252For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2253 2254| **ID**| **Error Message** | 2255| --------- |----------------------------------------------------------------------------------------------------------------| 2256| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2257 2258**Example** 2259 2260```ts 2261// Find the records that are not "os" in the NAME column, for example, Rose. 2262let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2263predicates.notLike("NAME", "os"); 2264``` 2265 2266 2267 2268## RdbStore 2269 2270Provides APIs for managing data in an RDB store. 2271 2272Before using the APIs of this class, use [executeSql](#executesql) to initialize the database table structure and related data. 2273 2274### Properties 2275 2276**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2277 2278| Name | Type | Read-Only | Optional| Description | 2279| ------------ | ----------- | ---- | -------------------------------- | -------------------------------- | 2280| version<sup>10+</sup> | number | No| No | RDB store version, which is an integer greater than 0. | 2281| rebuilt<sup>12+</sup> | [RebuildType](#rebuildtype12) | Yes| No| Whether the RDB store has been rebuilt or repaired.| 2282 2283**Error codes** 2284 2285For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 2286 2287| **ID**| **Error Message** | 2288|-----------| ------------------------------------------------------------ | 2289| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2290| 801 | Capability not supported. | 2291| 14800000 | Inner error. | 2292| 14800014 | Already closed. | 2293| 14800015 | The database does not respond. | 2294| 14800021 | SQLite: Generic error. | 2295| 14800023 | SQLite: Access permission denied. | 2296| 14800024 | SQLite: The database file is locked. | 2297| 14800025 | SQLite: A table in the database is locked. | 2298| 14800026 | SQLite: The database is out of memory. | 2299| 14800027 | SQLite: Attempt to write a readonly database. | 2300| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2301| 14800029 | SQLite: The database is full. | 2302| 14800030 | SQLite: Unable to open the database file. | 2303 2304**Example** 2305 2306```ts 2307// Set the RDB store version. 2308import { UIAbility } from '@kit.AbilityKit'; 2309import { BusinessError } from '@kit.BasicServicesKit'; 2310import { window } from '@kit.ArkUI'; 2311 2312let store: relationalStore.RdbStore | undefined = undefined; 2313 2314class EntryAbility extends UIAbility { 2315 onWindowStageCreate(windowStage: window.WindowStage) { 2316 const STORE_CONFIG: relationalStore.StoreConfig = { 2317 name: "RdbTest.db", 2318 securityLevel: relationalStore.SecurityLevel.S3, 2319 }; 2320 2321 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 2322 store = rdbStore; 2323 console.info('Get RdbStore successfully.') 2324 }).catch((err: BusinessError) => { 2325 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 2326 }) 2327 2328 // Set the RDB store version. 2329 if (store != undefined) { 2330 (store as relationalStore.RdbStore).version = 3; 2331 // Obtain the RDB store version. 2332 console.info(`RdbStore version is ${store.version}`); 2333 // Whether the RDB store has been rebuilt. 2334 console.info(`RdbStore rebuilt is ${store.rebuilt}`); 2335 } 2336 } 2337} 2338``` 2339 2340### insert 2341 2342insert(table: string, values: ValuesBucket, callback: AsyncCallback<number>):void 2343 2344Inserts 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. 2345 2346**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2347 2348**Parameters** 2349 2350| Name | Type | Mandatory| Description | 2351| -------- | ----------------------------- | ---- | ---------------------------------------------------------- | 2352| table | string | Yes | Name of the target table. | 2353| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2354| 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.| 2355 2356**Error codes** 2357 2358For 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). 2359 2360| **ID**| **Error Message** | 2361|-----------| ------------------------------------------------------------ | 2362| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2363| 14800000 | Inner error. | 2364| 14800011 | Database corrupted. | 2365| 14800014 | Already closed. | 2366| 14800015 | The database does not respond. | 2367| 14800021 | SQLite: Generic error. | 2368| 14800022 | SQLite: Callback routine requested an abort. | 2369| 14800023 | SQLite: Access permission denied. | 2370| 14800024 | SQLite: The database file is locked. | 2371| 14800025 | SQLite: A table in the database is locked. | 2372| 14800026 | SQLite: The database is out of memory. | 2373| 14800027 | SQLite: Attempt to write a readonly database. | 2374| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2375| 14800029 | SQLite: The database is full. | 2376| 14800030 | SQLite: Unable to open the database file. | 2377| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2378| 14800032 | SQLite: Abort due to constraint violation. | 2379| 14800033 | SQLite: Data type mismatch. | 2380| 14800034 | SQLite: Library used incorrectly. | 2381| 14800047 | The WAL file size exceeds the default limit. | 2382 2383**Example** 2384 2385```ts 2386let value1 = "Lisa"; 2387let value2 = 18; 2388let value3 = 100.5; 2389let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2390 2391// You can use either of the following: 2392const valueBucket1: relationalStore.ValuesBucket = { 2393 'NAME': value1, 2394 'AGE': value2, 2395 'SALARY': value3, 2396 'CODES': value4, 2397}; 2398const valueBucket2: relationalStore.ValuesBucket = { 2399 NAME: value1, 2400 AGE: value2, 2401 SALARY: value3, 2402 CODES: value4, 2403}; 2404const valueBucket3: relationalStore.ValuesBucket = { 2405 "NAME": value1, 2406 "AGE": value2, 2407 "SALARY": value3, 2408 "CODES": value4, 2409}; 2410 2411if (store != undefined) { 2412 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, (err: BusinessError, rowId: number) => { 2413 if (err) { 2414 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2415 return; 2416 } 2417 console.info(`Insert is successful, rowId = ${rowId}`); 2418 }) 2419} 2420``` 2421 2422### insert<sup>10+</sup> 2423 2424insert(table: string, values: ValuesBucket, conflict: ConflictResolution, callback: AsyncCallback<number>):void 2425 2426Inserts 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. 2427 2428**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2429 2430**Parameters** 2431 2432| Name | Type | Mandatory| Description | 2433| -------- | ------------------------------------------- | ---- | ---------------------------------------------------------- | 2434| table | string | Yes | Name of the target table. | 2435| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2436| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 2437| 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.| 2438 2439**Error codes** 2440 2441For 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). 2442 2443| **ID**| **Error Message** | 2444|-----------| ---------------------------------------------------- | 2445| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2446| 14800000 | Inner error. | 2447| 14800011 | Database corrupted. | 2448| 14800014 | Already closed. | 2449| 14800015 | The database does not respond. | 2450| 14800021 | SQLite: Generic error. | 2451| 14800022 | SQLite: Callback routine requested an abort. | 2452| 14800023 | SQLite: Access permission denied. | 2453| 14800024 | SQLite: The database file is locked. | 2454| 14800025 | SQLite: A table in the database is locked. | 2455| 14800026 | SQLite: The database is out of memory. | 2456| 14800027 | SQLite: Attempt to write a readonly database. | 2457| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2458| 14800029 | SQLite: The database is full. | 2459| 14800030 | SQLite: Unable to open the database file. | 2460| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2461| 14800032 | SQLite: Abort due to constraint violation. | 2462| 14800033 | SQLite: Data type mismatch. | 2463| 14800034 | SQLite: Library used incorrectly. | 2464| 14800047 | The WAL file size exceeds the default limit. | 2465 2466**Example** 2467 2468```ts 2469let value1 = "Lisa"; 2470let value2 = 18; 2471let value3 = 100.5; 2472let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2473 2474// You can use either of the following: 2475const valueBucket1: relationalStore.ValuesBucket = { 2476 'NAME': value1, 2477 'AGE': value2, 2478 'SALARY': value3, 2479 'CODES': value4, 2480}; 2481const valueBucket2: relationalStore.ValuesBucket = { 2482 NAME: value1, 2483 AGE: value2, 2484 SALARY: value3, 2485 CODES: value4, 2486}; 2487const valueBucket3: relationalStore.ValuesBucket = { 2488 "NAME": value1, 2489 "AGE": value2, 2490 "SALARY": value3, 2491 "CODES": value4, 2492}; 2493 2494if (store != undefined) { 2495 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, 2496 (err: BusinessError, rowId: number) => { 2497 if (err) { 2498 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2499 return; 2500 } 2501 console.info(`Insert is successful, rowId = ${rowId}`); 2502 }) 2503} 2504``` 2505 2506### insert 2507 2508insert(table: string, values: ValuesBucket):Promise<number> 2509 2510Inserts 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. 2511 2512**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2513 2514**Parameters** 2515 2516| Name| Type | Mandatory| Description | 2517| ------ | ----------------------------- | ---- | -------------------------- | 2518| table | string | Yes | Name of the target table. | 2519| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 2520 2521**Return value** 2522 2523| Type | Description | 2524| --------------------- | ------------------------------------------------- | 2525| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2526 2527**Error codes** 2528 2529For 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). 2530 2531| **ID**| **Error Message** | 2532|-----------| ------------------------------------------------------------ | 2533| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2534| 14800000 | Inner error. | 2535| 14800011 | Database corrupted. | 2536| 14800014 | Already closed. | 2537| 14800015 | The database does not respond. | 2538| 14800021 | SQLite: Generic error. | 2539| 14800022 | SQLite: Callback routine requested an abort. | 2540| 14800023 | SQLite: Access permission denied. | 2541| 14800024 | SQLite: The database file is locked. | 2542| 14800025 | SQLite: A table in the database is locked. | 2543| 14800026 | SQLite: The database is out of memory. | 2544| 14800027 | SQLite: Attempt to write a readonly database. | 2545| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2546| 14800029 | SQLite: The database is full. | 2547| 14800030 | SQLite: Unable to open the database file. | 2548| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2549| 14800032 | SQLite: Abort due to constraint violation. | 2550| 14800033 | SQLite: Data type mismatch. | 2551| 14800034 | SQLite: Library used incorrectly. | 2552| 14800047 | The WAL file size exceeds the default limit. | 2553 2554**Example** 2555 2556```ts 2557import { BusinessError } from '@kit.BasicServicesKit'; 2558 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).then((rowId: number) => { 2586 console.info(`Insert is successful, rowId = ${rowId}`); 2587 }).catch((err: BusinessError) => { 2588 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2589 }) 2590} 2591``` 2592 2593### insert<sup>10+</sup> 2594 2595insert(table: string, values: ValuesBucket, conflict: ConflictResolution):Promise<number> 2596 2597Inserts 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. 2598 2599**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2600 2601**Parameters** 2602 2603| Name | Type | Mandatory| Description | 2604| -------- | ------------------------------------------- | ---- | -------------------------- | 2605| table | string | Yes | Name of the target table. | 2606| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 2607| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 2608 2609**Return value** 2610 2611| Type | Description | 2612| --------------------- | ------------------------------------------------- | 2613| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2614 2615**Error codes** 2616 2617For 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). 2618 2619| **ID**| **Error Message** | 2620|-----------| ------------------------------------------------------------ | 2621| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2622| 14800000 | Inner error. | 2623| 14800011 | Database corrupted. | 2624| 14800014 | Already closed. | 2625| 14800015 | The database does not respond. | 2626| 14800021 | SQLite: Generic error. | 2627| 14800022 | SQLite: Callback routine requested an abort. | 2628| 14800023 | SQLite: Access permission denied. | 2629| 14800024 | SQLite: The database file is locked. | 2630| 14800025 | SQLite: A table in the database is locked. | 2631| 14800026 | SQLite: The database is out of memory. | 2632| 14800027 | SQLite: Attempt to write a readonly database. | 2633| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2634| 14800029 | SQLite: The database is full. | 2635| 14800030 | SQLite: Unable to open the database file. | 2636| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2637| 14800032 | SQLite: Abort due to constraint violation. | 2638| 14800033 | SQLite: Data type mismatch. | 2639| 14800034 | SQLite: Library used incorrectly. | 2640| 14800047 | The WAL file size exceeds the default limit. | 2641 2642**Example** 2643 2644```ts 2645import { BusinessError } from '@kit.BasicServicesKit'; 2646 2647let value1 = "Lisa"; 2648let value2 = 18; 2649let value3 = 100.5; 2650let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2651 2652// You can use either of the following: 2653const valueBucket1: relationalStore.ValuesBucket = { 2654 'NAME': value1, 2655 'AGE': value2, 2656 'SALARY': value3, 2657 'CODES': value4, 2658}; 2659const valueBucket2: relationalStore.ValuesBucket = { 2660 NAME: value1, 2661 AGE: value2, 2662 SALARY: value3, 2663 CODES: value4, 2664}; 2665const valueBucket3: relationalStore.ValuesBucket = { 2666 "NAME": value1, 2667 "AGE": value2, 2668 "SALARY": value3, 2669 "CODES": value4, 2670}; 2671 2672if (store != undefined) { 2673 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => { 2674 console.info(`Insert is successful, rowId = ${rowId}`); 2675 }).catch((err: BusinessError) => { 2676 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2677 }) 2678} 2679``` 2680 2681### insertSync<sup>12+</sup> 2682 2683insertSync(table: string, values: ValuesBucket, conflict?: ConflictResolution):number 2684 2685Inserts 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. 2686 2687**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2688 2689**Parameters** 2690 2691| Name | Type | Mandatory| Description | 2692| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 2693| table | string | Yes | Name of the target table. | 2694| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 2695| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 2696 2697**Return value** 2698 2699| Type | Description | 2700| ------ | ------------------------------------ | 2701| number | If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2702 2703**Error codes** 2704 2705For 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). 2706 2707| **ID**| **Error Message** | 2708| ------------ | ------------------------------------------------------------ | 2709| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2710| 14800000 | Inner error. | 2711| 14800011 | Database corrupted. | 2712| 14800014 | Already closed. | 2713| 14800015 | The database does not respond. | 2714| 14800021 | SQLite: Generic error. | 2715| 14800022 | SQLite: Callback routine requested an abort. | 2716| 14800023 | SQLite: Access permission denied. | 2717| 14800024 | SQLite: The database file is locked. | 2718| 14800025 | SQLite: A table in the database is locked. | 2719| 14800026 | SQLite: The database is out of memory. | 2720| 14800027 | SQLite: Attempt to write a readonly database. | 2721| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2722| 14800029 | SQLite: The database is full. | 2723| 14800030 | SQLite: Unable to open the database file. | 2724| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2725| 14800032 | SQLite: Abort due to constraint violation. | 2726| 14800033 | SQLite: Data type mismatch. | 2727| 14800034 | SQLite: Library used incorrectly. | 2728| 14800047 | The WAL file size exceeds the default limit. | 2729 2730**Example** 2731 2732```ts 2733import { BusinessError } from '@kit.BasicServicesKit'; 2734 2735let value1 = "Lisa"; 2736let value2 = 18; 2737let value3 = 100.5; 2738let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2739 2740// You can use either of the following: 2741const valueBucket1: relationalStore.ValuesBucket = { 2742 'NAME': value1, 2743 'AGE': value2, 2744 'SALARY': value3, 2745 'CODES': value4, 2746}; 2747const valueBucket2: relationalStore.ValuesBucket = { 2748 NAME: value1, 2749 AGE: value2, 2750 SALARY: value3, 2751 CODES: value4, 2752}; 2753const valueBucket3: relationalStore.ValuesBucket = { 2754 "NAME": value1, 2755 "AGE": value2, 2756 "SALARY": value3, 2757 "CODES": value4, 2758}; 2759 2760if (store != undefined) { 2761 try { 2762 let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 2763 console.info(`Insert is successful, rowId = ${rowId}`); 2764 } catch (error) { 2765 console.error(`Insert is failed, code is ${error.code},message is ${error.message}`); 2766 } 2767} 2768``` 2769 2770### insertSync<sup>12+</sup> 2771 2772insertSync(table: string, values: sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution):number 2773 2774Inserts 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. 2775 2776**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2777 2778**Parameters** 2779 2780| Name | Type | Mandatory| Description | 2781| -------- | ---------------------------------------------------------------------------------------------- | ---- | ------------------------------------------------------------------------------- | 2782| table | string | Yes | Name of the target table. | 2783| values | [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | Yes | Sendable data to insert. | 2784| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 2785 2786**Return value** 2787 2788| Type | Description | 2789| ------ | ------------------------------------ | 2790| number | If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 2791 2792**Error codes** 2793 2794For 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). 2795 2796| **ID**| **Error Message** | 2797| ------------ | ------------------------------------------------------------ | 2798| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2799| 14800000 | Inner error. | 2800| 14800011 | Database corrupted. | 2801| 14800014 | Already closed. | 2802| 14800015 | The database does not respond. | 2803| 14800021 | SQLite: Generic error. | 2804| 14800022 | SQLite: Callback routine requested an abort. | 2805| 14800023 | SQLite: Access permission denied. | 2806| 14800024 | SQLite: The database file is locked. | 2807| 14800025 | SQLite: A table in the database is locked. | 2808| 14800026 | SQLite: The database is out of memory. | 2809| 14800027 | SQLite: Attempt to write a readonly database. | 2810| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2811| 14800029 | SQLite: The database is full. | 2812| 14800030 | SQLite: Unable to open the database file. | 2813| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2814| 14800032 | SQLite: Abort due to constraint violation. | 2815| 14800033 | SQLite: Data type mismatch. | 2816| 14800034 | SQLite: Library used incorrectly. | 2817| 14800047 | The WAL file size exceeds the default limit. | 2818 2819**Example** 2820 2821```ts 2822import { sendableRelationalStore } from '@kit.ArkData'; 2823 2824const valuesBucket: relationalStore.ValuesBucket = { 2825 "NAME": 'hangman', 2826 "AGE": 18, 2827 "SALARY": 100.5, 2828 "CODES": new Uint8Array([1,2,3]), 2829}; 2830const sendableValuesBucket = sendableRelationalStore.toSendableValuesBucket(valuesBucket); 2831 2832if (store != undefined) { 2833 try { 2834 let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", sendableValuesBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 2835 console.info(`Insert is successful, rowId = ${rowId}`); 2836 } catch (error) { 2837 console.error(`Insert is failed, code is ${error.code},message is ${error.message}`); 2838 } 2839} 2840``` 2841 2842### batchInsert 2843 2844batchInsert(table: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>):void 2845 2846Inserts a batch of data into a table. This API uses an asynchronous callback to return the result. 2847 2848**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2849 2850**Parameters** 2851 2852| Name | Type | Mandatory| Description | 2853| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ | 2854| table | string | Yes | Name of the target table. | 2855| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert. | 2856| 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.| 2857 2858**Error codes** 2859 2860For 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). 2861 2862| **ID**| **Error Message** | 2863|-----------| ------------------------------------------------------------ | 2864| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2865| 14800000 | Inner error. | 2866| 14800011 | Database corrupted. | 2867| 14800014 | Already closed. | 2868| 14800015 | The database does not respond. | 2869| 14800021 | SQLite: Generic error. | 2870| 14800022 | SQLite: Callback routine requested an abort. | 2871| 14800023 | SQLite: Access permission denied. | 2872| 14800024 | SQLite: The database file is locked. | 2873| 14800025 | SQLite: A table in the database is locked. | 2874| 14800026 | SQLite: The database is out of memory. | 2875| 14800027 | SQLite: Attempt to write a readonly database. | 2876| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2877| 14800029 | SQLite: The database is full. | 2878| 14800030 | SQLite: Unable to open the database file. | 2879| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2880| 14800032 | SQLite: Abort due to constraint violation. | 2881| 14800033 | SQLite: Data type mismatch. | 2882| 14800034 | SQLite: Library used incorrectly. | 2883| 14800047 | The WAL file size exceeds the default limit. | 2884 2885**Example** 2886 2887```ts 2888 2889let value1 = "Lisa"; 2890let value2 = 18; 2891let value3 = 100.5; 2892let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2893let value5 = "Jack"; 2894let value6 = 19; 2895let value7 = 101.5; 2896let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2897let value9 = "Tom"; 2898let value10 = 20; 2899let value11 = 102.5; 2900let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2901 2902const valueBucket1: relationalStore.ValuesBucket = { 2903 'NAME': value1, 2904 'AGE': value2, 2905 'SALARY': value3, 2906 'CODES': value4, 2907}; 2908const valueBucket2: relationalStore.ValuesBucket = { 2909 'NAME': value5, 2910 'AGE': value6, 2911 'SALARY': value7, 2912 'CODES': value8, 2913}; 2914const valueBucket3: relationalStore.ValuesBucket = { 2915 'NAME': value9, 2916 'AGE': value10, 2917 'SALARY': value11, 2918 'CODES': value12, 2919}; 2920 2921let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2922if (store != undefined) { 2923 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets, (err, insertNum) => { 2924 if (err) { 2925 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2926 return; 2927 } 2928 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2929 }) 2930} 2931``` 2932 2933### batchInsert 2934 2935batchInsert(table: string, values: Array<ValuesBucket>):Promise<number> 2936 2937Inserts a batch of data into a table. This API uses a promise to return the result. 2938 2939**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2940 2941**Parameters** 2942 2943| Name| Type | Mandatory| Description | 2944| ------ | ------------------------------------------ | ---- | ---------------------------- | 2945| table | string | Yes | Name of the target table. | 2946| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 2947 2948**Return value** 2949 2950| Type | Description | 2951| --------------------- | ----------------------------------------------------------- | 2952| 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.| 2953 2954**Error codes** 2955 2956For 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). 2957 2958| **ID**| **Error Message** | 2959|-----------| ------------------------------------------------------------ | 2960| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2961| 14800000 | Inner error. | 2962| 14800011 | Database corrupted. | 2963| 14800014 | Already closed. | 2964| 14800015 | The database does not respond. | 2965| 14800021 | SQLite: Generic error. | 2966| 14800022 | SQLite: Callback routine requested an abort. | 2967| 14800023 | SQLite: Access permission denied. | 2968| 14800024 | SQLite: The database file is locked. | 2969| 14800025 | SQLite: A table in the database is locked. | 2970| 14800026 | SQLite: The database is out of memory. | 2971| 14800027 | SQLite: Attempt to write a readonly database. | 2972| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2973| 14800029 | SQLite: The database is full. | 2974| 14800030 | SQLite: Unable to open the database file. | 2975| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2976| 14800032 | SQLite: Abort due to constraint violation. | 2977| 14800033 | SQLite: Data type mismatch. | 2978| 14800034 | SQLite: Library used incorrectly. | 2979| 14800047 | The WAL file size exceeds the default limit. | 2980 2981**Example** 2982 2983```ts 2984import { BusinessError } from '@kit.BasicServicesKit'; 2985 2986let value1 = "Lisa"; 2987let value2 = 18; 2988let value3 = 100.5; 2989let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2990let value5 = "Jack"; 2991let value6 = 19; 2992let value7 = 101.5; 2993let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2994let value9 = "Tom"; 2995let value10 = 20; 2996let value11 = 102.5; 2997let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2998 2999const valueBucket1: relationalStore.ValuesBucket = { 3000 'NAME': value1, 3001 'AGE': value2, 3002 'SALARY': value3, 3003 'CODES': value4, 3004}; 3005const valueBucket2: relationalStore.ValuesBucket = { 3006 'NAME': value5, 3007 'AGE': value6, 3008 'SALARY': value7, 3009 'CODES': value8, 3010}; 3011const valueBucket3: relationalStore.ValuesBucket = { 3012 'NAME': value9, 3013 'AGE': value10, 3014 'SALARY': value11, 3015 'CODES': value12, 3016}; 3017 3018let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 3019if (store != undefined) { 3020 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => { 3021 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 3022 }).catch((err: BusinessError) => { 3023 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 3024 }) 3025} 3026``` 3027 3028### batchInsertSync<sup>12+</sup> 3029 3030batchInsertSync(table: string, values: Array<ValuesBucket>):number 3031 3032Inserts a batch of data into a table. This API returns the result synchronously. 3033 3034**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3035 3036**Parameters** 3037 3038| Name| Type | Mandatory| Description | 3039| ------ | ------------------------------------------ | ---- | ---------------------------- | 3040| table | string | Yes | Name of the target table. | 3041| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 3042 3043**Return value** 3044 3045| Type | Description | 3046| ------ | ---------------------------------------------- | 3047| number | If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 3048 3049**Error codes** 3050 3051For 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). 3052 3053| **ID**| **Error Message** | 3054| ------------ | ------------------------------------------------------------ | 3055| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3056| 14800000 | Inner error. | 3057| 14800011 | Database corrupted. | 3058| 14800014 | Already closed. | 3059| 14800015 | The database does not respond. | 3060| 14800021 | SQLite: Generic error. | 3061| 14800022 | SQLite: Callback routine requested an abort. | 3062| 14800023 | SQLite: Access permission denied. | 3063| 14800024 | SQLite: The database file is locked. | 3064| 14800025 | SQLite: A table in the database is locked. | 3065| 14800026 | SQLite: The database is out of memory. | 3066| 14800027 | SQLite: Attempt to write a readonly database. | 3067| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3068| 14800029 | SQLite: The database is full. | 3069| 14800030 | SQLite: Unable to open the database file. | 3070| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3071| 14800032 | SQLite: Abort due to constraint violation. | 3072| 14800033 | SQLite: Data type mismatch. | 3073| 14800034 | SQLite: Library used incorrectly. | 3074| 14800047 | The WAL file size exceeds the default limit. | 3075 3076**Example** 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 try { 3116 let insertNum: number = (store as relationalStore.RdbStore).batchInsertSync("EMPLOYEE", valueBuckets); 3117 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 3118 } catch (err) { 3119 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 3120 } 3121} 3122``` 3123 3124### update 3125 3126update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback<number>):void 3127 3128Updates 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. 3129 3130**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3131 3132**Parameters** 3133 3134| Name | Type | Mandatory| Description | 3135| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 3136| 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.| 3137| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3138| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows updated. | 3139 3140**Error codes** 3141 3142For 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). 3143 3144| **ID**| **Error Message** | 3145|-----------| ------------------------------------------------------------ | 3146| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3147| 14800000 | Inner error. | 3148| 14800011 | Database corrupted. | 3149| 14800014 | Already closed. | 3150| 14800015 | The database does not respond. | 3151| 14800021 | SQLite: Generic error. | 3152| 14800022 | SQLite: Callback routine requested an abort. | 3153| 14800023 | SQLite: Access permission denied. | 3154| 14800024 | SQLite: The database file is locked. | 3155| 14800025 | SQLite: A table in the database is locked. | 3156| 14800026 | SQLite: The database is out of memory. | 3157| 14800027 | SQLite: Attempt to write a readonly database. | 3158| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3159| 14800029 | SQLite: The database is full. | 3160| 14800030 | SQLite: Unable to open the database file. | 3161| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3162| 14800032 | SQLite: Abort due to constraint violation. | 3163| 14800033 | SQLite: Data type mismatch. | 3164| 14800034 | SQLite: Library used incorrectly. | 3165| 14800047 | The WAL file size exceeds the default limit. | 3166 3167**Example** 3168 3169```ts 3170 3171let value1 = "Rose"; 3172let value2 = 22; 3173let value3 = 200.5; 3174let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3175 3176// You can use either of the following: 3177const valueBucket1: relationalStore.ValuesBucket = { 3178 'NAME': value1, 3179 'AGE': value2, 3180 'SALARY': value3, 3181 'CODES': value4, 3182}; 3183const valueBucket2: relationalStore.ValuesBucket = { 3184 NAME: value1, 3185 AGE: value2, 3186 SALARY: value3, 3187 CODES: value4, 3188}; 3189const valueBucket3: relationalStore.ValuesBucket = { 3190 "NAME": value1, 3191 "AGE": value2, 3192 "SALARY": value3, 3193 "CODES": value4, 3194}; 3195 3196let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3197predicates.equalTo("NAME", "Lisa"); 3198if (store != undefined) { 3199 (store as relationalStore.RdbStore).update(valueBucket1, predicates,(err, rows) => { 3200 if (err) { 3201 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3202 return; 3203 } 3204 console.info(`Updated row count: ${rows}`); 3205 }) 3206} 3207``` 3208 3209### update<sup>10+</sup> 3210 3211update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution, callback: AsyncCallback<number>):void 3212 3213Updates 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. 3214 3215**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3216 3217**Parameters** 3218 3219| Name | Type | Mandatory| Description | 3220| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3221| 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.| 3222| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3223| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 3224| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows updated. | 3225 3226**Error codes** 3227 3228For 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). 3229 3230| **ID**| **Error Message** | 3231|-----------| ------------------------------------------------------------ | 3232| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3233| 14800000 | Inner error. | 3234| 14800011 | Database corrupted. | 3235| 14800014 | Already closed. | 3236| 14800015 | The database does not respond. | 3237| 14800021 | SQLite: Generic error. | 3238| 14800022 | SQLite: Callback routine requested an abort. | 3239| 14800023 | SQLite: Access permission denied. | 3240| 14800024 | SQLite: The database file is locked. | 3241| 14800025 | SQLite: A table in the database is locked. | 3242| 14800026 | SQLite: The database is out of memory. | 3243| 14800027 | SQLite: Attempt to write a readonly database. | 3244| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3245| 14800029 | SQLite: The database is full. | 3246| 14800030 | SQLite: Unable to open the database file. | 3247| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3248| 14800032 | SQLite: Abort due to constraint violation. | 3249| 14800033 | SQLite: Data type mismatch. | 3250| 14800034 | SQLite: Library used incorrectly. | 3251| 14800047 | The WAL file size exceeds the default limit. | 3252 3253**Example** 3254 3255```ts 3256 3257let value1 = "Rose"; 3258let value2 = 22; 3259let value3 = 200.5; 3260let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3261 3262// You can use either of the following: 3263const valueBucket1: relationalStore.ValuesBucket = { 3264 'NAME': value1, 3265 'AGE': value2, 3266 'SALARY': value3, 3267 'CODES': value4, 3268}; 3269const valueBucket2: relationalStore.ValuesBucket = { 3270 NAME: value1, 3271 AGE: value2, 3272 SALARY: value3, 3273 CODES: value4, 3274}; 3275const valueBucket3: relationalStore.ValuesBucket = { 3276 "NAME": value1, 3277 "AGE": value2, 3278 "SALARY": value3, 3279 "CODES": value4, 3280}; 3281 3282let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3283predicates.equalTo("NAME", "Lisa"); 3284if (store != undefined) { 3285 (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, (err, rows) => { 3286 if (err) { 3287 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3288 return; 3289 } 3290 console.info(`Updated row count: ${rows}`); 3291 }) 3292} 3293``` 3294 3295### update 3296 3297update(values: ValuesBucket, predicates: RdbPredicates):Promise<number> 3298 3299Updates 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. 3300 3301**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3302 3303**Parameters** 3304 3305| Name | Type | Mandatory| Description | 3306| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 3307| 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.| 3308| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3309 3310**Return value** 3311 3312| Type | Description | 3313| --------------------- | ----------------------------------------- | 3314| Promise<number> | Promise used to return the number of rows updated.| 3315 3316**Error codes** 3317 3318For 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). 3319 3320| **ID**| **Error Message** | 3321|-----------| ------------------------------------------------------------ | 3322| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3323| 14800000 | Inner error. | 3324| 14800011 | Database corrupted. | 3325| 14800014 | Already closed. | 3326| 14800015 | The database does not respond. | 3327| 14800021 | SQLite: Generic error. | 3328| 14800022 | SQLite: Callback routine requested an abort. | 3329| 14800023 | SQLite: Access permission denied. | 3330| 14800024 | SQLite: The database file is locked. | 3331| 14800025 | SQLite: A table in the database is locked. | 3332| 14800026 | SQLite: The database is out of memory. | 3333| 14800027 | SQLite: Attempt to write a readonly database. | 3334| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3335| 14800029 | SQLite: The database is full. | 3336| 14800030 | SQLite: Unable to open the database file. | 3337| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3338| 14800032 | SQLite: Abort due to constraint violation. | 3339| 14800033 | SQLite: Data type mismatch. | 3340| 14800034 | SQLite: Library used incorrectly. | 3341| 14800047 | The WAL file size exceeds the default limit. | 3342 3343**Example** 3344 3345```ts 3346import { BusinessError } from '@kit.BasicServicesKit'; 3347 3348let value1 = "Rose"; 3349let value2 = 22; 3350let value3 = 200.5; 3351let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3352 3353// You can use either of the following: 3354const valueBucket1: relationalStore.ValuesBucket = { 3355 'NAME': value1, 3356 'AGE': value2, 3357 'SALARY': value3, 3358 'CODES': value4, 3359}; 3360const valueBucket2: relationalStore.ValuesBucket = { 3361 NAME: value1, 3362 AGE: value2, 3363 SALARY: value3, 3364 CODES: value4, 3365}; 3366const valueBucket3: relationalStore.ValuesBucket = { 3367 "NAME": value1, 3368 "AGE": value2, 3369 "SALARY": value3, 3370 "CODES": value4, 3371}; 3372 3373let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3374predicates.equalTo("NAME", "Lisa"); 3375if (store != undefined) { 3376 (store as relationalStore.RdbStore).update(valueBucket1, predicates).then(async (rows: Number) => { 3377 console.info(`Updated row count: ${rows}`); 3378 }).catch((err: BusinessError) => { 3379 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3380 }) 3381} 3382``` 3383 3384### update<sup>10+</sup> 3385 3386update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution):Promise<number> 3387 3388Updates 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. 3389 3390**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3391 3392**Parameters** 3393 3394| Name | Type | Mandatory| Description | 3395| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3396| 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.| 3397| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3398| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 3399 3400**Return value** 3401 3402| Type | Description | 3403| --------------------- | ----------------------------------------- | 3404| Promise<number> | Promise used to return the number of rows updated.| 3405 3406**Error codes** 3407 3408For 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). 3409 3410| **ID**| **Error Message** | 3411|-----------| ------------------------------------------------------------ | 3412| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3413| 14800000 | Inner error. | 3414| 14800011 | Database corrupted. | 3415| 14800014 | Already closed. | 3416| 14800015 | The database does not respond. | 3417| 14800021 | SQLite: Generic error. | 3418| 14800022 | SQLite: Callback routine requested an abort. | 3419| 14800023 | SQLite: Access permission denied. | 3420| 14800024 | SQLite: The database file is locked. | 3421| 14800025 | SQLite: A table in the database is locked. | 3422| 14800026 | SQLite: The database is out of memory. | 3423| 14800027 | SQLite: Attempt to write a readonly database. | 3424| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3425| 14800029 | SQLite: The database is full. | 3426| 14800030 | SQLite: Unable to open the database file. | 3427| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3428| 14800032 | SQLite: Abort due to constraint violation. | 3429| 14800033 | SQLite: Data type mismatch. | 3430| 14800034 | SQLite: Library used incorrectly. | 3431| 14800047 | The WAL file size exceeds the default limit. | 3432 3433**Example** 3434 3435```ts 3436import { BusinessError } from '@kit.BasicServicesKit'; 3437 3438let value1 = "Rose"; 3439let value2 = 22; 3440let value3 = 200.5; 3441let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3442 3443// You can use either of the following: 3444const valueBucket1: relationalStore.ValuesBucket = { 3445 'NAME': value1, 3446 'AGE': value2, 3447 'SALARY': value3, 3448 'CODES': value4, 3449}; 3450const valueBucket2: relationalStore.ValuesBucket = { 3451 NAME: value1, 3452 AGE: value2, 3453 SALARY: value3, 3454 CODES: value4, 3455}; 3456const valueBucket3: relationalStore.ValuesBucket = { 3457 "NAME": value1, 3458 "AGE": value2, 3459 "SALARY": value3, 3460 "CODES": value4, 3461}; 3462 3463let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3464predicates.equalTo("NAME", "Lisa"); 3465if (store != undefined) { 3466 (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => { 3467 console.info(`Updated row count: ${rows}`); 3468 }).catch((err: BusinessError) => { 3469 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3470 }) 3471} 3472``` 3473 3474### updateSync<sup>12+</sup> 3475 3476updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution):number 3477 3478Updates data in the RDB store based on the specified **RdbPredicates** instance. Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 3479 3480**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3481 3482**Parameters** 3483 3484| Name | Type | Mandatory| Description | 3485| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3486| 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.| 3487| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 3488| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 3489 3490**Return value** 3491 3492| Type | Description | 3493| ------ | ------------------ | 3494| number | return the number of rows updated.| 3495 3496**Error codes** 3497 3498For 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). 3499 3500| **ID**| **Error Message** | 3501| ------------ | ------------------------------------------------------------ | 3502| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3503| 14800000 | Inner error. | 3504| 14800011 | Database corrupted. | 3505| 14800014 | Already closed. | 3506| 14800015 | The database does not respond. | 3507| 14800021 | SQLite: Generic error. | 3508| 14800022 | SQLite: Callback routine requested an abort. | 3509| 14800023 | SQLite: Access permission denied. | 3510| 14800024 | SQLite: The database file is locked. | 3511| 14800025 | SQLite: A table in the database is locked. | 3512| 14800026 | SQLite: The database is out of memory. | 3513| 14800027 | SQLite: Attempt to write a readonly database. | 3514| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3515| 14800029 | SQLite: The database is full. | 3516| 14800030 | SQLite: Unable to open the database file. | 3517| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3518| 14800032 | SQLite: Abort due to constraint violation. | 3519| 14800033 | SQLite: Data type mismatch. | 3520| 14800034 | SQLite: Library used incorrectly. | 3521| 14800047 | The WAL file size exceeds the default limit. | 3522 3523**Example** 3524 3525```ts 3526import { BusinessError } from '@kit.BasicServicesKit'; 3527 3528let value1 = "Rose"; 3529let value2 = 22; 3530let value3 = 200.5; 3531let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3532 3533// You can use either of the following: 3534const valueBucket1: relationalStore.ValuesBucket = { 3535 'NAME': value1, 3536 'AGE': value2, 3537 'SALARY': value3, 3538 'CODES': value4, 3539}; 3540const valueBucket2: relationalStore.ValuesBucket = { 3541 NAME: value1, 3542 AGE: value2, 3543 SALARY: value3, 3544 CODES: value4, 3545}; 3546const valueBucket3: relationalStore.ValuesBucket = { 3547 "NAME": value1, 3548 "AGE": value2, 3549 "SALARY": value3, 3550 "CODES": value4, 3551}; 3552 3553let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3554predicates.equalTo("NAME", "Lisa"); 3555if (store != undefined) { 3556 try { 3557 let rows: Number = (store as relationalStore.RdbStore).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 3558 console.info(`Updated row count: ${rows}`); 3559 } catch (error) { 3560 console.error(`Updated failed, code is ${error.code},message is ${error.message}`); 3561 } 3562} 3563``` 3564 3565### delete 3566 3567delete(predicates: RdbPredicates, callback: AsyncCallback<number>):void 3568 3569Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result. 3570 3571**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3572 3573**Parameters** 3574 3575| Name | Type | Mandatory| Description | 3576| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 3577| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 3578| callback | AsyncCallback<number> | Yes | Callback used to return the number of rows deleted. | 3579 3580**Error codes** 3581 3582For 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). 3583 3584| **ID**| **Error Message** | 3585|-----------| ------------------------------------------------------------ | 3586| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3587| 14800000 | Inner error. | 3588| 14800011 | Database corrupted. | 3589| 14800014 | Already closed. | 3590| 14800015 | The database does not respond. | 3591| 14800021 | SQLite: Generic error. | 3592| 14800022 | SQLite: Callback routine requested an abort. | 3593| 14800023 | SQLite: Access permission denied. | 3594| 14800024 | SQLite: The database file is locked. | 3595| 14800025 | SQLite: A table in the database is locked. | 3596| 14800026 | SQLite: The database is out of memory. | 3597| 14800027 | SQLite: Attempt to write a readonly database. | 3598| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3599| 14800029 | SQLite: The database is full. | 3600| 14800030 | SQLite: Unable to open the database file. | 3601| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3602| 14800032 | SQLite: Abort due to constraint violation. | 3603| 14800033 | SQLite: Data type mismatch. | 3604| 14800034 | SQLite: Library used incorrectly. | 3605| 14800047 | The WAL file size exceeds the default limit. | 3606 3607**Example** 3608 3609```ts 3610let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3611predicates.equalTo("NAME", "Lisa"); 3612if (store != undefined) { 3613 (store as relationalStore.RdbStore).delete(predicates, (err, rows) => { 3614 if (err) { 3615 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3616 return; 3617 } 3618 console.info(`Delete rows: ${rows}`); 3619 }) 3620} 3621``` 3622 3623### delete 3624 3625delete(predicates: RdbPredicates):Promise<number> 3626 3627Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result. 3628 3629**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3630 3631**Parameters** 3632 3633| Name | Type | Mandatory| Description | 3634| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 3635| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 3636 3637**Return value** 3638 3639| Type | Description | 3640| --------------------- | ------------------------------- | 3641| Promise<number> | Promise used to return the number of rows deleted.| 3642 3643**Error codes** 3644 3645For 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). 3646 3647| **ID**| **Error Message** | 3648|-----------| ------------------------------------------------------------ | 3649| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3650| 14800000 | Inner error. | 3651| 14800011 | Database corrupted. | 3652| 14800014 | Already closed. | 3653| 14800015 | The database does not respond. | 3654| 14800021 | SQLite: Generic error. | 3655| 14800022 | SQLite: Callback routine requested an abort. | 3656| 14800023 | SQLite: Access permission denied. | 3657| 14800024 | SQLite: The database file is locked. | 3658| 14800025 | SQLite: A table in the database is locked. | 3659| 14800026 | SQLite: The database is out of memory. | 3660| 14800027 | SQLite: Attempt to write a readonly database. | 3661| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3662| 14800029 | SQLite: The database is full. | 3663| 14800030 | SQLite: Unable to open the database file. | 3664| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3665| 14800032 | SQLite: Abort due to constraint violation. | 3666| 14800033 | SQLite: Data type mismatch. | 3667| 14800034 | SQLite: Library used incorrectly. | 3668| 14800047 | The WAL file size exceeds the default limit. | 3669 3670**Example** 3671 3672```ts 3673import { BusinessError } from '@kit.BasicServicesKit'; 3674 3675let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3676predicates.equalTo("NAME", "Lisa"); 3677if (store != undefined) { 3678 (store as relationalStore.RdbStore).delete(predicates).then((rows: Number) => { 3679 console.info(`Delete rows: ${rows}`); 3680 }).catch((err: BusinessError) => { 3681 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3682 }) 3683} 3684``` 3685 3686### deleteSync<sup>12+</sup> 3687 3688deleteSync(predicates: RdbPredicates):number 3689 3690Deletes data from the RDB store based on the specified **RdbPredicates** object. 3691 3692**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3693 3694**Parameters** 3695 3696| Name | Type | Mandatory| Description | 3697| ---------- | ------------------------------- | ---- | --------------------------------------- | 3698| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 3699 3700**Return value** 3701 3702| Type | Description | 3703| ------ | ------------------ | 3704| number | Number of rows updated.| 3705 3706**Error codes** 3707 3708For 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). 3709 3710| **ID**| **Error Message** | 3711| ------------ | ------------------------------------------------------------ | 3712| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3713| 14800000 | Inner error. | 3714| 14800011 | Database corrupted. | 3715| 14800014 | Already closed. | 3716| 14800015 | The database does not respond. | 3717| 14800021 | SQLite: Generic error. | 3718| 14800022 | SQLite: Callback routine requested an abort. | 3719| 14800023 | SQLite: Access permission denied. | 3720| 14800024 | SQLite: The database file is locked. | 3721| 14800025 | SQLite: A table in the database is locked. | 3722| 14800026 | SQLite: The database is out of memory. | 3723| 14800027 | SQLite: Attempt to write a readonly database. | 3724| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3725| 14800029 | SQLite: The database is full. | 3726| 14800030 | SQLite: Unable to open the database file. | 3727| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3728| 14800032 | SQLite: Abort due to constraint violation. | 3729| 14800033 | SQLite: Data type mismatch. | 3730| 14800034 | SQLite: Library used incorrectly. | 3731| 14800047 | The WAL file size exceeds the default limit. | 3732 3733**Example** 3734 3735```ts 3736import { BusinessError } from '@kit.BasicServicesKit'; 3737 3738let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3739predicates.equalTo("NAME", "Lisa"); 3740if (store != undefined) { 3741 try { 3742 let rows: Number = (store as relationalStore.RdbStore).deleteSync(predicates) 3743 console.info(`Delete rows: ${rows}`); 3744 } catch (err) { 3745 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3746 } 3747} 3748``` 3749 3750### query<sup>10+</sup> 3751 3752query(predicates: RdbPredicates, callback: AsyncCallback<ResultSet>):void 3753 3754Queries 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. 3755 3756**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3757 3758**Parameters** 3759 3760| Name | Type | Mandatory| Description | 3761| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 3762| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3763| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3764 3765**Error codes** 3766 3767For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3768 3769| **ID**| **Error Message** | 3770|-----------| ------------------------------------------------------------ | 3771| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3772| 14800000 | Inner error. | 3773| 14800014 | Already closed. | 3774| 14800015 | The database does not respond. | 3775 3776**Example** 3777 3778```ts 3779let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3780predicates.equalTo("NAME", "Rose"); 3781if (store != undefined) { 3782 (store as relationalStore.RdbStore).query(predicates, (err, resultSet) => { 3783 if (err) { 3784 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3785 return; 3786 } 3787 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3788 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3789 while (resultSet.goToNextRow()) { 3790 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3791 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3792 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3793 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3794 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3795 } 3796 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3797 resultSet.close(); 3798 }) 3799} 3800``` 3801 3802### query 3803 3804query(predicates: RdbPredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>):void 3805 3806Queries 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. 3807 3808**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3809 3810**Parameters** 3811 3812| Name | Type | Mandatory| Description | 3813| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 3814| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3815| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | 3816| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3817 3818**Error codes** 3819 3820For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3821 3822| **ID**| **Error Message** | 3823|-----------| ------------------------------------------------------------ | 3824| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3825| 14800000 | Inner error. | 3826| 14800014 | Already closed. | 3827| 14800015 | The database does not respond. | 3828 3829**Example** 3830 3831```ts 3832let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3833predicates.equalTo("NAME", "Rose"); 3834if (store != undefined) { 3835 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], (err, resultSet) => { 3836 if (err) { 3837 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3838 return; 3839 } 3840 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3841 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3842 while (resultSet.goToNextRow()) { 3843 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3844 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3845 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3846 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3847 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3848 } 3849 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3850 resultSet.close(); 3851 }) 3852} 3853``` 3854 3855### query 3856 3857query(predicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> 3858 3859Queries 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. 3860 3861**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3862 3863**Parameters** 3864 3865| Name | Type | Mandatory| Description | 3866| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 3867| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3868| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 3869 3870**Error codes** 3871 3872For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3873 3874| **ID**| **Error Message** | 3875|-----------| ------------------------------------------------------------ | 3876| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3877| 14800000 | Inner error. | 3878| 14800014 | Already closed. | 3879| 14800015 | The database does not respond. | 3880 3881**Return value** 3882 3883| Type | Description | 3884| ------------------------------------------------------- | -------------------------------------------------- | 3885| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3886 3887**Example** 3888 3889```ts 3890import { BusinessError } from '@kit.BasicServicesKit'; 3891 3892let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3893predicates.equalTo("NAME", "Rose"); 3894if (store != undefined) { 3895 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 3896 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3897 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3898 while (resultSet.goToNextRow()) { 3899 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3900 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3901 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3902 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3903 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3904 } 3905 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3906 resultSet.close(); 3907 }).catch((err: BusinessError) => { 3908 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3909 }) 3910} 3911``` 3912 3913### querySync<sup>12+</sup> 3914 3915querySync(predicates: RdbPredicates, columns?: Array<string>):ResultSet 3916 3917Queries data in the RDB store based on specified conditions. This API returns the result synchronously. If complex logic and a large number of loops are involved in the operations on the **resultSet** obtained by **querySync()**, the freeze problem may occur. You are advised to perform this operation in the [taskpool](../apis-arkts/js-apis-taskpool.md) thread. 3918 3919**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3920 3921**Parameters** 3922 3923| Name | Type | Mandatory| Description | 3924| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ | 3925| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3926| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns. <br>Default value: null.| 3927 3928**Error codes** 3929 3930For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3931 3932| **ID**| **Error Message** | 3933| ------------ | ------------------------------------------------------------ | 3934| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3935| 14800000 | Inner error. | 3936| 14800014 | Already closed. | 3937| 14800015 | The database does not respond. | 3938 3939**Return value** 3940 3941| Type | Description | 3942| ----------------------- | ----------------------------------- | 3943| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 3944 3945**Example** 3946 3947```ts 3948import { BusinessError } from '@kit.BasicServicesKit'; 3949 3950let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3951predicates.equalTo("NAME", "Rose"); 3952if (store != undefined) { 3953 try { 3954 let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); 3955 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3956 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 3957 while (resultSet.goToNextRow()) { 3958 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3959 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3960 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3961 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3962 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3963 } 3964 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 3965 resultSet.close(); 3966 } catch (err) { 3967 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3968 } 3969} 3970``` 3971 3972### remoteQuery 3973 3974remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string> , callback: AsyncCallback<ResultSet>): void 3975 3976Queries data from the RDB store of a remote device based on specified conditions. This API uses an asynchronous callback to return the result. 3977 3978> **NOTE** 3979> 3980> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 3981 3982**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3983 3984**Parameters** 3985 3986| Name | Type | Mandatory| Description | 3987| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- | 3988| device | string | Yes | ID of the remote device. | 3989| table | string | Yes | Name of the target table. | 3990| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 3991| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | 3992| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 3993 3994**Error codes** 3995 3996For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 3997 3998| **ID**| **Error Message** | 3999|-----------| ------------------------------------------------------------ | 4000| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4001| 801 | Capability not supported. | 4002| 14800000 | Inner error. | 4003| 14800014 | Already closed. | 4004 4005**Example** 4006 4007```ts 4008import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 4009import { BusinessError } from '@kit.BasicServicesKit'; 4010 4011let dmInstance: distributedDeviceManager.DeviceManager; 4012let deviceId: string | undefined = undefined; 4013 4014try { 4015 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 4016 let devices = dmInstance.getAvailableDeviceListSync(); 4017 if (deviceId != undefined) { 4018 deviceId = devices[0].networkId; 4019 } 4020} catch (err) { 4021 let code = (err as BusinessError).code; 4022 let message = (err as BusinessError).message; 4023 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 4024} 4025 4026let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 4027predicates.greaterThan("id", 0); 4028if (store != undefined && deviceId != undefined) { 4029 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 4030 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4031 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4032 while (resultSet.goToNextRow()) { 4033 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4034 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4035 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4036 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4037 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4038 } 4039 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4040 resultSet.close(); 4041 }).catch((err: BusinessError) => { 4042 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 4043 }) 4044} 4045``` 4046 4047### remoteQuery 4048 4049remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string>): Promise<ResultSet> 4050 4051Queries data from the RDB store of a remote device based on specified conditions. This API uses a promise to return the result. 4052 4053> **NOTE** 4054> 4055> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 4056 4057**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4058 4059**Parameters** 4060 4061| Name | Type | Mandatory| Description | 4062| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 4063| device | string | Yes | ID of the remote device. | 4064| table | string | Yes | Name of the target table. | 4065| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 4066| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns.| 4067 4068**Return value** 4069 4070| Type | Description | 4071| ------------------------------------------------------------ | -------------------------------------------------- | 4072| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 4073 4074**Error codes** 4075 4076For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4077 4078| **ID**| **Error Message** | 4079|-----------| ------------------------------------------------------------ | 4080| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4081| 801 | Capability not supported. | 4082| 14800000 | Inner error. | 4083| 14800014 | Already closed. | 4084 4085**Example** 4086 4087```ts 4088import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 4089import { BusinessError } from '@kit.BasicServicesKit'; 4090 4091let dmInstance: distributedDeviceManager.DeviceManager; 4092let deviceId: string | undefined = undefined; 4093 4094try { 4095 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 4096 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 4097 if (devices != undefined) { 4098 deviceId = devices[0].networkId; 4099 } 4100} catch (err) { 4101 let code = (err as BusinessError).code; 4102 let message = (err as BusinessError).message; 4103 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 4104} 4105 4106let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 4107predicates.greaterThan("id", 0); 4108if (store != undefined && deviceId != undefined) { 4109 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 4110 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4111 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4112 while (resultSet.goToNextRow()) { 4113 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4114 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4115 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4116 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4117 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4118 } 4119 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4120 resultSet.close(); 4121 }).catch((err: BusinessError) => { 4122 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 4123 }) 4124} 4125``` 4126 4127### querySql<sup>10+</sup> 4128 4129querySql(sql: string, callback: AsyncCallback<ResultSet>):void 4130 4131Queries 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. 4132 4133[Vector stores](#storeconfig) support standard syntax including **where**, **limit**, **offset**, **order by**, **group by**, and **having**, as well as extended syntax like **<->** (computing similarity) and **<=>** (computing cosine distance). This API can be used in aggregate functions (**max** and **min**), but cannot be used in aggregate functions like **sum**, **avg**, and **count** or basic functions (**random**, **abs**, **upper**, **lower**, and **length**). 4134 4135Aggregate functions cannot be nested. 4136 4137**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4138 4139**Parameters** 4140 4141| Name | Type | Mandatory| Description | 4142| -------- | -------------------------------------------- | ---- |---------------------------------------| 4143| sql | string | Yes | SQL statement to run. | 4144| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 4145 4146**Error codes** 4147 4148For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4149 4150| **ID**| **Error Message** | 4151|-----------| ------------------------------------------------------------ | 4152| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4153| 14800000 | Inner error. | 4154| 14800014 | Already closed. | 4155| 14800015 | The database does not respond. | 4156 4157**Example** 4158 4159RDB store: 4160 4161```ts 4162if (store != undefined) { 4163 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'", (err, resultSet) => { 4164 if (err) { 4165 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4166 return; 4167 } 4168 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4169 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4170 while (resultSet.goToNextRow()) { 4171 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4172 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4173 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4174 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4175 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4176 } 4177 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4178 resultSet.close(); 4179 }) 4180} 4181``` 4182 4183Vector store: 4184 4185```ts 4186// <-> means to calculate vector similarity, and <=> means to calculate the cosine distance. 4187const querySql = "select id, repr <-> '[1.5,5.6]' as distance from test ORDER BY repr <-> '[1.5,5.6]' limit 10 offset 1;"; 4188let resultSet = await store.querySql(querySql); 4189 4190// Aggregate query. GROUP BY supports multiple columns. 4191const querySql1 = "select id, repr from test group by id, repr having max(repr<=>[1.5,5.6]);"; 4192let resultSet1 = await store.querySql(querySql1); 4193 4194// Subquery. A maximum of 32 nested layers are supported. 4195const querySql2 = "select * from test where id in (select id from test1)"; 4196let resultSet2 = await store.querySql(querySql2); 4197``` 4198 4199### querySql 4200 4201querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void 4202 4203Queries 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. 4204 4205[Vector stores](#storeconfig) support standard syntax including **where**, **limit**, **offset**, **order by**, **group by**, and **having**, as well as extended syntax like **<->** (computing similarity) and **<=>** (computing cosine distance). This API can be used in aggregate functions (**max** and **min**), but cannot be used in aggregate functions like **sum**, **avg**, and **count** or basic functions (**random**, **abs**, **upper**, **lower**, and **length**). 4206 4207Aggregate functions cannot be nested. 4208 4209**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4210 4211**Parameters** 4212 4213| Name | Type | Mandatory| Description | 4214| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | 4215| sql | string | Yes | SQL statement to run. | 4216| 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.| 4217| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback used to return the result. If the operation is successful, a **ResultSet** object will be returned. | 4218 4219**Error codes** 4220 4221For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4222 4223| **ID**| **Error Message** | 4224|-----------| ------------------------------------------------------------ | 4225| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4226| 14800000 | Inner error. | 4227| 14800014 | Already closed. | 4228| 14800015 | The database does not respond. | 4229 4230**Example** 4231 4232```ts 4233if (store != undefined) { 4234 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], (err, resultSet) => { 4235 if (err) { 4236 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4237 return; 4238 } 4239 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4240 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4241 while (resultSet.goToNextRow()) { 4242 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4243 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4244 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4245 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4246 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4247 } 4248 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4249 resultSet.close(); 4250 }) 4251} 4252``` 4253 4254### querySql 4255 4256querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> 4257 4258Queries 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. 4259 4260[Vector stores](#storeconfig) support standard syntax including **where**, **limit**, **offset**, **order by**, **group by**, and **having**, as well as extended syntax like **<->** (computing similarity) and **<=>** (computing cosine distance). This API can be used in aggregate functions (**max** and **min**), but cannot be used in aggregate functions like **sum**, **avg**, and **count** or basic functions (**random**, **abs**, **upper**, **lower**, and **length**). 4261 4262Aggregate functions cannot be nested. 4263 4264**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4265 4266**Parameters** 4267 4268| Name | Type | Mandatory| Description | 4269| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4270| sql | string | Yes | SQL statement to run. | 4271| 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.| 4272 4273**Return value** 4274 4275| Type | Description | 4276| ------------------------------------------------------- | -------------------------------------------------- | 4277| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 4278 4279**Error codes** 4280 4281For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4282 4283| **ID**| **Error Message** | 4284|-----------| ------------------------------------------------------------ | 4285| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4286| 14800000 | Inner error. | 4287| 14800014 | Already closed. | 4288| 14800015 | The database does not respond. | 4289 4290**Example** 4291 4292RDB store: 4293 4294```ts 4295import { BusinessError } from '@kit.BasicServicesKit'; 4296 4297if (store != undefined) { 4298 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then((resultSet: relationalStore.ResultSet) => { 4299 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4300 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4301 while (resultSet.goToNextRow()) { 4302 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4303 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4304 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4305 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4306 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4307 } 4308 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4309 resultSet.close(); 4310 }).catch((err: BusinessError) => { 4311 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4312 }) 4313} 4314``` 4315 4316Vector store: 4317 4318```ts 4319// 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. 4320const querySql = "select id, repr <-> ? as distance from test where id = ? and repr <-> ? < 0.5 ORDER BY repr <-> ? limit 10;"; 4321const vectorValue: Float32Array = new Float32Array([1.5, 2.5]); 4322let resultSet = await store.querySql(querySql, [vectorValue, 1, vectorValue, vectorValue]); 4323``` 4324 4325### querySqlSync<sup>12+</sup> 4326 4327querySqlSync(sql: string, bindArgs?: Array<ValueType>):ResultSet 4328 4329Queries 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. 4330 4331**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4332 4333**Parameters** 4334 4335| Name | Type | Mandatory| Description | 4336| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4337| sql | string | Yes | SQL statement to run. | 4338| 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.| 4339 4340**Return value** 4341 4342| Type | Description | 4343| ----------------------- | ----------------------------------- | 4344| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 4345 4346**Error codes** 4347 4348For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 4349 4350| **ID**| **Error Message** | 4351| ------------ | ------------------------------------------------------------ | 4352| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4353| 14800000 | Inner error. | 4354| 14800014 | Already closed. | 4355| 14800015 | The database does not respond. | 4356 4357**Example** 4358 4359```ts 4360import { BusinessError } from '@kit.BasicServicesKit'; 4361 4362if (store != undefined) { 4363 try { 4364 let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'"); 4365 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4366 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 4367 while (resultSet.goToNextRow()) { 4368 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4369 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4370 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4371 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4372 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4373 } 4374 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 4375 resultSet.close(); 4376 } catch (err) { 4377 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4378 } 4379} 4380``` 4381 4382### executeSql<sup>10+</sup> 4383 4384executeSql(sql: string, callback: AsyncCallback<void>):void 4385 4386Executes 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. 4387 4388This 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). 4389 4390Statements separated by semicolons (\;) are not supported. 4391 4392**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4393 4394**Parameters** 4395 4396| Name | Type | Mandatory| Description | 4397| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4398| sql | string | Yes | SQL statement to run. | 4399| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4400 4401**Error codes** 4402 4403For 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). 4404 4405| **ID**| **Error Message** | 4406|-----------| ------------------------------------------------------------ | 4407| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4408| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4409| 14800000 | Inner error. | 4410| 14800011 | Database corrupted. | 4411| 14800014 | Already closed. | 4412| 14800015 | The database does not respond. | 4413| 14800021 | SQLite: Generic error. | 4414| 14800022 | SQLite: Callback routine requested an abort. | 4415| 14800023 | SQLite: Access permission denied. | 4416| 14800024 | SQLite: The database file is locked. | 4417| 14800025 | SQLite: A table in the database is locked. | 4418| 14800026 | SQLite: The database is out of memory. | 4419| 14800027 | SQLite: Attempt to write a readonly database. | 4420| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4421| 14800029 | SQLite: The database is full. | 4422| 14800030 | SQLite: Unable to open the database file. | 4423| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4424| 14800032 | SQLite: Abort due to constraint violation. | 4425| 14800033 | SQLite: Data type mismatch. | 4426| 14800034 | SQLite: Library used incorrectly. | 4427| 14800047 | The WAL file size exceeds the default limit. | 4428 4429**Example** 4430 4431```ts 4432const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" 4433if (store != undefined) { 4434 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, (err) => { 4435 if (err) { 4436 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4437 return; 4438 } 4439 console.info('Delete table done.'); 4440 }) 4441} 4442``` 4443 4444### executeSql 4445 4446executeSql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<void>):void 4447 4448Executes 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. 4449 4450This 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). 4451 4452Statements separated by semicolons (\;) are not supported. 4453 4454**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4455 4456**Parameters** 4457 4458| Name | Type | Mandatory| Description | 4459| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4460| sql | string | Yes | SQL statement to run. | 4461| 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.| 4462| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4463 4464**Error codes** 4465 4466For 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). 4467 4468| **ID**| **Error Message** | 4469|-----------| ------------------------------------------------------------ | 4470| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4471| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4472| 14800000 | Inner error. | 4473| 14800011 | Database corrupted. | 4474| 14800014 | Already closed. | 4475| 14800015 | The database does not respond. | 4476| 14800021 | SQLite: Generic error. | 4477| 14800022 | SQLite: Callback routine requested an abort. | 4478| 14800023 | SQLite: Access permission denied. | 4479| 14800024 | SQLite: The database file is locked. | 4480| 14800025 | SQLite: A table in the database is locked. | 4481| 14800026 | SQLite: The database is out of memory. | 4482| 14800027 | SQLite: Attempt to write a readonly database. | 4483| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4484| 14800029 | SQLite: The database is full. | 4485| 14800030 | SQLite: Unable to open the database file. | 4486| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4487| 14800032 | SQLite: Abort due to constraint violation. | 4488| 14800033 | SQLite: Data type mismatch. | 4489| 14800034 | SQLite: Library used incorrectly. | 4490| 14800047 | The WAL file size exceeds the default limit. | 4491 4492**Example** 4493 4494```ts 4495const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?" 4496if (store != undefined) { 4497 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, ['zhangsan'], (err) => { 4498 if (err) { 4499 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4500 return; 4501 } 4502 console.info('Delete table done.'); 4503 }) 4504} 4505``` 4506 4507### executeSql 4508 4509executeSql(sql: string, bindArgs?: Array<ValueType>):Promise<void> 4510 4511Executes 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. 4512 4513This 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). 4514 4515Statements separated by semicolons (\;) are not supported. 4516 4517**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4518 4519**Parameters** 4520 4521| Name | Type | Mandatory| Description | 4522| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4523| sql | string | Yes | SQL statement to run. | 4524| 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.| 4525 4526**Return value** 4527 4528| Type | Description | 4529| ------------------- | ------------------------- | 4530| Promise<void> | Promise that returns no value.| 4531 4532**Error codes** 4533 4534For 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). 4535 4536| **ID**| **Error Message** | 4537|-----------| ------------------------------------------------------------ | 4538| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4539| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4540| 14800000 | Inner error. | 4541| 14800011 | Database corrupted. | 4542| 14800014 | Already closed. | 4543| 14800015 | The database does not respond. | 4544| 14800021 | SQLite: Generic error. | 4545| 14800022 | SQLite: Callback routine requested an abort. | 4546| 14800023 | SQLite: Access permission denied. | 4547| 14800024 | SQLite: The database file is locked. | 4548| 14800025 | SQLite: A table in the database is locked. | 4549| 14800026 | SQLite: The database is out of memory. | 4550| 14800027 | SQLite: Attempt to write a readonly database. | 4551| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4552| 14800029 | SQLite: The database is full. | 4553| 14800030 | SQLite: Unable to open the database file. | 4554| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4555| 14800032 | SQLite: Abort due to constraint violation. | 4556| 14800033 | SQLite: Data type mismatch. | 4557| 14800034 | SQLite: Library used incorrectly. | 4558| 14800047 | The WAL file size exceeds the default limit. | 4559 4560**Example** 4561 4562```ts 4563import { BusinessError } from '@kit.BasicServicesKit'; 4564 4565const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" 4566if (store != undefined) { 4567 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE).then(() => { 4568 console.info('Delete table done.'); 4569 }).catch((err: BusinessError) => { 4570 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4571 }) 4572} 4573``` 4574 4575### execute<sup>12+</sup> 4576 4577execute(sql: string, args?: Array<ValueType>):Promise<ValueType> 4578 4579Executes 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. 4580 4581This 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. 4582 4583This 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). 4584 4585When 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. 4586 4587Statements separated by semicolons (\;) are not supported. 4588 4589**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4590 4591**Parameters** 4592 4593| Name | Type | Mandatory| Description | 4594| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4595| sql | string | Yes | SQL statement to run. | 4596| 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.| 4597 4598**Return value** 4599 4600| Type | Description | 4601| ------------------- | ------------------------- | 4602| Promise<[ValueType](#valuetype)> | Promise used to return the SQL execution result.| 4603 4604**Error codes** 4605 4606For 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). 4607 4608| **ID**| **Error Message** | 4609|-----------| ------------------------------------------------------------ | 4610| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4611| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4612| 14800000 | Inner error. | 4613| 14800011 | Database corrupted. | 4614| 14800014 | Already closed. | 4615| 14800015 | The database does not respond. | 4616| 14800021 | SQLite: Generic error. | 4617| 14800022 | SQLite: Callback routine requested an abort. | 4618| 14800023 | SQLite: Access permission denied. | 4619| 14800024 | SQLite: The database file is locked. | 4620| 14800025 | SQLite: A table in the database is locked. | 4621| 14800026 | SQLite: The database is out of memory. | 4622| 14800027 | SQLite: Attempt to write a readonly database. | 4623| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4624| 14800029 | SQLite: The database is full. | 4625| 14800030 | SQLite: Unable to open the database file. | 4626| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4627| 14800032 | SQLite: Abort due to constraint violation. | 4628| 14800033 | SQLite: Data type mismatch. | 4629| 14800034 | SQLite: Library used incorrectly. | 4630| 14800047 | The WAL file size exceeds the default limit. | 4631 4632**Example** 4633 4634RDB store: 4635 4636```ts 4637import { BusinessError } from '@kit.BasicServicesKit'; 4638 4639// Check the RDB store integrity. 4640if (store != undefined) { 4641 const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check'; 4642 (store as relationalStore.RdbStore).execute(SQL_CHECK_INTEGRITY).then((data) => { 4643 console.info(`check result: ${data}`); 4644 }).catch((err: BusinessError) => { 4645 console.error(`check failed, code is ${err.code}, message is ${err.message}`); 4646 }) 4647} 4648 4649// Delete all data from the table. 4650if (store != undefined) { 4651 const SQL_DELETE_TABLE = 'DELETE FROM test'; 4652 (store as relationalStore.RdbStore).execute(SQL_DELETE_TABLE).then((data) => { 4653 console.info(`delete result: ${data}`); 4654 }).catch((err: BusinessError) => { 4655 console.error(`delete failed, code is ${err.code}, message is ${err.message}`); 4656 }) 4657} 4658 4659// Delete a table. 4660if (store != undefined) { 4661 const SQL_DROP_TABLE = 'DROP TABLE test'; 4662 (store as relationalStore.RdbStore).execute(SQL_DROP_TABLE).then((data) => { 4663 console.info(`drop result: ${data}`); 4664 }).catch((err: BusinessError) => { 4665 console.error(`drop failed, code is ${err.code}, message is ${err.message}`); 4666 }) 4667} 4668``` 4669 4670Vector store: 4671 4672```ts 4673// FLOATVECTOR(2) is a vector property with a dimension of 2. The subsequent repr operation should be performed based on this dimension. 4674let createSql = "CREATE TABLE test (ID text PRIMARY KEY,REPR FLOATVECTOR(2));"; 4675// Create a table. 4676await store!.execute(createSql); 4677// Insert data using parameter binding. 4678let insertSql= "insert into test VALUES(?, ?);"; 4679const vectorValue: Float32Array = Float32Array.from([1.5, 6.6]); 4680await store!.execute(insertSql, [0, vectorValue]); 4681// Execute without using bound parameters. 4682await store!.execute("insert into test values(1, '[3.5, 1.8]');"); 4683``` 4684 4685### execute<sup>12+</sup> 4686 4687execute(sql: string, txId: number, args?: Array<ValueType>): Promise<ValueType> 4688 4689Executes 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. 4690 4691This 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. 4692 4693This API does not support data query. To query data, use [querySql](#querysql10). 4694 4695Statements separated by semicolons (\;) are not supported. 4696 4697**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4698 4699**Parameters** 4700 4701| Name | Type | Mandatory| Description | 4702| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4703| sql | string | Yes | SQL statement to run. | 4704| 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. | 4705| args | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If this parameter is left blank or set to **null** or **undefined**, the SQL statement is considered complete.| 4706 4707**Return value** 4708 4709| Type | Description | 4710| ------------------- | ------------------------- | 4711| Promise<[ValueType](#valuetype)> | Promise that returns **null**.| 4712 4713**Error codes** 4714 4715For 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). 4716 4717| **ID**| **Error Message** | 4718|-----------| ------------------------------------------------------------ | 4719| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4720| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4721| 14800000 | Inner error. | 4722| 14800011 | Database corrupted. | 4723| 14800014 | Already closed. | 4724| 14800015 | The database does not respond. | 4725| 14800021 | SQLite: Generic error. | 4726| 14800022 | SQLite: Callback routine requested an abort. | 4727| 14800023 | SQLite: Access permission denied. | 4728| 14800024 | SQLite: The database file is locked. | 4729| 14800025 | SQLite: A table in the database is locked. | 4730| 14800026 | SQLite: The database is out of memory. | 4731| 14800027 | SQLite: Attempt to write a readonly database. | 4732| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4733| 14800029 | SQLite: The database is full. | 4734| 14800030 | SQLite: Unable to open the database file. | 4735| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4736| 14800032 | SQLite: Abort due to constraint violation. | 4737| 14800033 | SQLite: Data type mismatch. | 4738| 14800034 | SQLite: Library used incorrectly. | 4739| 14800047 | The WAL file size exceeds the default limit. | 4740 4741**Example** 4742 4743```ts 4744import { BusinessError } from '@kit.BasicServicesKit'; 4745if (store != null) { 4746 let txId : number; 4747 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 4748 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 4749 .then(() => { 4750 (store as relationalStore.RdbStore).commit(txId); 4751 }) 4752 .catch((err: BusinessError) => { 4753 (store as relationalStore.RdbStore).rollback(txId) 4754 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 4755 }); 4756 }); 4757} 4758``` 4759 4760### executeSync<sup>12+</sup> 4761 4762executeSync(sql: string, args?: Array<ValueType>): ValueType 4763 4764Executes 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. 4765 4766This 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. 4767 4768This 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). 4769 4770Statements separated by semicolons (\;) are not supported. 4771 4772**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4773 4774**Parameters** 4775 4776| Name| Type | Mandatory| Description | 4777| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 4778| sql | string | Yes | SQL statement to run. | 4779| 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.| 4780 4781**Return value** 4782 4783| Type | Description | 4784| ----------------------- | ------------------- | 4785| [ValueType](#valuetype) | SQL execution result.| 4786 4787**Error codes** 4788 4789For 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). 4790 4791| **ID**| **Error Message** | 4792| ------------ | ------------------------------------------------------------ | 4793| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4794| 14800000 | Inner error. | 4795| 14800011 | Database corrupted. | 4796| 14800014 | Already closed. | 4797| 14800015 | The database does not respond. | 4798| 14800021 | SQLite: Generic error. | 4799| 14800022 | SQLite: Callback routine requested an abort. | 4800| 14800023 | SQLite: Access permission denied. | 4801| 14800024 | SQLite: The database file is locked. | 4802| 14800025 | SQLite: A table in the database is locked. | 4803| 14800026 | SQLite: The database is out of memory. | 4804| 14800027 | SQLite: Attempt to write a readonly database. | 4805| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4806| 14800029 | SQLite: The database is full. | 4807| 14800030 | SQLite: Unable to open the database file. | 4808| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4809| 14800032 | SQLite: Abort due to constraint violation. | 4810| 14800033 | SQLite: Data type mismatch. | 4811| 14800034 | SQLite: Library used incorrectly. | 4812| 14800047 | The WAL file size exceeds the default limit. | 4813 4814**Example** 4815 4816```ts 4817import { BusinessError } from '@kit.BasicServicesKit'; 4818 4819// Check the RDB store integrity. 4820if (store != undefined) { 4821 const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check'; 4822 try { 4823 let data = (store as relationalStore.RdbStore).executeSync(SQL_CHECK_INTEGRITY) 4824 console.info(`check result: ${data}`); 4825 } catch (err) { 4826 console.error(`check failed, code is ${err.code}, message is ${err.message}`); 4827 } 4828} 4829 4830// Delete all data from the table. 4831if (store != undefined) { 4832 const SQL_DELETE_TABLE = 'DELETE FROM test'; 4833 try { 4834 let data = (store as relationalStore.RdbStore).executeSync(SQL_DELETE_TABLE) 4835 console.info(`delete result: ${data}`); 4836 } catch (err) { 4837 console.error(`delete failed, code is ${err.code}, message is ${err.message}`); 4838 } 4839} 4840 4841// Delete a table. 4842if (store != undefined) { 4843 const SQL_DROP_TABLE = 'DROP TABLE test'; 4844 try { 4845 let data = (store as relationalStore.RdbStore).executeSync(SQL_DROP_TABLE) 4846 console.info(`drop result: ${data}`); 4847 } catch (err) { 4848 console.error(`drop failed, code is ${err.code}, message is ${err.message}`); 4849 } 4850} 4851``` 4852 4853### getModifyTime<sup>10+</sup> 4854 4855getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[], callback: AsyncCallback<ModifyTime>): void 4856 4857Obtains the last modification time of the data in a table. This API uses an asynchronous callback to return the result. 4858 4859**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4860 4861**Parameters** 4862 4863| Name | Type | Mandatory| Description | 4864| ----------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 4865| table | string | Yes | Name of the database table to query. | 4866| columnName | string | Yes | Column name of the database table to query. | 4867| 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.| 4868| callback | AsyncCallback<[ModifyTime](#modifytime10)> | Yes | Callback used to return the result. If the operation is successful, the **ModifyTime** object is returned.| 4869 4870**Error codes** 4871 4872For 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). 4873 4874| **ID**| **Error Message** | 4875|-----------| ------------------------------------------------------------ | 4876| 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. | 4877| 801 | Capability not supported. | 4878| 14800000 | Inner error. | 4879| 14800011 | Database corrupted. | 4880| 14800014 | Already closed. | 4881| 14800015 | The database does not respond. | 4882| 14800021 | SQLite: Generic error. | 4883| 14800022 | SQLite: Callback routine requested an abort. | 4884| 14800023 | SQLite: Access permission denied. | 4885| 14800024 | SQLite: The database file is locked. | 4886| 14800025 | SQLite: A table in the database is locked. | 4887| 14800026 | SQLite: The database is out of memory. | 4888| 14800027 | SQLite: Attempt to write a readonly database. | 4889| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4890| 14800029 | SQLite: The database is full. | 4891| 14800030 | SQLite: Unable to open the database file. | 4892| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4893| 14800032 | SQLite: Abort due to constraint violation. | 4894| 14800033 | SQLite: Data type mismatch. | 4895| 14800034 | SQLite: Library used incorrectly. | 4896 4897**Example** 4898 4899```ts 4900let PRIKey = [1, 4, 2, 3]; 4901if (store != undefined) { 4902 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey, (err, modifyTime: relationalStore.ModifyTime) => { 4903 if (err) { 4904 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 4905 return; 4906 } 4907 let size = modifyTime.size; 4908 }); 4909} 4910``` 4911 4912### getModifyTime<sup>10+</sup> 4913 4914getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[]): Promise<ModifyTime> 4915 4916Obtains the last modification time of the data in a table. This API uses a promise to return the result. 4917 4918**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4919 4920**Parameters** 4921 4922| Name | Type | Mandatory| Description | 4923| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ | 4924| table | string | Yes | Name of the database table to query. | 4925| columnName | string | Yes | Column name of the database table to query. | 4926| 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.| 4927 4928**Return value** 4929 4930| Type | Description | 4931| ------------------------------------------ | --------------------------------------------------------- | 4932| Promise<[ModifyTime](#modifytime10)> | Promise used to return the **ModifyTime** object.| 4933 4934**Error codes** 4935 4936For 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). 4937 4938| **ID**| **Error Message** | 4939|-----------| ------------------------------------------------------------ | 4940| 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. | 4941| 801 | Capability not supported. | 4942| 14800000 | Inner error. | 4943| 14800011 | Database corrupted. | 4944| 14800014 | Already closed. | 4945| 14800015 | The database does not respond. | 4946| 14800021 | SQLite: Generic error. | 4947| 14800022 | SQLite: Callback routine requested an abort. | 4948| 14800023 | SQLite: Access permission denied. | 4949| 14800024 | SQLite: The database file is locked. | 4950| 14800025 | SQLite: A table in the database is locked. | 4951| 14800026 | SQLite: The database is out of memory. | 4952| 14800027 | SQLite: Attempt to write a readonly database. | 4953| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4954| 14800029 | SQLite: The database is full. | 4955| 14800030 | SQLite: Unable to open the database file. | 4956| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4957| 14800032 | SQLite: Abort due to constraint violation. | 4958| 14800033 | SQLite: Data type mismatch. | 4959| 14800034 | SQLite: Library used incorrectly. | 4960 4961**Example** 4962 4963```ts 4964import { BusinessError } from '@kit.BasicServicesKit'; 4965 4966let PRIKey = [1, 2, 3]; 4967if (store != undefined) { 4968 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey) 4969 .then((modifyTime: relationalStore.ModifyTime) => { 4970 let size = modifyTime.size; 4971 }) 4972 .catch((err: BusinessError) => { 4973 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 4974 }); 4975} 4976``` 4977 4978### beginTransaction 4979 4980beginTransaction():void 4981 4982Begins a transaction before executing an SQL statement. 4983This API does not allow nested transactions and cannot be used across processes or threads. 4984 4985**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4986 4987**Error codes** 4988 4989For 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). 4990 4991| **ID**| **Error Message** | 4992|-----------| ------------------------------------------------------------ | 4993| 401 | Parameter error. The store must not be nullptr. | 4994| 14800000 | Inner error. | 4995| 14800011 | Database corrupted. | 4996| 14800014 | Already closed. | 4997| 14800015 | The database does not respond. | 4998| 14800021 | SQLite: Generic error. | 4999| 14800022 | SQLite: Callback routine requested an abort. | 5000| 14800023 | SQLite: Access permission denied. | 5001| 14800024 | SQLite: The database file is locked. | 5002| 14800025 | SQLite: A table in the database is locked. | 5003| 14800026 | SQLite: The database is out of memory. | 5004| 14800027 | SQLite: Attempt to write a readonly database. | 5005| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5006| 14800029 | SQLite: The database is full. | 5007| 14800030 | SQLite: Unable to open the database file. | 5008| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5009| 14800032 | SQLite: Abort due to constraint violation. | 5010| 14800033 | SQLite: Data type mismatch. | 5011| 14800034 | SQLite: Library used incorrectly. | 5012| 14800047 | The WAL file size exceeds the default limit. | 5013 5014**Example** 5015 5016```ts 5017 5018let value1 = "Lisa"; 5019let value2 = 18; 5020let value3 = 100.5; 5021let value4 = new Uint8Array([1, 2, 3]); 5022 5023if (store != undefined) { 5024 (store as relationalStore.RdbStore).beginTransaction(); 5025 const valueBucket: relationalStore.ValuesBucket = { 5026 'NAME': value1, 5027 'AGE': value2, 5028 'SALARY': value3, 5029 'CODES': value4, 5030 }; 5031 (store as relationalStore.RdbStore).insert("test", valueBucket); 5032 (store as relationalStore.RdbStore).commit(); 5033} 5034``` 5035 5036### beginTrans<sup>12+</sup> 5037 5038beginTrans(): Promise<number> 5039 5040Begins a transaction before executing the SQL statement. This API uses a promise to return the result. 5041 5042Different from [beginTransaction](#begintransaction), this API returns a transaction ID. [execute](#execute12-1) can specify the transaction ID to isolate different transactions. 5043 5044This API supports only [vector stores](#storeconfig). 5045 5046**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5047 5048**Return value** 5049 5050| Type | Description | 5051| ------------------- | ------------------------- | 5052| Promise<number> | Promise used to return the transaction ID.| 5053 5054**Error codes** 5055 5056For 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). 5057 5058| **ID**| **Error Message** | 5059|-----------| ------------------------------------------------------------ | 5060| 401 | Parameter error. The store must not be nullptr. | 5061| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 5062| 14800000 | Inner error. | 5063| 14800011 | Database corrupted. | 5064| 14800014 | Already closed. | 5065| 14800015 | The database does not respond. | 5066| 14800021 | SQLite: Generic error. | 5067| 14800022 | SQLite: Callback routine requested an abort. | 5068| 14800023 | SQLite: Access permission denied. | 5069| 14800024 | SQLite: The database file is locked. | 5070| 14800025 | SQLite: A table in the database is locked. | 5071| 14800026 | SQLite: The database is out of memory. | 5072| 14800027 | SQLite: Attempt to write a readonly database. | 5073| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5074| 14800029 | SQLite: The database is full. | 5075| 14800030 | SQLite: Unable to open the database file. | 5076| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5077| 14800032 | SQLite: Abort due to constraint violation. | 5078| 14800033 | SQLite: Data type mismatch. | 5079| 14800034 | SQLite: Library used incorrectly. | 5080| 14800047 | The WAL file size exceeds the default limit. | 5081 5082**Example** 5083 5084```ts 5085import { BusinessError } from '@kit.BasicServicesKit'; 5086if (store != null) { 5087 let txId : number; 5088 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 5089 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 5090 .then(() => { 5091 (store as relationalStore.RdbStore).commit(txId); 5092 }) 5093 .catch((err: BusinessError) => { 5094 (store as relationalStore.RdbStore).rollback(txId) 5095 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 5096 }); 5097 }); 5098} 5099``` 5100 5101### createTransaction<sup>14+</sup> 5102 5103createTransaction(options?: TransactionOptions): Promise<Transaction> 5104 5105Creates a transaction object and starts a transaction. This API uses a promise to return the result. 5106 5107Different 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). 5108 5109A 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. 5110 5111You are advised to use **createTransaction** instead of **beginTransaction**. 5112 5113**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5114 5115**Parameters** 5116 5117| Name | Type | Mandatory| Description | 5118| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ | 5119| options | [TransactionOptions](#transactionoptions14) | No | Configuration of the transaction object to create. | 5120 5121**Return value** 5122 5123| Type | Description | 5124| ------------------- | ------------------------- | 5125| Promise<[Transaction](#transaction14)> | Promise used to return the transaction object created.| 5126 5127**Error codes** 5128 5129For 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). 5130 5131| **ID**| **Error Message** | 5132|-----------| ------------------------------------------------------------ | 5133| 14800000 | Inner error. | 5134| 14800011 | Database corrupted. | 5135| 14800014 | Already closed. | 5136| 14800015 | The database is busy. | 5137| 14800023 | SQLite: Access permission denied. | 5138| 14800024 | SQLite: The database file is locked. | 5139| 14800026 | SQLite: The database is out of memory. | 5140| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5141| 14800029 | SQLite: The database is full. | 5142| 14800030 | SQLite: Unable to open the database file. | 5143 5144**Example** 5145 5146```ts 5147import { BusinessError } from '@kit.BasicServicesKit'; 5148 5149if (store != undefined) { 5150 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 5151 transaction.execute("DELETE FROM test WHERE age = ? OR age = ?", [21, 20]).then(() => { 5152 transaction.commit(); 5153 }).catch((e: BusinessError) => { 5154 transaction.rollback(); 5155 console.error(`execute sql failed, code is ${e.code},message is ${e.message}`); 5156 }); 5157 }).catch((err: BusinessError) => { 5158 console.error(`createTransaction faided, code is ${err.code},message is ${err.message}`); 5159 }); 5160} 5161``` 5162 5163### commit 5164 5165commit():void 5166 5167Commits the executed SQL statement. This API must be used with [beginTransaction](#begintransaction). 5168This API does not allow nested transactions and cannot be used across processes or threads. 5169 5170**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5171 5172**Error codes** 5173 5174For 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). 5175 5176| **ID**| **Error Message** | 5177|-----------| ------------------------------------------------------------ | 5178| 401 | Parameter error. The store must not be nullptr. | 5179| 14800000 | Inner error. | 5180| 14800011 | Database corrupted. | 5181| 14800014 | Already closed. | 5182| 14800015 | The database does not respond. | 5183| 14800021 | SQLite: Generic error. | 5184| 14800022 | SQLite: Callback routine requested an abort. | 5185| 14800023 | SQLite: Access permission denied. | 5186| 14800024 | SQLite: The database file is locked. | 5187| 14800025 | SQLite: A table in the database is locked. | 5188| 14800026 | SQLite: The database is out of memory. | 5189| 14800027 | SQLite: Attempt to write a readonly database. | 5190| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5191| 14800029 | SQLite: The database is full. | 5192| 14800030 | SQLite: Unable to open the database file. | 5193| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5194| 14800032 | SQLite: Abort due to constraint violation. | 5195| 14800033 | SQLite: Data type mismatch. | 5196| 14800034 | SQLite: Library used incorrectly. | 5197 5198**Example** 5199 5200```ts 5201 5202let value1 = "Lisa"; 5203let value2 = 18; 5204let value3 = 100.5; 5205let value4 = new Uint8Array([1, 2, 3]); 5206 5207if (store != undefined) { 5208 (store as relationalStore.RdbStore).beginTransaction(); 5209 const valueBucket: relationalStore.ValuesBucket = { 5210 'NAME': value1, 5211 'AGE': value2, 5212 'SALARY': value3, 5213 'CODES': value4, 5214 }; 5215 (store as relationalStore.RdbStore).insert("test", valueBucket); 5216 (store as relationalStore.RdbStore).commit(); 5217} 5218``` 5219 5220### commit<sup>12+</sup> 5221 5222commit(txId : number):Promise<void> 5223 5224Commits the executed SQL statement. This API must be used with [beginTrans](#begintrans12). 5225 5226This API supports only [vector stores](#storeconfig). 5227 5228**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5229 5230**Parameters** 5231 5232| Name | Type | Mandatory| Description | 5233| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 5234| txId | number | Yes | Transaction ID obtained via [beginTrans](#begintrans12). | 5235 5236**Return value** 5237 5238| Type | Description | 5239| ------------------- | ------------------------- | 5240| Promise<void> | Promise that returns no value.| 5241 5242**Error codes** 5243 5244For 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). 5245 5246| **ID**| **Error Message** | 5247|-----------| ------------------------------------------------------------ | 5248| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5249| 14800000 | Inner error. | 5250| 14800011 | Database corrupted. | 5251| 14800014 | Already closed. | 5252| 14800015 | The database does not respond. | 5253| 14800021 | SQLite: Generic error. | 5254| 14800022 | SQLite: Callback routine requested an abort. | 5255| 14800023 | SQLite: Access permission denied. | 5256| 14800024 | SQLite: The database file is locked. | 5257| 14800025 | SQLite: A table in the database is locked. | 5258| 14800026 | SQLite: The database is out of memory. | 5259| 14800027 | SQLite: Attempt to write a readonly database. | 5260| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5261| 14800029 | SQLite: The database is full. | 5262| 14800030 | SQLite: Unable to open the database file. | 5263| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5264| 14800032 | SQLite: Abort due to constraint violation. | 5265| 14800033 | SQLite: Data type mismatch. | 5266| 14800034 | SQLite: Library used incorrectly. | 5267 5268**Example** 5269 5270```ts 5271import { BusinessError } from '@kit.BasicServicesKit'; 5272if (store != null) { 5273 let txId : number; 5274 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 5275 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 5276 .then(() => { 5277 (store as relationalStore.RdbStore).commit(txId); 5278 }) 5279 .catch((err: BusinessError) => { 5280 (store as relationalStore.RdbStore).rollback(txId) 5281 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 5282 }); 5283 }); 5284} 5285``` 5286 5287### rollBack 5288 5289rollBack():void 5290 5291Rolls back the executed SQL statement. 5292This API does not allow nested transactions and cannot be used across processes or threads. 5293 5294**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5295 5296**Error codes** 5297 5298For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 5299 5300| **ID**| **Error Message** | 5301|-----------| ------------------------------------------------------------ | 5302| 401 | Parameter error. The store must not be nullptr. | 5303| 14800000 | Inner error. | 5304| 14800011 | Database corrupted. | 5305| 14800014 | Already closed. | 5306| 14800015 | The database does not respond. | 5307| 14800021 | SQLite: Generic error. | 5308| 14800022 | SQLite: Callback routine requested an abort. | 5309| 14800023 | SQLite: Access permission denied. | 5310| 14800024 | SQLite: The database file is locked. | 5311| 14800025 | SQLite: A table in the database is locked. | 5312| 14800026 | SQLite: The database is out of memory. | 5313| 14800027 | SQLite: Attempt to write a readonly database. | 5314| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5315| 14800029 | SQLite: The database is full. | 5316| 14800030 | SQLite: Unable to open the database file. | 5317| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5318| 14800032 | SQLite: Abort due to constraint violation. | 5319| 14800033 | SQLite: Data type mismatch. | 5320| 14800034 | SQLite: Library used incorrectly. | 5321 5322**Example** 5323 5324```ts 5325import { BusinessError } from '@kit.BasicServicesKit'; 5326 5327let value1 = "Lisa"; 5328let value2 = 18; 5329let value3 = 100.5; 5330let value4 = new Uint8Array([1, 2, 3]); 5331 5332if (store != undefined) { 5333 try { 5334 (store as relationalStore.RdbStore).beginTransaction() 5335 const valueBucket: relationalStore.ValuesBucket = { 5336 'NAME': value1, 5337 'AGE': value2, 5338 'SALARY': value3, 5339 'CODES': value4, 5340 }; 5341 (store as relationalStore.RdbStore).insert("test", valueBucket); 5342 (store as relationalStore.RdbStore).commit(); 5343 } catch (err) { 5344 let code = (err as BusinessError).code; 5345 let message = (err as BusinessError).message 5346 console.error(`Transaction failed, code is ${code},message is ${message}`); 5347 (store as relationalStore.RdbStore).rollBack(); 5348 } 5349} 5350``` 5351 5352### rollback<sup>12+</sup> 5353 5354rollback(txId : number):Promise<void> 5355 5356Rolls back the executed SQL statement. This API must be used with [beginTrans](#begintrans12). 5357 5358This API supports only [vector stores](#storeconfig). 5359 5360**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5361 5362**Parameters** 5363 5364| Name | Type | Mandatory| Description | 5365| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 5366| txId | number | Yes | Transaction ID obtained via [beginTrans](#begintrans12). | 5367 5368**Return value** 5369 5370| Type | Description | 5371| ------------------- | ------------------------- | 5372| Promise<void> | Promise that returns no value.| 5373 5374**Error codes** 5375 5376For 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). 5377 5378| **ID**| **Error Message** | 5379|-----------| ------------------------------------------------------------ | 5380| 401 | Parameter error. The store must not be nullptr. | 5381| 14800000 | Inner error. | 5382| 14800011 | Database corrupted. | 5383| 14800014 | Already closed. | 5384| 14800015 | The database does not respond. | 5385| 14800021 | SQLite: Generic error. | 5386| 14800022 | SQLite: Callback routine requested an abort. | 5387| 14800023 | SQLite: Access permission denied. | 5388| 14800024 | SQLite: The database file is locked. | 5389| 14800025 | SQLite: A table in the database is locked. | 5390| 14800026 | SQLite: The database is out of memory. | 5391| 14800027 | SQLite: Attempt to write a readonly database. | 5392| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5393| 14800029 | SQLite: The database is full. | 5394| 14800030 | SQLite: Unable to open the database file. | 5395| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5396| 14800032 | SQLite: Abort due to constraint violation. | 5397| 14800033 | SQLite: Data type mismatch. | 5398| 14800034 | SQLite: Library used incorrectly. | 5399 5400**Example** 5401 5402```ts 5403import { BusinessError } from '@kit.BasicServicesKit'; 5404if (store != null) { 5405 let txId : number; 5406 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 5407 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 5408 .then(() => { 5409 (store as relationalStore.RdbStore).commit(txId); 5410 }) 5411 .catch((err: BusinessError) => { 5412 (store as relationalStore.RdbStore).rollback(txId) 5413 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 5414 }); 5415 }); 5416} 5417``` 5418 5419### backup 5420 5421backup(destName:string, callback: AsyncCallback<void>):void 5422 5423Backs up an RDB store. This API uses an asynchronous callback to return the result. 5424 5425**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5426 5427**Parameters** 5428 5429| Name | Type | Mandatory| Description | 5430| -------- | ------------------------- | ---- | ------------------------ | 5431| destName | string | Yes | Name of the RDB store backup file.| 5432| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5433 5434**Error codes** 5435 5436For 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). 5437 5438| **ID**| **Error Message** | 5439|-----------| ------------------------------------------------------------ | 5440| 401 | Parameter error. The store must not be nullptr. | 5441| 14800000 | Inner error. | 5442| 14800010 | Invalid database path. | 5443| 14800011 | Database corrupted. | 5444| 14800014 | Already closed. | 5445| 14800015 | The database does not respond. | 5446| 14800021 | SQLite: Generic error. | 5447| 14800022 | SQLite: Callback routine requested an abort. | 5448| 14800023 | SQLite: Access permission denied. | 5449| 14800024 | SQLite: The database file is locked. | 5450| 14800025 | SQLite: A table in the database is locked. | 5451| 14800026 | SQLite: The database is out of memory. | 5452| 14800027 | SQLite: Attempt to write a readonly database. | 5453| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5454| 14800029 | SQLite: The database is full. | 5455| 14800030 | SQLite: Unable to open the database file. | 5456| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5457| 14800032 | SQLite: Abort due to constraint violation. | 5458| 14800033 | SQLite: Data type mismatch. | 5459| 14800034 | SQLite: Library used incorrectly. | 5460 5461**Example** 5462 5463```ts 5464if (store != undefined) { 5465 (store as relationalStore.RdbStore).backup("dbBackup.db", (err) => { 5466 if (err) { 5467 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 5468 return; 5469 } 5470 console.info('Backup success.'); 5471 }) 5472} 5473``` 5474 5475### backup 5476 5477backup(destName:string): Promise<void> 5478 5479Backs up an RDB store. This API uses a promise to return the result. 5480 5481**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5482 5483**Parameters** 5484 5485| Name | Type | Mandatory| Description | 5486| -------- | ------ | ---- | ------------------------ | 5487| destName | string | Yes | Name of the RDB store backup file.| 5488 5489**Return value** 5490 5491| Type | Description | 5492| ------------------- | ------------------------- | 5493| Promise<void> | Promise that returns no value.| 5494 5495**Error codes** 5496 5497For 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). 5498 5499| **ID**| **Error Message** | 5500|-----------| ------------------------------------------------------------ | 5501| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5502| 14800000 | Inner error. | 5503| 14800011 | Database corrupted. | 5504| 14800014 | Already closed. | 5505| 14800015 | The database does not respond. | 5506| 14800021 | SQLite: Generic error. | 5507| 14800022 | SQLite: Callback routine requested an abort. | 5508| 14800023 | SQLite: Access permission denied. | 5509| 14800024 | SQLite: The database file is locked. | 5510| 14800025 | SQLite: A table in the database is locked. | 5511| 14800026 | SQLite: The database is out of memory. | 5512| 14800027 | SQLite: Attempt to write a readonly database. | 5513| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5514| 14800029 | SQLite: The database is full. | 5515| 14800030 | SQLite: Unable to open the database file. | 5516| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5517| 14800032 | SQLite: Abort due to constraint violation. | 5518| 14800033 | SQLite: Data type mismatch. | 5519| 14800034 | SQLite: Library used incorrectly. | 5520 5521**Example** 5522 5523```ts 5524import { BusinessError } from '@kit.BasicServicesKit'; 5525 5526if (store != undefined) { 5527 let promiseBackup = (store as relationalStore.RdbStore).backup("dbBackup.db"); 5528 promiseBackup.then(() => { 5529 console.info('Backup success.'); 5530 }).catch((err: BusinessError) => { 5531 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 5532 }) 5533} 5534``` 5535 5536### restore 5537 5538restore(srcName:string, callback: AsyncCallback<void>):void 5539 5540Restores an RDB store from a backup file. This API uses an asynchronous callback to return the result. 5541 5542**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5543 5544**Parameters** 5545 5546| Name | Type | Mandatory| Description | 5547| -------- | ------------------------- | ---- | ------------------------ | 5548| srcName | string | Yes | Name of the RDB store backup file.| 5549| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5550 5551**Error codes** 5552 5553For 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). 5554 5555| **ID**| **Error Message** | 5556|-----------| ------------------------------------------------------------ | 5557| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5558| 14800000 | Inner error. | 5559| 14800011 | Database corrupted. | 5560| 14800014 | Already closed. | 5561| 14800015 | The database does not respond. | 5562| 14800021 | SQLite: Generic error. | 5563| 14800022 | SQLite: Callback routine requested an abort. | 5564| 14800023 | SQLite: Access permission denied. | 5565| 14800024 | SQLite: The database file is locked. | 5566| 14800025 | SQLite: A table in the database is locked. | 5567| 14800026 | SQLite: The database is out of memory. | 5568| 14800027 | SQLite: Attempt to write a readonly database. | 5569| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5570| 14800029 | SQLite: The database is full. | 5571| 14800030 | SQLite: Unable to open the database file. | 5572| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5573| 14800032 | SQLite: Abort due to constraint violation. | 5574| 14800033 | SQLite: Data type mismatch. | 5575| 14800034 | SQLite: Library used incorrectly. | 5576 5577**Example** 5578 5579```ts 5580if (store != undefined) { 5581 (store as relationalStore.RdbStore).restore("dbBackup.db", (err) => { 5582 if (err) { 5583 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 5584 return; 5585 } 5586 console.info('Restore success.'); 5587 }) 5588} 5589``` 5590 5591### restore 5592 5593restore(srcName:string): Promise<void> 5594 5595Restores an RDB store from a backup file. This API uses a promise to return the result. 5596 5597**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5598 5599**Parameters** 5600 5601| Name | Type | Mandatory| Description | 5602| ------- | ------ | ---- | ------------------------ | 5603| srcName | string | Yes | Name of the RDB store backup file.| 5604 5605**Return value** 5606 5607| Type | Description | 5608| ------------------- | ------------------------- | 5609| Promise<void> | Promise that returns no value.| 5610 5611**Error codes** 5612 5613For 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). 5614 5615| **ID**| **Error Message** | 5616|-----------| ------------------------------------------------------------ | 5617| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5618| 14800000 | Inner error. | 5619| 14800011 | Database corrupted. | 5620| 14800014 | Already closed. | 5621| 14800015 | The database does not respond. | 5622| 14800021 | SQLite: Generic error. | 5623| 14800022 | SQLite: Callback routine requested an abort. | 5624| 14800023 | SQLite: Access permission denied. | 5625| 14800024 | SQLite: The database file is locked. | 5626| 14800025 | SQLite: A table in the database is locked. | 5627| 14800026 | SQLite: The database is out of memory. | 5628| 14800027 | SQLite: Attempt to write a readonly database. | 5629| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5630| 14800029 | SQLite: The database is full. | 5631| 14800030 | SQLite: Unable to open the database file. | 5632| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5633| 14800032 | SQLite: Abort due to constraint violation. | 5634| 14800033 | SQLite: Data type mismatch. | 5635| 14800034 | SQLite: Library used incorrectly. | 5636 5637**Example** 5638 5639```ts 5640import { BusinessError } from '@kit.BasicServicesKit'; 5641 5642if (store != undefined) { 5643 let promiseRestore = (store as relationalStore.RdbStore).restore("dbBackup.db"); 5644 promiseRestore.then(() => { 5645 console.info('Restore success.'); 5646 }).catch((err: BusinessError) => { 5647 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 5648 }) 5649} 5650``` 5651 5652### setDistributedTables 5653 5654setDistributedTables(tables: Array<string>, callback: AsyncCallback<void>): void 5655 5656Sets distributed tables. This API uses an asynchronous callback to return the result. 5657 5658**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5659 5660**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5661 5662**Parameters** 5663 5664| Name | Type | Mandatory| Description | 5665| -------- | ------------------------- | ---- | ---------------------- | 5666| tables | Array<string> | Yes | Names of the distributed tables to set.| 5667| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 5668 5669**Error codes** 5670 5671For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5672 5673| **ID**| **Error Message** | 5674|-----------| ------------------------------------------------------------ | 5675| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5676| 801 | Capability not supported. | 5677| 14800000 | Inner error. | 5678| 14800014 | Already closed. | 5679 5680**Example** 5681 5682```ts 5683if (store != undefined) { 5684 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], (err) => { 5685 if (err) { 5686 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5687 return; 5688 } 5689 console.info('SetDistributedTables successfully.'); 5690 }) 5691} 5692``` 5693 5694### setDistributedTables 5695 5696 setDistributedTables(tables: Array<string>): Promise<void> 5697 5698Sets distributed tables. This API uses a promise to return the result. 5699 5700**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5701 5702**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5703 5704**Parameters** 5705 5706| Name| Type | Mandatory| Description | 5707| ------ | ------------------------ | ---- | ------------------------ | 5708| tables | ArrayArray<string> | Yes | Names of the distributed tables to set.| 5709 5710**Return value** 5711 5712| Type | Description | 5713| ------------------- | ------------------------- | 5714| Promise<void> | Promise that returns no value.| 5715 5716**Error codes** 5717 5718For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5719 5720| **ID**| **Error Message** | 5721|-----------| ------------------------------------------------------------ | 5722| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5723| 801 | Capability not supported. | 5724| 14800000 | Inner error. | 5725| 14800014 | Already closed. | 5726 5727**Example** 5728 5729```ts 5730import { BusinessError } from '@kit.BasicServicesKit'; 5731 5732if (store != undefined) { 5733 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"]).then(() => { 5734 console.info('SetDistributedTables successfully.'); 5735 }).catch((err: BusinessError) => { 5736 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5737 }) 5738} 5739``` 5740 5741### setDistributedTables<sup>10+</sup> 5742 5743setDistributedTables(tables: Array<string>, type: DistributedType, callback: AsyncCallback<void>): void 5744 5745Sets distributed tables. This API uses an asynchronous callback to return the result. 5746 5747**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5748 5749**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5750 5751**Parameters** 5752 5753| Name | Type | Mandatory| Description | 5754| -------- | ------------------------------------- | ---- | ---------------------------- | 5755| tables | Array<string> | Yes | Names of the distributed tables to set.| 5756| type | [DistributedType](#distributedtype10) | Yes | Distributed type of the tables. | 5757| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 5758 5759**Error codes** 5760 5761For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5762 5763| **ID**| **Error Message** | 5764|-----------| ------------------------------------------------------------ | 5765| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5766| 801 | Capability not supported. | 5767| 14800000 | Inner error. | 5768| 14800014 | Already closed. | 5769| 14800051 | The type of the distributed table does not match. | 5770 5771**Example** 5772 5773```ts 5774if (store != undefined) { 5775 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, (err) => { 5776 if (err) { 5777 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5778 return; 5779 } 5780 console.info('SetDistributedTables successfully.'); 5781 }) 5782} 5783``` 5784 5785### setDistributedTables<sup>10+</sup> 5786 5787setDistributedTables(tables: Array<string>, type: DistributedType, config: DistributedConfig, callback: AsyncCallback<void>): void 5788 5789Sets distributed tables. This API uses an asynchronous callback to return the result. 5790 5791**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5792 5793**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5794 5795**Parameters** 5796 5797| Name | Type | Mandatory | Description | 5798| -------- | ----------------------------------- | --- | --------------- | 5799| tables | Array<string> | Yes | Names of the distributed tables to set. | 5800| type | [DistributedType](#distributedtype10) | Yes | Distributed type of the tables.| 5801| config | [DistributedConfig](#distributedconfig10) | Yes| Configuration of the distributed mode.| 5802| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 5803 5804**Error codes** 5805 5806For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5807 5808| **ID**| **Error Message** | 5809|-----------| ------------------------------------------------------------ | 5810| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5811| 801 | Capability not supported. | 5812| 14800000 | Inner error. | 5813| 14800014 | Already closed. | 5814| 14800051 | The type of the distributed table does not match. | 5815 5816**Example** 5817 5818```ts 5819if (store != undefined) { 5820 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 5821 autoSync: true 5822 }, (err) => { 5823 if (err) { 5824 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5825 return; 5826 } 5827 console.info('SetDistributedTables successfully.'); 5828 }) 5829} 5830``` 5831 5832### setDistributedTables<sup>10+</sup> 5833 5834 setDistributedTables(tables: Array<string>, type?: DistributedType, config?: DistributedConfig): Promise<void> 5835 5836Sets distributed tables. This API uses a promise to return the result. 5837 5838**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5839 5840**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5841 5842**Parameters** 5843 5844| Name| Type | Mandatory| Description | 5845| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ | 5846| tables | Array<string> | Yes | Names of the distributed tables to set. | 5847| type | [DistributedType](#distributedtype10) | No | Distributed type of the tables. <br>Default value: **relationalStore.DistributedType.DISTRIBUTED_DEVICE**.| 5848| 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.| 5849 5850**Return value** 5851 5852| Type | Description | 5853| ------------------- | ------------------------- | 5854| Promise<void> | Promise that returns no value.| 5855 5856**Error codes** 5857 5858For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5859 5860| **ID**| **Error Message** | 5861|-----------| ------------------------------------------------------------ | 5862| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5863| 801 | Capability not supported. | 5864| 14800000 | Inner error. | 5865| 14800014 | Already closed. | 5866| 14800051 | The type of the distributed table does not match. | 5867 5868**Example** 5869 5870```ts 5871import { BusinessError } from '@kit.BasicServicesKit'; 5872 5873if (store != undefined) { 5874 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 5875 autoSync: true 5876 }).then(() => { 5877 console.info('SetDistributedTables successfully.'); 5878 }).catch((err: BusinessError) => { 5879 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5880 }) 5881} 5882``` 5883 5884### obtainDistributedTableName 5885 5886obtainDistributedTableName(device: string, table: string, callback: AsyncCallback<string>): void 5887 5888Obtains 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. 5889 5890> **NOTE** 5891> 5892> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 5893 5894**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5895 5896**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5897 5898**Parameters** 5899 5900| Name | Type | Mandatory| Description | 5901| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 5902| device | string | Yes | ID of the remote device. | 5903| table | string | Yes | Local table name of the remote device. | 5904| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| 5905 5906**Error codes** 5907 5908For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5909 5910| **ID**| **Error Message** | 5911|-----------| ------------------------------------------------------------ | 5912| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5913| 801 | Capability not supported. | 5914| 14800000 | Inner error. | 5915| 14800014 | Already closed. | 5916 5917**Example** 5918 5919```ts 5920import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5921import { BusinessError } from '@kit.BasicServicesKit'; 5922 5923let dmInstance: distributedDeviceManager.DeviceManager; 5924let deviceId: string | undefined = undefined; 5925 5926try { 5927 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5928 let devices = dmInstance.getAvailableDeviceListSync(); 5929 deviceId = devices[0].networkId; 5930} catch (err) { 5931 let code = (err as BusinessError).code; 5932 let message = (err as BusinessError).message 5933 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5934} 5935 5936if (store != undefined && deviceId != undefined) { 5937 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE", (err, tableName) => { 5938 if (err) { 5939 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 5940 return; 5941 } 5942 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 5943 }) 5944} 5945``` 5946 5947### obtainDistributedTableName 5948 5949 obtainDistributedTableName(device: string, table: string): Promise<string> 5950 5951Obtains 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. 5952 5953> **NOTE** 5954> 5955> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 5956 5957**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 5958 5959**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5960 5961**Parameters** 5962 5963| Name| Type | Mandatory| Description | 5964| ------ | ------ | ---- | -------------------- | 5965| device | string | Yes | ID of the remote device. | 5966| table | string | Yes | Local table name of the remote device.| 5967 5968**Return value** 5969 5970| Type | Description | 5971| --------------------- | ----------------------------------------------------- | 5972| Promise<string> | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| 5973 5974**Error codes** 5975 5976For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 5977 5978| **ID**| **Error Message** | 5979|-----------| ------------------------------------------------------------ | 5980| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5981| 801 | Capability not supported. | 5982| 14800000 | Inner error. | 5983| 14800014 | Already closed. | 5984 5985**Example** 5986 5987```ts 5988import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5989import { BusinessError } from '@kit.BasicServicesKit'; 5990 5991let dmInstance: distributedDeviceManager.DeviceManager; 5992let deviceId: string | undefined = undefined; 5993 5994try { 5995 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5996 let devices = dmInstance.getAvailableDeviceListSync(); 5997 deviceId = devices[0].networkId; 5998} catch (err) { 5999 let code = (err as BusinessError).code; 6000 let message = (err as BusinessError).message 6001 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 6002} 6003 6004if (store != undefined && deviceId != undefined) { 6005 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE").then((tableName: string) => { 6006 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 6007 }).catch((err: BusinessError) => { 6008 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 6009 }) 6010} 6011``` 6012 6013### sync 6014 6015sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void 6016 6017Synchronizes data between devices. This API uses an asynchronous callback to return the result. 6018 6019**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 6020 6021**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6022 6023**Parameters** 6024 6025| Name | Type | Mandatory| Description | 6026| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ | 6027| mode | [SyncMode](#syncmode) | Yes | Data sync mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**. | 6028| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | 6029| 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. | 6030 6031**Error codes** 6032 6033For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6034 6035| **ID**| **Error Message** | 6036|-----------| ------------------------------------------------------------ | 6037| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6038| 801 | Capability not supported. | 6039| 14800000 | Inner error. | 6040| 14800014 | Already closed. | 6041 6042**Example** 6043 6044```ts 6045import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6046import { BusinessError } from '@kit.BasicServicesKit'; 6047 6048let dmInstance: distributedDeviceManager.DeviceManager; 6049let deviceIds: Array<string> = []; 6050 6051try { 6052 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 6053 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 6054 for (let i = 0; i < devices.length; i++) { 6055 deviceIds[i] = devices[i].networkId!; 6056 } 6057} catch (err) { 6058 let code = (err as BusinessError).code; 6059 let message = (err as BusinessError).message 6060 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 6061} 6062 6063let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 6064predicates.inDevices(deviceIds); 6065if (store != undefined) { 6066 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, (err, result) => { 6067 if (err) { 6068 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 6069 return; 6070 } 6071 console.info('Sync done.'); 6072 for (let i = 0; i < result.length; i++) { 6073 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 6074 } 6075 }) 6076} 6077``` 6078 6079### sync 6080 6081 sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>> 6082 6083Synchronizes data between devices. This API uses a promise to return the result. 6084 6085**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 6086 6087**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6088 6089**Parameters** 6090 6091| Name | Type | Mandatory| Description | 6092| ---------- | ------------------------------------ | ---- | ------------------------------ | 6093| mode | [SyncMode](#syncmode) | Yes | Data sync mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**.| 6094| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | 6095 6096**Return value** 6097 6098| Type | Description | 6099| -------------------------------------------- | ------------------------------------------------------------ | 6100| 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. | 6101 6102**Error codes** 6103 6104For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6105 6106| **ID**| **Error Message** | 6107|-----------| ------------------------------------------------------------ | 6108| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6109| 801 | Capability not supported. | 6110| 14800000 | Inner error. | 6111| 14800014 | Already closed. | 6112 6113**Example** 6114 6115```ts 6116import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6117import { BusinessError } from '@kit.BasicServicesKit'; 6118 6119let dmInstance: distributedDeviceManager.DeviceManager; 6120let deviceIds: Array<string> = []; 6121 6122try { 6123 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 6124 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 6125 for (let i = 0; i < devices.length; i++) { 6126 deviceIds[i] = devices[i].networkId!; 6127 } 6128} catch (err) { 6129 let code = (err as BusinessError).code; 6130 let message = (err as BusinessError).message 6131 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 6132} 6133 6134let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 6135predicates.inDevices(deviceIds); 6136if (store != undefined) { 6137 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates).then((result: Object[][]) => { 6138 console.info('Sync done.'); 6139 for (let i = 0; i < result.length; i++) { 6140 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 6141 } 6142 }).catch((err: BusinessError) => { 6143 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 6144 }) 6145} 6146``` 6147 6148### cloudSync<sup>10+</sup> 6149 6150cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 6151 6152Manually 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. 6153 6154**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6155 6156**Parameters** 6157 6158| Name | Type | Mandatory| Description | 6159| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6160| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 6161| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details. | 6162| callback | AsyncCallback<void> | Yes | Callback used to send the sync result to the caller.| 6163 6164**Error codes** 6165 6166For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6167 6168| **ID**| **Error Message** | 6169|-----------|-------| 6170| 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. | 6171| 801 | Capability not supported. | 6172| 14800014 | Already closed. | 6173 6174**Example** 6175 6176```ts 6177if (store != undefined) { 6178 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetails) => { 6179 console.info(`Progess: ${progressDetails}`); 6180 }, (err) => { 6181 if (err) { 6182 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 6183 return; 6184 } 6185 console.info('Cloud sync succeeded'); 6186 }); 6187} 6188``` 6189 6190### cloudSync<sup>10+</sup> 6191 6192cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>): Promise<void> 6193 6194Manually 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. 6195 6196**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6197 6198**Parameters** 6199 6200| Name | Type | Mandatory| Description | 6201| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 6202| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 6203| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details.| 6204 6205**Return value** 6206 6207| Type | Description | 6208| ------------------- | --------------------------------------- | 6209| Promise<void> | Promise used to send the sync result.| 6210 6211**Error codes** 6212 6213For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6214 6215| **ID**| **Error Message** | 6216|-----------|------------------| 6217| 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. | 6218| 801 | Capability not supported. | 6219| 14800014 | Already closed. | 6220 6221**Example** 6222 6223```ts 6224import { BusinessError } from '@kit.BasicServicesKit'; 6225 6226if (store != undefined) { 6227 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetail: relationalStore.ProgressDetails) => { 6228 console.info(`progress: ${progressDetail}`); 6229 }).then(() => { 6230 console.info('Cloud sync succeeded'); 6231 }).catch((err: BusinessError) => { 6232 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 6233 }); 6234} 6235``` 6236 6237### cloudSync<sup>10+</sup> 6238 6239cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 6240 6241Manually 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. 6242 6243**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6244 6245**Parameters** 6246 6247| Name | Type | Mandatory| Description | 6248| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6249| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 6250| tables | string[] | Yes | Name of the table to synchronize. | 6251| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details. | 6252| callback | AsyncCallback<void> | Yes | Callback used to send the sync result to the caller.| 6253 6254**Error codes** 6255 6256For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6257 6258| **ID**| **Error Message** | 6259|-----------|-------| 6260| 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.| 6261| 801 | Capability not supported. | 6262| 14800014 | Already closed. | 6263 6264**Example** 6265 6266```ts 6267const tables = ["table1", "table2"]; 6268 6269if (store != undefined) { 6270 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => { 6271 console.info(`Progess: ${progressDetail}`); 6272 }, (err) => { 6273 if (err) { 6274 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 6275 return; 6276 } 6277 console.info('Cloud sync succeeded'); 6278 }); 6279}; 6280``` 6281 6282### cloudSync<sup>10+</sup> 6283 6284cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>): Promise<void> 6285 6286Manually 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. 6287 6288**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6289 6290**Parameters** 6291 6292| Name | Type | Mandatory| Description | 6293| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 6294| mode | [SyncMode](#syncmode) | Yes | Sync mode of the database. | 6295| tables | string[] | Yes | Name of the table to synchronize. | 6296| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database sync details.| 6297 6298**Return value** 6299 6300| Type | Description | 6301| ------------------- | --------------------------------------- | 6302| Promise<void> | Promise used to send the sync result.| 6303 6304**Error codes** 6305 6306For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6307 6308| **ID**| **Error Message** | 6309|-----------|---------------| 6310| 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 | 6311| 801 | Capability not supported. | 6312| 14800014 | Already closed. | 6313 6314**Example** 6315 6316```ts 6317import { BusinessError } from '@kit.BasicServicesKit'; 6318 6319const tables = ["table1", "table2"]; 6320 6321if (store != undefined) { 6322 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => { 6323 console.info(`progress: ${progressDetail}`); 6324 }).then(() => { 6325 console.info('Cloud sync succeeded'); 6326 }).catch((err: BusinessError) => { 6327 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 6328 }); 6329}; 6330``` 6331 6332### on('dataChange') 6333 6334on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 6335 6336Subscribes to data changes of specified devices. When the data of the specified devices changes, a callback is invoked to return the data change. 6337 6338**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6339 6340**Parameters** 6341 6342| Name | Type | Mandatory| Description | 6343| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6344| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6345| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe. | 6346| 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.| 6347 6348**Error codes** 6349 6350For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6351 6352| **ID**| **Error Message** | 6353|-----------|-------------| 6354| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6355| 801 | Capability not supported. | 6356| 14800014 | Already closed. | 6357 6358**Example** 6359 6360```ts 6361import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6362import { BusinessError } from '@kit.BasicServicesKit'; 6363 6364let storeObserver = (devices: Array<string>) => { 6365 if (devices != undefined) { 6366 for (let i = 0; i < devices.length; i++) { 6367 console.info(`device= ${devices[i]} data changed`); 6368 } 6369 } 6370} 6371 6372try { 6373 if (store != undefined) { 6374 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) 6375 } 6376} catch (err) { 6377 let code = (err as BusinessError).code; 6378 let message = (err as BusinessError).message 6379 console.error(`Register observer failed, code is ${code},message is ${message}`); 6380} 6381``` 6382 6383### on('dataChange')<sup>10+</sup> 6384 6385on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 6386 6387Subscribes to data changes of the specified devices. The registered callback will be called when data in a distributed or local RDB store changes. 6388 6389**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6390 6391**Parameters** 6392 6393| Name | Type | Mandatory| Description | 6394| -------- | ----------------------------------- | ---- | ------------------------------------------- | 6395| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6396| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe.| 6397| 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.| 6398 6399**Error codes** 6400 6401For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6402 6403| **ID**| **Error Message** | 6404|-----------|-------------| 6405| 202 | Permission verification failed, application which is not a system application uses system API. | 6406| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6407| 801 | Capability not supported. | 6408| 14800014 | Already closed. | 6409 6410Example 1: **type** is **SUBSCRIBE_TYPE_REMOTE**. 6411 6412```ts 6413import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6414import { BusinessError } from '@kit.BasicServicesKit'; 6415 6416let storeObserver = (devices: Array<string>) => { 6417 if (devices != undefined) { 6418 for (let i = 0; i < devices.length; i++) { 6419 console.info(`device= ${devices[i]} data changed`); 6420 } 6421 } 6422} 6423 6424try { 6425 if (store != undefined) { 6426 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6427 } 6428} catch (err) { 6429 let code = (err as BusinessError).code; 6430 let message = (err as BusinessError).message; 6431 console.error(`Register observer failed, code is ${code},message is ${message}`); 6432} 6433``` 6434 6435Example 2: **type** is **SUBSCRIBE_TYPE_LOCAL_DETAILS**. 6436 6437```ts 6438import { BusinessError } from '@kit.BasicServicesKit'; 6439 6440let changeInfos = (changeInfos: Array<relationalStore.ChangeInfo>) => { 6441 for (let i = 0; i < changeInfos.length; i++) { 6442 console.info(`changeInfos = ${changeInfos[i]}`); 6443 } 6444} 6445 6446try { 6447 if (store != undefined) { 6448 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_LOCAL_DETAILS, changeInfos); 6449 } 6450} catch (err) { 6451 let code = (err as BusinessError).code; 6452 let message = (err as BusinessError).message; 6453 console.error(`on dataChange fail, code is ${code},message is ${message}`); 6454} 6455 6456let value1 = "Lisa"; 6457let value2 = 18; 6458let value3 = 100.5; 6459let value4 = new Uint8Array([1, 2, 3]); 6460 6461try { 6462 const valueBucket: relationalStore.ValuesBucket = { 6463 'name': value1, 6464 'age': value2, 6465 'salary': value3, 6466 'blobType': value4, 6467 }; 6468 6469 if (store != undefined) { 6470 (store as relationalStore.RdbStore).insert('test', valueBucket); 6471 } 6472} catch (err) { 6473 let code = (err as BusinessError).code; 6474 let message = (err as BusinessError).message; 6475 console.error(`insert fail, code is ${code},message is ${message}`); 6476} 6477``` 6478 6479### on<sup>10+</sup> 6480 6481on(event: string, interProcess: boolean, observer: Callback\<void>): void 6482 6483Subscribes to process events. This callback is invoked by [emit](#emit10). 6484 6485**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6486 6487**Parameters** 6488 6489| Name | Type | Mandatory| Description | 6490| ------------ | --------------- | ---- | ------------------------------------------------------------ | 6491| event | string | Yes | Event name, which must match the event type in **emit**. | 6492| 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.| 6493| observer | Callback\<void> | Yes | Callback used to return the result. | 6494 6495**Error codes** 6496 6497For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6498 6499| **ID**| **Error Message** | 6500|-----------|-------------| 6501| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6502| 801 | Capability not supported. | 6503| 14800000 | Inner error. | 6504| 14800014 | Already closed. | 6505| 14800050 | Failed to obtain the subscription service. | 6506 6507**Example** 6508 6509```ts 6510import { BusinessError } from '@kit.BasicServicesKit'; 6511 6512let storeObserver = () => { 6513 console.info(`storeObserver`); 6514} 6515 6516try { 6517 if (store != undefined) { 6518 (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver); 6519 } 6520} catch (err) { 6521 let code = (err as BusinessError).code; 6522 let message = (err as BusinessError).message 6523 console.error(`Register observer failed, code is ${code},message is ${message}`); 6524} 6525``` 6526 6527### on('autoSyncProgress')<sup>11+</sup> 6528 6529on(event: 'autoSyncProgress', progress: Callback<ProgressDetails>): void 6530 6531Subscribes 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. 6532 6533**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6534 6535**Parameters** 6536 6537| Name | Type | Mandatory| Description | 6538| ------------ |---------------------------------| ---- |-----------------------------------| 6539| event | string | Yes | Event type. The value is **'autoSyncProgress'**, which indicates the auto sync progress.| 6540| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to return the auto sync progress. | 6541 6542**Error codes** 6543 6544For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6545 6546| **ID**| **Error Message** | 6547|-----------|--------| 6548| 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. | 6549| 801 | Capability not supported. | 6550| 14800014 | Already closed. | 6551 6552**Example** 6553 6554```ts 6555import { BusinessError } from '@kit.BasicServicesKit'; 6556 6557let progressDetail = (progressDetail: relationalStore.ProgressDetails) => { 6558 console.info(`progress: ${progressDetail}`); 6559} 6560 6561try { 6562 if (store != undefined) { 6563 (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail) 6564 } 6565} catch (err) { 6566 let code = (err as BusinessError).code; 6567 let message = (err as BusinessError).message 6568 console.error(`Register observer failed, code is ${code},message is ${message}`); 6569} 6570``` 6571 6572### on('statistics')<sup>12+</sup> 6573 6574on(event: 'statistics', observer: Callback<SqlExecutionInfo>): void 6575 6576Subscribes to SQL statistics. 6577 6578**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6579 6580**Parameters** 6581 6582| Name | Type | Mandatory| Description | 6583| ------------ |---------------------------------| ---- |-----------------------------------| 6584| event | string | Yes | Event type. The value is **'statistics'**, which indicates the statistics of the SQL execution time.| 6585| observer | Callback<[SqlExecutionInfo](#sqlexecutioninfo12)> | Yes | Callback used to return the statistics about the SQL execution time in the database. | 6586 6587**Error codes** 6588 6589For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6590 6591| **ID**| **Error Message** | 6592|-----------|--------| 6593| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 6594| 801 | Capability not supported. | 6595| 14800000 | Inner error. | 6596| 14800014 | Already closed. | 6597 6598**Example** 6599 6600```ts 6601import { BusinessError } from '@kit.BasicServicesKit'; 6602 6603let sqlExecutionInfo = (sqlExecutionInfo: relationalStore.SqlExecutionInfo) => { 6604 console.info(`sql: ${sqlExecutionInfo.sql[0]}`); 6605 console.info(`totalTime: ${sqlExecutionInfo.totalTime}`); 6606 console.info(`waitTime: ${sqlExecutionInfo.waitTime}`); 6607 console.info(`prepareTime: ${sqlExecutionInfo.prepareTime}`); 6608 console.info(`executeTime: ${sqlExecutionInfo.executeTime}`); 6609} 6610 6611try { 6612 if (store != undefined) { 6613 (store as relationalStore.RdbStore).on('statistics', sqlExecutionInfo); 6614 } 6615} catch (err) { 6616 let code = (err as BusinessError).code; 6617 let message = (err as BusinessError).message; 6618 console.error(`Register observer failed, code is ${code},message is ${message}`); 6619} 6620 6621try { 6622 let value1 = "Lisa"; 6623 let value2 = 18; 6624 let value3 = 100.5; 6625 let value4 = new Uint8Array([1, 2, 3, 4, 5]); 6626 6627 const valueBucket: relationalStore.ValuesBucket = { 6628 'NAME': value1, 6629 'AGE': value2, 6630 'SALARY': value3, 6631 'CODES': value4, 6632 }; 6633 if (store != undefined) { 6634 (store as relationalStore.RdbStore).insert('test', valueBucket); 6635 } 6636} catch (err) { 6637 console.error(`insert fail, code:${err.code}, message: ${err.message}`); 6638} 6639``` 6640 6641### off('dataChange') 6642 6643off(event:'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 6644 6645Unsubscribes from data changes of the specified devices. 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 to unregister. **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 | Already closed. | 6666 6667**Example** 6668 6669```ts 6670import { BusinessError } from '@kit.BasicServicesKit'; 6671 6672let storeObserver = (devices: Array<string>) => { 6673 if (devices != undefined) { 6674 for (let i = 0; i < devices.length; i++) { 6675 console.info(`device= ${devices[i]} data changed`); 6676 } 6677 } 6678} 6679 6680try { 6681 if (store != undefined) { 6682 // The Lambda expression cannot be used here. 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 6691try { 6692 if (store != undefined) { 6693 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6694 } 6695} catch (err) { 6696 let code = (err as BusinessError).code; 6697 let message = (err as BusinessError).message 6698 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6699} 6700``` 6701 6702### off('dataChange')<sup>10+</sup> 6703 6704off(event:'dataChange', type: SubscribeType, observer?: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 6705 6706Unsubscribes from data changes of this RDB store. 6707 6708**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6709 6710**Parameters** 6711 6712| Name | Type | Mandatory| Description | 6713| -------- | ---------------------------------- | ---- | ------------------------------------------ | 6714| event | string | Yes | Event type. The value is **'dataChange'**, which indicates data changes. | 6715| type | [SubscribeType](#subscribetype) | Yes | Type of data change to observe. | 6716| 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**.| 6717 6718**Error codes** 6719 6720For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6721 6722| **ID**| **Error Message** | 6723|-----------|-------------| 6724| 202 | Permission verification failed, application which is not a system application uses system API. | 6725| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6726| 801 | Capability not supported. | 6727| 14800014 | Already closed. | 6728 6729**Example** 6730 6731```ts 6732import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6733import { BusinessError } from '@kit.BasicServicesKit'; 6734 6735let storeObserver = (devices: Array<string>) => { 6736 if (devices != undefined) { 6737 for (let i = 0; i < devices.length; i++) { 6738 console.info(`device= ${devices[i]} data changed`); 6739 } 6740 } 6741} 6742 6743try { 6744 if (store != undefined) { 6745 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6746 } 6747} catch (err) { 6748 let code = (err as BusinessError).code; 6749 let message = (err as BusinessError).message; 6750 console.error(`Register observer failed, code is ${code},message is ${message}`); 6751} 6752 6753try { 6754 if (store != undefined) { 6755 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6756 } 6757} catch (err) { 6758 let code = (err as BusinessError).code; 6759 let message = (err as BusinessError).message 6760 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6761} 6762``` 6763 6764### off<sup>10+</sup> 6765 6766off(event: string, interProcess: boolean, observer?: Callback\<void>): void 6767 6768Unsubscribes from process events. 6769 6770**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6771 6772**Parameters** 6773 6774| Name | Type | Mandatory| Description | 6775| ------------ | --------------- | ---- | ------------------------------------------------------------ | 6776| event | string | Yes | Event name, which must match the event type in **on()**.| 6777| 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.| 6778| observer | Callback\<void> | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 6779 6780**Error codes** 6781 6782For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6783 6784| **ID**| **Error Message** | 6785| ------------ | -------------------------------------- | 6786| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6787| 801 | Capability not supported. | 6788| 14800000 | Inner error. | 6789| 14800014 | Already closed. | 6790| 14800050 | Failed to obtain the subscription service. | 6791 6792**Example** 6793 6794```ts 6795import { BusinessError } from '@kit.BasicServicesKit'; 6796 6797let storeObserver = () => { 6798 console.info(`storeObserver`); 6799} 6800 6801try { 6802 if (store != undefined) { 6803 (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver); 6804 } 6805} catch (err) { 6806 let code = (err as BusinessError).code; 6807 let message = (err as BusinessError).message 6808 console.error(`Register observer failed, code is ${code},message is ${message}`); 6809} 6810 6811try { 6812 if (store != undefined) { 6813 (store as relationalStore.RdbStore).off('storeObserver', false, storeObserver); 6814 } 6815} catch (err) { 6816 let code = (err as BusinessError).code; 6817 let message = (err as BusinessError).message 6818 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6819} 6820``` 6821 6822### off('autoSyncProgress')<sup>11+</sup> 6823 6824off(event: 'autoSyncProgress', progress?: Callback<ProgressDetails>): void 6825 6826Unsubscribes from the auto sync progress. 6827 6828**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6829 6830**Parameters** 6831 6832| Name | Type | Mandatory| Description | 6833| ------------ |---------------------------------| ---- |------------------------------------------------------------------| 6834| event | string | Yes | Event type. The value is **'autoSyncProgress'**, which indicates the auto sync progress. | 6835| 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.| 6836 6837**Error codes** 6838 6839For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6840 6841| **ID**| **Error Message** | 6842| ------------ |--------------------| 6843| 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. | 6844| 801 | Capability not supported. | 6845| 14800014 | Already closed. | 6846 6847**Example** 6848 6849```ts 6850import { BusinessError } from '@kit.BasicServicesKit'; 6851 6852let progressDetail = (progressDetail: relationalStore.ProgressDetails) => { 6853 console.info(`progress: ${progressDetail}`); 6854} 6855 6856try { 6857 if (store != undefined) { 6858 (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail) 6859 } 6860} catch (err) { 6861 let code = (err as BusinessError).code; 6862 let message = (err as BusinessError).message 6863 console.error(`Register observer failed, code is ${code},message is ${message}`); 6864} 6865 6866try { 6867 if (store != undefined) { 6868 (store as relationalStore.RdbStore).off('autoSyncProgress', progressDetail); 6869 } 6870} catch (err) { 6871 let code = (err as BusinessError).code; 6872 let message = (err as BusinessError).message; 6873 console.error(`Unregister failed, code is ${code},message is ${message}`); 6874} 6875``` 6876 6877### off('statistics')<sup>12+</sup> 6878 6879off(event: 'statistics', observer?: Callback<SqlExecutionInfo>): void 6880 6881Unsubscribes from SQL statistics. 6882 6883**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6884 6885**Parameters** 6886 6887| Name | Type | Mandatory| Description | 6888| ------------ |---------------------------------| ---- |-----------------------------------| 6889| event | string | Yes | Event type. The value is **'statistics'**, which indicates the statistics of the SQL execution time.| 6890| observer | Callback<[SqlExecutionInfo](#sqlexecutioninfo12)> | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 6891 6892 6893**Error codes** 6894 6895For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6896 6897| **ID**| **Error Message** | 6898|-----------|--------| 6899| 401 | Parameter error. | 6900| 801 | Capability not supported. | 6901| 14800000 | Inner error. | 6902| 14800014 | Already closed. | 6903 6904```ts 6905import { BusinessError } from '@kit.BasicServicesKit'; 6906 6907try { 6908 if (store != undefined) { 6909 (store as relationalStore.RdbStore).off('statistics'); 6910 } 6911} catch (err) { 6912 let code = (err as BusinessError).code; 6913 let message = (err as BusinessError).message; 6914 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6915} 6916``` 6917 6918### emit<sup>10+</sup> 6919 6920emit(event: string): void 6921 6922Triggers the inter-process or intra-process event listener registered in [on](#on10). 6923 6924**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 6925 6926**Parameters** 6927 6928| Name| Type | Mandatory| Description | 6929| ------ | ------ | ---- | -------------------- | 6930| 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).| 6931 6932**Error codes** 6933 6934For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 6935 6936| **ID**| **Error Message** | 6937| --------- |---------------------------------------------------------------------------------------------------------------| 6938| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6939| 801 | Capability not supported. | 6940| 14800000 | Inner error. | 6941| 14800014 | Already closed. | 6942| 14800050 | Failed to obtain the subscription service. | 6943 6944 6945**Example** 6946 6947```ts 6948if (store != undefined) { 6949 (store as relationalStore.RdbStore).emit('storeObserver'); 6950} 6951``` 6952 6953### cleanDirtyData<sup>11+</sup> 6954 6955cleanDirtyData(table: string, cursor: number, callback: AsyncCallback<void>): void 6956 6957Clears 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. 6958 6959**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 6960 6961**Parameters** 6962 6963| Name | Type | Mandatory| Description | 6964| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6965| table | string | Yes | Name of the table in the RDB store. | 6966| 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. | 6967| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 6968 6969**Error codes** 6970 6971For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.md). 6972 6973| **ID**| **Error Message** | 6974|-----------|---------------| 6975| 401 | Parameter error. Possible causes: 1. 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. | 6976| 801 | Capability not supported. | 6977| 14800000 | Inner error. | 6978| 14800011 | Database corrupted. | 6979| 14800014 | Already closed. | 6980| 14800015 | The database does not respond. | 6981| 14800021 | SQLite: Generic error. | 6982| 14800022 | SQLite: Callback routine requested an abort. | 6983| 14800023 | SQLite: Access permission denied. | 6984| 14800024 | SQLite: The database file is locked. | 6985| 14800025 | SQLite: A table in the database is locked. | 6986| 14800026 | SQLite: The database is out of memory. | 6987| 14800027 | SQLite: Attempt to write a readonly database. | 6988| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6989| 14800029 | SQLite: The database is full. | 6990| 14800030 | SQLite: Unable to open the database file. | 6991| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6992| 14800032 | SQLite: Abort due to constraint violation. | 6993| 14800033 | SQLite: Data type mismatch. | 6994| 14800034 | SQLite: Library used incorrectly. | 6995 6996**Example** 6997 6998```ts 6999if (store != undefined) { 7000 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100, (err) => { 7001 if (err) { 7002 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 7003 return; 7004 } 7005 console.info('clean dirty data succeeded'); 7006 }) 7007} 7008``` 7009 7010### cleanDirtyData<sup>11+</sup> 7011 7012cleanDirtyData(table: string, callback: AsyncCallback<void>): void 7013 7014Clears all dirty data from the local device. The dirty data is the data that has been deleted from the cloud. 7015 7016**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 7017 7018**Parameters** 7019 7020| Name | Type | Mandatory| Description | 7021| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 7022| table | string | Yes | Name of the table in the RDB store.| 7023| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 7024 7025**Error codes** 7026 7027For 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). 7028 7029| **ID**| **Error Message** | 7030|-----------|---------| 7031| 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. | 7032| 801 | Capability not supported. | 7033| 14800000 | Inner error. | 7034| 14800011 | Database corrupted. | 7035| 14800014 | Already closed. | 7036| 14800015 | The database does not respond. | 7037| 14800021 | SQLite: Generic error. | 7038| 14800022 | SQLite: Callback routine requested an abort. | 7039| 14800023 | SQLite: Access permission denied. | 7040| 14800024 | SQLite: The database file is locked. | 7041| 14800025 | SQLite: A table in the database is locked. | 7042| 14800026 | SQLite: The database is out of memory. | 7043| 14800027 | SQLite: Attempt to write a readonly database. | 7044| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7045| 14800029 | SQLite: The database is full. | 7046| 14800030 | SQLite: Unable to open the database file. | 7047| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7048| 14800032 | SQLite: Abort due to constraint violation. | 7049| 14800033 | SQLite: Data type mismatch. | 7050| 14800034 | SQLite: Library used incorrectly. | 7051 7052**Example** 7053 7054```ts 7055if (store != undefined) { 7056 (store as relationalStore.RdbStore).cleanDirtyData('test_table', (err) => { 7057 if (err) { 7058 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 7059 return; 7060 } 7061 console.info('clean dirty data succeeded'); 7062 }) 7063} 7064``` 7065 7066### cleanDirtyData<sup>11+</sup> 7067 7068cleanDirtyData(table: string, cursor?: number): Promise<void> 7069 7070Clears 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. 7071 7072**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 7073 7074**Parameters** 7075 7076| Name | Type | Mandatory| Description | 7077| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 7078| table | string | Yes | Name of the table in the RDB store. | 7079| 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.| 7080 7081**Return value** 7082| Name | Description | 7083| -------- | ------------------------------------------------- | 7084| Promise\<void> | Promise that returns no value. | 7085 7086**Error codes** 7087 7088For 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). 7089 7090| **ID**| **Error Message** | 7091|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 7092| 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. | 7093| 801 | Capability not supported. | 7094| 14800000 | Inner error. | 7095| 14800011 | Database corrupted. | 7096| 14800014 | Already closed. | 7097| 14800015 | The database does not respond. | 7098| 14800021 | SQLite: Generic error. | 7099| 14800022 | SQLite: Callback routine requested an abort. | 7100| 14800023 | SQLite: Access permission denied. | 7101| 14800024 | SQLite: The database file is locked. | 7102| 14800025 | SQLite: A table in the database is locked. | 7103| 14800026 | SQLite: The database is out of memory. | 7104| 14800027 | SQLite: Attempt to write a readonly database. | 7105| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7106| 14800029 | SQLite: The database is full. | 7107| 14800030 | SQLite: Unable to open the database file. | 7108| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7109| 14800032 | SQLite: Abort due to constraint violation. | 7110| 14800033 | SQLite: Data type mismatch. | 7111| 14800034 | SQLite: Library used incorrectly. | 7112 7113**Example** 7114 7115```ts 7116import { BusinessError } from '@kit.BasicServicesKit'; 7117 7118if (store != undefined) { 7119 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100).then(() => { 7120 console.info('clean dirty data succeeded'); 7121 }).catch ((err: BusinessError) => { 7122 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 7123 }) 7124} 7125``` 7126 7127### attach<sup>12+</sup> 7128 7129attach(fullPath: string, attachName: string, waitTime?: number) : Promise<number> 7130 7131Attaches an RDB store to this RDB store so that the data in the attached RDB store can be directly accessed using the SQL statement. 7132 7133The 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. 7134 7135Before the RDB store is switched to the non-WAL mode, ensure that all **ResultSet**s are closed and all write operations are complete. Otherwise, error 14800015 will be reported. 7136 7137The **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. 7138 7139**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7140 7141**Parameters** 7142 7143| Name | Type | Mandatory | Description | 7144| ----------- | ------ | --- | ------------ | 7145| fullPath | string | Yes | Path of the database file to attach.| 7146| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 7147| waitTime | number | No | Maximum time period (in seconds) allowed for attaching the database file. <br>Value range: 1 to 300<br>Default value: 2| 7148 7149**Return value** 7150 7151| Type | Description | 7152| ---------------- | ---------------------------- | 7153| Promise<number> | Promise used to return the number of attached RDB stores.| 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). For details about how to handle error 14800011, see [Database Backup and Restore](../../database/data-backup-and-restore.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| 14800010 | Invalid database path. | 7165| 14800011 | Database corrupted. | 7166| 14800014 | Already closed. | 7167| 14800015 | The database does not respond. | 7168| 14800016 | The database alias already exists. | 7169| 14800021 | SQLite: Generic error. | 7170| 14800022 | SQLite: Callback routine requested an abort. | 7171| 14800023 | SQLite: Access permission denied. | 7172| 14800024 | SQLite: The database file is locked. | 7173| 14800025 | SQLite: A table in the database is locked. | 7174| 14800026 | SQLite: The database is out of memory. | 7175| 14800027 | SQLite: Attempt to write a readonly database. | 7176| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7177| 14800029 | SQLite: The database is full. | 7178| 14800030 | SQLite: Unable to open the database file. | 7179| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7180| 14800032 | SQLite: Abort due to constraint violation. | 7181| 14800033 | SQLite: Data type mismatch. | 7182| 14800034 | SQLite: Library used incorrectly. | 7183 7184**Example** 7185 7186```ts 7187// Attach a non-encrypted RDB store to a non-encrypted RDB store. 7188import { BusinessError } from '@kit.BasicServicesKit'; 7189 7190if (store != undefined) { 7191 (store as relationalStore.RdbStore).attach("/path/rdbstore1.db", "attachDB").then((number: number) => { 7192 console.info('attach succeeded'); 7193 }).catch ((err: BusinessError) => { 7194 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 7195 }) 7196} 7197``` 7198 7199### attach<sup>12+</sup> 7200 7201attach(context: Context, config: StoreConfig, attachName: string, waitTime?: number) : Promise<number> 7202 7203Attaches an RDB store to this RDB store so that the data in the attached RDB store can be directly accessed using the SQL statement. 7204 7205This API cannot be used to attach a non-encrypted RDB store to an encrypted RDB store. After the **attach()** API is called, the RDB store is switched to non-WAL mode, which may affect the performance. 7206 7207Before 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. 7208 7209The **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. 7210 7211**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7212 7213**Parameters** 7214 7215| Name | Type | Mandatory | Description | 7216| ----------- | ------ | --- | ------------ | 7217| 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).| 7218| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store to attach. | 7219| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 7220| waitTime | number | No | Maximum time period (in seconds) allowed for attaching the database file. <br>Value range: 1 to 300<br>Default value: 2| 7221 7222**Return value** 7223 7224| Type | Description | 7225| ---------------- | ---------------------------- | 7226| Promise<number> | Promise used to return the number of attached RDB stores.| 7227 7228**Error codes** 7229 7230For 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). 7231 7232| **ID**| **Error Message** | 7233|-----------| ------------------------------------------------------------ | 7234| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7235| 801 | Capability not supported. | 7236| 14800000 | Inner error. | 7237| 14800010 | Invalid database path. | 7238| 14800011 | Database corrupted. | 7239| 14800014 | Already closed. | 7240| 14800015 | The database does not respond. | 7241| 14800016 | The database alias already exists. | 7242| 14801001 | The operation is supported in the stage model only. | 7243| 14801002 | Invalid data group ID. | 7244| 14800021 | SQLite: Generic error. | 7245| 14800022 | SQLite: Callback routine requested an abort. | 7246| 14800023 | SQLite: Access permission denied. | 7247| 14800024 | SQLite: The database file is locked. | 7248| 14800025 | SQLite: A table in the database is locked. | 7249| 14800026 | SQLite: The database is out of memory. | 7250| 14800027 | SQLite: Attempt to write a readonly database. | 7251| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7252| 14800029 | SQLite: The database is full. | 7253| 14800030 | SQLite: Unable to open the database file. | 7254| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7255| 14800032 | SQLite: Abort due to constraint violation. | 7256| 14800033 | SQLite: Data type mismatch. | 7257| 14800034 | SQLite: Library used incorrectly. | 7258 7259Example 1: Attach a non-encrypted RDB store to a non-encrypted RDB store. 7260 7261```ts 7262import { BusinessError } from '@kit.BasicServicesKit'; 7263 7264let attachStore: relationalStore.RdbStore | undefined = undefined; 7265 7266const STORE_CONFIG1: relationalStore.StoreConfig = { 7267 name: "rdbstore1.db", 7268 securityLevel: relationalStore.SecurityLevel.S3, 7269} 7270 7271relationalStore.getRdbStore(this.context, STORE_CONFIG1).then(async (rdbStore: relationalStore.RdbStore) => { 7272 attachStore = rdbStore; 7273 console.info('Get RdbStore successfully.') 7274}).catch((err: BusinessError) => { 7275 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 7276}) 7277 7278if (store != undefined) { 7279 (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG1, "attachDB").then((number: number) => { 7280 console.info(`attach succeeded, number is ${number}`); 7281 }).catch ((err: BusinessError) => { 7282 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 7283 }) 7284} 7285``` 7286 7287Example 2: Attach an encrypted RDB store to a non-encrypted RDB store. 7288 7289```ts 7290import { BusinessError } from '@kit.BasicServicesKit'; 7291 7292let attachStore: relationalStore.RdbStore | undefined = undefined; 7293 7294 7295const STORE_CONFIG2: relationalStore.StoreConfig = { 7296 name: "rdbstore2.db", 7297 encrypt: true, 7298 securityLevel: relationalStore.SecurityLevel.S3, 7299} 7300 7301relationalStore.getRdbStore(this.context, STORE_CONFIG2).then(async (rdbStore: relationalStore.RdbStore) => { 7302 attachStore = rdbStore; 7303 console.info('Get RdbStore successfully.') 7304}).catch((err: BusinessError) => { 7305 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 7306}) 7307 7308if (store != undefined) { 7309 (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG2, "attachDB2", 10).then((number: number) => { 7310 console.info(`attach succeeded, number is ${number}`); 7311 }).catch ((err: BusinessError) => { 7312 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 7313 }) 7314} 7315``` 7316 7317### detach<sup>12+</sup> 7318 7319detach(attachName: string, waitTime?: number) : Promise<number> 7320 7321Detaches an RDB store from this RDB store. 7322 7323After all attached RDB stores are detached, the RDB is switched to the WAL mode. 7324 7325Before 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. 7326 7327**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7328 7329**Parameters** 7330 7331| Name | Type | Mandatory | Description | 7332| ----------- | ------ | --- | ------------ | 7333| attachName | string | Yes | Alias of the RDB store formed after the attach operation.| 7334| waitTime | number | No | Maximum time period (in seconds) allowed for detaching the RDB store. <br>Value range: 1 to 300<br>Default value: 2| 7335 7336**Return value** 7337 7338| Type | Description | 7339| ---------------- | ---------------------------- | 7340| Promise<number> | Promise used to return the number of remaining attached RDB stores.| 7341 7342**Error codes** 7343 7344For 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). 7345 7346| **ID**| **Error Message** | 7347|-----------|------------------------| 7348| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7349| 14800000 | Inner error. | 7350| 14800011 | Database corrupted. | 7351| 14800014 | Already closed. | 7352| 14800015 | The database does not respond. | 7353| 14800021 | SQLite: Generic error. | 7354| 14800022 | SQLite: Callback routine requested an abort. | 7355| 14800023 | SQLite: Access permission denied. | 7356| 14800024 | SQLite: The database file is locked. | 7357| 14800025 | SQLite: A table in the database is locked. | 7358| 14800026 | SQLite: The database is out of memory. | 7359| 14800027 | SQLite: Attempt to write a readonly database. | 7360| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7361| 14800029 | SQLite: The database is full. | 7362| 14800030 | SQLite: Unable to open the database file. | 7363| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7364| 14800032 | SQLite: Abort due to constraint violation. | 7365| 14800033 | SQLite: Data type mismatch. | 7366| 14800034 | SQLite: Library used incorrectly. | 7367 7368**Example** 7369 7370```ts 7371import { BusinessError } from '@kit.BasicServicesKit'; 7372 7373if (store != undefined) { 7374 (store as relationalStore.RdbStore).detach("attachDB").then((number: number) => { 7375 console.info(`detach succeeded, number is ${number}`); 7376 }).catch ((err: BusinessError) => { 7377 console.error(`detach failed, code is ${err.code},message is ${err.message}`); 7378 }) 7379} 7380``` 7381 7382### lockRow<sup>12+</sup> 7383 7384lockRow(predicates: RdbPredicates):Promise<void> 7385 7386Locks data in this RDB store. This API uses a promise to return the result. The locked data is blocked from device-cloud sync. 7387 7388This 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. 7389This 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. 7390This API cannot be used for deleted data. 7391 7392**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7393 7394**Parameters** 7395 7396| Name | Type | Mandatory| Description | 7397| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 7398| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions for locking data.| 7399 7400**Return value** 7401 7402| Type | Description | 7403| --------------------- | ------------------------------- | 7404| Promise<void> | Promise that returns no value. | 7405 7406**Error codes** 7407 7408For 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). 7409 7410| **ID**| **Error Message** | 7411|-----------|----------------------------------------------------------------------------------------------| 7412| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7413| 14800000 | Inner error. | 7414| 14800011 | Database corrupted. | 7415| 14800014 | Already closed. | 7416| 14800015 | The database does not respond. | 7417| 14800018 | No data meets the condition. | 7418| 14800021 | SQLite: Generic error. | 7419| 14800022 | SQLite: Callback routine requested an abort. | 7420| 14800023 | SQLite: Access permission denied. | 7421| 14800024 | SQLite: The database file is locked. | 7422| 14800025 | SQLite: A table in the database is locked. | 7423| 14800026 | SQLite: The database is out of memory. | 7424| 14800027 | SQLite: Attempt to write a readonly database. | 7425| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7426| 14800029 | SQLite: The database is full. | 7427| 14800030 | SQLite: Unable to open the database file. | 7428| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7429| 14800032 | SQLite: Abort due to constraint violation. | 7430| 14800033 | SQLite: Data type mismatch. | 7431| 14800034 | SQLite: Library used incorrectly. | 7432 7433**Example** 7434 7435```ts 7436import { BusinessError } from '@kit.BasicServicesKit'; 7437 7438let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7439predicates.equalTo("NAME", "Lisa"); 7440if (store != undefined) { 7441 (store as relationalStore.RdbStore).lockRow(predicates).then(() => { 7442 console.info(`Lock success`); 7443 }).catch((err: BusinessError) => { 7444 console.error(`Lock failed, code is ${err.code},message is ${err.message}`); 7445 }) 7446} 7447``` 7448 7449### unlockRow<sup>12+</sup> 7450 7451unlockRow(predicates: RdbPredicates):Promise<void> 7452 7453Unlocks data in this RDB store. This API uses a promise to return the result. 7454 7455This 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. 7456This 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. 7457This API cannot be used for deleted data. 7458 7459**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7460 7461**Parameters** 7462 7463| Name | Type | Mandatory| Description | 7464| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 7465| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions for unlocking data.| 7466 7467**Return value** 7468 7469| Type | Description | 7470| --------------------- | ------------------------------- | 7471| Promise<void> | Promise that returns no value. | 7472 7473**Error codes** 7474 7475For 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). 7476 7477| **ID**| **Error Message** | 7478|-----------| ------------------------------------------------------------ | 7479| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7480| 14800000 | Inner error. | 7481| 14800011 | Database corrupted. | 7482| 14800014 | Already closed. | 7483| 14800015 | The database does not respond. | 7484| 14800018 | No data meets the condition. | 7485| 14800021 | SQLite: Generic error. | 7486| 14800022 | SQLite: Callback routine requested an abort. | 7487| 14800023 | SQLite: Access permission denied. | 7488| 14800024 | SQLite: The database file is locked. | 7489| 14800025 | SQLite: A table in the database is locked. | 7490| 14800026 | SQLite: The database is out of memory. | 7491| 14800027 | SQLite: Attempt to write a readonly database. | 7492| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7493| 14800029 | SQLite: The database is full. | 7494| 14800030 | SQLite: Unable to open the database file. | 7495| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7496| 14800032 | SQLite: Abort due to constraint violation. | 7497| 14800033 | SQLite: Data type mismatch. | 7498| 14800034 | SQLite: Library used incorrectly. | 7499 7500**Example** 7501 7502```ts 7503import { BusinessError } from '@kit.BasicServicesKit'; 7504 7505let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7506predicates.equalTo("NAME", "Lisa"); 7507if (store != undefined) { 7508 (store as relationalStore.RdbStore).unlockRow(predicates).then(() => { 7509 console.info(`Unlock success`); 7510 }).catch((err: BusinessError) => { 7511 console.error(`Unlock failed, code is ${err.code},message is ${err.message}`); 7512 }) 7513} 7514``` 7515 7516### queryLockedRow<sup>12+</sup> 7517 7518queryLockedRow(predicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> 7519 7520Queries the locked data in this RDB store. This API uses a promise to return the result. 7521Due to the limit of the shared memory (max. 2 MB), a single data record cannot exceed 2 MB. Otherwise, the query operation will fail. 7522 7523**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7524 7525**Parameters** 7526 7527| Name | Type | Mandatory| Description | 7528| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 7529| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 7530| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 7531 7532**Error codes** 7533 7534For 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). 7535 7536| **ID**| **Error Message** | 7537|-----------| ------------------------------------------------------------ | 7538| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7539| 14800000 | Inner error. | 7540| 14800011 | Database corrupted. | 7541| 14800014 | Already closed. | 7542| 14800015 | The database does not respond. | 7543| 14800021 | SQLite: Generic error. | 7544| 14800022 | SQLite: Callback routine requested an abort. | 7545| 14800023 | SQLite: Access permission denied. | 7546| 14800024 | SQLite: The database file is locked. | 7547| 14800025 | SQLite: A table in the database is locked. | 7548| 14800026 | SQLite: The database is out of memory. | 7549| 14800027 | SQLite: Attempt to write a readonly database. | 7550| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7551| 14800029 | SQLite: The database is full. | 7552| 14800030 | SQLite: Unable to open the database file. | 7553| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7554| 14800032 | SQLite: Abort due to constraint violation. | 7555| 14800033 | SQLite: Data type mismatch. | 7556| 14800034 | SQLite: Library used incorrectly. | 7557 7558**Return value** 7559 7560| Type | Description | 7561| ------------------------------------------------------- | -------------------------------------------------- | 7562| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 7563 7564**Example** 7565 7566```ts 7567import { BusinessError } from '@kit.BasicServicesKit'; 7568 7569let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7570predicates.equalTo("NAME", "Rose"); 7571if (store != undefined) { 7572 (store as relationalStore.RdbStore).queryLockedRow(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 7573 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 7574 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 7575 while (resultSet.goToNextRow()) { 7576 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 7577 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 7578 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 7579 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 7580 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 7581 } 7582 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 7583 resultSet.close(); 7584 }).catch((err: BusinessError) => { 7585 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 7586 }) 7587} 7588``` 7589### close<sup>12+</sup> 7590 7591close(): Promise<void> 7592 7593Closes this RDB store. This API uses a promise to return the result. 7594 7595**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7596 7597**Return value** 7598 7599| Type | Description | 7600| ------------------- | ------------- | 7601| Promise<void> | Promise used to| 7602 7603**Error codes** 7604 7605For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 7606 7607| **ID**| **Error Message** | 7608| ------------ | ----------------------------------------------- | 7609| 401 | Parameter error. The store must not be nullptr. | 7610| 14800000 | Inner error. | 7611 7612**Example** 7613 7614```ts 7615import { BusinessError } from '@kit.BasicServicesKit'; 7616 7617if (store != undefined) { 7618 (store as relationalStore.RdbStore).close().then(() => { 7619 console.info(`close succeeded`); 7620 }).catch ((err: BusinessError) => { 7621 console.error(`close failed, code is ${err.code},message is ${err.message}`); 7622 }) 7623} 7624``` 7625 7626## ResultSet 7627 7628Provides APIs to access the **resultSet** object returned by **query()**. 7629 7630### Usage 7631 7632Obtain the **resultSet** object first. 7633 7634**Example** 7635 7636```ts 7637import { UIAbility } from '@kit.AbilityKit'; 7638import { BusinessError } from '@kit.BasicServicesKit'; 7639import { window } from '@kit.ArkUI'; 7640 7641let store: relationalStore.RdbStore | undefined = undefined; 7642 7643class EntryAbility extends UIAbility { 7644 onWindowStageCreate(windowStage: window.WindowStage) { 7645 const STORE_CONFIG: relationalStore.StoreConfig = { 7646 name: "RdbTest.db", 7647 securityLevel: relationalStore.SecurityLevel.S3, 7648 }; 7649 7650 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 7651 store = rdbStore; 7652 console.info('Get RdbStore successfully.') 7653 }).catch((err: BusinessError) => { 7654 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 7655 }) 7656 7657 let resultSet: relationalStore.ResultSet | undefined = undefined; 7658 let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7659 predicates.equalTo("AGE", 18); 7660 if (store != undefined) { 7661 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((result: relationalStore.ResultSet) => { 7662 resultSet = result; 7663 console.info(`resultSet columnNames: ${resultSet.columnNames}`); 7664 console.info(`resultSet columnCount: ${resultSet.columnCount}`); 7665 }); 7666 } 7667 } 7668} 7669``` 7670 7671### Properties 7672 7673**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7674 7675| Name | Type | Mandatory| Description | 7676| ------------ | ------------------- | ---- | -------------------------------- | 7677| columnNames | Array<string> | Yes | Names of all columns in the result set. | 7678| columnCount | number | Yes | Number of columns in the result set. | 7679| rowCount | number | Yes | Number of rows in the result set. | 7680| rowIndex | number | Yes | Index of the current row in the result set. <br>Default value: **-1**. The index position starts from **0**.| 7681| 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.| 7682| isAtLastRow | boolean | Yes | Whether the result set pointer is in the last row. The value **true** means the pointer is in the last row.| 7683| isEnded | boolean | Yes | Whether the result set pointer is after the last row. The value **true** means the pointer is after the last row.| 7684| isStarted | boolean | Yes | Whether the result set pointer is moved. The value **true** means the pointer is moved. | 7685| isClosed | boolean | Yes | Whether the result set is closed. The value **true** means the result set is closed. | 7686 7687### getColumnIndex 7688 7689getColumnIndex(columnName: string): number 7690 7691Obtains the column index based on the column name. 7692 7693**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7694 7695**Parameters** 7696 7697| Name | Type | Mandatory| Description | 7698| ---------- | ------ | ---- | -------------------------- | 7699| columnName | string | Yes | Column name.| 7700 7701**Return value** 7702 7703| Type | Description | 7704| ------ | ------------------ | 7705| number | Column index obtained.| 7706 7707**Error codes** 7708 7709For 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). 7710 7711| **ID**| **Error Message** | 7712|-----------| ------------------------------------------------------------ | 7713| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7714| 14800000 | Inner error. | 7715| 14800011 | Database corrupted. | 7716| 14800013 | Column out of bounds. | 7717| 14800014 | Already closed. | 7718| 14800019 | The SQL must be a query statement. | 7719| 14800021 | SQLite: Generic error. | 7720| 14800022 | SQLite: Callback routine requested an abort. | 7721| 14800023 | SQLite: Access permission denied. | 7722| 14800024 | SQLite: The database file is locked. | 7723| 14800025 | SQLite: A table in the database is locked. | 7724| 14800026 | SQLite: The database is out of memory. | 7725| 14800027 | SQLite: Attempt to write a readonly database. | 7726| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7727| 14800029 | SQLite: The database is full. | 7728| 14800030 | SQLite: Unable to open the database file. | 7729| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7730| 14800032 | SQLite: Abort due to constraint violation. | 7731| 14800033 | SQLite: Data type mismatch. | 7732| 14800034 | SQLite: Library used incorrectly. | 7733 7734**Example** 7735 7736```ts 7737if (resultSet != undefined) { 7738 const id = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("ID")); 7739 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 7740 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 7741 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 7742} 7743``` 7744 7745### getColumnName 7746 7747getColumnName(columnIndex: number): string 7748 7749Obtains the column name based on the specified column index. 7750 7751**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7752 7753**Parameters** 7754 7755| Name | Type | Mandatory| Description | 7756| ----------- | ------ | ---- | -------------------------- | 7757| columnIndex | number | Yes | Column index.| 7758 7759**Return value** 7760 7761| Type | Description | 7762| ------ | ------------------ | 7763| string | Column name obtained.| 7764 7765**Error codes** 7766 7767For 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). 7768 7769| **ID**| **Error Message** | 7770|-----------| ------------------------------------------------------------ | 7771| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7772| 14800000 | Inner error. | 7773| 14800011 | Database corrupted. | 7774| 14800013 | Column out of bounds. | 7775| 14800014 | Already closed. | 7776| 14800019 | The SQL must be a query statement. | 7777| 14800021 | SQLite: Generic error. | 7778| 14800022 | SQLite: Callback routine requested an abort. | 7779| 14800023 | SQLite: Access permission denied. | 7780| 14800024 | SQLite: The database file is locked. | 7781| 14800025 | SQLite: A table in the database is locked. | 7782| 14800026 | SQLite: The database is out of memory. | 7783| 14800027 | SQLite: Attempt to write a readonly database. | 7784| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7785| 14800029 | SQLite: The database is full. | 7786| 14800030 | SQLite: Unable to open the database file. | 7787| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7788| 14800032 | SQLite: Abort due to constraint violation. | 7789| 14800033 | SQLite: Data type mismatch. | 7790| 14800034 | SQLite: Library used incorrectly. | 7791 7792**Example** 7793 7794```ts 7795if (resultSet != undefined) { 7796 const id = (resultSet as relationalStore.ResultSet).getColumnName(0); 7797 const name = (resultSet as relationalStore.ResultSet).getColumnName(1); 7798 const age = (resultSet as relationalStore.ResultSet).getColumnName(2); 7799} 7800``` 7801 7802### goTo 7803 7804goTo(offset:number): boolean 7805 7806Moves the result set pointer based on the offset specified. 7807 7808**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7809 7810**Parameters** 7811 7812| Name| Type | Mandatory| Description | 7813| ------ | ------ | ---- | ---------------------------- | 7814| 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.| 7815 7816**Return value** 7817 7818| Type | Description | 7819| ------- | --------------------------------------------- | 7820| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7821 7822**Error codes** 7823 7824For 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). 7825 7826| **ID**| **Error Message** | 7827|-----------| ------------------------------------------------------------ | 7828| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7829| 14800000 | Inner error. | 7830| 14800011 | Database corrupted. | 7831| 14800012 | Row out of bounds. | 7832| 14800014 | Already closed. | 7833| 14800019 | The SQL must be a query statement. | 7834| 14800021 | SQLite: Generic error. | 7835| 14800022 | SQLite: Callback routine requested an abort. | 7836| 14800023 | SQLite: Access permission denied. | 7837| 14800024 | SQLite: The database file is locked. | 7838| 14800025 | SQLite: A table in the database is locked. | 7839| 14800026 | SQLite: The database is out of memory. | 7840| 14800027 | SQLite: Attempt to write a readonly database. | 7841| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7842| 14800029 | SQLite: The database is full. | 7843| 14800030 | SQLite: Unable to open the database file. | 7844| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7845| 14800032 | SQLite: Abort due to constraint violation. | 7846| 14800033 | SQLite: Data type mismatch. | 7847| 14800034 | SQLite: Library used incorrectly. | 7848 7849**Example** 7850 7851```ts 7852if (resultSet != undefined) { 7853 (resultSet as relationalStore.ResultSet).goTo(1); 7854} 7855``` 7856 7857### goToRow 7858 7859goToRow(position: number): boolean 7860 7861Moves to the specified row in the result set. 7862 7863**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7864 7865**Parameters** 7866 7867| Name | Type | Mandatory| Description | 7868| -------- | ------ | ---- | ------------------------ | 7869| position | number | Yes | Destination position to move to.| 7870 7871**Return value** 7872 7873| Type | Description | 7874| ------- | --------------------------------------------- | 7875| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7876 7877**Error codes** 7878 7879For 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). 7880 7881| **ID**| **Error Message** | 7882|-----------| ------------------------------------------------------------ | 7883| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7884| 14800000 | Inner error. | 7885| 14800011 | Database corrupted. | 7886| 14800012 | Row out of bounds. | 7887| 14800014 | Already closed. | 7888| 14800019 | The SQL must be a query statement. | 7889| 14800021 | SQLite: Generic error. | 7890| 14800022 | SQLite: Callback routine requested an abort. | 7891| 14800023 | SQLite: Access permission denied. | 7892| 14800024 | SQLite: The database file is locked. | 7893| 14800025 | SQLite: A table in the database is locked. | 7894| 14800026 | SQLite: The database is out of memory. | 7895| 14800027 | SQLite: Attempt to write a readonly database. | 7896| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7897| 14800029 | SQLite: The database is full. | 7898| 14800030 | SQLite: Unable to open the database file. | 7899| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7900| 14800032 | SQLite: Abort due to constraint violation. | 7901| 14800033 | SQLite: Data type mismatch. | 7902| 14800034 | SQLite: Library used incorrectly. | 7903 7904**Example** 7905 7906```ts 7907if (resultSet != undefined) { 7908 (resultSet as relationalStore.ResultSet).goToRow(5); 7909} 7910``` 7911 7912### goToFirstRow 7913 7914goToFirstRow(): boolean 7915 7916 7917Moves to the first row of the result set. 7918 7919**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7920 7921**Return value** 7922 7923| Type | Description | 7924| ------- | --------------------------------------------- | 7925| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7926 7927**Error codes** 7928 7929For 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). 7930 7931| **ID**| **Error Message** | 7932|-----------| ------------------------------------------------------------ | 7933| 14800000 | Inner error. | 7934| 14800011 | Database corrupted. | 7935| 14800012 | Row out of bounds. | 7936| 14800014 | Already closed. | 7937| 14800019 | The SQL must be a query statement. | 7938| 14800021 | SQLite: Generic error. | 7939| 14800022 | SQLite: Callback routine requested an abort. | 7940| 14800023 | SQLite: Access permission denied. | 7941| 14800024 | SQLite: The database file is locked. | 7942| 14800025 | SQLite: A table in the database is locked. | 7943| 14800026 | SQLite: The database is out of memory. | 7944| 14800027 | SQLite: Attempt to write a readonly database. | 7945| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7946| 14800029 | SQLite: The database is full. | 7947| 14800030 | SQLite: Unable to open the database file. | 7948| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7949| 14800032 | SQLite: Abort due to constraint violation. | 7950| 14800033 | SQLite: Data type mismatch. | 7951| 14800034 | SQLite: Library used incorrectly. | 7952 7953**Example** 7954 7955```ts 7956if (resultSet != undefined) { 7957 (resultSet as relationalStore.ResultSet).goToFirstRow(); 7958} 7959``` 7960 7961### goToLastRow 7962 7963goToLastRow(): boolean 7964 7965Moves to the last row of the result set. 7966 7967**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 7968 7969**Return value** 7970 7971| Type | Description | 7972| ------- | --------------------------------------------- | 7973| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 7974 7975**Error codes** 7976 7977For 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). 7978 7979| **ID**| **Error Message** | 7980|-----------| ------------------------------------------------------------ | 7981| 14800000 | Inner error. | 7982| 14800011 | Database corrupted. | 7983| 14800012 | Row out of bounds. | 7984| 14800014 | Already closed. | 7985| 14800019 | The SQL must be a query statement. | 7986| 14800021 | SQLite: Generic error. | 7987| 14800022 | SQLite: Callback routine requested an abort. | 7988| 14800023 | SQLite: Access permission denied. | 7989| 14800024 | SQLite: The database file is locked. | 7990| 14800025 | SQLite: A table in the database is locked. | 7991| 14800026 | SQLite: The database is out of memory. | 7992| 14800027 | SQLite: Attempt to write a readonly database. | 7993| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7994| 14800029 | SQLite: The database is full. | 7995| 14800030 | SQLite: Unable to open the database file. | 7996| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7997| 14800032 | SQLite: Abort due to constraint violation. | 7998| 14800033 | SQLite: Data type mismatch. | 7999| 14800034 | SQLite: Library used incorrectly. | 8000 8001**Example** 8002 8003```ts 8004if (resultSet != undefined) { 8005 (resultSet as relationalStore.ResultSet).goToLastRow(); 8006} 8007``` 8008 8009### goToNextRow 8010 8011goToNextRow(): boolean 8012 8013Moves to the next row in the result set. 8014 8015**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8016 8017**Return value** 8018 8019| Type | Description | 8020| ------- | --------------------------------------------- | 8021| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 8022 8023**Error codes** 8024 8025For 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). 8026 8027| **ID**| **Error Message** | 8028|-----------| ------------------------------------------------------------ | 8029| 14800000 | Inner error. | 8030| 14800011 | Database corrupted. | 8031| 14800012 | Row out of bounds. | 8032| 14800014 | Already closed. | 8033| 14800019 | The SQL must be a query statement. | 8034| 14800021 | SQLite: Generic error. | 8035| 14800022 | SQLite: Callback routine requested an abort. | 8036| 14800023 | SQLite: Access permission denied. | 8037| 14800024 | SQLite: The database file is locked. | 8038| 14800025 | SQLite: A table in the database is locked. | 8039| 14800026 | SQLite: The database is out of memory. | 8040| 14800027 | SQLite: Attempt to write a readonly database. | 8041| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8042| 14800029 | SQLite: The database is full. | 8043| 14800030 | SQLite: Unable to open the database file. | 8044| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8045| 14800032 | SQLite: Abort due to constraint violation. | 8046| 14800033 | SQLite: Data type mismatch. | 8047| 14800034 | SQLite: Library used incorrectly. | 8048 8049**Example** 8050 8051```ts 8052if (resultSet != undefined) { 8053 (resultSet as relationalStore.ResultSet).goToNextRow(); 8054} 8055``` 8056 8057### goToPreviousRow 8058 8059goToPreviousRow(): boolean 8060 8061Moves to the previous row in the result set. 8062 8063**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8064 8065**Return value** 8066 8067| Type | Description | 8068| ------- | --------------------------------------------- | 8069| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 8070 8071**Error codes** 8072 8073For 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). 8074 8075| **ID**| **Error Message** | 8076|-----------| ------------------------------------------------------------ | 8077| 14800000 | Inner error. | 8078| 14800011 | Database corrupted. | 8079| 14800012 | Row out of bounds. | 8080| 14800014 | Already closed. | 8081| 14800019 | The SQL must be a query statement. | 8082| 14800021 | SQLite: Generic error. | 8083| 14800022 | SQLite: Callback routine requested an abort. | 8084| 14800023 | SQLite: Access permission denied. | 8085| 14800024 | SQLite: The database file is locked. | 8086| 14800025 | SQLite: A table in the database is locked. | 8087| 14800026 | SQLite: The database is out of memory. | 8088| 14800027 | SQLite: Attempt to write a readonly database. | 8089| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8090| 14800029 | SQLite: The database is full. | 8091| 14800030 | SQLite: Unable to open the database file. | 8092| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8093| 14800032 | SQLite: Abort due to constraint violation. | 8094| 14800033 | SQLite: Data type mismatch. | 8095| 14800034 | SQLite: Library used incorrectly. | 8096 8097**Example** 8098 8099```ts 8100if (resultSet != undefined) { 8101 (resultSet as relationalStore.ResultSet).goToPreviousRow(); 8102} 8103``` 8104 8105### getValue<sup>12+</sup> 8106 8107getValue(columnIndex: number): ValueType 8108 8109Obtains 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. 8110 8111**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8112 8113**Parameters** 8114 8115| Name | Type | Mandatory| Description | 8116| ----------- | ------ | ---- | ----------------------- | 8117| columnIndex | number | Yes | Index of the target column, starting from 0.| 8118 8119**Return value** 8120 8121| Type | Description | 8122| ---------- | -------------------------------- | 8123| [ValueType](#valuetype) | Value obtained. | 8124 8125**Error codes** 8126 8127For 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). 8128 8129| **ID**| **Error Message** | 8130|-----------|---------| 8131| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8132| 14800000 | Inner error. | 8133| 14800011 | Database corrupted. | 8134| 14800012 | Row out of bounds. | 8135| 14800013 | Column out of bounds. | 8136| 14800014 | Already closed. | 8137| 14800021 | SQLite: Generic error. | 8138| 14800022 | SQLite: Callback routine requested an abort. | 8139| 14800023 | SQLite: Access permission denied. | 8140| 14800024 | SQLite: The database file is locked. | 8141| 14800025 | SQLite: A table in the database is locked. | 8142| 14800026 | SQLite: The database is out of memory. | 8143| 14800027 | SQLite: Attempt to write a readonly database. | 8144| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8145| 14800029 | SQLite: The database is full. | 8146| 14800030 | SQLite: Unable to open the database file. | 8147| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8148| 14800032 | SQLite: Abort due to constraint violation. | 8149| 14800033 | SQLite: Data type mismatch. | 8150| 14800034 | SQLite: Library used incorrectly. | 8151 8152**Example** 8153 8154```ts 8155if (resultSet != undefined) { 8156 const codes = (resultSet as relationalStore.ResultSet).getValue((resultSet as relationalStore.ResultSet).getColumnIndex("BIGINT_COLUMN")); 8157} 8158``` 8159 8160### getBlob 8161 8162getBlob(columnIndex: number): Uint8Array 8163 8164 8165Obtains 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. 8166 8167**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8168 8169**Parameters** 8170 8171| Name | Type | Mandatory| Description | 8172| ----------- | ------ | ---- | ----------------------- | 8173| columnIndex | number | Yes | Index of the target column, starting from 0.| 8174 8175**Return value** 8176 8177| Type | Description | 8178| ---------- | -------------------------------- | 8179| Uint8Array | Value obtained.| 8180 8181**Error codes** 8182 8183For 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). 8184 8185| **ID**| **Error Message** | 8186|-----------| ------------------------------------------------------------ | 8187| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8188| 14800000 | Inner error. | 8189| 14800011 | Database corrupted. | 8190| 14800012 | Row out of bounds. | 8191| 14800013 | Column out of bounds. | 8192| 14800014 | Already closed. | 8193| 14800021 | SQLite: Generic error. | 8194| 14800022 | SQLite: Callback routine requested an abort. | 8195| 14800023 | SQLite: Access permission denied. | 8196| 14800024 | SQLite: The database file is locked. | 8197| 14800025 | SQLite: A table in the database is locked. | 8198| 14800026 | SQLite: The database is out of memory. | 8199| 14800027 | SQLite: Attempt to write a readonly database. | 8200| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8201| 14800029 | SQLite: The database is full. | 8202| 14800030 | SQLite: Unable to open the database file. | 8203| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8204| 14800032 | SQLite: Abort due to constraint violation. | 8205| 14800033 | SQLite: Data type mismatch. | 8206| 14800034 | SQLite: Library used incorrectly. | 8207 8208**Example** 8209 8210```ts 8211if (resultSet != undefined) { 8212 const codes = (resultSet as relationalStore.ResultSet).getBlob((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 8213} 8214``` 8215 8216### getString 8217 8218getString(columnIndex: number): string 8219 8220Obtains 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. 8221 8222**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8223 8224**Parameters** 8225 8226| Name | Type | Mandatory| Description | 8227| ----------- | ------ | ---- | ----------------------- | 8228| columnIndex | number | Yes | Index of the target column, starting from 0.| 8229 8230**Return value** 8231 8232| Type | Description | 8233| ------ | ---------------------------- | 8234| string | String obtained.| 8235 8236**Error codes** 8237 8238For 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). 8239 8240| **ID**| **Error Message** | 8241|-----------| ------------------------------------------------------------ | 8242| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8243| 14800000 | Inner error. | 8244| 14800011 | Database corrupted. | 8245| 14800012 | Row out of bounds. | 8246| 14800013 | Column out of bounds. | 8247| 14800014 | Already closed. | 8248| 14800021 | SQLite: Generic error. | 8249| 14800022 | SQLite: Callback routine requested an abort. | 8250| 14800023 | SQLite: Access permission denied. | 8251| 14800024 | SQLite: The database file is locked. | 8252| 14800025 | SQLite: A table in the database is locked. | 8253| 14800026 | SQLite: The database is out of memory. | 8254| 14800027 | SQLite: Attempt to write a readonly database. | 8255| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8256| 14800029 | SQLite: The database is full. | 8257| 14800030 | SQLite: Unable to open the database file. | 8258| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8259| 14800032 | SQLite: Abort due to constraint violation. | 8260| 14800033 | SQLite: Data type mismatch. | 8261| 14800034 | SQLite: Library used incorrectly. | 8262 8263**Example** 8264 8265```ts 8266if (resultSet != undefined) { 8267 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 8268} 8269``` 8270 8271### getLong 8272 8273getLong(columnIndex: number): number 8274 8275Obtains 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. 8276 8277**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8278 8279**Parameters** 8280 8281| Name | Type | Mandatory| Description | 8282| ----------- | ------ | ---- | ----------------------- | 8283| columnIndex | number | Yes | Index of the target column, starting from 0.| 8284 8285**Return value** 8286 8287| Type | Description | 8288| ------ | ------------------------------------------------------------ | 8289| 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).| 8290 8291**Error codes** 8292 8293For 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). 8294 8295| **ID**| **Error Message** | 8296|-----------| ------------------------------------------------------------ | 8297| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8298| 14800000 | Inner error. | 8299| 14800011 | Database corrupted. | 8300| 14800012 | Row out of bounds. | 8301| 14800013 | Column out of bounds. | 8302| 14800014 | Already closed. | 8303| 14800021 | SQLite: Generic error. | 8304| 14800022 | SQLite: Callback routine requested an abort. | 8305| 14800023 | SQLite: Access permission denied. | 8306| 14800024 | SQLite: The database file is locked. | 8307| 14800025 | SQLite: A table in the database is locked. | 8308| 14800026 | SQLite: The database is out of memory. | 8309| 14800027 | SQLite: Attempt to write a readonly database. | 8310| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8311| 14800029 | SQLite: The database is full. | 8312| 14800030 | SQLite: Unable to open the database file. | 8313| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8314| 14800032 | SQLite: Abort due to constraint violation. | 8315| 14800033 | SQLite: Data type mismatch. | 8316| 14800034 | SQLite: Library used incorrectly. | 8317 8318**Example** 8319 8320```ts 8321if (resultSet != undefined) { 8322 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 8323} 8324``` 8325 8326### getDouble 8327 8328getDouble(columnIndex: number): number 8329 8330Obtains 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. 8331 8332**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8333 8334**Parameters** 8335 8336| Name | Type | Mandatory| Description | 8337| ----------- | ------ | ---- | ----------------------- | 8338| columnIndex | number | Yes | Index of the target column, starting from 0.| 8339 8340**Return value** 8341 8342| Type | Description | 8343| ------ | ---------------------------- | 8344| number | Returns the value obtained.| 8345 8346**Error codes** 8347 8348For 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). 8349 8350| **ID**| **Error Message** | 8351|-----------| ------------------------------------------------------------ | 8352| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8353| 14800000 | Inner error. | 8354| 14800011 | Database corrupted. | 8355| 14800012 | Row out of bounds. | 8356| 14800013 | Column out of bounds. | 8357| 14800014 | Already closed. | 8358| 14800021 | SQLite: Generic error. | 8359| 14800022 | SQLite: Callback routine requested an abort. | 8360| 14800023 | SQLite: Access permission denied. | 8361| 14800024 | SQLite: The database file is locked. | 8362| 14800025 | SQLite: A table in the database is locked. | 8363| 14800026 | SQLite: The database is out of memory. | 8364| 14800027 | SQLite: Attempt to write a readonly database. | 8365| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8366| 14800029 | SQLite: The database is full. | 8367| 14800030 | SQLite: Unable to open the database file. | 8368| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8369| 14800032 | SQLite: Abort due to constraint violation. | 8370| 14800033 | SQLite: Data type mismatch. | 8371| 14800034 | SQLite: Library used incorrectly. | 8372 8373**Example** 8374 8375```ts 8376if (resultSet != undefined) { 8377 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 8378} 8379``` 8380 8381### getAsset<sup>10+</sup> 8382 8383getAsset(columnIndex: number): Asset 8384 8385Obtains 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. 8386 8387**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8388 8389**Parameters** 8390 8391| Name | Type | Mandatory | Description | 8392| ----------- | ------ | --- | ------------ | 8393| columnIndex | number | Yes | Index of the target column, starting from 0.| 8394 8395**Return value** 8396 8397| Type | Description | 8398| --------------- | -------------------------- | 8399| [Asset](#asset10) | Returns the value obtained.| 8400 8401**Error codes** 8402 8403For 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). 8404 8405| **ID**| **Error Message** | 8406|-----------| ------------------------------------------------------------ | 8407| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8408| 14800000 | Inner error. | 8409| 14800011 | Database corrupted. | 8410| 14800012 | Row out of bounds. | 8411| 14800013 | Column out of bounds. | 8412| 14800014 | Already closed. | 8413| 14800021 | SQLite: Generic error. | 8414| 14800022 | SQLite: Callback routine requested an abort. | 8415| 14800023 | SQLite: Access permission denied. | 8416| 14800024 | SQLite: The database file is locked. | 8417| 14800025 | SQLite: A table in the database is locked. | 8418| 14800026 | SQLite: The database is out of memory. | 8419| 14800027 | SQLite: Attempt to write a readonly database. | 8420| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8421| 14800029 | SQLite: The database is full. | 8422| 14800030 | SQLite: Unable to open the database file. | 8423| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8424| 14800032 | SQLite: Abort due to constraint violation. | 8425| 14800033 | SQLite: Data type mismatch. | 8426| 14800034 | SQLite: Library used incorrectly. | 8427 8428**Example** 8429 8430```ts 8431if (resultSet != undefined) { 8432 const doc = (resultSet as relationalStore.ResultSet).getAsset((resultSet as relationalStore.ResultSet).getColumnIndex("DOC")); 8433} 8434``` 8435 8436### getAssets<sup>10+</sup> 8437 8438getAssets(columnIndex: number): Assets 8439 8440Obtains the value from the specified column and current row, and returns the value in the [Assets](#assets10) format. If the type of the value in the column is **Assets**, the value of the Assets type is returned. If the value in the column is null, **null** is returned. If the value in the column is of other types, **14800000** is returned. 8441 8442**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8443 8444**Parameters** 8445 8446| Name | Type | Mandatory | Description | 8447| ----------- | ------ | --- | ------------ | 8448| columnIndex | number | Yes | Index of the target column, starting from 0.| 8449 8450**Return value** 8451 8452| Type | Description | 8453| ---------------- | ---------------------------- | 8454| [Assets](#assets10)| Returns the value obtained.| 8455 8456**Error codes** 8457 8458For 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). 8459 8460| **ID**| **Error Message** | 8461|-----------| ------------------------------------------------------------ | 8462| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8463| 14800000 | Inner error. | 8464| 14800011 | Database corrupted. | 8465| 14800012 | Row out of bounds. | 8466| 14800013 | Column out of bounds. | 8467| 14800014 | Already closed. | 8468| 14800021 | SQLite: Generic error. | 8469| 14800022 | SQLite: Callback routine requested an abort. | 8470| 14800023 | SQLite: Access permission denied. | 8471| 14800024 | SQLite: The database file is locked. | 8472| 14800025 | SQLite: A table in the database is locked. | 8473| 14800026 | SQLite: The database is out of memory. | 8474| 14800027 | SQLite: Attempt to write a readonly database. | 8475| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8476| 14800029 | SQLite: The database is full. | 8477| 14800030 | SQLite: Unable to open the database file. | 8478| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8479| 14800032 | SQLite: Abort due to constraint violation. | 8480| 14800033 | SQLite: Data type mismatch. | 8481| 14800034 | SQLite: Library used incorrectly. | 8482 8483**Example** 8484 8485```ts 8486if (resultSet != undefined) { 8487 const docs = (resultSet as relationalStore.ResultSet).getAssets((resultSet as relationalStore.ResultSet).getColumnIndex("DOCS")); 8488} 8489``` 8490 8491### getRow<sup>11+</sup> 8492 8493getRow(): ValuesBucket 8494 8495Obtains the data in the current row. 8496 8497**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8498 8499**Return value** 8500 8501| Type | Description | 8502| ---------------- | ---------------------------- | 8503| [ValuesBucket](#valuesbucket) | Data obtained.| 8504 8505**Error codes** 8506 8507For 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). 8508 8509| **ID**| **Error Message** | 8510|-----------| ------------------------------------------------------------ | 8511| 14800000 | Inner error. | 8512| 14800011 | Database corrupted. | 8513| 14800012 | Row out of bounds. | 8514| 14800013 | Column out of bounds. | 8515| 14800014 | Already closed. | 8516| 14800021 | SQLite: Generic error. | 8517| 14800022 | SQLite: Callback routine requested an abort. | 8518| 14800023 | SQLite: Access permission denied. | 8519| 14800024 | SQLite: The database file is locked. | 8520| 14800025 | SQLite: A table in the database is locked. | 8521| 14800026 | SQLite: The database is out of memory. | 8522| 14800027 | SQLite: Attempt to write a readonly database. | 8523| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8524| 14800029 | SQLite: The database is full. | 8525| 14800030 | SQLite: Unable to open the database file. | 8526| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8527| 14800032 | SQLite: Abort due to constraint violation. | 8528| 14800033 | SQLite: Data type mismatch. | 8529| 14800034 | SQLite: Library used incorrectly. | 8530 8531**Example** 8532 8533```ts 8534if (resultSet != undefined) { 8535 const row = (resultSet as relationalStore.ResultSet).getRow(); 8536} 8537``` 8538 8539### getRows<sup>18+</sup> 8540 8541getRows(maxCount: number, position?: number): Promise<Array\<ValuesBucket>> 8542 8543Obtains 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. 8544 8545**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8546 8547**Parameters** 8548 8549| Name | Type | Mandatory| Description | 8550| ----------- | ------ | ---- | ----------------------- | 8551| 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.| 8552| 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.| 8553 8554 8555**Return value** 8556 8557| Type | Description | 8558| ---------------- | ---------------------------- | 8559| 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.| 8560 8561**Error codes** 8562 8563For 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). 8564 8565| **ID**| **Error Message** | 8566|-----------| ------------------------------------------------------------ | 8567| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8568| 14800000 | Inner error. | 8569| 14800011 | Database corrupted. | 8570| 14800012 | Row out of bounds. | 8571| 14800013 | Column out of bounds. | 8572| 14800014 | Already closed. | 8573| 14800021 | SQLite: Generic error. | 8574| 14800022 | SQLite: Callback routine requested an abort. | 8575| 14800023 | SQLite: Access permission denied. | 8576| 14800024 | SQLite: The database file is locked. | 8577| 14800025 | SQLite: A table in the database is locked. | 8578| 14800026 | SQLite: The database is out of memory. | 8579| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8580| 14800029 | SQLite: The database is full. | 8581| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8582| 14800032 | SQLite: Abort due to constraint violation. | 8583| 14800033 | SQLite: Data type mismatch. | 8584 8585**Example** 8586 8587```ts 8588// Obtain 100 rows of data. 8589async function proccessRows(resultSet: relationalStore.ResultSet) { 8590 // Example 1: Specify only maxCount. 8591 if (resultSet != undefined) { 8592 let rows:Array<relationalStore.ValuesBucket> 8593 let maxCount:number = 50 8594 // 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. 8595 // 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. 8596 while ((rows = await (resultSet as relationalStore.ResultSet).getRows(maxCount)).length != 0) { 8597 console.info(JSON.stringify(rows[0])) 8598 } 8599 } 8600 8601 // Example 2: Specify maxCount and position. 8602 if (resultSet != undefined) { 8603 let rows:Array<relationalStore.ValuesBucket> 8604 let maxCount:number = 50 8605 let position:number = 50 8606 while ((rows = await (resultSet as relationalStore.ResultSet).getRows(maxCount, position)).length != 0) { 8607 console.info(JSON.stringify(rows[0])) 8608 position += rows.length 8609 } 8610 } 8611} 8612``` 8613 8614### getSendableRow<sup>12+</sup> 8615 8616getSendableRow(): sendableRelationalStore.ValuesBucket 8617 8618Obtains the sendable data from the current row. The sendable data can be passed across threads. 8619 8620**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8621 8622**Return value** 8623 8624| Type | Description | 8625| ---------------------------------------------------------------------------------------------- | ---------------------------------------------- | 8626| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | Sendable data obtained for cross-thread transfer.| 8627 8628**Error codes** 8629 8630For 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). 8631 8632| **ID**| **Error Message** | 8633| ------------ | --------------------------------------------- | 8634| 14800000 | Inner error. | 8635| 14800011 | Database corrupted. | 8636| 14800012 | Row out of bounds. | 8637| 14800013 | Column out of bounds. | 8638| 14800014 | Already closed. | 8639| 14800021 | SQLite: Generic error. | 8640| 14800022 | SQLite: Callback routine requested an abort. | 8641| 14800023 | SQLite: Access permission denied. | 8642| 14800024 | SQLite: The database file is locked. | 8643| 14800025 | SQLite: A table in the database is locked. | 8644| 14800026 | SQLite: The database is out of memory. | 8645| 14800027 | SQLite: Attempt to write a readonly database. | 8646| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8647| 14800029 | SQLite: The database is full. | 8648| 14800030 | SQLite: Unable to open the database file. | 8649| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8650| 14800032 | SQLite: Abort due to constraint violation. | 8651| 14800033 | SQLite: Data type mismatch. | 8652| 14800034 | SQLite: Library used incorrectly. | 8653 8654**Example** 8655 8656```ts 8657import { taskpool } from '@kit.ArkTS'; 8658import type ctx from '@ohos.app.ability.common'; 8659import { sendableRelationalStore } from '@kit.ArkData'; 8660 8661@Concurrent 8662async function getDataByName(name: string, context: ctx.UIAbilityContext) { 8663 const STORE_CONFIG: relationalStore.StoreConfig = { 8664 name: "RdbTest.db", 8665 securityLevel: relationalStore.SecurityLevel.S3 8666 }; 8667 const store = await relationalStore.getRdbStore(context, STORE_CONFIG); 8668 const predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 8669 predicates.equalTo("NAME", name); 8670 const resultSet = store.querySync(predicates); 8671 8672 if (resultSet.rowCount > 0) { 8673 resultSet.goToFirstRow(); 8674 const sendableValuesBucket = resultSet.getSendableRow(); 8675 return sendableValuesBucket; 8676 } else { 8677 return null; 8678 } 8679} 8680 8681class EntryAbility extends UIAbility { 8682 async onWindowStageCreate(windowStage: window.WindowStage) { 8683 const task = new taskpool.Task(getDataByName, 'Lisa', getContext()); 8684 const sendableValuesBucket = await taskpool.execute(task) as sendableRelationalStore.ValuesBucket; 8685 8686 if (sendableValuesBucket) { 8687 const columnCount = sendableValuesBucket.size; 8688 const age = sendableValuesBucket.get('age'); 8689 const name = sendableValuesBucket.get('name'); 8690 console.info(`Query data in taskpool succeeded, name is "${name}", age is "${age}"`) 8691 } 8692 } 8693} 8694``` 8695 8696### isColumnNull 8697 8698isColumnNull(columnIndex: number): boolean 8699 8700Checks whether the value in the specified column is null. 8701 8702**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8703 8704**Parameters** 8705 8706| Name | Type | Mandatory| Description | 8707| ----------- | ------ | ---- | ----------------------- | 8708| columnIndex | number | Yes | Index of the target column, starting from 0.| 8709 8710**Return value** 8711 8712| Type | Description | 8713| ------- | --------------------------------------------------------- | 8714| boolean | Returns **true** if the value is null; returns **false** otherwise.| 8715 8716**Error codes** 8717 8718For 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). 8719 8720| **ID**| **Error Message** | 8721|-----------| ------------------------------------------------------- | 8722| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8723| 14800000 | Inner error. | 8724| 14800011 | Database corrupted. | 8725| 14800012 | Row out of bounds. | 8726| 14800013 | Column out of bounds. | 8727| 14800014 | Already closed. | 8728| 14800021 | SQLite: Generic error. | 8729| 14800022 | SQLite: Callback routine requested an abort. | 8730| 14800023 | SQLite: Access permission denied. | 8731| 14800024 | SQLite: The database file is locked. | 8732| 14800025 | SQLite: A table in the database is locked. | 8733| 14800026 | SQLite: The database is out of memory. | 8734| 14800027 | SQLite: Attempt to write a readonly database. | 8735| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8736| 14800029 | SQLite: The database is full. | 8737| 14800030 | SQLite: Unable to open the database file. | 8738| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8739| 14800032 | SQLite: Abort due to constraint violation. | 8740| 14800033 | SQLite: Data type mismatch. | 8741| 14800034 | SQLite: Library used incorrectly. | 8742 8743**Example** 8744 8745```ts 8746if (resultSet != undefined) { 8747 const isColumnNull = (resultSet as relationalStore.ResultSet).isColumnNull((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 8748} 8749``` 8750 8751### close 8752 8753close(): void 8754 8755Closes this **resultSet** to release memory. If the **resultSet** is not closed, FD or memory leaks may occur. 8756 8757**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8758 8759**Example** 8760 8761```ts 8762if (resultSet != undefined) { 8763 (resultSet as relationalStore.ResultSet).close(); 8764} 8765``` 8766 8767**Error codes** 8768 8769For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 8770 8771| **ID**| **Error Message** | 8772|-----------| ------------------------------------------------------------ | 8773| 14800000 | Inner error. | 8774| 14800012 | Row out of bounds. | 8775 8776## Transaction<sup>14+</sup> 8777 8778Provides 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). 8779 8780Currently, 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. 8781 8782When 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. 8783 8784**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8785 8786**Example** 8787 8788```ts 8789import { UIAbility } from '@kit.AbilityKit'; 8790import { BusinessError } from '@kit.BasicServicesKit'; 8791import { window } from '@kit.ArkUI'; 8792 8793let store: relationalStore.RdbStore | undefined = undefined; 8794 8795class EntryAbility extends UIAbility { 8796 async onWindowStageCreate(windowStage: window.WindowStage) { 8797 const STORE_CONFIG: relationalStore.StoreConfig = { 8798 name: "RdbTest.db", 8799 securityLevel: relationalStore.SecurityLevel.S3, 8800 }; 8801 8802 await relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 8803 store = rdbStore; 8804 console.info('Get RdbStore successfully.') 8805 }).catch((err: BusinessError) => { 8806 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 8807 }) 8808 8809 if (store != undefined) { 8810 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 8811 console.info(`createTransaction success`); 8812 // Perform subsequent operations after the transaction instance is successfully obtained. 8813 }).catch((err: BusinessError) => { 8814 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 8815 }); 8816 } 8817 } 8818} 8819``` 8820 8821### commit<sup>14+</sup> 8822 8823commit(): Promise<void> 8824 8825Commits 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. 8826 8827**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8828 8829**Return value** 8830 8831| Type | Description | 8832| ------------------- | ------------------------- | 8833| Promise<void> | Promise that returns no value.| 8834 8835**Error codes** 8836 8837For 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). 8838 8839| **ID**| **Error Message** | 8840|-----------| ------------------------------------------------------------ | 8841| 14800000 | Inner error. | 8842| 14800011 | Database corrupted. | 8843| 14800014 | Already closed. | 8844| 14800023 | SQLite: Access permission denied. | 8845| 14800024 | SQLite: The database file is locked. | 8846| 14800026 | SQLite: The database is out of memory. | 8847| 14800027 | SQLite: Attempt to write a readonly database. | 8848| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8849| 14800029 | SQLite: The database is full. | 8850 8851**Example** 8852 8853```ts 8854let value1 = "Lisa"; 8855let value2 = 18; 8856let value3 = 100.5; 8857let value4 = new Uint8Array([1, 2, 3]); 8858 8859if (store != undefined) { 8860 const valueBucket: relationalStore.ValuesBucket = { 8861 'NAME': value1, 8862 'AGE': value2, 8863 'SALARY': value3, 8864 'CODES': value4, 8865 }; 8866 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 8867 transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => { 8868 transaction.commit(); 8869 }).catch((e: BusinessError) => { 8870 transaction.rollback(); 8871 console.error(`execute sql failed, code is ${e.code},message is ${e.message}`); 8872 }); 8873 }).catch((err: BusinessError) => { 8874 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 8875 }); 8876} 8877``` 8878 8879### rollback<sup>14+</sup> 8880 8881rollback(): Promise<void> 8882 8883Rolls back the executed SQL statement. After **rollback()** is called, the transaction object and the created **ResultSet** object will be closed. 8884 8885**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8886 8887**Return value** 8888 8889| Type | Description | 8890| ------------------- | ------------------------- | 8891| Promise<void> | Promise that returns no value.| 8892 8893**Error codes** 8894 8895For 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). 8896 8897| **ID**| **Error Message** | 8898|-----------| ------------------------------------------------------------ | 8899| 14800000 | Inner error. | 8900| 14800011 | Database corrupted. | 8901| 14800014 | Already closed. | 8902| 14800023 | SQLite: Access permission denied. | 8903| 14800024 | SQLite: The database file is locked. | 8904| 14800026 | SQLite: The database is out of memory. | 8905| 14800027 | SQLite: Attempt to write a readonly database. | 8906| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8907| 14800029 | SQLite: The database is full. | 8908 8909**Example** 8910 8911```ts 8912if (store != undefined) { 8913 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 8914 transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => { 8915 transaction.commit(); 8916 }).catch((e: BusinessError) => { 8917 transaction.rollback(); 8918 console.error(`execute sql failed, code is ${e.code},message is ${e.message}`); 8919 }); 8920 }).catch((err: BusinessError) => { 8921 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 8922 }); 8923} 8924 8925``` 8926 8927### insert<sup>14+</sup> 8928 8929insert(table: string, values: ValuesBucket, conflict?: ConflictResolution): Promise<number> 8930 8931Inserts 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. 8932 8933**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 8934 8935**Parameters** 8936 8937| Name | Type | Mandatory| Description | 8938| -------- | ------------------------------------------- | ---- | -------------------------- | 8939| table | string | Yes | Name of the target table. | 8940| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 8941| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**. | 8942 8943**Return value** 8944 8945| Type | Description | 8946| --------------------- | ------------------------------------------------- | 8947| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 8948 8949**Error codes** 8950 8951For 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). 8952 8953| **ID**| **Error Message** | 8954|-----------| ------------------------------------------------------------ | 8955| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8956| 14800000 | Inner error. | 8957| 14800011 | Database corrupted. | 8958| 14800014 | Already closed. | 8959| 14800021 | SQLite: Generic error. | 8960| 14800023 | SQLite: Access permission denied. | 8961| 14800024 | SQLite: The database file is locked. | 8962| 14800025 | SQLite: A table in the database is locked. | 8963| 14800026 | SQLite: The database is out of memory. | 8964| 14800027 | SQLite: Attempt to write a readonly database. | 8965| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8966| 14800029 | SQLite: The database is full. | 8967| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8968| 14800033 | SQLite: Data type mismatch. | 8969| 14800047 | The WAL file size exceeds the default limit. | 8970 8971**Example** 8972 8973```ts 8974let value1 = "Lisa"; 8975let value2 = 18; 8976let value3 = 100.5; 8977let value4 = new Uint8Array([1, 2, 3, 4, 5]); 8978 8979// You can use either of the following: 8980const valueBucket1: relationalStore.ValuesBucket = { 8981 'NAME': value1, 8982 'AGE': value2, 8983 'SALARY': value3, 8984 'CODES': value4, 8985}; 8986const valueBucket2: relationalStore.ValuesBucket = { 8987 NAME: value1, 8988 AGE: value2, 8989 SALARY: value3, 8990 CODES: value4, 8991}; 8992const valueBucket3: relationalStore.ValuesBucket = { 8993 "NAME": value1, 8994 "AGE": value2, 8995 "SALARY": value3, 8996 "CODES": value4, 8997}; 8998 8999if (store != undefined) { 9000 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9001 transaction.insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => { 9002 transaction.commit(); 9003 console.info(`Insert is successful, rowId = ${rowId}`); 9004 }).catch((e: BusinessError) => { 9005 transaction.rollback(); 9006 console.error(`Insert is failed, code is ${e.code},message is ${e.message}`); 9007 }); 9008 }).catch((err: BusinessError) => { 9009 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9010 }); 9011} 9012``` 9013 9014### insertSync<sup>14+</sup> 9015 9016insertSync(table: string, values: ValuesBucket | sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution): number 9017 9018Inserts 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. 9019 9020**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9021 9022**Parameters** 9023 9024| Name | Type | Mandatory| Description | 9025| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 9026| table | string | Yes | Name of the target table. | 9027| values | [ValuesBucket](#valuesbucket) \| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | Yes | Row of data to insert. | 9028| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 9029 9030**Return value** 9031 9032| Type | Description | 9033| ------ | ------------------------------------ | 9034| number | If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 9035 9036**Error codes** 9037 9038For 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). 9039 9040| **ID**| **Error Message** | 9041| ------------ | ------------------------------------------------------------ | 9042| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9043| 14800000 | Inner error. | 9044| 14800011 | Database corrupted. | 9045| 14800014 | Already closed. | 9046| 14800021 | SQLite: Generic error. | 9047| 14800023 | SQLite: Access permission denied. | 9048| 14800024 | SQLite: The database file is locked. | 9049| 14800025 | SQLite: A table in the database is locked. | 9050| 14800026 | SQLite: The database is out of memory. | 9051| 14800027 | SQLite: Attempt to write a readonly database. | 9052| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9053| 14800029 | SQLite: The database is full. | 9054| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9055| 14800033 | SQLite: Data type mismatch. | 9056| 14800047 | The WAL file size exceeds the default limit. | 9057 9058**Example** 9059 9060```ts 9061let value1 = "Lisa"; 9062let value2 = 18; 9063let value3 = 100.5; 9064let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9065 9066// You can use either of the following: 9067const valueBucket1: relationalStore.ValuesBucket = { 9068 'NAME': value1, 9069 'AGE': value2, 9070 'SALARY': value3, 9071 'CODES': value4, 9072}; 9073const valueBucket2: relationalStore.ValuesBucket = { 9074 NAME: value1, 9075 AGE: value2, 9076 SALARY: value3, 9077 CODES: value4, 9078}; 9079const valueBucket3: relationalStore.ValuesBucket = { 9080 "NAME": value1, 9081 "AGE": value2, 9082 "SALARY": value3, 9083 "CODES": value4, 9084}; 9085 9086if (store != undefined) { 9087 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9088 try { 9089 let rowId: number = (transaction as relationalStore.Transaction).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 9090 transaction.commit(); 9091 console.info(`Insert is successful, rowId = ${rowId}`); 9092 } catch (e) { 9093 transaction.rollback(); 9094 console.error(`Insert is failed, code is ${e.code},message is ${e.message}`); 9095 }; 9096 }).catch((err: BusinessError) => { 9097 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9098 }); 9099} 9100``` 9101 9102### batchInsert<sup>14+</sup> 9103 9104batchInsert(table: string, values: Array<ValuesBucket>): Promise<number> 9105 9106Inserts a batch of data into a table. This API uses a promise to return the result. 9107 9108**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9109 9110**Parameters** 9111 9112| Name| Type | Mandatory| Description | 9113| ------ | ------------------------------------------ | ---- | ---------------------------- | 9114| table | string | Yes | Name of the target table. | 9115| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 9116 9117**Return value** 9118 9119| Type | Description | 9120| --------------------- | ----------------------------------------------------------- | 9121| 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.| 9122 9123**Error codes** 9124 9125For 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). 9126 9127| **ID**| **Error Message** | 9128|-----------| ------------------------------------------------------------ | 9129| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9130| 14800000 | Inner error. | 9131| 14800011 | Database corrupted. | 9132| 14800014 | Already closed. | 9133| 14800021 | SQLite: Generic error. | 9134| 14800023 | SQLite: Access permission denied. | 9135| 14800024 | SQLite: The database file is locked. | 9136| 14800025 | SQLite: A table in the database is locked. | 9137| 14800026 | SQLite: The database is out of memory. | 9138| 14800027 | SQLite: Attempt to write a readonly database. | 9139| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9140| 14800029 | SQLite: The database is full. | 9141| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9142| 14800033 | SQLite: Data type mismatch. | 9143| 14800047 | The WAL file size exceeds the default limit. | 9144 9145**Example** 9146 9147```ts 9148let value1 = "Lisa"; 9149let value2 = 18; 9150let value3 = 100.5; 9151let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9152let value5 = "Jack"; 9153let value6 = 19; 9154let value7 = 101.5; 9155let value8 = new Uint8Array([6, 7, 8, 9, 10]); 9156let value9 = "Tom"; 9157let value10 = 20; 9158let value11 = 102.5; 9159let value12 = new Uint8Array([11, 12, 13, 14, 15]); 9160 9161const valueBucket1: relationalStore.ValuesBucket = { 9162 'NAME': value1, 9163 'AGE': value2, 9164 'SALARY': value3, 9165 'CODES': value4, 9166}; 9167const valueBucket2: relationalStore.ValuesBucket = { 9168 'NAME': value5, 9169 'AGE': value6, 9170 'SALARY': value7, 9171 'CODES': value8, 9172}; 9173const valueBucket3: relationalStore.ValuesBucket = { 9174 'NAME': value9, 9175 'AGE': value10, 9176 'SALARY': value11, 9177 'CODES': value12, 9178}; 9179 9180let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 9181if (store != undefined) { 9182 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9183 transaction.batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => { 9184 transaction.commit(); 9185 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 9186 }).catch((e: BusinessError) => { 9187 transaction.rollback(); 9188 console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`); 9189 }); 9190 }).catch((err: BusinessError) => { 9191 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9192 }); 9193} 9194``` 9195 9196### batchInsertSync<sup>14+</sup> 9197 9198batchInsertSync(table: string, values: Array<ValuesBucket>): number 9199 9200Inserts a batch of data into a table. This API returns the result synchronously. 9201 9202**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9203 9204**Parameters** 9205 9206| Name| Type | Mandatory| Description | 9207| ------ | ------------------------------------------ | ---- | ---------------------------- | 9208| table | string | Yes | Name of the target table. | 9209| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 9210 9211**Return value** 9212 9213| Type | Description | 9214| ------ | ---------------------------------------------- | 9215| number | If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 9216 9217**Error codes** 9218 9219For 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). 9220 9221| **ID**| **Error Message** | 9222| ------------ | ------------------------------------------------------------ | 9223| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9224| 14800000 | Inner error. | 9225| 14800011 | Database corrupted. | 9226| 14800014 | Already closed. | 9227| 14800021 | SQLite: Generic error. | 9228| 14800023 | SQLite: Access permission denied. | 9229| 14800024 | SQLite: The database file is locked. | 9230| 14800025 | SQLite: A table in the database is locked. | 9231| 14800026 | SQLite: The database is out of memory. | 9232| 14800027 | SQLite: Attempt to write a readonly database. | 9233| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9234| 14800029 | SQLite: The database is full. | 9235| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9236| 14800033 | SQLite: Data type mismatch. | 9237| 14800047 | The WAL file size exceeds the default limit. | 9238 9239**Example** 9240 9241```ts 9242let value1 = "Lisa"; 9243let value2 = 18; 9244let value3 = 100.5; 9245let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9246let value5 = "Jack"; 9247let value6 = 19; 9248let value7 = 101.5; 9249let value8 = new Uint8Array([6, 7, 8, 9, 10]); 9250let value9 = "Tom"; 9251let value10 = 20; 9252let value11 = 102.5; 9253let value12 = new Uint8Array([11, 12, 13, 14, 15]); 9254 9255const valueBucket1: relationalStore.ValuesBucket = { 9256 'NAME': value1, 9257 'AGE': value2, 9258 'SALARY': value3, 9259 'CODES': value4, 9260}; 9261const valueBucket2: relationalStore.ValuesBucket = { 9262 'NAME': value5, 9263 'AGE': value6, 9264 'SALARY': value7, 9265 'CODES': value8, 9266}; 9267const valueBucket3: relationalStore.ValuesBucket = { 9268 'NAME': value9, 9269 'AGE': value10, 9270 'SALARY': value11, 9271 'CODES': value12, 9272}; 9273 9274let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 9275if (store != undefined) { 9276 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9277 try { 9278 let insertNum: number = (transaction as relationalStore.Transaction).batchInsertSync("EMPLOYEE", valueBuckets); 9279 transaction.commit(); 9280 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 9281 } catch (e) { 9282 transaction.rollback(); 9283 console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`); 9284 }; 9285 }).catch((err: BusinessError) => { 9286 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9287 }); 9288} 9289``` 9290 9291### update<sup>14+</sup> 9292 9293update(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): Promise<number> 9294 9295Updates 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. 9296 9297**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9298 9299**Parameters** 9300 9301| Name | Type | Mandatory| Description | 9302| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 9303| 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.| 9304| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 9305| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**. | 9306 9307**Return value** 9308 9309| Type | Description | 9310| --------------------- | ----------------------------------------- | 9311| Promise<number> | Promise used to return the number of rows updated.| 9312 9313**Error codes** 9314 9315For 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). 9316 9317| **ID**| **Error Message** | 9318|-----------| ------------------------------------------------------------ | 9319| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9320| 14800000 | Inner error. | 9321| 14800011 | Database corrupted. | 9322| 14800014 | Already closed. | 9323| 14800021 | SQLite: Generic error. | 9324| 14800023 | SQLite: Access permission denied. | 9325| 14800024 | SQLite: The database file is locked. | 9326| 14800025 | SQLite: A table in the database is locked. | 9327| 14800026 | SQLite: The database is out of memory. | 9328| 14800027 | SQLite: Attempt to write a readonly database. | 9329| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9330| 14800029 | SQLite: The database is full. | 9331| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9332| 14800033 | SQLite: Data type mismatch. | 9333| 14800047 | The WAL file size exceeds the default limit. | 9334 9335**Example** 9336 9337```ts 9338let value1 = "Rose"; 9339let value2 = 22; 9340let value3 = 200.5; 9341let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9342 9343// You can use either of the following: 9344const valueBucket1: relationalStore.ValuesBucket = { 9345 'NAME': value1, 9346 'AGE': value2, 9347 'SALARY': value3, 9348 'CODES': value4, 9349}; 9350const valueBucket2: relationalStore.ValuesBucket = { 9351 NAME: value1, 9352 AGE: value2, 9353 SALARY: value3, 9354 CODES: value4, 9355}; 9356const valueBucket3: relationalStore.ValuesBucket = { 9357 "NAME": value1, 9358 "AGE": value2, 9359 "SALARY": value3, 9360 "CODES": value4, 9361}; 9362 9363let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 9364predicates.equalTo("NAME", "Lisa"); 9365 9366if (store != undefined) { 9367 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9368 transaction.update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => { 9369 transaction.commit(); 9370 console.info(`Updated row count: ${rows}`); 9371 }).catch((e: BusinessError) => { 9372 transaction.rollback(); 9373 console.error(`Updated failed, code is ${e.code},message is ${e.message}`); 9374 }); 9375 }).catch((err: BusinessError) => { 9376 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9377 }); 9378} 9379``` 9380 9381### updateSync<sup>14+</sup> 9382 9383updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): number 9384 9385Updates 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. 9386 9387**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9388 9389**Parameters** 9390 9391| Name | Type | Mandatory| Description | 9392| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 9393| 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.| 9394| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 9395| conflict | [ConflictResolution](#conflictresolution10) | No | Resolution used to resolve the conflict. <br>Default value: **relationalStore.ConflictResolution.ON_CONFLICT_NONE**.| 9396 9397**Return value** 9398 9399| Type | Description | 9400| ------ | ------------------ | 9401| number | return the number of rows updated.| 9402 9403**Error codes** 9404 9405For 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). 9406 9407| **ID**| **Error Message** | 9408| ------------ | ------------------------------------------------------------ | 9409| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9410| 14800000 | Inner error. | 9411| 14800011 | Database corrupted. | 9412| 14800014 | Already closed. | 9413| 14800021 | SQLite: Generic error. | 9414| 14800023 | SQLite: Access permission denied. | 9415| 14800024 | SQLite: The database file is locked. | 9416| 14800025 | SQLite: A table in the database is locked. | 9417| 14800026 | SQLite: The database is out of memory. | 9418| 14800027 | SQLite: Attempt to write a readonly database. | 9419| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9420| 14800029 | SQLite: The database is full. | 9421| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9422| 14800033 | SQLite: Data type mismatch. | 9423| 14800047 | The WAL file size exceeds the default limit. | 9424 9425**Example** 9426 9427```ts 9428let value1 = "Rose"; 9429let value2 = 22; 9430let value3 = 200.5; 9431let value4 = new Uint8Array([1, 2, 3, 4, 5]); 9432 9433// You can use either of the following: 9434const valueBucket1: relationalStore.ValuesBucket = { 9435 'NAME': value1, 9436 'AGE': value2, 9437 'SALARY': value3, 9438 'CODES': value4, 9439}; 9440const valueBucket2: relationalStore.ValuesBucket = { 9441 NAME: value1, 9442 AGE: value2, 9443 SALARY: value3, 9444 CODES: value4, 9445}; 9446const valueBucket3: relationalStore.ValuesBucket = { 9447 "NAME": value1, 9448 "AGE": value2, 9449 "SALARY": value3, 9450 "CODES": value4, 9451}; 9452 9453let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 9454predicates.equalTo("NAME", "Lisa"); 9455 9456if (store != undefined) { 9457 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9458 try { 9459 let rows: Number = (transaction as relationalStore.Transaction).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 9460 transaction.commit(); 9461 console.info(`Updated row count: ${rows}`); 9462 } catch (e) { 9463 transaction.rollback(); 9464 console.error(`Updated failed, code is ${e.code},message is ${e.message}`); 9465 }; 9466 }).catch((err: BusinessError) => { 9467 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9468 }); 9469} 9470``` 9471 9472### delete<sup>14+</sup> 9473 9474delete(predicates: RdbPredicates):Promise<number> 9475 9476Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result. 9477 9478**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9479 9480**Parameters** 9481 9482| Name | Type | Mandatory| Description | 9483| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 9484| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 9485 9486**Return value** 9487 9488| Type | Description | 9489| --------------------- | ------------------------------- | 9490| Promise<number> | Promise used to return the number of rows deleted.| 9491 9492**Error codes** 9493 9494For 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). 9495 9496| **ID**| **Error Message** | 9497|-----------| ------------------------------------------------------------ | 9498| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9499| 14800000 | Inner error. | 9500| 14800011 | Database corrupted. | 9501| 14800014 | Already closed. | 9502| 14800021 | SQLite: Generic error. | 9503| 14800023 | SQLite: Access permission denied. | 9504| 14800024 | SQLite: The database file is locked. | 9505| 14800025 | SQLite: A table in the database is locked. | 9506| 14800026 | SQLite: The database is out of memory. | 9507| 14800027 | SQLite: Attempt to write a readonly database. | 9508| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9509| 14800029 | SQLite: The database is full. | 9510| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9511| 14800033 | SQLite: Data type mismatch. | 9512| 14800047 | The WAL file size exceeds the default limit. | 9513 9514**Example** 9515 9516```ts 9517let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 9518predicates.equalTo("NAME", "Lisa"); 9519 9520if (store != undefined) { 9521 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9522 transaction.delete(predicates).then((rows: Number) => { 9523 transaction.commit(); 9524 console.info(`Delete rows: ${rows}`); 9525 }).catch((e: BusinessError) => { 9526 transaction.rollback(); 9527 console.error(`Delete failed, code is ${e.code},message is ${e.message}`); 9528 }); 9529 }).catch((err: BusinessError) => { 9530 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9531 }); 9532} 9533``` 9534 9535### deleteSync<sup>14+</sup> 9536 9537deleteSync(predicates: RdbPredicates): number 9538 9539Deletes data from the database based on the specified **RdbPredicates** object. 9540 9541**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9542 9543**Parameters** 9544 9545| Name | Type | Mandatory| Description | 9546| ---------- | ------------------------------- | ---- | --------------------------------------- | 9547| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 9548 9549**Return value** 9550 9551| Type | Description | 9552| ------ | ------------------ | 9553| number | return the number of rows updated.| 9554 9555**Error codes** 9556 9557For 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). 9558 9559| **ID**| **Error Message** | 9560| ------------ | ------------------------------------------------------------ | 9561| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9562| 14800000 | Inner error. | 9563| 14800011 | Database corrupted. | 9564| 14800014 | Already closed. | 9565| 14800021 | SQLite: Generic error. | 9566| 14800023 | SQLite: Access permission denied. | 9567| 14800024 | SQLite: The database file is locked. | 9568| 14800025 | SQLite: A table in the database is locked. | 9569| 14800026 | SQLite: The database is out of memory. | 9570| 14800027 | SQLite: Attempt to write a readonly database. | 9571| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9572| 14800029 | SQLite: The database is full. | 9573| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9574| 14800033 | SQLite: Data type mismatch. | 9575| 14800047 | The WAL file size exceeds the default limit. | 9576 9577**Example** 9578 9579```ts 9580let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 9581predicates.equalTo("NAME", "Lisa"); 9582 9583if (store != undefined) { 9584 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9585 try { 9586 let rows: Number = (transaction as relationalStore.Transaction).deleteSync(predicates); 9587 transaction.commit(); 9588 console.info(`Delete rows: ${rows}`); 9589 } catch (e) { 9590 transaction.rollback(); 9591 console.error(`Delete failed, code is ${e.code},message is ${e.message}`); 9592 }; 9593 }).catch((err: BusinessError) => { 9594 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9595 }); 9596} 9597``` 9598 9599### query<sup>14+</sup> 9600 9601query(predicates: RdbPredicates, columns?: Array<string>): Promise<ResultSet> 9602 9603Queries 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. 9604 9605**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9606 9607**Parameters** 9608 9609| Name | Type | Mandatory| Description | 9610| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 9611| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 9612| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 9613 9614**Error codes** 9615 9616For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 9617 9618| **ID**| **Error Message** | 9619|-----------| ------------------------------------------------------------ | 9620| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9621| 14800000 | Inner error. | 9622| 14800011 | Database corrupted. | 9623| 14800014 | Already closed. | 9624| 14800021 | SQLite: Generic error. | 9625| 14800023 | SQLite: Access permission denied. | 9626| 14800024 | SQLite: The database file is locked. | 9627| 14800026 | SQLite: The database is out of memory. | 9628| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9629| 14800047 | The WAL file size exceeds the default limit. | 9630 9631**Return value** 9632 9633| Type | Description | 9634| ------------------------------------------------------- | -------------------------------------------------- | 9635| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 9636 9637**Example** 9638 9639```ts 9640let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 9641predicates.equalTo("NAME", "Rose"); 9642 9643if (store != undefined) { 9644 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9645 transaction.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 9646 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 9647 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 9648 while (resultSet.goToNextRow()) { 9649 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 9650 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 9651 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 9652 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 9653 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 9654 } 9655 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 9656 resultSet.close(); 9657 transaction.commit(); 9658 }).catch((e: BusinessError) => { 9659 transaction.rollback(); 9660 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 9661 }); 9662 }).catch((err: BusinessError) => { 9663 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9664 }); 9665} 9666``` 9667 9668### querySync<sup>14+</sup> 9669 9670querySync(predicates: RdbPredicates, columns?: Array<string>): ResultSet 9671 9672Queries 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. 9673 9674**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9675 9676**Parameters** 9677 9678| Name | Type | Mandatory| Description | 9679| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ | 9680| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 9681| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns. <br>Default value: null.| 9682 9683**Error codes** 9684 9685For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 9686 9687| **ID**| **Error Message** | 9688| ------------ | ------------------------------------------------------------ | 9689| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9690| 14800000 | Inner error. | 9691| 14800011 | Database corrupted. | 9692| 14800014 | Already closed. | 9693| 14800021 | SQLite: Generic error. | 9694| 14800023 | SQLite: Access permission denied. | 9695| 14800024 | SQLite: The database file is locked. | 9696| 14800025 | SQLite: A table in the database is locked. | 9697| 14800026 | SQLite: The database is out of memory. | 9698| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9699| 14800047 | The WAL file size exceeds the default limit. | 9700 9701**Return value** 9702 9703| Type | Description | 9704| ----------------------- | ----------------------------------- | 9705| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 9706 9707**Example** 9708 9709```ts 9710let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 9711predicates.equalTo("NAME", "Rose"); 9712 9713if (store != undefined) { 9714 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9715 try { 9716 let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); 9717 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 9718 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 9719 while (resultSet.goToNextRow()) { 9720 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 9721 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 9722 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 9723 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 9724 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 9725 } 9726 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 9727 resultSet.close(); 9728 transaction.commit(); 9729 } catch (e) { 9730 transaction.rollback(); 9731 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 9732 }; 9733 }).catch((err: BusinessError) => { 9734 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9735 }); 9736} 9737``` 9738 9739### querySql<sup>14+</sup> 9740 9741querySql(sql: string, args?: Array<ValueType>): Promise<ResultSet> 9742 9743Queries 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. 9744 9745**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9746 9747**Parameters** 9748 9749| Name | Type | Mandatory| Description | 9750| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 9751| sql | string | Yes | SQL statement to run. | 9752| 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.| 9753 9754**Return value** 9755 9756| Type | Description | 9757| ------------------------------------------------------- | -------------------------------------------------- | 9758| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 9759 9760**Error codes** 9761 9762For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 9763 9764| **ID**| **Error Message** | 9765|-----------| ------------------------------------------------------------ | 9766| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9767| 14800000 | Inner error. | 9768| 14800011 | Database corrupted. | 9769| 14800014 | Already closed. | 9770| 14800021 | SQLite: Generic error. | 9771| 14800023 | SQLite: Access permission denied. | 9772| 14800024 | SQLite: The database file is locked. | 9773| 14800025 | SQLite: A table in the database is locked. | 9774| 14800026 | SQLite: The database is out of memory. | 9775| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9776| 14800047 | The WAL file size exceeds the default limit. | 9777 9778**Example** 9779 9780```ts 9781if (store != undefined) { 9782 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9783 transaction.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then((resultSet: relationalStore.ResultSet) => { 9784 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 9785 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 9786 while (resultSet.goToNextRow()) { 9787 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 9788 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 9789 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 9790 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 9791 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 9792 } 9793 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 9794 resultSet.close(); 9795 transaction.commit(); 9796 }).catch((e: BusinessError) => { 9797 transaction.rollback(); 9798 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 9799 }); 9800 }).catch((err: BusinessError) => { 9801 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9802 }); 9803} 9804``` 9805 9806### querySqlSync<sup>14+</sup> 9807 9808querySqlSync(sql: string, args?: Array<ValueType>): ResultSet 9809 9810Queries 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. 9811 9812**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9813 9814**Parameters** 9815 9816| Name | Type | Mandatory| Description | 9817| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 9818| sql | string | Yes | SQL statement to run. | 9819| 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.| 9820 9821**Return value** 9822 9823| Type | Description | 9824| ----------------------- | ----------------------------------- | 9825| [ResultSet](#resultset) | If the operation is successful, a **ResultSet** object will be returned.| 9826 9827**Error codes** 9828 9829For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 9830 9831| **ID**| **Error Message** | 9832| ------------ | ------------------------------------------------------------ | 9833| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9834| 14800000 | Inner error. | 9835| 14800011 | Database corrupted. | 9836| 14800014 | Already closed. | 9837| 14800021 | SQLite: Generic error. | 9838| 14800023 | SQLite: Access permission denied. | 9839| 14800024 | SQLite: The database file is locked. | 9840| 14800025 | SQLite: A table in the database is locked. | 9841| 14800026 | SQLite: The database is out of memory. | 9842| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9843| 14800047 | The WAL file size exceeds the default limit. | 9844 9845**Example** 9846 9847```ts 9848if (store != undefined) { 9849 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9850 try { 9851 let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'"); 9852 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 9853 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 9854 while (resultSet.goToNextRow()) { 9855 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 9856 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 9857 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 9858 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 9859 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 9860 } 9861 // Release the memory of resultSet. If the memory is not released, FD or memory leaks may occur. 9862 resultSet.close(); 9863 transaction.commit(); 9864 } catch (e) { 9865 transaction.rollback(); 9866 console.error(`Query failed, code is ${e.code},message is ${e.message}`); 9867 }; 9868 }).catch((err: BusinessError) => { 9869 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9870 }); 9871} 9872``` 9873 9874### execute<sup>14+</sup> 9875 9876execute(sql: string, args?: Array<ValueType>): Promise<ValueType> 9877 9878Executes 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. 9879 9880This 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. 9881 9882This 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. 9883 9884Statements separated by semicolons (\;) are not supported. 9885 9886**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9887 9888**Parameters** 9889 9890| Name | Type | Mandatory| Description | 9891| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 9892| sql | string | Yes | SQL statement to run. | 9893| 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.| 9894 9895**Return value** 9896 9897| Type | Description | 9898| ------------------- | ------------------------- | 9899| Promise<[ValueType](#valuetype)> | Promise used to return the SQL execution result.| 9900 9901**Error codes** 9902 9903For 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). 9904 9905| **ID**| **Error Message** | 9906|-----------| ------------------------------------------------------------ | 9907| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9908| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 9909| 14800000 | Inner error. | 9910| 14800011 | Database corrupted. | 9911| 14800014 | Already closed. | 9912| 14800021 | SQLite: Generic error. | 9913| 14800023 | SQLite: Access permission denied. | 9914| 14800024 | SQLite: The database file is locked. | 9915| 14800025 | SQLite: A table in the database is locked. | 9916| 14800026 | SQLite: The database is out of memory. | 9917| 14800027 | SQLite: Attempt to write a readonly database. | 9918| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9919| 14800029 | SQLite: The database is full. | 9920| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9921| 14800033 | SQLite: Data type mismatch. | 9922| 14800047 | The WAL file size exceeds the default limit. | 9923 9924**Example** 9925 9926```ts 9927// Delete all data from the table. 9928if (store != undefined) { 9929 const SQL_DELETE_TABLE = 'DELETE FROM test'; 9930 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 9931 transaction.execute(SQL_DELETE_TABLE).then((data) => { 9932 transaction.commit(); 9933 console.info(`delete result: ${data}`); 9934 }).catch((e: BusinessError) => { 9935 transaction.rollback(); 9936 console.error(`delete failed, code is ${e.code}, message is ${e.message}`); 9937 }); 9938 }).catch((err: BusinessError) => { 9939 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 9940 }); 9941} 9942``` 9943 9944### executeSync<sup>14+</sup> 9945 9946executeSync(sql: string, args?: Array<ValueType>): ValueType 9947 9948Executes 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. 9949 9950This 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. 9951 9952This 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. 9953 9954Statements separated by semicolons (\;) are not supported. 9955 9956**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 9957 9958**Parameters** 9959 9960| Name| Type | Mandatory| Description | 9961| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 9962| sql | string | Yes | SQL statement to run. | 9963| 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.| 9964 9965**Return value** 9966 9967| Type | Description | 9968| ----------------------- | ------------------- | 9969| [ValueType](#valuetype) | SQL execution result.| 9970 9971**Error codes** 9972 9973For 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). 9974 9975| **ID**| **Error Message** | 9976| ------------ | ------------------------------------------------------------ | 9977| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 9978| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 9979| 14800000 | Inner error. | 9980| 14800011 | Database corrupted. | 9981| 14800014 | Already closed. | 9982| 14800021 | SQLite: Generic error. | 9983| 14800023 | SQLite: Access permission denied. | 9984| 14800024 | SQLite: The database file is locked. | 9985| 14800025 | SQLite: A table in the database is locked. | 9986| 14800026 | SQLite: The database is out of memory. | 9987| 14800027 | SQLite: Attempt to write a readonly database. | 9988| 14800028 | SQLite: Some kind of disk I/O error occurred. | 9989| 14800029 | SQLite: The database is full. | 9990| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 9991| 14800033 | SQLite: Data type mismatch. | 9992| 14800047 | The WAL file size exceeds the default limit. | 9993 9994**Example** 9995 9996```ts 9997// Delete all data from the table. 9998if (store != undefined) { 9999 (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => { 10000 const SQL_DELETE_TABLE = 'DELETE FROM test'; 10001 try { 10002 let data = (transaction as relationalStore.Transaction).executeSync(SQL_DELETE_TABLE); 10003 transaction.commit(); 10004 console.info(`delete result: ${data}`); 10005 } catch (e) { 10006 transaction.rollback(); 10007 console.error(`delete failed, code is ${e.code}, message is ${e.message}`); 10008 }; 10009 }).catch((err: BusinessError) => { 10010 console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`); 10011 }); 10012} 10013``` 10014