js-apis-data-relationalStore.md 192.9 KB
Newer Older
A
Annie_wang 已提交
1
# @ohos.data.relationalStore (RDB Store)
A
Annie_wang 已提交
2

G
Gloria 已提交
3
The relational database (RDB) store manages data based on relational models. It provides a complete mechanism for managing local databases based on the underlying SQLite. To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements. The worker threads are not supported.
A
Annie_wang 已提交
4 5 6 7 8

The **relationalStore** module provides the following functions:

- [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.
- [RdbStore](#rdbstore): provides APIs for managing data in an RDB store.
A
Annie_wang 已提交
9
- [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store. 
A
Annie_wang 已提交
10

A
Annie_wang 已提交
11
> **NOTE**
A
Annie_wang 已提交
12 13 14 15 16 17
> 
> 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.

## Modules to Import

```js
A
Annie_wang 已提交
18
import relationalStore from '@ohos.data.relationalStore'
A
Annie_wang 已提交
19 20
```

A
Annie_wang 已提交
21
## relationalStore.getRdbStore
A
Annie_wang 已提交
22 23 24 25 26 27 28 29 30 31 32

getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback<RdbStore>): void

Obtains 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.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                                          | Mandatory| Description                                                        |
| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
A
Annie_wang 已提交
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).|
A
Annie_wang 已提交
34 35 36 37 38 39 40
| config   | [StoreConfig](#storeconfig)               | Yes  | Configuration of the RDB store.                               |
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes  | Callback invoked to return the RDB store obtained.                  |

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
41 42 43 44 45
| **ID**| **Error Message**                                               |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800011     | Failed to open database by database corrupted.              |
| 14800000     | Inner error.                                                |
G
Gloria 已提交
46 47
| 14801001     | Only supported in stage mode.                               |
| 14801002     | The data group id is not valid.                             |
A
Annie_wang 已提交
48 49 50 51 52 53

**Example**

FA model:

```js
A
Annie_wang 已提交
54

A
Annie_wang 已提交
55
import featureAbility from '@ohos.ability.featureAbility'
A
Annie_wang 已提交
56

A
Annie_wang 已提交
57 58
var store;

A
Annie_wang 已提交
59
// Obtain the context.
A
Annie_wang 已提交
60
let context = featureAbility.getContext();
A
Annie_wang 已提交
61 62

const STORE_CONFIG = {
A
Annie_wang 已提交
63 64 65 66 67 68 69
  name: "RdbTest.db",
  securityLevel: relationalStore.SecurityLevel.S1
};

relationalStore.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) {
  store = rdbStore;
  if (err) {
A
Annie_wang 已提交
70
    console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
71 72 73
    return;
  }
  console.info(`Get RdbStore successfully.`);
A
Annie_wang 已提交
74 75 76 77 78 79
})
```

Stage model:

```ts
A
Annie_wang 已提交
80
import UIAbility from '@ohos.app.ability.UIAbility'
A
Annie_wang 已提交
81 82

class EntryAbility extends UIAbility {
A
Annie_wang 已提交
83 84 85 86 87 88
  onWindowStageCreate(windowStage) {
    var store;
    const STORE_CONFIG = {
      name: "RdbTest.db",
      securityLevel: relationalStore.SecurityLevel.S1
    };
A
Annie_wang 已提交
89
        
A
Annie_wang 已提交
90 91 92
    relationalStore.getRdbStore(this.context, STORE_CONFIG, function (err, rdbStore) {
      store = rdbStore;
      if (err) {
A
Annie_wang 已提交
93
        console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
94 95 96 97 98
        return;
      }
      console.info(`Get RdbStore successfully.`);
    })
  }
A
Annie_wang 已提交
99 100 101
}
```

A
Annie_wang 已提交
102
## relationalStore.getRdbStore
A
Annie_wang 已提交
103 104 105 106 107 108 109 110 111 112 113

getRdbStore(context: Context, config: StoreConfig): Promise&lt;RdbStore&gt;

Obtains 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.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name | Type                            | Mandatory| Description                                                        |
| ------- | -------------------------------- | ---- | ------------------------------------------------------------ |
A
Annie_wang 已提交
114
| 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).|
A
Annie_wang 已提交
115 116 117 118 119 120
| config  | [StoreConfig](#storeconfig) | Yes  | Configuration of the RDB store.                               |

**Return value**

| Type                                     | Description                             |
| ----------------------------------------- | --------------------------------- |
A
Annie_wang 已提交
121
| Promise&lt;[RdbStore](#rdbstore)&gt; | Promise used to return the **RdbStore** object.|
A
Annie_wang 已提交
122 123 124 125 126

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
127 128 129 130 131
| **ID**| **Error Message**                                               |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800011     | Failed to open database by database corrupted.              |
| 14800000     | Inner error.                                                |
G
Gloria 已提交
132 133
| 14801001     | Only supported in stage mode.                               |
| 14801002     | The data group id is not valid.                             |
A
Annie_wang 已提交
134 135 136 137 138 139 140

**Example**

FA model:

```js
import featureAbility from '@ohos.ability.featureAbility'
A
Annie_wang 已提交
141

A
Annie_wang 已提交
142 143
var store;

A
Annie_wang 已提交
144
// Obtain the context.
A
Annie_wang 已提交
145
let context = featureAbility.getContext();
A
Annie_wang 已提交
146 147

const STORE_CONFIG = {
A
Annie_wang 已提交
148 149 150
  name: "RdbTest.db",
  securityLevel: relationalStore.SecurityLevel.S1
};
A
Annie_wang 已提交
151

A
Annie_wang 已提交
152
let promise = relationalStore.getRdbStore(context, STORE_CONFIG);
A
Annie_wang 已提交
153
promise.then(async (rdbStore) => {
A
Annie_wang 已提交
154 155
  store = rdbStore;
  console.info(`Get RdbStore successfully.`);
A
Annie_wang 已提交
156
}).catch((err) => {
A
Annie_wang 已提交
157
  console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
158 159 160 161 162 163
})
```

Stage model:

```ts
A
Annie_wang 已提交
164
import UIAbility from '@ohos.app.ability.UIAbility'
A
Annie_wang 已提交
165 166

class EntryAbility extends UIAbility {
A
Annie_wang 已提交
167 168 169 170 171 172
  onWindowStageCreate(windowStage) {
    var store;
    const STORE_CONFIG = {
      name: "RdbTest.db",
      securityLevel: relationalStore.SecurityLevel.S1
    };
A
Annie_wang 已提交
173
        
A
Annie_wang 已提交
174 175 176 177 178
    let promise = relationalStore.getRdbStore(this.context, STORE_CONFIG);
    promise.then(async (rdbStore) => {
      store = rdbStore;
      console.info(`Get RdbStore successfully.`)
    }).catch((err) => {
A
Annie_wang 已提交
179
      console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
180 181
    })
  }
A
Annie_wang 已提交
182 183 184
}
```

A
Annie_wang 已提交
185
## relationalStore.deleteRdbStore
A
Annie_wang 已提交
186 187 188 189 190

deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void

Deletes an RDB store. This API uses an asynchronous callback to return the result.

G
Gloria 已提交
191 192
After the deletion, you are advised to set the database object to null.

A
Annie_wang 已提交
193 194 195 196 197 198
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                     | Mandatory| Description                                                        |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
A
Annie_wang 已提交
199
| 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).|
A
Annie_wang 已提交
200 201 202 203 204 205 206
| name     | string                    | Yes  | Name of the RDB store to delete.                                                |
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result.                                      |

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
207 208 209 210
| **ID**| **Error Message**                                               |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800000     | Inner error.                                                |
A
Annie_wang 已提交
211 212 213 214 215 216 217

**Example**

FA model:

```js
import featureAbility from '@ohos.ability.featureAbility'
A
Annie_wang 已提交
218

219 220
var store;

A
Annie_wang 已提交
221
// Obtain the context.
A
Annie_wang 已提交
222 223
let context = featureAbility.getContext()

A
Annie_wang 已提交
224 225
relationalStore.deleteRdbStore(context, "RdbTest.db", function (err) {
  if (err) {
A
Annie_wang 已提交
226
    console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
227 228
    return;
  }
G
Gloria 已提交
229
  store = null;
A
Annie_wang 已提交
230
  console.info(`Delete RdbStore successfully.`);
A
Annie_wang 已提交
231 232 233 234 235 236
})
```

Stage model:

```ts
A
Annie_wang 已提交
237
import UIAbility from '@ohos.app.ability.UIAbility'
A
Annie_wang 已提交
238

239 240
var store;

A
Annie_wang 已提交
241
class EntryAbility extends UIAbility {
A
Annie_wang 已提交
242 243 244
  onWindowStageCreate(windowStage){
    relationalStore.deleteRdbStore(this.context, "RdbTest.db", function (err) {
      if (err) {
A
Annie_wang 已提交
245
        console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
246 247
        return;
      }
G
Gloria 已提交
248
      store = null;
A
Annie_wang 已提交
249 250 251
      console.info(`Delete RdbStore successfully.`);
    })
  }
A
Annie_wang 已提交
252 253 254
}
```

A
Annie_wang 已提交
255
## relationalStore.deleteRdbStore
A
Annie_wang 已提交
256 257 258 259 260

deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;

Deletes an RDB store. This API uses a promise to return the result.

G
Gloria 已提交
261 262
After the deletion, you are advised to set the database object to null.

A
Annie_wang 已提交
263 264 265 266 267 268
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name | Type   | Mandatory| Description                                                        |
| ------- | ------- | ---- | ------------------------------------------------------------ |
A
Annie_wang 已提交
269
| 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).|
A
Annie_wang 已提交
270 271 272 273 274 275 276 277 278 279 280 281
| name    | string  | Yes  | Name of the RDB store to delete.                                                |

**Return value**

| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
282 283 284 285
| **ID**| **Error Message**                                               |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800000     | Inner error.                                                |
A
Annie_wang 已提交
286 287 288 289 290 291 292

**Example**

FA model:

```js
import featureAbility from '@ohos.ability.featureAbility'
A
Annie_wang 已提交
293

294 295
var store;

A
Annie_wang 已提交
296
// Obtain the context.
A
Annie_wang 已提交
297
let context = featureAbility.getContext();
A
Annie_wang 已提交
298

A
Annie_wang 已提交
299
let promise = relationalStore.deleteRdbStore(context, "RdbTest.db");
A
Annie_wang 已提交
300
promise.then(()=>{
G
Gloria 已提交
301
  store = null;
A
Annie_wang 已提交
302
  console.info(`Delete RdbStore successfully.`);
A
Annie_wang 已提交
303
}).catch((err) => {
A
Annie_wang 已提交
304
  console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
305 306 307 308 309 310
})
```

Stage model:

```ts
A
Annie_wang 已提交
311
import UIAbility from '@ohos.app.ability.UIAbility'
A
Annie_wang 已提交
312

313 314
var store;

A
Annie_wang 已提交
315
class EntryAbility extends UIAbility {
A
Annie_wang 已提交
316 317 318
  onWindowStageCreate(windowStage){
    let promise = relationalStore.deleteRdbStore(this.context, "RdbTest.db");
    promise.then(()=>{
G
Gloria 已提交
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
      store = null;
      console.info(`Delete RdbStore successfully.`);
    }).catch((err) => {
      console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
    })
  }
}
```

## relationalStore.deleteRdbStore<sup>10+</sup>

deleteRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback\<void>): void

Deletes an RDB store. This API uses an asynchronous callback to return the result.

After the deletion, you are advised to set the database object to null. If the database file is in the public sandbox directory, you must use this API to delete the database. If the database is accessed by multiple processes at the same time, you are advised to send a database deletion notification to other processes.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                       | Mandatory| Description                                                        |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| 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).|
| config   | [StoreConfig](#storeconfig) | Yes  | Configuration of the RDB store.                               |
| callback | AsyncCallback&lt;void&gt;   | Yes  | Callback invoked to return the result.                                      |

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                               |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800000     | Inner error.                                                |
| 14801001     | Only supported in stage mode.                               |
| 14801002     | The data group id is not valid.                             |

**Example**

FA model:

```js
import featureAbility from '@ohos.ability.featureAbility'

364 365
var store;

G
Gloria 已提交
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
// Obtain the context.
let context = featureAbility.getContext()
const STORE_CONFIG = {
  name: "RdbTest.db",
  securityLevel: relationalStore.SecurityLevel.S1
};

relationalStore.deleteRdbStore(context, STORE_CONFIG, function (err) {
  if (err) {
    console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
    return;
  }
  store = null;
  console.info(`Delete RdbStore successfully.`);
})
```

Stage model:

```ts
import UIAbility from '@ohos.app.ability.UIAbility'

388 389
var store;

G
Gloria 已提交
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
class EntryAbility extends UIAbility {
  onWindowStageCreate(windowStage){
    const STORE_CONFIG = {
      name: "RdbTest.db",
      securityLevel: relationalStore.SecurityLevel.S1
    };
    relationalStore.deleteRdbStore(this.context, STORE_CONFIG, function (err) {
      if (err) {
        console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
        return;
      }
      store = null;
      console.info(`Delete RdbStore successfully.`);
    })
  }
}
```

## relationalStore.deleteRdbStore<sup>10+</sup>

deleteRdbStore(context: Context, config: StoreConfig): Promise\<void>

Deletes an RDB store. This API uses a promise to return the result.

After the deletion, you are advised to set the database object to null. If the database file is in the public sandbox directory, you must use this API to delete the database. If the database is accessed by multiple processes at the same time, you are advised to send a database deletion notification to other processes.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name | Type                       | Mandatory| Description                                                        |
| ------- | --------------------------- | ---- | ------------------------------------------------------------ |
| 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).|
| config  | [StoreConfig](#storeconfig) | Yes  | Configuration of the RDB store.                               |

**Return value**

| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                               |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800000     | Inner error.                                                |
| 14801001     | Only supported in stage mode.                               |
| 14801002     | The data group id is not valid.                             |

**Example**

FA model:

```js
import featureAbility from '@ohos.ability.featureAbility'

449 450
var store;

G
Gloria 已提交
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
// Obtain the context.
let context = featureAbility.getContext();
const STORE_CONFIG = {
  name: "RdbTest.db",
  securityLevel: relationalStore.SecurityLevel.S1
};

let promise = relationalStore.deleteRdbStore(context, STORE_CONFIG);
promise.then(()=>{
  store = null;
  console.info(`Delete RdbStore successfully.`);
}).catch((err) => {
  console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
})
```

Stage model:

```ts
import UIAbility from '@ohos.app.ability.UIAbility'

472 473
var store;

G
Gloria 已提交
474 475 476 477 478 479 480 481 482
class EntryAbility extends UIAbility {
  onWindowStageCreate(windowStage){
    const STORE_CONFIG = {
      name: "RdbTest.db",
      securityLevel: relationalStore.SecurityLevel.S1
    };
    let promise = relationalStore.deleteRdbStore(this.context, STORE_CONFIG);
    promise.then(()=>{
      store = null;
A
Annie_wang 已提交
483 484
      console.info(`Delete RdbStore successfully.`);
    }).catch((err) => {
A
Annie_wang 已提交
485
      console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
486 487
    })
  }
A
Annie_wang 已提交
488 489 490 491 492 493 494 495 496 497 498 499 500
}
```

## StoreConfig

Defines the RDB store configuration.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name       | Type         | Mandatory| Description                                                     |
| ------------- | ------------- | ---- | --------------------------------------------------------- |
| name          | string        | Yes  | Database file name.                                           |
| securityLevel | [SecurityLevel](#securitylevel) | Yes  | Security level of the RDB store.                                       |
A
Annie_wang 已提交
501
| encrypt       | boolean       | No  | Whether to encrypt the RDB store.<br>The value **true** means to encrypt the RDB store; the value **false** (default) means the opposite.|
G
Gloria 已提交
502
| dataGroupId<sup>10+</sup> | string | No| Application group ID, which needs to be obtained from the AppGallery.<br>**Model restriction**: This attribute can be used only in the stage model.<br>This parameter is supported since API version 10. It specifies the **relationalStore** instance created in the sandbox directory corresponding to the **dataGroupId**. If this parameter is not specified, the **relationalStore** instance is created in the sandbox directory of the application.|
A
Annie_wang 已提交
503 504 505 506 507

## SecurityLevel

Enumerates the RDB store security levels.

A
Annie_wang 已提交
508 509
> **NOTE**
>
G
Gloria 已提交
510
> To perform data synchronization operations, the RDB store security level must be lower than or equal to that of the peer device. For details, see the [Access Control Mechanism in Cross-Device Synchronization](../../database/access-control-by-device-and-data-level.md#access-control-mechanism-in-cross-device-synchronization).
A
Annie_wang 已提交
511

A
Annie_wang 已提交
512 513 514 515 516 517 518 519 520
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name| Value  | Description                                                        |
| ---- | ---- | ------------------------------------------------------------ |
| 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.|
| 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.|
| 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.|
| 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.|

A
Annie_wang 已提交
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
## AssetStatus<sup>10+</sup>

Enumerates the asset statuses. Use the enum names instead of the enum values.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name                             | Value  | Description            |
| ------------------------------- | --- | -------------- |
| ASSET_NORMAL     | -   | The asset is in normal status.     |
| ASSET_INSERT | - | The asset is to be inserted to the cloud.|
| ASSET_UPDATE | - | The asset is to be updated to the cloud.|
| ASSET_DELETE | - | The asset is to be deleted from the cloud.|
| ASSET_ABNORMAL    | -   | The asset is in abnormal status.     |
| ASSET_DOWNLOADING | -   | The asset is being downloaded to a local device.|

## Asset<sup>10+</sup>

Defines information about an asset (such as a document, image, and video). The asset APIs do not support **Datashare**.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name         | Type                         | Mandatory | Description          |
| ----------- | --------------------------- | --- | ------------ |
| name        | string                      | Yes  | Asset name.      |
| uri         | string                      | Yes  | Asset URI, which is an absolute path in the system.      |
| path        | string                      | Yes  | Application sandbox path of the asset.      |
| createTime  | string                      | Yes  | Time when the asset was created.  |
| modifyTime  | string                      | Yes  | Time when the asset was last modified.|
| size        | string                      | Yes  | Size of the asset.   |
| status      | [AssetStatus](#assetstatus10) | No  | Asset status. The default value is **ASSET_NORMAL**.       |

## Assets<sup>10+</sup>

Defines an array of the [Asset](#asset10) type.

G
Gloria 已提交
556 557
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
Annie_wang 已提交
558 559 560 561
| Type   | Description                |
| ------- | -------------------- |
| [Asset](#asset10)[] | Array of assets.  |

A
Annie_wang 已提交
562 563 564 565 566 567 568 569
## ValueType

Defines the data types allowed.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Type   | Description                |
| ------- | -------------------- |
A
Annie_wang 已提交
570
| null<sup>10+</sup>    | Null.  |
A
Annie_wang 已提交
571 572 573
| number  | Number.  |
| string  | String.  |
| boolean | Boolean.|
A
Annie_wang 已提交
574 575 576
| Uint8Array<sup>10+</sup>           | Uint8 array.           |
| Asset<sup>10+</sup>  | [Asset](#asset10).    |
| Assets<sup>10+</sup> | [Assets](#assets10).|
A
Annie_wang 已提交
577 578 579

## ValuesBucket

A
Annie_wang 已提交
580
Enumerates the types of the key in a KV pair. This type is not multi-thread safe. If a **ValuesBucket** instance is operated by multiple threads at the same time in an application, use a lock for the instance.
A
Annie_wang 已提交
581 582 583

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
Annie_wang 已提交
584 585 586
| Key Type| Value Type                  |
| ------ | ----------------------- |
| string | [ValueType](#valuetype) |
A
Annie_wang 已提交
587

G
Gloria 已提交
588 589
## PRIKeyType<sup>10+</sup> 

A
Annie_wang 已提交
590
Enumerates the types of the primary key in a row of a database table.
G
Gloria 已提交
591 592 593 594 595

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Type            | Description                              |
| ---------------- | ---------------------------------- |
A
Annie_wang 已提交
596 597
| number | The primary key is a number.|
| string | The primary key is a string.|
G
Gloria 已提交
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618

## UTCTime<sup>10+</sup>

Represents the data type of the UTC time.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Type| Description           |
| ---- | --------------- |
| Date | UTC time.|

## ModifyTime<sup>10+</sup> 

Represents the data type of the primary key and modification time of a database table.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Type                                                   | Description                                                        |
| ------------------------------------------------------- | ------------------------------------------------------------ |
| Map<[PRIKeyType](#prikeytype10), [UTCTime](#utctime10)> | The key is the primary key of a row in the database table, and the value is the last modification time of the row in UTC format.|

A
Annie_wang 已提交
619 620
## SyncMode

A
Annie_wang 已提交
621
Enumerates the database synchronization modes.
A
Annie_wang 已提交
622 623 624

| Name          | Value  | Description                              |
| -------------- | ---- | ---------------------------------- |
A
Annie_wang 已提交
625 626
| SYNC_MODE_PUSH                       | 0   | Push data from a local device to a remote device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core                    |
| SYNC_MODE_PULL                       | 1   | Pull data from a remote device to a local device.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core                     |
G
Gloria 已提交
627 628 629
| SYNC_MODE_TIME_FIRST<sup>10+</sup>   | -   | Synchronize with the data with the latest modification time. Use the enum names instead of the enum values.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client|
| SYNC_MODE_NATIVE_FIRST<sup>10+</sup> | -   | Synchronize data from a local device to the cloud. Use the enum names instead of the enum values.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client            |
| SYNC_MODE_CLOUD_FIRST<sup>10+</sup>  | -   | Synchronize data from the cloud to a local device. Use the enum names instead of the enum values.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client            |
A
Annie_wang 已提交
630 631 632

## SubscribeType

A
Annie_wang 已提交
633
Enumerates the subscription types.
A
Annie_wang 已提交
634 635 636 637 638

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

| Name                 | Value  | Description              |
| --------------------- | ---- | ------------------ |
A
Annie_wang 已提交
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
| SUBSCRIBE_TYPE_REMOTE | 0    | Subscribe to remote data changes.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core|
| SUBSCRIBE_TYPE_CLOUD<sup>10+</sup> | -  | Subscribe to cloud data changes. Use the enum names instead of the enum values.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client|
| SUBSCRIBE_TYPE_CLOUD_DETAILS<sup>10+</sup> | -  | Subscribe to cloud data change details. Use the enum names instead of the enum values.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client|

## ChangeType<sup>10+</sup>

Enumerates data change types. Use the enum names instead of the enum values.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

| Name                        | Value  | Description                        |
| -------------------------- | --- | -------------------------- |
| DATA_CHANGE  | -   | Data change.  |
| ASSET_CHANGE | -   | Asset change.|

## ChangeInfo<sup>10+</sup>

Defines the details about the device-cloud synchronization process.

G
Gloria 已提交
660
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
A
Annie_wang 已提交
661

G
Gloria 已提交
662 663 664 665 666 667 668
| Name    | Type                              | Mandatory| Description                                                        |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| table    | string                             | Yes  | Name of the table with data changes.                                    |
| type     | [ChangeType](#changetype10)        | Yes  | Type of the data changed, which can be data or asset.        |
| inserted | Array\<string\> \| Array\<number\> | Yes  | Location where data is inserted. If the primary key of the table is of the string type, the value is the value of the primary key. Otherwise, the value is the row number of the inserted data.|
| updated  | Array\<string\> \| Array\<number\> | Yes  | Location where data is updated. If the primary key of the table is of the string type, the value is the value of the primary key. Otherwise, the value is the row number of the updated data.|
| deleted  | Array\<string\> \| Array\<number\> | Yes  | Location where data is deleted. If the primary key of the table is of the string type, the value is the value of the primary key. Otherwise, the value is the row number of the deleted data.|
A
Annie_wang 已提交
669 670 671 672 673 674 675 676 677

## DistributedType<sup>10+</sup>

Enumerates the distributed table types. Use the enum names instead of the enum values.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

| Name               | Value  | Description                                                                                                |
| ------------------ | --- | -------------------------------------------------------------------------------------------------- |
678 679
| DISTRIBUTED_DEVICE | -  | Distributed database table synchronized between devices.<br>**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core |
| DISTRIBUTED_CLOUD  | -   | Distributed database table synchronized between the device and the cloud.<br>**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client |
A
Annie_wang 已提交
680 681 682 683 684 685 686 687 688

## DistributedConfig<sup>10+</sup>

Defines the configuration of the distributed mode of tables.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name    | Type   | Mandatory| Description                                                        |
| -------- | ------- | ---- | ------------------------------------------------------------ |
689
| autoSync | boolean | Yes  | The value **true** means both automatic synchronization and manual synchronization are supported for the table.<br/>The value **false** means only manual synchronization is supported for the table. |
A
Annie_wang 已提交
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705

## ConflictResolution<sup>10+</sup>

Defines the resolution to use when **insert()** and **update()** conflict.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name                | Value  | Description                                                        |
| -------------------- | ---- | ------------------------------------------------------------ |
| ON_CONFLICT_NONE | 0 | No operation is performed.|
| ON_CONFLICT_ROLLBACK | 1    | Abort the SQL statement and roll back the current transaction.               |
| 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.|
| 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.|
| ON_CONFLICT_IGNORE   | 4    | Skip the rows that contain constraint violations and continue to process the subsequent rows of the SQL statement.|
| 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.|

G
Gloria 已提交
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
## Progress<sup>10+</sup>

Enumerates the device-cloud synchronization processes. Use the enum names instead of the enum values.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name            | Value  | Description                    |
| ---------------- | ---- | ------------------------ |
| SYNC_BEGIN       | -    | The device-cloud synchronization starts.  |
| SYNC_IN_PROGRESS | -    | The device-cloud synchronization is in progress.|
| SYNC_FINISH      | -    | The device-cloud synchronization is complete.|

## Statistic<sup>10+</sup>

Represents the device-cloud synchronization statistics information.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

724 725 726 727 728 729
| Name      | Type  | Mandatory| Description                                    |
| ---------- | ------ | ---- | ---------------------------------------- |
| total      | number | Yes  | Total number of rows to be synchronized between the device and cloud in the database table.    |
| successful | number | Yes  | Number of rows that are successfully synchronized between the device and cloud in the database table.      |
| failed     | number | Yes  | Number of rows that failed to be synchronized between the device and cloud in the database table.      |
| remained   | number | Yes  | Number of rows that are not executed for device-cloud synchronization in the database table.|
G
Gloria 已提交
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769

## TableDetails<sup>10+</sup>

Represents the upload and download statistics of device-cloud synchronization tasks.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name    | Type                     | Mandatory| Description                                      |
| -------- | ------------------------- | ---- | ------------------------------------------ |
| upload   | [Statistic](#statistic10) | Yes  | Statistics of the device-cloud upload tasks.|
| download | [Statistic](#statistic10) | Yes  | Statistics of the device-cloud download tasks.|

## ProgressCode<sup>10+</sup>

Enumerates the device-cloud synchronization states. Use the enum names instead of the enum values.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name                 | Value  | Description                                                        |
| --------------------- | ---- | ------------------------------------------------------------ |
| SUCCESS               | -    | The device-cloud synchronization is successful.                                      |
| UNKNOWN_ERROR         | -    | An unknown error occurs during device-cloud synchronization.                              |
| NETWORK_ERROR         | -    | A network error occurs during device-cloud synchronization.                              |
| CLOUD_DISABLED        | -    | The cloud is unavailable.                                            |
| LOCKED_BY_OTHERS      | -    | The device-cloud synchronization of another device is being performed.<br>Start device-cloud synchronization after checking that cloud resources are not occupied by other devices.|
| RECORD_LIMIT_EXCEEDED | -    | The number of records or size of the data to be synchronized exceeds the maximum. The maximum value is configured on the cloud.|
| NO_SPACE_FOR_ASSET    | -    | The remaining cloud space is less than the size of the data to be synchronized.                    |

## ProgressDetails<sup>10+</sup>

Represents the statistics of the overall device-cloud synchronization (upload and download) tasks.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name    | Type                                             | Mandatory| Description                                                        |
| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
| schedule | [Progress](#progress10)                           | Yes  | Device-cloud synchronization process.                                          |
| code     | [ProgressCode](#progresscode10)                   | Yes  | Device-cloud synchronization state.                                    |
| details  | [table: string] : [TableDetails](#tabledetails10) | Yes  | Statistics of each table.<br>The key indicates the table name, and the value indicates the device-cloud synchronization statistics of the table.|

A
Annie_wang 已提交
770 771
## RdbPredicates

A
Annie_wang 已提交
772
Defines 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.
A
Annie_wang 已提交
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790

### constructor

constructor(name: string)

A constructor used to create an **RdbPredicates** object.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description        |
| ------ | ------ | ---- | ------------ |
| name   | string | Yes  | Database table name.|

**Example**

```js
A
Annie_wang 已提交
791
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
A
Annie_wang 已提交
792 793 794 795 796 797 798 799
```

### inDevices

inDevices(devices: Array&lt;string&gt;): RdbPredicates

Sets an **RdbPredicates** to specify the remote devices to connect on the network during distributed database synchronization.

A
Annie_wang 已提交
800
> **NOTE**
A
Annie_wang 已提交
801
>
A
Annie_wang 已提交
802 803
> The value of **devices** can be obtained by [deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync).
If **inDevices** is specified in **predicates** when **sync()** is called, data is synchronized with the specified device. If **inDevices** is not specified, data is synchronized with all devices on the network by default.
A
Annie_wang 已提交
804

A
Annie_wang 已提交
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name | Type               | Mandatory| Description                      |
| ------- | ------------------- | ---- | -------------------------- |
| devices | Array&lt;string&gt; | Yes  | IDs of the remote devices in the same network.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
822
import deviceManager from '@ohos.distributedDeviceManager';
A
Annie_wang 已提交
823
let dmInstance = null;
A
Annie_wang 已提交
824
let deviceIds = [];
A
Annie_wang 已提交
825

A
Annie_wang 已提交
826 827 828 829 830 831 832 833 834 835
try {
  dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
  let devices = dmInstance.getAvailableDeviceListSync();
  for (var i = 0; i < devices.length; i++) {
      deviceIds[i] = devices[i].networkId;
  }
} catch (err) {
  console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
}

A
Annie_wang 已提交
836
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
A
Annie_wang 已提交
837
predicates.inDevices(deviceIds);
A
Annie_wang 已提交
838 839 840 841 842 843 844 845 846
```

### inAllDevices

inAllDevices(): RdbPredicates


Sets an **RdbPredicates** to specify all remote devices on the network to connect during distributed database synchronization.

A
Annie_wang 已提交
847

A
Annie_wang 已提交
848 849 850 851 852 853 854 855 856 857 858
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
859 860
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.inAllDevices();
A
Annie_wang 已提交
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
```

### equalTo

equalTo(field: string, value: ValueType): RdbPredicates


Sets an **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                   | Mandatory| Description                  |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | Yes  | Column name in the database table.    |
| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
888 889
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "lisi");
A
Annie_wang 已提交
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
```


### notEqualTo

notEqualTo(field: string, value: ValueType): RdbPredicates


Sets an **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                   | Mandatory| Description                  |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | Yes  | Column name in the database table.    |
| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
918 919
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.notEqualTo("NAME", "lisi");
A
Annie_wang 已提交
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
```


### beginWrap

beginWrap(): RdbPredicates


Adds a left parenthesis to the **RdbPredicates**.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Return value**

| Type                                | Description                     |
| ------------------------------------ | ------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a left parenthesis.|

**Example**

```js
A
Annie_wang 已提交
941
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
A
Annie_wang 已提交
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966
predicates.equalTo("NAME", "lisi")
    .beginWrap()
    .equalTo("AGE", 18)
    .or()
    .equalTo("SALARY", 200.5)
    .endWrap()
```

### endWrap

endWrap(): RdbPredicates

Adds a right parenthesis to the **RdbPredicates**.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Return value**

| Type                                | Description                     |
| ------------------------------------ | ------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with a right parenthesis.|

**Example**

```js
A
Annie_wang 已提交
967
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
A
Annie_wang 已提交
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
predicates.equalTo("NAME", "lisi")
    .beginWrap()
    .equalTo("AGE", 18)
    .or()
    .equalTo("SALARY", 200.5)
    .endWrap()
```

### or

or(): RdbPredicates

Adds the OR condition to the **RdbPredicates**.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Return value**

| Type                                | Description                     |
| ------------------------------------ | ------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the OR condition.|

**Example**

```js
A
Annie_wang 已提交
993
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
A
Annie_wang 已提交
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
predicates.equalTo("NAME", "Lisa")
    .or()
    .equalTo("NAME", "Rose")
```

### and

and(): RdbPredicates

Adds the AND condition to the **RdbPredicates**.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Return value**

| Type                                | Description                     |
| ------------------------------------ | ------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** with the AND condition.|

**Example**

```js
A
Annie_wang 已提交
1016
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
A
Annie_wang 已提交
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
predicates.equalTo("NAME", "Lisa")
    .and()
    .equalTo("SALARY", 200.5)
```

### contains

contains(field: string, value: string): RdbPredicates

Sets an **RdbPredicates** to match a string containing the specified value.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| field  | string | Yes  | Column name in the database table.    |
| value  | string | Yes  | Value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1046 1047
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.contains("NAME", "os");
A
Annie_wang 已提交
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
```

### beginsWith

beginsWith(field: string, value: string): RdbPredicates

Sets an **RdbPredicates** to match a string that starts with the specified value.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| field  | string | Yes  | Column name in the database table.    |
| value  | string | Yes  | Value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1074 1075
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.beginsWith("NAME", "os");
A
Annie_wang 已提交
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
```

### endsWith

endsWith(field: string, value: string): RdbPredicates

Sets an **RdbPredicates** to match a string that ends with the specified value.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| field  | string | Yes  | Column name in the database table.    |
| value  | string | Yes  | Value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1102 1103
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.endsWith("NAME", "se");
A
Annie_wang 已提交
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
```

### isNull

isNull(field: string): RdbPredicates

Sets an **RdbPredicates** to match the field whose value is null.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description              |
| ------ | ------ | ---- | ------------------ |
| field  | string | Yes  | Column name in the database table.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1129 1130
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.isNull("NAME");
A
Annie_wang 已提交
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
```

### isNotNull

isNotNull(field: string): RdbPredicates

Sets an **RdbPredicates** to match the field whose value is not null.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description              |
| ------ | ------ | ---- | ------------------ |
| field  | string | Yes  | Column name in the database table.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1156 1157
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.isNotNull("NAME");
A
Annie_wang 已提交
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
```

### like

like(field: string, value: string): RdbPredicates

Sets an **RdbPredicates** to match a string that is similar to the specified value.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| field  | string | Yes  | Column name in the database table.    |
| value  | string | Yes  | Value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1184 1185
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.like("NAME", "%os%");
A
Annie_wang 已提交
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
```

### glob

glob(field: string, value: string): RdbPredicates

Sets an **RdbPredicates** to match the specified string.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| field  | string | Yes  | Column name in the database table.                                          |
| 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.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1212 1213
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.glob("NAME", "?h*g");
A
Annie_wang 已提交
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
```

### between

between(field: string, low: ValueType, high: ValueType): RdbPredicates

Sets an **RdbPredicates** to match the field with data type **ValueType** and value within the specified range.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                   | Mandatory| Description                      |
| ------ | ----------------------- | ---- | -------------------------- |
| field  | string                  | Yes  | Column name in the database table.        |
| low    | [ValueType](#valuetype) | Yes  | Minimum value to match the **RdbPredicates**.  |
| high   | [ValueType](#valuetype) | Yes  | Maximum value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1241 1242
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.between("AGE", 10, 50);
A
Annie_wang 已提交
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
```

### notBetween

notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates

Sets an **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                   | Mandatory| Description                      |
| ------ | ----------------------- | ---- | -------------------------- |
| field  | string                  | Yes  | Column name in the database table.        |
| low    | [ValueType](#valuetype) | Yes  | Minimum value to match the **RdbPredicates**.  |
| high   | [ValueType](#valuetype) | Yes  | Maximum value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1270 1271
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.notBetween("AGE", 10, 50);
A
Annie_wang 已提交
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
```

### greaterThan

greaterThan(field: string, value: ValueType): RdbPredicates

Sets an **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                   | Mandatory| Description                  |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | Yes  | Column name in the database table.    |
| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1298 1299
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.greaterThan("AGE", 18);
A
Annie_wang 已提交
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
```

### lessThan

lessThan(field: string, value: ValueType): RdbPredicates

Sets an **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                   | Mandatory| Description                  |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | Yes  | Column name in the database table.    |
| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1326 1327
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.lessThan("AGE", 20);
A
Annie_wang 已提交
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353
```

### greaterThanOrEqualTo

greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates

Sets an **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                   | Mandatory| Description                  |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | Yes  | Column name in the database table.    |
| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1354 1355
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.greaterThanOrEqualTo("AGE", 18);
A
Annie_wang 已提交
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
```

### lessThanOrEqualTo

lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates

Sets an **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                   | Mandatory| Description                  |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | Yes  | Column name in the database table.    |
| value  | [ValueType](#valuetype) | Yes  | Value to match the **RdbPredicates**.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1382 1383
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.lessThanOrEqualTo("AGE", 20);
A
Annie_wang 已提交
1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
```

### orderByAsc

orderByAsc(field: string): RdbPredicates

Sets an **RdbPredicates** to match the column with values sorted in ascending order.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description              |
| ------ | ------ | ---- | ------------------ |
| field  | string | Yes  | Column name in the database table.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1409 1410
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.orderByAsc("NAME");
A
Annie_wang 已提交
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
```

### orderByDesc

orderByDesc(field: string): RdbPredicates

Sets an **RdbPredicates** to match the column with values sorted in descending order.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description              |
| ------ | ------ | ---- | ------------------ |
| field  | string | Yes  | Column name in the database table.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1436 1437
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.orderByDesc("AGE");
A
Annie_wang 已提交
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456
```

### distinct

distinct(): RdbPredicates

Sets an **RdbPredicates** to filter out duplicate records.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Return value**

| Type                                | Description                          |
| ------------------------------------ | ------------------------------ |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that can filter out duplicate records.|

**Example**

```js
A
Annie_wang 已提交
1457 1458
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose").distinct();
A
Annie_wang 已提交
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
```

### limitAs

limitAs(value: number): RdbPredicates

Sets an **RdbPredicates** to specify the maximum number of records.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
| value  | number | Yes  | Maximum number of records.|

**Return value**

| Type                                | Description                                |
| ------------------------------------ | ------------------------------------ |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the maximum number of records.|

**Example**

```js
A
Annie_wang 已提交
1484 1485
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose").limitAs(3);
A
Annie_wang 已提交
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
```

### offsetAs

offsetAs(rowOffset: number): RdbPredicates

Sets an **RdbPredicates** to specify the start position of the returned result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name   | Type  | Mandatory| Description                              |
| --------- | ------ | ---- | ---------------------------------- |
| rowOffset | number | Yes  | Number of rows to offset from the beginning. The value is a positive integer.|

**Return value**

| Type                                | Description                                |
| ------------------------------------ | ------------------------------------ |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the start position of the returned result.|

**Example**

```js
A
Annie_wang 已提交
1511 1512
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose").offsetAs(3);
A
Annie_wang 已提交
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
```

### groupBy

groupBy(fields: Array&lt;string&gt;): RdbPredicates

Sets an **RdbPredicates** to group rows that have the same value into summary rows.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type               | Mandatory| Description                |
| ------ | ------------------- | ---- | -------------------- |
| fields | Array&lt;string&gt; | Yes  | Names of columns to group.|

**Return value**

| Type                                | Description                  |
| ------------------------------------ | ---------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that groups rows with the same value.|

**Example**

```js
A
Annie_wang 已提交
1538 1539
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.groupBy(["AGE", "NAME"]);
A
Annie_wang 已提交
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565
```

### indexedBy

indexedBy(field: string): RdbPredicates

Sets an **RdbPredicates** object to specify the index column.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description          |
| ------ | ------ | ---- | -------------- |
| field  | string | Yes  | Name of the index column.|

**Return value**


| Type                                | Description                                 |
| ------------------------------------ | ------------------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object that specifies the index column.|

**Example**

```js
A
Annie_wang 已提交
1566 1567
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.indexedBy("SALARY_INDEX");
A
Annie_wang 已提交
1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593
```

### in

in(field: string, value: Array&lt;ValueType&gt;): RdbPredicates

Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                                | Mandatory| Description                                   |
| ------ | ------------------------------------ | ---- | --------------------------------------- |
| field  | string                               | Yes  | Column name in the database table.                     |
| value  | Array&lt;[ValueType](#valuetype)&gt; | Yes  | Array of **ValueType**s to match.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1594 1595
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.in("AGE", [18, 20]);
A
Annie_wang 已提交
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621
```

### notIn

notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicates

Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                                | Mandatory| Description                                 |
| ------ | ------------------------------------ | ---- | ------------------------------------- |
| field  | string                               | Yes  | Column name in the database table.                   |
| value  | Array&lt;[ValueType](#valuetype)&gt; | Yes  | Array of **ValueType**s to match.|

**Return value**

| Type                                | Description                      |
| ------------------------------------ | -------------------------- |
| [RdbPredicates](#rdbpredicates) | **RdbPredicates** object created.|

**Example**

```js
A
Annie_wang 已提交
1622 1623
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.notIn("NAME", ["Lisa", "Rose"]);
A
Annie_wang 已提交
1624 1625 1626 1627
```

## RdbStore

A
Annie_wang 已提交
1628
Provides APIs to manage an RDB store.
A
Annie_wang 已提交
1629

A
Annie_wang 已提交
1630
Before using the APIs of this class, use [executeSql](#executesql) to initialize the database table structure and related data.
A
Annie_wang 已提交
1631 1632 1633 1634 1635 1636 1637

### Attributes<sup>10+</sup>

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name        | Type           | Mandatory| Description                            |
| ------------ | ----------- | ---- | -------------------------------- |
A
Annie_wang 已提交
1638 1639 1640 1641 1642 1643
| version<sup>10+</sup>  | number | Yes  | RDB store version, which is an integer greater than 0.      |

**Example**

```js
// Set the RDB store version.
A
Annie_wang 已提交
1644
store.version = 3;
A
Annie_wang 已提交
1645
// Obtain the RDB store version.
A
Annie_wang 已提交
1646
console.info(`RdbStore version is ${store.version}`);
A
Annie_wang 已提交
1647
```
A
Annie_wang 已提交
1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664

### insert

insert(table: string, values: ValuesBucket, callback: AsyncCallback&lt;number&gt;):void

Inserts a row of data into a table. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                         | Mandatory| Description                                                      |
| -------- | ----------------------------- | ---- | ---------------------------------------------------------- |
| table    | string                        | Yes  | Name of the target table.                                          |
| values   | [ValuesBucket](#valuesbucket) | Yes  | Row of data to insert.                                |
| 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.|

A
Annie_wang 已提交
1665 1666 1667 1668
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
1669 1670 1671 1672
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
1673

A
Annie_wang 已提交
1674 1675 1676 1677
**Example**

```js
const valueBucket = {
A
Annie_wang 已提交
1678 1679 1680 1681 1682 1683 1684
  "NAME": "Lisa",
  "AGE": 18,
  "SALARY": 100.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
store.insert("EMPLOYEE", valueBucket, function (err, rowId) {
  if (err) {
A
Annie_wang 已提交
1685
    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
1686 1687 1688
    return;
  }
  console.info(`Insert is successful, rowId = ${rowId}`);
A
Annie_wang 已提交
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708
})
```

### insert<sup>10+</sup>

insert(table: string, values: ValuesBucket,  conflict: ConflictResolution, callback: AsyncCallback&lt;number&gt;):void

Inserts a row of data into a table. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                                       | Mandatory| Description                                                      |
| -------- | ------------------------------------------- | ---- | ---------------------------------------------------------- |
| table    | string                                      | Yes  | Name of the target table.                                          |
| values   | [ValuesBucket](#valuesbucket)               | Yes  | Row of data to insert.                                |
| conflict | [ConflictResolution](#conflictresolution10) | Yes  | Resolution used to resolve the conflict.                                        |
| 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.|

A
Annie_wang 已提交
1709 1710 1711 1712
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
1713 1714 1715 1716
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
1717

A
Annie_wang 已提交
1718 1719 1720 1721
**Example**

```js
const valueBucket = {
A
Annie_wang 已提交
1722 1723 1724 1725 1726 1727 1728
  "NAME": "Lisa",
  "AGE": 18,
  "SALARY": 100.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
store.insert("EMPLOYEE", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, function (err, rowId) {
  if (err) {
A
Annie_wang 已提交
1729
    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
1730 1731 1732
    return;
  }
  console.info(`Insert is successful, rowId = ${rowId}`);
A
Annie_wang 已提交
1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
})
```

### insert

insert(table: string, values: ValuesBucket):Promise&lt;number&gt;

Inserts a row of data into a table. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                         | Mandatory| Description                      |
| ------ | ----------------------------- | ---- | -------------------------- |
| table  | string                        | Yes  | Name of the target table.          |
| values | [ValuesBucket](#valuesbucket) | Yes  | Row of data to insert.|

**Return value**

| Type                 | Description                                             |
| --------------------- | ------------------------------------------------- |
| 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.|

A
Annie_wang 已提交
1757 1758 1759 1760
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
1761 1762 1763 1764
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
1765

A
Annie_wang 已提交
1766 1767 1768 1769
**Example**

```js
const valueBucket = {
A
Annie_wang 已提交
1770 1771 1772 1773 1774 1775
  "NAME": "Lisa",
  "AGE": 18,
  "SALARY": 100.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
let promise = store.insert("EMPLOYEE", valueBucket);
A
Annie_wang 已提交
1776
promise.then((rowId) => {
A
Annie_wang 已提交
1777 1778
  console.info(`Insert is successful, rowId = ${rowId}`);
}).catch((err) => {
A
Annie_wang 已提交
1779
  console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804
})
```

### insert<sup>10+</sup>

insert(table: string, values: ValuesBucket,  conflict: ConflictResolution):Promise&lt;number&gt;

Inserts a row of data into a table. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                                       | Mandatory| Description                      |
| -------- | ------------------------------------------- | ---- | -------------------------- |
| table    | string                                      | Yes  | Name of the target table.          |
| values   | [ValuesBucket](#valuesbucket)               | Yes  | Row of data to insert.|
| conflict | [ConflictResolution](#conflictresolution10) | Yes  | Resolution used to resolve the conflict.        |

**Return value**

| Type                 | Description                                             |
| --------------------- | ------------------------------------------------- |
| 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.|

A
Annie_wang 已提交
1805 1806 1807 1808
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
1809 1810 1811 1812
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
1813

A
Annie_wang 已提交
1814 1815 1816 1817
**Example**

```js
const valueBucket = {
A
Annie_wang 已提交
1818 1819 1820 1821 1822 1823
  "NAME": "Lisa",
  "AGE": 18,
  "SALARY": 100.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
let promise = store.insert("EMPLOYEE", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
A
Annie_wang 已提交
1824
promise.then((rowId) => {
A
Annie_wang 已提交
1825 1826
  console.info(`Insert is successful, rowId = ${rowId}`);
}).catch((err) => {
A
Annie_wang 已提交
1827
  console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846
})
```

### batchInsert

batchInsert(table: string, values: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;):void

Batch inserts data into a table. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                                      | Mandatory| Description                                                        |
| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
| table    | string                                     | Yes  | Name of the target table.                                            |
| values   | Array&lt;[ValuesBucket](#valuesbucket)&gt; | Yes  | An array of data to insert.                                |
| 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.|

A
Annie_wang 已提交
1847 1848 1849 1850
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
1851 1852 1853 1854
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
1855

A
Annie_wang 已提交
1856 1857 1858 1859
**Example**

```js
const valueBucket1 = {
A
Annie_wang 已提交
1860 1861 1862 1863 1864
  "NAME": "Lisa",
  "AGE": 18,
  "SALARY": 100.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5])
};
A
Annie_wang 已提交
1865
const valueBucket2 = {
A
Annie_wang 已提交
1866 1867 1868 1869 1870
  "NAME": "Jack",
  "AGE": 19,
  "SALARY": 101.5,
  "CODES": new Uint8Array([6, 7, 8, 9, 10])
};
A
Annie_wang 已提交
1871
const valueBucket3 = {
A
Annie_wang 已提交
1872 1873 1874 1875 1876
  "NAME": "Tom",
  "AGE": 20,
  "SALARY": 102.5,
  "CODES": new Uint8Array([11, 12, 13, 14, 15])
};
A
Annie_wang 已提交
1877 1878

let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
A
Annie_wang 已提交
1879 1880
store.batchInsert("EMPLOYEE", valueBuckets, function(err, insertNum) {
  if (err) {
A
Annie_wang 已提交
1881
    console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
1882 1883 1884
    return;
  }
  console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
A
Annie_wang 已提交
1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908
})
```

### batchInsert

batchInsert(table: string, values: Array&lt;ValuesBucket&gt;):Promise&lt;number&gt;

Batch inserts data into a table. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                                      | Mandatory| Description                        |
| ------ | ------------------------------------------ | ---- | ---------------------------- |
| table  | string                                     | Yes  | Name of the target table.            |
| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | Yes  | An array of data to insert.|

**Return value**

| Type                 | Description                                                       |
| --------------------- | ----------------------------------------------------------- |
| 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.|

A
Annie_wang 已提交
1909 1910 1911 1912
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
1913 1914 1915 1916
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
1917

A
Annie_wang 已提交
1918 1919 1920 1921
**Example**

```js
const valueBucket1 = {
A
Annie_wang 已提交
1922 1923 1924 1925 1926
  "NAME": "Lisa",
  "AGE": 18,
  "SALARY": 100.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5])
};
A
Annie_wang 已提交
1927
const valueBucket2 = {
A
Annie_wang 已提交
1928 1929 1930 1931 1932
  "NAME": "Jack",
  "AGE": 19,
  "SALARY": 101.5,
  "CODES": new Uint8Array([6, 7, 8, 9, 10])
};
A
Annie_wang 已提交
1933
const valueBucket3 = {
A
Annie_wang 已提交
1934 1935 1936 1937 1938
  "NAME": "Tom",
  "AGE": 20,
  "SALARY": 102.5,
  "CODES": new Uint8Array([11, 12, 13, 14, 15])
};
A
Annie_wang 已提交
1939 1940

let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
A
Annie_wang 已提交
1941
let promise = store.batchInsert("EMPLOYEE", valueBuckets);
A
Annie_wang 已提交
1942
promise.then((insertNum) => {
A
Annie_wang 已提交
1943 1944
  console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
}).catch((err) => {
A
Annie_wang 已提交
1945
  console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964
})
```

### update

update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void

Updates data in the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type                                | Mandatory| Description                                                        |
| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| 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.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Update conditions specified by the **RdbPredicates** object.                   |
| callback   | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the number of rows updated.                  |

A
Annie_wang 已提交
1965 1966 1967 1968
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
1969 1970 1971 1972
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
1973

A
Annie_wang 已提交
1974 1975 1976 1977
**Example**

```js
const valueBucket = {
A
Annie_wang 已提交
1978 1979 1980 1981 1982 1983 1984 1985 1986
  "NAME": "Rose",
  "AGE": 22,
  "SALARY": 200.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa");
store.update(valueBucket, predicates, function (err, rows) {
  if (err) {
A
Annie_wang 已提交
1987
    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
1988 1989 1990
    return;
  }
  console.info(`Updated row count: ${rows}`);
A
Annie_wang 已提交
1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
})
```

### update<sup>10+</sup>

update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution, callback: AsyncCallback&lt;number&gt;):void

Updates data in the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type                                       | Mandatory| Description                                                        |
| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| predicates | [RdbPredicates](#rdbpredicates)            | Yes  | Update conditions specified by the **RdbPredicates** object.                     |
| conflict   | [ConflictResolution](#conflictresolution10) | Yes  | Resolution used to resolve the conflict.                                          |
| callback   | AsyncCallback&lt;number&gt;                 | Yes  | Callback invoked to return the number of rows updated.                  |

A
Annie_wang 已提交
2011 2012 2013 2014
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
2015 2016 2017 2018
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
2019

A
Annie_wang 已提交
2020 2021 2022 2023
**Example**

```js
const valueBucket = {
A
Annie_wang 已提交
2024 2025 2026 2027 2028 2029 2030 2031 2032
  "NAME": "Rose",
  "AGE": 22,
  "SALARY": 200.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa");
store.update(valueBucket, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, function (err, rows) {
  if (err) {
A
Annie_wang 已提交
2033
    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2034 2035 2036
    return;
  }
  console.info(`Updated row count: ${rows}`);
A
Annie_wang 已提交
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060
})
```

### update

update(values: ValuesBucket, predicates: RdbPredicates):Promise&lt;number&gt;

Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name      | Type                                | Mandatory| Description                                                        |
| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
| 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.|
| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Update conditions specified by the **RdbPredicates** object.                   |

**Return value**

| Type                 | Description                                     |
| --------------------- | ----------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|

A
Annie_wang 已提交
2061 2062 2063 2064
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
2065 2066 2067 2068
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
2069

A
Annie_wang 已提交
2070 2071 2072 2073
**Example**

```js
const valueBucket = {
A
Annie_wang 已提交
2074 2075 2076 2077 2078 2079 2080 2081
  "NAME": "Rose",
  "AGE": 22,
  "SALARY": 200.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa");
let promise = store.update(valueBucket, predicates);
A
Annie_wang 已提交
2082
promise.then(async (rows) => {
A
Annie_wang 已提交
2083
  console.info(`Updated row count: ${rows}`);
A
Annie_wang 已提交
2084
}).catch((err) => {
A
Annie_wang 已提交
2085
  console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110
})
```

### update<sup>10+</sup>

update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution):Promise&lt;number&gt;

Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type                                       | Mandatory| Description                                                        |
| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| predicates | [RdbPredicates](#rdbpredicates)            | Yes  | Update conditions specified by the **RdbPredicates** object.                     |
| conflict   | [ConflictResolution](#conflictresolution10) | Yes  | Resolution used to resolve the conflict.                                          |

**Return value**

| Type                 | Description                                     |
| --------------------- | ----------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|

A
Annie_wang 已提交
2111 2112 2113 2114
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
2115 2116 2117 2118
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
2119

A
Annie_wang 已提交
2120 2121 2122 2123
**Example**

```js
const valueBucket = {
A
Annie_wang 已提交
2124 2125 2126 2127 2128 2129 2130 2131
  "NAME": "Rose",
  "AGE": 22,
  "SALARY": 200.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa");
let promise = store.update(valueBucket, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
A
Annie_wang 已提交
2132
promise.then(async (rows) => {
A
Annie_wang 已提交
2133
  console.info(`Updated row count: ${rows}`);
A
Annie_wang 已提交
2134
}).catch((err) => {
A
Annie_wang 已提交
2135
  console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146
})
```

### update

update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void

Updates data based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
Annie_wang 已提交
2147 2148
**Model restriction**: This API can be used only in the stage model.

A
Annie_wang 已提交
2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159
**System API**: This is a system API.

**Parameters**

| Name    | Type                                                        | Mandatory| Description                                                        |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| table      | string                                                       | Yes  | Name of the target table.                                            |
| 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.|
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Update conditions specified by the **DataSharePredicates** object.               |
| callback   | AsyncCallback&lt;number&gt;                                  | Yes  | Callback invoked to return the number of rows updated.                  |

A
Annie_wang 已提交
2160 2161 2162 2163
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
2164 2165 2166 2167
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
2168

A
Annie_wang 已提交
2169 2170 2171 2172 2173 2174 2175 2176 2177
**Example**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
const valueBucket = {
    "NAME": "Rose",
    "AGE": 22,
    "SALARY": 200.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
A
Annie_wang 已提交
2178 2179 2180 2181 2182
};
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Lisa");
store.update("EMPLOYEE", valueBucket, predicates, function (err, rows) {
  if (err) {
A
Annie_wang 已提交
2183
    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2184 2185 2186
    return;
  }
  console.info(`Updated row count: ${rows}`);
A
Annie_wang 已提交
2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197
})
```

### update

update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt;

Updates data based on the specified **DataSharePredicates** object. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
Annie_wang 已提交
2198 2199
**Model restriction**: This API can be used only in the stage model.

A
Annie_wang 已提交
2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215
**System API**: This is a system API.

**Parameters**

| Name    | Type                                                        | Mandatory| Description                                                        |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| table      | string                                                       | Yes  | Name of the target table.                                            |
| 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.|
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Update conditions specified by the **DataSharePredicates** object.               |

**Return value**

| Type                 | Description                                     |
| --------------------- | ----------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|

A
Annie_wang 已提交
2216 2217 2218 2219
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
2220 2221 2222 2223
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
2224

A
Annie_wang 已提交
2225 2226 2227 2228 2229
**Example**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
const valueBucket = {
A
Annie_wang 已提交
2230 2231 2232 2233 2234 2235 2236 2237
  "NAME": "Rose",
  "AGE": 22,
  "SALARY": 200.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Lisa");
let promise = store.update("EMPLOYEE", valueBucket, predicates);
A
Annie_wang 已提交
2238
promise.then(async (rows) => {
A
Annie_wang 已提交
2239
  console.info(`Updated row count: ${rows}`);
A
Annie_wang 已提交
2240
}).catch((err) => {
A
Annie_wang 已提交
2241
  console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259
})
```

### delete

delete(predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void

Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type                                | Mandatory| Description                                     |
| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Conditions specified by the **RdbPredicates** object for deleting data.|
| callback   | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the number of rows deleted. |

A
Annie_wang 已提交
2260 2261 2262 2263
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
2264 2265 2266 2267
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
2268

A
Annie_wang 已提交
2269 2270 2271
**Example**

```js
A
Annie_wang 已提交
2272 2273 2274 2275
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa");
store.delete(predicates, function (err, rows) {
  if (err) {
A
Annie_wang 已提交
2276
    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2277 2278 2279
    return;
  }
  console.info(`Delete rows: ${rows}`);
A
Annie_wang 已提交
2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302
})
```

### delete

delete(predicates: RdbPredicates):Promise&lt;number&gt;

Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type                                | Mandatory| Description                                     |
| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Conditions specified by the **RdbPredicates** object for deleting data.|

**Return value**

| Type                 | Description                           |
| --------------------- | ------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of rows deleted.|

A
Annie_wang 已提交
2303 2304 2305 2306
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
2307 2308 2309 2310
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
2311

A
Annie_wang 已提交
2312 2313 2314
**Example**

```js
A
Annie_wang 已提交
2315 2316 2317
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa");
let promise = store.delete(predicates);
A
Annie_wang 已提交
2318
promise.then((rows) => {
A
Annie_wang 已提交
2319
  console.info(`Delete rows: ${rows}`);
A
Annie_wang 已提交
2320
}).catch((err) => {
A
Annie_wang 已提交
2321
  console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332
})
```

### delete

delete(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void

Deletes data from the RDB store based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
Annie_wang 已提交
2333 2334
**Model restriction**: This API can be used only in the stage model.

A
Annie_wang 已提交
2335 2336 2337 2338 2339 2340 2341 2342 2343 2344
**System API**: This is a system API.

**Parameters**

| Name    | Type                                                        | Mandatory| Description                                         |
| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- |
| table      | string                                                       | Yes  | Name of the target table.                             |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Conditions specified by the **DataSharePredicates** object for deleting data.|
| callback   | AsyncCallback&lt;number&gt;                                  | Yes  | Callback invoked to return the number of rows deleted.     |

A
Annie_wang 已提交
2345 2346 2347 2348
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
2349 2350 2351 2352
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
2353

A
Annie_wang 已提交
2354 2355 2356 2357
**Example**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
A
Annie_wang 已提交
2358 2359 2360 2361
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Lisa");
store.delete("EMPLOYEE", predicates, function (err, rows) {
  if (err) {
A
Annie_wang 已提交
2362
    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2363 2364 2365
    return;
  }
  console.info(`Delete rows: ${rows}`);
A
Annie_wang 已提交
2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376
})
```

### delete

delete(table: string, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt;

Deletes data from the RDB store based on the specified **DataSharePredicates** object. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
Annie_wang 已提交
2377 2378
**Model restriction**: This API can be used only in the stage model.

A
Annie_wang 已提交
2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393
**System API**: This is a system API.

**Parameters**

| Name    | Type                                                        | Mandatory| Description                                         |
| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- |
| table      | string                                                       | Yes  | Name of the target table.                             |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Conditions specified by the **DataSharePredicates** object for deleting data.|

**Return value**

| Type                 | Description                           |
| --------------------- | ------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of rows deleted.|

A
Annie_wang 已提交
2394 2395 2396 2397
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
2398 2399 2400 2401
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
2402

A
Annie_wang 已提交
2403 2404 2405 2406
**Example**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
A
Annie_wang 已提交
2407 2408 2409
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Lisa");
let promise = store.delete("EMPLOYEE", predicates);
A
Annie_wang 已提交
2410
promise.then((rows) => {
A
Annie_wang 已提交
2411
  console.info(`Delete rows: ${rows}`);
A
Annie_wang 已提交
2412
}).catch((err) => {
A
Annie_wang 已提交
2413
  console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2414 2415 2416
})
```

G
Gloria 已提交
2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451
### query<sup>10+</sup>

query(predicates: RdbPredicates, callback: AsyncCallback&lt;ResultSet&gt;):void

Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type                                                        | Mandatory| Description                                                       |
| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| predicates | [RdbPredicates](#rdbpredicates)                         | Yes  | Query conditions specified by the **RdbPredicates** object.                  |
| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

**Example**

```js
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose");
store.query(predicates, function (err, resultSet) {
  if (err) {
    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
    return;
  }
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2452
  while (resultSet.goToNextRow()) {
G
Gloria 已提交
2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463
    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
  }
  // Release the dataset memory.
  resultSet.close();
})
```

A
Annie_wang 已提交
2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479
### query

query(predicates: RdbPredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void

Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type                                                        | Mandatory| Description                                                       |
| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| predicates | [RdbPredicates](#rdbpredicates)                         | Yes  | Query conditions specified by the **RdbPredicates** object.                  |
| columns    | Array&lt;string&gt;                                          | Yes  | Columns to query. If this parameter is not specified, the query applies to all columns.           |
| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|

A
Annie_wang 已提交
2480 2481 2482 2483 2484 2485 2486 2487
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
2488 2489 2490
**Example**

```js
A
Annie_wang 已提交
2491 2492 2493 2494
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose");
store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
  if (err) {
A
Annie_wang 已提交
2495
    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2496 2497
    return;
  }
A
Annie_wang 已提交
2498 2499
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2500
  while (resultSet.goToNextRow()) {
A
Annie_wang 已提交
2501 2502 2503 2504 2505 2506 2507 2508
    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
  }
  // Release the dataset memory.
  resultSet.close();
A
Annie_wang 已提交
2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526
})
```

### query

query(predicates: RdbPredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;

Queries data from the RDB store based on specified conditions. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type                                | Mandatory| Description                                            |
| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Query conditions specified by the **RdbPredicates** object.       |
| columns    | Array&lt;string&gt;                  | No  | Columns to query. If this parameter is not specified, the query applies to all columns.|

A
Annie_wang 已提交
2527 2528 2529 2530 2531 2532 2533 2534
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
2535 2536 2537 2538 2539 2540 2541 2542 2543
**Return value**

| Type                                                   | Description                                              |
| ------------------------------------------------------- | -------------------------------------------------- |
| Promise&lt;[ResultSet](#resultset)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|

**Example**

  ```js
A
Annie_wang 已提交
2544 2545 2546
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
A
Annie_wang 已提交
2547
promise.then((resultSet) => {
A
Annie_wang 已提交
2548 2549
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2550
  while (resultSet.goToNextRow()) {
A
Annie_wang 已提交
2551 2552 2553 2554 2555 2556 2557 2558
    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
  }
  // Release the dataset memory.
  resultSet.close();
A
Annie_wang 已提交
2559
}).catch((err) => {
A
Annie_wang 已提交
2560
  console.error(`Query failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2561 2562 2563
})
  ```

G
Gloria 已提交
2564
### query<sup>10+</sup>
A
Annie_wang 已提交
2565

G
Gloria 已提交
2566
query(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;ResultSet&gt;):void
A
Annie_wang 已提交
2567 2568 2569 2570 2571

Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
Annie_wang 已提交
2572 2573
**Model restriction**: This API can be used only in the stage model.

A
Annie_wang 已提交
2574 2575 2576 2577 2578 2579 2580 2581 2582 2583
**System API**: This is a system API.

**Parameters**

| Name    | Type                                                        | Mandatory| Description                                                       |
| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| table      | string                                                       | Yes  | Name of the target table.                                           |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Query conditions specified by the **DataSharePredicates** object.              |
| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|

A
Annie_wang 已提交
2584 2585 2586 2587 2588 2589 2590 2591
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
2592 2593 2594 2595
**Example**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
A
Annie_wang 已提交
2596 2597
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Rose");
G
Gloria 已提交
2598
store.query("EMPLOYEE", predicates, function (err, resultSet) {
A
Annie_wang 已提交
2599
  if (err) {
A
Annie_wang 已提交
2600
    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2601 2602
    return;
  }
A
Annie_wang 已提交
2603 2604
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2605
  while (resultSet.goToNextRow()) {
A
Annie_wang 已提交
2606 2607 2608 2609 2610 2611 2612 2613
    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
  }
  // Release the dataset memory.
  resultSet.close();
A
Annie_wang 已提交
2614 2615 2616 2617 2618
})
```

### query

G
Gloria 已提交
2619
query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
A
Annie_wang 已提交
2620

G
Gloria 已提交
2621
Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
2622 2623 2624

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
Annie_wang 已提交
2625 2626
**Model restriction**: This API can be used only in the stage model.

A
Annie_wang 已提交
2627 2628 2629 2630
**System API**: This is a system API.

**Parameters**

G
Gloria 已提交
2631 2632 2633 2634 2635 2636
| Name    | Type                                                        | Mandatory| Description                                                       |
| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| table      | string                                                       | Yes  | Name of the target table.                                           |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Query conditions specified by the **DataSharePredicates** object.              |
| columns    | Array&lt;string&gt;                                          | Yes  | Columns to query. If this parameter is not specified, the query applies to all columns.           |
| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
A
Annie_wang 已提交
2637

A
Annie_wang 已提交
2638 2639 2640 2641 2642 2643 2644 2645
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
2646 2647 2648 2649
**Example**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
A
Annie_wang 已提交
2650 2651
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Rose");
G
Gloria 已提交
2652 2653 2654 2655 2656
store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
  if (err) {
    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
    return;
  }
A
Annie_wang 已提交
2657 2658
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2659
  while (resultSet.goToNextRow()) {
A
Annie_wang 已提交
2660 2661 2662 2663 2664 2665 2666 2667
    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
  }
  // Release the dataset memory.
  resultSet.close();
A
Annie_wang 已提交
2668 2669 2670
})
```

G
Gloria 已提交
2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714
### query

query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;

Queries data from the RDB store based on specified conditions. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Model restriction**: This API can be used only in the stage model.

**System API**: This is a system API.

**Parameters**

| Name    | Type                                                        | Mandatory| Description                                            |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ |
| table      | string                                                       | Yes  | Name of the target table.                                |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes  | Query conditions specified by the **DataSharePredicates** object.   |
| columns    | Array&lt;string&gt;                                          | No  | Columns to query. If this parameter is not specified, the query applies to all columns.|

**Return value**

| Type                                                   | Description                                              |
| ------------------------------------------------------- | -------------------------------------------------- |
| Promise&lt;[ResultSet](#resultset)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

**Example**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Rose");
let promise = store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2715
  while (resultSet.goToNextRow()) {
G
Gloria 已提交
2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729
    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
  }
  // Release the dataset memory.
  resultSet.close();
}).catch((err) => {
  console.error(`Query failed, code is ${err.code},message is ${err.message}`);
})
```

### remoteQuery
A
Annie_wang 已提交
2730 2731 2732 2733 2734

remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt; , callback: AsyncCallback&lt;ResultSet&gt;): void

Queries data from the RDB store of a remote device based on specified conditions. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
2735
> **NOTE**
A
Annie_wang 已提交
2736
>
A
Annie_wang 已提交
2737
> The value of **device** can be obtained by [deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync).
A
Annie_wang 已提交
2738

A
Annie_wang 已提交
2739 2740 2741 2742
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

A
Annie_wang 已提交
2743 2744 2745 2746 2747 2748
| Name    | Type                                        | Mandatory| Description                                                     |
| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- |
| device     | string                                       | Yes  | ID of the remote device.                                       |
| table      | string                                       | Yes  | Name of the target table.                                         |
| predicates | [RdbPredicates](#rdbpredicates)              | Yes  | Query conditions specified by the **RdbPredicates** object.                |
| columns    | Array&lt;string&gt;                          | Yes  | Columns to query. If this parameter is not specified, the query applies to all columns.         |
A
Annie_wang 已提交
2749 2750
| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|

A
Annie_wang 已提交
2751 2752 2753 2754 2755 2756 2757 2758
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
2759 2760 2761
**Example**

```js
A
Annie_wang 已提交
2762
import deviceManager from '@ohos.distributedDeviceManager';
A
Annie_wang 已提交
2763
let dmInstance = null;
A
Annie_wang 已提交
2764
let deviceId = null;
A
Annie_wang 已提交
2765

A
Annie_wang 已提交
2766 2767 2768 2769 2770 2771 2772
try {
  dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
  let devices = dmInstance.getAvailableDeviceListSync();
  deviceId = devices[0].networkId;
} catch (err) {
  console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
}
A
Annie_wang 已提交
2773

A
Annie_wang 已提交
2774 2775
let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.greaterThan("id", 0);
A
Annie_wang 已提交
2776
store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"],
A
Annie_wang 已提交
2777
  function(err, resultSet) {
A
Annie_wang 已提交
2778
    if (err) {
A
Annie_wang 已提交
2779
      console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2780
      return;
A
Annie_wang 已提交
2781
    }
A
Annie_wang 已提交
2782 2783
    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
    // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2784
    while (resultSet.goToNextRow()) {
A
Annie_wang 已提交
2785 2786 2787 2788 2789 2790 2791 2792
      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
    }
    // Release the dataset memory.
    resultSet.close();
A
Annie_wang 已提交
2793 2794
  }
)
A
Annie_wang 已提交
2795 2796 2797 2798 2799 2800 2801 2802
```

### remoteQuery

remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt;): Promise&lt;ResultSet&gt;

Queries data from the RDB store of a remote device based on specified conditions. This API uses a promise to return the result.

A
Annie_wang 已提交
2803
> **NOTE**
A
Annie_wang 已提交
2804
>
A
Annie_wang 已提交
2805
> The value of **device** can be obtained by [deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync).
A
Annie_wang 已提交
2806

A
Annie_wang 已提交
2807 2808 2809 2810 2811 2812
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type                                | Mandatory| Description                                            |
| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
A
Annie_wang 已提交
2813
| device     | string                               | Yes  | ID of the remote device.                  |
A
Annie_wang 已提交
2814 2815 2816 2817 2818 2819 2820 2821 2822 2823
| table      | string                               | Yes  | Name of the target table.                                |
| predicates | [RdbPredicates](#rdbpredicates) | Yes  | Query conditions specified by the **RdbPredicates** object.     |
| columns    | Array&lt;string&gt;                  | Yes  | Columns to query. If this parameter is not specified, the query applies to all columns.|

**Return value**

| Type                                                        | Description                                              |
| ------------------------------------------------------------ | -------------------------------------------------- |
| Promise&lt;[ResultSet](#resultset)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|

A
Annie_wang 已提交
2824 2825 2826 2827 2828 2829 2830 2831
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
2832 2833 2834
**Example**

```js
A
Annie_wang 已提交
2835
import deviceManager from '@ohos.distributedDeviceManager';
A
Annie_wang 已提交
2836
let dmInstance = null;
A
Annie_wang 已提交
2837
let deviceId = null;
A
Annie_wang 已提交
2838

A
Annie_wang 已提交
2839 2840 2841 2842 2843 2844 2845
try {
  dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
  let devices = dmInstance.getAvailableDeviceListSync();
  deviceId = devices[0].networkId;
} catch (err) {
  console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
}
A
Annie_wang 已提交
2846

A
Annie_wang 已提交
2847 2848
let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.greaterThan("id", 0);
A
Annie_wang 已提交
2849
let promise = store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
A
Annie_wang 已提交
2850
promise.then((resultSet) => {
A
Annie_wang 已提交
2851 2852
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2853
  while (resultSet.goToNextRow()) {
A
Annie_wang 已提交
2854 2855 2856 2857 2858 2859 2860 2861
    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
  }
  // Release the dataset memory.
  resultSet.close();
A
Annie_wang 已提交
2862
}).catch((err) => {
A
Annie_wang 已提交
2863
  console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2864 2865 2866
})
```

G
Gloria 已提交
2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899
### querySql<sup>10+</sup>

querySql(sql: string, callback: AsyncCallback&lt;ResultSet&gt;):void

Queries data using the specified SQL statement. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                                        | Mandatory| Description                                                        |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| sql      | string                                       | Yes  | SQL statement to run.                                       |
| callback | AsyncCallback&lt;[ResultSet](#resultset)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.   |

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

**Example**

```js
store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'", function (err, resultSet) {
  if (err) {
    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
    return;
  }
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2900
  while (resultSet.goToNextRow()) {
G
Gloria 已提交
2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911
    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
  }
  // Release the dataset memory.
  resultSet.close();
})
```

A
Annie_wang 已提交
2912 2913 2914 2915 2916 2917 2918 2919 2920 2921
### querySql

querySql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void

Queries data using the specified SQL statement. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

A
Annie_wang 已提交
2922 2923 2924 2925 2926
| Name  | Type                                        | Mandatory| Description                                                        |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| sql      | string                                       | Yes  | SQL statement to run.                                       |
| 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.|
| callback | AsyncCallback&lt;[ResultSet](#resultset)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.   |
A
Annie_wang 已提交
2927

A
Annie_wang 已提交
2928 2929 2930 2931 2932 2933 2934 2935
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
2936 2937 2938
**Example**

```js
A
Annie_wang 已提交
2939 2940
store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
  if (err) {
A
Annie_wang 已提交
2941
    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
2942 2943
    return;
  }
A
Annie_wang 已提交
2944 2945
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2946
  while (resultSet.goToNextRow()) {
A
Annie_wang 已提交
2947 2948 2949 2950 2951 2952 2953 2954
    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
  }
  // Release the dataset memory.
  resultSet.close();
A
Annie_wang 已提交
2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967
})
```

### querySql

querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt;

Queries data using the specified SQL statement. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

A
Annie_wang 已提交
2968 2969 2970 2971
| Name  | Type                                | Mandatory| Description                                                        |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| sql      | string                               | Yes  | SQL statement to run.                                       |
| 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.|
A
Annie_wang 已提交
2972 2973 2974 2975 2976 2977 2978

**Return value**

| Type                                                   | Description                                              |
| ------------------------------------------------------- | -------------------------------------------------- |
| Promise&lt;[ResultSet](#resultset)&gt; | Promise used to return the result. If the operation is successful, a **ResultSet** object will be returned.|

A
Annie_wang 已提交
2979 2980 2981 2982 2983 2984 2985 2986
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
2987 2988 2989
**Example**

```js
A
Annie_wang 已提交
2990
let promise = store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'");
A
Annie_wang 已提交
2991
promise.then((resultSet) => {
A
Annie_wang 已提交
2992 2993
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet is a cursor of a data set. By default, the cursor points to the -1st record. Valid data starts from 0.
2994
  while (resultSet.goToNextRow()) {
A
Annie_wang 已提交
2995 2996 2997 2998 2999 3000 3001 3002
    const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
    const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
    const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
    const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
    console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
  }
  // Release the dataset memory.
  resultSet.close();
A
Annie_wang 已提交
3003
}).catch((err) => {
A
Annie_wang 已提交
3004
  console.error(`Query failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3005 3006 3007
})
```

G
Gloria 已提交
3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044
### executeSql<sup>10+</sup>

executeSql(sql: string, callback: AsyncCallback&lt;void&gt;):void

Executes an SQL statement that contains specified arguments but returns no value. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                                | Mandatory| Description                                                        |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| sql      | string                               | Yes  | SQL statement to run.                                       |
| callback | AsyncCallback&lt;void&gt;            | Yes  | Callback invoked to return the result.                                      |

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |

**Example**

```js
const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"
store.executeSql(SQL_DELETE_TABLE, function(err) {
  if (err) {
    console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
    return;
  }
  console.info(`Delete table done.`);
})
```

A
Annie_wang 已提交
3045 3046 3047 3048 3049 3050 3051 3052 3053 3054
### executeSql

executeSql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;void&gt;):void

Executes an SQL statement that contains specified arguments but returns no value. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

A
Annie_wang 已提交
3055 3056 3057 3058 3059 3060 3061 3062 3063 3064
| Name  | Type                                | Mandatory| Description                                                        |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| sql      | string                               | Yes  | SQL statement to run.                                       |
| 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.|
| callback | AsyncCallback&lt;void&gt;            | Yes  | Callback invoked to return the result.                                      |

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
3065 3066 3067 3068
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
3069 3070 3071 3072

**Example**

```js
A
Annie_wang 已提交
3073 3074
const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?"
store.executeSql(SQL_DELETE_TABLE, ['zhangsan'], function(err) {
A
Annie_wang 已提交
3075
  if (err) {
A
Annie_wang 已提交
3076
    console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3077 3078
    return;
  }
A
Annie_wang 已提交
3079
  console.info(`Delete table done.`);
A
Annie_wang 已提交
3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092
})
```

### executeSql

executeSql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;void&gt;

Executes an SQL statement that contains specified arguments but returns no value. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

A
Annie_wang 已提交
3093 3094 3095 3096
| Name  | Type                                | Mandatory| Description                                                        |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| sql      | string                               | Yes  | SQL statement to run.                                       |
| 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.|
A
Annie_wang 已提交
3097 3098 3099 3100 3101 3102 3103

**Return value**

| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

A
Annie_wang 已提交
3104 3105 3106 3107
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
3108 3109 3110 3111
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
3112

A
Annie_wang 已提交
3113 3114 3115
**Example**

```js
A
Annie_wang 已提交
3116 3117
const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"
let promise = store.executeSql(SQL_DELETE_TABLE);
A
Annie_wang 已提交
3118
promise.then(() => {
A
Annie_wang 已提交
3119
    console.info(`Delete table done.`);
A
Annie_wang 已提交
3120
}).catch((err) => {
A
Annie_wang 已提交
3121
    console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3122 3123 3124
})
```

G
Gloria 已提交
3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203
### getModifyTime<sup>10+</sup>

getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[], callback: AsyncCallback&lt;ModifyTime&gt;): void

Obtains the last modification time of the data in a table. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name     | Type                                            | Mandatory| Description                                                        |
| ----------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| table       | string                                           | Yes  | Name of the database table to query.                                |
| columnName  | string                                           | Yes  | Column name of the database table to query.                                |
| primaryKeys | [PRIKeyType](#prikeytype10)[]                    | Yes  | Primary keys of the rows to query.<br>If the database table has no primary key, **rowid** must be passed in through **columnName**. In this case, **primaryKeys** specifies the row numbers of the database table to query.<br>If the database table has no primary key and no **rowid** is passed in through **columnName**, an error code will be returned.|
| callback    | AsyncCallback&lt;[ModifyTime](#modifytime10)&gt; | Yes  | Callback invoked to return the result. If the operation is successful, the **ModifyTime** object is returned.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**|
| ------------ | ------------ |
| 14800000     | Inner error. |

**Example**

```js
let PRIKey = [1, 4, 2, 3];
store.getModifyTime("cloud_tasks", "uuid", PRIKey, function (err, modifyTime) {
    if (err) {
        console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`);
        return;
    }
    let size = modifyTime.size();
});
```

### getModifyTime<sup>10+</sup>

getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[]): Promise&lt;ModifyTime&gt;

Obtains the last modification time of the data in a table. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name     | Type                         | Mandatory| Description                                                        |
| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ |
| table       | string                        | Yes  | Name of the database table to query.                                |
| columnName  | string                        | Yes  | Column name of the database table to query.                                |
| primaryKeys | [PRIKeyType](#prikeytype10)[] | Yes  | Primary keys of the rows to query.<br>If the database table has no primary key, **rowid** must be passed in through **columnName**. In this case, **primaryKeys** specifies the row numbers of the database table to query.<br>If the database table has no primary key and no **rowid** is passed in through **columnName**, an error code will be returned.|

**Return value**

| Type                                      | Description                                                     |
| ------------------------------------------ | --------------------------------------------------------- |
| Promise&lt;[ModifyTime](#modifytime10)&gt; | Promise used to return the **ModifyTime** object.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**|
| ------------ | ------------ |
| 14800000     | Inner error. |

**Example**

```js
let PRIKey = [1, 2, 3];
store.getModifyTime("cloud_tasks", "uuid", PRIKey).then((modifyTime) => {
    let size = modifyTime.size();
}).catch((err) => {
    console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`);
});
```

A
Annie_wang 已提交
3204 3205 3206 3207 3208 3209 3210 3211
### beginTransaction

beginTransaction():void

Starts the transaction before executing an SQL statement.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

A
Annie_wang 已提交
3212 3213 3214 3215
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
3216 3217 3218 3219
| **ID**| **Error Message**                                |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
A
Annie_wang 已提交
3220

A
Annie_wang 已提交
3221 3222 3223 3224
**Example**

```js
import featureAbility from '@ohos.ability.featureAbility'
A
Annie_wang 已提交
3225 3226 3227 3228 3229 3230 3231
let context = featureAbility.getContext();
const STORE_CONFIG = { 
  name: "RdbTest.db",
  securityLevel: relationalStore.SecurityLevel.S1
};
relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
  if (err) {
A
Annie_wang 已提交
3232
    console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243
    return;
  }
  store.beginTransaction();
  const valueBucket = {
    "name": "lisi",
	"age": 18,
	"salary": 100.5,
	"blobType": new Uint8Array([1, 2, 3]),
  };
  await store.insert("test", valueBucket);
  store.commit();
A
Annie_wang 已提交
3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258
})
```

### commit

commit():void

Commits the executed SQL statements.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility'
A
Annie_wang 已提交
3259 3260 3261 3262 3263 3264 3265
let context = featureAbility.getContext();
const STORE_CONFIG = { 
  name: "RdbTest.db",
  securityLevel: relationalStore.SecurityLevel.S1
};
relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
  if (err) {
A
Annie_wang 已提交
3266
     console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277
     return;
  }
  store.beginTransaction();
  const valueBucket = {
	"name": "lisi",
	"age": 18,
	"salary": 100.5,
	"blobType": new Uint8Array([1, 2, 3]),
  };
  await store.insert("test", valueBucket);
  store.commit();
A
Annie_wang 已提交
3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292
})
```

### rollBack

rollBack():void

Rolls back the SQL statements that have been executed.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility'
A
Annie_wang 已提交
3293 3294 3295 3296 3297 3298 3299
let context = featureAbility.getContext();
const STORE_CONFIG = { 
  name: "RdbTest.db",
  securityLevel: relationalStore.SecurityLevel.S1
};
relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
  if (err) {
A
Annie_wang 已提交
3300
    console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314
    return;
  }
  try {
    store.beginTransaction()
    const valueBucket = {
	  "id": 1,
	  "name": "lisi",
	  "age": 18,
	  "salary": 100.5,
	  "blobType": new Uint8Array([1, 2, 3]),
	};
	await store.insert("test", valueBucket);
    store.commit();
  } catch (err) {
A
Annie_wang 已提交
3315
    console.error(`Transaction failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3316 3317
    store.rollBack();
  }
A
Annie_wang 已提交
3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335
})
```

### backup

backup(destName:string, callback: AsyncCallback&lt;void&gt;):void

Backs up an RDB store. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                     | Mandatory| Description                    |
| -------- | ------------------------- | ---- | ------------------------ |
| destName | string                    | Yes  | Name of the RDB store backup file.|
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result.  |

A
Annie_wang 已提交
3336 3337 3338 3339 3340 3341 3342 3343
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
3344 3345 3346
**Example**

```js
A
Annie_wang 已提交
3347 3348
store.backup("dbBackup.db", function(err) {
  if (err) {
A
Annie_wang 已提交
3349
    console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3350 3351 3352
    return;
  }
  console.info(`Backup success.`);
A
Annie_wang 已提交
3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375
})
```

### backup

backup(destName:string): Promise&lt;void&gt;

Backs up an RDB store. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type  | Mandatory| Description                    |
| -------- | ------ | ---- | ------------------------ |
| destName | string | Yes  | Name of the RDB store backup file.|

**Return value**

| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

A
Annie_wang 已提交
3376 3377 3378 3379 3380 3381 3382 3383
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
3384 3385 3386
**Example**

```js
A
Annie_wang 已提交
3387
let promiseBackup = store.backup("dbBackup.db");
A
Annie_wang 已提交
3388
promiseBackup.then(()=>{
A
Annie_wang 已提交
3389
  console.info(`Backup success.`);
A
Annie_wang 已提交
3390
}).catch((err)=>{
A
Annie_wang 已提交
3391
  console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409
})
```

### restore

restore(srcName:string, callback: AsyncCallback&lt;void&gt;):void

Restores an RDB store from a backup file. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                     | Mandatory| Description                    |
| -------- | ------------------------- | ---- | ------------------------ |
| srcName  | string                    | Yes  | Name of the RDB store backup file.|
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result.  |

A
Annie_wang 已提交
3410 3411 3412 3413 3414 3415 3416 3417
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
3418 3419 3420
**Example**

```js
A
Annie_wang 已提交
3421 3422
store.restore("dbBackup.db", function(err) {
  if (err) {
A
Annie_wang 已提交
3423
    console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3424 3425 3426
    return;
  }
  console.info(`Restore success.`);
A
Annie_wang 已提交
3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449
})
```

### restore

restore(srcName:string): Promise&lt;void&gt;

Restores an RDB store from a backup file. This API uses a promise to return the result.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name | Type  | Mandatory| Description                    |
| ------- | ------ | ---- | ------------------------ |
| srcName | string | Yes  | Name of the RDB store backup file.|

**Return value**

| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

A
Annie_wang 已提交
3450 3451 3452 3453 3454 3455 3456 3457
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
3458 3459 3460
**Example**

```js
A
Annie_wang 已提交
3461
let promiseRestore = store.restore("dbBackup.db");
A
Annie_wang 已提交
3462
promiseRestore.then(()=>{
A
Annie_wang 已提交
3463
  console.info(`Restore success.`);
A
Annie_wang 已提交
3464
}).catch((err)=>{
A
Annie_wang 已提交
3465
  console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485
})
```

### setDistributedTables

setDistributedTables(tables: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void

Sets distributed tables. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                     | Mandatory| Description                  |
| -------- | ------------------------- | ---- | ---------------------- |
| tables   | Array&lt;string&gt;       | Yes  | Names of the distributed tables to set.|
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result.|

A
Annie_wang 已提交
3486 3487 3488 3489 3490 3491 3492 3493
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
3494 3495 3496
**Example**

```js
A
Annie_wang 已提交
3497 3498
store.setDistributedTables(["EMPLOYEE"], function (err) {
  if (err) {
A
Annie_wang 已提交
3499
    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3500 3501 3502
    return;
  }
  console.info(`SetDistributedTables successfully.`);
A
Annie_wang 已提交
3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517
})
```

### setDistributedTables

 setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt;

Sets distributed tables. This API uses a promise to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

A
Annie_wang 已提交
3518 3519 3520
| Name| Type                    | Mandatory| Description                    |
| ------ | ------------------------ | ---- | ------------------------ |
| tables | ArrayArray&lt;string&gt; | Yes  | Names of the distributed tables to set.|
A
Annie_wang 已提交
3521 3522 3523 3524 3525 3526 3527

**Return value**

| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

A
Annie_wang 已提交
3528 3529 3530 3531
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

A
Annie_wang 已提交
3532 3533 3534
| **ID**| **Error Message**|
| ------------ | ------------ |
| 14800000     | Inner error. |
A
Annie_wang 已提交
3535

A
Annie_wang 已提交
3536 3537 3538
**Example**

```js
A
Annie_wang 已提交
3539
let promise = store.setDistributedTables(["EMPLOYEE"]);
A
Annie_wang 已提交
3540
promise.then(() => {
A
Annie_wang 已提交
3541
  console.info(`SetDistributedTables successfully.`);
A
Annie_wang 已提交
3542
}).catch((err) => {
A
Annie_wang 已提交
3543
  console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3544 3545 3546
})
```

A
Annie_wang 已提交
3547 3548
### setDistributedTables<sup>10+</sup>

3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585
setDistributedTables(tables: Array&lt;string&gt;, type: DistributedType, callback: AsyncCallback&lt;void&gt;): void

Sets distributed tables. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                                 | Mandatory| Description                        |
| -------- | ------------------------------------- | ---- | ---------------------------- |
| tables   | Array&lt;string&gt;                   | Yes  | Names of the distributed tables to set.|
| type     | [DistributedType](#distributedtype10) | Yes  | Distributed type of the tables.            |
| callback | AsyncCallback&lt;void&gt;             | Yes  | Callback invoked to return the result.      |

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**|
| ------------ | ------------ |
| 14800000     | Inner error. |
| 14800051     |The type of the distributed table does not match.|

**Example**

```js
store.setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, function (err) {
  if (err) {
    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
    return;
  }
  console.info(`SetDistributedTables successfully.`);
})
```

A
Annie_wang 已提交
3586 3587


3588 3589 3590
### setDistributedTables<sup>10+</sup>

setDistributedTables(tables: Array&lt;string&gt;, type: DistributedType, config: DistributedConfig, callback: AsyncCallback&lt;void&gt;): void
A
Annie_wang 已提交
3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602

Sets distributed tables. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name     | Type                                 | Mandatory | Description             |
| -------- | ----------------------------------- | --- | --------------- |
| tables   | Array&lt;string&gt;                 | Yes  | Names of the distributed tables to set.    |
3603
| type     | [DistributedType](#distributedtype10) | Yes  | Distributed type of the tables.|
A
Annie_wang 已提交
3604 3605 3606
| config | [DistributedConfig](#distributedconfig10) | Yes| Configuration of the distributed mode.|
| callback | AsyncCallback&lt;void&gt;           | Yes  | Callback invoked to return the result.|

3607 3608 3609 3610 3611 3612 3613 3614 3615
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                     |
| ------------ | ------------------------------------------------- |
| 14800000     | Inner error.                                      |
| 14800051     | The type of the distributed table does not match. |

A
Annie_wang 已提交
3616 3617 3618
**Example**

```js
3619 3620 3621
store.setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, {
  autoSync: true
}, function (err) {
A
Annie_wang 已提交
3622 3623 3624 3625 3626 3627 3628 3629 3630 3631
  if (err) {
    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
    return;
  }
  console.info(`SetDistributedTables successfully.`);
})
```

### setDistributedTables<sup>10+</sup>

3632
 setDistributedTables(tables: Array&lt;string>, type?: DistributedType, config?: DistributedConfig): Promise&lt;void>
A
Annie_wang 已提交
3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643

Sets distributed tables. This API uses a promise to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type                                     | Mandatory| Description                                                        |
| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ |
3644 3645
| tables | Array&lt;string&gt;                       | Yes  | Names of the distributed tables to set.                                |
| type   | [DistributedType](#distributedtype10)     | No  | Distributed type of the tables. The default value is **relationalStore.DistributedType.DISTRIBUTED_DEVICE**.|
A
Annie_wang 已提交
3646 3647 3648 3649 3650 3651 3652 3653
| config | [DistributedConfig](#distributedconfig10) | No  | Configuration of the distributed mode. If this parameter is not specified, the value of **autoSync** is **false** by default, which means only manual synchronization is supported.|

**Return value**

| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|

3654 3655 3656 3657 3658 3659 3660 3661 3662
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                     |
| ------------ | ------------------------------------------------- |
| 14800000     | Inner error.                                      |
| 14800051     | The type of the distributed table does not match. |

A
Annie_wang 已提交
3663 3664 3665
**Example**

```js
3666 3667 3668
let promise = store.setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, {
  autoSync: true
});
A
Annie_wang 已提交
3669 3670 3671 3672 3673 3674 3675
promise.then(() => {
  console.info(`SetDistributedTables successfully.`);
}).catch((err) => {
  console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
})
```

A
Annie_wang 已提交
3676 3677 3678 3679
### obtainDistributedTableName

obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void

A
Annie_wang 已提交
3680
Obtains 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.
A
Annie_wang 已提交
3681

A
Annie_wang 已提交
3682
> **NOTE**
A
Annie_wang 已提交
3683
>
A
Annie_wang 已提交
3684
> The value of **device** can be obtained by [deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync).
A
Annie_wang 已提交
3685 3686 3687 3688 3689 3690 3691 3692 3693

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                       | Mandatory| Description                                                        |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
A
Annie_wang 已提交
3694 3695
| device   | string                      | Yes  | ID of the remote device.                                               |
| table    | string                      | Yes  | Local table name of the remote device.                                        |
A
Annie_wang 已提交
3696 3697
| 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.|

A
Annie_wang 已提交
3698 3699 3700 3701 3702 3703 3704 3705
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
3706 3707 3708
**Example**

```js
A
Annie_wang 已提交
3709
import deviceManager from '@ohos.distributedDeviceManager';
A
Annie_wang 已提交
3710
let dmInstance = null;
A
Annie_wang 已提交
3711
let deviceId = null;
A
Annie_wang 已提交
3712

A
Annie_wang 已提交
3713 3714 3715 3716 3717 3718 3719
try {
  dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
  let devices = dmInstance.getAvailableDeviceListSync();
  deviceId = devices[0].networkId;
} catch (err) {
  console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
}
A
Annie_wang 已提交
3720 3721

store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) {
A
Annie_wang 已提交
3722
    if (err) {
A
Annie_wang 已提交
3723
        console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3724
        return;
A
Annie_wang 已提交
3725
    }
A
Annie_wang 已提交
3726
    console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
A
Annie_wang 已提交
3727 3728 3729 3730 3731 3732 3733
})
```

### obtainDistributedTableName

 obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt;

A
Annie_wang 已提交
3734
Obtains 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.
A
Annie_wang 已提交
3735

A
Annie_wang 已提交
3736
> **NOTE**
A
Annie_wang 已提交
3737
>
A
Annie_wang 已提交
3738
> The value of **device** can be obtained by [deviceManager.getAvailableDeviceListSync](js-apis-distributedDeviceManager.md#getavailabledevicelistsync).
A
Annie_wang 已提交
3739 3740 3741 3742 3743 3744 3745

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

A
Annie_wang 已提交
3746 3747 3748 3749
| Name| Type  | Mandatory| Description                |
| ------ | ------ | ---- | -------------------- |
| device | string | Yes  | ID of the remote device.        |
| table  | string | Yes  | Local table name of the remote device.|
A
Annie_wang 已提交
3750 3751 3752 3753 3754 3755 3756

**Return value**

| Type                 | Description                                                 |
| --------------------- | ----------------------------------------------------- |
| Promise&lt;string&gt; | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.|

A
Annie_wang 已提交
3757 3758 3759 3760 3761 3762 3763 3764
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
3765 3766 3767
**Example**

```js
A
Annie_wang 已提交
3768
import deviceManager from '@ohos.distributedDeviceManager';
A
Annie_wang 已提交
3769
let dmInstance = null;
A
Annie_wang 已提交
3770
let deviceId = null;
A
Annie_wang 已提交
3771

A
Annie_wang 已提交
3772 3773 3774 3775 3776 3777 3778
try {
  dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
  let devices = dmInstance.getAvailableDeviceListSync();
  deviceId = devices[0].networkId;
} catch (err) {
  console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
}
A
Annie_wang 已提交
3779 3780

let promise = store.obtainDistributedTableName(deviceId, "EMPLOYEE");
A
Annie_wang 已提交
3781
promise.then((tableName) => {
A
Annie_wang 已提交
3782
  console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
A
Annie_wang 已提交
3783
}).catch((err) => {
A
Annie_wang 已提交
3784
  console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801
})
```

### sync

sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback&lt;Array&lt;[string, number]&gt;&gt;): void

Synchronizes data between devices. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type                                              | Mandatory| Description                                                        |
| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
A
Annie_wang 已提交
3802
| mode       | [SyncMode](#syncmode)                             | Yes  | Data synchronization mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**.                              |
A
Annie_wang 已提交
3803 3804 3805
| predicates | [RdbPredicates](#rdbpredicates)               | Yes  | **RdbPredicates** object that specifies the data and devices to synchronize.                                        |
| 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. |

A
Annie_wang 已提交
3806 3807 3808 3809 3810 3811 3812 3813
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
3814 3815 3816
**Example**

```js
A
Annie_wang 已提交
3817
import deviceManager from '@ohos.distributedDeviceManager';
A
Annie_wang 已提交
3818
let dmInstance = null;
A
Annie_wang 已提交
3819
let deviceIds = [];
A
Annie_wang 已提交
3820

A
Annie_wang 已提交
3821 3822 3823 3824 3825 3826 3827 3828 3829
try {
  dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
  let devices = dmInstance.getAvailableDeviceListSync();
  for (var i = 0; i < devices.length; i++) {
      deviceIds[i] = devices[i].networkId;
  }
} catch (err) {
  console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
}
A
Annie_wang 已提交
3830

A
Annie_wang 已提交
3831
let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
A
Annie_wang 已提交
3832
predicates.inDevices(deviceIds);
A
Annie_wang 已提交
3833 3834
store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
  if (err) {
A
Annie_wang 已提交
3835
    console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3836 3837 3838 3839 3840 3841
    return;
  }
  console.info(`Sync done.`);
  for (let i = 0; i < result.length; i++) {
    console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
  }
A
Annie_wang 已提交
3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858
})
```

### sync

 sync(mode: SyncMode, predicates: RdbPredicates): Promise&lt;Array&lt;[string, number]&gt;&gt;

Synchronizes data between devices. This API uses a promise to return the result.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type                                | Mandatory| Description                          |
| ---------- | ------------------------------------ | ---- | ------------------------------ |
A
Annie_wang 已提交
3859
| mode       | [SyncMode](#syncmode)               | Yes  | Data synchronization mode. The value can be **relationalStore.SyncMode.SYNC_MODE_PUSH** or **relationalStore.SyncMode.SYNC_MODE_PULL**.|
A
Annie_wang 已提交
3860 3861 3862 3863 3864 3865 3866 3867
| predicates | [RdbPredicates](#rdbpredicates) | Yes  | **RdbPredicates** object that specifies the data and devices to synchronize.          |

**Return value**

| Type                                        | Description                                                        |
| -------------------------------------------- | ------------------------------------------------------------ |
| 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. |

A
Annie_wang 已提交
3868 3869 3870 3871 3872 3873 3874 3875
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

A
Annie_wang 已提交
3876 3877 3878
**Example**

```js
A
Annie_wang 已提交
3879
import deviceManager from '@ohos.distributedDeviceManager';
A
Annie_wang 已提交
3880
let dmInstance = null;
A
Annie_wang 已提交
3881
let deviceIds = [];
A
Annie_wang 已提交
3882

A
Annie_wang 已提交
3883 3884 3885 3886 3887 3888 3889 3890 3891
try {
  dmInstance = deviceManager.createDeviceManager("com.example.appdatamgrverify");
  let devices = dmInstance.getAvailableDeviceListSync();
  for (var i = 0; i < devices.length; i++) {
      deviceIds[i] = devices[i].networkId;
  }
} catch (err) {
  console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
}
A
Annie_wang 已提交
3892

A
Annie_wang 已提交
3893
let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
A
Annie_wang 已提交
3894
predicates.inDevices(deviceIds);
A
Annie_wang 已提交
3895
let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates);
A
Annie_wang 已提交
3896
promise.then((result) =>{
A
Annie_wang 已提交
3897
  console.info(`Sync done.`);
A
Annie_wang 已提交
3898
  for (let i = 0; i < result.length; i++) {
A
Annie_wang 已提交
3899 3900
    console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
  }
A
Annie_wang 已提交
3901
}).catch((err) => {
A
Annie_wang 已提交
3902
  console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
3903 3904 3905
})
```

G
Gloria 已提交
3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926
### cloudSync<sup>10+</sup>

cloudSync(mode: SyncMode, progress: Callback&lt;ProgressDetails&gt;, callback: AsyncCallback&lt;void&gt;): void

Manually starts device-cloud synchronization for all distributed tables. This API uses an asynchronous callback to return the result. Before using this API, ensure that the cloud service must be available.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client

**Parameters**

| Name  | Type                                                 | Mandatory| Description                                              |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
| mode     | [SyncMode](#syncmode)                                 | Yes  | Synchronization mode of the database.                            |
| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | Yes  | Callback used to process database synchronization details.            |
| callback | AsyncCallback&lt;void&gt;                             | Yes  | Callback invoked to send the synchronization result to the caller.|

**Example**

```js
3927
store.cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, function (progressDetails) {
G
Gloria 已提交
3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967
    console.info(`Progess: ${progressDetails}`);
}, function (err) {
     if (err) {
         console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`);
         return;
     }
     console.info('Cloud sync succeeded');
});
```

### cloudSync<sup>10+</sup>

cloudSync(mode: SyncMode, progress: Callback&lt;ProgressDetails&gt;): Promise&lt;void&gt;

Manually starts device-cloud synchronization for all distributed tables. This API uses a promise to return the result. Before using this API, ensure that the cloud service must be available.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client

**Parameters**

| Name  | Type                                                 | Mandatory| Description                                  |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| mode     | [SyncMode](#syncmode)                                 | Yes  | Synchronization mode of the database.                |
| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | Yes  | Callback used to process database synchronization details.|

**Return value**

| Type               | Description                                   |
| ------------------- | --------------------------------------- |
| Promise&lt;void&gt; | Promise used to send the synchronization result.|

**Example**

```js
function progress(progressDetail) {
    console.info(`progress: ${progressDetail}`);
}

3968
store.cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, progress).then(() => {
G
Gloria 已提交
3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997
    console.info('Cloud sync succeeded');
}).catch((err) => {
    console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`);
});
```

### cloudSync<sup>10+</sup>

cloudSync(mode: SyncMode, tables: string[], progress: Callback&lt;ProgressDetails&gt;, callback: AsyncCallback&lt;void&gt;): void

Manually starts device-cloud synchronization of the specified table. This API uses an asynchronous callback to return the result. Before using this API, ensure that the cloud service must be available.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client

**Parameters**

| Name  | Type                                                 | Mandatory| Description                                              |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
| mode     | [SyncMode](#syncmode)                                 | Yes  | Synchronization mode of the database.                            |
| tables   | string[]                                              | Yes  | Name of the table to synchronize.                                  |
| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | Yes  | Callback used to process database synchronization details.            |
| callback | AsyncCallback&lt;void&gt;                             | Yes  | Callback invoked to send the synchronization result to the caller.|

**Example**

```js
const tables = ["table1", "table2"];
3998
store.cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, function (progressDetails) {
G
Gloria 已提交
3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040
    console.info(`Progess: ${progressDetails}`);
}, function (err) {
     if (err) {
         console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`);
         return;
     }
     console.info('Cloud sync succeeded');
});
```

### cloudSync<sup>10+</sup>

cloudSync(mode: SyncMode, tables: string[], progress: Callback&lt;ProgressDetails&gt;): Promise&lt;void&gt;

Manually starts device-cloud synchronization of the specified table. This API uses a promise to return the result. Before using this API, ensure that the cloud service must be available.

**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC

**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client

**Parameters**

| Name  | Type                                                 | Mandatory| Description                                  |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| mode     | [SyncMode](#syncmode)                                 | Yes  | Synchronization mode of the database.                |
| tables   | string[]                                              | Yes  | Name of the table to synchronize.                      |
| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | Yes  | Callback used to process database synchronization details.|

**Return value**

| Type               | Description                                   |
| ------------------- | --------------------------------------- |
| Promise&lt;void&gt; | Promise used to send the synchronization result.|

**Example**

```js
const tables = ["table1", "table2"];
function progress(progressDetail) {
    console.info(`progress: ${progressDetail}`);
}

4041
store.cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, progress).then(() => {
G
Gloria 已提交
4042 4043 4044 4045 4046 4047
    console.info('Cloud sync succeeded');
}).catch((err) => {
    console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`);
});
```

A
Annie_wang 已提交
4048 4049 4050 4051
### on('dataChange')

on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void

G
Gloria 已提交
4052
Registers a data change event listener for the RDB store. When the data in the RDB store changes, a callback is invoked to return the data changes.
A
Annie_wang 已提交
4053 4054 4055 4056 4057 4058 4059 4060

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| event    | string                                                       | Yes  | Event to observe. The value is **dataChange**, which indicates a data change event.                          |
G
Gloria 已提交
4061
| type     | [SubscribeType](#subscribetype) | Yes  | Subscription type to register.                                                  |
A
Annie_wang 已提交
4062 4063 4064 4065
| observer | Callback&lt;Array&lt;string&gt;&gt;                          | Yes  | Callback invoked to return the data change. **Array<string>** indicates the IDs of the peer devices whose data in the database is changed.|

**Example**

G
Gloria 已提交
4066
```js
A
Annie_wang 已提交
4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082
function storeObserver(devices) {
  for (let i = 0; i < devices.length; i++) {
    console.info(`device= ${devices[i]} data changed`);
  }
}
try {
  store.on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
} catch (err) {
  console.error(`Register observer failed, code is ${err.code},message is ${err.message}`);
}
```

### on('dataChange')<sup>10+</sup>

on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;ChangeInfo&gt;&gt;): void

G
Gloria 已提交
4083
Registers a data change event listener for the RDB store. When the data in the RDB store changes, a callback is invoked to return the data changes.
A
Annie_wang 已提交
4084 4085 4086 4087 4088 4089 4090

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                               | Mandatory| Description                                       |
| -------- | ----------------------------------- | ---- | ------------------------------------------- |
A
Annie_wang 已提交
4091
| event    | string                              | Yes  | Event to observe. The value is **dataChange**, which indicates a data change event.         |
A
Annie_wang 已提交
4092
| type     | [SubscribeType](#subscribetype)    | Yes  | Subscription type to register.|
G
Gloria 已提交
4093
| observer | Callback&lt;Array&lt;string&gt;&gt; \| Callback&lt;Array&lt;[ChangeInfo](#changeinfo10)&gt;&gt; | Yes  | Callback invoked to return the data change.<br>If **type** is **SUBSCRIBE_TYPE_REMOTE**, **observer** must be **Callback&lt;Array&lt;string&gt;&gt;**, where **Array&lt;string&gt;** specifies the IDs of the peer devices with data changes.<br>If **type** is **SUBSCRIBE_TYPE_CLOUD**, **observer** must be **Callback&lt;Array&lt;string&gt;&gt;**, where **Array&lt;string&gt;** specifies the cloud accounts with data changes.<br>If **type** is **SUBSCRIBE_TYPE_CLOUD_DETAILS**, **observer** must be **Callback&lt;Array&lt;ChangeInfo&gt;&gt;**, where **Array&lt;ChangeInfo&gt;** specifies the details about the device-cloud synchronization.|
A
Annie_wang 已提交
4094 4095 4096 4097 4098

**Example**

```js
function storeObserver(devices) {
A
Annie_wang 已提交
4099 4100 4101
  for (let i = 0; i < devices.length; i++) {
    console.info(`device= ${devices[i]} data changed`);
  }
A
Annie_wang 已提交
4102 4103
}
try {
A
Annie_wang 已提交
4104
  store.on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
A
Annie_wang 已提交
4105
} catch (err) {
A
Annie_wang 已提交
4106
  console.error(`Register observer failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
4107 4108 4109
}
```

G
Gloria 已提交
4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122
### on<sup>10+</sup>

on(event: string, interProcess: boolean, observer: Callback\<void>): void

Registers an intra-process or inter-process event listener for the RDB store. This callback is invoked by [emit](#emit10).

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name      | Type           | Mandatory| Description                                                        |
| ------------ | --------------- | ---- | ------------------------------------------------------------ |
| event        | string          | Yes  | Event name to observe.                                              |
A
Annie_wang 已提交
4123
| interProcess | boolean         | Yes  | Type of the event to observe.<br>The value **true** means the inter-process event.<br>The value **false** means the intra-process event.|
G
Gloria 已提交
4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147
| observer     | Callback\<void> | Yes  | Callback invoked to return the result.                                                  |

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                          |
| ------------ | -------------------------------------- |
| 14800000     | Inner error.                           |
| 14800050     | Failed to obtain subscription service. |

**Example**

```js
function storeObserver() {
    console.info(`storeObserver`);
}
try {
  store.on('storeObserver', false, storeObserver);
} catch (err) {
  console.error(`Register observer failed, code is ${err.code},message is ${err.message}`);
}
```

A
Annie_wang 已提交
4148 4149 4150 4151
### off('dataChange')

off(event:'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void

A
Annie_wang 已提交
4152 4153 4154 4155 4156 4157 4158 4159
Unregisters the data change event listener.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
G
Gloria 已提交
4160 4161
| event    | string                                                       | Yes  | Event type. The value is **dataChange**, which indicates a data change event.                      |
| type     | [SubscribeType](#subscribetype) | Yes  | Subscription type to unregister.                                                |
A
Annie_wang 已提交
4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183
| 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.|

**Example**

```
function storeObserver(devices) {
  for (let i = 0; i < devices.length; i++) {
    console.info(`device= ${devices[i]} data changed`);
  }
}
try {
  store.off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
} catch (err) {
  console.error(`Unregister observer failed, code is ${err.code},message is ${err.message}`);
}
```

### off('dataChange')<sup>10+</sup>

off(event:'dataChange', type: SubscribeType, observer?: Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;ChangeInfo&gt;&gt;): void

Unregisters the data change event listener.
A
Annie_wang 已提交
4184 4185 4186 4187 4188 4189 4190

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type                               | Mandatory| Description                                       |
| -------- | ---------------------------------- | ---- | ------------------------------------------ |
G
Gloria 已提交
4191 4192 4193
| event    | string                              | Yes  | Event type. The value is **dataChange**, which indicates a data change event.      |
| type     | [SubscribeType](#subscribetype)     | Yes  | Subscription type to unregister.                              |
| observer | Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;[ChangeInfo](#changeinfo10)&gt;&gt; | No| Callback invoked to return the result.<br>If **type** is **SUBSCRIBE_TYPE_REMOTE**, **observer** must be **Callback&lt;Array&lt;string&gt;&gt;**, where **Array&lt;string&gt;** specifies the IDs of the peer devices with data changes.<br>If **type** is **SUBSCRIBE_TYPE_CLOUD**, **observer** must be **Callback&lt;Array&lt;string&gt;&gt;**, where **Array&lt;string&gt;** specifies the cloud accounts with data changes.<br>If **type** is **SUBSCRIBE_TYPE_CLOUD_DETAILS**, **observer** must be **Callback&lt;Array&lt;ChangeInfo&gt;&gt;**, where **Array&lt;ChangeInfo&gt;** specifies the details about the device-cloud synchronization.<br>If **observer** is not specified, listening for all data change events of the specified **type** will be canceled.|
A
Annie_wang 已提交
4194 4195 4196 4197 4198

**Example**

```js
function storeObserver(devices) {
A
Annie_wang 已提交
4199 4200 4201
  for (let i = 0; i < devices.length; i++) {
    console.info(`device= ${devices[i]} data changed`);
  }
A
Annie_wang 已提交
4202 4203
}
try {
A
Annie_wang 已提交
4204
  store.off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
A
Annie_wang 已提交
4205
} catch (err) {
A
Annie_wang 已提交
4206
  console.error(`Unregister observer failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
4207 4208 4209
}
```

G
Gloria 已提交
4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276
### off<sup>10+</sup>

off(event: string, interProcess: boolean, observer?: Callback\<void>): void

Unregisters the data change event listener.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name      | Type           | Mandatory| Description                                                        |
| ------------ | --------------- | ---- | ------------------------------------------------------------ |
| event        | string          | Yes  | Name of the event to unsubscribe from.                                          |
| interProcess | boolean         | Yes  | Type of the event.<br>The value **true** means the inter-process event.<br>The value **false** means the intra-process event.|
| observer     | Callback\<void> | No  | Callback for the event to unregister. If this parameter is specified, the specified callback will be unregistered. If this parameter is not specified, all callbacks of the specified event will be unregistered.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                          |
| ------------ | -------------------------------------- |
| 14800000     | Inner error.                           |
| 14800050     | Failed to obtain subscription service. |

**Example**

```js
function storeObserver() {
    console.info(`storeObserver`);
}
try {
  store.off('storeObserver', false, storeObserver);
} catch (err) {
  console.error(`Register observer failed, code is ${err.code},message is ${err.message}`);
}
```

### emit<sup>10+</sup>

emit(event: string): void

Triggers the inter-process or intra-process event listener registered through [on](#on10).

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description                |
| ------ | ------ | ---- | -------------------- |
| event  | string | Yes  | Name of the event.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                          |
| ------------ | -------------------------------------- |
| 14800000     | Inner error.                           |
| 14800050     | Failed to obtain subscription service. |

**Example**

```js
store.emit('storeObserver');
```

A
Annie_wang 已提交
4277 4278 4279 4280 4281 4282
## ResultSet

Provides 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.

### Usage

A
Annie_wang 已提交
4283
Obtain the **resultSet** object first.
A
Annie_wang 已提交
4284 4285

```js
A
Annie_wang 已提交
4286
let resultSet = null;
A
Annie_wang 已提交
4287
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
A
Annie_wang 已提交
4288
predicates.equalTo("AGE", 18);
A
Annie_wang 已提交
4289
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
A
Annie_wang 已提交
4290 4291
promise.then((result) => {
  resultSet = result;
A
Annie_wang 已提交
4292 4293
  console.info(`resultSet columnNames: ${resultSet.columnNames}`);
  console.info(`resultSet columnCount: ${resultSet.columnCount}`);
A
Annie_wang 已提交
4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412
});
```

### Attributes

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

| Name        | Type           | Mandatory| Description                            |
| ------------ | ------------------- | ---- | -------------------------------- |
| columnNames  | Array&lt;string&gt; | Yes  | Names of all columns in the result set.      |
| columnCount  | number              | Yes  | Number of columns in the result set.            |
| rowCount     | number              | Yes  | Number of rows in the result set.            |
| rowIndex     | number              | Yes  | Index of the current row in the result set.        |
| isAtFirstRow | boolean             | Yes  | Whether the cursor is in the first row of the result set.      |
| isAtLastRow  | boolean             | Yes  | Whether the cursor is in the last row of the result set.    |
| isEnded      | boolean             | Yes  | Whether the cursor is after the last row of the result set.|
| isStarted    | boolean             | Yes  | Whether the cursor has been moved.            |
| isClosed     | boolean             | Yes  | Whether the result set is closed.        |

### getColumnIndex

getColumnIndex(columnName: string): number

Obtains the column index based on the column name.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name    | Type  | Mandatory| Description                      |
| ---------- | ------ | ---- | -------------------------- |
| columnName | string | Yes  | Column name.|

**Return value**

| Type  | Description              |
| ------ | ------------------ |
| number | Column index obtained.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |

**Example**

  ```js
resultSet.goToFirstRow();
const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
  ```

### getColumnName

getColumnName(columnIndex: number): string

Obtains the column name based on the specified column index.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name     | Type  | Mandatory| Description                      |
| ----------- | ------ | ---- | -------------------------- |
| columnIndex | number | Yes  | Column index.|

**Return value**

| Type  | Description              |
| ------ | ------------------ |
| string | Column name obtained.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |

**Example**

  ```js
const id = resultSet.getColumnName(0);
const name = resultSet.getColumnName(1);
const age = resultSet.getColumnName(2);
  ```

### goTo

goTo(offset:number): boolean

Moves the cursor to the row based on the specified offset.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name| Type  | Mandatory| Description                        |
| ------ | ------ | ---- | ---------------------------- |
| offset | number | Yes  | Offset relative to the current position.|

**Return value**

| Type   | Description                                         |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
A
Annie_wang 已提交
4413
| 14800012     | The result set is empty or the specified location is invalid. |
A
Annie_wang 已提交
4414 4415 4416 4417

**Example**

  ```js
A
Annie_wang 已提交
4418 4419
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise= store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
A
Annie_wang 已提交
4420
promise.then((resultSet) => {
A
Annie_wang 已提交
4421 4422
  resultSet.goTo(1);
  resultSet.close();
A
Annie_wang 已提交
4423
}).catch((err) => {
A
Annie_wang 已提交
4424
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453
});
  ```

### goToRow

goToRow(position: number): boolean

Moves to the specified row in the result set.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name  | Type  | Mandatory| Description                    |
| -------- | ------ | ---- | ------------------------ |
| position | number | Yes  | Destination position to move to.|

**Return value**

| Type   | Description                                         |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
A
Annie_wang 已提交
4454
| 14800012     | The result set is empty or the specified location is invalid. |
A
Annie_wang 已提交
4455 4456 4457 4458

**Example**

  ```js
A
Annie_wang 已提交
4459 4460
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
A
Annie_wang 已提交
4461
promise.then((resultSet) => {
A
Annie_wang 已提交
4462
  resultSet.goToRow(5);
A
Annie_wang 已提交
4463
  resultSet.close();
A
Annie_wang 已提交
4464
}).catch((err) => {
A
Annie_wang 已提交
4465
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489
});
  ```

### goToFirstRow

goToFirstRow(): boolean


Moves to the first row of the result set.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Return value**

| Type   | Description                                         |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
A
Annie_wang 已提交
4490
| 14800012     | The result set is empty or the specified location is invalid. |
A
Annie_wang 已提交
4491 4492 4493 4494

**Example**

  ```js
A
Annie_wang 已提交
4495 4496
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
A
Annie_wang 已提交
4497
promise.then((resultSet) => {
A
Annie_wang 已提交
4498 4499
  resultSet.goToFirstRow();
  resultSet.close();
A
Annie_wang 已提交
4500
}).catch((err) => {
A
Annie_wang 已提交
4501
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524
});
  ```

### goToLastRow

goToLastRow(): boolean

Moves to the last row of the result set.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Return value**

| Type   | Description                                         |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
A
Annie_wang 已提交
4525
| 14800012     | The result set is empty or the specified location is invalid. |
A
Annie_wang 已提交
4526 4527 4528 4529

**Example**

  ```js
A
Annie_wang 已提交
4530 4531
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
A
Annie_wang 已提交
4532
promise.then((resultSet) => {
A
Annie_wang 已提交
4533 4534
  resultSet.goToLastRow();
  resultSet.close();
A
Annie_wang 已提交
4535
}).catch((err) => {
A
Annie_wang 已提交
4536
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559
});
  ```

### goToNextRow

goToNextRow(): boolean

Moves to the next row in the result set.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Return value**

| Type   | Description                                         |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
A
Annie_wang 已提交
4560
| 14800012     | The result set is empty or the specified location is invalid. |
A
Annie_wang 已提交
4561 4562 4563 4564

**Example**

  ```js
A
Annie_wang 已提交
4565 4566
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
A
Annie_wang 已提交
4567
promise.then((resultSet) => {
A
Annie_wang 已提交
4568 4569
  resultSet.goToNextRow();
  resultSet.close();
A
Annie_wang 已提交
4570
}).catch((err) => {
A
Annie_wang 已提交
4571
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594
});
  ```

### goToPreviousRow

goToPreviousRow(): boolean

Moves to the previous row in the result set.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Return value**

| Type   | Description                                         |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
A
Annie_wang 已提交
4595
| 14800012     | The result set is empty or the specified location is invalid. |
A
Annie_wang 已提交
4596 4597 4598 4599

**Example**

  ```js
A
Annie_wang 已提交
4600 4601
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
A
Annie_wang 已提交
4602
promise.then((resultSet) => {
A
Annie_wang 已提交
4603 4604
  resultSet.goToPreviousRow();
  resultSet.close();
A
Annie_wang 已提交
4605
}).catch((err) => {
A
Annie_wang 已提交
4606
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629
});
  ```

### getBlob

getBlob(columnIndex: number): Uint8Array

Obtains the value in the form of a byte array based on the specified column and the current row.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name     | Type  | Mandatory| Description                   |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes  | Index of the target column, starting from 0.|

**Return value**

| Type      | Description                            |
| ---------- | -------------------------------- |
| Uint8Array | Value obtained.|

A
Annie_wang 已提交
4630 4631 4632 4633 4634 4635 4636 4637
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |

A
Annie_wang 已提交
4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663
**Example**

  ```js
const codes = resultSet.getBlob(resultSet.getColumnIndex("CODES"));
  ```

### getString

getString(columnIndex: number): string

Obtains the value in the form of a string based on the specified column and the current row.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name     | Type  | Mandatory| Description                   |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes  | Index of the target column, starting from 0.|

**Return value**

| Type  | Description                        |
| ------ | ---------------------------- |
| string | String obtained.|

A
Annie_wang 已提交
4664 4665 4666 4667 4668 4669 4670 4671
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |

A
Annie_wang 已提交
4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693
**Example**

  ```js
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
  ```

### getLong

getLong(columnIndex: number): number

Obtains the value of the Long type based on the specified column and the current row.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name     | Type  | Mandatory| Description                   |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes  | Index of the target column, starting from 0.|

**Return value**

A
Annie_wang 已提交
4694 4695
| Type  | Description                                                        |
| ------ | ------------------------------------------------------------ |
G
Gloria 已提交
4696
| number | Value obtained.<br>The value range supported by this API is **Number.MIN_SAFE_INTEGER** to **Number.MAX_SAFE_INTEGER**. If the value is out of this range, use [getDouble](#getdouble).|
A
Annie_wang 已提交
4697 4698 4699 4700 4701 4702 4703 4704

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |
A
Annie_wang 已提交
4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729

**Example**

  ```js
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
  ```

### getDouble

getDouble(columnIndex: number): number

Obtains the value of the double type based on the specified column and the current row.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name     | Type  | Mandatory| Description                   |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes  | Index of the target column, starting from 0.|

**Return value**

| Type  | Description                        |
| ------ | ---------------------------- |
A
Annie_wang 已提交
4730
| number | Returns the value obtained.|
A
Annie_wang 已提交
4731

A
Annie_wang 已提交
4732 4733 4734 4735 4736 4737 4738 4739
**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |

A
Annie_wang 已提交
4740 4741 4742 4743 4744 4745
**Example**

  ```js
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
  ```

A
Annie_wang 已提交
4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814
### getAsset<sup>10+</sup>

getAsset(columnIndex: number): Asset

Obtains the value in the [Asset](#asset10) format based on the specified column and current row.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name        | Type    | Mandatory | Description          |
| ----------- | ------ | --- | ------------ |
| columnIndex | number | Yes  | Index of the target column, starting from 0.|

**Return value**

| Type             | Description                        |
| --------------- | -------------------------- |
| [Asset](#asset10) | Returns the value obtained.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                    |
| --------- | ------------------------------------------------------------ |
| 14800013  | The column value is null or the column type is incompatible. |

**Example**

```js
const doc = resultSet.getAsset(resultSet.getColumnIndex("DOC"));
```

### getAssets<sup>10+</sup>

getAssets(columnIndex: number): Assets

Obtains the value in the [Assets](#assets10) format based on the specified column and current row.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name        | Type    | Mandatory | Description          |
| ----------- | ------ | --- | ------------ |
| columnIndex | number | Yes  | Index of the target column, starting from 0.|

**Return value**

| Type             | Description                          |
| ---------------- | ---------------------------- |
| [Assets](#assets10)| Returns the value obtained.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |

**Example**

```js
const docs = resultSet.getAssets(resultSet.getColumnIndex("DOCS"));
```


A
Annie_wang 已提交
4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859
### isColumnNull

isColumnNull(columnIndex: number): boolean

Checks whether the value in the specified column is null.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Parameters**

| Name     | Type  | Mandatory| Description                   |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes  | Index of the target column, starting from 0.|

**Return value**

| Type   | Description                                                     |
| ------- | --------------------------------------------------------- |
| boolean | Returns **true** if the value is null; returns **false** otherwise.|

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |

**Example**

  ```js
const isColumnNull = resultSet.isColumnNull(resultSet.getColumnIndex("CODES"));
  ```

### close

close(): void

Closes this result set.

**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core

**Example**

  ```js
A
Annie_wang 已提交
4860 4861
let predicatesClose = new relationalStore.RdbPredicates("EMPLOYEE");
let promiseClose = store.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
A
Annie_wang 已提交
4862
promiseClose.then((resultSet) => {
A
Annie_wang 已提交
4863
  resultSet.close();
A
Annie_wang 已提交
4864
}).catch((err) => {
A
Annie_wang 已提交
4865
  console.error(`resultset close failed, code is ${err.code},message is ${err.message}`);
A
Annie_wang 已提交
4866 4867 4868 4869 4870 4871 4872 4873 4874
});
  ```

**Error codes**

For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).

| **ID**| **Error Message**                                                |
| ------------ | ------------------------------------------------------------ |
A
Annie_wang 已提交
4875
| 14800012     | The result set is empty or the specified location is invalid. |