• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.data.relationalStore (RDB Store)
2
3The relational database (RDB) store manages data based on relational models. With the underlying SQLite database, the RDB store provides a complete mechanism for managing local databases. 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.
4
5The **relationalStore** module provides the following functions:
6
7- [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.
8- [RdbStore](#rdbstore): provides APIs for managing data in an RDB store.
9- [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store.
10
11> **NOTE**
12>
13> 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.
14
15## Modules to Import
16
17```js
18import relationalStore from '@ohos.data.relationalStore'
19```
20
21## relationalStore.getRdbStore
22
23getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback<RdbStore>): void
24
25Obtains 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.
26
27**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
28
29**Parameters**
30
31| Name  | Type                                          | Mandatory| Description                                                        |
32| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
33| context  | Context                                        | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
34| config   | [StoreConfig](#storeconfig)               | Yes  | Configuration of the RDB store.                               |
35| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes  | Callback invoked to return the RDB store obtained.                  |
36
37**Error codes**
38
39For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
40
41| **ID**| **Error Message**                                               |
42| ------------ | ----------------------------------------------------------- |
43| 14800010     | Failed to open or delete database by invalid database path. |
44| 14800011     | Failed to open database by database corrupted.              |
45| 14800000     | Inner error.                                                |
46
47**Example**
48
49FA model:
50
51```js
52
53import featureAbility from '@ohos.ability.featureAbility'
54
55var store;
56
57// Obtain the context.
58let context = featureAbility.getContext();
59
60const STORE_CONFIG = {
61  name: "RdbTest.db",
62  securityLevel: relationalStore.SecurityLevel.S1
63};
64
65relationalStore.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) {
66  store = rdbStore;
67  if (err) {
68    console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
69    return;
70  }
71  console.info(`Get RdbStore successfully.`);
72})
73```
74
75Stage model:
76
77```ts
78import UIAbility from '@ohos.app.ability.UIAbility'
79
80class EntryAbility extends UIAbility {
81  onWindowStageCreate(windowStage) {
82    var store;
83    const STORE_CONFIG = {
84      name: "RdbTest.db",
85      securityLevel: relationalStore.SecurityLevel.S1
86    };
87
88    relationalStore.getRdbStore(this.context, STORE_CONFIG, function (err, rdbStore) {
89      store = rdbStore;
90      if (err) {
91        console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
92        return;
93      }
94      console.info(`Get RdbStore successfully.`);
95    })
96  }
97}
98```
99
100## relationalStore.getRdbStore
101
102getRdbStore(context: Context, config: StoreConfig): Promise&lt;RdbStore&gt;
103
104Obtains 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.
105
106**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
107
108**Parameters**
109
110| Name | Type                            | Mandatory| Description                                                        |
111| ------- | -------------------------------- | ---- | ------------------------------------------------------------ |
112| context | Context                          | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
113| config  | [StoreConfig](#storeconfig) | Yes  | Configuration of the RDB store.                               |
114
115**Return value**
116
117| Type                                     | Description                             |
118| ----------------------------------------- | --------------------------------- |
119| Promise&lt;[RdbStore](#rdbstore)&gt; | Promise used to return the **RdbStore** object.|
120
121**Error codes**
122
123For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
124
125| **ID**| **Error Message**                                               |
126| ------------ | ----------------------------------------------------------- |
127| 14800010     | Failed to open or delete database by invalid database path. |
128| 14800011     | Failed to open database by database corrupted.              |
129| 14800000     | Inner error.                                                |
130
131**Example**
132
133FA model:
134
135```js
136import featureAbility from '@ohos.ability.featureAbility'
137
138var store;
139
140// Obtain the context.
141let context = featureAbility.getContext();
142
143const STORE_CONFIG = {
144  name: "RdbTest.db",
145  securityLevel: relationalStore.SecurityLevel.S1
146};
147
148let promise = relationalStore.getRdbStore(context, STORE_CONFIG);
149promise.then(async (rdbStore) => {
150  store = rdbStore;
151  console.info(`Get RdbStore successfully.`);
152}).catch((err) => {
153  console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
154})
155```
156
157Stage model:
158
159```ts
160import UIAbility from '@ohos.app.ability.UIAbility'
161
162class EntryAbility extends UIAbility {
163  onWindowStageCreate(windowStage) {
164    var store;
165    const STORE_CONFIG = {
166      name: "RdbTest.db",
167      securityLevel: relationalStore.SecurityLevel.S1
168    };
169
170    let promise = relationalStore.getRdbStore(this.context, STORE_CONFIG);
171    promise.then(async (rdbStore) => {
172      store = rdbStore;
173      console.info(`Get RdbStore successfully.`)
174    }).catch((err) => {
175      console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
176    })
177  }
178}
179```
180
181## relationalStore.deleteRdbStore
182
183deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
184
185Deletes an RDB store. This API uses an asynchronous callback to return the result.
186
187**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
188
189**Parameters**
190
191| Name  | Type                     | Mandatory| Description                                                        |
192| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
193| context  | Context                   | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
194| name     | string                    | Yes  | Name of the RDB store to delete.                                                |
195| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result.                                      |
196
197**Error codes**
198
199For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
200
201| **ID**| **Error Message**                                               |
202| ------------ | ----------------------------------------------------------- |
203| 14800010     | Failed to open or delete database by invalid database path. |
204| 14800000     | Inner error.                                                |
205
206**Example**
207
208FA model:
209
210```js
211import featureAbility from '@ohos.ability.featureAbility'
212
213// Obtain the context.
214let context = featureAbility.getContext()
215
216relationalStore.deleteRdbStore(context, "RdbTest.db", function (err) {
217  if (err) {
218    console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
219    return;
220  }
221  console.info(`Delete RdbStore successfully.`);
222})
223```
224
225Stage model:
226
227```ts
228import UIAbility from '@ohos.app.ability.UIAbility'
229
230class EntryAbility extends UIAbility {
231  onWindowStageCreate(windowStage){
232    relationalStore.deleteRdbStore(this.context, "RdbTest.db", function (err) {
233      if (err) {
234        console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
235        return;
236      }
237      console.info(`Delete RdbStore successfully.`);
238    })
239  }
240}
241```
242
243## relationalStore.deleteRdbStore
244
245deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;
246
247Deletes an RDB store. This API uses a promise to return the result.
248
249**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
250
251**Parameters**
252
253| Name | Type   | Mandatory| Description                                                        |
254| ------- | ------- | ---- | ------------------------------------------------------------ |
255| context | Context | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
256| name    | string  | Yes  | Name of the RDB store to delete.                                                |
257
258**Return value**
259
260| Type               | Description                     |
261| ------------------- | ------------------------- |
262| Promise&lt;void&gt; | Promise that returns no value.|
263
264**Error codes**
265
266For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
267
268| **ID**| **Error Message**                                               |
269| ------------ | ----------------------------------------------------------- |
270| 14800010     | Failed to open or delete database by invalid database path. |
271| 14800000     | Inner error.                                                |
272
273**Example**
274
275FA model:
276
277```js
278import featureAbility from '@ohos.ability.featureAbility'
279
280// Obtain the context.
281let context = featureAbility.getContext();
282
283let promise = relationalStore.deleteRdbStore(context, "RdbTest.db");
284promise.then(()=>{
285  console.info(`Delete RdbStore successfully.`);
286}).catch((err) => {
287  console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
288})
289```
290
291Stage model:
292
293```ts
294import UIAbility from '@ohos.app.ability.UIAbility'
295
296class EntryAbility extends UIAbility {
297  onWindowStageCreate(windowStage){
298    let promise = relationalStore.deleteRdbStore(this.context, "RdbTest.db");
299    promise.then(()=>{
300      console.info(`Delete RdbStore successfully.`);
301    }).catch((err) => {
302      console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
303    })
304  }
305}
306```
307
308## StoreConfig
309
310Defines the RDB store configuration.
311
312**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
313
314| Name       | Type         | Mandatory| Description                                                     |
315| ------------- | ------------- | ---- | --------------------------------------------------------- |
316| name          | string        | Yes  | Database file name.                                           |
317| securityLevel | [SecurityLevel](#securitylevel) | Yes  | Security level of the RDB store.                                       |
318| encrypt       | boolean       | No  | Whether to encrypt the RDB store.<br> The value **true** means to encrypt the RDB store;<br> the value **false** (default) means the opposite.|
319
320## SecurityLevel
321
322Enumerates the RDB store security levels.
323
324> **NOTE**
325>
326> 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 [Cross-Device Data Synchronization Mechanism]( ../../database/sync-app-data-across-devices-overview.md#cross-device-data-synchronization-mechanism).
327
328**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
329
330| Name| Value  | Description                                                        |
331| ---- | ---- | ------------------------------------------------------------ |
332| 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.|
333| 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.|
334| 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.|
335| 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.|
336
337## ValueType
338
339Defines the data types allowed.
340
341**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
342
343| Type   | Description                |
344| ------- | -------------------- |
345| number  | Number.  |
346| string  | String.  |
347| boolean | Boolean.|
348
349## ValuesBucket
350
351Defines the types of the key and value 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.
352
353**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
354
355| Key Type| Value Type                                                     |
356| ------ | ----------------------------------------------------------- |
357| string | [ValueType](#valuetype)\|&nbsp;Uint8Array&nbsp;\|&nbsp;null |
358
359## SyncMode
360
361Defines the database synchronization mode.
362
363**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
364
365| Name          | Value  | Description                              |
366| -------------- | ---- | ---------------------------------- |
367| SYNC_MODE_PUSH | 0    | Data is pushed from a local device to a remote device.|
368| SYNC_MODE_PULL | 1    | Data is pulled from a remote device to a local device.  |
369
370## SubscribeType
371
372Defines the subscription type.
373
374**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
375
376**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
377
378| Name                 | Value  | Description              |
379| --------------------- | ---- | ------------------ |
380| SUBSCRIBE_TYPE_REMOTE | 0    | Subscribe to remote data changes.|
381| SUBSCRIBE_TYPE_CLOUD<sup>10+</sup> | 1    | Subscribe to cloud data changes.|
382
383## ConflictResolution<sup>10+</sup>
384
385Defines the resolution to use when **insert()** and **update()** conflict.
386
387**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
388
389| Name                | Value  | Description                                                        |
390| -------------------- | ---- | ------------------------------------------------------------ |
391| ON_CONFLICT_NONE | 0 | No operation is performed.|
392| ON_CONFLICT_ROLLBACK | 1    | Abort the SQL statement and roll back the current transaction.               |
393| 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.|
394| 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.|
395| ON_CONFLICT_IGNORE   | 4    | Skip the rows that contain constraint violations and continue to process the subsequent rows of the SQL statement.|
396| 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.|
397
398## RdbPredicates
399
400Defines 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.
401
402### constructor
403
404constructor(name: string)
405
406A constructor used to create an **RdbPredicates** object.
407
408**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
409
410**Parameters**
411
412| Name| Type  | Mandatory| Description        |
413| ------ | ------ | ---- | ------------ |
414| name   | string | Yes  | Database table name.|
415
416**Example**
417
418```js
419let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
420```
421
422### inDevices
423
424inDevices(devices: Array&lt;string&gt;): RdbPredicates
425
426Sets an **RdbPredicates** to specify the remote devices to connect on the network during distributed database synchronization.
427
428> **NOTE**
429>
430> The value of **devices** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications.
431
432**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
433
434**Parameters**
435
436| Name | Type               | Mandatory| Description                      |
437| ------- | ------------------- | ---- | -------------------------- |
438| devices | Array&lt;string&gt; | Yes  | IDs of the remote devices in the same network.|
439
440**Return value**
441
442| Type                                | Description                      |
443| ------------------------------------ | -------------------------- |
444| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
445
446**Example**
447
448```js
449import deviceManager from '@ohos.distributedHardware.deviceManager';
450let dmInstance = null;
451let deviceIds = [];
452
453deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
454    if (err) {
455        console.log("create device manager failed, err=" + err);
456        return;
457    }
458    dmInstance = manager;
459    let devices = dmInstance.getTrustedDeviceListSync();
460    for (var i = 0; i < devices.length; i++) {
461        deviceIds[i] = devices[i].deviceId;
462    }
463})
464
465let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
466predicates.inDevices(deviceIds);
467```
468
469### inAllDevices
470
471inAllDevices(): RdbPredicates
472
473
474Sets an **RdbPredicates** to specify all remote devices on the network to connect during distributed database synchronization.
475
476**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
477
478**Return value**
479
480| Type                                | Description                      |
481| ------------------------------------ | -------------------------- |
482| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
483
484**Example**
485
486```js
487let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
488predicates.inAllDevices();
489```
490
491### equalTo
492
493equalTo(field: string, value: ValueType): RdbPredicates
494
495
496Sets an **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.
497
498**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
499
500**Parameters**
501
502| Name| Type                   | Mandatory| Description                  |
503| ------ | ----------------------- | ---- | ---------------------- |
504| field  | string                  | Yes  | Column name in the database table.    |
505| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|
506
507**Return value**
508
509| Type                                | Description                      |
510| ------------------------------------ | -------------------------- |
511| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
512
513**Example**
514
515```js
516let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
517predicates.equalTo("NAME", "lisi");
518```
519
520
521### notEqualTo
522
523notEqualTo(field: string, value: ValueType): RdbPredicates
524
525
526Sets an **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.
527
528**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
529
530**Parameters**
531
532| Name| Type                   | Mandatory| Description                  |
533| ------ | ----------------------- | ---- | ---------------------- |
534| field  | string                  | Yes  | Column name in the database table.    |
535| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|
536
537**Return value**
538
539| Type                                | Description                      |
540| ------------------------------------ | -------------------------- |
541| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
542
543**Example**
544
545```js
546let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
547predicates.notEqualTo("NAME", "lisi");
548```
549
550
551### beginWrap
552
553beginWrap(): RdbPredicates
554
555
556Adds a left parenthesis to the **RdbPredicates**.
557
558**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
559
560**Return value**
561
562| Type                                | Description                     |
563| ------------------------------------ | ------------------------- |
564| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.|
565
566**Example**
567
568```js
569let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
570predicates.equalTo("NAME", "lisi")
571    .beginWrap()
572    .equalTo("AGE", 18)
573    .or()
574    .equalTo("SALARY", 200.5)
575    .endWrap()
576```
577
578### endWrap
579
580endWrap(): RdbPredicates
581
582Adds a right parenthesis to the **RdbPredicates**.
583
584**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
585
586**Return value**
587
588| Type                                | Description                     |
589| ------------------------------------ | ------------------------- |
590| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.|
591
592**Example**
593
594```js
595let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
596predicates.equalTo("NAME", "lisi")
597    .beginWrap()
598    .equalTo("AGE", 18)
599    .or()
600    .equalTo("SALARY", 200.5)
601    .endWrap()
602```
603
604### or
605
606or(): RdbPredicates
607
608Adds the OR condition to the **RdbPredicates**.
609
610**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
611
612**Return value**
613
614| Type                                | Description                     |
615| ------------------------------------ | ------------------------- |
616| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.|
617
618**Example**
619
620```js
621let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
622predicates.equalTo("NAME", "Lisa")
623    .or()
624    .equalTo("NAME", "Rose")
625```
626
627### and
628
629and(): RdbPredicates
630
631Adds the AND condition to the **RdbPredicates**.
632
633**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
634
635**Return value**
636
637| Type                                | Description                     |
638| ------------------------------------ | ------------------------- |
639| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.|
640
641**Example**
642
643```js
644let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
645predicates.equalTo("NAME", "Lisa")
646    .and()
647    .equalTo("SALARY", 200.5)
648```
649
650### contains
651
652contains(field: string, value: string): RdbPredicates
653
654Sets an **RdbPredicates** to match a string containing the specified value.
655
656**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
657
658**Parameters**
659
660| Name| Type  | Mandatory| Description                  |
661| ------ | ------ | ---- | ---------------------- |
662| field  | string | Yes  | Column name in the database table.    |
663| value  | string | Yes  | Value to match the **RdbPredicates**.|
664
665**Return value**
666
667| Type                                | Description                      |
668| ------------------------------------ | -------------------------- |
669| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
670
671**Example**
672
673```js
674let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
675predicates.contains("NAME", "os");
676```
677
678### beginsWith
679
680beginsWith(field: string, value: string): RdbPredicates
681
682Sets an **RdbPredicates** to match a string that starts with the specified value.
683
684**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
685
686**Parameters**
687
688| Name| Type  | Mandatory| Description                  |
689| ------ | ------ | ---- | ---------------------- |
690| field  | string | Yes  | Column name in the database table.    |
691| value  | string | Yes  | Value to match the **RdbPredicates**.|
692
693**Return value**
694
695| Type                                | Description                      |
696| ------------------------------------ | -------------------------- |
697| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
698
699**Example**
700
701```js
702let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
703predicates.beginsWith("NAME", "os");
704```
705
706### endsWith
707
708endsWith(field: string, value: string): RdbPredicates
709
710Sets an **RdbPredicates** to match a string that ends with the specified value.
711
712**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
713
714**Parameters**
715
716| Name| Type  | Mandatory| Description                  |
717| ------ | ------ | ---- | ---------------------- |
718| field  | string | Yes  | Column name in the database table.    |
719| value  | string | Yes  | Value to match the **RdbPredicates**.|
720
721**Return value**
722
723| Type                                | Description                      |
724| ------------------------------------ | -------------------------- |
725| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
726
727**Example**
728
729```js
730let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
731predicates.endsWith("NAME", "se");
732```
733
734### isNull
735
736isNull(field: string): RdbPredicates
737
738Sets an **RdbPredicates** to match the field whose value is null.
739
740**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
741
742**Parameters**
743
744| Name| Type  | Mandatory| Description              |
745| ------ | ------ | ---- | ------------------ |
746| field  | string | Yes  | Column name in the database table.|
747
748**Return value**
749
750| Type                                | Description                      |
751| ------------------------------------ | -------------------------- |
752| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
753
754**Example**
755
756```js
757let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
758predicates.isNull("NAME");
759```
760
761### isNotNull
762
763isNotNull(field: string): RdbPredicates
764
765Sets an **RdbPredicates** to match the field whose value is not null.
766
767**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
768
769**Parameters**
770
771| Name| Type  | Mandatory| Description              |
772| ------ | ------ | ---- | ------------------ |
773| field  | string | Yes  | Column name in the database table.|
774
775**Return value**
776
777| Type                                | Description                      |
778| ------------------------------------ | -------------------------- |
779| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
780
781**Example**
782
783```js
784let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
785predicates.isNotNull("NAME");
786```
787
788### like
789
790like(field: string, value: string): RdbPredicates
791
792Sets an **RdbPredicates** to match a string that is similar to the specified value.
793
794**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
795
796**Parameters**
797
798| Name| Type  | Mandatory| Description                  |
799| ------ | ------ | ---- | ---------------------- |
800| field  | string | Yes  | Column name in the database table.    |
801| value  | string | Yes  | Value to match the **RdbPredicates**.|
802
803**Return value**
804
805| Type                                | Description                      |
806| ------------------------------------ | -------------------------- |
807| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
808
809**Example**
810
811```js
812let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
813predicates.like("NAME", "%os%");
814```
815
816### glob
817
818glob(field: string, value: string): RdbPredicates
819
820Sets an **RdbPredicates** to match the specified string.
821
822**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
823
824**Parameters**
825
826| Name| Type  | Mandatory| Description                                                        |
827| ------ | ------ | ---- | ------------------------------------------------------------ |
828| field  | string | Yes  | Column name in the database table.                                          |
829| 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.|
830
831**Return value**
832
833| Type                                | Description                      |
834| ------------------------------------ | -------------------------- |
835| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
836
837**Example**
838
839```js
840let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
841predicates.glob("NAME", "?h*g");
842```
843
844### between
845
846between(field: string, low: ValueType, high: ValueType): RdbPredicates
847
848Sets an **RdbPredicates** to match the field with data type **ValueType** and value within the specified range.
849
850**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
851
852**Parameters**
853
854| Name| Type                   | Mandatory| Description                      |
855| ------ | ----------------------- | ---- | -------------------------- |
856| field  | string                  | Yes  | Column name in the database table.        |
857| low    | [ValueType](#valuetype) | Yes  | Minimum value to match the **RdbPredicates**.  |
858| high   | [ValueType](#valuetype) | Yes  | Maximum value to match the **RdbPredicates**.|
859
860**Return value**
861
862| Type                                | Description                      |
863| ------------------------------------ | -------------------------- |
864| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
865
866**Example**
867
868```js
869let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
870predicates.between("AGE", 10, 50);
871```
872
873### notBetween
874
875notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates
876
877Sets an **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range.
878
879**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
880
881**Parameters**
882
883| Name| Type                   | Mandatory| Description                      |
884| ------ | ----------------------- | ---- | -------------------------- |
885| field  | string                  | Yes  | Column name in the database table.        |
886| low    | [ValueType](#valuetype) | Yes  | Minimum value to match the **RdbPredicates**.  |
887| high   | [ValueType](#valuetype) | Yes  | Maximum value to match the **RdbPredicates**.|
888
889**Return value**
890
891| Type                                | Description                      |
892| ------------------------------------ | -------------------------- |
893| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
894
895**Example**
896
897```js
898let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
899predicates.notBetween("AGE", 10, 50);
900```
901
902### greaterThan
903
904greaterThan(field: string, value: ValueType): RdbPredicates
905
906Sets an **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value.
907
908**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
909
910**Parameters**
911
912| Name| Type                   | Mandatory| Description                  |
913| ------ | ----------------------- | ---- | ---------------------- |
914| field  | string                  | Yes  | Column name in the database table.    |
915| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|
916
917**Return value**
918
919| Type                                | Description                      |
920| ------------------------------------ | -------------------------- |
921| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
922
923**Example**
924
925```js
926let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
927predicates.greaterThan("AGE", 18);
928```
929
930### lessThan
931
932lessThan(field: string, value: ValueType): RdbPredicates
933
934Sets an **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value.
935
936**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
937
938**Parameters**
939
940| Name| Type                   | Mandatory| Description                  |
941| ------ | ----------------------- | ---- | ---------------------- |
942| field  | string                  | Yes  | Column name in the database table.    |
943| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|
944
945**Return value**
946
947| Type                                | Description                      |
948| ------------------------------------ | -------------------------- |
949| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
950
951**Example**
952
953```js
954let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
955predicates.lessThan("AGE", 20);
956```
957
958### greaterThanOrEqualTo
959
960greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates
961
962Sets an **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value.
963
964**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
965
966**Parameters**
967
968| Name| Type                   | Mandatory| Description                  |
969| ------ | ----------------------- | ---- | ---------------------- |
970| field  | string                  | Yes  | Column name in the database table.    |
971| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|
972
973**Return value**
974
975| Type                                | Description                      |
976| ------------------------------------ | -------------------------- |
977| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
978
979**Example**
980
981```js
982let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
983predicates.greaterThanOrEqualTo("AGE", 18);
984```
985
986### lessThanOrEqualTo
987
988lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates
989
990Sets an **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value.
991
992**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
993
994**Parameters**
995
996| Name| Type                   | Mandatory| Description                  |
997| ------ | ----------------------- | ---- | ---------------------- |
998| field  | string                  | Yes  | Column name in the database table.    |
999| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|
1000
1001**Return value**
1002
1003| Type                                | Description                      |
1004| ------------------------------------ | -------------------------- |
1005| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
1006
1007**Example**
1008
1009```js
1010let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1011predicates.lessThanOrEqualTo("AGE", 20);
1012```
1013
1014### orderByAsc
1015
1016orderByAsc(field: string): RdbPredicates
1017
1018Sets an **RdbPredicates** to match the column with values sorted in ascending order.
1019
1020**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1021
1022**Parameters**
1023
1024| Name| Type  | Mandatory| Description              |
1025| ------ | ------ | ---- | ------------------ |
1026| field  | string | Yes  | Column name in the database table.|
1027
1028**Return value**
1029
1030| Type                                | Description                      |
1031| ------------------------------------ | -------------------------- |
1032| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
1033
1034**Example**
1035
1036```js
1037let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1038predicates.orderByAsc("NAME");
1039```
1040
1041### orderByDesc
1042
1043orderByDesc(field: string): RdbPredicates
1044
1045Sets an **RdbPredicates** to match the column with values sorted in descending order.
1046
1047**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1048
1049**Parameters**
1050
1051| Name| Type  | Mandatory| Description              |
1052| ------ | ------ | ---- | ------------------ |
1053| field  | string | Yes  | Column name in the database table.|
1054
1055**Return value**
1056
1057| Type                                | Description                      |
1058| ------------------------------------ | -------------------------- |
1059| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
1060
1061**Example**
1062
1063```js
1064let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1065predicates.orderByDesc("AGE");
1066```
1067
1068### distinct
1069
1070distinct(): RdbPredicates
1071
1072Sets an **RdbPredicates** to filter out duplicate records.
1073
1074**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1075
1076**Return value**
1077
1078| Type                                | Description                          |
1079| ------------------------------------ | ------------------------------ |
1080| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.|
1081
1082**Example**
1083
1084```js
1085let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1086predicates.equalTo("NAME", "Rose").distinct();
1087```
1088
1089### limitAs
1090
1091limitAs(value: number): RdbPredicates
1092
1093Sets an **RdbPredicates** to specify the maximum number of records.
1094
1095**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1096
1097**Parameters**
1098
1099| Name| Type  | Mandatory| Description            |
1100| ------ | ------ | ---- | ---------------- |
1101| value  | number | Yes  | Maximum number of records.|
1102
1103**Return value**
1104
1105| Type                                | Description                                |
1106| ------------------------------------ | ------------------------------------ |
1107| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.|
1108
1109**Example**
1110
1111```js
1112let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1113predicates.equalTo("NAME", "Rose").limitAs(3);
1114```
1115
1116### offsetAs
1117
1118offsetAs(rowOffset: number): RdbPredicates
1119
1120Sets an **RdbPredicates** to specify the start position of the returned result.
1121
1122**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1123
1124**Parameters**
1125
1126| Name   | Type  | Mandatory| Description                              |
1127| --------- | ------ | ---- | ---------------------------------- |
1128| rowOffset | number | Yes  | Number of rows to offset from the beginning. The value is a positive integer.|
1129
1130**Return value**
1131
1132| Type                                | Description                                |
1133| ------------------------------------ | ------------------------------------ |
1134| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.|
1135
1136**Example**
1137
1138```js
1139let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1140predicates.equalTo("NAME", "Rose").offsetAs(3);
1141```
1142
1143### groupBy
1144
1145groupBy(fields: Array&lt;string&gt;): RdbPredicates
1146
1147Sets an **RdbPredicates** to group rows that have the same value into summary rows.
1148
1149**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1150
1151**Parameters**
1152
1153| Name| Type               | Mandatory| Description                |
1154| ------ | ------------------- | ---- | -------------------- |
1155| fields | Array&lt;string&gt; | Yes  | Names of columns to group.|
1156
1157**Return value**
1158
1159| Type                                | Description                  |
1160| ------------------------------------ | ---------------------- |
1161| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.|
1162
1163**Example**
1164
1165```js
1166let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1167predicates.groupBy(["AGE", "NAME"]);
1168```
1169
1170### indexedBy
1171
1172indexedBy(field: string): RdbPredicates
1173
1174Sets an **RdbPredicates** object to specify the index column.
1175
1176**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1177
1178**Parameters**
1179
1180| Name| Type  | Mandatory| Description          |
1181| ------ | ------ | ---- | -------------- |
1182| field  | string | Yes  | Name of the index column.|
1183
1184**Return value**
1185
1186
1187| Type                                | Description                                 |
1188| ------------------------------------ | ------------------------------------- |
1189| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.|
1190
1191**Example**
1192
1193```js
1194let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1195predicates.indexedBy("SALARY_INDEX");
1196```
1197
1198### in
1199
1200in(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
1201
1202Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.
1203
1204**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1205
1206**Parameters**
1207
1208| Name| Type                                | Mandatory| Description                                   |
1209| ------ | ------------------------------------ | ---- | --------------------------------------- |
1210| field  | string                               | Yes  | Column name in the database table.                     |
1211| value  | Array&lt;[ValueType](#valuetype)&gt; | Yes  | Array of **ValueType**s to match.|
1212
1213**Return value**
1214
1215| Type                                | Description                      |
1216| ------------------------------------ | -------------------------- |
1217| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
1218
1219**Example**
1220
1221```js
1222let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1223predicates.in("AGE", [18, 20]);
1224```
1225
1226### notIn
1227
1228notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
1229
1230Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.
1231
1232**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1233
1234**Parameters**
1235
1236| Name| Type                                | Mandatory| Description                                 |
1237| ------ | ------------------------------------ | ---- | ------------------------------------- |
1238| field  | string                               | Yes  | Column name in the database table.                   |
1239| value  | Array&lt;[ValueType](#valuetype)&gt; | Yes  | Array of **ValueType**s to match.|
1240
1241**Return value**
1242
1243| Type                                | Description                      |
1244| ------------------------------------ | -------------------------- |
1245| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|
1246
1247**Example**
1248
1249```js
1250let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1251predicates.notIn("NAME", ["Lisa", "Rose"]);
1252```
1253
1254## RdbStore
1255
1256Provides APIs to manage an RDB store.
1257
1258Before using the APIs of this class, use [executeSql](#executesql) to initialize the database table structure and related data.
1259
1260### Attributes<sup>10+</sup>
1261
1262**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1263
1264| Name        | Type           | Mandatory| Description                            |
1265| ------------ | ----------- | ---- | -------------------------------- |
1266| version<sup>10+</sup>  | number | Yes  | RDB store version, which is an integer greater than 0.      |
1267
1268**Example**
1269
1270```js
1271// Set the RDB store version.
1272store.version = 3;
1273// Obtain the RDB store version.
1274console.info(`RdbStore version is ${store.version}`);
1275```
1276
1277### insert
1278
1279insert(table: string, values: ValuesBucket, callback: AsyncCallback&lt;number&gt;):void
1280
1281Inserts a row of data into a table. This API uses an asynchronous callback to return the result.
1282
1283**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1284
1285**Parameters**
1286
1287| Name  | Type                         | Mandatory| Description                                                      |
1288| -------- | ----------------------------- | ---- | ---------------------------------------------------------- |
1289| table    | string                        | Yes  | Name of the target table.                                          |
1290| values   | [ValuesBucket](#valuesbucket) | Yes  | Row of data to insert.                                |
1291| callback | AsyncCallback&lt;number&gt;   | Yes  | Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
1292
1293**Error codes**
1294
1295For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1296
1297| **ID**| **Error Message**                                |
1298| ------------ | -------------------------------------------- |
1299| 14800047     | The WAL file size exceeds the default limit. |
1300| 14800000     | Inner error.                                 |
1301
1302**Example**
1303
1304```js
1305const valueBucket = {
1306  "NAME": "Lisa",
1307  "AGE": 18,
1308  "SALARY": 100.5,
1309  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
1310};
1311store.insert("EMPLOYEE", valueBucket, function (err, rowId) {
1312  if (err) {
1313    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
1314    return;
1315  }
1316  console.info(`Insert is successful, rowId = ${rowId}`);
1317})
1318```
1319
1320### insert<sup>10+</sup>
1321
1322insert(table: string, values: ValuesBucket,  conflict: ConflictResolution, callback: AsyncCallback&lt;number&gt;):void
1323
1324Inserts a row of data into a table. This API uses an asynchronous callback to return the result.
1325
1326**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1327
1328**Parameters**
1329
1330| Name  | Type                                       | Mandatory| Description                                                      |
1331| -------- | ------------------------------------------- | ---- | ---------------------------------------------------------- |
1332| table    | string                                      | Yes  | Name of the target table.                                          |
1333| values   | [ValuesBucket](#valuesbucket)               | Yes  | Row of data to insert.                                |
1334| conflict | [ConflictResolution](#conflictresolution10) | Yes  | Resolution used to resolve the conflict.                                        |
1335| callback | AsyncCallback&lt;number&gt;                 | Yes  | Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
1336
1337**Error codes**
1338
1339For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1340
1341| **ID**| **Error Message**                                |
1342| ------------ | -------------------------------------------- |
1343| 14800047     | The WAL file size exceeds the default limit. |
1344| 14800000     | Inner error.                                 |
1345
1346**Example**
1347
1348```js
1349const valueBucket = {
1350  "NAME": "Lisa",
1351  "AGE": 18,
1352  "SALARY": 100.5,
1353  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
1354};
1355store.insert("EMPLOYEE", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, function (err, rowId) {
1356  if (err) {
1357    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
1358    return;
1359  }
1360  console.info(`Insert is successful, rowId = ${rowId}`);
1361})
1362```
1363
1364### insert
1365
1366insert(table: string, values: ValuesBucket):Promise&lt;number&gt;
1367
1368Inserts a row of data into a table. This API uses a promise to return the result.
1369
1370**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1371
1372**Parameters**
1373
1374| Name| Type                         | Mandatory| Description                      |
1375| ------ | ----------------------------- | ---- | -------------------------- |
1376| table  | string                        | Yes  | Name of the target table.          |
1377| values | [ValuesBucket](#valuesbucket) | Yes  | Row of data to insert.|
1378
1379**Return value**
1380
1381| Type                 | Description                                             |
1382| --------------------- | ------------------------------------------------- |
1383| Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
1384
1385**Error codes**
1386
1387For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1388
1389| **ID**| **Error Message**                                |
1390| ------------ | -------------------------------------------- |
1391| 14800047     | The WAL file size exceeds the default limit. |
1392| 14800000     | Inner error.                                 |
1393
1394**Example**
1395
1396```js
1397const valueBucket = {
1398  "NAME": "Lisa",
1399  "AGE": 18,
1400  "SALARY": 100.5,
1401  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
1402};
1403let promise = store.insert("EMPLOYEE", valueBucket);
1404promise.then((rowId) => {
1405  console.info(`Insert is successful, rowId = ${rowId}`);
1406}).catch((err) => {
1407  console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
1408})
1409```
1410
1411### insert<sup>10+</sup>
1412
1413insert(table: string, values: ValuesBucket,  conflict: ConflictResolution):Promise&lt;number&gt;
1414
1415Inserts a row of data into a table. This API uses a promise to return the result.
1416
1417**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1418
1419**Parameters**
1420
1421| Name  | Type                                       | Mandatory| Description                      |
1422| -------- | ------------------------------------------- | ---- | -------------------------- |
1423| table    | string                                      | Yes  | Name of the target table.          |
1424| values   | [ValuesBucket](#valuesbucket)               | Yes  | Row of data to insert.|
1425| conflict | [ConflictResolution](#conflictresolution10) | Yes  | Resolution used to resolve the conflict.        |
1426
1427**Return value**
1428
1429| Type                 | Description                                             |
1430| --------------------- | ------------------------------------------------- |
1431| Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
1432
1433**Error codes**
1434
1435For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1436
1437| **ID**| **Error Message**                                |
1438| ------------ | -------------------------------------------- |
1439| 14800047     | The WAL file size exceeds the default limit. |
1440| 14800000     | Inner error.                                 |
1441
1442**Example**
1443
1444```js
1445const valueBucket = {
1446  "NAME": "Lisa",
1447  "AGE": 18,
1448  "SALARY": 100.5,
1449  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
1450};
1451let promise = store.insert("EMPLOYEE", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
1452promise.then((rowId) => {
1453  console.info(`Insert is successful, rowId = ${rowId}`);
1454}).catch((err) => {
1455  console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
1456})
1457```
1458
1459### batchInsert
1460
1461batchInsert(table: string, values: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;):void
1462
1463Batch inserts data into a table. This API uses an asynchronous callback to return the result.
1464
1465**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1466
1467**Parameters**
1468
1469| Name  | Type                                      | Mandatory| Description                                                        |
1470| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
1471| table    | string                                     | Yes  | Name of the target table.                                            |
1472| values   | Array&lt;[ValuesBucket](#valuesbucket)&gt; | Yes  | An array of data to insert.                                |
1473| callback | AsyncCallback&lt;number&gt;                | Yes  | Callback invoked to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.|
1474
1475**Error codes**
1476
1477For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1478
1479| **ID**| **Error Message**                                |
1480| ------------ | -------------------------------------------- |
1481| 14800047     | The WAL file size exceeds the default limit. |
1482| 14800000     | Inner error.                                 |
1483
1484**Example**
1485
1486```js
1487const valueBucket1 = {
1488  "NAME": "Lisa",
1489  "AGE": 18,
1490  "SALARY": 100.5,
1491  "CODES": new Uint8Array([1, 2, 3, 4, 5])
1492};
1493const valueBucket2 = {
1494  "NAME": "Jack",
1495  "AGE": 19,
1496  "SALARY": 101.5,
1497  "CODES": new Uint8Array([6, 7, 8, 9, 10])
1498};
1499const valueBucket3 = {
1500  "NAME": "Tom",
1501  "AGE": 20,
1502  "SALARY": 102.5,
1503  "CODES": new Uint8Array([11, 12, 13, 14, 15])
1504};
1505
1506let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
1507store.batchInsert("EMPLOYEE", valueBuckets, function(err, insertNum) {
1508  if (err) {
1509    console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
1510    return;
1511  }
1512  console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
1513})
1514```
1515
1516### batchInsert
1517
1518batchInsert(table: string, values: Array&lt;ValuesBucket&gt;):Promise&lt;number&gt;
1519
1520Batch inserts data into a table. This API uses a promise to return the result.
1521
1522**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1523
1524**Parameters**
1525
1526| Name| Type                                      | Mandatory| Description                        |
1527| ------ | ------------------------------------------ | ---- | ---------------------------- |
1528| table  | string                                     | Yes  | Name of the target table.            |
1529| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | Yes  | An array of data to insert.|
1530
1531**Return value**
1532
1533| Type                 | Description                                                       |
1534| --------------------- | ----------------------------------------------------------- |
1535| Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.|
1536
1537**Error codes**
1538
1539For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1540
1541| **ID**| **Error Message**                                |
1542| ------------ | -------------------------------------------- |
1543| 14800047     | The WAL file size exceeds the default limit. |
1544| 14800000     | Inner error.                                 |
1545
1546**Example**
1547
1548```js
1549const valueBucket1 = {
1550  "NAME": "Lisa",
1551  "AGE": 18,
1552  "SALARY": 100.5,
1553  "CODES": new Uint8Array([1, 2, 3, 4, 5])
1554};
1555const valueBucket2 = {
1556  "NAME": "Jack",
1557  "AGE": 19,
1558  "SALARY": 101.5,
1559  "CODES": new Uint8Array([6, 7, 8, 9, 10])
1560};
1561const valueBucket3 = {
1562  "NAME": "Tom",
1563  "AGE": 20,
1564  "SALARY": 102.5,
1565  "CODES": new Uint8Array([11, 12, 13, 14, 15])
1566};
1567
1568let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
1569let promise = store.batchInsert("EMPLOYEE", valueBuckets);
1570promise.then((insertNum) => {
1571  console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
1572}).catch((err) => {
1573  console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
1574})
1575```
1576
1577### update
1578
1579update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
1580
1581Updates data in the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.
1582
1583**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1584
1585**Parameters**
1586
1587| Name    | Type                                | Mandatory| Description                                                        |
1588| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
1589| 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.|
1590| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Update conditions specified by the **RdbPredicates** object.                   |
1591| callback   | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the number of rows updated.                  |
1592
1593**Error codes**
1594
1595For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1596
1597| **ID**| **Error Message**                                |
1598| ------------ | -------------------------------------------- |
1599| 14800047     | The WAL file size exceeds the default limit. |
1600| 14800000     | Inner error.                                 |
1601
1602**Example**
1603
1604```js
1605const valueBucket = {
1606  "NAME": "Rose",
1607  "AGE": 22,
1608  "SALARY": 200.5,
1609  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
1610};
1611let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1612predicates.equalTo("NAME", "Lisa");
1613store.update(valueBucket, predicates, function (err, rows) {
1614  if (err) {
1615    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
1616    return;
1617  }
1618  console.info(`Updated row count: ${rows}`);
1619})
1620```
1621
1622### update<sup>10+</sup>
1623
1624update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution, callback: AsyncCallback&lt;number&gt;):void
1625
1626Updates data in the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.
1627
1628**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1629
1630**Parameters**
1631
1632| Name    | Type                                       | Mandatory| Description                                                        |
1633| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
1634| 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.|
1635| predicates | [RdbPredicates](#rdbpredicates)            | Yes  | Update conditions specified by the **RdbPredicates** object.                     |
1636| conflict   | [ConflictResolution](#conflictresolution10) | Yes  | Resolution used to resolve the conflict.                                          |
1637| callback   | AsyncCallback&lt;number&gt;                 | Yes  | Callback invoked to return the number of rows updated.                  |
1638
1639**Error codes**
1640
1641For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1642
1643| **ID**| **Error Message**                                |
1644| ------------ | -------------------------------------------- |
1645| 14800047     | The WAL file size exceeds the default limit. |
1646| 14800000     | Inner error.                                 |
1647
1648**Example**
1649
1650```js
1651const valueBucket = {
1652  "NAME": "Rose",
1653  "AGE": 22,
1654  "SALARY": 200.5,
1655  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
1656};
1657let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1658predicates.equalTo("NAME", "Lisa");
1659store.update(valueBucket, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, function (err, rows) {
1660  if (err) {
1661    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
1662    return;
1663  }
1664  console.info(`Updated row count: ${rows}`);
1665})
1666```
1667
1668### update
1669
1670update(values: ValuesBucket, predicates: RdbPredicates):Promise&lt;number&gt;
1671
1672Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the result.
1673
1674**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1675
1676**Parameters**
1677
1678| Name      | Type                                | Mandatory| Description                                                        |
1679| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
1680| 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.|
1681| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Update conditions specified by the **RdbPredicates** object.                   |
1682
1683**Return value**
1684
1685| Type                 | Description                                     |
1686| --------------------- | ----------------------------------------- |
1687| Promise&lt;number&gt; | Promise used to return the number of rows updated.|
1688
1689**Error codes**
1690
1691For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1692
1693| **ID**| **Error Message**                                |
1694| ------------ | -------------------------------------------- |
1695| 14800047     | The WAL file size exceeds the default limit. |
1696| 14800000     | Inner error.                                 |
1697
1698**Example**
1699
1700```js
1701const valueBucket = {
1702  "NAME": "Rose",
1703  "AGE": 22,
1704  "SALARY": 200.5,
1705  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
1706};
1707let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1708predicates.equalTo("NAME", "Lisa");
1709let promise = store.update(valueBucket, predicates);
1710promise.then(async (rows) => {
1711  console.info(`Updated row count: ${rows}`);
1712}).catch((err) => {
1713  console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
1714})
1715```
1716
1717### update<sup>10+</sup>
1718
1719update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution):Promise&lt;number&gt;
1720
1721Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the result.
1722
1723**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1724
1725**Parameters**
1726
1727| Name    | Type                                       | Mandatory| Description                                                        |
1728| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
1729| 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.|
1730| predicates | [RdbPredicates](#rdbpredicates)            | Yes  | Update conditions specified by the **RdbPredicates** object.                     |
1731| conflict   | [ConflictResolution](#conflictresolution10) | Yes  | Resolution used to resolve the conflict.                                          |
1732
1733**Return value**
1734
1735| Type                 | Description                                     |
1736| --------------------- | ----------------------------------------- |
1737| Promise&lt;number&gt; | Promise used to return the number of rows updated.|
1738
1739**Error codes**
1740
1741For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1742
1743| **ID**| **Error Message**                                |
1744| ------------ | -------------------------------------------- |
1745| 14800047     | The WAL file size exceeds the default limit. |
1746| 14800000     | Inner error.                                 |
1747
1748**Example**
1749
1750```js
1751const valueBucket = {
1752  "NAME": "Rose",
1753  "AGE": 22,
1754  "SALARY": 200.5,
1755  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
1756};
1757let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1758predicates.equalTo("NAME", "Lisa");
1759let promise = store.update(valueBucket, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
1760promise.then(async (rows) => {
1761  console.info(`Updated row count: ${rows}`);
1762}).catch((err) => {
1763  console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
1764})
1765```
1766
1767### update
1768
1769update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void
1770
1771Updates data based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
1772
1773**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1774
1775**Model restriction**: This API can be used only in the stage model.
1776
1777**System API**: This is a system API.
1778
1779**Parameters**
1780
1781| Name    | Type                                                        | Mandatory| Description                                                        |
1782| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1783| table      | string                                                       | Yes  | Name of the target table.                                            |
1784| 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.|
1785| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Update conditions specified by the **DataSharePredicates** object.               |
1786| callback   | AsyncCallback&lt;number&gt;                                  | Yes  | Callback invoked to return the number of rows updated.                  |
1787
1788**Error codes**
1789
1790For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1791
1792| **ID**| **Error Message**                                |
1793| ------------ | -------------------------------------------- |
1794| 14800047     | The WAL file size exceeds the default limit. |
1795| 14800000     | Inner error.                                 |
1796
1797**Example**
1798
1799```js
1800import dataSharePredicates from '@ohos.data.dataSharePredicates'
1801const valueBucket = {
1802    "NAME": "Rose",
1803    "AGE": 22,
1804    "SALARY": 200.5,
1805    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
1806};
1807let predicates = new dataSharePredicates.DataSharePredicates();
1808predicates.equalTo("NAME", "Lisa");
1809store.update("EMPLOYEE", valueBucket, predicates, function (err, rows) {
1810  if (err) {
1811    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
1812    return;
1813  }
1814  console.info(`Updated row count: ${rows}`);
1815})
1816```
1817
1818### update
1819
1820update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt;
1821
1822Updates data based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
1823
1824**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1825
1826**Model restriction**: This API can be used only in the stage model.
1827
1828**System API**: This is a system API.
1829
1830**Parameters**
1831
1832| Name    | Type                                                        | Mandatory| Description                                                        |
1833| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1834| table      | string                                                       | Yes  | Name of the target table.                                            |
1835| 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.|
1836| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Update conditions specified by the **DataSharePredicates** object.               |
1837
1838**Return value**
1839
1840| Type                 | Description                                     |
1841| --------------------- | ----------------------------------------- |
1842| Promise&lt;number&gt; | Promise used to return the number of rows updated.|
1843
1844**Error codes**
1845
1846For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1847
1848| **ID**| **Error Message**                                |
1849| ------------ | -------------------------------------------- |
1850| 14800047     | The WAL file size exceeds the default limit. |
1851| 14800000     | Inner error.                                 |
1852
1853**Example**
1854
1855```js
1856import dataSharePredicates from '@ohos.data.dataSharePredicates'
1857const valueBucket = {
1858  "NAME": "Rose",
1859  "AGE": 22,
1860  "SALARY": 200.5,
1861  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
1862};
1863let predicates = new dataSharePredicates.DataSharePredicates();
1864predicates.equalTo("NAME", "Lisa");
1865let promise = store.update("EMPLOYEE", valueBucket, predicates);
1866promise.then(async (rows) => {
1867  console.info(`Updated row count: ${rows}`);
1868}).catch((err) => {
1869  console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
1870})
1871```
1872
1873### delete
1874
1875delete(predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
1876
1877Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.
1878
1879**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1880
1881**Parameters**
1882
1883| Name    | Type                                | Mandatory| Description                                     |
1884| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
1885| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Conditions specified by the **RdbPredicates** object for deleting data.|
1886| callback   | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the number of rows deleted. |
1887
1888**Error codes**
1889
1890For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1891
1892| **ID**| **Error Message**                                |
1893| ------------ | -------------------------------------------- |
1894| 14800047     | The WAL file size exceeds the default limit. |
1895| 14800000     | Inner error.                                 |
1896
1897**Example**
1898
1899```js
1900let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1901predicates.equalTo("NAME", "Lisa");
1902store.delete(predicates, function (err, rows) {
1903  if (err) {
1904    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
1905    return;
1906  }
1907  console.info(`Delete rows: ${rows}`);
1908})
1909```
1910
1911### delete
1912
1913delete(predicates: RdbPredicates):Promise&lt;number&gt;
1914
1915Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result.
1916
1917**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1918
1919**Parameters**
1920
1921| Name    | Type                                | Mandatory| Description                                     |
1922| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
1923| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Conditions specified by the **RdbPredicates** object for deleting data.|
1924
1925**Return value**
1926
1927| Type                 | Description                           |
1928| --------------------- | ------------------------------- |
1929| Promise&lt;number&gt; | Promise used to return the number of rows deleted.|
1930
1931**Error codes**
1932
1933For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1934
1935| **ID**| **Error Message**                                |
1936| ------------ | -------------------------------------------- |
1937| 14800047     | The WAL file size exceeds the default limit. |
1938| 14800000     | Inner error.                                 |
1939
1940**Example**
1941
1942```js
1943let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1944predicates.equalTo("NAME", "Lisa");
1945let promise = store.delete(predicates);
1946promise.then((rows) => {
1947  console.info(`Delete rows: ${rows}`);
1948}).catch((err) => {
1949  console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
1950})
1951```
1952
1953### delete
1954
1955delete(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void
1956
1957Deletes data from the RDB store based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
1958
1959**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
1960
1961**Model restriction**: This API can be used only in the stage model.
1962
1963**System API**: This is a system API.
1964
1965**Parameters**
1966
1967| Name    | Type                                                        | Mandatory| Description                                         |
1968| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- |
1969| table      | string                                                       | Yes  | Name of the target table.                             |
1970| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Conditions specified by the **DataSharePredicates** object for deleting data.|
1971| callback   | AsyncCallback&lt;number&gt;                                  | Yes  | Callback invoked to return the number of rows deleted.     |
1972
1973**Error codes**
1974
1975For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
1976
1977| **ID**| **Error Message**                                |
1978| ------------ | -------------------------------------------- |
1979| 14800047     | The WAL file size exceeds the default limit. |
1980| 14800000     | Inner error.                                 |
1981
1982**Example**
1983
1984```js
1985import dataSharePredicates from '@ohos.data.dataSharePredicates'
1986let predicates = new dataSharePredicates.DataSharePredicates();
1987predicates.equalTo("NAME", "Lisa");
1988store.delete("EMPLOYEE", predicates, function (err, rows) {
1989  if (err) {
1990    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
1991    return;
1992  }
1993  console.info(`Delete rows: ${rows}`);
1994})
1995```
1996
1997### delete
1998
1999delete(table: string, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt;
2000
2001Deletes data from the RDB store based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
2002
2003**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2004
2005**Model restriction**: This API can be used only in the stage model.
2006
2007**System API**: This is a system API.
2008
2009**Parameters**
2010
2011| Name    | Type                                                        | Mandatory| Description                                         |
2012| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- |
2013| table      | string                                                       | Yes  | Name of the target table.                             |
2014| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Conditions specified by the **DataSharePredicates** object for deleting data.|
2015
2016**Return value**
2017
2018| Type                 | Description                           |
2019| --------------------- | ------------------------------- |
2020| Promise&lt;number&gt; | Promise used to return the number of rows deleted.|
2021
2022**Error codes**
2023
2024For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2025
2026| **ID**| **Error Message**                                |
2027| ------------ | -------------------------------------------- |
2028| 14800047     | The WAL file size exceeds the default limit. |
2029| 14800000     | Inner error.                                 |
2030
2031**Example**
2032
2033```js
2034import dataSharePredicates from '@ohos.data.dataSharePredicates'
2035let predicates = new dataSharePredicates.DataSharePredicates();
2036predicates.equalTo("NAME", "Lisa");
2037let promise = store.delete("EMPLOYEE", predicates);
2038promise.then((rows) => {
2039  console.info(`Delete rows: ${rows}`);
2040}).catch((err) => {
2041  console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
2042})
2043```
2044
2045### query
2046
2047query(predicates: RdbPredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
2048
2049Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.
2050
2051**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2052
2053**Parameters**
2054
2055| Name    | Type                                                        | Mandatory| Description                                                       |
2056| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
2057| predicates | [RdbPredicates](#rdbpredicates)                         | Yes  | Query conditions specified by the **RdbPredicates** object.                  |
2058| columns    | Array&lt;string&gt;                                          | Yes  | Columns to query. If this parameter is not specified, the query applies to all columns.           |
2059| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
2060
2061**Error codes**
2062
2063For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2064
2065| **ID**| **Error Message**                |
2066| ------------ | ---------------------------- |
2067| 14800000     | Inner error.                 |
2068
2069**Example**
2070
2071```js
2072let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2073predicates.equalTo("NAME", "Rose");
2074store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
2075  if (err) {
2076    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2077    return;
2078  }
2079  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
2080  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2081  while(resultSet.goToNextRow()) {
2082    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
2083    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
2084    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
2085    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
2086    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
2087  }
2088  // Release the dataset memory.
2089  resultSet.close();
2090})
2091```
2092
2093### query
2094
2095query(predicates: RdbPredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
2096
2097Queries data from the RDB store based on specified conditions. This API uses a promise to return the result.
2098
2099**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2100
2101**Parameters**
2102
2103| Name    | Type                                | Mandatory| Description                                            |
2104| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
2105| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Query conditions specified by the **RdbPredicates** object.       |
2106| columns    | Array&lt;string&gt;                  | No  | Columns to query. If this parameter is not specified, the query applies to all columns.|
2107
2108**Error codes**
2109
2110For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2111
2112| **ID**| **Error Message**                |
2113| ------------ | ---------------------------- |
2114| 14800000     | Inner error.                 |
2115
2116**Return value**
2117
2118| Type                                                   | Description                                              |
2119| ------------------------------------------------------- | -------------------------------------------------- |
2120| Promise&lt;[ResultSet](#resultset)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
2121
2122**Example**
2123
2124  ```js
2125let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2126predicates.equalTo("NAME", "Rose");
2127let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
2128promise.then((resultSet) => {
2129  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
2130  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2131  while(resultSet.goToNextRow()) {
2132    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
2133    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
2134    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
2135    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
2136    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
2137  }
2138  // Release the dataset memory.
2139  resultSet.close();
2140}).catch((err) => {
2141  console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2142})
2143  ```
2144
2145### query
2146
2147query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
2148
2149Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.
2150
2151**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2152
2153**Model restriction**: This API can be used only in the stage model.
2154
2155**System API**: This is a system API.
2156
2157**Parameters**
2158
2159| Name    | Type                                                        | Mandatory| Description                                                       |
2160| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
2161| table      | string                                                       | Yes  | Name of the target table.                                           |
2162| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Query conditions specified by the **DataSharePredicates** object.              |
2163| columns    | Array&lt;string&gt;                                          | Yes  | Columns to query. If this parameter is not specified, the query applies to all columns.           |
2164| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
2165
2166**Error codes**
2167
2168For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2169
2170| **ID**| **Error Message**                |
2171| ------------ | ---------------------------- |
2172| 14800000     | Inner error.                 |
2173
2174**Example**
2175
2176```js
2177import dataSharePredicates from '@ohos.data.dataSharePredicates'
2178let predicates = new dataSharePredicates.DataSharePredicates();
2179predicates.equalTo("NAME", "Rose");
2180store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
2181  if (err) {
2182    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2183    return;
2184  }
2185  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
2186  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2187  while(resultSet.goToNextRow()) {
2188    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
2189    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
2190    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
2191    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
2192    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
2193  }
2194  // Release the dataset memory.
2195  resultSet.close();
2196})
2197```
2198
2199### query
2200
2201query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
2202
2203Queries data from the RDB store based on specified conditions. This API uses a promise to return the result.
2204
2205**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2206
2207**Model restriction**: This API can be used only in the stage model.
2208
2209**System API**: This is a system API.
2210
2211**Parameters**
2212
2213| Name    | Type                                                        | Mandatory| Description                                            |
2214| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ |
2215| table      | string                                                       | Yes  | Name of the target table.                                |
2216| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Query conditions specified by the **DataSharePredicates** object.   |
2217| columns    | Array&lt;string&gt;                                          | No  | Columns to query. If this parameter is not specified, the query applies to all columns.|
2218
2219**Return value**
2220
2221| Type                                                   | Description                                              |
2222| ------------------------------------------------------- | -------------------------------------------------- |
2223| Promise&lt;[ResultSet](#resultset)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
2224
2225**Error codes**
2226
2227For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2228
2229| **ID**| **Error Message**                |
2230| ------------ | ---------------------------- |
2231| 14800000     | Inner error.                 |
2232
2233**Example**
2234
2235```js
2236import dataSharePredicates from '@ohos.data.dataSharePredicates'
2237let predicates = new dataSharePredicates.DataSharePredicates();
2238predicates.equalTo("NAME", "Rose");
2239let promise = store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
2240promise.then((resultSet) => {
2241  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
2242  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2243  while(resultSet.goToNextRow()) {
2244    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
2245    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
2246    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
2247    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
2248    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
2249  }
2250  // Release the dataset memory.
2251  resultSet.close();
2252}).catch((err) => {
2253  console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2254})
2255```
2256
2257### remoteQuery
2258
2259remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt; , callback: AsyncCallback&lt;ResultSet&gt;): void
2260
2261Queries data from the RDB store of a remote device based on specified conditions. This API uses an asynchronous callback to return the result.
2262
2263> **NOTE**<br/>
2264>
2265> The value of **device** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications.
2266
2267**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2268
2269**Parameters**
2270
2271| Name    | Type                                        | Mandatory| Description                                                     |
2272| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- |
2273| device     | string                                       | Yes  | ID of the remote device.                                       |
2274| table      | string                                       | Yes  | Name of the target table.                                         |
2275| predicates | [RdbPredicates](#rdbpredicates)              | Yes  | Query conditions specified by the **RdbPredicates** object.                |
2276| columns    | Array&lt;string&gt;                          | Yes  | Columns to query. If this parameter is not specified, the query applies to all columns.         |
2277| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
2278
2279**Error codes**
2280
2281For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2282
2283| **ID**| **Error Message**                |
2284| ------------ | ---------------------------- |
2285| 14800000     | Inner error.                 |
2286
2287**Example**
2288
2289```js
2290import deviceManager from '@ohos.distributedHardware.deviceManager';
2291let dmInstance = null;
2292let deviceId = null;
2293
2294deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
2295    if (err) {
2296        console.log("create device manager failed, err=" + err);
2297        return;
2298    }
2299    dmInstance = manager;
2300    let devices = dmInstance.getTrustedDeviceListSync();
2301    deviceId = devices[0].deviceId;
2302})
2303
2304let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
2305predicates.greaterThan("id", 0);
2306store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"],
2307  function(err, resultSet) {
2308    if (err) {
2309      console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
2310      return;
2311    }
2312    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
2313    // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2314    while(resultSet.goToNextRow()) {
2315      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
2316      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
2317      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
2318      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
2319      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
2320    }
2321    // Release the dataset memory.
2322    resultSet.close();
2323  }
2324)
2325```
2326
2327### remoteQuery
2328
2329remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt;): Promise&lt;ResultSet&gt;
2330
2331Queries data from the RDB store of a remote device based on specified conditions. This API uses a promise to return the result.
2332
2333> **NOTE**<br/>
2334>
2335> The value of **device** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications.
2336
2337**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2338
2339**Parameters**
2340
2341| Name    | Type                                | Mandatory| Description                                            |
2342| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
2343| device     | string                               | Yes  | ID of the remote device.                  |
2344| table      | string                               | Yes  | Name of the target table.                                |
2345| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Query conditions specified by the **RdbPredicates** object.     |
2346| columns    | Array&lt;string&gt;                  | Yes  | Columns to query. If this parameter is not specified, the query applies to all columns.|
2347
2348**Return value**
2349
2350| Type                                                        | Description                                              |
2351| ------------------------------------------------------------ | -------------------------------------------------- |
2352| Promise&lt;[ResultSet](#resultset)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
2353
2354**Error codes**
2355
2356For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2357
2358| **ID**| **Error Message**                |
2359| ------------ | ---------------------------- |
2360| 14800000     | Inner error.                 |
2361
2362**Example**
2363
2364```js
2365import deviceManager from '@ohos.distributedHardware.deviceManager';
2366let dmInstance = null;
2367let deviceId = null;
2368
2369deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
2370    if (err) {
2371        console.log("create device manager failed, err=" + err);
2372        return;
2373    }
2374    dmInstance = manager;
2375    let devices = dmInstance.getTrustedDeviceListSync();
2376    deviceId = devices[0].deviceId;
2377})
2378
2379let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
2380predicates.greaterThan("id", 0);
2381let promise = store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
2382promise.then((resultSet) => {
2383  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
2384  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2385  while(resultSet.goToNextRow()) {
2386    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
2387    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
2388    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
2389    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
2390    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
2391  }
2392  // Release the dataset memory.
2393  resultSet.close();
2394}).catch((err) => {
2395  console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
2396})
2397```
2398
2399### querySql
2400
2401querySql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
2402
2403Queries data using the specified SQL statement. This API uses an asynchronous callback to return the result.
2404
2405**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2406
2407**Parameters**
2408
2409| Name  | Type                                        | Mandatory| Description                                                        |
2410| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
2411| sql      | string                                       | Yes  | SQL statement to run.                                       |
2412| bindArgs | Array&lt;[ValueType](#valuetype)&gt;         | 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.|
2413| callback | AsyncCallback&lt;[ResultSet](#resultset)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.   |
2414
2415**Error codes**
2416
2417For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2418
2419| **ID**| **Error Message**                |
2420| ------------ | ---------------------------- |
2421| 14800000     | Inner error.                 |
2422
2423**Example**
2424
2425```js
2426store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
2427  if (err) {
2428    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2429    return;
2430  }
2431  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
2432  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2433  while(resultSet.goToNextRow()) {
2434    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
2435    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
2436    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
2437    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
2438    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
2439  }
2440  // Release the dataset memory.
2441  resultSet.close();
2442})
2443```
2444
2445### querySql
2446
2447querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt;
2448
2449Queries data using the specified SQL statement. This API uses a promise to return the result.
2450
2451**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2452
2453**Parameters**
2454
2455| Name  | Type                                | Mandatory| Description                                                        |
2456| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
2457| sql      | string                               | Yes  | SQL statement to run.                                       |
2458| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 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.|
2459
2460**Return value**
2461
2462| Type                                                   | Description                                              |
2463| ------------------------------------------------------- | -------------------------------------------------- |
2464| Promise&lt;[ResultSet](#resultset)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|
2465
2466**Error codes**
2467
2468For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2469
2470| **ID**| **Error Message**                |
2471| ------------ | ---------------------------- |
2472| 14800000     | Inner error.                 |
2473
2474**Example**
2475
2476```js
2477let promise = store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'");
2478promise.then((resultSet) => {
2479  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
2480  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2481  while(resultSet.goToNextRow()) {
2482    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
2483    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
2484    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
2485    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
2486    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
2487  }
2488  // Release the dataset memory.
2489  resultSet.close();
2490}).catch((err) => {
2491  console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2492})
2493```
2494
2495### executeSql
2496
2497executeSql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;void&gt;):void
2498
2499Executes an SQL statement that contains specified arguments but returns no value. This API uses an asynchronous callback to return the result.
2500
2501**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2502
2503**Parameters**
2504
2505| Name  | Type                                | Mandatory| Description                                                        |
2506| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
2507| sql      | string                               | Yes  | SQL statement to run.                                       |
2508| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 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.|
2509| callback | AsyncCallback&lt;void&gt;            | Yes  | Callback invoked to return the result.                                      |
2510
2511**Error codes**
2512
2513For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2514
2515| **ID**| **Error Message**                                |
2516| ------------ | -------------------------------------------- |
2517| 14800047     | The WAL file size exceeds the default limit. |
2518| 14800000     | Inner error.                                 |
2519
2520**Example**
2521
2522```js
2523const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?"
2524store.executeSql(SQL_DELETE_TABLE, ['zhangsan'], function(err) {
2525  if (err) {
2526    console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
2527    return;
2528  }
2529  console.info(`Delete table done.`);
2530})
2531```
2532
2533### executeSql
2534
2535executeSql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;void&gt;
2536
2537Executes an SQL statement that contains specified arguments but returns no value. This API uses a promise to return the result.
2538
2539**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2540
2541**Parameters**
2542
2543| Name  | Type                                | Mandatory| Description                                                        |
2544| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
2545| sql      | string                               | Yes  | SQL statement to run.                                       |
2546| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 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.|
2547
2548**Return value**
2549
2550| Type               | Description                     |
2551| ------------------- | ------------------------- |
2552| Promise&lt;void&gt; | Promise that returns no value.|
2553
2554**Error codes**
2555
2556For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2557
2558| **ID**| **Error Message**                                |
2559| ------------ | -------------------------------------------- |
2560| 14800047     | The WAL file size exceeds the default limit. |
2561| 14800000     | Inner error.                                 |
2562
2563**Example**
2564
2565```js
2566const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"
2567let promise = store.executeSql(SQL_DELETE_TABLE);
2568promise.then(() => {
2569    console.info(`Delete table done.`);
2570}).catch((err) => {
2571    console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
2572})
2573```
2574
2575### beginTransaction
2576
2577beginTransaction():void
2578
2579Starts the transaction before executing an SQL statement.
2580
2581**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2582
2583**Error codes**
2584
2585For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2586
2587| **ID**| **Error Message**                                |
2588| ------------ | -------------------------------------------- |
2589| 14800047     | The WAL file size exceeds the default limit. |
2590| 14800000     | Inner error.                                 |
2591
2592**Example**
2593
2594```js
2595import featureAbility from '@ohos.ability.featureAbility'
2596let context = featureAbility.getContext();
2597const STORE_CONFIG = {
2598  name: "RdbTest.db",
2599  securityLevel: relationalStore.SecurityLevel.S1
2600};
2601relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
2602  if (err) {
2603    console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`);
2604    return;
2605  }
2606  store.beginTransaction();
2607  const valueBucket = {
2608    "name": "lisi",
2609	"age": 18,
2610	"salary": 100.5,
2611	"blobType": new Uint8Array([1, 2, 3]),
2612  };
2613  await store.insert("test", valueBucket);
2614  store.commit();
2615})
2616```
2617
2618### commit
2619
2620commit():void
2621
2622Commits the executed SQL statements.
2623
2624**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2625
2626**Example**
2627
2628```js
2629import featureAbility from '@ohos.ability.featureAbility'
2630let context = featureAbility.getContext();
2631const STORE_CONFIG = {
2632  name: "RdbTest.db",
2633  securityLevel: relationalStore.SecurityLevel.S1
2634};
2635relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
2636  if (err) {
2637     console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`);
2638     return;
2639  }
2640  store.beginTransaction();
2641  const valueBucket = {
2642	"name": "lisi",
2643	"age": 18,
2644	"salary": 100.5,
2645	"blobType": new Uint8Array([1, 2, 3]),
2646  };
2647  await store.insert("test", valueBucket);
2648  store.commit();
2649})
2650```
2651
2652### rollBack
2653
2654rollBack():void
2655
2656Rolls back the SQL statements that have been executed.
2657
2658**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2659
2660**Example**
2661
2662```js
2663import featureAbility from '@ohos.ability.featureAbility'
2664let context = featureAbility.getContext();
2665const STORE_CONFIG = {
2666  name: "RdbTest.db",
2667  securityLevel: relationalStore.SecurityLevel.S1
2668};
2669relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
2670  if (err) {
2671    console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`);
2672    return;
2673  }
2674  try {
2675    store.beginTransaction()
2676    const valueBucket = {
2677	  "id": 1,
2678	  "name": "lisi",
2679	  "age": 18,
2680	  "salary": 100.5,
2681	  "blobType": new Uint8Array([1, 2, 3]),
2682	};
2683	await store.insert("test", valueBucket);
2684    store.commit();
2685  } catch (err) {
2686    console.error(`Transaction failed, code is ${err.code},message is ${err.message}`);
2687    store.rollBack();
2688  }
2689})
2690```
2691
2692### backup
2693
2694backup(destName:string, callback: AsyncCallback&lt;void&gt;):void
2695
2696Backs up an RDB store. This API uses an asynchronous callback to return the result.
2697
2698**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2699
2700**Parameters**
2701
2702| Name  | Type                     | Mandatory| Description                    |
2703| -------- | ------------------------- | ---- | ------------------------ |
2704| destName | string                    | Yes  | Name of the RDB store backup file.|
2705| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result.  |
2706
2707**Error codes**
2708
2709For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2710
2711| **ID**| **Error Message**                |
2712| ------------ | ---------------------------- |
2713| 14800000     | Inner error.                 |
2714
2715**Example**
2716
2717```js
2718store.backup("dbBackup.db", function(err) {
2719  if (err) {
2720    console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
2721    return;
2722  }
2723  console.info(`Backup success.`);
2724})
2725```
2726
2727### backup
2728
2729backup(destName:string): Promise&lt;void&gt;
2730
2731Backs up an RDB store. This API uses a promise to return the result.
2732
2733**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2734
2735**Parameters**
2736
2737| Name  | Type  | Mandatory| Description                    |
2738| -------- | ------ | ---- | ------------------------ |
2739| destName | string | Yes  | Name of the RDB store backup file.|
2740
2741**Return value**
2742
2743| Type               | Description                     |
2744| ------------------- | ------------------------- |
2745| Promise&lt;void&gt; | Promise that returns no value.|
2746
2747**Error codes**
2748
2749For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2750
2751| **ID**| **Error Message**                |
2752| ------------ | ---------------------------- |
2753| 14800000     | Inner error.                 |
2754
2755**Example**
2756
2757```js
2758let promiseBackup = store.backup("dbBackup.db");
2759promiseBackup.then(()=>{
2760  console.info(`Backup success.`);
2761}).catch((err)=>{
2762  console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
2763})
2764```
2765
2766### restore
2767
2768restore(srcName:string, callback: AsyncCallback&lt;void&gt;):void
2769
2770Restores an RDB store from a backup file. 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| srcName  | string                    | Yes  | Name of the RDB store backup file.|
2779| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result.  |
2780
2781**Error codes**
2782
2783For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2784
2785| **ID**| **Error Message**                |
2786| ------------ | ---------------------------- |
2787| 14800000     | Inner error.                 |
2788
2789**Example**
2790
2791```js
2792store.restore("dbBackup.db", function(err) {
2793  if (err) {
2794    console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
2795    return;
2796  }
2797  console.info(`Restore success.`);
2798})
2799```
2800
2801### restore
2802
2803restore(srcName:string): Promise&lt;void&gt;
2804
2805Restores an RDB store from a backup file. This API uses a promise to return the result.
2806
2807**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2808
2809**Parameters**
2810
2811| Name | Type  | Mandatory| Description                    |
2812| ------- | ------ | ---- | ------------------------ |
2813| srcName | string | Yes  | Name of the RDB store backup file.|
2814
2815**Return value**
2816
2817| Type               | Description                     |
2818| ------------------- | ------------------------- |
2819| Promise&lt;void&gt; | Promise that returns no value.|
2820
2821**Error codes**
2822
2823For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2824
2825| **ID**| **Error Message**                |
2826| ------------ | ---------------------------- |
2827| 14800000     | Inner error.                 |
2828
2829**Example**
2830
2831```js
2832let promiseRestore = store.restore("dbBackup.db");
2833promiseRestore.then(()=>{
2834  console.info(`Restore success.`);
2835}).catch((err)=>{
2836  console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
2837})
2838```
2839
2840### setDistributedTables
2841
2842setDistributedTables(tables: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
2843
2844Sets distributed tables. This API uses an asynchronous callback to return the result.
2845
2846**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
2847
2848**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2849
2850**Parameters**
2851
2852| Name  | Type                     | Mandatory| Description                  |
2853| -------- | ------------------------- | ---- | ---------------------- |
2854| tables   | Array&lt;string&gt;       | Yes  | Names of the distributed tables to set.|
2855| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result.|
2856
2857**Error codes**
2858
2859For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2860
2861| **ID**| **Error Message**                |
2862| ------------ | ---------------------------- |
2863| 14800000     | Inner error.                 |
2864
2865**Example**
2866
2867```js
2868store.setDistributedTables(["EMPLOYEE"], function (err) {
2869  if (err) {
2870    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
2871    return;
2872  }
2873  console.info(`SetDistributedTables successfully.`);
2874})
2875```
2876
2877### setDistributedTables
2878
2879 setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt;
2880
2881Sets distributed tables. This API uses a promise to return the result.
2882
2883**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
2884
2885**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2886
2887**Parameters**
2888
2889| Name| Type               | Mandatory| Description                    |
2890| ------ | ------------------- | ---- | ------------------------ |
2891| tables | Array&lt;string&gt; | Yes  | Names of the distributed tables to set.|
2892
2893**Return value**
2894
2895| Type               | Description                     |
2896| ------------------- | ------------------------- |
2897| Promise&lt;void&gt; | Promise that returns no value.|
2898
2899**Error codes**
2900
2901For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2902
2903| **ID**| **Error Message**                |
2904| ------------ | ---------------------------- |
2905| 14800000     | Inner error.                 |
2906
2907**Example**
2908
2909```js
2910let promise = store.setDistributedTables(["EMPLOYEE"]);
2911promise.then(() => {
2912  console.info(`SetDistributedTables successfully.`);
2913}).catch((err) => {
2914  console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
2915})
2916```
2917
2918### obtainDistributedTableName
2919
2920obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void
2921
2922Obtains 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.
2923
2924> **NOTE**
2925>
2926> The value of **device** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications.
2927
2928**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
2929
2930**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2931
2932**Parameters**
2933
2934| Name  | Type                       | Mandatory| Description                                                        |
2935| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
2936| device   | string                      | Yes  | ID of the remote device.                                               |
2937| table    | string                      | Yes  | Local table name of the remote device.                                        |
2938| callback | AsyncCallback&lt;string&gt; | Yes  | Callback invoked to return the result. If the operation succeeds, the distributed table name of the remote device is returned.|
2939
2940**Error codes**
2941
2942For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
2943
2944| **ID**| **Error Message**                |
2945| ------------ | ---------------------------- |
2946| 14800000     | Inner error.                 |
2947
2948**Example**
2949
2950```js
2951import deviceManager from '@ohos.distributedHardware.deviceManager';
2952let dmInstance = null;
2953let deviceId = null;
2954
2955deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
2956    if (err) {
2957        console.log("create device manager failed, err=" + err);
2958        return;
2959    }
2960    dmInstance = manager;
2961    let devices = dmInstance.getTrustedDeviceListSync();
2962    deviceId = devices[0].deviceId;
2963})
2964
2965store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) {
2966    if (err) {
2967        console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
2968        return;
2969    }
2970    console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
2971})
2972```
2973
2974### obtainDistributedTableName
2975
2976 obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt;
2977
2978Obtains 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.
2979
2980> **NOTE**
2981>
2982> The value of **device** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications.
2983
2984**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
2985
2986**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
2987
2988**Parameters**
2989
2990| Name| Type  | Mandatory| Description                |
2991| ------ | ------ | ---- | -------------------- |
2992| device | string | Yes  | ID of the remote device.        |
2993| table  | string | Yes  | Local table name of the remote device.|
2994
2995**Return value**
2996
2997| Type                 | Description                                                 |
2998| --------------------- | ----------------------------------------------------- |
2999| Promise&lt;string&gt; | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.|
3000
3001**Error codes**
3002
3003For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3004
3005| **ID**| **Error Message**                |
3006| ------------ | ---------------------------- |
3007| 14800000     | Inner error.                 |
3008
3009**Example**
3010
3011```js
3012import deviceManager from '@ohos.distributedHardware.deviceManager';
3013let dmInstance = null;
3014let deviceId = null;
3015
3016deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
3017    if (err) {
3018        console.log("create device manager failed, err=" + err);
3019        return;
3020    }
3021    dmInstance = manager;
3022    let devices = dmInstance.getTrustedDeviceListSync();
3023    deviceId = devices[0].deviceId;
3024})
3025
3026let promise = store.obtainDistributedTableName(deviceId, "EMPLOYEE");
3027promise.then((tableName) => {
3028  console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
3029}).catch((err) => {
3030  console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
3031})
3032```
3033
3034### sync
3035
3036sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback&lt;Array&lt;[string, number]&gt;&gt;): void
3037
3038Synchronizes data between devices. This API uses an asynchronous callback to return the result.
3039
3040**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
3041
3042**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3043
3044**Parameters**
3045
3046| Name    | Type                                              | Mandatory| Description                                                        |
3047| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
3048| mode       | [SyncMode](#syncmode)                             | Yes  | Data synchronization mode. The value can be **push** or **pull**.                              |
3049| predicates | [RdbPredicates](#rdbpredicates)               | Yes  | **RdbPredicates** object that specifies the data and devices to synchronize.                                        |
3050| callback   | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | 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. |
3051
3052**Error codes**
3053
3054For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3055
3056| **ID**| **Error Message**                |
3057| ------------ | ---------------------------- |
3058| 14800000     | Inner error.                 |
3059
3060**Example**
3061
3062```js
3063import deviceManager from '@ohos.distributedHardware.deviceManager';
3064let dmInstance = null;
3065let deviceIds = [];
3066
3067deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
3068    if (err) {
3069        console.log("create device manager failed, err=" + err);
3070        return;
3071    }
3072    dmInstance = manager;
3073    let devices = dmInstance.getTrustedDeviceListSync();
3074    for (var i = 0; i < devices.length; i++) {
3075        deviceIds[i] = devices[i].deviceId;
3076    }
3077})
3078
3079let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
3080predicates.inDevices(deviceIds);
3081store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
3082  if (err) {
3083    console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
3084    return;
3085  }
3086  console.info(`Sync done.`);
3087  for (let i = 0; i < result.length; i++) {
3088    console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
3089  }
3090})
3091```
3092
3093### sync
3094
3095 sync(mode: SyncMode, predicates: RdbPredicates): Promise&lt;Array&lt;[string, number]&gt;&gt;
3096
3097Synchronizes data between devices. This API uses a promise to return the result.
3098
3099**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
3100
3101**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3102
3103**Parameters**
3104
3105| Name    | Type                                | Mandatory| Description                          |
3106| ---------- | ------------------------------------ | ---- | ------------------------------ |
3107| mode       | [SyncMode](#syncmode)               | Yes  | Data synchronization mode. The value can be **push** or **pull**.|
3108| predicates | [RdbPredicates](#rdbpredicates) | Yes  | **RdbPredicates** object that specifies the data and devices to synchronize.          |
3109
3110**Return value**
3111
3112| Type                                        | Description                                                        |
3113| -------------------------------------------- | ------------------------------------------------------------ |
3114| Promise&lt;Array&lt;[string, number]&gt;&gt; | 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. |
3115
3116**Error codes**
3117
3118For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3119
3120| **ID**| **Error Message**                |
3121| ------------ | ---------------------------- |
3122| 14800000     | Inner error.                 |
3123
3124**Example**
3125
3126```js
3127import deviceManager from '@ohos.distributedHardware.deviceManager';
3128let dmInstance = null;
3129let deviceIds = [];
3130
3131deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
3132    if (err) {
3133        console.log("create device manager failed, err=" + err);
3134        return;
3135    }
3136    dmInstance = manager;
3137    let devices = dmInstance.getTrustedDeviceListSync();
3138    for (var i = 0; i < devices.length; i++) {
3139        deviceIds[i] = devices[i].deviceId;
3140    }
3141})
3142
3143let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
3144predicates.inDevices(deviceIds);
3145let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates);
3146promise.then((result) =>{
3147  console.info(`Sync done.`);
3148  for (let i = 0; i < result.length; i++) {
3149    console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
3150  }
3151}).catch((err) => {
3152  console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
3153})
3154```
3155
3156### on('dataChange')
3157
3158on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
3159
3160Registers an observer for this RDB store. When the data in the RDB store changes, a callback is invoked to return the data changes.
3161
3162**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3163
3164**Parameters**
3165
3166| Name  | Type                               | Mandatory| Description                                       |
3167| -------- | ----------------------------------- | ---- | ------------------------------------------- |
3168| event    | string                              | Yes  | Event to observe. The value is **dataChange**, which indicates a data change event.         |
3169| type     | [SubscribeType](#subscribetype)    | Yes  | Subscription type to register.|
3170| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes  | Callback invoked to return the data change event. **Array<string>** indicates the IDs of the peer devices whose data in the database is changed.|
3171
3172**Example**
3173
3174```js
3175function storeObserver(devices) {
3176  for (let i = 0; i < devices.length; i++) {
3177    console.info(`device= ${devices[i]} data changed`);
3178  }
3179}
3180try {
3181  store.on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
3182} catch (err) {
3183  console.error(`Register observer failed, code is ${err.code},message is ${err.message}`);
3184}
3185```
3186
3187### off('dataChange')
3188
3189off(event:'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
3190
3191Unregisters the observer of the specified type from the RDB store. This API uses a callback to return the result.
3192
3193**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3194
3195**Parameters**
3196
3197| Name  | Type                               | Mandatory| Description                                       |
3198| -------- | ---------------------------------- | ---- | ------------------------------------------ |
3199| event    | string                              | Yes  | Event type. The value is **dataChange**, which indicates a data change event.         |
3200| type     | [SubscribeType](#subscribetype)     | Yes  | Subscription type to unregister.                                |
3201| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes  | Callback for the data change event. **Array<string>** indicates the IDs of the peer devices whose data in the database is changed.|
3202
3203**Example**
3204
3205```js
3206function storeObserver(devices) {
3207  for (let i = 0; i < devices.length; i++) {
3208    console.info(`device= ${devices[i]} data changed`);
3209  }
3210}
3211try {
3212  store.off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
3213} catch (err) {
3214  console.error(`Unregister observer failed, code is ${err.code},message is ${err.message}`);
3215}
3216```
3217
3218## ResultSet
3219
3220Provides APIs to access the result set obtained by querying the RDB store. A result set is a set of results returned after **query()** is called.
3221
3222### Usage
3223
3224Obtain the **resultSet** object first.
3225
3226```js
3227let resultSet = null;
3228let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3229predicates.equalTo("AGE", 18);
3230let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
3231promise.then((result) => {
3232  resultSet = result;
3233  console.info(`resultSet columnNames: ${resultSet.columnNames}`);
3234  console.info(`resultSet columnCount: ${resultSet.columnCount}`);
3235});
3236```
3237
3238### Attributes
3239
3240**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3241
3242| Name        | Type           | Mandatory| Description                            |
3243| ------------ | ------------------- | ---- | -------------------------------- |
3244| columnNames  | Array&lt;string&gt; | Yes  | Names of all columns in the result set.      |
3245| columnCount  | number              | Yes  | Number of columns in the result set.            |
3246| rowCount     | number              | Yes  | Number of rows in the result set.            |
3247| rowIndex     | number              | Yes  | Index of the current row in the result set.        |
3248| isAtFirstRow | boolean             | Yes  | Whether the cursor is in the first row of the result set.      |
3249| isAtLastRow  | boolean             | Yes  | Whether the cursor is in the last row of the result set.    |
3250| isEnded      | boolean             | Yes  | Whether the cursor is after the last row of the result set.|
3251| isStarted    | boolean             | Yes  | Whether the cursor has been moved.            |
3252| isClosed     | boolean             | Yes  | Whether the result set is closed.        |
3253
3254### getColumnIndex
3255
3256getColumnIndex(columnName: string): number
3257
3258Obtains the column index based on the column name.
3259
3260**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3261
3262**Parameters**
3263
3264| Name    | Type  | Mandatory| Description                      |
3265| ---------- | ------ | ---- | -------------------------- |
3266| columnName | string | Yes  | Column name.|
3267
3268**Return value**
3269
3270| Type  | Description              |
3271| ------ | ------------------ |
3272| number | Column index obtained.|
3273
3274**Error codes**
3275
3276For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3277
3278| **ID**| **Error Message**                                                |
3279| ------------ | ------------------------------------------------------------ |
3280| 14800013     | The column value is null or the column type is incompatible. |
3281
3282**Example**
3283
3284  ```js
3285resultSet.goToFirstRow();
3286const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3287const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3288const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3289const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3290  ```
3291
3292### getColumnName
3293
3294getColumnName(columnIndex: number): string
3295
3296Obtains the column name based on the specified column index.
3297
3298**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3299
3300**Parameters**
3301
3302| Name     | Type  | Mandatory| Description                      |
3303| ----------- | ------ | ---- | -------------------------- |
3304| columnIndex | number | Yes  | Column index.|
3305
3306**Return value**
3307
3308| Type  | Description              |
3309| ------ | ------------------ |
3310| string | Column name obtained.|
3311
3312**Error codes**
3313
3314For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3315
3316| **ID**| **Error Message**                                                |
3317| ------------ | ------------------------------------------------------------ |
3318| 14800013     | The column value is null or the column type is incompatible. |
3319
3320**Example**
3321
3322  ```js
3323const id = resultSet.getColumnName(0);
3324const name = resultSet.getColumnName(1);
3325const age = resultSet.getColumnName(2);
3326  ```
3327
3328### goTo
3329
3330goTo(offset:number): boolean
3331
3332Moves the cursor to the row based on the specified offset.
3333
3334**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3335
3336**Parameters**
3337
3338| Name| Type  | Mandatory| Description                        |
3339| ------ | ------ | ---- | ---------------------------- |
3340| offset | number | Yes  | Offset relative to the current position.|
3341
3342**Return value**
3343
3344| Type   | Description                                         |
3345| ------- | --------------------------------------------- |
3346| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3347
3348**Error codes**
3349
3350For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3351
3352| **ID**| **Error Message**                                                |
3353| ------------ | ------------------------------------------------------------ |
3354| 14800012     | The result set is empty or the specified location is invalid. |
3355
3356**Example**
3357
3358  ```js
3359let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3360let promise= store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
3361promise.then((resultSet) => {
3362  resultSet.goTo(1);
3363  resultSet.close();
3364}).catch((err) => {
3365  console.error(`query failed, code is ${err.code},message is ${err.message}`);
3366});
3367  ```
3368
3369### goToRow
3370
3371goToRow(position: number): boolean
3372
3373Moves to the specified row in the result set.
3374
3375**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3376
3377**Parameters**
3378
3379| Name  | Type  | Mandatory| Description                    |
3380| -------- | ------ | ---- | ------------------------ |
3381| position | number | Yes  | Destination position to move to.|
3382
3383**Return value**
3384
3385| Type   | Description                                         |
3386| ------- | --------------------------------------------- |
3387| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3388
3389**Error codes**
3390
3391For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3392
3393| **ID**| **Error Message**                                                |
3394| ------------ | ------------------------------------------------------------ |
3395| 14800012     | The result set is empty or the specified location is invalid. |
3396
3397**Example**
3398
3399  ```js
3400let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3401let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
3402promise.then((resultSet) => {
3403  resultSet.goToRow(5);
3404  resultSet.close();
3405}).catch((err) => {
3406  console.error(`query failed, code is ${err.code},message is ${err.message}`);
3407});
3408  ```
3409
3410### goToFirstRow
3411
3412goToFirstRow(): boolean
3413
3414
3415Moves to the first row of the result set.
3416
3417**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3418
3419**Return value**
3420
3421| Type   | Description                                         |
3422| ------- | --------------------------------------------- |
3423| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3424
3425**Error codes**
3426
3427For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3428
3429| **ID**| **Error Message**                                                |
3430| ------------ | ------------------------------------------------------------ |
3431| 14800012     | The result set is empty or the specified location is invalid. |
3432
3433**Example**
3434
3435  ```js
3436let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3437let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
3438promise.then((resultSet) => {
3439  resultSet.goToFirstRow();
3440  resultSet.close();
3441}).catch((err) => {
3442  console.error(`query failed, code is ${err.code},message is ${err.message}`);
3443});
3444  ```
3445
3446### goToLastRow
3447
3448goToLastRow(): boolean
3449
3450Moves to the last row of the result set.
3451
3452**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3453
3454**Return value**
3455
3456| Type   | Description                                         |
3457| ------- | --------------------------------------------- |
3458| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3459
3460**Error codes**
3461
3462For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3463
3464| **ID**| **Error Message**                                                |
3465| ------------ | ------------------------------------------------------------ |
3466| 14800012     | The result set is empty or the specified location is invalid. |
3467
3468**Example**
3469
3470  ```js
3471let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3472let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
3473promise.then((resultSet) => {
3474  resultSet.goToLastRow();
3475  resultSet.close();
3476}).catch((err) => {
3477  console.error(`query failed, code is ${err.code},message is ${err.message}`);
3478});
3479  ```
3480
3481### goToNextRow
3482
3483goToNextRow(): boolean
3484
3485Moves to the next row in the result set.
3486
3487**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3488
3489**Return value**
3490
3491| Type   | Description                                         |
3492| ------- | --------------------------------------------- |
3493| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3494
3495**Error codes**
3496
3497For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3498
3499| **ID**| **Error Message**                                                |
3500| ------------ | ------------------------------------------------------------ |
3501| 14800012     | The result set is empty or the specified location is invalid. |
3502
3503**Example**
3504
3505  ```js
3506let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3507let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
3508promise.then((resultSet) => {
3509  resultSet.goToNextRow();
3510  resultSet.close();
3511}).catch((err) => {
3512  console.error(`query failed, code is ${err.code},message is ${err.message}`);
3513});
3514  ```
3515
3516### goToPreviousRow
3517
3518goToPreviousRow(): boolean
3519
3520Moves to the previous row in the result set.
3521
3522**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3523
3524**Return value**
3525
3526| Type   | Description                                         |
3527| ------- | --------------------------------------------- |
3528| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
3529
3530**Error codes**
3531
3532For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3533
3534| **ID**| **Error Message**                                                |
3535| ------------ | ------------------------------------------------------------ |
3536| 14800012     | The result set is empty or the specified location is invalid. |
3537
3538**Example**
3539
3540  ```js
3541let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3542let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
3543promise.then((resultSet) => {
3544  resultSet.goToPreviousRow();
3545  resultSet.close();
3546}).catch((err) => {
3547  console.error(`query failed, code is ${err.code},message is ${err.message}`);
3548});
3549  ```
3550
3551### getBlob
3552
3553getBlob(columnIndex: number): Uint8Array
3554
3555Obtains the value in the form of a byte array based on the specified column and the current row.
3556
3557**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3558
3559**Parameters**
3560
3561| Name     | Type  | Mandatory| Description                   |
3562| ----------- | ------ | ---- | ----------------------- |
3563| columnIndex | number | Yes  | Index of the target column, starting from 0.|
3564
3565**Return value**
3566
3567| Type      | Description                            |
3568| ---------- | -------------------------------- |
3569| Uint8Array | Value obtained.|
3570
3571**Error codes**
3572
3573For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3574
3575| **ID**| **Error Message**                                                |
3576| ------------ | ------------------------------------------------------------ |
3577| 14800013     | The column value is null or the column type is incompatible. |
3578
3579**Example**
3580
3581  ```js
3582const codes = resultSet.getBlob(resultSet.getColumnIndex("CODES"));
3583  ```
3584
3585### getString
3586
3587getString(columnIndex: number): string
3588
3589Obtains the value in the form of a string based on the specified column and the current row.
3590
3591**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3592
3593**Parameters**
3594
3595| Name     | Type  | Mandatory| Description                   |
3596| ----------- | ------ | ---- | ----------------------- |
3597| columnIndex | number | Yes  | Index of the target column, starting from 0.|
3598
3599**Return value**
3600
3601| Type  | Description                        |
3602| ------ | ---------------------------- |
3603| string | String obtained.|
3604
3605**Error codes**
3606
3607For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3608
3609| **ID**| **Error Message**                                                |
3610| ------------ | ------------------------------------------------------------ |
3611| 14800013     | The column value is null or the column type is incompatible. |
3612
3613**Example**
3614
3615  ```js
3616const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3617  ```
3618
3619### getLong
3620
3621getLong(columnIndex: number): number
3622
3623Obtains the value of the Long type based on the specified column and the current row.
3624
3625**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3626
3627**Parameters**
3628
3629| Name     | Type  | Mandatory| Description                   |
3630| ----------- | ------ | ---- | ----------------------- |
3631| columnIndex | number | Yes  | Index of the target column, starting from 0.|
3632
3633**Return value**
3634
3635| Type  | Description                                                        |
3636| ------ | ------------------------------------------------------------ |
3637| number | Value obtained.<br>The value range supported by API is **Number.MIN_SAFE_INTEGER** to **Number.MAX_SAFE_INTEGER**. If the value is out of this range, use [getDouble](#getdouble).|
3638
3639**Error codes**
3640
3641For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3642
3643| **ID**| **Error Message**                                                |
3644| ------------ | ------------------------------------------------------------ |
3645| 14800013     | The column value is null or the column type is incompatible. |
3646
3647**Example**
3648
3649  ```js
3650const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3651  ```
3652
3653### getDouble
3654
3655getDouble(columnIndex: number): number
3656
3657Obtains the value of the double type based on the specified column and the current row.
3658
3659**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3660
3661**Parameters**
3662
3663| Name     | Type  | Mandatory| Description                   |
3664| ----------- | ------ | ---- | ----------------------- |
3665| columnIndex | number | Yes  | Index of the target column, starting from 0.|
3666
3667**Return value**
3668
3669| Type  | Description                        |
3670| ------ | ---------------------------- |
3671| number | Value obtained.|
3672
3673**Error codes**
3674
3675For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3676
3677| **ID**| **Error Message**                                                |
3678| ------------ | ------------------------------------------------------------ |
3679| 14800013     | The column value is null or the column type is incompatible. |
3680
3681**Example**
3682
3683  ```js
3684const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3685  ```
3686
3687### isColumnNull
3688
3689isColumnNull(columnIndex: number): boolean
3690
3691Checks whether the value in the specified column is null.
3692
3693**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3694
3695**Parameters**
3696
3697| Name     | Type  | Mandatory| Description                   |
3698| ----------- | ------ | ---- | ----------------------- |
3699| columnIndex | number | Yes  | Index of the target column, starting from 0.|
3700
3701**Return value**
3702
3703| Type   | Description                                                     |
3704| ------- | --------------------------------------------------------- |
3705| boolean | Returns **true** if the value is null; returns **false** otherwise.|
3706
3707**Error codes**
3708
3709For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3710
3711| **ID**| **Error Message**                                                |
3712| ------------ | ------------------------------------------------------------ |
3713| 14800013     | The column value is null or the column type is incompatible. |
3714
3715**Example**
3716
3717  ```js
3718const isColumnNull = resultSet.isColumnNull(resultSet.getColumnIndex("CODES"));
3719  ```
3720
3721### close
3722
3723close(): void
3724
3725Closes this result set.
3726
3727**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
3728
3729**Example**
3730
3731  ```js
3732let predicatesClose = new relationalStore.RdbPredicates("EMPLOYEE");
3733let promiseClose = store.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
3734promiseClose.then((resultSet) => {
3735  resultSet.close();
3736}).catch((err) => {
3737  console.error(`resultset close failed, code is ${err.code},message is ${err.message}`);
3738});
3739  ```
3740
3741**Error codes**
3742
3743For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
3744
3745| **ID**| **Error Message**                                                |
3746| ------------ | ------------------------------------------------------------ |
3747| 14800012     | The result set is empty or the specified location is invalid. |
3748