1# @ohos.data.relationalStore (RDB Store) 2 3The relational database (RDB) store manages data based on relational models. It provides a complete mechanism for managing local databases based on the underlying SQLite. To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements. The worker threads are not supported. 4ArkTS supports the following basic data types: number, string, binary data, and boolean. The maximum size of a data record is 2 MB. If a data record exceeds 2 MB, it can be inserted successfully but cannot be read. 5 6The **relationalStore** module provides the following functions: 7 8- [RdbPredicates](#rdbpredicates): provides predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store. 9- [RdbStore](#rdbstore): provides APIs for managing data in an RDB store. 10- [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store. 11 12> **NOTE** 13> 14> 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. 15 16## Modules to Import 17 18```ts 19import relationalStore from '@ohos.data.relationalStore'; 20``` 21 22## relationalStore.getRdbStore 23 24getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback<RdbStore>): void 25 26Obtains an RDB store. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. 27 28**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 29 30**Parameters** 31 32| Name | Type | Mandatory| Description | 33| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | 34| 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).| 35| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 36| callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes | Callback invoked to return the RDB store obtained. | 37 38**Error codes** 39 40For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 41 42| **ID**| **Error Message** | 43| ------------ | ----------------------------------------------------------- | 44| 14800010 | Failed to open or delete database by invalid database path. | 45| 14800011 | Failed to open database by database corrupted. | 46| 14800000 | Inner error. | 47| 14801001 | Only supported in stage mode. | 48| 14801002 | The data group id is not valid. | 49 50**Example** 51 52FA model: 53 54```js 55import featureAbility from '@ohos.ability.featureAbility'; 56import { BusinessError } from "@ohos.base"; 57 58let store: relationalStore.RdbStore | undefined = undefined; 59let context = getContext(this); 60 61const STORE_CONFIG: relationalStore.StoreConfig = { 62 name: "RdbTest.db", 63 securityLevel: relationalStore.SecurityLevel.S1 64}; 65 66relationalStore.getRdbStore(context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 67 store = rdbStore; 68 if (err) { 69 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 70 return; 71 } 72 console.info('Get RdbStore successfully.'); 73}) 74``` 75 76Stage model: 77 78```ts 79import UIAbility from '@ohos.app.ability.UIAbility'; 80import window from '@ohos.window'; 81import { BusinessError } from "@ohos.base"; 82 83let store: relationalStore.RdbStore | undefined = undefined; 84 85class EntryAbility extends UIAbility { 86 onWindowStageCreate(windowStage: window.WindowStage) { 87 const STORE_CONFIG: relationalStore.StoreConfig = { 88 name: "RdbTest.db", 89 securityLevel: relationalStore.SecurityLevel.S1 90 }; 91 92 relationalStore.getRdbStore(this.context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 93 store = rdbStore; 94 if (err) { 95 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 96 return; 97 } 98 console.info('Get RdbStore successfully.'); 99 }) 100 } 101} 102``` 103 104## relationalStore.getRdbStore 105 106getRdbStore(context: Context, config: StoreConfig): Promise<RdbStore> 107 108Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations. 109 110**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 111 112**Parameters** 113 114| Name | Type | Mandatory| Description | 115| ------- | -------------------------------- | ---- | ------------------------------------------------------------ | 116| 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).| 117| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 118 119**Return value** 120 121| Type | Description | 122| ----------------------------------------- | --------------------------------- | 123| Promise<[RdbStore](#rdbstore)> | Promise used to return the **RdbStore** object.| 124 125**Error codes** 126 127For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 128 129| **ID**| **Error Message** | 130| ------------ | ----------------------------------------------------------- | 131| 14800010 | Failed to open or delete database by invalid database path. | 132| 14800011 | Failed to open database by database corrupted. | 133| 14800000 | Inner error. | 134| 14801001 | Only supported in stage mode. | 135| 14801002 | The data group id is not valid. | 136 137**Example** 138 139FA model: 140 141```js 142import featureAbility from '@ohos.ability.featureAbility'; 143import { BusinessError } from "@ohos.base"; 144 145let store: relationalStore.RdbStore | undefined = undefined; 146let context = getContext(this); 147 148const STORE_CONFIG: relationalStore.StoreConfig = { 149 name: "RdbTest.db", 150 securityLevel: relationalStore.SecurityLevel.S1 151}; 152 153relationalStore.getRdbStore(context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 154 store = rdbStore; 155 console.info('Get RdbStore successfully.') 156}).catch((err: BusinessError) => { 157 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 158}) 159``` 160 161Stage model: 162 163```ts 164import UIAbility from '@ohos.app.ability.UIAbility'; 165import window from '@ohos.window'; 166import { BusinessError } from "@ohos.base"; 167 168let store: relationalStore.RdbStore | undefined = undefined; 169 170class EntryAbility extends UIAbility { 171 onWindowStageCreate(windowStage: window.WindowStage) { 172 const STORE_CONFIG: relationalStore.StoreConfig = { 173 name: "RdbTest.db", 174 securityLevel: relationalStore.SecurityLevel.S1 175 }; 176 177 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 178 store = rdbStore; 179 console.info('Get RdbStore successfully.') 180 }).catch((err: BusinessError) => { 181 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 182 }) 183 } 184} 185``` 186 187## relationalStore.deleteRdbStore 188 189deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void 190 191Deletes an RDB store. This API uses an asynchronous callback to return the result. 192 193After the deletion, you are advised to set the database object to null. If a customized path is set in [StoreConfig](#storeconfig) when an RDB store is created, using this API cannot delete the RDB store. Use [deleteRdbStore<sup>10+</sup>](#relationalstoredeleterdbstore10) instead. 194 195**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 196 197**Parameters** 198 199| Name | Type | Mandatory| Description | 200| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 201| 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).| 202| name | string | Yes | Name of the RDB store to delete. | 203| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | 204 205**Error codes** 206 207For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 208 209| **ID**| **Error Message** | 210| ------------ | ----------------------------------------------------------- | 211| 14800010 | Failed to open or delete database by invalid database path. | 212| 14800000 | Inner error. | 213 214**Example** 215 216FA model: 217 218```js 219import featureAbility from '@ohos.ability.featureAbility'; 220import { BusinessError } from "@ohos.base"; 221 222let store: relationalStore.RdbStore | undefined = undefined; 223let context = getContext(this); 224 225relationalStore.deleteRdbStore(context, "RdbTest.db", (err: BusinessError) => { 226 if (err) { 227 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 228 return; 229 } 230 store = undefined; 231 console.info('Delete RdbStore successfully.'); 232}) 233``` 234 235Stage model: 236 237```ts 238import UIAbility from '@ohos.app.ability.UIAbility'; 239import window from '@ohos.window'; 240import { BusinessError } from "@ohos.base"; 241 242let store: relationalStore.RdbStore | undefined = undefined; 243 244class EntryAbility extends UIAbility { 245 onWindowStageCreate(windowStage: window.WindowStage){ 246 relationalStore.deleteRdbStore(this.context, "RdbTest.db", (err: BusinessError) => { 247 if (err) { 248 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 249 return; 250 } 251 store = undefined; 252 console.info('Delete RdbStore successfully.'); 253 }) 254 } 255} 256``` 257 258## relationalStore.deleteRdbStore 259 260deleteRdbStore(context: Context, name: string): Promise<void> 261 262Deletes an RDB store. This API uses a promise to return the result. 263 264After the deletion, you are advised to set the database object to null. If a customized path is set in [StoreConfig](#storeconfig) when an RDB store is created, using this API cannot delete the RDB store. Use [deleteRdbStore<sup>10+</sup>](#relationalstoredeleterdbstore10-1) instead. 265 266**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 267 268**Parameters** 269 270| Name | Type | Mandatory| Description | 271| ------- | ------- | ---- | ------------------------------------------------------------ | 272| 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).| 273| name | string | Yes | Name of the RDB store to delete. | 274 275**Return value** 276 277| Type | Description | 278| ------------------- | ------------------------- | 279| Promise<void> | Promise that returns no value.| 280 281**Error codes** 282 283For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 284 285| **ID**| **Error Message** | 286| ------------ | ----------------------------------------------------------- | 287| 14800010 | Failed to open or delete database by invalid database path. | 288| 14800000 | Inner error. | 289 290**Example** 291 292FA model: 293 294```js 295import featureAbility from '@ohos.ability.featureAbility'; 296import { BusinessError } from "@ohos.base"; 297 298let store: relationalStore.RdbStore | undefined = undefined; 299let context = getContext(this); 300 301relationalStore.deleteRdbStore(context, "RdbTest.db").then(()=>{ 302 store = undefined; 303 console.info('Delete RdbStore successfully.'); 304}).catch((err: BusinessError) => { 305 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 306}) 307``` 308 309Stage model: 310 311```ts 312import UIAbility from '@ohos.app.ability.UIAbility'; 313import window from '@ohos.window'; 314import { BusinessError } from "@ohos.base"; 315 316let store: relationalStore.RdbStore | undefined = undefined; 317 318class EntryAbility extends UIAbility { 319 onWindowStageCreate(windowStage: window.WindowStage){ 320 relationalStore.deleteRdbStore(this.context, "RdbTest.db").then(()=>{ 321 store = undefined; 322 console.info('Delete RdbStore successfully.'); 323 }).catch((err: BusinessError) => { 324 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 325 }) 326 } 327} 328``` 329 330## relationalStore.deleteRdbStore<sup>10+</sup> 331 332deleteRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback\<void>): void 333 334Deletes an RDB store. This API uses an asynchronous callback to return the result. 335 336After 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). 337 338**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 339 340**Parameters** 341 342| Name | Type | Mandatory| Description | 343| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 344| 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).| 345| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 346| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | 347 348**Error codes** 349 350For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 351 352| **ID**| **Error Message** | 353| ------------ | ----------------------------------------------------------- | 354| 14800010 | Failed to open or delete database by invalid database path. | 355| 14800000 | Inner error. | 356| 14801001 | Only supported in stage mode. | 357| 14801002 | The data group id is not valid. | 358 359**Example** 360 361FA model: 362 363```js 364import featureAbility from '@ohos.ability.featureAbility'; 365import { BusinessError } from "@ohos.base"; 366 367let store: relationalStore.RdbStore | undefined = undefined; 368let context = getContext(this); 369 370const STORE_CONFIG: relationalStore.StoreConfig = { 371 name: "RdbTest.db", 372 securityLevel: relationalStore.SecurityLevel.S1 373}; 374 375relationalStore.deleteRdbStore(context, STORE_CONFIG, (err: BusinessError) => { 376 if (err) { 377 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 378 return; 379 } 380 store = undefined; 381 console.info('Delete RdbStore successfully.'); 382}) 383``` 384 385Stage model: 386 387```ts 388import UIAbility from '@ohos.app.ability.UIAbility'; 389import window from '@ohos.window'; 390import { BusinessError } from "@ohos.base"; 391 392let store: relationalStore.RdbStore | undefined = undefined; 393 394class EntryAbility extends UIAbility { 395 onWindowStageCreate(windowStage: window.WindowStage){ 396 const STORE_CONFIG: relationalStore.StoreConfig = { 397 name: "RdbTest.db", 398 securityLevel: relationalStore.SecurityLevel.S1 399 }; 400 relationalStore.deleteRdbStore(this.context, STORE_CONFIG, (err: BusinessError) => { 401 if (err) { 402 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 403 return; 404 } 405 store = undefined; 406 console.info('Delete RdbStore successfully.'); 407 }) 408 } 409} 410 411``` 412 413## relationalStore.deleteRdbStore<sup>10+</sup> 414 415deleteRdbStore(context: Context, config: StoreConfig): Promise\<void> 416 417Deletes an RDB store. This API uses a promise to return the result. 418 419After 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). 420 421**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 422 423**Parameters** 424 425| Name | Type | Mandatory| Description | 426| ------- | --------------------------- | ---- | ------------------------------------------------------------ | 427| 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).| 428| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | 429 430**Return value** 431 432| Type | Description | 433| ------------------- | ------------------------- | 434| Promise<void> | Promise that returns no value.| 435 436**Error codes** 437 438For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 439 440| **ID**| **Error Message** | 441| ------------ | ----------------------------------------------------------- | 442| 14800010 | Failed to open or delete database by invalid database path. | 443| 14800000 | Inner error. | 444| 14801001 | Only supported in stage mode. | 445| 14801002 | The data group id is not valid. | 446 447**Example** 448 449FA model: 450 451```js 452import featureAbility from '@ohos.ability.featureAbility'; 453import { BusinessError } from "@ohos.base"; 454 455let store: relationalStore.RdbStore | undefined = undefined; 456let context = getContext(this); 457 458const STORE_CONFIG: relationalStore.StoreConfig = { 459 name: "RdbTest.db", 460 securityLevel: relationalStore.SecurityLevel.S1 461}; 462 463relationalStore.deleteRdbStore(context, STORE_CONFIG).then(()=>{ 464 store = undefined; 465 console.info('Delete RdbStore successfully.'); 466}).catch((err: BusinessError) => { 467 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 468}) 469``` 470 471Stage model: 472 473```ts 474import UIAbility from '@ohos.app.ability.UIAbility'; 475import window from '@ohos.window'; 476import { BusinessError } from "@ohos.base"; 477 478let store: relationalStore.RdbStore | undefined = undefined; 479 480class EntryAbility extends UIAbility { 481 onWindowStageCreate(windowStage: window.WindowStage){ 482 const STORE_CONFIG: relationalStore.StoreConfig = { 483 name: "RdbTest.db", 484 securityLevel: relationalStore.SecurityLevel.S1 485 }; 486 relationalStore.deleteRdbStore(this.context, STORE_CONFIG).then(()=>{ 487 store = undefined; 488 console.info('Delete RdbStore successfully.'); 489 }).catch((err: BusinessError) => { 490 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 491 }) 492 } 493} 494``` 495 496## StoreConfig 497 498Defines the RDB store configuration. 499 500| Name | Type | Mandatory| Description | 501| ------------- | ------------- | ---- | --------------------------------------------------------- | 502| name | string | Yes | Database file name, which is the unique identifier of the database.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 503| securityLevel | [SecurityLevel](#securitylevel) | Yes | Security level of the RDB store.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 504| encrypt | boolean | No | Whether to encrypt the RDB store.<br>The value **true** means to encrypt the RDB store; the value **false** (default) means the opposite.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 505| dataGroupId<sup>10+</sup> | string | No| Application group ID, which needs to be obtained from AppGallery.<br>**Model restriction**: This attribute can be used only in the stage model.<br>This parameter is supported since API version 10. The **RdbStore** instance is created in the sandbox directory corresponding to the specified **dataGroupId**. If this parameter is not specified, the **RdbStore** instance is created in the sandbox directory of the application.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 506| customDir<sup>11+</sup> | string | No| Customized path of the RDB store.<br>**Constraints**: The value cannot exceed 128 bytes.<br>This parameter is supported since API version 11. The RDB store directory is in the **context.databaseDir**/**rdb**/**customDir** format. **context.databaseDir** specifies the application sandbox path. **rdb** is a fixed field that indicates an RDB store. **customDir** specifies the customized path. If this parameter is not specified, the **RdbStore** instance is created in the sandbox directory of the application.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 507| autoCleanDirtyData<sup>11+<sup> | boolean | No| Whether to automatically clear the dirty data (data that has been deleted from the cloud) from the local device. The value **true** means to clear the dirty data automatically. The value **false** means to clear the data manually. The default value is **true**.<br>This parameter applies to the RDB stores with device-cloud synergy. To manually clear the dirty data, use [cleanDirtyData<sup>11+</sup>](#cleandirtydata11).<br>This parameter is supported since API version 11.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 508 509## SecurityLevel 510 511Enumerates the RDB store security levels. Use the enum name rather than the enum value. 512 513> **NOTE** 514> 515> To perform data synchronization operations, the RDB store security level must be lower than or equal to that of the peer device. For details, see the [Access Control Mechanism in Cross-Device Synchronization](../../database/access-control-by-device-and-data-level.md#access-control-mechanism-in-cross-device-synchronization). 516 517**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 518 519| Name| Value | Description | 520| ---- | ---- | ------------------------------------------------------------ | 521| 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.| 522| 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.| 523| 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.| 524| 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.| 525 526## AssetStatus<sup>10+</sup> 527 528Enumerates the asset statuses. Use the enum name rather than the enum value. 529 530**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 531 532| Name | Value | Description | 533| ------------------------------- | --- | -------------- | 534| ASSET_NORMAL | 1 | The asset is in normal status. | 535| ASSET_INSERT | 2 | The asset is to be inserted to the cloud.| 536| ASSET_UPDATE | 3 | The asset is to be updated to the cloud.| 537| ASSET_DELETE | 4 | The asset is to be deleted from the cloud.| 538| ASSET_ABNORMAL | 5 | The asset is in abnormal status. | 539| ASSET_DOWNLOADING | 6 | The asset is being downloaded to a local device.| 540 541## Asset<sup>10+</sup> 542 543Defines information about an asset (such as a document, image, and video). The asset APIs do not support **Datashare**. 544 545**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 546 547| Name | Type | Mandatory | Description | 548| ----------- | --------------------------- | --- | ------------ | 549| name | string | Yes | Asset name. | 550| uri | string | Yes | Asset URI, which is an absolute path in the system. | 551| path | string | Yes | Application sandbox path of the asset. | 552| createTime | string | Yes | Time when the asset was created. | 553| modifyTime | string | Yes | Time when the asset was last modified.| 554| size | string | Yes | Size of the asset. | 555| status | [AssetStatus](#assetstatus10) | No | Asset status. The default value is **ASSET_NORMAL**. | 556 557## Assets<sup>10+</sup> 558 559Defines an array of the [Asset](#asset10) type. 560 561**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 562 563| Type | Description | 564| ------- | -------------------- | 565| [Asset](#asset10)[] | Array of assets. | 566 567## ValueType 568 569Enumerates the types of the value in a KV pair. The type varies with the parameter function. 570 571**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 572 573| Type | Description | 574| ------- | -------------------- | 575| null<sup>10+</sup> | Null. | 576| number | Number. | 577| string | String. | 578| boolean | Boolean.| 579| Uint8Array<sup>10+</sup> | Uint8 array. | 580| Asset<sup>10+</sup> | [Asset](#asset10). | 581| Assets<sup>10+</sup> | [Assets](#assets10).| 582 583## ValuesBucket 584 585Enumerates the types of the key in a KV pair. This type is not multi-thread safe. If a **ValuesBucket** instance is operated by multiple threads at the same time in an application, use a lock for the instance. 586 587**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 588 589| Key Type| Value Type | 590| ------ | ----------------------- | 591| number | The primary key is a number.| 592| string | The primary key is a string.| 593 594## PRIKeyType<sup>10+</sup> 595 596Enumerates the types of the primary key in a row of a database table. 597 598**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 599 600| Type | Description | 601| ---------------- | ---------------------------------- | 602| number | The primary key is a number.| 603| string | The primary key is a string.| 604 605## UTCTime<sup>10+</sup> 606 607Represents the data type of the UTC time. 608 609**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 610 611| Type| Description | 612| ---- | --------------- | 613| Date | UTC time.| 614 615## ModifyTime<sup>10+</sup> 616 617Represents the data type of the primary key and modification time of a database table. 618 619**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 620 621| Type | Description | 622| ------------------------------------------------------- | ------------------------------------------------------------ | 623| 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.| 624 625## SyncMode 626 627Enumerates the database synchronization modes. Use the enum name rather than the enum value. 628 629| Name | Value | Description | 630| -------------- | ---- | ---------------------------------- | 631| SYNC_MODE_PUSH | 0 | Push data from a local device to a remote device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 632| SYNC_MODE_PULL | 1 | Pull data from a remote device to a local device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 633| SYNC_MODE_TIME_FIRST<sup>10+</sup> | 4 | Synchronize with the data with the latest modification time.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 634| SYNC_MODE_NATIVE_FIRST<sup>10+</sup> | 5 | Synchronize data from a local device to the cloud.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 635| SYNC_MODE_CLOUD_FIRST<sup>10+</sup> | 6 | Synchronize data from the cloud to a local device.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 636 637## Origin<sup>11+</sup> 638 639Enumerates the data sources. Use the enum name rather than the enum value. 640 641**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 642 643| Name | Value | Description | 644| -------------- | ---- | ---------------------------------- | 645| LOCAL | 0 | Local data. | 646| CLOUD | 1 | Cloud data. | 647| REMOTE | 2 | Remote device data.| 648 649## Field<sup>11+</sup> 650 651Enumerates the special fields used in predicates. Use the enum name rather than the enum value. 652 653**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 654 655| Name | Value | Description | 656| -------------- | ---- | ---------------------------------- | 657| CURSOR_FIELD | '#_cursor' | Field name to be searched based on the cursor.| 658| ORIGIN_FIELD | '#_origin' | Data source to be searched based on the cursor. | 659| 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 on the search based on the cursor. <br>The value **true** means the dirty data is cleared; the value **false** means the opposite.| 660| 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.| 661| 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.| 662| SHARING_RESOURCE_FIELD | '#_sharing_resource_field' | Resource shared. It fills in the result set returned when the shared resource is searched.| 663 664## SubscribeType 665 666Enumerates the subscription types. Use the enum name rather than the enum value. 667 668**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 669 670| Name | Value | Description | 671| --------------------- | ---- | ------------------ | 672| SUBSCRIBE_TYPE_REMOTE | 0 | Subscribe to remote data changes.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core| 673| SUBSCRIBE_TYPE_CLOUD<sup>10+</sup> | 1 | Subscribe to cloud data changes.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 674| SUBSCRIBE_TYPE_CLOUD_DETAILS<sup>10+</sup> | 2 | Subscribe to cloud data change details.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 675 676## ChangeType<sup>10+</sup> 677 678Enumerates data change types. Use the enum name rather than the enum value. 679 680**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 681 682**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 683 684| Name | Value | Description | 685| -------------------------- | --- | -------------------------- | 686| DATA_CHANGE | 0 | Data change. | 687| ASSET_CHANGE | 1 | Asset change.| 688 689## ChangeInfo<sup>10+</sup> 690 691Defines the details about the device-cloud synchronization process. 692 693**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 694 695| Name | Type | Mandatory| Description | 696| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ | 697| table | string | Yes | Name of the table with data changes. | 698| type | [ChangeType](#changetype10) | Yes | Type of the data changed, which can be data or asset. | 699| 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.| 700| 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.| 701| 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.| 702 703## DistributedType<sup>10+</sup> 704 705Enumerates the distributed table types. Use the enum name rather than the enum value. 706 707**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 708 709| Name | Value | Description | 710| ------------------ | --- | -------------------------------------------------------------------------------------------------- | 711| DISTRIBUTED_DEVICE | 0 | Distributed database table synchronized between devices.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | 712| DISTRIBUTED_CLOUD | 1 | Distributed database table synchronized between the device and the cloud.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client| 713 714## DistributedConfig<sup>10+</sup> 715 716Defines the configuration of the distributed mode of tables. 717 718**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 719 720| Name | Type | Mandatory| Description | 721| -------- | ------- | ---- | ------------------------------------------------------------ | 722| autoSync | boolean | Yes | The value **true** means both automatic synchronization and manual synchronization are supported for the table. The value **false** means only manual synchronization is supported for the table.| 723 724## ConflictResolution<sup>10+</sup> 725 726Defines the resolution to use when **insert()** and **update()** conflict. Use the enum name rather than the enum value. 727 728**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 729 730| Name | Value | Description | 731| -------------------- | ---- | ------------------------------------------------------------ | 732| ON_CONFLICT_NONE | 0 | No operation is performed.| 733| ON_CONFLICT_ROLLBACK | 1 | Abort the SQL statement and roll back the current transaction. | 734| 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.| 735| 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.| 736| ON_CONFLICT_IGNORE | 4 | Skip the rows that contain constraint violations and continue to process the subsequent rows of the SQL statement.| 737| 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.| 738 739## Progress<sup>10+</sup> 740 741Enumerates the device-cloud synchronization processes. Use the enum name rather than the enum value. 742 743**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 744 745| Name | Value | Description | 746| ---------------- | ---- | ------------------------ | 747| SYNC_BEGIN | 0 | The device-cloud synchronization starts. | 748| SYNC_IN_PROGRESS | 1 | The device-cloud synchronization is in progress.| 749| SYNC_FINISH | 2 | The device-cloud synchronization is complete.| 750 751## Statistic<sup>10+</sup> 752 753Represents the device-cloud synchronization statistics information. 754 755**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 756 757| Name | Type | Mandatory| Description | 758| ---------- | ------ | ---- | ---------------------------------------- | 759| total | number | Yes | Total number of rows to be synchronized between the device and cloud in the database table. | 760| successful | number | Yes | Number of rows that are successfully synchronized between the device and cloud in the database table. | 761| failed | number | Yes | Number of rows that failed to be synchronized between the device and cloud in the database table. | 762| remained | number | Yes | Number of rows that are not executed for device-cloud synchronization in the database table.| 763 764## TableDetails<sup>10+</sup> 765 766Represents the upload and download statistics of device-cloud synchronization tasks. 767 768**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 769 770| Name | Type | Mandatory| Description | 771| -------- | ------------------------- | ---- | ------------------------------------------ | 772| upload | [Statistic](#statistic10) | Yes | Statistics of the device-cloud upload tasks.| 773| download | [Statistic](#statistic10) | Yes | Statistics of the device-cloud download tasks.| 774 775## ProgressCode<sup>10+</sup> 776 777Enumerates the device-cloud synchronization states. Use the enum name rather than the enum value. 778 779**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 780 781| Name | Value | Description | 782| --------------------- | ---- | ------------------------------------------------------------ | 783| SUCCESS | 0 | The device-cloud synchronization is successful. | 784| UNKNOWN_ERROR | 1 | An unknown error occurs during device-cloud synchronization. | 785| NETWORK_ERROR | 2 | A network error occurs during device-cloud synchronization. | 786| CLOUD_DISABLED | 3 | The cloud is unavailable. | 787| LOCKED_BY_OTHERS | 4 | The device-cloud synchronization of another device is being performed.<br>Start device-cloud synchronization after checking that cloud resources are not occupied by other devices.| 788| 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.| 789| NO_SPACE_FOR_ASSET | 6 | The remaining cloud space is less than the size of the data to be synchronized. | 790 791## ProgressDetails<sup>10+</sup> 792 793Represents the statistics of the overall device-cloud synchronization (upload and download) tasks. 794 795**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 796 797| Name | Type | Mandatory| Description | 798| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | 799| schedule | [Progress](#progress10) | Yes | Device-cloud synchronization process. | 800| code | [ProgressCode](#progresscode10) | Yes | Device-cloud synchronization state. | 801| details | Record<string, [TableDetails](#tabledetails10)> | Yes | Statistics of each table.<br>The key indicates the table name, and the value indicates the device-cloud synchronization statistics of the table.| 802 803## RdbPredicates 804 805Defines the predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false. This type is not multi-thread safe. If an **RdbPredicates** instance is operated by multiple threads at the same time in an application, use a lock for the instance. 806 807### constructor 808 809constructor(name: string) 810 811A constructor used to create an **RdbPredicates** object. 812 813**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 814 815**Parameters** 816 817| Name| Type | Mandatory| Description | 818| ------ | ------ | ---- | ------------ | 819| name | string | Yes | Database table name.| 820 821**Example** 822 823```ts 824let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 825``` 826 827### inDevices 828 829inDevices(devices: Array<string>): RdbPredicates 830 831Sets an **RdbPredicates** to specify the remote devices to connect on the network during distributed database synchronization. 832 833> **NOTE** 834> 835> **devices** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 836If **inDevices** is specified in **predicates** when **sync()** is called, data is synchronized with the specified device. If **inDevices** is not specified, data is synchronized with all devices on the network by default. 837 838**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 839 840**Parameters** 841 842| Name | Type | Mandatory| Description | 843| ------- | ------------------- | ---- | -------------------------- | 844| devices | Array<string> | Yes | IDs of the remote devices in the same network.| 845 846**Return value** 847 848| Type | Description | 849| ------------------------------------ | -------------------------- | 850| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 851 852**Example** 853 854```ts 855import deviceManager from '@ohos.distributedDeviceManager'; 856 857let dmInstance: deviceManager.DeviceManager; 858let deviceIds: Array<string> = []; 859 860try { 861 dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify"); 862 let devices: Array<deviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 863 for (let i = 0; i < devices.length; i++) { 864 deviceIds[i] = devices[i].networkId!; 865 } 866} catch (err) { 867 let code = (err as BusinessError).code; 868 let message = (err as BusinessError).message 869 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 870} 871 872let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 873predicates.inDevices(deviceIds); 874``` 875 876### inAllDevices 877 878inAllDevices(): RdbPredicates 879 880 881Sets an **RdbPredicates** to specify all remote devices on the network to connect during distributed database synchronization. 882 883 884**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 885 886**Return value** 887 888| Type | Description | 889| ------------------------------------ | -------------------------- | 890| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 891 892**Example** 893 894```ts 895let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 896predicates.inAllDevices(); 897``` 898 899### equalTo 900 901equalTo(field: string, value: ValueType): RdbPredicates 902 903 904Sets an **RdbPredicates** object to match the fields in the specified column that are equal to the given value. 905 906**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 907 908**Parameters** 909 910| Name| Type | Mandatory| Description | 911| ------ | ----------------------- | ---- | ---------------------- | 912| field | string | Yes | Column name in the database table. | 913| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 914 915**Return value** 916 917| Type | Description | 918| ------------------------------------ | -------------------------- | 919| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 920 921**Example** 922 923```ts 924// Locate data of Lisa in the EMPLOYEE table. 925let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 926predicates.equalTo("NAME", "Lisa"); 927``` 928 929 930### notEqualTo 931 932notEqualTo(field: string, value: ValueType): RdbPredicates 933 934 935Sets an **RdbPredicates** object to match the fields in the specified column that are not equal to the given value. 936 937**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 938 939**Parameters** 940 941| Name| Type | Mandatory| Description | 942| ------ | ----------------------- | ---- | ---------------------- | 943| field | string | Yes | Column name in the database table. | 944| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 945 946**Return value** 947 948| Type | Description | 949| ------------------------------------ | -------------------------- | 950| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 951 952**Example** 953 954```ts 955// Locate data of the employees whose name is not Lisa in the table. 956let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 957predicates.notEqualTo("NAME", "Lisa"); 958``` 959 960 961### beginWrap 962 963beginWrap(): RdbPredicates 964 965 966Adds a left parenthesis to the **RdbPredicates**. 967 968**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 969 970**Return value** 971 972| Type | Description | 973| ------------------------------------ | ------------------------- | 974| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.| 975 976**Example** 977 978```ts 979let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 980predicates.equalTo("NAME", "Lisa") 981 .beginWrap() 982 .equalTo("AGE", 18) 983 .or() 984 .equalTo("SALARY", 200.5) 985 .endWrap() 986``` 987 988### endWrap 989 990endWrap(): RdbPredicates 991 992Adds a right parenthesis to the **RdbPredicates**. 993 994**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 995 996**Return value** 997 998| Type | Description | 999| ------------------------------------ | ------------------------- | 1000| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.| 1001 1002**Example** 1003 1004```ts 1005let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1006predicates.equalTo("NAME", "Lisa") 1007 .beginWrap() 1008 .equalTo("AGE", 18) 1009 .or() 1010 .equalTo("SALARY", 200.5) 1011 .endWrap() 1012``` 1013 1014### or 1015 1016or(): RdbPredicates 1017 1018Adds the OR condition to the **RdbPredicates**. 1019 1020**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1021 1022**Return value** 1023 1024| Type | Description | 1025| ------------------------------------ | ------------------------- | 1026| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.| 1027 1028**Example** 1029 1030```ts 1031// Locate the employees named Lisa or Rose in the table. 1032let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1033predicates.equalTo("NAME", "Lisa") 1034 .or() 1035 .equalTo("NAME", "Rose") 1036``` 1037 1038### and 1039 1040and(): RdbPredicates 1041 1042Adds the AND condition to the **RdbPredicates**. 1043 1044**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1045 1046**Return value** 1047 1048| Type | Description | 1049| ------------------------------------ | ------------------------- | 1050| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.| 1051 1052**Example** 1053 1054```ts 1055// Locate the field with name of Lisa and salary of 200.5 in the table. 1056let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1057predicates.equalTo("NAME", "Lisa") 1058 .and() 1059 .equalTo("SALARY", 200.5) 1060``` 1061 1062### contains 1063 1064contains(field: string, value: string): RdbPredicates 1065 1066Sets an **RdbPredicates** object to match the fields in the specified column that contain the given value. 1067 1068**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1069 1070**Parameters** 1071 1072| Name| Type | Mandatory| Description | 1073| ------ | ------ | ---- | ---------------------- | 1074| field | string | Yes | Column name in the database table. | 1075| value | string | Yes | Value to match the **RdbPredicates**.| 1076 1077**Return value** 1078 1079| Type | Description | 1080| ------------------------------------ | -------------------------- | 1081| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1082 1083**Example** 1084 1085```ts 1086// Locate data of the employees whose name contains os, for example, Rose, in the table. 1087let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1088predicates.contains("NAME", "os"); 1089``` 1090 1091### beginsWith 1092 1093beginsWith(field: string, value: string): RdbPredicates 1094 1095Sets an **RdbPredicates** object to match the fields in the specified column that begin with the given value. 1096 1097**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1098 1099**Parameters** 1100 1101| Name| Type | Mandatory| Description | 1102| ------ | ------ | ---- | ---------------------- | 1103| field | string | Yes | Column name in the database table. | 1104| value | string | Yes | Value to match the **RdbPredicates**.| 1105 1106**Return value** 1107 1108| Type | Description | 1109| ------------------------------------ | -------------------------- | 1110| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1111 1112**Example** 1113 1114```ts 1115// Locate data of the employees whose name begins with Li, for example, Lisa, in the table. 1116let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1117predicates.beginsWith("NAME", "Li"); 1118``` 1119 1120### endsWith 1121 1122endsWith(field: string, value: string): RdbPredicates 1123 1124Sets an **RdbPredicates** object to match the fields in the specified column that end with the given value. 1125 1126**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1127 1128**Parameters** 1129 1130| Name| Type | Mandatory| Description | 1131| ------ | ------ | ---- | ---------------------- | 1132| field | string | Yes | Column name in the database table. | 1133| value | string | Yes | Value to match the **RdbPredicates**.| 1134 1135**Return value** 1136 1137| Type | Description | 1138| ------------------------------------ | -------------------------- | 1139| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1140 1141**Example** 1142 1143```ts 1144// Locate data of the employees whose name ends with se, for example, Rose, in the table. 1145let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1146predicates.endsWith("NAME", "se"); 1147``` 1148 1149### isNull 1150 1151isNull(field: string): RdbPredicates 1152 1153Sets an **RdbPredicates** object to match the fields in the specified column that are **null**. 1154 1155**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1156 1157**Parameters** 1158 1159| Name| Type | Mandatory| Description | 1160| ------ | ------ | ---- | ------------------ | 1161| field | string | Yes | Column name in the database table.| 1162 1163**Return value** 1164 1165| Type | Description | 1166| ------------------------------------ | -------------------------- | 1167| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1168 1169**Example** 1170 1171```ts 1172let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1173predicates.isNull("NAME"); 1174``` 1175 1176### isNotNull 1177 1178isNotNull(field: string): RdbPredicates 1179 1180Sets an **RdbPredicates** object to match the fields in the specified column that are not **null**. 1181 1182**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1183 1184**Parameters** 1185 1186| Name| Type | Mandatory| Description | 1187| ------ | ------ | ---- | ------------------ | 1188| field | string | Yes | Column name in the database table.| 1189 1190**Return value** 1191 1192| Type | Description | 1193| ------------------------------------ | -------------------------- | 1194| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1195 1196**Example** 1197 1198```ts 1199let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1200predicates.isNotNull("NAME"); 1201``` 1202 1203### like 1204 1205like(field: string, value: string): RdbPredicates 1206 1207Sets an **RdbPredicates** object to match the fields in the specified column that are similar to the given value. 1208 1209**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1210 1211**Parameters** 1212 1213| Name| Type | Mandatory| Description | 1214| ------ | ------ | ---- | ---------------------- | 1215| field | string | Yes | Column name in the database table. | 1216| value | string | Yes | Value to match the **RdbPredicates**.| 1217 1218**Return value** 1219 1220| Type | Description | 1221| ------------------------------------ | -------------------------- | 1222| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1223 1224**Example** 1225 1226```ts 1227// Locate data of the employees whose name is similar to os in the table, for example, Rose. 1228let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1229predicates.like("NAME", "%os%"); 1230``` 1231 1232### glob 1233 1234glob(field: string, value: string): RdbPredicates 1235 1236Sets an **RdbPredicates** object to locate the fields in the specified column that match the given string. 1237 1238**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1239 1240**Parameters** 1241 1242| Name| Type | Mandatory| Description | 1243| ------ | ------ | ---- | ------------------------------------------------------------ | 1244| field | string | Yes | Column name in the database table. | 1245| value | string | Yes | Value to match the **RdbPredicates**.<br><br>Wildcards are supported. * indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character.| 1246 1247**Return value** 1248 1249| Type | Description | 1250| ------------------------------------ | -------------------------- | 1251| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1252 1253**Example** 1254 1255```ts 1256// Locate data of the employees whose name matches the "?h*g" string in the table. 1257let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1258predicates.glob("NAME", "?h*g"); 1259``` 1260 1261### between 1262 1263between(field: string, low: ValueType, high: ValueType): RdbPredicates 1264 1265Sets an **RdbPredicates** object to match the fields in the specified column that are within the given range (including the min. and max. values). 1266 1267**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1268 1269**Parameters** 1270 1271| Name| Type | Mandatory| Description | 1272| ------ | ----------------------- | ---- | -------------------------- | 1273| field | string | Yes | Column name in the database table. | 1274| low | [ValueType](#valuetype) | Yes | Minimum value to match. | 1275| high | [ValueType](#valuetype) | Yes | Maximum value to match.| 1276 1277**Return value** 1278 1279| Type | Description | 1280| ------------------------------------ | -------------------------- | 1281| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1282 1283**Example** 1284 1285```ts 1286// Locate data of the employees with age between 10 and 50 (including 10 and 50) in the table. 1287let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1288predicates.between("AGE", 10, 50); 1289``` 1290 1291### notBetween 1292 1293notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates 1294 1295Sets an **RdbPredicates** object to match the fields in the specified column that are out of the given range (excluding the min. and max. values). 1296 1297**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1298 1299**Parameters** 1300 1301| Name| Type | Mandatory| Description | 1302| ------ | ----------------------- | ---- | -------------------------- | 1303| field | string | Yes | Column name in the database table. | 1304| low | [ValueType](#valuetype) | Yes | Minimum value to match. | 1305| high | [ValueType](#valuetype) | Yes | Maximum value to match.| 1306 1307**Return value** 1308 1309| Type | Description | 1310| ------------------------------------ | -------------------------- | 1311| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1312 1313**Example** 1314 1315```ts 1316// Locate data of the employees who are younger than 10 or older than 50 in the table. 1317let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1318predicates.notBetween("AGE", 10, 50); 1319``` 1320 1321### greaterThan 1322 1323greaterThan(field: string, value: ValueType): RdbPredicates 1324 1325Sets an **RdbPredicates** object to match the fields in the specified column that are greater than the given value. 1326 1327**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1328 1329**Parameters** 1330 1331| Name| Type | Mandatory| Description | 1332| ------ | ----------------------- | ---- | ---------------------- | 1333| field | string | Yes | Column name in the database table. | 1334| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1335 1336**Return value** 1337 1338| Type | Description | 1339| ------------------------------------ | -------------------------- | 1340| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1341 1342**Example** 1343 1344```ts 1345// Locate data of the employees who are older than 18 in the table. 1346let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1347predicates.greaterThan("AGE", 18); 1348``` 1349 1350### lessThan 1351 1352lessThan(field: string, value: ValueType): RdbPredicates 1353 1354Sets an **RdbPredicates** object to match the fields in the specified column that are less than the given value. 1355 1356**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1357 1358**Parameters** 1359 1360| Name| Type | Mandatory| Description | 1361| ------ | ----------------------- | ---- | ---------------------- | 1362| field | string | Yes | Column name in the database table. | 1363| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1364 1365**Return value** 1366 1367| Type | Description | 1368| ------------------------------------ | -------------------------- | 1369| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1370 1371**Example** 1372 1373```ts 1374// Locate data of the employees who are younger than 20 in the table. 1375let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1376predicates.lessThan("AGE", 20); 1377``` 1378 1379### greaterThanOrEqualTo 1380 1381greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1382 1383Sets an **RdbPredicates** object to match the fields in the specified column that are greater than or equal to the given value. 1384 1385**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1386 1387**Parameters** 1388 1389| Name| Type | Mandatory| Description | 1390| ------ | ----------------------- | ---- | ---------------------- | 1391| field | string | Yes | Column name in the database table. | 1392| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1393 1394**Return value** 1395 1396| Type | Description | 1397| ------------------------------------ | -------------------------- | 1398| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1399 1400**Example** 1401 1402```ts 1403// Locate data of the employees who are 18 or older in the table. 1404let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1405predicates.greaterThanOrEqualTo("AGE", 18); 1406``` 1407 1408### lessThanOrEqualTo 1409 1410lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1411 1412Sets an **RdbPredicates** object to match the fields in the specified column that are less than or equal to the given value. 1413 1414**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1415 1416**Parameters** 1417 1418| Name| Type | Mandatory| Description | 1419| ------ | ----------------------- | ---- | ---------------------- | 1420| field | string | Yes | Column name in the database table. | 1421| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicates**.| 1422 1423**Return value** 1424 1425| Type | Description | 1426| ------------------------------------ | -------------------------- | 1427| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1428 1429**Example** 1430 1431```ts 1432// Locate data of the employees who are 20 or younger in the table. 1433let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1434predicates.lessThanOrEqualTo("AGE", 20); 1435``` 1436 1437### orderByAsc 1438 1439orderByAsc(field: string): RdbPredicates 1440 1441Sets an **RdbPredicates** object to sort the fields in the specified column in ascending order. 1442 1443**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1444 1445**Parameters** 1446 1447| Name| Type | Mandatory| Description | 1448| ------ | ------ | ---- | ------------------ | 1449| field | string | Yes | Column name in the database table.| 1450 1451**Return value** 1452 1453| Type | Description | 1454| ------------------------------------ | -------------------------- | 1455| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1456 1457**Example** 1458 1459```ts 1460let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1461predicates.orderByAsc("NAME"); 1462``` 1463 1464### orderByDesc 1465 1466orderByDesc(field: string): RdbPredicates 1467 1468Sets an **RdbPredicates** object to sort the fields in the specified column in descending order. 1469 1470**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1471 1472**Parameters** 1473 1474| Name| Type | Mandatory| Description | 1475| ------ | ------ | ---- | ------------------ | 1476| field | string | Yes | Column name in the database table.| 1477 1478**Return value** 1479 1480| Type | Description | 1481| ------------------------------------ | -------------------------- | 1482| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1483 1484**Example** 1485 1486```ts 1487let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1488predicates.orderByDesc("AGE"); 1489``` 1490 1491### distinct 1492 1493distinct(): RdbPredicates 1494 1495Sets an **RdbPredicates** object to filter out duplicate records. 1496 1497**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1498 1499**Return value** 1500 1501| Type | Description | 1502| ------------------------------------ | ------------------------------ | 1503| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.| 1504 1505**Example** 1506 1507```ts 1508let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1509predicates.equalTo("NAME", "Rose").distinct(); 1510``` 1511 1512### limitAs 1513 1514limitAs(value: number): RdbPredicates 1515 1516Sets an **RdbPredicates** object to specify the maximum number of records. 1517 1518**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1519 1520**Parameters** 1521 1522| Name| Type | Mandatory| Description | 1523| ------ | ------ | ---- | ---------------- | 1524| value | number | Yes | Maximum number of records.| 1525 1526**Return value** 1527 1528| Type | Description | 1529| ------------------------------------ | ------------------------------------ | 1530| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.| 1531 1532**Example** 1533 1534```ts 1535let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1536predicates.equalTo("NAME", "Rose").limitAs(3); 1537``` 1538 1539### offsetAs 1540 1541offsetAs(rowOffset: number): RdbPredicates 1542 1543Sets an **RdbPredicates** object to specify the start position of the returned result. 1544 1545**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1546 1547**Parameters** 1548 1549| Name | Type | Mandatory| Description | 1550| --------- | ------ | ---- | ---------------------------------- | 1551| rowOffset | number | Yes | Number of rows to offset from the beginning. The value is a positive integer.| 1552 1553**Return value** 1554 1555| Type | Description | 1556| ------------------------------------ | ------------------------------------ | 1557| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.| 1558 1559**Example** 1560 1561```ts 1562let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1563predicates.equalTo("NAME", "Rose").offsetAs(3); 1564``` 1565 1566### groupBy 1567 1568groupBy(fields: Array<string>): RdbPredicates 1569 1570Sets an **RdbPredicates** object to group rows that have the same value into summary rows. 1571 1572**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1573 1574**Parameters** 1575 1576| Name| Type | Mandatory| Description | 1577| ------ | ------------------- | ---- | -------------------- | 1578| fields | Array<string> | Yes | Names of columns to group.| 1579 1580**Return value** 1581 1582| Type | Description | 1583| ------------------------------------ | ---------------------- | 1584| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.| 1585 1586**Example** 1587 1588```ts 1589let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1590predicates.groupBy(["AGE", "NAME"]); 1591``` 1592 1593### indexedBy 1594 1595indexedBy(field: string): RdbPredicates 1596 1597Sets an **RdbPredicates** object to specify the index column. 1598 1599**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1600 1601**Parameters** 1602 1603| Name| Type | Mandatory| Description | 1604| ------ | ------ | ---- | -------------- | 1605| field | string | Yes | Name of the index column.| 1606 1607**Return value** 1608 1609 1610| Type | Description | 1611| ------------------------------------ | ------------------------------------- | 1612| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.| 1613 1614**Example** 1615 1616```ts 1617let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1618predicates.indexedBy("SALARY"); 1619``` 1620 1621### in 1622 1623in(field: string, value: Array<ValueType>): RdbPredicates 1624 1625Sets an **RdbPredicates** object to match the fields in the specified column that are in the given range. 1626 1627**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1628 1629**Parameters** 1630 1631| Name| Type | Mandatory| Description | 1632| ------ | ------------------------------------ | ---- | --------------------------------------- | 1633| field | string | Yes | Column name in the database table. | 1634| value | Array<[ValueType](#valuetype)> | Yes | Array of **ValueType**s to match.| 1635 1636**Return value** 1637 1638| Type | Description | 1639| ------------------------------------ | -------------------------- | 1640| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1641 1642**Example** 1643 1644```ts 1645// Locate data of the employees with age of [18, 20] in the table. 1646let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1647predicates.in("AGE", [18, 20]); 1648``` 1649 1650### notIn 1651 1652notIn(field: string, value: Array<ValueType>): RdbPredicates 1653 1654Sets an **RdbPredicates** object to match the fields in the specified column that are out of the given range. 1655 1656**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1657 1658**Parameters** 1659 1660| Name| Type | Mandatory| Description | 1661| ------ | ------------------------------------ | ---- | ------------------------------------- | 1662| field | string | Yes | Column name in the database table. | 1663| value | Array<[ValueType](#valuetype)> | Yes | Array of **ValueType**s to match.| 1664 1665**Return value** 1666 1667| Type | Description | 1668| ------------------------------------ | -------------------------- | 1669| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.| 1670 1671**Example** 1672 1673```ts 1674// Locate data of all the employees except Lisa and Rose in the table. 1675let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1676predicates.notIn("NAME", ["Lisa", "Rose"]); 1677``` 1678 1679## RdbStore 1680 1681Provides APIs to manage an RDB store. 1682 1683Before using the APIs of this class, use [executeSql](#executesql) to initialize the database table structure and related data. 1684 1685### Attributes<sup>10+</sup> 1686 1687**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1688 1689| Name | Type | Mandatory| Description | 1690| ------------ | ----------- | ---- | -------------------------------- | 1691| version<sup>10+</sup> | number | Yes | RDB store version, which is an integer greater than 0. | 1692 1693**Example** 1694 1695```ts 1696// Set the RDB store version. 1697if(store != undefined) { 1698 (store as relationalStore.RdbStore).version = 3; 1699 // Obtain the RDB store version. 1700 console.info(`RdbStore version is ${store.version}`); 1701} 1702``` 1703 1704### insert 1705 1706insert(table: string, values: ValuesBucket, callback: AsyncCallback<number>):void 1707 1708Inserts 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. 1709 1710**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1711 1712**Parameters** 1713 1714| Name | Type | Mandatory| Description | 1715| -------- | ----------------------------- | ---- | ---------------------------------------------------------- | 1716| table | string | Yes | Name of the target table. | 1717| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 1718| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 1719 1720**Error codes** 1721 1722For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 1723 1724| **ID**| **Error Message** | 1725| ------------ | -------------------------------------------- | 1726| 14800047 | The WAL file size exceeds the default limit. | 1727| 14800000 | Inner error. | 1728 1729**Example** 1730 1731```ts 1732import { ValuesBucket } from '@ohos.data.ValuesBucket'; 1733 1734let key1 = "NAME"; 1735let key2 = "AGE"; 1736let key3 = "SALARY"; 1737let key4 = "CODES"; 1738let value1 = "Lisa"; 1739let value2 = 18; 1740let value3 = 100.5; 1741let value4 = new Uint8Array([1, 2, 3, 4, 5]); 1742const valueBucket: ValuesBucket = { 1743 key1: value1, 1744 key2: value2, 1745 key3: value3, 1746 key4: value4, 1747}; 1748if(store != undefined) { 1749 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket, (err: BusinessError, rowId: number) => { 1750 if (err) { 1751 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 1752 return; 1753 } 1754 console.info(`Insert is successful, rowId = ${rowId}`); 1755 }) 1756} 1757``` 1758 1759### insert<sup>10+</sup> 1760 1761insert(table: string, values: ValuesBucket, conflict: ConflictResolution, callback: AsyncCallback<number>):void 1762 1763Inserts 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. 1764 1765**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1766 1767**Parameters** 1768 1769| Name | Type | Mandatory| Description | 1770| -------- | ------------------------------------------- | ---- | ---------------------------------------------------------- | 1771| table | string | Yes | Name of the target table. | 1772| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. | 1773| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 1774| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 1775 1776**Error codes** 1777 1778For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 1779 1780| **ID**| **Error Message** | 1781| ------------ | -------------------------------------------- | 1782| 14800047 | The WAL file size exceeds the default limit. | 1783| 14800000 | Inner error. | 1784 1785**Example** 1786 1787```ts 1788import { ValuesBucket } from '@ohos.data.ValuesBucket'; 1789 1790let key1 = "NAME"; 1791let key2 = "AGE"; 1792let key3 = "SALARY"; 1793let key4 = "CODES"; 1794let value1 = "Lisa"; 1795let value2 = 18; 1796let value3 = 100.5; 1797let value4 = new Uint8Array([1, 2, 3, 4, 5]); 1798const valueBucket: ValuesBucket = { 1799 key1: value1, 1800 key2: value2, 1801 key3: value3, 1802 key4: value4, 1803}; 1804if(store != undefined) { 1805 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, 1806 (err: BusinessError, rowId: number) => { 1807 if (err) { 1808 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 1809 return; 1810 } 1811 console.info(`Insert is successful, rowId = ${rowId}`); 1812 }) 1813} 1814``` 1815 1816### insert 1817 1818insert(table: string, values: ValuesBucket):Promise<number> 1819 1820Inserts 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. 1821 1822**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1823 1824**Parameters** 1825 1826| Name| Type | Mandatory| Description | 1827| ------ | ----------------------------- | ---- | -------------------------- | 1828| table | string | Yes | Name of the target table. | 1829| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 1830 1831**Return value** 1832 1833| Type | Description | 1834| --------------------- | ------------------------------------------------- | 1835| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 1836 1837**Error codes** 1838 1839For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 1840 1841| **ID**| **Error Message** | 1842| ------------ | -------------------------------------------- | 1843| 14800047 | The WAL file size exceeds the default limit. | 1844| 14800000 | Inner error. | 1845 1846**Example** 1847 1848```ts 1849import { ValuesBucket } from '@ohos.data.ValuesBucket'; 1850import { BusinessError } from "@ohos.base"; 1851 1852let key1 = "NAME"; 1853let key2 = "AGE"; 1854let key3 = "SALARY"; 1855let key4 = "CODES"; 1856let value1 = "Lisa"; 1857let value2 = 18; 1858let value3 = 100.5; 1859let value4 = new Uint8Array([1, 2, 3, 4, 5]); 1860const valueBucket: ValuesBucket = { 1861 key1: value1, 1862 key2: value2, 1863 key3: value3, 1864 key4: value4, 1865}; 1866if(store != undefined) { 1867 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket).then((rowId: number) => { 1868 console.info(`Insert is successful, rowId = ${rowId}`); 1869 }).catch((err: BusinessError) => { 1870 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 1871 }) 1872} 1873``` 1874 1875### insert<sup>10+</sup> 1876 1877insert(table: string, values: ValuesBucket, conflict: ConflictResolution):Promise<number> 1878 1879Inserts 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. 1880 1881**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1882 1883**Parameters** 1884 1885| Name | Type | Mandatory| Description | 1886| -------- | ------------------------------------------- | ---- | -------------------------- | 1887| table | string | Yes | Name of the target table. | 1888| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.| 1889| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 1890 1891**Return value** 1892 1893| Type | Description | 1894| --------------------- | ------------------------------------------------- | 1895| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| 1896 1897**Error codes** 1898 1899For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 1900 1901| **ID**| **Error Message** | 1902| ------------ | -------------------------------------------- | 1903| 14800047 | The WAL file size exceeds the default limit. | 1904| 14800000 | Inner error. | 1905 1906**Example** 1907 1908```ts 1909import { ValuesBucket } from '@ohos.data.ValuesBucket'; 1910import { BusinessError } from "@ohos.base"; 1911 1912let key1 = "NAME"; 1913let key2 = "AGE"; 1914let key3 = "SALARY"; 1915let key4 = "CODES"; 1916let value1 = "Lisa"; 1917let value2 = 18; 1918let value3 = 100.5; 1919let value4 = new Uint8Array([1, 2, 3, 4, 5]); 1920const valueBucket: ValuesBucket = { 1921 key1: value1, 1922 key2: value2, 1923 key3: value3, 1924 key4: value4, 1925}; 1926if(store != undefined) { 1927 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => { 1928 console.info(`Insert is successful, rowId = ${rowId}`); 1929 }).catch((err: BusinessError) => { 1930 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 1931 }) 1932} 1933``` 1934 1935### batchInsert 1936 1937batchInsert(table: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>):void 1938 1939Batch inserts data into a table. This API uses an asynchronous callback to return the result. 1940 1941**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 1942 1943**Parameters** 1944 1945| Name | Type | Mandatory| Description | 1946| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ | 1947| table | string | Yes | Name of the target table. | 1948| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert. | 1949| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.| 1950 1951**Error codes** 1952 1953For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 1954 1955| **ID**| **Error Message** | 1956| ------------ | -------------------------------------------- | 1957| 14800047 | The WAL file size exceeds the default limit. | 1958| 14800000 | Inner error. | 1959 1960**Example** 1961 1962```ts 1963import { ValuesBucket } from '@ohos.data.ValuesBucket'; 1964 1965let key1 = "NAME"; 1966let key2 = "AGE"; 1967let key3 = "SALARY"; 1968let key4 = "CODES"; 1969let value1 = "Lisa"; 1970let value2 = 18; 1971let value3 = 100.5; 1972let value4 = new Uint8Array([1, 2, 3, 4, 5]); 1973let value5 = "Jack"; 1974let value6 = 19; 1975let value7 = 101.5; 1976let value8 = new Uint8Array([6, 7, 8, 9, 10]); 1977let value9 = "Tom"; 1978let value10 = 20; 1979let value11 = 102.5; 1980let value12 = new Uint8Array([11, 12, 13, 14, 15]); 1981const valueBucket1: ValuesBucket = { 1982 key1: value1, 1983 key2: value2, 1984 key3: value3, 1985 key4: value4, 1986}; 1987const valueBucket2: ValuesBucket = { 1988 key1: value5, 1989 key2: value6, 1990 key3: value7, 1991 key4: value8, 1992}; 1993const valueBucket3: ValuesBucket = { 1994 key1: value9, 1995 key2: value10, 1996 key3: value11, 1997 key4: value12, 1998}; 1999 2000let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2001if(store != undefined) { 2002 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets, (err, insertNum) => { 2003 if (err) { 2004 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2005 return; 2006 } 2007 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2008 }) 2009} 2010``` 2011 2012### batchInsert 2013 2014batchInsert(table: string, values: Array<ValuesBucket>):Promise<number> 2015 2016Batch inserts data into a table. This API uses a promise to return the result. 2017 2018**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2019 2020**Parameters** 2021 2022| Name| Type | Mandatory| Description | 2023| ------ | ------------------------------------------ | ---- | ---------------------------- | 2024| table | string | Yes | Name of the target table. | 2025| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert.| 2026 2027**Return value** 2028 2029| Type | Description | 2030| --------------------- | ----------------------------------------------------------- | 2031| 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.| 2032 2033**Error codes** 2034 2035For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2036 2037| **ID**| **Error Message** | 2038| ------------ | -------------------------------------------- | 2039| 14800047 | The WAL file size exceeds the default limit. | 2040| 14800000 | Inner error. | 2041 2042**Example** 2043 2044```ts 2045import { ValuesBucket } from '@ohos.data.ValuesBucket'; 2046import { BusinessError } from "@ohos.base"; 2047 2048let key1 = "NAME"; 2049let key2 = "AGE"; 2050let key3 = "SALARY"; 2051let key4 = "CODES"; 2052let value1 = "Lisa"; 2053let value2 = 18; 2054let value3 = 100.5; 2055let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2056let value5 = "Jack"; 2057let value6 = 19; 2058let value7 = 101.5; 2059let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2060let value9 = "Tom"; 2061let value10 = 20; 2062let value11 = 102.5; 2063let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2064const valueBucket1: ValuesBucket = { 2065 key1: value1, 2066 key2: value2, 2067 key3: value3, 2068 key4: value4, 2069}; 2070const valueBucket2: ValuesBucket = { 2071 key1: value5, 2072 key2: value6, 2073 key3: value7, 2074 key4: value8, 2075}; 2076const valueBucket3: ValuesBucket = { 2077 key1: value9, 2078 key2: value10, 2079 key3: value11, 2080 key4: value12, 2081}; 2082 2083let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2084if(store != undefined) { 2085 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => { 2086 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2087 }).catch((err: BusinessError) => { 2088 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2089 }) 2090} 2091``` 2092 2093### update 2094 2095update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback<number>):void 2096 2097Updates 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. 2098 2099**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2100 2101**Parameters** 2102 2103| Name | Type | Mandatory| Description | 2104| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 2105| 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.| 2106| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 2107| callback | AsyncCallback<number> | Yes | Callback invoked to return the number of rows updated. | 2108 2109**Error codes** 2110 2111For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2112 2113| **ID**| **Error Message** | 2114| ------------ | -------------------------------------------- | 2115| 14800047 | The WAL file size exceeds the default limit. | 2116| 14800000 | Inner error. | 2117 2118**Example** 2119 2120```ts 2121import { ValuesBucket } from '@ohos.data.ValuesBucket'; 2122 2123let key1 = "NAME"; 2124let key2 = "AGE"; 2125let key3 = "SALARY"; 2126let key4 = "CODES"; 2127let value1 = "Rose"; 2128let value2 = 22; 2129let value3 = 200.5; 2130let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2131const valueBucket: ValuesBucket = { 2132 key1: value1, 2133 key2: value2, 2134 key3: value3, 2135 key4: value4, 2136}; 2137let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2138predicates.equalTo("NAME", "Lisa"); 2139if(store != undefined) { 2140 (store as relationalStore.RdbStore).update(valueBucket, predicates,(err, rows) => { 2141 if (err) { 2142 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 2143 return; 2144 } 2145 console.info(`Updated row count: ${rows}`); 2146 }) 2147} 2148``` 2149 2150### update<sup>10+</sup> 2151 2152update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution, callback: AsyncCallback<number>):void 2153 2154Updates 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. 2155 2156**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2157 2158**Parameters** 2159 2160| Name | Type | Mandatory| Description | 2161| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 2162| 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.| 2163| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 2164| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 2165| callback | AsyncCallback<number> | Yes | Callback invoked to return the number of rows updated. | 2166 2167**Error codes** 2168 2169For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2170 2171| **ID**| **Error Message** | 2172| ------------ | -------------------------------------------- | 2173| 14800047 | The WAL file size exceeds the default limit. | 2174| 14800000 | Inner error. | 2175 2176**Example** 2177 2178```ts 2179import { ValuesBucket } from '@ohos.data.ValuesBucket'; 2180 2181let key1 = "NAME"; 2182let key2 = "AGE"; 2183let key3 = "SALARY"; 2184let key4 = "CODES"; 2185let value1 = "Rose"; 2186let value2 = 22; 2187let value3 = 200.5; 2188let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2189const valueBucket: ValuesBucket = { 2190 key1: value1, 2191 key2: value2, 2192 key3: value3, 2193 key4: value4, 2194}; 2195let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2196predicates.equalTo("NAME", "Lisa"); 2197if(store != undefined) { 2198 (store as relationalStore.RdbStore).update(valueBucket, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, (err, rows) => { 2199 if (err) { 2200 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 2201 return; 2202 } 2203 console.info(`Updated row count: ${rows}`); 2204 }) 2205} 2206``` 2207 2208### update 2209 2210update(values: ValuesBucket, predicates: RdbPredicates):Promise<number> 2211 2212Updates 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. 2213 2214**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2215 2216**Parameters** 2217 2218| Name | Type | Mandatory| Description | 2219| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 2220| 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.| 2221| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 2222 2223**Return value** 2224 2225| Type | Description | 2226| --------------------- | ----------------------------------------- | 2227| Promise<number> | Promise used to return the number of rows updated.| 2228 2229**Error codes** 2230 2231For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2232 2233| **ID**| **Error Message** | 2234| ------------ | -------------------------------------------- | 2235| 14800047 | The WAL file size exceeds the default limit. | 2236| 14800000 | Inner error. | 2237 2238**Example** 2239 2240```ts 2241import { ValuesBucket } from '@ohos.data.ValuesBucket'; 2242import { BusinessError } from "@ohos.base"; 2243 2244let key1 = "NAME"; 2245let key2 = "AGE"; 2246let key3 = "SALARY"; 2247let key4 = "CODES"; 2248let value1 = "Rose"; 2249let value2 = 22; 2250let value3 = 200.5; 2251let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2252const valueBucket: ValuesBucket = { 2253 key1: value1, 2254 key2: value2, 2255 key3: value3, 2256 key4: value4, 2257}; 2258let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2259predicates.equalTo("NAME", "Lisa"); 2260if(store != undefined) { 2261 (store as relationalStore.RdbStore).update(valueBucket, predicates).then(async (rows: Number) => { 2262 console.info(`Updated row count: ${rows}`); 2263 }).catch((err: BusinessError) => { 2264 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 2265 }) 2266} 2267``` 2268 2269### update<sup>10+</sup> 2270 2271update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution):Promise<number> 2272 2273Updates 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. 2274 2275**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2276 2277**Parameters** 2278 2279| Name | Type | Mandatory| Description | 2280| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 2281| 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.| 2282| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. | 2283| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. | 2284 2285**Return value** 2286 2287| Type | Description | 2288| --------------------- | ----------------------------------------- | 2289| Promise<number> | Promise used to return the number of rows updated.| 2290 2291**Error codes** 2292 2293For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2294 2295| **ID**| **Error Message** | 2296| ------------ | -------------------------------------------- | 2297| 14800047 | The WAL file size exceeds the default limit. | 2298| 14800000 | Inner error. | 2299 2300**Example** 2301 2302```ts 2303import { ValuesBucket } from '@ohos.data.ValuesBucket'; 2304import { BusinessError } from "@ohos.base"; 2305 2306let key1 = "NAME"; 2307let key2 = "AGE"; 2308let key3 = "SALARY"; 2309let key4 = "CODES"; 2310let value1 = "Rose"; 2311let value2 = 22; 2312let value3 = 200.5; 2313let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2314const valueBucket: ValuesBucket = { 2315 key1: value1, 2316 key2: value2, 2317 key3: value3, 2318 key4: value4, 2319}; 2320let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2321predicates.equalTo("NAME", "Lisa"); 2322if(store != undefined) { 2323 (store as relationalStore.RdbStore).update(valueBucket, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => { 2324 console.info(`Updated row count: ${rows}`); 2325 }).catch((err: BusinessError) => { 2326 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 2327 }) 2328} 2329``` 2330 2331### delete 2332 2333delete(predicates: RdbPredicates, callback: AsyncCallback<number>):void 2334 2335Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result. 2336 2337**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2338 2339**Parameters** 2340 2341| Name | Type | Mandatory| Description | 2342| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 2343| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 2344| callback | AsyncCallback<number> | Yes | Callback invoked to return the number of rows deleted. | 2345 2346**Error codes** 2347 2348For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2349 2350| **ID**| **Error Message** | 2351| ------------ | -------------------------------------------- | 2352| 14800047 | The WAL file size exceeds the default limit. | 2353| 14800000 | Inner error. | 2354 2355**Example** 2356 2357```ts 2358let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2359predicates.equalTo("NAME", "Lisa"); 2360if(store != undefined) { 2361 (store as relationalStore.RdbStore).delete(predicates, (err, rows) => { 2362 if (err) { 2363 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 2364 return; 2365 } 2366 console.info(`Delete rows: ${rows}`); 2367 }) 2368} 2369``` 2370 2371### delete 2372 2373delete(predicates: RdbPredicates):Promise<number> 2374 2375Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result. 2376 2377**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2378 2379**Parameters** 2380 2381| Name | Type | Mandatory| Description | 2382| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 2383| predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| 2384 2385**Return value** 2386 2387| Type | Description | 2388| --------------------- | ------------------------------- | 2389| Promise<number> | Promise used to return the number of rows deleted.| 2390 2391**Error codes** 2392 2393For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2394 2395| **ID**| **Error Message** | 2396| ------------ | -------------------------------------------- | 2397| 14800047 | The WAL file size exceeds the default limit. | 2398| 14800000 | Inner error. | 2399 2400**Example** 2401 2402```ts 2403import { BusinessError } from "@ohos.base"; 2404 2405let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2406predicates.equalTo("NAME", "Lisa"); 2407if(store != undefined) { 2408 (store as relationalStore.RdbStore).delete(predicates).then((rows: Number) => { 2409 console.info(`Delete rows: ${rows}`); 2410 }).catch((err: BusinessError) => { 2411 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 2412 }) 2413} 2414``` 2415 2416### query<sup>10+</sup> 2417 2418query(predicates: RdbPredicates, callback: AsyncCallback<ResultSet>):void 2419 2420Queries 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. 2421 2422**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2423 2424**Parameters** 2425 2426| Name | Type | Mandatory| Description | 2427| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 2428| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 2429| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| 2430 2431**Error codes** 2432 2433For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2434 2435| **ID**| **Error Message** | 2436| ------------ | ---------------------------- | 2437| 14800000 | Inner error. | 2438 2439**Example** 2440 2441```ts 2442let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2443predicates.equalTo("NAME", "Rose"); 2444if(store != undefined) { 2445 (store as relationalStore.RdbStore).query(predicates, (err, resultSet) => { 2446 if (err) { 2447 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 2448 return; 2449 } 2450 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 2451 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 2452 while (resultSet.goToNextRow()) { 2453 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 2454 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 2455 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 2456 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 2457 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 2458 } 2459 // Release the dataset memory. 2460 resultSet.close(); 2461 }) 2462} 2463``` 2464 2465### query 2466 2467query(predicates: RdbPredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>):void 2468 2469Queries 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. 2470 2471**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2472 2473**Parameters** 2474 2475| Name | Type | Mandatory| Description | 2476| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 2477| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 2478| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | 2479| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| 2480 2481**Error codes** 2482 2483For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2484 2485| **ID**| **Error Message** | 2486| ------------ | ---------------------------- | 2487| 14800000 | Inner error. | 2488 2489**Example** 2490 2491```ts 2492let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2493predicates.equalTo("NAME", "Rose"); 2494if(store != undefined) { 2495 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], (err, resultSet) => { 2496 if (err) { 2497 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 2498 return; 2499 } 2500 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 2501 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 2502 while (resultSet.goToNextRow()) { 2503 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 2504 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 2505 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 2506 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 2507 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 2508 } 2509 // Release the dataset memory. 2510 resultSet.close(); 2511 }) 2512} 2513``` 2514 2515### query 2516 2517query(predicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> 2518 2519Queries 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. 2520 2521**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2522 2523**Parameters** 2524 2525| Name | Type | Mandatory| Description | 2526| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 2527| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 2528| columns | Array<string> | No | Columns to query. If this parameter is not specified, the query applies to all columns.| 2529 2530**Error codes** 2531 2532For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2533 2534| **ID**| **Error Message** | 2535| ------------ | ---------------------------- | 2536| 14800000 | Inner error. | 2537 2538**Return value** 2539 2540| Type | Description | 2541| ------------------------------------------------------- | -------------------------------------------------- | 2542| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 2543 2544**Example** 2545 2546```ts 2547import { BusinessError } from "@ohos.base"; 2548 2549let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2550predicates.equalTo("NAME", "Rose"); 2551if(store != undefined) { 2552 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 2553 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 2554 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 2555 while (resultSet.goToNextRow()) { 2556 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 2557 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 2558 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 2559 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 2560 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 2561 } 2562 // Release the dataset memory. 2563 resultSet.close(); 2564 }).catch((err: BusinessError) => { 2565 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 2566 }) 2567} 2568``` 2569 2570### remoteQuery 2571 2572remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string> , callback: AsyncCallback<ResultSet>): void 2573 2574Queries data from the RDB store of a remote device based on specified conditions. This API uses an asynchronous callback to return the result. 2575 2576> **NOTE** 2577> 2578> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 2579 2580**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2581 2582**Parameters** 2583 2584| Name | Type | Mandatory| Description | 2585| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- | 2586| device | string | Yes | ID of the remote device. | 2587| table | string | Yes | Name of the target table. | 2588| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 2589| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. | 2590| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| 2591 2592**Error codes** 2593 2594For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2595 2596| **ID**| **Error Message** | 2597| ------------ | ---------------------------- | 2598| 14800000 | Inner error. | 2599 2600**Example** 2601 2602```ts 2603import deviceManager from '@ohos.distributedDeviceManager'; 2604import { BusinessError } from "@ohos.base"; 2605 2606let dmInstance: deviceManager.DeviceManager; 2607let deviceId: string | undefined = undefined; 2608 2609try { 2610 dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify"); 2611 let devices = dmInstance.getAvailableDeviceListSync(); 2612 if(deviceId != undefined) { 2613 deviceId = devices[0].networkId; 2614 } 2615} catch (err) { 2616 let code = (err as BusinessError).code; 2617 let message = (err as BusinessError).message; 2618 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 2619} 2620 2621let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 2622predicates.greaterThan("id", 0); 2623if(store != undefined && deviceId != undefined) { 2624 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 2625 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 2626 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 2627 while (resultSet.goToNextRow()) { 2628 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 2629 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 2630 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 2631 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 2632 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 2633 } 2634 // Release the dataset memory. 2635 resultSet.close(); 2636 }).catch((err: BusinessError) => { 2637 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 2638 }) 2639} 2640``` 2641 2642### remoteQuery 2643 2644remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string>): Promise<ResultSet> 2645 2646Queries data from the RDB store of a remote device based on specified conditions. This API uses a promise to return the result. 2647 2648> **NOTE** 2649> 2650> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 2651 2652**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2653 2654**Parameters** 2655 2656| Name | Type | Mandatory| Description | 2657| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 2658| device | string | Yes | ID of the remote device. | 2659| table | string | Yes | Name of the target table. | 2660| predicates | [RdbPredicates](#rdbpredicates) | Yes | Query conditions specified by the **RdbPredicates** object. | 2661| columns | Array<string> | Yes | Columns to query. If this parameter is not specified, the query applies to all columns.| 2662 2663**Return value** 2664 2665| Type | Description | 2666| ------------------------------------------------------------ | -------------------------------------------------- | 2667| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 2668 2669**Error codes** 2670 2671For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2672 2673| **ID**| **Error Message** | 2674| ------------ | ---------------------------- | 2675| 14800000 | Inner error. | 2676 2677**Example** 2678 2679```ts 2680import deviceManager from '@ohos.distributedDeviceManager'; 2681import { BusinessError } from "@ohos.base"; 2682 2683let dmInstance: deviceManager.DeviceManager; 2684let deviceId: string | undefined = undefined; 2685 2686try { 2687 dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify"); 2688 let devices: Array<deviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 2689 if(devices != undefined) { 2690 deviceId = devices[0].networkId; 2691 } 2692} catch (err) { 2693 let code = (err as BusinessError).code; 2694 let message = (err as BusinessError).message; 2695 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 2696} 2697 2698let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 2699predicates.greaterThan("id", 0); 2700if(store != undefined && deviceId != undefined) { 2701 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 2702 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 2703 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 2704 while (resultSet.goToNextRow()) { 2705 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 2706 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 2707 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 2708 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 2709 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 2710 } 2711 // Release the dataset memory. 2712 resultSet.close(); 2713 }).catch((err: BusinessError) => { 2714 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 2715 }) 2716} 2717``` 2718 2719### querySql<sup>10+</sup> 2720 2721querySql(sql: string, callback: AsyncCallback<ResultSet>):void 2722 2723Queries data using the specified SQL statement. This API uses an asynchronous callback to return the result. 2724 2725**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2726 2727**Parameters** 2728 2729| Name | Type | Mandatory| Description | 2730| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | 2731| sql | string | Yes | SQL statement to run. | 2732| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned. | 2733 2734**Error codes** 2735 2736For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2737 2738| **ID**| **Error Message** | 2739| ------------ | ---------------------------- | 2740| 14800000 | Inner error. | 2741 2742**Example** 2743 2744```ts 2745if(store != undefined) { 2746 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'", (err, resultSet) => { 2747 if (err) { 2748 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 2749 return; 2750 } 2751 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 2752 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 2753 while (resultSet.goToNextRow()) { 2754 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 2755 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 2756 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 2757 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 2758 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 2759 } 2760 // Release the dataset memory. 2761 resultSet.close(); 2762 }) 2763} 2764``` 2765 2766### querySql 2767 2768querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void 2769 2770Queries data using the specified SQL statement. This API uses an asynchronous callback to return the result. 2771 2772**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2773 2774**Parameters** 2775 2776| Name | Type | Mandatory| Description | 2777| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | 2778| sql | string | Yes | SQL statement to run. | 2779| 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.| 2780| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned. | 2781 2782**Error codes** 2783 2784For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2785 2786| **ID**| **Error Message** | 2787| ------------ | ---------------------------- | 2788| 14800000 | Inner error. | 2789 2790**Example** 2791 2792```ts 2793if(store != undefined) { 2794 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], (err, resultSet) => { 2795 if (err) { 2796 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 2797 return; 2798 } 2799 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 2800 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 2801 while (resultSet.goToNextRow()) { 2802 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 2803 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 2804 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 2805 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 2806 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 2807 } 2808 // Release the dataset memory. 2809 resultSet.close(); 2810 }) 2811} 2812``` 2813 2814### querySql 2815 2816querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> 2817 2818Queries data using the specified SQL statement. This API uses a promise to return the result. 2819 2820**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2821 2822**Parameters** 2823 2824| Name | Type | Mandatory| Description | 2825| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 2826| sql | string | Yes | SQL statement to run. | 2827| 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.| 2828 2829**Return value** 2830 2831| Type | Description | 2832| ------------------------------------------------------- | -------------------------------------------------- | 2833| Promise<[ResultSet](#resultset)> | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.| 2834 2835**Error codes** 2836 2837For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2838 2839| **ID**| **Error Message** | 2840| ------------ | ---------------------------- | 2841| 14800000 | Inner error. | 2842 2843**Example** 2844 2845```ts 2846import { BusinessError } from "@ohos.base"; 2847 2848if(store != undefined) { 2849 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then((resultSet: relationalStore.ResultSet) => { 2850 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 2851 // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0. 2852 while (resultSet.goToNextRow()) { 2853 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 2854 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 2855 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 2856 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 2857 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 2858 } 2859 // Release the dataset memory. 2860 resultSet.close(); 2861 }).catch((err: BusinessError) => { 2862 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 2863 }) 2864} 2865``` 2866 2867### executeSql<sup>10+</sup> 2868 2869executeSql(sql: string, callback: AsyncCallback<void>):void 2870 2871Executes an SQL statement that contains specified arguments but returns no value. This API uses an asynchronous callback to return the result. 2872 2873**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2874 2875**Parameters** 2876 2877| Name | Type | Mandatory| Description | 2878| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 2879| sql | string | Yes | SQL statement to run. | 2880| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | 2881 2882**Error codes** 2883 2884For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2885 2886| **ID**| **Error Message** | 2887| ------------ | -------------------------------------------- | 2888| 14800047 | The WAL file size exceeds the default limit. | 2889| 14800000 | Inner error. | 2890 2891**Example** 2892 2893```ts 2894const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" 2895if(store != undefined) { 2896 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, (err) => { 2897 if (err) { 2898 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 2899 return; 2900 } 2901 console.info('Delete table done.'); 2902 }) 2903} 2904``` 2905 2906### executeSql 2907 2908executeSql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<void>):void 2909 2910Executes an SQL statement that contains specified arguments but returns no value. This API uses an asynchronous callback to return the result. 2911 2912**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2913 2914**Parameters** 2915 2916| Name | Type | Mandatory| Description | 2917| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 2918| sql | string | Yes | SQL statement to run. | 2919| 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.| 2920| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | 2921 2922**Error codes** 2923 2924For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2925 2926| **ID**| **Error Message** | 2927| ------------ | -------------------------------------------- | 2928| 14800047 | The WAL file size exceeds the default limit. | 2929| 14800000 | Inner error. | 2930 2931**Example** 2932 2933```ts 2934const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?" 2935if(store != undefined) { 2936 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, ['zhangsan'], (err) => { 2937 if (err) { 2938 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 2939 return; 2940 } 2941 console.info('Delete table done.'); 2942 }) 2943} 2944``` 2945 2946### executeSql 2947 2948executeSql(sql: string, bindArgs?: Array<ValueType>):Promise<void> 2949 2950Executes an SQL statement that contains specified arguments but returns no value. This API uses a promise to return the result. 2951 2952**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2953 2954**Parameters** 2955 2956| Name | Type | Mandatory| Description | 2957| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 2958| sql | string | Yes | SQL statement to run. | 2959| 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.| 2960 2961**Return value** 2962 2963| Type | Description | 2964| ------------------- | ------------------------- | 2965| Promise<void> | Promise that returns no value.| 2966 2967**Error codes** 2968 2969For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 2970 2971| **ID**| **Error Message** | 2972| ------------ | -------------------------------------------- | 2973| 14800047 | The WAL file size exceeds the default limit. | 2974| 14800000 | Inner error. | 2975 2976**Example** 2977 2978```ts 2979import { BusinessError } from "@ohos.base"; 2980 2981const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" 2982if(store != undefined) { 2983 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE).then(() => { 2984 console.info('Delete table done.'); 2985 }).catch((err: BusinessError) => { 2986 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 2987 }) 2988} 2989``` 2990 2991### getModifyTime<sup>10+</sup> 2992 2993getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[], callback: AsyncCallback<ModifyTime>): void 2994 2995Obtains the last modification time of the data in a table. This API uses an asynchronous callback to return the result. 2996 2997**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 2998 2999**Parameters** 3000 3001| Name | Type | Mandatory| Description | 3002| ----------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 3003| table | string | Yes | Name of the database table to query. | 3004| columnName | string | Yes | Column name of the database table to query. | 3005| 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.| 3006| callback | AsyncCallback<[ModifyTime](#modifytime10)> | Yes | Callback invoked to return the result. If the operation is successful, the **ModifyTime** object is returned.| 3007 3008**Error codes** 3009 3010For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3011 3012| **ID**| **Error Message**| 3013| ------------ | ------------ | 3014| 14800000 | Inner error. | 3015 3016**Example** 3017 3018```ts 3019let PRIKey = [1, 4, 2, 3]; 3020if(store != undefined) { 3021 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey, (err, modifyTime: relationalStore.ModifyTime) => { 3022 if (err) { 3023 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 3024 return; 3025 } 3026 let size = modifyTime.size; 3027 }); 3028} 3029``` 3030 3031### getModifyTime<sup>10+</sup> 3032 3033getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[]): Promise<ModifyTime> 3034 3035Obtains the last modification time of the data in a table. This API uses a promise to return the result. 3036 3037**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3038 3039**Parameters** 3040 3041| Name | Type | Mandatory| Description | 3042| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ | 3043| table | string | Yes | Name of the database table to query. | 3044| columnName | string | Yes | Column name of the database table to query. | 3045| 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.| 3046 3047**Return value** 3048 3049| Type | Description | 3050| ------------------------------------------ | --------------------------------------------------------- | 3051| Promise<[ModifyTime](#modifytime10)> | Promise used to return the **ModifyTime** object.| 3052 3053**Error codes** 3054 3055For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3056 3057| **ID**| **Error Message**| 3058| ------------ | ------------ | 3059| 14800000 | Inner error. | 3060 3061**Example** 3062 3063```ts 3064import { BusinessError } from "@ohos.base"; 3065 3066let PRIKey = [1, 2, 3]; 3067if(store != undefined) { 3068 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey) 3069 .then((modifyTime: relationalStore.ModifyTime) => { 3070 let size = modifyTime.size; 3071 }) 3072 .catch((err: BusinessError) => { 3073 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 3074 }); 3075} 3076``` 3077 3078### beginTransaction 3079 3080beginTransaction():void 3081 3082Starts the transaction before executing an SQL statement. 3083This API cannot be used in multi-process or multi-thread scenarios. 3084 3085**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3086 3087**Error codes** 3088 3089For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3090 3091| **ID**| **Error Message** | 3092| ------------ | -------------------------------------------- | 3093| 14800047 | The WAL file size exceeds the default limit. | 3094| 14800000 | Inner error. | 3095 3096**Example** 3097 3098```ts 3099import featureAbility from '@ohos.ability.featureAbility' 3100import { ValuesBucket } from '@ohos.data.ValuesBucket'; 3101 3102let key1 = "name"; 3103let key2 = "age"; 3104let key3 = "SALARY"; 3105let key4 = "blobType"; 3106let value1 = "Lisa"; 3107let value2 = 18; 3108let value3 = 100.5; 3109let value4 = new Uint8Array([1, 2, 3]); 3110 3111store.beginTransaction(); 3112const valueBucket: ValuesBucket = { 3113 key1: value1, 3114 key2: value2, 3115 key3: value3, 3116 key4: value4, 3117}; 3118store.insert("test", valueBucket); 3119store.commit(); 3120``` 3121 3122### commit 3123 3124commit():void 3125 3126Commits the executed SQL statements. 3127This API cannot be used in multi-process or multi-thread scenarios. 3128 3129**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3130 3131**Example** 3132 3133```ts 3134import { ValuesBucket } from '@ohos.data.ValuesBucket'; 3135 3136let key1 = "name"; 3137let key2 = "age"; 3138let key3 = "SALARY"; 3139let key4 = "blobType"; 3140let value1 = "Lisa"; 3141let value2 = 18; 3142let value3 = 100.5; 3143let value4 = new Uint8Array([1, 2, 3]); 3144 3145store.beginTransaction(); 3146const valueBucket: ValuesBucket = { 3147 key1: value1, 3148 key2: value2, 3149 key3: value3, 3150 key4: value4, 3151}; 3152store.insert("test", valueBucket); 3153store.commit(); 3154``` 3155 3156### rollBack 3157 3158rollBack():void 3159 3160Rolls back the SQL statements that have been executed. 3161This API cannot be used in multi-process or multi-thread scenarios. 3162 3163**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3164 3165**Example** 3166 3167```ts 3168import { ValuesBucket } from '@ohos.data.ValuesBucket'; 3169 3170let key1 = "name"; 3171let key2 = "age"; 3172let key3 = "SALARY"; 3173let key4 = "blobType"; 3174let value1 = "Lisa"; 3175let value2 = 18; 3176let value3 = 100.5; 3177let value4 = new Uint8Array([1, 2, 3]); 3178 3179try { 3180 store.beginTransaction() 3181 const valueBucket: ValuesBucket = { 3182 key1: value1, 3183 key2: value2, 3184 key3: value3, 3185 key4: value4, 3186 }; 3187 store.insert("test", valueBucket); 3188 store.commit(); 3189} catch (err) { 3190 let code = (err as BusinessError).code; 3191 let message = (err as BusinessError).message 3192 console.error(`Transaction failed, code is ${code},message is ${message}`); 3193 store.rollBack(); 3194} 3195``` 3196 3197### backup 3198 3199backup(destName:string, callback: AsyncCallback<void>):void 3200 3201Backs up an RDB store. This API uses an asynchronous callback to return the result. 3202 3203**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3204 3205**Parameters** 3206 3207| Name | Type | Mandatory| Description | 3208| -------- | ------------------------- | ---- | ------------------------ | 3209| destName | string | Yes | Name of the RDB store backup file.| 3210| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | 3211 3212**Error codes** 3213 3214For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3215 3216| **ID**| **Error Message** | 3217| ------------ | ---------------------------- | 3218| 14800000 | Inner error. | 3219 3220**Example** 3221 3222```ts 3223if(store != undefined) { 3224 (store as relationalStore.RdbStore).backup("dbBackup.db", (err) => { 3225 if (err) { 3226 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 3227 return; 3228 } 3229 console.info('Backup success.'); 3230 }) 3231} 3232``` 3233 3234### backup 3235 3236backup(destName:string): Promise<void> 3237 3238Backs up an RDB store. This API uses a promise to return the result. 3239 3240**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3241 3242**Parameters** 3243 3244| Name | Type | Mandatory| Description | 3245| -------- | ------ | ---- | ------------------------ | 3246| destName | string | Yes | Name of the RDB store backup file.| 3247 3248**Return value** 3249 3250| Type | Description | 3251| ------------------- | ------------------------- | 3252| Promise<void> | Promise that returns no value.| 3253 3254**Error codes** 3255 3256For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3257 3258| **ID**| **Error Message** | 3259| ------------ | ---------------------------- | 3260| 14800000 | Inner error. | 3261 3262**Example** 3263 3264```ts 3265import { BusinessError } from "@ohos.base"; 3266 3267if(store != undefined) { 3268 let promiseBackup = (store as relationalStore.RdbStore).backup("dbBackup.db"); 3269 promiseBackup.then(() => { 3270 console.info('Backup success.'); 3271 }).catch((err: BusinessError) => { 3272 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 3273 }) 3274} 3275``` 3276 3277### restore 3278 3279restore(srcName:string, callback: AsyncCallback<void>):void 3280 3281Restores an RDB store from a backup file. This API uses an asynchronous callback to return the result. 3282 3283**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3284 3285**Parameters** 3286 3287| Name | Type | Mandatory| Description | 3288| -------- | ------------------------- | ---- | ------------------------ | 3289| srcName | string | Yes | Name of the RDB store backup file.| 3290| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | 3291 3292**Error codes** 3293 3294For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3295 3296| **ID**| **Error Message** | 3297| ------------ | ---------------------------- | 3298| 14800000 | Inner error. | 3299 3300**Example** 3301 3302```ts 3303if(store != undefined) { 3304 (store as relationalStore.RdbStore).restore("dbBackup.db", (err) => { 3305 if (err) { 3306 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 3307 return; 3308 } 3309 console.info('Restore success.'); 3310 }) 3311} 3312``` 3313 3314### restore 3315 3316restore(srcName:string): Promise<void> 3317 3318Restores an RDB store from a backup file. This API uses a promise to return the result. 3319 3320**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3321 3322**Parameters** 3323 3324| Name | Type | Mandatory| Description | 3325| ------- | ------ | ---- | ------------------------ | 3326| srcName | string | Yes | Name of the RDB store backup file.| 3327 3328**Return value** 3329 3330| Type | Description | 3331| ------------------- | ------------------------- | 3332| Promise<void> | Promise that returns no value.| 3333 3334**Error codes** 3335 3336For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3337 3338| **ID**| **Error Message** | 3339| ------------ | ---------------------------- | 3340| 14800000 | Inner error. | 3341 3342**Example** 3343 3344```ts 3345import { BusinessError } from "@ohos.base"; 3346 3347if(store != undefined) { 3348 let promiseRestore = (store as relationalStore.RdbStore).restore("dbBackup.db"); 3349 promiseRestore.then(() => { 3350 console.info('Restore success.'); 3351 }).catch((err: BusinessError) => { 3352 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 3353 }) 3354} 3355``` 3356 3357### setDistributedTables 3358 3359setDistributedTables(tables: Array<string>, callback: AsyncCallback<void>): void 3360 3361Sets distributed tables. This API uses an asynchronous callback to return the result. 3362 3363**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3364 3365**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3366 3367**Parameters** 3368 3369| Name | Type | Mandatory| Description | 3370| -------- | ------------------------- | ---- | ---------------------- | 3371| tables | Array<string> | Yes | Names of the distributed tables to set.| 3372| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| 3373 3374**Error codes** 3375 3376For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3377 3378| **ID**| **Error Message** | 3379| ------------ | ---------------------------- | 3380| 14800000 | Inner error. | 3381 3382**Example** 3383 3384```ts 3385if(store != undefined) { 3386 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], (err) => { 3387 if (err) { 3388 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 3389 return; 3390 } 3391 console.info('SetDistributedTables successfully.'); 3392 }) 3393} 3394``` 3395 3396### setDistributedTables 3397 3398 setDistributedTables(tables: Array<string>): Promise<void> 3399 3400Sets distributed tables. This API uses a promise to return the result. 3401 3402**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3403 3404**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3405 3406**Parameters** 3407 3408| Name| Type | Mandatory| Description | 3409| ------ | ------------------------ | ---- | ------------------------ | 3410| tables | ArrayArray<string> | Yes | Names of the distributed tables to set.| 3411 3412**Return value** 3413 3414| Type | Description | 3415| ------------------- | ------------------------- | 3416| Promise<void> | Promise that returns no value.| 3417 3418**Error codes** 3419 3420For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3421 3422| **ID**| **Error Message**| 3423| ------------ | ------------ | 3424| 14800000 | Inner error. | 3425 3426**Example** 3427 3428```ts 3429import { BusinessError } from "@ohos.base"; 3430 3431if(store != undefined) { 3432 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"]).then(() => { 3433 console.info('SetDistributedTables successfully.'); 3434 }).catch((err: BusinessError) => { 3435 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 3436 }) 3437} 3438``` 3439 3440### setDistributedTables<sup>10+</sup> 3441 3442setDistributedTables(tables: Array<string>, type: DistributedType, callback: AsyncCallback<void>): void 3443 3444Sets distributed tables. This API uses an asynchronous callback to return the result. 3445 3446**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3447 3448**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3449 3450**Parameters** 3451 3452| Name | Type | Mandatory| Description | 3453| -------- | ------------------------------------- | ---- | ---------------------------- | 3454| tables | Array<string> | Yes | Names of the distributed tables to set.| 3455| type | [DistributedType](#distributedtype10) | Yes | Distributed type of the tables. | 3456| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | 3457 3458**Error codes** 3459 3460For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3461 3462| **ID**| **Error Message**| 3463| ------------ | ------------ | 3464| 14800000 | Inner error. | 3465| 14800051 |The type of the distributed table does not match.| 3466 3467**Example** 3468 3469```ts 3470if(store != undefined) { 3471 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, (err) => { 3472 if (err) { 3473 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 3474 return; 3475 } 3476 console.info('SetDistributedTables successfully.'); 3477 }) 3478} 3479``` 3480 3481 3482 3483### setDistributedTables<sup>10+</sup> 3484 3485setDistributedTables(tables: Array<string>, type: DistributedType, config: DistributedConfig, callback: AsyncCallback<void>): void 3486 3487Sets distributed tables. This API uses an asynchronous callback to return the result. 3488 3489**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3490 3491**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3492 3493**Parameters** 3494 3495| Name | Type | Mandatory | Description | 3496| -------- | ----------------------------------- | --- | --------------- | 3497| tables | Array<string> | Yes | Names of the distributed tables to set. | 3498| type | [DistributedType](#distributedtype10) | Yes | Distributed type of the tables.| 3499| config | [DistributedConfig](#distributedconfig10) | Yes| Configuration of the distributed mode.| 3500| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| 3501 3502**Error codes** 3503 3504For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3505 3506| **ID**| **Error Message** | 3507| ------------ | ------------------------------------------------- | 3508| 14800000 | Inner error. | 3509| 14800051 | The type of the distributed table does not match. | 3510 3511**Example** 3512 3513```ts 3514if(store != undefined) { 3515 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 3516 autoSync: true 3517 }, (err) => { 3518 if (err) { 3519 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 3520 return; 3521 } 3522 console.info('SetDistributedTables successfully.'); 3523 }) 3524} 3525``` 3526 3527### setDistributedTables<sup>10+</sup> 3528 3529 setDistributedTables(tables: Array<string>, type?: DistributedType, config?: DistributedConfig): Promise<void> 3530 3531Sets distributed tables. This API uses a promise to return the result. 3532 3533**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3534 3535**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3536 3537**Parameters** 3538 3539| Name| Type | Mandatory| Description | 3540| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ | 3541| tables | Array<string> | Yes | Names of the distributed tables to set. | 3542| type | [DistributedType](#distributedtype10) | No | Distributed type of the tables. The default value is **relationalStore.DistributedType.DISTRIBUTED_DEVICE**.| 3543| 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 synchronization is supported.| 3544 3545**Return value** 3546 3547| Type | Description | 3548| ------------------- | ------------------------- | 3549| Promise<void> | Promise that returns no value.| 3550 3551**Error codes** 3552 3553For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3554 3555| **ID**| **Error Message** | 3556| ------------ | ------------------------------------------------- | 3557| 14800000 | Inner error. | 3558| 14800051 | The type of the distributed table does not match. | 3559 3560**Example** 3561 3562```ts 3563import { BusinessError } from "@ohos.base"; 3564 3565if(store != undefined) { 3566 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 3567 autoSync: true 3568 }).then(() => { 3569 console.info('SetDistributedTables successfully.'); 3570 }).catch((err: BusinessError) => { 3571 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 3572 }) 3573} 3574``` 3575 3576### obtainDistributedTableName 3577 3578obtainDistributedTableName(device: string, table: string, callback: AsyncCallback<string>): void 3579 3580Obtains 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. 3581 3582> **NOTE** 3583> 3584> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 3585 3586**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3587 3588**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3589 3590**Parameters** 3591 3592| Name | Type | Mandatory| Description | 3593| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 3594| device | string | Yes | ID of the remote device. | 3595| table | string | Yes | Local table name of the remote device. | 3596| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| 3597 3598**Error codes** 3599 3600For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3601 3602| **ID**| **Error Message** | 3603| ------------ | ---------------------------- | 3604| 14800000 | Inner error. | 3605 3606**Example** 3607 3608```ts 3609import deviceManager from '@ohos.distributedDeviceManager'; 3610 3611let dmInstance: deviceManager.DeviceManager; 3612let deviceId: string | undefined = undefined; 3613 3614try { 3615 dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify"); 3616 let devices = dmInstance.getAvailableDeviceListSync(); 3617 deviceId = devices[0].networkId; 3618} catch (err) { 3619 let code = (err as BusinessError).code; 3620 let message = (err as BusinessError).message 3621 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 3622} 3623 3624if(store != undefined && deviceId != undefined) { 3625 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE", (err, tableName) => { 3626 if (err) { 3627 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 3628 return; 3629 } 3630 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 3631 }) 3632} 3633``` 3634 3635### obtainDistributedTableName 3636 3637 obtainDistributedTableName(device: string, table: string): Promise<string> 3638 3639Obtains 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. 3640 3641> **NOTE** 3642> 3643> **device** can be obtained by [deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). 3644 3645**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3646 3647**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3648 3649**Parameters** 3650 3651| Name| Type | Mandatory| Description | 3652| ------ | ------ | ---- | -------------------- | 3653| device | string | Yes | ID of the remote device. | 3654| table | string | Yes | Local table name of the remote device.| 3655 3656**Return value** 3657 3658| Type | Description | 3659| --------------------- | ----------------------------------------------------- | 3660| Promise<string> | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| 3661 3662**Error codes** 3663 3664For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3665 3666| **ID**| **Error Message** | 3667| ------------ | ---------------------------- | 3668| 14800000 | Inner error. | 3669 3670**Example** 3671 3672```ts 3673import deviceManager from '@ohos.distributedDeviceManager'; 3674import { BusinessError } from "@ohos.base"; 3675 3676let dmInstance: deviceManager.DeviceManager; 3677let deviceId: string | undefined = undefined; 3678 3679try { 3680 dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify"); 3681 let devices = dmInstance.getAvailableDeviceListSync(); 3682 deviceId = devices[0].networkId; 3683} catch (err) { 3684 let code = (err as BusinessError).code; 3685 let message = (err as BusinessError).message 3686 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 3687} 3688 3689if(store != undefined && deviceId != undefined) { 3690 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE").then((tableName: string) => { 3691 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 3692 }).catch((err: BusinessError) => { 3693 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 3694 }) 3695} 3696``` 3697 3698### sync 3699 3700sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void 3701 3702Synchronizes data between devices. This API uses an asynchronous callback to return the result. 3703 3704**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3705 3706**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3707 3708**Parameters** 3709 3710| Name | Type | Mandatory| Description | 3711| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ | 3712| mode | [SyncMode](#syncmode) | Yes | Data synchronization mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**. | 3713| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | 3714| callback | AsyncCallback<Array<[string, number]>> | Yes | Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | 3715 3716**Error codes** 3717 3718For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3719 3720| **ID**| **Error Message** | 3721| ------------ | ---------------------------- | 3722| 14800000 | Inner error. | 3723 3724**Example** 3725 3726```ts 3727import deviceManager from '@ohos.distributedDeviceManager'; 3728 3729let dmInstance: deviceManager.DeviceManager; 3730let deviceIds: Array<string> = []; 3731 3732try { 3733 dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify"); 3734 let devices: Array<deviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 3735 for (let i = 0; i < devices.length; i++) { 3736 deviceIds[i] = devices[i].networkId!; 3737 } 3738} catch (err) { 3739 let code = (err as BusinessError).code; 3740 let message = (err as BusinessError).message 3741 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 3742} 3743 3744let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 3745predicates.inDevices(deviceIds); 3746if(store != undefined) { 3747 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, (err, result) => { 3748 if (err) { 3749 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 3750 return; 3751 } 3752 console.info('Sync done.'); 3753 for (let i = 0; i < result.length; i++) { 3754 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 3755 } 3756 }) 3757} 3758``` 3759 3760### sync 3761 3762 sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>> 3763 3764Synchronizes data between devices. This API uses a promise to return the result. 3765 3766**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3767 3768**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3769 3770**Parameters** 3771 3772| Name | Type | Mandatory| Description | 3773| ---------- | ------------------------------------ | ---- | ------------------------------ | 3774| mode | [SyncMode](#syncmode) | Yes | Data synchronization mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**.| 3775| predicates | [RdbPredicates](#rdbpredicates) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | 3776 3777**Return value** 3778 3779| Type | Description | 3780| -------------------------------------------- | ------------------------------------------------------------ | 3781| Promise<Array<[string, number]>> | Promise used to send the synchronization result. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | 3782 3783**Error codes** 3784 3785For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 3786 3787| **ID**| **Error Message** | 3788| ------------ | ---------------------------- | 3789| 14800000 | Inner error. | 3790 3791**Example** 3792 3793```ts 3794import deviceManager from '@ohos.distributedDeviceManager'; 3795import { BusinessError } from "@ohos.base"; 3796 3797let dmInstance: deviceManager.DeviceManager; 3798let deviceIds: Array<string> = []; 3799 3800try { 3801 dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify"); 3802 let devices: Array<deviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 3803 for (let i = 0; i < devices.length; i++) { 3804 deviceIds[i] = devices[i].networkId!; 3805 } 3806} catch (err) { 3807 let code = (err as BusinessError).code; 3808 let message = (err as BusinessError).message 3809 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 3810} 3811 3812let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 3813predicates.inDevices(deviceIds); 3814if(store != undefined) { 3815 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates).then((result: Object[][]) => { 3816 console.info('Sync done.'); 3817 for (let i = 0; i < result.length; i++) { 3818 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 3819 } 3820 }).catch((err: BusinessError) => { 3821 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 3822 }) 3823} 3824``` 3825 3826### cloudSync<sup>10+</sup> 3827 3828cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 3829 3830Manually starts device-cloud synchronization 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. 3831 3832**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3833 3834**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 3835 3836**Parameters** 3837 3838| Name | Type | Mandatory| Description | 3839| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 3840| mode | [SyncMode](#syncmode) | Yes | Synchronization mode of the database. | 3841| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database synchronization details. | 3842| callback | AsyncCallback<void> | Yes | Callback invoked to send the synchronization result to the caller.| 3843 3844**Example** 3845 3846```ts 3847if(store != undefined) { 3848 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetails) => { 3849 console.info(`Progess: ${progressDetails}`); 3850 }, (err) => { 3851 if (err) { 3852 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 3853 return; 3854 } 3855 console.info('Cloud sync succeeded'); 3856 }); 3857} 3858``` 3859 3860### cloudSync<sup>10+</sup> 3861 3862cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>): Promise<void> 3863 3864Manually starts device-cloud synchronization 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. 3865 3866**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3867 3868**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 3869 3870**Parameters** 3871 3872| Name | Type | Mandatory| Description | 3873| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 3874| mode | [SyncMode](#syncmode) | Yes | Synchronization mode of the database. | 3875| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database synchronization details.| 3876 3877**Return value** 3878 3879| Type | Description | 3880| ------------------- | --------------------------------------- | 3881| Promise<void> | Promise used to send the synchronization result.| 3882 3883**Example** 3884 3885```ts 3886import { BusinessError } from "@ohos.base"; 3887 3888if(store != undefined) { 3889 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetail: relationalStore.ProgressDetails) => { 3890 console.info(`progress: ${progressDetail}`); 3891 }).then(() => { 3892 console.info('Cloud sync succeeded'); 3893 }).catch((err: BusinessError) => { 3894 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 3895 }); 3896} 3897``` 3898 3899### cloudSync<sup>10+</sup> 3900 3901cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 3902 3903Manually starts device-cloud synchronization 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. 3904 3905**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3906 3907**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 3908 3909**Parameters** 3910 3911| Name | Type | Mandatory| Description | 3912| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 3913| mode | [SyncMode](#syncmode) | Yes | Synchronization mode of the database. | 3914| tables | string[] | Yes | Name of the table to synchronize. | 3915| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database synchronization details. | 3916| callback | AsyncCallback<void> | Yes | Callback invoked to send the synchronization result to the caller.| 3917 3918**Example** 3919 3920```ts 3921const tables = ["table1", "table2"]; 3922 3923if(store != undefined) { 3924 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => { 3925 console.info(`Progess: ${progressDetail}`); 3926 }, (err) => { 3927 if (err) { 3928 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 3929 return; 3930 } 3931 console.info('Cloud sync succeeded'); 3932 }); 3933}; 3934``` 3935 3936### cloudSync<sup>10+</sup> 3937 3938cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>): Promise<void> 3939 3940Manually starts device-cloud synchronization 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. 3941 3942**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3943 3944**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 3945 3946**Parameters** 3947 3948| Name | Type | Mandatory| Description | 3949| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 3950| mode | [SyncMode](#syncmode) | Yes | Synchronization mode of the database. | 3951| tables | string[] | Yes | Name of the table to synchronize. | 3952| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback used to process database synchronization details.| 3953 3954**Return value** 3955 3956| Type | Description | 3957| ------------------- | --------------------------------------- | 3958| Promise<void> | Promise used to send the synchronization result.| 3959 3960**Example** 3961 3962```ts 3963import { BusinessError } from "@ohos.base"; 3964 3965const tables = ["table1", "table2"]; 3966 3967if(store != undefined) { 3968 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetail: relationalStore.ProgressDetails) => { 3969 console.info(`progress: ${progressDetail}`); 3970 }).then(() => { 3971 console.info('Cloud sync succeeded'); 3972 }).catch((err: BusinessError) => { 3973 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 3974 }); 3975}; 3976``` 3977 3978### on('dataChange') 3979 3980on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 3981 3982Registers a data change event listener for the RDB store. When the data in the RDB store changes, a callback is invoked to return the data changes. 3983 3984**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 3985 3986**Parameters** 3987 3988| Name | Type | Mandatory| Description | 3989| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3990| event | string | Yes | Event type. The value is **dataChange**, which indicates data changes. | 3991| type | [SubscribeType](#subscribetype) | Yes | Subscription type to register. | 3992| observer | Callback<Array<string>> | Yes | Callback invoked to return the data change. **Array<string>** indicates the IDs of the peer devices whose data in the database is changed.| 3993 3994**Example** 3995 3996```ts 3997import deviceManager from '@ohos.distributedHardware.deviceManager'; 3998 3999let devices: string | undefined = undefined; 4000 4001try { 4002 if (store != undefined) { 4003 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, (storeObserver) => { 4004 if (devices != undefined) { 4005 for (let i = 0; i < devices.length; i++) { 4006 console.info(`device= ${devices[i]} data changed`); 4007 } 4008 } 4009 }) 4010 } 4011} catch (err) { 4012 let code = (err as BusinessError).code; 4013 let message = (err as BusinessError).message 4014 console.error(`Register observer failed, code is ${code},message is ${message}`); 4015} 4016``` 4017 4018### on('dataChange')<sup>10+</sup> 4019 4020on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 4021 4022Registers a data change event listener for the RDB store. When the data in the RDB store changes, a callback is invoked to return the data changes. 4023 4024**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4025 4026**Parameters** 4027 4028| Name | Type | Mandatory| Description | 4029| -------- | ----------------------------------- | ---- | ------------------------------------------- | 4030| event | string | Yes | Event type. The value is **dataChange**, which indicates data changes. | 4031| type | [SubscribeType](#subscribetype) | Yes | Subscription type to register.| 4032| observer | Callback<Array<string>> \| Callback<Array<[ChangeInfo](#changeinfo10)>> | Yes | Callback invoked to return the data change.<br>If **type** is **SUBSCRIBE_TYPE_REMOTE**, **observer** must be **Callback<Array<string>>**, where **Array<string>** specifies 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>** specifies the cloud accounts with data changes.<br>If **type** is **SUBSCRIBE_TYPE_CLOUD_DETAILS**, **observer** must be **Callback<Array<ChangeInfo>>**, where **Array<ChangeInfo>** specifies the details about the device-cloud synchronization. | 4033 4034**Example** 4035 4036```ts 4037import deviceManager from '@ohos.distributedHardware.deviceManager'; 4038 4039let devices: string | undefined = undefined; 4040 4041try { 4042 if(store != undefined) { 4043 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver => { 4044 if (devices != undefined) { 4045 for (let i = 0; i < devices.length; i++) { 4046 console.info(`device= ${devices[i]} data changed`); 4047 } 4048 } 4049 }); 4050 } 4051} catch (err) { 4052 let code = (err as BusinessError).code; 4053 let message = (err as BusinessError).message 4054 console.error(`Register observer failed, code is ${code},message is ${message}`); 4055} 4056``` 4057 4058### on<sup>10+</sup> 4059 4060on(event: string, interProcess: boolean, observer: Callback\<void>): void 4061 4062Registers an intra-process or inter-process event listener for the RDB store. This callback is invoked by [emit](#emit10). 4063 4064**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4065 4066**Parameters** 4067 4068| Name | Type | Mandatory| Description | 4069| ------------ | --------------- | ---- | ------------------------------------------------------------ | 4070| event | string | Yes | Event name to observe. | 4071| interProcess | boolean | Yes | Type of the event to observe.<br>The value **true** means the inter-process event.<br>The value **false** means the intra-process event.| 4072| observer | Callback\<void> | Yes | Callback invoked to return the result. | 4073 4074**Error codes** 4075 4076For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4077 4078| **ID**| **Error Message** | 4079| ------------ | -------------------------------------- | 4080| 14800000 | Inner error. | 4081| 14800050 | Failed to obtain subscription service. | 4082 4083**Example** 4084 4085```ts 4086try { 4087 if(store != undefined) { 4088 (store as relationalStore.RdbStore).on('storeObserver', false, (storeObserver) => { 4089 console.info(`storeObserver`); 4090 }); 4091 } 4092} catch (err) { 4093 let code = (err as BusinessError).code; 4094 let message = (err as BusinessError).message 4095 console.error(`Register observer failed, code is ${code},message is ${message}`); 4096} 4097``` 4098 4099### on('autoSyncProgress')<sup>11+</sup> 4100 4101on(event: 'autoSyncProgress', progress: Callback<ProgressDetails>): void 4102 4103Registers a listener for the auto synchronization progress. This API can be called only when device-cloud synchronization is enabled and the network connection is normal. When auto synchronization is performed, a callback will be invoked to send a notification of the synchronization progress. 4104 4105**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4106 4107**Parameters** 4108 4109| Name | Type | Mandatory| Description | 4110| ------------ |---------------------------------| ---- |-----------------------------------| 4111| event | string | Yes | Event type. The value is **autoSyncProgress**, which indicates the auto synchronization progress.| 4112| progress | Callback<[ProgressDetails](#progressdetails10)> | Yes | Callback invoked to return the auto synchronization progress. | 4113 4114**Example** 4115 4116```ts 4117import {BusinessError} from "@ohos.base"; 4118 4119try { 4120 if(store != undefined) { 4121 (store as relationalStore.RdbStore).on('autoSyncProgress', (progressDetail: relationalStore.ProgressDetails) => { 4122 console.info(`progress: ${progressDetail}`); 4123 }); 4124 } 4125} catch (err) { 4126 let code = (err as BusinessError).code; 4127 let message = (err as BusinessError).message 4128 console.error(`Register observer failed, code is ${code},message is ${message}`); 4129} 4130``` 4131 4132### off('dataChange') 4133 4134off(event:'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 4135 4136Unregisters the data change event listener. 4137 4138**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4139 4140**Parameters** 4141 4142| Name | Type | Mandatory| Description | 4143| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4144| event | string | Yes | Event type. The value is **dataChange**, which indicates data changes. | 4145| type | [SubscribeType](#subscribetype) | Yes | Subscription type to unregister. | 4146| observer | Callback<Array<string>> | Yes | Callback for the data change. **Array<string>** indicates the IDs of the peer devices whose data in the database is changed. | 4147 4148**Example** 4149 4150```ts 4151let devices: string | undefined = undefined; 4152 4153try { 4154 if(store != undefined) { 4155 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, (storeObserver) => { 4156 if (devices != undefined){ 4157 for (let i = 0; i < devices.length; i++) { 4158 console.info(`device= ${devices[i]} data changed`); 4159 } 4160 } 4161 }); 4162 } 4163} catch (err) { 4164 let code = (err as BusinessError).code; 4165 let message = (err as BusinessError).message 4166 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 4167} 4168``` 4169 4170### off('dataChange')<sup>10+</sup> 4171 4172off(event:'dataChange', type: SubscribeType, observer?: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 4173 4174Unregisters the data change event listener. 4175 4176**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4177 4178**Parameters** 4179 4180| Name | Type | Mandatory| Description | 4181| -------- | ---------------------------------- | ---- | ------------------------------------------ | 4182| event | string | Yes | Event type. The value is **dataChange**, which indicates data changes. | 4183| type | [SubscribeType](#subscribetype) | Yes | Subscription type to unregister. | 4184| observer | Callback<Array<string>>\| Callback<Array<[ChangeInfo](#changeinfo10)>> | No| Callback for the data change.<br>If **type** is **SUBSCRIBE_TYPE_REMOTE**, **observer** must be **Callback<Array<string>>**, where **Array<string>** specifies 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>** specifies the cloud accounts with data changes.<br>If **type** is **SUBSCRIBE_TYPE_CLOUD_DETAILS**, **observer** must be **Callback<Array<ChangeInfo>>**, where **Array<ChangeInfo>** specifies the details about the device-cloud synchronization.<br>If **observer** is not specified, listening for all data change events of the specified **type** will be canceled. | 4185 4186**Example** 4187 4188```ts 4189import deviceManager from '@ohos.distributedHardware.deviceManager'; 4190 4191let devices: string | undefined = undefined; 4192 4193try { 4194 if(store != undefined) { 4195 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, (storeObserver) => { 4196 if (devices != undefined) { 4197 for (let i = 0; i < devices.length; i++) { 4198 console.info(`device= ${devices[i]} data changed`); 4199 } 4200 } 4201 }); 4202 } 4203} catch (err) { 4204 let code = (err as BusinessError).code; 4205 let message = (err as BusinessError).message 4206 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 4207} 4208``` 4209 4210### off<sup>10+</sup> 4211 4212off(event: string, interProcess: boolean, observer?: Callback\<void>): void 4213 4214Unregisters the data change event listener. 4215 4216**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4217 4218**Parameters** 4219 4220| Name | Type | Mandatory| Description | 4221| ------------ | --------------- | ---- | ------------------------------------------------------------ | 4222| event | string | Yes | Name of the event. | 4223| interProcess | boolean | Yes | Type of the event.<br>The value **true** means the inter-process event.<br>The value **false** means the intra-process event.| 4224| observer | Callback\<void> | No | Callback for the event to unregister.<br/>If this parameter is specified, the specified callback will be unregistered. If this parameter is not specified, all callbacks of the specified event will be unregistered. | 4225 4226**Error codes** 4227 4228For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4229 4230| **ID**| **Error Message** | 4231| ------------ | -------------------------------------- | 4232| 14800000 | Inner error. | 4233| 14800050 | Failed to obtain subscription service. | 4234 4235**Example** 4236 4237```ts 4238try { 4239 if(store != undefined) { 4240 (store as relationalStore.RdbStore).off('storeObserver', false, (storeObserver) => { 4241 console.info(`storeObserver`); 4242 }); 4243 } 4244} catch (err) { 4245 let code = (err as BusinessError).code; 4246 let message = (err as BusinessError).message 4247 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 4248} 4249``` 4250 4251### off('autoSyncProgress')<sup>11+</sup> 4252 4253off(event: 'autoSyncProgress', progress?: Callback<ProgressDetails>): void 4254 4255Unregisters the listener for the auto synchronization progress. 4256 4257**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4258 4259**Parameters** 4260 4261| Name | Type | Mandatory| Description | 4262| ------------ |---------------------------------| ---- |------------------------------------------------------------------| 4263| event | string | Yes | Event type. The value is **autoSyncProgress**, which indicates the auto synchronization progress. | 4264| observer | Callback<[ProgressDetails](#progressdetails10)> | No | Callback for the auto synchronization progress. If this parameter is specified, the specified callback will be unregistered. If this parameter is **null** or **undefined** or not specified, all callbacks for **autoSyncProgress** will be unregistered.| 4265 4266**Example** 4267 4268```ts 4269import {BusinessError} from "@ohos.base"; 4270 4271try { 4272 if(store != undefined) { 4273 (store as relationalStore.RdbStore).off('autoSyncProgress', (progressDetail: relationalStore.ProgressDetails) => { 4274 console.info(`progress: ${progressDetail}`); 4275 }); 4276 } 4277} catch (err) { 4278 let code = (err as BusinessError).code; 4279 let message = (err as BusinessError).message; 4280 console.error(`Unregister failed, code is ${code},message is ${message}`); 4281} 4282``` 4283 4284### emit<sup>10+</sup> 4285 4286emit(event: string): void 4287 4288Triggers the inter-process or intra-process event listener registered through [on](#on10). 4289 4290**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4291 4292**Parameters** 4293 4294| Name| Type | Mandatory| Description | 4295| ------ | ------ | ---- | -------------------- | 4296| event | string | Yes | Name of the event.| 4297 4298**Error codes** 4299 4300For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4301 4302| **ID**| **Error Message** | 4303| ------------ | -------------------------------------- | 4304| 14800000 | Inner error. | 4305| 14800050 | Failed to obtain subscription service. | 4306 4307**Example** 4308 4309```ts 4310if(store != undefined) { 4311 (store as relationalStore.RdbStore).emit('storeObserver'); 4312} 4313``` 4314 4315### cleanDirtyData<sup>11+</sup> 4316 4317cleanDirtyData(table: string, cursor: number, callback: AsyncCallback<void>): void 4318 4319Clears the dirty data with the cursor smaller than the specified cursor from the local device. The dirty data is the data that has been deleted from the cloud. 4320 4321**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 4322 4323**Parameters** 4324 4325| Name | Type | Mandatory| Description | 4326| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 4327| table | string | Yes | Name of the table in the RDB store. | 4328| 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. | 4329| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| 4330 4331**Error codes** 4332 4333For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4334 4335| **ID**| **Error Message** | 4336| ------------ | -------------------------------------- | 4337| 14800000 | Inner error. | 4338 4339**Example** 4340 4341```ts 4342if(store != undefined) { 4343 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100, (err) => { 4344 if (err) { 4345 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 4346 return; 4347 } 4348 console.info('clean dirty data succeeded'); 4349 }) 4350} 4351``` 4352 4353### cleanDirtyData<sup>11+</sup> 4354 4355cleanDirtyData(table: string, callback: AsyncCallback<void>): void 4356 4357Clears all dirty data from the local device. The dirty data is the data that has been deleted from the cloud. 4358 4359**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 4360 4361**Parameters** 4362 4363| Name | Type | Mandatory| Description | 4364| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 4365| table | string | Yes | Name of the table in the RDB store.| 4366| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| 4367 4368**Error codes** 4369 4370For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4371 4372| **ID**| **Error Message** | 4373| ------------ | -------------------------------------- | 4374| 14800000 | Inner error. | 4375 4376**Example** 4377 4378```ts 4379if(store != undefined) { 4380 (store as relationalStore.RdbStore).cleanDirtyData('test_table', (err) => { 4381 if (err) { 4382 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 4383 return; 4384 } 4385 console.info('clean dirty data succeeded'); 4386 }) 4387} 4388``` 4389 4390### cleanDirtyData<sup>11+</sup> 4391 4392cleanDirtyData(table: string, cursor?: number): Promise<void> 4393 4394Clears the dirty data with the cursor 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. 4395 4396**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 4397 4398**Parameters** 4399 4400| Name | Type | Mandatory| Description | 4401| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 4402| table | string | Yes | Name of the table in the RDB store. | 4403| 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. | 4404 4405**Return value** 4406| Name | Description | 4407| -------- | ------------------------------------------------- | 4408| Promise\<void> | Promise that returns no value. | 4409 4410**Error codes** 4411 4412For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4413 4414| **ID**| **Error Message** | 4415| ------------ | -------------------------------------- | 4416| 14800000 | Inner error. | 4417 4418**Example** 4419 4420```ts 4421import { BusinessError } from "@ohos.base"; 4422 4423if(store != undefined) { 4424 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100).then(() => { 4425 console.info('clean dirty data succeeded'); 4426 }).catch ((err: BusinessError) => { 4427 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 4428 }) 4429} 4430``` 4431 4432## ResultSet 4433 4434Provides APIs to access the **resultSet** object returned by **query()**. 4435 4436### Usage 4437 4438Obtain the **resultSet** object first. 4439 4440**Example** 4441 4442```ts 4443let resultSet: relationalStore.ResultSet | undefined = undefined; 4444let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 4445predicates.equalTo("AGE", 18); 4446if(store != undefined) { 4447 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((result: relationalStore.ResultSet) => { 4448 resultSet = result; 4449 console.info(`resultSet columnNames: ${resultSet.columnNames}`); 4450 console.info(`resultSet columnCount: ${resultSet.columnCount}`); 4451 }); 4452} 4453``` 4454 4455### Attributes 4456 4457**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4458 4459| Name | Type | Mandatory| Description | 4460| ------------ | ------------------- | ---- | -------------------------------- | 4461| columnNames | Array<string> | Yes | Names of all columns in the result set. | 4462| columnCount | number | Yes | Number of columns in the result set. | 4463| rowCount | number | Yes | Number of rows in the result set. | 4464| rowIndex | number | Yes | Index of the current row in the result set. | 4465| isAtFirstRow | boolean | Yes | Whether the cursor is in the first row of the result set. | 4466| isAtLastRow | boolean | Yes | Whether the cursor is in the last row of the result set. | 4467| isEnded | boolean | Yes | Whether the cursor is after the last row of the result set.| 4468| isStarted | boolean | Yes | Whether the cursor has been moved. | 4469| isClosed | boolean | Yes | Whether the result set is closed. | 4470 4471### getColumnIndex 4472 4473getColumnIndex(columnName: string): number 4474 4475Obtains the column index based on the column name. 4476 4477**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4478 4479**Parameters** 4480 4481| Name | Type | Mandatory| Description | 4482| ---------- | ------ | ---- | -------------------------- | 4483| columnName | string | Yes | Column name.| 4484 4485**Return value** 4486 4487| Type | Description | 4488| ------ | ------------------ | 4489| number | Column index obtained.| 4490 4491**Error codes** 4492 4493For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4494 4495| **ID**| **Error Message** | 4496| ------------ | ------------------------------------------------------------ | 4497| 14800013 | The column value is null or the column type is incompatible. | 4498 4499**Example** 4500 4501```ts 4502if(resultSet != undefined) { 4503 const id = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("ID")); 4504 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 4505 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 4506 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 4507} 4508``` 4509 4510### getColumnName 4511 4512getColumnName(columnIndex: number): string 4513 4514Obtains the column name based on the specified column index. 4515 4516**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4517 4518**Parameters** 4519 4520| Name | Type | Mandatory| Description | 4521| ----------- | ------ | ---- | -------------------------- | 4522| columnIndex | number | Yes | Column index.| 4523 4524**Return value** 4525 4526| Type | Description | 4527| ------ | ------------------ | 4528| string | Column name obtained.| 4529 4530**Error codes** 4531 4532For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4533 4534| **ID**| **Error Message** | 4535| ------------ | ------------------------------------------------------------ | 4536| 14800013 | The column value is null or the column type is incompatible. | 4537 4538**Example** 4539 4540```ts 4541if(resultSet != undefined) { 4542 const id = (resultSet as relationalStore.ResultSet).getColumnName(0); 4543 const name = (resultSet as relationalStore.ResultSet).getColumnName(1); 4544 const age = (resultSet as relationalStore.ResultSet).getColumnName(2); 4545} 4546``` 4547 4548### goTo 4549 4550goTo(offset:number): boolean 4551 4552Moves the cursor to the row based on the specified offset. 4553 4554**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4555 4556**Parameters** 4557 4558| Name| Type | Mandatory| Description | 4559| ------ | ------ | ---- | ---------------------------- | 4560| offset | number | Yes | Offset relative to the current position.| 4561 4562**Return value** 4563 4564| Type | Description | 4565| ------- | --------------------------------------------- | 4566| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 4567 4568**Error codes** 4569 4570For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4571 4572| **ID**| **Error Message** | 4573| ------------ | ------------------------------------------------------------ | 4574| 14800012 | The result set is empty or the specified location is invalid. | 4575 4576**Example** 4577 4578```ts 4579if(resultSet != undefined) { 4580 (resultSet as relationalStore.ResultSet).goTo(1); 4581} 4582``` 4583 4584### goToRow 4585 4586goToRow(position: number): boolean 4587 4588Moves to the specified row in the result set. 4589 4590**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4591 4592**Parameters** 4593 4594| Name | Type | Mandatory| Description | 4595| -------- | ------ | ---- | ------------------------ | 4596| position | number | Yes | Destination position to move to.| 4597 4598**Return value** 4599 4600| Type | Description | 4601| ------- | --------------------------------------------- | 4602| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 4603 4604**Error codes** 4605 4606For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4607 4608| **ID**| **Error Message** | 4609| ------------ | ------------------------------------------------------------ | 4610| 14800012 | The result set is empty or the specified location is invalid. | 4611 4612**Example** 4613 4614```ts 4615if(resultSet != undefined) { 4616 (resultSet as relationalStore.ResultSet).goToRow(5); 4617} 4618``` 4619 4620### goToFirstRow 4621 4622goToFirstRow(): boolean 4623 4624 4625Moves to the first row of the result set. 4626 4627**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4628 4629**Return value** 4630 4631| Type | Description | 4632| ------- | --------------------------------------------- | 4633| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 4634 4635**Error codes** 4636 4637For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4638 4639| **ID**| **Error Message** | 4640| ------------ | ------------------------------------------------------------ | 4641| 14800012 | The result set is empty or the specified location is invalid. | 4642 4643**Example** 4644 4645```ts 4646if(resultSet != undefined) { 4647 (resultSet as relationalStore.ResultSet).goToFirstRow(); 4648} 4649``` 4650 4651### goToLastRow 4652 4653goToLastRow(): boolean 4654 4655Moves to the last row of the result set. 4656 4657**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4658 4659**Return value** 4660 4661| Type | Description | 4662| ------- | --------------------------------------------- | 4663| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 4664 4665**Error codes** 4666 4667For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4668 4669| **ID**| **Error Message** | 4670| ------------ | ------------------------------------------------------------ | 4671| 14800012 | The result set is empty or the specified location is invalid. | 4672 4673**Example** 4674 4675```ts 4676if(resultSet != undefined) { 4677 (resultSet as relationalStore.ResultSet).goToLastRow(); 4678} 4679``` 4680 4681### goToNextRow 4682 4683goToNextRow(): boolean 4684 4685Moves to the next row in the result set. 4686 4687**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4688 4689**Return value** 4690 4691| Type | Description | 4692| ------- | --------------------------------------------- | 4693| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 4694 4695**Error codes** 4696 4697For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4698 4699| **ID**| **Error Message** | 4700| ------------ | ------------------------------------------------------------ | 4701| 14800012 | The result set is empty or the specified location is invalid. | 4702 4703**Example** 4704 4705```ts 4706if(resultSet != undefined) { 4707 (resultSet as relationalStore.ResultSet).goToNextRow(); 4708} 4709``` 4710 4711### goToPreviousRow 4712 4713goToPreviousRow(): boolean 4714 4715Moves to the previous row in the result set. 4716 4717**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4718 4719**Return value** 4720 4721| Type | Description | 4722| ------- | --------------------------------------------- | 4723| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| 4724 4725**Error codes** 4726 4727For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4728 4729| **ID**| **Error Message** | 4730| ------------ | ------------------------------------------------------------ | 4731| 14800012 | The result set is empty or the specified location is invalid. | 4732 4733**Example** 4734 4735```ts 4736if(resultSet != undefined) { 4737 (resultSet as relationalStore.ResultSet).goToPreviousRow(); 4738} 4739``` 4740 4741### getBlob 4742 4743getBlob(columnIndex: number): Uint8Array 4744 4745Obtains the value in the form of a byte array based on the specified column and the current row. 4746 4747**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4748 4749**Parameters** 4750 4751| Name | Type | Mandatory| Description | 4752| ----------- | ------ | ---- | ----------------------- | 4753| columnIndex | number | Yes | Index of the target column, starting from 0.| 4754 4755**Return value** 4756 4757| Type | Description | 4758| ---------- | -------------------------------- | 4759| Uint8Array | Value obtained.| 4760 4761**Error codes** 4762 4763For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4764 4765| **ID**| **Error Message** | 4766| ------------ | ------------------------------------------------------------ | 4767| 14800013 | The column value is null or the column type is incompatible. | 4768 4769**Example** 4770 4771```ts 4772if(resultSet != undefined) { 4773 const codes = (resultSet as relationalStore.ResultSet).getBlob((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 4774} 4775``` 4776 4777### getString 4778 4779getString(columnIndex: number): string 4780 4781Obtains the value in the form of a string based on the specified column and the current row. 4782 4783**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4784 4785**Parameters** 4786 4787| Name | Type | Mandatory| Description | 4788| ----------- | ------ | ---- | ----------------------- | 4789| columnIndex | number | Yes | Index of the target column, starting from 0.| 4790 4791**Return value** 4792 4793| Type | Description | 4794| ------ | ---------------------------- | 4795| string | String obtained.| 4796 4797**Error codes** 4798 4799For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4800 4801| **ID**| **Error Message** | 4802| ------------ | ------------------------------------------------------------ | 4803| 14800013 | The column value is null or the column type is incompatible. | 4804 4805**Example** 4806 4807```ts 4808if(resultSet != undefined) { 4809 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 4810} 4811``` 4812 4813### getLong 4814 4815getLong(columnIndex: number): number 4816 4817Obtains the value of the Long type based on the specified column and the current row. 4818 4819**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4820 4821**Parameters** 4822 4823| Name | Type | Mandatory| Description | 4824| ----------- | ------ | ---- | ----------------------- | 4825| columnIndex | number | Yes | Index of the target column, starting from 0.| 4826 4827**Return value** 4828 4829| Type | Description | 4830| ------ | ------------------------------------------------------------ | 4831| 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).| 4832 4833**Error codes** 4834 4835For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4836 4837| **ID**| **Error Message** | 4838| ------------ | ------------------------------------------------------------ | 4839| 14800013 | The column value is null or the column type is incompatible. | 4840 4841**Example** 4842 4843```ts 4844if(resultSet != undefined) { 4845 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 4846 } 4847``` 4848 4849### getDouble 4850 4851getDouble(columnIndex: number): number 4852 4853Obtains the value of the double type based on the specified column and the current row. 4854 4855**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4856 4857**Parameters** 4858 4859| Name | Type | Mandatory| Description | 4860| ----------- | ------ | ---- | ----------------------- | 4861| columnIndex | number | Yes | Index of the target column, starting from 0.| 4862 4863**Return value** 4864 4865| Type | Description | 4866| ------ | ---------------------------- | 4867| number | Returns the value obtained.| 4868 4869**Error codes** 4870 4871For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4872 4873| **ID**| **Error Message** | 4874| ------------ | ------------------------------------------------------------ | 4875| 14800013 | The column value is null or the column type is incompatible. | 4876 4877**Example** 4878 4879```ts 4880if(resultSet != undefined) { 4881 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 4882} 4883``` 4884 4885### getAsset<sup>10+</sup> 4886 4887getAsset(columnIndex: number): Asset 4888 4889Obtains the value in the [Asset](#asset10) format based on the specified column and current row. 4890 4891**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4892 4893**Parameters** 4894 4895| Name | Type | Mandatory | Description | 4896| ----------- | ------ | --- | ------------ | 4897| columnIndex | number | Yes | Index of the target column, starting from 0.| 4898 4899**Return value** 4900 4901| Type | Description | 4902| --------------- | -------------------------- | 4903| [Asset](#asset10) | Returns the value obtained.| 4904 4905**Error codes** 4906 4907For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4908 4909| **ID**| **Error Message** | 4910| --------- | ------------------------------------------------------------ | 4911| 14800013 | The column value is null or the column type is incompatible. | 4912 4913**Example** 4914 4915```ts 4916if(resultSet != undefined) { 4917 const doc = (resultSet as relationalStore.ResultSet).getAsset((resultSet as relationalStore.ResultSet).getColumnIndex("DOC")); 4918} 4919``` 4920 4921### getAssets<sup>10+</sup> 4922 4923getAssets(columnIndex: number): Assets 4924 4925Obtains the value in the [Assets](#assets10) format based on the specified column and current row. 4926 4927**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4928 4929**Parameters** 4930 4931| Name | Type | Mandatory | Description | 4932| ----------- | ------ | --- | ------------ | 4933| columnIndex | number | Yes | Index of the target column, starting from 0.| 4934 4935**Return value** 4936 4937| Type | Description | 4938| ---------------- | ---------------------------- | 4939| [Assets](#assets10)| Returns the value obtained.| 4940 4941**Error codes** 4942 4943For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4944 4945| **ID**| **Error Message** | 4946| ------------ | ------------------------------------------------------------ | 4947| 14800013 | The column value is null or the column type is incompatible. | 4948 4949**Example** 4950 4951```ts 4952if(resultSet != undefined) { 4953 const docs = (resultSet as relationalStore.ResultSet).getAssets((resultSet as relationalStore.ResultSet).getColumnIndex("DOCS")); 4954} 4955``` 4956 4957### getRow<sup>11+</sup> 4958 4959getRow(): ValuesBucket 4960 4961Obtains the data in the current row. 4962 4963**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4964 4965**Return value** 4966 4967| Type | Description | 4968| ---------------- | ---------------------------- | 4969| [ValuesBucket](#valuesbucket) | Data obtained.| 4970 4971**Error codes** 4972 4973For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 4974 4975| **ID**| **Error Message** | 4976| ------------ | ---------------------------- | 4977| 14800000 | Inner error. | 4978 4979**Example** 4980 4981```ts 4982if(resultSet != undefined) { 4983 const row = (resultSet as relationalStore.ResultSet).getRow(); 4984} 4985``` 4986 4987### isColumnNull 4988 4989isColumnNull(columnIndex: number): boolean 4990 4991Checks whether the value in the specified column is null. 4992 4993**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 4994 4995**Parameters** 4996 4997| Name | Type | Mandatory| Description | 4998| ----------- | ------ | ---- | ----------------------- | 4999| columnIndex | number | Yes | Index of the target column, starting from 0.| 5000 5001**Return value** 5002 5003| Type | Description | 5004| ------- | --------------------------------------------------------- | 5005| boolean | Returns **true** if the value is null; returns **false** otherwise.| 5006 5007**Error codes** 5008 5009For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 5010 5011| **ID**| **Error Message** | 5012| ------------ | ------------------------------------------------------------ | 5013| 14800013 | The column value is null or the column type is incompatible. | 5014 5015**Example** 5016 5017```ts 5018if(resultSet != undefined) { 5019 const isColumnNull = (resultSet as relationalStore.ResultSet).isColumnNull((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 5020} 5021``` 5022 5023### close 5024 5025close(): void 5026 5027Closes this result set. 5028 5029**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core 5030 5031**Example** 5032 5033```ts 5034if(resultSet != undefined) { 5035 (resultSet as relationalStore.ResultSet).close(); 5036} 5037``` 5038 5039**Error codes** 5040 5041For details about the error codes, see [RDB Error Codes](errorcode-data-rdb.md). 5042 5043| **ID**| **Error Message** | 5044| ------------ | ------------------------------------------------------------ | 5045| 14800012 | The result set is empty or the specified location is invalid. | 5046 5047 5048<!--no_check-->