js-apis-data-relationalStore.md 181.5 KB
Newer Older
1 2
# @ohos.data.relationalStore (关系型数据库)

L
worker  
lihuihui 已提交
3
关系型数据库(Relational Database,RDB)是一种基于关系模型来管理数据的数据库。关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制,对外提供了一系列的增、删、改、查等接口,也可以直接运行用户输入的SQL语句来满足复杂的场景需要。不支持Worker线程。
4 5 6

该模块提供以下关系型数据库相关的常用功能:

7 8
- [RdbPredicates](#rdbpredicates): 数据库中用来代表数据实体的性质、特征或者数据实体之间关系的词项,主要用来定义数据库的操作条件。
- [RdbStore](#rdbstore):提供管理关系数据库(RDB)方法的接口。
L
LiRui 已提交
9
- [ResultSet](#resultset):提供用户调用关系型数据库查询接口之后返回的结果集合。
10 11 12 13 14 15 16 17

> **说明:**
> 
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

## 导入模块

```js
18
import relationalStore from '@ohos.data.relationalStore'
19 20
```

21
## relationalStore.getRdbStore
22

23
getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback<RdbStore>): void
24 25 26 27 28 29 30 31 32

获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                                           | 必填 | 说明                                                         |
| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
W
wangxiyue 已提交
33
| context  | Context                                        | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 |
34
| config   | [StoreConfig](#storeconfig)               | 是   | 与此RDB存储相关的数据库配置。                                |
35
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | 是   | 指定callback回调函数,返回RdbStore对象。                   |
36 37 38 39 40

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
41 42 43 44 45
| **错误码ID** | **错误信息**                                                |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800011     | Failed to open database by database corrupted.              |
| 14800000     | Inner error.                                                |
L
rdb  
lihuihui 已提交
46 47
| 14801001     | Only supported in stage mode.                               |
| 14801002     | The data group id is not valid.                             |
48 49 50 51 52 53

**示例:**

FA模型示例:

```js
54

55
import featureAbility from '@ohos.ability.featureAbility'
56

57 58
var store;

59
// 获取context
60
let context = featureAbility.getContext();
61 62

const STORE_CONFIG = {
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) {
G
ge-yafang 已提交
70
    console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
71 72 73
    return;
  }
  console.info(`Get RdbStore successfully.`);
74 75 76 77 78 79
})
```

Stage模型示例:

```ts
80
import UIAbility from '@ohos.app.ability.UIAbility'
81 82

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

102
## relationalStore.getRdbStore
103

104
getRdbStore(context: Context, config: StoreConfig): Promise&lt;RdbStore&gt;
105 106 107 108 109 110 111 112 113

获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名  | 类型                             | 必填 | 说明                                                         |
| ------- | -------------------------------- | ---- | ------------------------------------------------------------ |
W
wangxiyue 已提交
114
| context | Context                          | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 |
115 116 117 118 119 120
| config  | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |

**返回值**

| 类型                                      | 说明                              |
| ----------------------------------------- | --------------------------------- |
121
| Promise&lt;[RdbStore](#rdbstore)&gt; | Promise对象。返回RdbStore对象。 |
122 123 124 125 126

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
127 128 129 130 131
| **错误码ID** | **错误信息**                                                |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800011     | Failed to open database by database corrupted.              |
| 14800000     | Inner error.                                                |
L
rdb  
lihuihui 已提交
132 133
| 14801001     | Only supported in stage mode.                               |
| 14801002     | The data group id is not valid.                             |
134 135 136 137 138 139 140

**示例:**

FA模型示例:

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

142 143
var store;

144
// 获取context
145
let context = featureAbility.getContext();
146 147

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

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

Stage模型示例:

```ts
164
import UIAbility from '@ohos.app.ability.UIAbility'
165 166

class EntryAbility extends UIAbility {
167 168 169 170 171 172
  onWindowStageCreate(windowStage) {
    var store;
    const STORE_CONFIG = {
      name: "RdbTest.db",
      securityLevel: relationalStore.SecurityLevel.S1
    };
173
        
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) => {
G
ge-yafang 已提交
179
      console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
180 181
    })
  }
182 183 184
}
```

185
## relationalStore.deleteRdbStore
186 187 188 189 190 191 192 193 194 195 196

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

删除数据库,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                      | 必填 | 说明                                                         |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
W
wangxiyue 已提交
197
| context  | Context                   | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 |
198 199 200 201 202 203 204
| name     | string                    | 是   | 数据库名称。                                                 |
| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。                                       |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
205 206 207 208
| **错误码ID** | **错误信息**                                                |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800000     | Inner error.                                                |
209 210 211 212 213 214 215

**示例:**

FA模型示例:

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

// 获取context
218 219
let context = featureAbility.getContext()

220 221
relationalStore.deleteRdbStore(context, "RdbTest.db", function (err) {
  if (err) {
L
delete  
lihuihui 已提交
222
    console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
223 224 225
    return;
  }
  console.info(`Delete RdbStore successfully.`);
226 227 228 229 230 231
})
```

Stage模型示例:

```ts
232
import UIAbility from '@ohos.app.ability.UIAbility'
233 234

class EntryAbility extends UIAbility {
235
  onWindowStageCreate(windowStage){
L
rdb  
lihuihui 已提交
236

237 238
    relationalStore.deleteRdbStore(this.context, "RdbTest.db", function (err) {
      if (err) {
L
delete  
lihuihui 已提交
239
        console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
240 241 242 243 244
        return;
      }
      console.info(`Delete RdbStore successfully.`);
    })
  }
245 246 247
}
```

L
rdb  
lihuihui 已提交
248
## relationalStore.deleteRdbStore
L
rdb  
lihuihui 已提交
249

L
rdb  
lihuihui 已提交
250
deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;
L
rdb  
lihuihui 已提交
251

L
rdb  
lihuihui 已提交
252
使用指定的数据库文件配置删除数据库,使用Promise异步回调。
L
rdb  
lihuihui 已提交
253 254 255

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

L
rdb  
lihuihui 已提交
256
**参数**
L
rdb  
lihuihui 已提交
257

L
rdb  
lihuihui 已提交
258 259 260 261 262 263 264 265 266 267
| 参数名  | 类型    | 必填 | 说明                                                         |
| ------- | ------- | ---- | ------------------------------------------------------------ |
| context | Context | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 |
| name    | string  | 是   | 数据库名称。                                                 |

**返回值**

| 类型                | 说明                      |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
L
rdb  
lihuihui 已提交
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800000     | Inner error.                                                |

**示例:**

FA模型示例:

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

// 获取context
L
rdb  
lihuihui 已提交
286
let context = featureAbility.getContext();
L
rdb  
lihuihui 已提交
287

L
rdb  
lihuihui 已提交
288 289
let promise = relationalStore.deleteRdbStore(context, "RdbTest.db");
promise.then(()=>{
L
rdb  
lihuihui 已提交
290
  console.info(`Delete RdbStore successfully.`);
L
rdb  
lihuihui 已提交
291 292
}).catch((err) => {
  console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
L
rdb  
lihuihui 已提交
293 294 295 296 297 298 299 300 301 302
})
```

Stage模型示例:

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

class EntryAbility extends UIAbility {
  onWindowStageCreate(windowStage){
L
rdb  
lihuihui 已提交
303 304
    let promise = relationalStore.deleteRdbStore(this.context, "RdbTest.db");
    promise.then(()=>{
L
rdb  
lihuihui 已提交
305
      console.info(`Delete RdbStore successfully.`);
L
rdb  
lihuihui 已提交
306 307
    }).catch((err) => {
      console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
L
rdb  
lihuihui 已提交
308 309 310 311 312
    })
  }
}
```

L
rdb  
lihuihui 已提交
313
## relationalStore.deleteRdbStore<sup>10+</sup>
L
rdb  
lihuihui 已提交
314

L
rdb  
lihuihui 已提交
315
deleteRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback\<void>): void
316

L
rdb  
lihuihui 已提交
317
使用指定的数据库文件配置删除数据库,使用callback异步回调。若数据库文件处于公共沙箱目录下,则删除数据库时必须使用该接口。
318 319 320

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

L
rdb  
lihuihui 已提交
321
**参数:**
322

L
rdb  
lihuihui 已提交
323 324 325 326 327
| 参数名   | 类型                        | 必填 | 说明                                                         |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| context  | Context                     | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 |
| config   | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |
| callback | AsyncCallback&lt;void&gt;   | 是   | 指定callback回调函数。                                       |
328 329 330 331 332

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
333 334 335 336
| **错误码ID** | **错误信息**                                                |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800000     | Inner error.                                                |
L
rdb  
lihuihui 已提交
337 338
| 14801001     | Only supported in stage mode.                               |
| 14801002     | The data group id is not valid.                             |
339 340 341 342 343 344 345

**示例:**

FA模型示例:

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

// 获取context
L
rdb  
lihuihui 已提交
348 349 350 351 352
let context = featureAbility.getContext()
const STORE_CONFIG = {
  name: "RdbTest.db",
  securityLevel: relationalStore.SecurityLevel.S1
};
353

L
rdb  
lihuihui 已提交
354 355 356 357 358
relationalStore.deleteRdbStore(context, STORE_CONFIG, function (err) {
  if (err) {
    console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
    return;
  }
359
  console.info(`Delete RdbStore successfully.`);
360 361 362 363 364 365
})
```

Stage模型示例:

```ts
366
import UIAbility from '@ohos.app.ability.UIAbility'
367 368

class EntryAbility extends UIAbility {
369
  onWindowStageCreate(windowStage){
L
rdb  
lihuihui 已提交
370 371 372 373 374 375 376 377 378
    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;
      }
379 380 381
      console.info(`Delete RdbStore successfully.`);
    })
  }
382 383 384
}
```

L
rdb  
lihuihui 已提交
385
## relationalStore.deleteRdbStore<sup>10+</sup>
L
rdb  
lihuihui 已提交
386

L
rdb  
lihuihui 已提交
387
deleteRdbStore(context: Context, config: StoreConfig): Promise\<void>
L
rdb  
lihuihui 已提交
388

L
rdb  
lihuihui 已提交
389
使用指定的数据库文件配置删除数据库,使用Promise异步回调。若数据库文件处于公共沙箱目录下,则删除数据库时必须使用该接口。
L
rdb  
lihuihui 已提交
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数**

| 参数名  | 类型                        | 必填 | 说明                                                         |
| ------- | --------------------------- | ---- | ------------------------------------------------------------ |
| context | Context                     | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)<br>Stage模型的应用Context定义见[Context](js-apis-inner-application-uiAbilityContext.md)。 |
| config  | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |

**返回值**

| 类型                | 说明                      |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                |
| ------------ | ----------------------------------------------------------- |
| 14800010     | Failed to open or delete database by invalid database path. |
| 14800000     | Inner error.                                                |
L
rdb  
lihuihui 已提交
414 415
| 14801001     | Only supported in stage mode.                               |
| 14801002     | The data group id is not valid.                             |
L
rdb  
lihuihui 已提交
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 449 450 451 452 453 454 455 456 457 458 459

**示例:**

FA模型示例:

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

// 获取context
let context = featureAbility.getContext();
const STORE_CONFIG = {
  name: "RdbTest.db",
  securityLevel: relationalStore.SecurityLevel.S1
};

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

Stage模型示例:

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

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(()=>{
      console.info(`Delete RdbStore successfully.`);
    }).catch((err) => {
      console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
    })
  }
}
```

460
## StoreConfig
461 462 463 464 465 466 467 468

管理关系数据库配置。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 名称        | 类型          | 必填 | 说明                                                      |
| ------------- | ------------- | ---- | --------------------------------------------------------- |
| name          | string        | 是   | 数据库文件名。                                            |
P
PaDaBoo 已提交
469
| securityLevel | [SecurityLevel](#securitylevel) | 是   | 设置数据库安全级别                                        |
L
delete  
lihuihui 已提交
470
| encrypt       | boolean       | 否   | 指定数据库是否加密,默认不加密。<br/> true:加密。<br/> false:非加密。 |
L
rdb  
lihuihui 已提交
471
| dataGroupId<sup>10+</sup> | string | 否 | 应用组ID,需要向应用市场获取。<br/>**模型约束:** 此属性仅在Stage模型下可用。<br/>从API version 10开始,支持此可选参数。指定在此dataGroupId对应的沙箱路径下创建relationalStore实例,当此参数不填时,默认在本应用沙箱目录下创建relationalStore实例。 |
472

473
## SecurityLevel
474 475 476

数据库的安全级别枚举。

L
lihuihui 已提交
477 478
> **说明:**
>
L
query  
lihuihui 已提交
479
> 若需要进行同步操作,数据库安全等级应不高于对端设备安全等级,具体可见[跨设备同步访问控制机制](../../database/sync-app-data-across-devices-overview.md#跨设备同步访问控制机制)。
L
lihuihui 已提交
480

481 482 483 484 485 486 487 488 489
**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 名称 | 值   | 说明                                                         |
| ---- | ---- | ------------------------------------------------------------ |
| S1   | 1    | 表示数据库的安全级别为低级别,当数据泄露时会产生较低影响。例如,包含壁纸等系统数据的数据库。 |
| S2   | 2    | 表示数据库的安全级别为中级别,当数据泄露时会产生较大影响。例如,包含录音、视频等用户生成数据或通话记录等信息的数据库。 |
| S3   | 3    | 表示数据库的安全级别为高级别,当数据泄露时会产生重大影响。例如,包含用户运动、健康、位置等信息的数据库。 |
| S4   | 4    | 表示数据库的安全级别为关键级别,当数据泄露时会产生严重影响。例如,包含认证凭据、财务数据等信息的数据库。 |

R
renjiecui 已提交
490 491
## AssetStatus<sup>10+</sup>

R
renjiecui 已提交
492
描述资产附件的状态枚举。请使用枚举名称而非枚举值。
R
renjiecui 已提交
493 494 495 496 497

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 名称                              | 值   | 说明             |
| ------------------------------- | --- | -------------- |
R
renjiecui 已提交
498
| ASSET_NORMAL     | -   | 表示资产状态正常。      |
R
renjiecui 已提交
499
| ASSET_INSERT | - | 表示资产需要插入到云端。 |
R
renjiecui 已提交
500
| ASSET_UPDATE | - | 表示资产需要更新到云端。 |
R
renjiecui 已提交
501
| ASSET_DELETE | - | 表示资产需要在云端删除。 |
R
renjiecui 已提交
502 503
| ASSET_ABNORMAL    | -   | 表示资产状态异常。      |
| ASSET_DOWNLOADING | -   | 表示资产正在下载到本地设备。 |
R
renjiecui 已提交
504 505 506

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

R
renjiecui 已提交
507
记录资产附件(文件、图片、视频等类型文件)的相关信息。资产类型的相关接口暂不支持Datashare。
R
renjiecui 已提交
508 509 510 511 512 513

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 名称          | 类型                          | 必填  | 说明           |
| ----------- | --------------------------- | --- | ------------ |
| name        | string                      | 是   | 资产的名称。       |
R
renjiecui 已提交
514 515
| uri         | string                      | 是   | 资产的uri,在系统里的绝对路径。       |
| path        | string                      | 是   | 资产在应用沙箱里的路径。       |
R
renjiecui 已提交
516
| createTime  | string                      | 是   | 资产被创建出来的时间。   |
R
renjiecui 已提交
517
| modifyTime  | string                      | 是   | 资产最后一次被修改的时间。 |
R
renjiecui 已提交
518 519
| size        | string                      | 是   | 资产占用空间的大小。    |
| status      | [AssetStatus](#assetstatus10) | 否   | 资产的状态,默认值为ASSET_NORMAL。        |
R
renjiecui 已提交
520 521 522

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

R
renjiecui 已提交
523
表示[Asset](#asset10)类型的数组。
R
renjiecui 已提交
524

R
renjiecui 已提交
525 526
**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

R
renjiecui 已提交
527 528
| 类型    | 说明                 |
| ------- | -------------------- |
R
renjiecui 已提交
529
| [Asset](#asset10)[] | 表示Asset类型的数组。   |
R
renjiecui 已提交
530

531
## ValueType
532 533 534 535 536 537 538

用于表示允许的数据字段类型。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 类型    | 说明                 |
| ------- | -------------------- |
R
renjiecui 已提交
539
| null<sup>10+</sup>    | 表示值类型为空。   |
540 541 542
| number  | 表示值类型为数字。   |
| string  | 表示值类型为字符。   |
| boolean | 表示值类型为布尔值。 |
R
renjiecui 已提交
543
| Uint8Array<sup>10+</sup>           | 表示值类型为Uint8类型的数组。            |
R
renjiecui 已提交
544
| Asset<sup>10+</sup>  | 表示值类型为附件[Asset](#asset10)。     |
R
renjiecui 已提交
545
| Assets<sup>10+</sup> | 表示值类型为附件数组[Assets](#assets10)。 |
546

547
## ValuesBucket
548

W
wangdengze 已提交
549
用于存储键值对的类型。该类型不是多线程安全的,如果应用中存在多线程同时操作该类派生出的实例,注意加锁保护。
550 551 552

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

R
renjiecui 已提交
553 554 555
| 键类型 | 值类型                   |
| ------ | ----------------------- |
| string | [ValueType](#valuetype) |
556

R
renjiecui 已提交
557 558
## PRIKeyType<sup>10+</sup> 

R
renjiecui 已提交
559
用于表示数据库表某一行主键的数据类型。
R
renjiecui 已提交
560 561 562

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

R
renjiecui 已提交
563 564 565
| 类型             | 说明                               |
| ---------------- | ---------------------------------- |
| number \| string | 主键的类型可以是number或者string。 |
R
renjiecui 已提交
566 567 568

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

R
renjiecui 已提交
569
用于表示UTC类型时间的数据类型。
R
renjiecui 已提交
570 571 572 573 574 575 576 577 578

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 类型 | 说明            |
| ---- | --------------- |
| Date | UTC类型的时间。 |

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

R
renjiecui 已提交
579
用于存储数据库表的主键和修改时间的数据类型。
R
renjiecui 已提交
580 581 582 583 584 585 586

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 类型                                                    | 说明                                                         |
| ------------------------------------------------------- | ------------------------------------------------------------ |
| Map<[PRIKeyType](#prikeytype10), [UTCTime](#utctime10)> | 键表示是数据库表某一行的主键,值表示该行的最后修改时间,用UTC格式表示。 |

587
## SyncMode
588 589 590 591 592

指数据库同步模式。

| 名称           | 值   | 说明                               |
| -------------- | ---- | ---------------------------------- |
R
renjiecui 已提交
593 594
| SYNC_MODE_PUSH                       | 0   | 表示数据从本地设备推送到远程设备。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core                     |
| SYNC_MODE_PULL                       | 1   | 表示数据从远程设备拉至本地设备。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core                      |
R
renjiecui 已提交
595 596 597
| SYNC_MODE_TIME_FIRST<sup>10+</sup>   | -   | 表示数据从修改时间较近的一端同步到修改时间较远的一端。请使用枚举名称而非枚举值。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
| SYNC_MODE_NATIVE_FIRST<sup>10+</sup> | -   | 表示数据从本地设备同步到云端。请使用枚举名称而非枚举值。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client             |
| SYNC_MODE_CLOUD_FIRST<sup>10+</sup>  | -   | 表示数据从云端同步到本地设备。请使用枚举名称而非枚举值。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client             |
598

599
## SubscribeType
600 601 602 603 604 605 606

描述订阅类型。

**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

| 名称                  | 值   | 说明               |
| --------------------- | ---- | ------------------ |
L
LiRui 已提交
607 608 609
| SUBSCRIBE_TYPE_REMOTE | 0    | 订阅远程数据更改。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
| SUBSCRIBE_TYPE_CLOUD<sup>10+</sup> | -  | 订阅云端数据更改。请使用枚举名称而非枚举值。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
| SUBSCRIBE_TYPE_CLOUD_DETAILS<sup>10+</sup> | -  | 订阅云端数据更改详情。请使用枚举名称而非枚举值。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
610

R
renjiecui 已提交
611 612
## ChangeType<sup>10+</sup>

R
renjiecui 已提交
613
描述数据变更类型的枚举。请使用枚举名称而非枚举值。
R
renjiecui 已提交
614 615 616

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

R
renjiecui 已提交
617 618
**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

R
renjiecui 已提交
619 620
| 名称                         | 值   | 说明                         |
| -------------------------- | --- | -------------------------- |
R
renjiecui 已提交
621 622
| DATA_CHANGE  | -   | 表示是数据发生变更。   |
| ASSET_CHANGE | -   | 表示是资产附件发生了变更。 |
R
renjiecui 已提交
623 624 625 626 627

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

记录端云同步过程详情。

R
renjiecui 已提交
628
**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
R
renjiecui 已提交
629

R
renjiecui 已提交
630 631 632 633 634 635 636
| 名称     | 类型                               | 必填 | 说明                                                         |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| table    | string                             | 是   | 表示发生变化的表的名称。                                     |
| type     | [ChangeType](#changetype10)        | 是   | 表示发生变化的数据的类型,数据或者资产附件发生变化。         |
| inserted | Array\<string\> \| Array\<number\> | 是   | 记录插入数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示插入数据的行号。 |
| updated  | Array\<string\> \| Array\<number\> | 是   | 记录更新数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示更新数据的行号。 |
| deleted  | Array\<string\> \| Array\<number\> | 是   | 记录删除数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示删除数据的行号。 |
R
renjiecui 已提交
637 638 639

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

R
renjiecui 已提交
640
描述表的分布式类型的枚举。请使用枚举名称而非枚举值。
R
renjiecui 已提交
641

R
renjiecui 已提交
642 643
**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

R
renjiecui 已提交
644 645
| 名称                | 值   | 说明                                                                                                 |
| ------------------ | --- | -------------------------------------------------------------------------------------------------- |
R
renjiecui 已提交
646 647
| DISTRIBUTED_DEVICE | -  | 表示在不同设备之间分布式的数据库表。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core               |
| DISTRIBUTED_CLOUD  | -   | 表示在设备和云端之间分布式的数据库表。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
R
renjiecui 已提交
648 649 650 651 652 653 654

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

记录表的分布式配置信息。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

R
renjiecui 已提交
655 656
| 名称     | 类型    | 必填 | 说明                                                         |
| -------- | ------- | ---- | ------------------------------------------------------------ |
R
renjiecui 已提交
657
| autoSync | boolean | 是   | 该值为true时,表示该表支持自动同步和手动同步;该值为false时,表示该表只支持手动同步,不支持自动同步。 |
R
renjiecui 已提交
658

L
lihuihui 已提交
659 660 661 662 663 664 665 666
## ConflictResolution<sup>10+</sup>

插入和修改接口的冲突解决方式。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 名称                 | 值   | 说明                                                         |
| -------------------- | ---- | ------------------------------------------------------------ |
P
PaDaBoo 已提交
667
| ON_CONFLICT_NONE | 0 | 表示当冲突发生时,不做任何处理。 |
L
lihuihui 已提交
668 669 670 671 672 673
| ON_CONFLICT_ROLLBACK | 1    | 表示当冲突发生时,中止SQL语句并回滚当前事务。                |
| ON_CONFLICT_ABORT    | 2    | 表示当冲突发生时,中止当前SQL语句,并撤销当前 SQL 语句所做的任何更改,但是由同一事务中先前的 SQL 语句引起的更改被保留并且事务保持活动状态。 |
| ON_CONFLICT_FAIL     | 3    | 表示当冲突发生时,中止当前 SQL 语句。但它不会撤销失败的 SQL 语句的先前更改,也不会结束事务。 |
| ON_CONFLICT_IGNORE   | 4    | 表示当冲突发生时,跳过包含违反约束的行并继续处理 SQL 语句的后续行。 |
| ON_CONFLICT_REPLACE  | 5    | 表示当冲突发生时,在插入或更新当前行之前删除导致约束违例的预先存在的行,并且命令会继续正常执行。 |

R
renjiecui 已提交
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
## Progress<sup>10+</sup>

描述端云同步过程的枚举。请使用枚举名称而非枚举值。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 名称             | 值   | 说明                     |
| ---------------- | ---- | ------------------------ |
| SYNC_BEGIN       | -    | 表示端云同步过程开始。   |
| SYNC_IN_PROGRESS | -    | 表示正在端云同步过程中。 |
| SYNC_FINISH      | -    | 表示端云同步过程已完成。 |

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

描述数据库表的端云同步过程的统计信息。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 名称     | 类型   | 必填 | 说明                                     |
| -------- | ------ | ---- | ---------------------------------------- |
| total    | number | 是   | 表示数据库表中需要端云同步的总行数。     |
| success  | number | 是   | 表示数据库表中端云同步成功的行数。       |
| failed   | number | 是   | 表示数据库表中端云同步失败的行数。       |
| remained | number | 是   | 表示数据库表中端云同步剩余未执行的行数。 |

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

描述数据库表执行端云同步任务上传和下载的统计信息。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 名称     | 类型                      | 必填 | 说明                                       |
| -------- | ------------------------- | ---- | ------------------------------------------ |
| upload   | [Statistic](#statistic10) | 是   | 表示数据库表中端云同步上传过程的统计信息。 |
| download | [Statistic](#statistic10) | 是   | 表示数据库表中端云同步下载过程的统计信息。 |

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

表示端云同步过程的状态。请使用枚举名称而非枚举值。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

R
renjiecui 已提交
716 717 718 719 720 721 722 723 724
| 名称                  | 值   | 说明                                                         |
| --------------------- | ---- | ------------------------------------------------------------ |
| SUCCESS               | -    | 表示端云同步过程成功。                                       |
| UNKNOWN_ERROR         | -    | 表示端云同步过程遇到未知错误。                               |
| NETWORK_ERROR         | -    | 表示端云同步过程遇到网络错误。                               |
| CLOUD_DISABLED        | -    | 表示云端不可用。                                             |
| LOCKED_BY_OTHERS      | -    | 表示有其他设备正在端云同步,本设备无法进行端云同步。<br>请确保无其他设备占用云端资源后,再使用本设备进行端云同步任务。 |
| RECORD_LIMIT_EXCEEDED | -    | 表示本次端云同步需要同步的条目或大小超出最大值。由云端配置最大值。 |
| NO_SPACE_FOR_ASSET    | -    | 表示云空间剩余空间小于待同步的资产大小。                     |
R
renjiecui 已提交
725 726 727

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

R
renjiecui 已提交
728
描述数据库整体执行端云同步任务上传和下载的统计信息。
R
renjiecui 已提交
729 730 731 732 733 734 735 736 737

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 名称     | 类型                                              | 必填 | 说明                                                         |
| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
| schedule | [Progress](#progress10)                           | 是   | 表示端云同步过程。                                           |
| code     | [ProgressCode](#progresscode10)                   | 是   | 表示端云同步过程的状态。                                     |
| details  | [table: string] : [TableDetails](#tabledetails10) | 是   | 表示端云同步各表的统计信息。<br>键表示表名,值表示该表的端云同步过程统计信息。 |

738
## RdbPredicates
739

W
wangdengze 已提交
740
表示关系型数据库(RDB)的谓词。该类确定RDB中条件表达式的值是true还是false。该类型不是多线程安全的,如果应用中存在多线程同时操作该类派生出的实例,注意加锁保护。
741

742
### constructor
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758

constructor(name: string)

构造函数。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明         |
| ------ | ------ | ---- | ------------ |
| name   | string | 是   | 数据库表名。 |

**示例:**

```js
759
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
760 761
```

762
### inDevices
763 764 765 766 767

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

同步分布式数据库时连接到组网内指定的远程设备。

L
device  
lihuihui 已提交
768 769 770 771
> **说明:**
>
> 其中devices通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。

772 773 774 775 776 777 778 779 780 781 782 783
**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名  | 类型                | 必填 | 说明                       |
| ------- | ------------------- | ---- | -------------------------- |
| devices | Array&lt;string&gt; | 是   | 指定的组网内的远程设备ID。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
784
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
785 786 787 788

**示例:**

```js
L
device  
lihuihui 已提交
789 790
import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null;
L
lihuihui 已提交
791
let deviceIds = [];
L
device  
lihuihui 已提交
792 793 794 795 796 797 798 799 800 801 802 803 804

deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
    if (err) {
        console.log("create device manager failed, err=" + err);
        return;
    }
    dmInstance = manager;
    let devices = dmInstance.getTrustedDeviceListSync();
    for (var i = 0; i < devices.length; i++) {
        deviceIds[i] = devices[i].deviceId;
    }
})
                                  
805
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
L
device  
lihuihui 已提交
806
predicates.inDevices(deviceIds);
807 808
```

809
### inAllDevices
810 811 812 813 814 815 816 817 818 819 820 821

inAllDevices(): RdbPredicates


同步分布式数据库时连接到组网内所有的远程设备。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
822
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
823 824 825 826

**示例:**

```js
827 828
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.inAllDevices();
829 830
```

831
### equalTo
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850

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


配置谓词以匹配数据字段为ValueType且值等于指定值的字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                    | 必填 | 说明                   |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | 是   | 数据库表中的列名。     |
| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
851
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
852 853 854 855

**示例:**

```js
856 857
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "lisi");
858 859 860
```


861
### notEqualTo
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880

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


配置谓词以匹配数据字段为ValueType且值不等于指定值的字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                    | 必填 | 说明                   |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | 是   | 数据库表中的列名。     |
| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
881
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
882 883 884 885

**示例:**

```js
886 887
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.notEqualTo("NAME", "lisi");
888 889 890
```


891
### beginWrap
892 893 894 895 896 897 898 899 900 901 902 903

beginWrap(): RdbPredicates


向谓词添加左括号。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**返回值**

| 类型                                 | 说明                      |
| ------------------------------------ | ------------------------- |
904
| [RdbPredicates](#rdbpredicates) | 返回带有左括号的Rdb谓词。 |
905 906 907 908

**示例:**

```js
909
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
910 911 912 913 914 915 916 917
predicates.equalTo("NAME", "lisi")
    .beginWrap()
    .equalTo("AGE", 18)
    .or()
    .equalTo("SALARY", 200.5)
    .endWrap()
```

918
### endWrap
919 920 921 922 923 924 925 926 927 928 929

endWrap(): RdbPredicates

向谓词添加右括号。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**返回值**

| 类型                                 | 说明                      |
| ------------------------------------ | ------------------------- |
930
| [RdbPredicates](#rdbpredicates) | 返回带有右括号的Rdb谓词。 |
931 932 933 934

**示例:**

```js
935
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
936 937 938 939 940 941 942 943
predicates.equalTo("NAME", "lisi")
    .beginWrap()
    .equalTo("AGE", 18)
    .or()
    .equalTo("SALARY", 200.5)
    .endWrap()
```

944
### or
945 946 947 948 949 950 951 952 953 954 955

or(): RdbPredicates

将或条件添加到谓词中。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**返回值**

| 类型                                 | 说明                      |
| ------------------------------------ | ------------------------- |
956
| [RdbPredicates](#rdbpredicates) | 返回带有或条件的Rdb谓词。 |
957 958 959 960

**示例:**

```js
961
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
962 963 964 965 966
predicates.equalTo("NAME", "Lisa")
    .or()
    .equalTo("NAME", "Rose")
```

967
### and
968 969 970 971 972 973 974 975 976 977 978

and(): RdbPredicates

向谓词添加和条件。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**返回值**

| 类型                                 | 说明                      |
| ------------------------------------ | ------------------------- |
979
| [RdbPredicates](#rdbpredicates) | 返回带有和条件的Rdb谓词。 |
980 981 982 983

**示例:**

```js
984
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
985 986 987 988 989
predicates.equalTo("NAME", "Lisa")
    .and()
    .equalTo("SALARY", 200.5)
```

990
### contains
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008

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

配置谓词以匹配数据字段为string且value包含指定值的字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明                   |
| ------ | ------ | ---- | ---------------------- |
| field  | string | 是   | 数据库表中的列名。     |
| value  | string | 是   | 指示要与谓词匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1009
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1010 1011 1012 1013

**示例:**

```js
1014 1015
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.contains("NAME", "os");
1016 1017
```

1018
### beginsWith
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036

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

配置谓词以匹配数据字段为string且值以指定字符串开头的字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明                   |
| ------ | ------ | ---- | ---------------------- |
| field  | string | 是   | 数据库表中的列名。     |
| value  | string | 是   | 指示要与谓词匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1037
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1038 1039 1040 1041

**示例:**

```js
1042 1043
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.beginsWith("NAME", "os");
1044 1045
```

1046
### endsWith
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064

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

配置谓词以匹配数据字段为string且值以指定字符串结尾的字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明                   |
| ------ | ------ | ---- | ---------------------- |
| field  | string | 是   | 数据库表中的列名。     |
| value  | string | 是   | 指示要与谓词匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1065
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1066 1067 1068 1069

**示例:**

```js
1070 1071
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.endsWith("NAME", "se");
1072 1073
```

1074
### isNull
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091

isNull(field: string): RdbPredicates

配置谓词以匹配值为null的字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明               |
| ------ | ------ | ---- | ------------------ |
| field  | string | 是   | 数据库表中的列名。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1092
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1093 1094 1095 1096

**示例**

```js
1097 1098
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.isNull("NAME");
1099 1100
```

1101
### isNotNull
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118

isNotNull(field: string): RdbPredicates

配置谓词以匹配值不为null的指定字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明               |
| ------ | ------ | ---- | ------------------ |
| field  | string | 是   | 数据库表中的列名。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1119
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1120 1121 1122 1123

**示例:**

```js
1124 1125
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.isNotNull("NAME");
1126 1127
```

1128
### like
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146

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

配置谓词以匹配数据字段为string且值类似于指定字符串的字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明                   |
| ------ | ------ | ---- | ---------------------- |
| field  | string | 是   | 数据库表中的列名。     |
| value  | string | 是   | 指示要与谓词匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1147
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1148 1149 1150 1151

**示例:**

```js
1152 1153
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.like("NAME", "%os%");
1154 1155
```

1156
### glob
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174

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

配置RdbPredicates匹配数据字段为string的指定字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| field  | string | 是   | 数据库表中的列名。                                           |
| value  | string | 是   | 指示要与谓词匹配的值。<br>支持通配符,*表示0个、1个或多个数字或字符,?表示1个数字或字符。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1175
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1176 1177 1178 1179

**示例:**

```js
1180 1181
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.glob("NAME", "?h*g");
1182 1183
```

1184
### between
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203

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

将谓词配置为匹配数据字段为ValueType且value在给定范围内的指定字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                    | 必填 | 说明                       |
| ------ | ----------------------- | ---- | -------------------------- |
| field  | string                  | 是   | 数据库表中的列名。         |
| low    | [ValueType](#valuetype) | 是   | 指示与谓词匹配的最小值。   |
| high   | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的最大值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1204
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1205 1206 1207 1208

**示例:**

```js
1209 1210
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.between("AGE", 10, 50);
1211 1212
```

1213
### notBetween
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232

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

配置RdbPredicates以匹配数据字段为ValueType且value超出给定范围的指定字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                    | 必填 | 说明                       |
| ------ | ----------------------- | ---- | -------------------------- |
| field  | string                  | 是   | 数据库表中的列名。         |
| low    | [ValueType](#valuetype) | 是   | 指示与谓词匹配的最小值。   |
| high   | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的最大值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1233
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1234 1235 1236 1237

**示例:**

```js
1238 1239
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.notBetween("AGE", 10, 50);
1240 1241
```

1242
### greaterThan
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260

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

配置谓词以匹配数据字段为ValueType且值大于指定值的字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                    | 必填 | 说明                   |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | 是   | 数据库表中的列名。     |
| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1261
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1262 1263 1264 1265

**示例:**

```js
1266 1267
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.greaterThan("AGE", 18);
1268 1269
```

1270
### lessThan
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288

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

配置谓词以匹配数据字段为valueType且value小于指定值的字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                    | 必填 | 说明                   |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | 是   | 数据库表中的列名。     |
| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1289
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1290 1291 1292 1293

**示例:**

```js
1294 1295
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.lessThan("AGE", 20);
1296 1297
```

1298
### greaterThanOrEqualTo
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316

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

配置谓词以匹配数据字段为ValueType且value大于或等于指定值的字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                    | 必填 | 说明                   |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | 是   | 数据库表中的列名。     |
| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1317
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1318 1319 1320 1321

**示例:**

```js
1322 1323
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.greaterThanOrEqualTo("AGE", 18);
1324 1325
```

1326
### lessThanOrEqualTo
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344

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

配置谓词以匹配数据字段为ValueType且value小于或等于指定值的字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                    | 必填 | 说明                   |
| ------ | ----------------------- | ---- | ---------------------- |
| field  | string                  | 是   | 数据库表中的列名。     |
| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1345
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1346 1347 1348 1349

**示例:**

```js
1350 1351
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.lessThanOrEqualTo("AGE", 20);
1352 1353
```

1354
### orderByAsc
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371

orderByAsc(field: string): RdbPredicates

配置谓词以匹配其值按升序排序的列。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明               |
| ------ | ------ | ---- | ------------------ |
| field  | string | 是   | 数据库表中的列名。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1372
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1373 1374 1375 1376

**示例:**

```js
1377 1378
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.orderByAsc("NAME");
1379 1380
```

1381
### orderByDesc
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398

orderByDesc(field: string): RdbPredicates

配置谓词以匹配其值按降序排序的列。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明               |
| ------ | ------ | ---- | ------------------ |
| field  | string | 是   | 数据库表中的列名。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1399
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1400 1401 1402 1403

**示例:**

```js
1404 1405
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.orderByDesc("AGE");
1406 1407
```

1408
### distinct
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419

distinct(): RdbPredicates

配置谓词以过滤重复记录并仅保留其中一个。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**返回值**

| 类型                                 | 说明                           |
| ------------------------------------ | ------------------------------ |
1420
| [RdbPredicates](#rdbpredicates) | 返回可用于过滤重复记录的谓词。 |
1421 1422 1423 1424

**示例:**

```js
1425 1426
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose").distinct();
1427 1428
```

1429
### limitAs
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446

limitAs(value: number): RdbPredicates

设置最大数据记录数的谓词。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明             |
| ------ | ------ | ---- | ---------------- |
| value  | number | 是   | 最大数据记录数。 |

**返回值**

| 类型                                 | 说明                                 |
| ------------------------------------ | ------------------------------------ |
1447
| [RdbPredicates](#rdbpredicates) | 返回可用于设置最大数据记录数的谓词。 |
1448 1449 1450 1451

**示例:**

```js
1452 1453
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose").limitAs(3);
1454 1455
```

1456
### offsetAs
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473

offsetAs(rowOffset: number): RdbPredicates

配置RdbPredicates以指定返回结果的起始位置。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名    | 类型   | 必填 | 说明                               |
| --------- | ------ | ---- | ---------------------------------- |
| rowOffset | number | 是   | 返回结果的起始位置,取值为正整数。 |

**返回值**

| 类型                                 | 说明                                 |
| ------------------------------------ | ------------------------------------ |
1474
| [RdbPredicates](#rdbpredicates) | 返回具有指定返回结果起始位置的谓词。 |
1475 1476 1477 1478

**示例:**

```js
1479 1480
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose").offsetAs(3);
1481 1482
```

1483
### groupBy
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500

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

配置RdbPredicates按指定列分组查询结果。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                | 必填 | 说明                 |
| ------ | ------------------- | ---- | -------------------- |
| fields | Array&lt;string&gt; | 是   | 指定分组依赖的列名。 |

**返回值**

| 类型                                 | 说明                   |
| ------------------------------------ | ---------------------- |
1501
| [RdbPredicates](#rdbpredicates) | 返回分组查询列的谓词。 |
1502 1503 1504 1505

**示例:**

```js
1506 1507
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.groupBy(["AGE", "NAME"]);
1508 1509
```

1510
### indexedBy
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528

indexedBy(field: string): RdbPredicates

配置RdbPredicates以指定索引列。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明           |
| ------ | ------ | ---- | -------------- |
| field  | string | 是   | 索引列的名称。 |

**返回值**


| 类型                                 | 说明                                  |
| ------------------------------------ | ------------------------------------- |
1529
| [RdbPredicates](#rdbpredicates) | 返回具有指定索引列的RdbPredicates。 |
1530 1531 1532 1533

**示例:**

```js
1534 1535
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.indexedBy("SALARY_INDEX");
1536 1537
```

1538
### in
1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556

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

配置RdbPredicates以匹配数据字段为ValueType数组且值在给定范围内的指定字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                                 | 必填 | 说明                                    |
| ------ | ------------------------------------ | ---- | --------------------------------------- |
| field  | string                               | 是   | 数据库表中的列名。                      |
| value  | Array&lt;[ValueType](#valuetype)&gt; | 是   | 以ValueType型数组形式指定的要匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1557
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1558 1559 1560 1561

**示例:**

```js
1562 1563
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.in("AGE", [18, 20]);
1564 1565
```

1566
### notIn
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584

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

将RdbPredicates配置为匹配数据字段为ValueType且值超出给定范围的指定字段。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                                 | 必填 | 说明                                  |
| ------ | ------------------------------------ | ---- | ------------------------------------- |
| field  | string                               | 是   | 数据库表中的列名。                    |
| value  | Array&lt;[ValueType](#valuetype)&gt; | 是   | 以ValueType数组形式指定的要匹配的值。 |

**返回值**

| 类型                                 | 说明                       |
| ------------------------------------ | -------------------------- |
1585
| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1586 1587 1588 1589

**示例:**

```js
1590 1591
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.notIn("NAME", ["Lisa", "Rose"]);
1592 1593
```

1594
## RdbStore
1595 1596 1597

提供管理关系数据库(RDB)方法的接口。

L
lihuihui 已提交
1598
在使用以下相关接口前,请使用[executeSql](#executesql)接口初始化数据库表结构和相关数据。
1599

1600
### 属性<sup>10+</sup>
L
leiiyb 已提交
1601 1602 1603 1604 1605

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 名称         | 类型            | 必填 | 说明                             |
| ------------ | ----------- | ---- | -------------------------------- |
1606 1607 1608 1609 1610 1611
| version<sup>10+</sup>  | number | 是   | 设置和获取数据库版本,值为大于0的正整数。       |

**示例:**

```js
// 设置数据库版本
1612
store.version = 3;
1613
// 获取数据库版本
1614
console.info(`RdbStore version is ${store.version}`);
1615
```
L
leiiyb 已提交
1616

1617
### insert
1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632

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

向目标表中插入一行数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                          | 必填 | 说明                                                       |
| -------- | ----------------------------- | ---- | ---------------------------------------------------------- |
| table    | string                        | 是   | 指定的目标表名。                                           |
| values   | [ValuesBucket](#valuesbucket) | 是   | 表示要插入到表中的数据行。                                 |
| callback | AsyncCallback&lt;number&gt;   | 是   | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 |

1633 1634 1635 1636
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
1637 1638 1639 1640
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
1641

1642 1643 1644 1645
**示例:**

```js
const valueBucket = {
1646 1647 1648 1649 1650 1651 1652
  "NAME": "Lisa",
  "AGE": 18,
  "SALARY": 100.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
store.insert("EMPLOYEE", valueBucket, function (err, rowId) {
  if (err) {
G
ge-yafang 已提交
1653
    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
1654 1655 1656
    return;
  }
  console.info(`Insert is successful, rowId = ${rowId}`);
1657 1658 1659
})
```

L
lihuihui 已提交
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
### insert<sup>10+</sup>

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

向目标表中插入一行数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                                        | 必填 | 说明                                                       |
| -------- | ------------------------------------------- | ---- | ---------------------------------------------------------- |
| table    | string                                      | 是   | 指定的目标表名。                                           |
| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。                                 |
P
PaDaBoo 已提交
1674
| conflict | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决方式。                                         |
L
lihuihui 已提交
1675 1676
| callback | AsyncCallback&lt;number&gt;                 | 是   | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 |

1677 1678 1679 1680
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
1681 1682 1683 1684
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
1685

L
lihuihui 已提交
1686 1687 1688 1689
**示例:**

```js
const valueBucket = {
1690 1691 1692 1693 1694 1695 1696
  "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) {
G
ge-yafang 已提交
1697
    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
1698 1699 1700
    return;
  }
  console.info(`Insert is successful, rowId = ${rowId}`);
L
lihuihui 已提交
1701 1702 1703
})
```

1704
### insert
1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724

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

向目标表中插入一行数据,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                          | 必填 | 说明                       |
| ------ | ----------------------------- | ---- | -------------------------- |
| table  | string                        | 是   | 指定的目标表名。           |
| values | [ValuesBucket](#valuesbucket) | 是   | 表示要插入到表中的数据行。 |

**返回值**

| 类型                  | 说明                                              |
| --------------------- | ------------------------------------------------- |
| Promise&lt;number&gt; | Promise对象。如果操作成功,返回行ID;否则返回-1。 |

1725 1726 1727 1728
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
1729 1730 1731 1732
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
1733

1734 1735 1736 1737
**示例:**

```js
const valueBucket = {
1738 1739 1740 1741 1742 1743
  "NAME": "Lisa",
  "AGE": 18,
  "SALARY": 100.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
let promise = store.insert("EMPLOYEE", valueBucket);
1744
promise.then((rowId) => {
1745 1746
  console.info(`Insert is successful, rowId = ${rowId}`);
}).catch((err) => {
G
ge-yafang 已提交
1747
  console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
1748 1749 1750
})
```

L
lihuihui 已提交
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764
### insert<sup>10+</sup>

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

向目标表中插入一行数据,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                                        | 必填 | 说明                       |
| -------- | ------------------------------------------- | ---- | -------------------------- |
| table    | string                                      | 是   | 指定的目标表名。           |
| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。 |
P
PaDaBoo 已提交
1765
| conflict | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决方式。         |
L
lihuihui 已提交
1766 1767 1768 1769 1770 1771 1772

**返回值**

| 类型                  | 说明                                              |
| --------------------- | ------------------------------------------------- |
| Promise&lt;number&gt; | Promise对象。如果操作成功,返回行ID;否则返回-1。 |

1773 1774 1775 1776
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
1777 1778 1779 1780
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
1781

L
lihuihui 已提交
1782 1783 1784 1785
**示例:**

```js
const valueBucket = {
1786 1787 1788 1789 1790 1791
  "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);
L
lihuihui 已提交
1792
promise.then((rowId) => {
1793 1794
  console.info(`Insert is successful, rowId = ${rowId}`);
}).catch((err) => {
G
ge-yafang 已提交
1795
  console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
L
lihuihui 已提交
1796 1797 1798
})
```

1799
### batchInsert
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814

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

向目标表中插入一组数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                                       | 必填 | 说明                                                         |
| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
| table    | string                                     | 是   | 指定的目标表名。                                             |
| values   | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。                                 |
| callback | AsyncCallback&lt;number&gt;                | 是   | 指定callback回调函数。如果操作成功,返回插入的数据个数,否则返回-1。 |

1815 1816 1817 1818
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
1819 1820 1821 1822
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
1823

1824 1825 1826 1827
**示例:**

```js
const valueBucket1 = {
1828 1829 1830 1831 1832
  "NAME": "Lisa",
  "AGE": 18,
  "SALARY": 100.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5])
};
1833
const valueBucket2 = {
1834 1835 1836 1837 1838
  "NAME": "Jack",
  "AGE": 19,
  "SALARY": 101.5,
  "CODES": new Uint8Array([6, 7, 8, 9, 10])
};
1839
const valueBucket3 = {
1840 1841 1842 1843 1844
  "NAME": "Tom",
  "AGE": 20,
  "SALARY": 102.5,
  "CODES": new Uint8Array([11, 12, 13, 14, 15])
};
1845 1846

let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
1847 1848
store.batchInsert("EMPLOYEE", valueBuckets, function(err, insertNum) {
  if (err) {
G
ge-yafang 已提交
1849
    console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
1850 1851 1852
    return;
  }
  console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
1853 1854 1855
})
```

1856
### batchInsert
1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876

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

向目标表中插入一组数据,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型                                       | 必填 | 说明                         |
| ------ | ------------------------------------------ | ---- | ---------------------------- |
| table  | string                                     | 是   | 指定的目标表名。             |
| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。 |

**返回值**

| 类型                  | 说明                                                        |
| --------------------- | ----------------------------------------------------------- |
| Promise&lt;number&gt; | Promise对象。如果操作成功,返回插入的数据个数,否则返回-1。 |

1877 1878 1879 1880
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
1881 1882 1883 1884
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
1885

1886 1887 1888 1889
**示例:**

```js
const valueBucket1 = {
1890 1891 1892 1893 1894
  "NAME": "Lisa",
  "AGE": 18,
  "SALARY": 100.5,
  "CODES": new Uint8Array([1, 2, 3, 4, 5])
};
1895
const valueBucket2 = {
1896 1897 1898 1899 1900
  "NAME": "Jack",
  "AGE": 19,
  "SALARY": 101.5,
  "CODES": new Uint8Array([6, 7, 8, 9, 10])
};
1901
const valueBucket3 = {
1902 1903 1904 1905 1906
  "NAME": "Tom",
  "AGE": 20,
  "SALARY": 102.5,
  "CODES": new Uint8Array([11, 12, 13, 14, 15])
};
1907 1908

let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
1909
let promise = store.batchInsert("EMPLOYEE", valueBuckets);
1910
promise.then((insertNum) => {
1911 1912
  console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
}).catch((err) => {
G
ge-yafang 已提交
1913
  console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
1914 1915 1916
})
```

1917
### update
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929

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

根据RdbPredicates的指定实例对象更新数据库中的数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名     | 类型                                 | 必填 | 说明                                                         |
| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| values     | [ValuesBucket](#valuesbucket)        | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
1930
| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的更新条件。                    |
1931 1932
| callback   | AsyncCallback&lt;number&gt;          | 是   | 指定的callback回调方法。返回受影响的行数。                   |

1933 1934 1935 1936
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
1937 1938 1939 1940
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
1941

1942 1943 1944 1945
**示例:**

```js
const valueBucket = {
1946 1947 1948 1949 1950 1951 1952 1953 1954
  "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) {
G
ge-yafang 已提交
1955
    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
1956 1957 1958
    return;
  }
  console.info(`Updated row count: ${rows}`);
1959 1960 1961
})
```

L
lihuihui 已提交
1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
### update<sup>10+</sup>

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

根据RdbPredicates的指定实例对象更新数据库中的数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名     | 类型                                        | 必填 | 说明                                                         |
| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
1975
| predicates | [RdbPredicates](#rdbpredicates)            | 是   | RdbPredicates的实例对象指定的更新条件。                      |
P
PaDaBoo 已提交
1976
| conflict   | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决方式。                                           |
L
lihuihui 已提交
1977 1978
| callback   | AsyncCallback&lt;number&gt;                 | 是   | 指定的callback回调方法。返回受影响的行数。                   |

1979 1980 1981 1982
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
1983 1984 1985 1986
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
1987

L
lihuihui 已提交
1988 1989 1990 1991
**示例:**

```js
const valueBucket = {
1992 1993 1994 1995 1996 1997 1998 1999 2000
  "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) {
G
ge-yafang 已提交
2001
    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
2002 2003 2004
    return;
  }
  console.info(`Updated row count: ${rows}`);
L
lihuihui 已提交
2005 2006 2007
})
```

2008
### update
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020

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

根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名       | 类型                                 | 必填 | 说明                                                         |
| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
| values       | [ValuesBucket](#valuesbucket)        | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
2021
| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的更新条件。                    |
2022 2023 2024 2025 2026 2027 2028

**返回值**

| 类型                  | 说明                                      |
| --------------------- | ----------------------------------------- |
| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |

2029 2030 2031 2032
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
2033 2034 2035 2036
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
2037

2038 2039 2040 2041
**示例:**

```js
const valueBucket = {
2042 2043 2044 2045 2046 2047 2048 2049
  "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);
P
PaDaBoo 已提交
2050
promise.then(async (rows) => {
2051
  console.info(`Updated row count: ${rows}`);
2052
}).catch((err) => {
G
ge-yafang 已提交
2053
  console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
2054 2055 2056
})
```

L
lihuihui 已提交
2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069
### update<sup>10+</sup>

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

根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名     | 类型                                        | 必填 | 说明                                                         |
| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
2070
| predicates | [RdbPredicates](#rdbpredicates)            | 是   | RdbPredicates的实例对象指定的更新条件。                      |
P
PaDaBoo 已提交
2071
| conflict   | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决方式。                                           |
L
lihuihui 已提交
2072 2073 2074 2075 2076 2077 2078

**返回值**

| 类型                  | 说明                                      |
| --------------------- | ----------------------------------------- |
| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |

2079 2080 2081 2082
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
2083 2084 2085 2086
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
2087

L
lihuihui 已提交
2088 2089 2090 2091
**示例:**

```js
const valueBucket = {
2092 2093 2094 2095 2096 2097 2098 2099
  "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);
P
PaDaBoo 已提交
2100
promise.then(async (rows) => {
2101
  console.info(`Updated row count: ${rows}`);
L
lihuihui 已提交
2102
}).catch((err) => {
G
ge-yafang 已提交
2103
  console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
L
lihuihui 已提交
2104 2105 2106
})
```

2107
### update
2108 2109 2110 2111 2112 2113 2114

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

根据DataSharePredicates的指定实例对象更新数据库中的数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

G
ge-yafang 已提交
2115 2116
**模型约束:** 此接口仅可在Stage模型下可用。

2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127
**系统接口:** 此接口为系统接口。

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                                                         |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| table      | string                                                       | 是   | 指定的目标表名。                                             |
| values     | [ValuesBucket](#valuesbucket)                                | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是   | DataSharePredicates的实例对象指定的更新条件。                |
| callback   | AsyncCallback&lt;number&gt;                                  | 是   | 指定的callback回调方法。返回受影响的行数。                   |

2128 2129 2130 2131
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
2132 2133 2134 2135
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
2136

2137 2138 2139 2140 2141 2142 2143 2144 2145
**示例:**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
const valueBucket = {
    "NAME": "Rose",
    "AGE": 22,
    "SALARY": 200.5,
    "CODES": new Uint8Array([1, 2, 3, 4, 5]),
2146 2147 2148 2149 2150
};
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Lisa");
store.update("EMPLOYEE", valueBucket, predicates, function (err, rows) {
  if (err) {
G
ge-yafang 已提交
2151
    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
2152 2153 2154
    return;
  }
  console.info(`Updated row count: ${rows}`);
2155 2156 2157
})
```

2158
### update
2159 2160 2161 2162 2163 2164 2165

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

根据DataSharePredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

G
ge-yafang 已提交
2166 2167
**模型约束:** 此接口仅可在Stage模型下可用。

2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183
**系统接口:** 此接口为系统接口。

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                                                         |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| table      | string                                                       | 是   | 指定的目标表名。                                             |
| values     | [ValuesBucket](#valuesbucket)                                | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是   | DataSharePredicates的实例对象指定的更新条件。                |

**返回值**

| 类型                  | 说明                                      |
| --------------------- | ----------------------------------------- |
| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |

2184 2185 2186 2187
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
2188 2189 2190 2191
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
2192

2193 2194 2195 2196 2197
**示例:**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
const valueBucket = {
2198 2199 2200 2201 2202 2203 2204 2205
  "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);
P
PaDaBoo 已提交
2206
promise.then(async (rows) => {
2207
  console.info(`Updated row count: ${rows}`);
2208
}).catch((err) => {
G
ge-yafang 已提交
2209
  console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
2210 2211 2212
})
```

2213
### delete
2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224

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

根据RdbPredicates的指定实例对象从数据库中删除数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名     | 类型                                 | 必填 | 说明                                      |
| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
2225
| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
2226 2227
| callback   | AsyncCallback&lt;number&gt;          | 是   | 指定callback回调函数。返回受影响的行数。  |

2228 2229 2230 2231
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
2232 2233 2234 2235
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
2236

2237 2238 2239
**示例:**

```js
2240 2241 2242 2243
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa");
store.delete(predicates, function (err, rows) {
  if (err) {
G
ge-yafang 已提交
2244
    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
2245 2246 2247
    return;
  }
  console.info(`Delete rows: ${rows}`);
2248 2249 2250
})
```

2251
### delete
2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262

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

根据RdbPredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名     | 类型                                 | 必填 | 说明                                      |
| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
2263
| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
2264 2265 2266 2267 2268 2269 2270

**返回值**

| 类型                  | 说明                            |
| --------------------- | ------------------------------- |
| Promise&lt;number&gt; | Promise对象。返回受影响的行数。 |

2271 2272 2273 2274
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
2275 2276 2277 2278
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
2279

2280 2281 2282
**示例:**

```js
2283 2284 2285
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa");
let promise = store.delete(predicates);
2286
promise.then((rows) => {
2287
  console.info(`Delete rows: ${rows}`);
2288
}).catch((err) => {
G
ge-yafang 已提交
2289
  console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
2290 2291 2292
})
```

2293
### delete
2294 2295 2296 2297 2298 2299 2300

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

根据DataSharePredicates的指定实例对象从数据库中删除数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

G
ge-yafang 已提交
2301 2302
**模型约束:** 此接口仅可在Stage模型下可用。

2303 2304 2305 2306 2307 2308 2309 2310 2311 2312
**系统接口:** 此接口为系统接口。

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                                          |
| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- |
| table      | string                                                       | 是   | 指定的目标表名。                              |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是   | DataSharePredicates的实例对象指定的删除条件。 |
| callback   | AsyncCallback&lt;number&gt;                                  | 是   | 指定callback回调函数。返回受影响的行数。      |

2313 2314 2315 2316
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
2317 2318 2319 2320
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
2321

2322 2323 2324 2325
**示例:**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
2326 2327 2328 2329
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Lisa");
store.delete("EMPLOYEE", predicates, function (err, rows) {
  if (err) {
G
ge-yafang 已提交
2330
    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
2331 2332 2333
    return;
  }
  console.info(`Delete rows: ${rows}`);
2334 2335 2336
})
```

2337
### delete
2338 2339 2340 2341 2342 2343 2344

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

根据DataSharePredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

G
ge-yafang 已提交
2345 2346
**模型约束:** 此接口仅可在Stage模型下可用。

2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361
**系统接口:** 此接口为系统接口。

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                                          |
| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- |
| table      | string                                                       | 是   | 指定的目标表名。                              |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是   | DataSharePredicates的实例对象指定的删除条件。 |

**返回值**

| 类型                  | 说明                            |
| --------------------- | ------------------------------- |
| Promise&lt;number&gt; | Promise对象。返回受影响的行数。 |

2362 2363 2364 2365
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
2366 2367 2368 2369
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
2370

2371 2372 2373 2374
**示例:**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
2375 2376 2377
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Lisa");
let promise = store.delete("EMPLOYEE", predicates);
2378
promise.then((rows) => {
2379
  console.info(`Delete rows: ${rows}`);
2380
}).catch((err) => {
G
ge-yafang 已提交
2381
  console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
2382 2383 2384
})
```

2385
### query
2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396

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

根据指定条件查询数据库中的数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                                                        |
| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
2397
| predicates | [RdbPredicates](#rdbpredicates)                         | 是   | RdbPredicates的实例对象指定的查询条件。                   |
2398
| columns    | Array&lt;string&gt;                                          | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。            |
P
PaDaBoo 已提交
2399
| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
2400

L
LiRui 已提交
2401 2402 2403 2404 2405 2406 2407 2408
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

2409 2410 2411
**示例:**

```js
2412 2413 2414 2415
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose");
store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
  if (err) {
G
ge-yafang 已提交
2416
    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2417 2418
    return;
  }
M
MangTsang 已提交
2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
  while(resultSet.goToNextRow()) {
    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}`);
  }
  // 释放数据集的内存
  resultSet.close();
2430 2431 2432
})
```

2433
### query
2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444

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

根据指定条件查询数据库中的数据,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名     | 类型                                 | 必填 | 说明                                             |
| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
2445
| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。        |
2446 2447
| columns    | Array&lt;string&gt;                  | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。 |

L
LiRui 已提交
2448 2449 2450 2451 2452 2453 2454 2455
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

2456 2457 2458 2459
**返回值**

| 类型                                                    | 说明                                               |
| ------------------------------------------------------- | -------------------------------------------------- |
P
PaDaBoo 已提交
2460
| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
2461 2462 2463 2464

**示例:**

  ```js
2465 2466 2467
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
2468
promise.then((resultSet) => {
M
MangTsang 已提交
2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
  while(resultSet.goToNextRow()) {
    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}`);
  }
  // 释放数据集的内存
  resultSet.close();
2480
}).catch((err) => {
G
ge-yafang 已提交
2481
  console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2482 2483 2484
})
  ```

2485
### query
2486 2487 2488 2489 2490 2491 2492

query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void

根据指定条件查询数据库中的数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

G
ge-yafang 已提交
2493 2494
**模型约束:** 此接口仅可在Stage模型下可用。

2495 2496 2497 2498 2499 2500 2501 2502 2503
**系统接口:** 此接口为系统接口。

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                                                        |
| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| table      | string                                                       | 是   | 指定的目标表名。                                            |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是   | DataSharePredicates的实例对象指定的查询条件。               |
| columns    | Array&lt;string&gt;                                          | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。            |
P
PaDaBoo 已提交
2504
| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
2505

L
LiRui 已提交
2506 2507 2508 2509 2510 2511 2512 2513
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

2514 2515 2516 2517
**示例:**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
2518 2519 2520 2521
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Rose");
store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
  if (err) {
G
ge-yafang 已提交
2522
    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2523 2524
    return;
  }
M
MangTsang 已提交
2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
  while(resultSet.goToNextRow()) {
    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}`);
  }
  // 释放数据集的内存
  resultSet.close();
2536 2537 2538
})
```

2539
### query
2540 2541 2542 2543 2544 2545 2546

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

根据指定条件查询数据库中的数据,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

G
ge-yafang 已提交
2547 2548
**模型约束:** 此接口仅可在Stage模型下可用。

2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562
**系统接口:** 此接口为系统接口。

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                                             |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ |
| table      | string                                                       | 是   | 指定的目标表名。                                 |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是   | DataSharePredicates的实例对象指定的查询条件。    |
| columns    | Array&lt;string&gt;                                          | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。 |

**返回值**

| 类型                                                    | 说明                                               |
| ------------------------------------------------------- | -------------------------------------------------- |
P
PaDaBoo 已提交
2563
| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
2564

L
LiRui 已提交
2565 2566 2567 2568 2569 2570 2571 2572
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

2573 2574 2575 2576
**示例:**

```js
import dataSharePredicates from '@ohos.data.dataSharePredicates'
2577 2578 2579
let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Rose");
let promise = store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
2580
promise.then((resultSet) => {
M
MangTsang 已提交
2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
  while(resultSet.goToNextRow()) {
    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}`);
  }
  // 释放数据集的内存
  resultSet.close();
2592
}).catch((err) => {
G
ge-yafang 已提交
2593
  console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2594 2595 2596
})
```

2597
### remoteQuery
2598 2599 2600 2601 2602

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

根据指定条件查询远程设备数据库中的数据。使用callback异步回调。

L
devices  
lihuihui 已提交
2603 2604 2605 2606
> **说明:**
>
> 其中device通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。

L
device  
lihuihui 已提交
2607 2608
**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

2609 2610
**参数:**

L
device  
lihuihui 已提交
2611 2612 2613 2614 2615 2616
| 参数名     | 类型                                         | 必填 | 说明                                                      |
| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- |
| device     | string                                       | 是   | 指定的远程设备ID。                                        |
| table      | string                                       | 是   | 指定的目标表名。                                          |
| predicates | [RdbPredicates](#rdbpredicates)              | 是   | RdbPredicates的实例对象,指定查询的条件。                 |
| columns    | Array&lt;string&gt;                          | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。          |
P
PaDaBoo 已提交
2617
| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
2618

L
LiRui 已提交
2619 2620 2621 2622 2623 2624 2625 2626
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

2627 2628 2629
**示例:**

```js
L
device  
lihuihui 已提交
2630 2631
import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null;
L
lihuihui 已提交
2632
let deviceId = null;
L
device  
lihuihui 已提交
2633 2634 2635 2636 2637 2638 2639 2640

deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
    if (err) {
        console.log("create device manager failed, err=" + err);
        return;
    }
    dmInstance = manager;
    let devices = dmInstance.getTrustedDeviceListSync();
L
lihuihui 已提交
2641
    deviceId = devices[0].deviceId;
L
device  
lihuihui 已提交
2642 2643
})

2644 2645
let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.greaterThan("id", 0);
L
device  
lihuihui 已提交
2646
store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"],
2647
  function(err, resultSet) {
2648
    if (err) {
G
ge-yafang 已提交
2649
      console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
2650
      return;
2651
    }
M
MangTsang 已提交
2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662
    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
    while(resultSet.goToNextRow()) {
      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}`);
    }
    // 释放数据集的内存
    resultSet.close();
2663 2664
  }
)
2665 2666
```

2667
### remoteQuery
2668 2669 2670 2671 2672

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

根据指定条件查询远程设备数据库中的数据。使用Promise异步回调。

L
devices  
lihuihui 已提交
2673 2674 2675 2676
> **说明:**
>
> 其中device通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。

L
device  
lihuihui 已提交
2677 2678
**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

2679 2680 2681 2682
**参数:**

| 参数名     | 类型                                 | 必填 | 说明                                             |
| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
L
device  
lihuihui 已提交
2683
| device     | string                               | 是   | 指定的远程设备ID。                   |
2684
| table      | string                               | 是   | 指定的目标表名。                                 |
2685
| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象,指定查询的条件。      |
2686 2687 2688 2689 2690 2691
| columns    | Array&lt;string&gt;                  | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。 |

**返回值**

| 类型                                                         | 说明                                               |
| ------------------------------------------------------------ | -------------------------------------------------- |
P
PaDaBoo 已提交
2692
| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
2693

L
LiRui 已提交
2694 2695 2696 2697 2698 2699 2700 2701
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

2702 2703 2704
**示例:**

```js
L
device  
lihuihui 已提交
2705 2706
import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null;
L
lihuihui 已提交
2707
let deviceId = null;
L
device  
lihuihui 已提交
2708 2709 2710 2711 2712 2713 2714 2715

deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
    if (err) {
        console.log("create device manager failed, err=" + err);
        return;
    }
    dmInstance = manager;
    let devices = dmInstance.getTrustedDeviceListSync();
L
lihuihui 已提交
2716
    deviceId = devices[0].deviceId;
L
device  
lihuihui 已提交
2717 2718
})

2719 2720
let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.greaterThan("id", 0);
L
lihuihui 已提交
2721
let promise = store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
2722
promise.then((resultSet) => {
M
MangTsang 已提交
2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
  while(resultSet.goToNextRow()) {
    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}`);
  }
  // 释放数据集的内存
  resultSet.close();
2734
}).catch((err) => {
G
ge-yafang 已提交
2735
  console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
2736 2737 2738
})
```

M
marui 已提交
2739
### querySql<sup>10+</sup>
2740

M
marui 已提交
2741
querySql(sql: string, callback: AsyncCallback&lt;ResultSet&gt;):void
M
marui 已提交
2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783

根据指定SQL语句查询数据库中的数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                                         | 必填 | 说明                                                         |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| sql      | string                                       | 是   | 指定要执行的SQL语句。                                        |
| callback | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。    |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

**示例:**

```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是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
  while(resultSet.goToNextRow()) {
    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}`);
  }
  // 释放数据集的内存
  resultSet.close();
})
```

2784
### querySql
2785 2786 2787 2788 2789 2790 2791 2792 2793

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

根据指定SQL语句查询数据库中的数据,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

L
query  
lihuihui 已提交
2794 2795 2796
| 参数名   | 类型                                         | 必填 | 说明                                                         |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| sql      | string                                       | 是   | 指定要执行的SQL语句。                                        |
L
lihuihui 已提交
2797
| bindArgs | Array&lt;[ValueType](#valuetype)&gt;         | 是   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数需为空数组。 |
L
query  
lihuihui 已提交
2798
| callback | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。    |
2799

L
LiRui 已提交
2800 2801 2802 2803 2804 2805 2806 2807
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

2808 2809 2810
**示例:**

```js
2811 2812
store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
  if (err) {
G
ge-yafang 已提交
2813
    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2814 2815
    return;
  }
M
MangTsang 已提交
2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
  while(resultSet.goToNextRow()) {
    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}`);
  }
  // 释放数据集的内存
  resultSet.close();
2827 2828 2829
})
```

2830
### querySql
2831 2832 2833 2834 2835 2836 2837 2838 2839

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

根据指定SQL语句查询数据库中的数据,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

L
query  
lihuihui 已提交
2840 2841 2842 2843
| 参数名   | 类型                                 | 必填 | 说明                                                         |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
2844 2845 2846 2847 2848

**返回值**

| 类型                                                    | 说明                                               |
| ------------------------------------------------------- | -------------------------------------------------- |
P
PaDaBoo 已提交
2849
| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
2850

L
LiRui 已提交
2851 2852 2853 2854 2855 2856 2857 2858
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

2859 2860 2861
**示例:**

```js
L
RDB  
lihuihui 已提交
2862
let promise = store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'");
2863
promise.then((resultSet) => {
M
MangTsang 已提交
2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874
  console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
  // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
  while(resultSet.goToNextRow()) {
    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}`);
  }
  // 释放数据集的内存
  resultSet.close();
2875
}).catch((err) => {
G
ge-yafang 已提交
2876
  console.error(`Query failed, code is ${err.code},message is ${err.message}`);
2877 2878 2879
})
```

M
marui 已提交
2880
### executeSql<sup>10+</sup>
2881

M
marui 已提交
2882
executeSql(sql: string, callback: AsyncCallback&lt;void&gt;):void
M
marui 已提交
2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916

执行包含指定参数但不返回值的SQL语句,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                                 | 必填 | 说明                                                         |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
| callback | AsyncCallback&lt;void&gt;            | 是   | 指定callback回调函数。                                       |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |

**示例:**

```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.`);
})
```

2917
### executeSql
2918 2919 2920 2921 2922 2923 2924 2925 2926

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

执行包含指定参数但不返回值的SQL语句,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

L
query  
lihuihui 已提交
2927 2928 2929
| 参数名   | 类型                                 | 必填 | 说明                                                         |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
L
lihuihui 已提交
2930
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 是   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数需为空数组。 |
L
query  
lihuihui 已提交
2931
| callback | AsyncCallback&lt;void&gt;            | 是   | 指定callback回调函数。                                       |
2932

2933 2934 2935 2936
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
2937 2938 2939 2940
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
2941

2942 2943 2944
**示例:**

```js
L
RDB  
lihuihui 已提交
2945 2946
const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?"
store.executeSql(SQL_DELETE_TABLE, ['zhangsan'], function(err) {
2947
  if (err) {
G
ge-yafang 已提交
2948
    console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
2949 2950
    return;
  }
L
RDB  
lihuihui 已提交
2951
  console.info(`Delete table done.`);
2952 2953 2954
})
```

2955
### executeSql
2956 2957 2958 2959 2960 2961 2962 2963 2964

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

执行包含指定参数但不返回值的SQL语句,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

L
query  
lihuihui 已提交
2965 2966 2967 2968
| 参数名   | 类型                                 | 必填 | 说明                                                         |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
2969 2970 2971 2972 2973 2974 2975

**返回值**

| 类型                | 说明                      |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

2976 2977 2978 2979
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
2980 2981 2982 2983
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
2984

2985 2986 2987
**示例:**

```js
L
RDB  
lihuihui 已提交
2988 2989
const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"
let promise = store.executeSql(SQL_DELETE_TABLE);
2990
promise.then(() => {
L
RDB  
lihuihui 已提交
2991
    console.info(`Delete table done.`);
2992
}).catch((err) => {
G
ge-yafang 已提交
2993
    console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
2994 2995 2996
})
```

R
renjiecui 已提交
2997 2998
### getModifyTime<sup>10+</sup>

R
renjiecui 已提交
2999
getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[], callback: AsyncCallback&lt;ModifyTime&gt;): void
R
renjiecui 已提交
3000

R
renjiecui 已提交
3001
获取数据库表中数据的最后修改时间,使用callback异步回调。
R
renjiecui 已提交
3002 3003 3004 3005 3006

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

R
renjiecui 已提交
3007 3008 3009 3010 3011 3012
| 参数名      | 类型                                             | 必填 | 说明                                                         |
| ----------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| table       | string                                           | 是   | 指定要查询的数据库表的表名。                                 |
| columnName  | string                                           | 是   | 指定要查询的数据库表的列名。                                 |
| primaryKeys | [PRIKeyType](#prikeytype10)[]                    | 是   | 指定要查询的行的主键。<br>如果数据库表无主键,参数columnName需传入"rowid",此时primaryKeys为要查询的数据库表的行号。<br>如果数据库表无主键,参数columnName传入不为"rowid",返回对应的错误码。 |
| callback    | AsyncCallback&lt;[ModifyTime](#modifytime10)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ModifyTime对象,表示数据的最后修改时间。 |
R
renjiecui 已提交
3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息** |
| ------------ | ------------ |
| 14800000     | Inner error. |

**示例:**

```js
R
renjiecui 已提交
3025 3026 3027 3028 3029 3030
let PRIKey = [1, 4, 2, 3];
relationalStore.getModifyTime("cloud_tasks", "uuid", PRIKey, function (err, modifyTime) {
    if (err) {
        console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`);
        return;
    }
R
renjiecui 已提交
3031 3032 3033 3034 3035 3036
    let size = modifyTime.size();
});
```

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

R
renjiecui 已提交
3037
getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[]): Promise&lt;ModifyTime&gt;
R
renjiecui 已提交
3038

R
renjiecui 已提交
3039
获取数据库表中数据的最后修改时间,使用Promise异步回调。
R
renjiecui 已提交
3040 3041 3042 3043 3044

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

R
renjiecui 已提交
3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055
| 参数名      | 类型                          | 必填 | 说明                                                         |
| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ |
| table       | string                        | 是   | 指定要查询的数据库表的表名。                                 |
| columnName  | string                        | 是   | 指定要查询的数据库表的列名。                                 |
| primaryKeys | [PRIKeyType](#prikeytype10)[] | 是   | 指定要查询的行的主键。<br>如果数据库表无主键,参数columnName需传入"rowid",此时primaryKeys为要查询的数据库表的行号。<br>如果数据库表无主键,参数columnName传入不为"rowid",返回对应的错误码。 |

**返回值**

| 类型                                       | 说明                                                      |
| ------------------------------------------ | --------------------------------------------------------- |
| Promise&lt;[ModifyTime](#modifytime10)&gt; | 返回ModifyTime类型的Promise对象,表示数据最后的修改时间。 |
R
renjiecui 已提交
3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息** |
| ------------ | ------------ |
| 14800000     | Inner error. |

**示例:**

```js
R
renjiecui 已提交
3068 3069
let PRIKey = [1, 2, 3];
relationalStore.getModifyTime("cloud_tasks", "uuid", PRIKey).then((modifyTime) => {
R
renjiecui 已提交
3070
    let size = modifyTime.size();
R
renjiecui 已提交
3071 3072
}).catch((err) => {
    console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`);
R
renjiecui 已提交
3073 3074 3075
});
```

3076
### beginTransaction
3077 3078 3079 3080 3081 3082 3083

beginTransaction():void

在开始执行SQL语句之前,开始事务。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

3084 3085 3086 3087
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

L
LiRui 已提交
3088 3089 3090 3091
| **错误码ID** | **错误信息**                                 |
| ------------ | -------------------------------------------- |
| 14800047     | The WAL file size exceeds the default limit. |
| 14800000     | Inner error.                                 |
3092

3093 3094 3095 3096
**示例:**

```js
import featureAbility from '@ohos.ability.featureAbility'
3097 3098 3099 3100 3101 3102 3103
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) {
G
ge-yafang 已提交
3104
    console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`);
3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115
    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();
3116 3117 3118
})
```

3119
### commit
3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130

commit():void

提交已执行的SQL语句。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**示例:**

```js
import featureAbility from '@ohos.ability.featureAbility'
3131 3132 3133 3134 3135 3136 3137
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) {
G
ge-yafang 已提交
3138
     console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`);
3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149
     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();
3150 3151 3152
})
```

3153
### rollBack
3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164

rollBack():void

回滚已经执行的SQL语句。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**示例:**

```js
import featureAbility from '@ohos.ability.featureAbility'
3165 3166 3167 3168 3169 3170 3171
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) {
G
ge-yafang 已提交
3172
    console.error(`GetRdbStore failed, code is ${err.code},message is ${err.message}`);
3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186
    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) {
G
ge-yafang 已提交
3187
    console.error(`Transaction failed, code is ${err.code},message is ${err.message}`);
3188 3189
    store.rollBack();
  }
3190 3191 3192
})
```

3193
### backup
3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207

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

以指定名称备份数据库,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                      | 必填 | 说明                     |
| -------- | ------------------------- | ---- | ------------------------ |
| destName | string                    | 是   | 指定数据库的备份文件名。 |
| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。   |

L
LiRui 已提交
3208 3209 3210 3211 3212 3213 3214 3215
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

3216 3217 3218
**示例:**

```js
3219 3220
store.backup("dbBackup.db", function(err) {
  if (err) {
G
ge-yafang 已提交
3221
    console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
3222 3223 3224
    return;
  }
  console.info(`Backup success.`);
3225 3226 3227
})
```

3228
### backup
3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247

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

以指定名称备份数据库,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型   | 必填 | 说明                     |
| -------- | ------ | ---- | ------------------------ |
| destName | string | 是   | 指定数据库的备份文件名。 |

**返回值**

| 类型                | 说明                      |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

L
LiRui 已提交
3248 3249 3250 3251 3252 3253 3254 3255
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

3256 3257 3258
**示例:**

```js
3259
let promiseBackup = store.backup("dbBackup.db");
3260
promiseBackup.then(()=>{
3261
  console.info(`Backup success.`);
3262
}).catch((err)=>{
G
ge-yafang 已提交
3263
  console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
3264 3265 3266
})
```

3267
### restore
3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281

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

从指定的数据库备份文件恢复数据库,使用callback异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                      | 必填 | 说明                     |
| -------- | ------------------------- | ---- | ------------------------ |
| srcName  | string                    | 是   | 指定数据库的备份文件名。 |
| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。   |

L
LiRui 已提交
3282 3283 3284 3285 3286 3287 3288 3289
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

3290 3291 3292
**示例:**

```js
3293 3294
store.restore("dbBackup.db", function(err) {
  if (err) {
G
ge-yafang 已提交
3295
    console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
3296 3297 3298
    return;
  }
  console.info(`Restore success.`);
3299 3300 3301
})
```

3302
### restore
3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321

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

从指定的数据库备份文件恢复数据库,使用Promise异步回调。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名  | 类型   | 必填 | 说明                     |
| ------- | ------ | ---- | ------------------------ |
| srcName | string | 是   | 指定数据库的备份文件名。 |

**返回值**

| 类型                | 说明                      |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

L
LiRui 已提交
3322 3323 3324 3325 3326 3327 3328 3329
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

3330 3331 3332
**示例:**

```js
3333
let promiseRestore = store.restore("dbBackup.db");
3334
promiseRestore.then(()=>{
3335
  console.info(`Restore success.`);
3336
}).catch((err)=>{
G
ge-yafang 已提交
3337
  console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
3338 3339 3340
})
```

3341
### setDistributedTables
3342 3343 3344

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

R
renjiecui 已提交
3345
设置分布式数据库表,使用callback异步回调。
3346 3347 3348 3349 3350 3351 3352 3353 3354

**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                      | 必填 | 说明                   |
| -------- | ------------------------- | ---- | ---------------------- |
R
renjiecui 已提交
3355
| tables   | Array&lt;string&gt;       | 是   | 要设置的分布式数据库表表名。 |
3356 3357
| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。 |

L
LiRui 已提交
3358 3359 3360 3361 3362 3363 3364 3365
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

3366 3367 3368
**示例:**

```js
3369 3370
store.setDistributedTables(["EMPLOYEE"], function (err) {
  if (err) {
G
ge-yafang 已提交
3371
    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
3372 3373 3374
    return;
  }
  console.info(`SetDistributedTables successfully.`);
3375 3376 3377
})
```

R
renjiecui 已提交
3378
### setDistributedTables
R
renjiecui 已提交
3379

R
renjiecui 已提交
3380
 setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt;
R
renjiecui 已提交
3381

R
renjiecui 已提交
3382
设置分布式数据库表,使用Promise异步回调。
R
renjiecui 已提交
3383 3384 3385 3386 3387 3388 3389

**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

R
renjiecui 已提交
3390 3391
| 参数名 | 类型                     | 必填 | 说明                     |
| ------ | ------------------------ | ---- | ------------------------ |
R
renjiecui 已提交
3392
| tables | ArrayArray&lt;string&gt; | 是   | 要设置的分布式数据库表表名。 |
R
renjiecui 已提交
3393 3394 3395 3396 3397 3398

**返回值**

| 类型                | 说明                      |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
R
renjiecui 已提交
3399 3400 3401

**错误码:**

3402
以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)
R
renjiecui 已提交
3403 3404 3405 3406 3407 3408 3409 3410

| **错误码ID** | **错误信息** |
| ------------ | ------------ |
| 14800000     | Inner error. |

**示例:**

```js
R
renjiecui 已提交
3411 3412
let promise = store.setDistributedTables(["EMPLOYEE"]);
promise.then(() => {
R
renjiecui 已提交
3413
  console.info(`SetDistributedTables successfully.`);
R
renjiecui 已提交
3414 3415
}).catch((err) => {
  console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
R
renjiecui 已提交
3416 3417 3418
})
```

R
renjiecui 已提交
3419
### setDistributedTables<sup>10+</sup>
3420

R
renjiecui 已提交
3421
setDistributedTables(tables: Array&lt;string&gt;, type: number, config: DistributedConfig, callback: AsyncCallback&lt;void&gt;): void
3422

R
renjiecui 已提交
3423
设置分布式数据库表,使用callback异步回调。
3424 3425 3426 3427 3428 3429 3430

**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

R
renjiecui 已提交
3431 3432
| 参数名      | 类型                                  | 必填  | 说明              |
| -------- | ----------------------------------- | --- | --------------- |
R
renjiecui 已提交
3433
| tables   | Array&lt;string&gt;                 | 是   | 要设置的分布式数据库表表名。     |
R
renjiecui 已提交
3434 3435 3436
| type     | number | 是   | 表的分布式类型。目前支持的入参值为: relationalStore.DistributedType.DISTRIBUTED_DEVICE、relationalStore.DistributedType.DISTRIBUTED_CLOUD。<br> 当type为relationalStore.DistributedType.DISTRIBUTED_DEVICE时,表示表在不同设备之间分布式。<br> 当type为relationalStore.DistributedType.DISTRIBUTED_CLOUD时,表示表在设备和云端之间分布式。 |
| config | [DistributedConfig](#distributedconfig10) | 是 | 表的分布式配置信息。 |
| callback | AsyncCallback&lt;void&gt;           | 是   | 指定callback回调函数。 |
3437 3438 3439 3440

**示例:**

```js
R
renjiecui 已提交
3441 3442
let config = new DistributedConfig();
config.autoSync = true;
R
renjiecui 已提交
3443 3444 3445 3446 3447
store.setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, config, function (err) {
  if (err) {
    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
    return;
  }
3448
  console.info(`SetDistributedTables successfully.`);
3449 3450
})
```
R
renjiecui 已提交
3451

R
renjiecui 已提交
3452 3453
### setDistributedTables<sup>10+</sup>

R
renjiecui 已提交
3454
 setDistributedTables(tables: Array&lt;string>, type?: number, config?: DistributedConfig): Promise&lt;void>
R
renjiecui 已提交
3455

R
renjiecui 已提交
3456
设置分布式数据库表,使用Promise异步回调。
R
renjiecui 已提交
3457 3458 3459 3460 3461 3462 3463

**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

R
renjiecui 已提交
3464 3465
| 参数名 | 类型                                      | 必填 | 说明                                                         |
| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ |
R
renjiecui 已提交
3466
| tables | Array&lt;string&gt;                       | 是   | 要设置的分布式数据库表表名。                                     |
R
renjiecui 已提交
3467 3468 3469 3470 3471 3472 3473 3474
| type   | number                                    | 否   | 表的分布式类型。默认值是relationalStore.DistributedType.DISTRIBUTED_DEVICE。<br> 目前支持的入参值为: relationalStore.DistributedType.DISTRIBUTED_DEVICE、relationalStore.DistributedType.DISTRIBUTED_CLOUD。<br/> 当type为relationalStore.DistributedType.DISTRIBUTED_DEVICE时,表示表在不同设备之间分布式。<br/> 当type为relationalStore.DistributedType.DISTRIBUTED_CLOUD时,表示表在设备和云端之间分布式。 |
| config | [DistributedConfig](#distributedconfig10) | 否   | 表的分布式配置信息。不传入时默认autoSync为false,即只支持手动同步。 |

**返回值**

| 类型                | 说明                      |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
R
renjiecui 已提交
3475 3476 3477 3478

**示例:**

```js
R
renjiecui 已提交
3479 3480
let config = new DistributedConfig();
config.autoSync = true;
R
renjiecui 已提交
3481 3482
let promise = store.setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, config);
promise.then(() => {
R
renjiecui 已提交
3483
  console.info(`SetDistributedTables successfully.`);
R
renjiecui 已提交
3484 3485
}).catch((err) => {
  console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
R
renjiecui 已提交
3486 3487 3488
})
```

3489
### obtainDistributedTableName
3490 3491 3492

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

L
device  
lihuihui 已提交
3493
根据远程设备的本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名, 使用callback异步回调。
3494

L
device  
lihuihui 已提交
3495 3496 3497 3498
> **说明:**
>
> 其中device通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。

L
device  
lihuihui 已提交
3499 3500 3501 3502
**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

3503 3504 3505 3506
**参数:**

| 参数名   | 类型                        | 必填 | 说明                                                         |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
L
device  
lihuihui 已提交
3507
| device   | string                      | 是   | 远程设备ID 。                                                |
L
devices  
lihuihui 已提交
3508
| table    | string                      | 是   | 远程设备的本地表名。                                         |
3509 3510
| callback | AsyncCallback&lt;string&gt; | 是   | 指定的callback回调函数。如果操作成功,返回远程设备的分布式表名。 |

L
LiRui 已提交
3511 3512 3513 3514 3515 3516 3517 3518
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

3519 3520 3521
**示例:**

```js
L
device  
lihuihui 已提交
3522 3523
import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null;
L
lihuihui 已提交
3524
let deviceId = null;
L
device  
lihuihui 已提交
3525 3526 3527 3528 3529 3530 3531 3532

deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
    if (err) {
        console.log("create device manager failed, err=" + err);
        return;
    }
    dmInstance = manager;
    let devices = dmInstance.getTrustedDeviceListSync();
L
lihuihui 已提交
3533
    deviceId = devices[0].deviceId;
L
device  
lihuihui 已提交
3534 3535 3536
})

store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) {
3537
    if (err) {
G
ge-yafang 已提交
3538
        console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
3539
        return;
3540
    }
3541
    console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
3542 3543 3544
})
```

3545
### obtainDistributedTableName
3546 3547 3548

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

L
device  
lihuihui 已提交
3549
根据远程设备的本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名,使用Promise异步回调。
3550

L
device  
lihuihui 已提交
3551 3552 3553 3554
> **说明:**
>
> 其中device通过调用[deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync)方法得到。deviceManager模块的接口均为系统接口,仅系统应用可用。

L
device  
lihuihui 已提交
3555 3556 3557 3558
**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

3559 3560
**参数:**

L
devices  
lihuihui 已提交
3561 3562
| 参数名 | 类型   | 必填 | 说明                 |
| ------ | ------ | ---- | -------------------- |
L
device  
lihuihui 已提交
3563
| device | string | 是   | 远程设备ID。         |
L
devices  
lihuihui 已提交
3564
| table  | string | 是   | 远程设备的本地表名。 |
3565 3566 3567 3568 3569 3570 3571

**返回值**

| 类型                  | 说明                                                  |
| --------------------- | ----------------------------------------------------- |
| Promise&lt;string&gt; | Promise对象。如果操作成功,返回远程设备的分布式表名。 |

L
LiRui 已提交
3572 3573 3574 3575 3576 3577 3578 3579
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

3580 3581 3582
**示例:**

```js
L
device  
lihuihui 已提交
3583 3584
import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null;
L
lihuihui 已提交
3585
let deviceId = null;
L
device  
lihuihui 已提交
3586 3587 3588 3589 3590 3591 3592 3593

deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
    if (err) {
        console.log("create device manager failed, err=" + err);
        return;
    }
    dmInstance = manager;
    let devices = dmInstance.getTrustedDeviceListSync();
L
lihuihui 已提交
3594
    deviceId = devices[0].deviceId;
L
device  
lihuihui 已提交
3595 3596 3597
})

let promise = store.obtainDistributedTableName(deviceId, "EMPLOYEE");
3598
promise.then((tableName) => {
3599
  console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
3600
}).catch((err) => {
G
ge-yafang 已提交
3601
  console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
3602 3603 3604
})
```

3605
### sync
3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618

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

在设备之间同步数据, 使用callback异步回调。

**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名     | 类型                                               | 必填 | 说明                                                         |
| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
R
renjiecui 已提交
3619
| mode       | [SyncMode](#syncmode)                             | 是   | 指同步模式。该值可以是relationalStore.SyncMode.SYNC_MODE_PUSH、relationalStore.SyncMode.SYNC_MODE_PULL。                               |
3620
| predicates | [RdbPredicates](#rdbpredicates)               | 是   | 约束同步数据和设备。                                         |
3621 3622
| callback   | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | 是   | 指定的callback回调函数,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 |

L
LiRui 已提交
3623 3624 3625 3626 3627 3628 3629 3630
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

3631 3632 3633
**示例:**

```js
L
device  
lihuihui 已提交
3634 3635
import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null;
L
lihuihui 已提交
3636
let deviceIds = [];
L
device  
lihuihui 已提交
3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649

deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
    if (err) {
        console.log("create device manager failed, err=" + err);
        return;
    }
    dmInstance = manager;
    let devices = dmInstance.getTrustedDeviceListSync();
    for (var i = 0; i < devices.length; i++) {
        deviceIds[i] = devices[i].deviceId;
    }
})

3650
let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
L
device  
lihuihui 已提交
3651
predicates.inDevices(deviceIds);
3652 3653
store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
  if (err) {
G
ge-yafang 已提交
3654
    console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
3655 3656 3657 3658 3659 3660
    return;
  }
  console.info(`Sync done.`);
  for (let i = 0; i < result.length; i++) {
    console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
  }
3661 3662 3663
})
```

3664
### sync
3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677

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

在设备之间同步数据,使用Promise异步回调。

**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名     | 类型                                 | 必填 | 说明                           |
| ---------- | ------------------------------------ | ---- | ------------------------------ |
R
renjiecui 已提交
3678
| mode       | [SyncMode](#syncmode)               | 是   | 指同步模式。该值可以是relationalStore.SyncMode.SYNC_MODE_PUSH、relationalStore.SyncMode.SYNC_MODE_PULL。 |
3679
| predicates | [RdbPredicates](#rdbpredicates) | 是   | 约束同步数据和设备。           |
3680 3681 3682 3683 3684 3685 3686

**返回值**

| 类型                                         | 说明                                                         |
| -------------------------------------------- | ------------------------------------------------------------ |
| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise对象,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 |

L
LiRui 已提交
3687 3688 3689 3690 3691 3692 3693 3694
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                 |
| ------------ | ---------------------------- |
| 14800000     | Inner error.                 |

3695 3696 3697
**示例:**

```js
L
device  
lihuihui 已提交
3698 3699
import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null;
L
lihuihui 已提交
3700
let deviceIds = [];
L
device  
lihuihui 已提交
3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713

deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
    if (err) {
        console.log("create device manager failed, err=" + err);
        return;
    }
    dmInstance = manager;
    let devices = dmInstance.getTrustedDeviceListSync();
    for (var i = 0; i < devices.length; i++) {
        deviceIds[i] = devices[i].deviceId;
    }
})

3714
let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
L
device  
lihuihui 已提交
3715
predicates.inDevices(deviceIds);
3716
let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates);
W
wangxiyue 已提交
3717
promise.then((result) =>{
3718
  console.info(`Sync done.`);
W
wangxiyue 已提交
3719
  for (let i = 0; i < result.length; i++) {
3720 3721
    console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
  }
3722
}).catch((err) => {
G
ge-yafang 已提交
3723
  console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
3724 3725 3726
})
```

R
renjiecui 已提交
3727 3728
### cloudSync<sup>10+</sup>

R
renjiecui 已提交
3729
cloudSync(mode: SyncMode, progress: Callback&lt;ProgressDetails&gt;, callback: AsyncCallback&lt;void&gt;): void
R
renjiecui 已提交
3730

R
renjiecui 已提交
3731
手动执行对所有分布式表的端云同步,使用callback异步回调。使用该接口需要实现云服务功能。
R
renjiecui 已提交
3732 3733 3734 3735 3736 3737 3738 3739 3740

**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client

**参数:**

| 参数名   | 类型                                                  | 必填 | 说明                                               |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
R
renjiecui 已提交
3741
| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                             |
R
renjiecui 已提交
3742 3743 3744 3745 3746
| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。             |
| callback | AsyncCallback&lt;void&gt;                             | 是   | 指定的callback回调函数,用于向调用者发送同步结果。 |

**示例:**

R
renjiecui 已提交
3747
```js
R
renjiecui 已提交
3748 3749
relationalStore.cloudSync(relatioanalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, function (progressDetails) {
    console.info(`Progess: ${progressDetails}`);
R
renjiecui 已提交
3750 3751 3752 3753 3754
}, function (err) {
     if (err) {
         console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`);
         return;
     }
R
renjiecui 已提交
3755
     console.info('Cloud sync succeeded');
R
renjiecui 已提交
3756 3757 3758 3759 3760
});
```

### cloudSync<sup>10+</sup>

R
renjiecui 已提交
3761
cloudSync(mode: SyncMode, progress: Callback&lt;ProgressDetails&gt;): Promise&lt;void&gt;
R
renjiecui 已提交
3762

R
renjiecui 已提交
3763
手动执行对所有分布式表的端云同步,使用Promise异步回调。使用该接口需要实现云服务功能。
R
renjiecui 已提交
3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783

**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client

**参数:**

| 参数名   | 类型                                                  | 必填 | 说明                                   |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                 |
| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。 |

**返回值**

| 类型                | 说明                                    |
| ------------------- | --------------------------------------- |
| Promise&lt;void&gt; | Promise对象,用于向调用者发送同步结果。 |

**示例:**

R
renjiecui 已提交
3784
```js
R
renjiecui 已提交
3785 3786
function progress(progressDetail) {
    console.info(`progress: ${progressDetail}`);
R
renjiecui 已提交
3787 3788
}

R
renjiecui 已提交
3789
relationalStore.cloudSync(relatioanalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, progress).then(() => {
R
renjiecui 已提交
3790 3791 3792
    console.info('Cloud sync succeeded');
}).catch((err) => {
    console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`);
R
renjiecui 已提交
3793 3794 3795 3796 3797
});
```

### cloudSync<sup>10+</sup>

R
renjiecui 已提交
3798
cloudSync(mode: SyncMode, tables: string[], progress: Callback&lt;ProgressDetails&gt;, callback: AsyncCallback&lt;void&gt;): void
R
renjiecui 已提交
3799

R
renjiecui 已提交
3800
手动执行对指定表的端云同步,使用callback异步回调。使用该接口需要实现云服务功能。
R
renjiecui 已提交
3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816

**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client

**参数:**

| 参数名   | 类型                                                  | 必填 | 说明                                               |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                             |
| tables   | string[]                                              | 是   | 指定同步的表名。                                   |
| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。             |
| callback | AsyncCallback&lt;void&gt;                             | 是   | 指定的callback回调函数,用于向调用者发送同步结果。 |

**示例:**

R
renjiecui 已提交
3817
```js
R
renjiecui 已提交
3818
const tables = ["table1", "table2"];
R
renjiecui 已提交
3819 3820
relationalStore.cloudSync(relatioanalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, function (progressDetails) {
    console.info(`Progess: ${progressDetails}`);
R
renjiecui 已提交
3821 3822 3823 3824 3825
}, function (err) {
     if (err) {
         console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`);
         return;
     }
R
renjiecui 已提交
3826
     console.info('Cloud sync succeeded');
R
renjiecui 已提交
3827 3828 3829 3830 3831
});
```

### cloudSync<sup>10+</sup>

R
renjiecui 已提交
3832
cloudSync(mode: SyncMode, tables: string[], progress: Callback&lt;ProgressDetails&gt;): Promise&lt;void&gt;
R
renjiecui 已提交
3833

R
renjiecui 已提交
3834
手动执行对指定表的端云同步,使用Promise异步回调。使用该接口需要实现云服务功能。
R
renjiecui 已提交
3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855

**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC

**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client

**参数:**

| 参数名   | 类型                                                  | 必填 | 说明                                   |
| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                 |
| tables   | string[]                                              | 是   | 指定同步的表名。                       |
| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。 |

**返回值**

| 类型                | 说明                                    |
| ------------------- | --------------------------------------- |
| Promise&lt;void&gt; | Promise对象,用于向调用者发送同步结果。 |

**示例:**

R
renjiecui 已提交
3856
```js
R
renjiecui 已提交
3857
const tables = ["table1", "table2"];
R
renjiecui 已提交
3858 3859
function progress(progressDetail) {
    console.info(`progress: ${progressDetail}`);
R
renjiecui 已提交
3860 3861
}

R
renjiecui 已提交
3862
relationalStore.cloudSync(relatioanalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, progress).then(() => {
R
renjiecui 已提交
3863 3864 3865
    console.info('Cloud sync succeeded');
}).catch((err) => {
    console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`);
R
renjiecui 已提交
3866 3867 3868
});
```

3869
### on('dataChange')
3870

R
renjiecui 已提交
3871 3872
on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void

R
renjiecui 已提交
3873
注册数据库的数据变更的事件监听。当分布式数据库中的数据发生更改时,将调用回调。
R
renjiecui 已提交
3874 3875 3876 3877 3878 3879 3880 3881

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| event    | string                                                       | 是   | 取值为'dataChange',表示数据更改。                           |
3882
| type     | [SubscribeType](#subscribetype) | 是   | 订阅类型。                                                   |
R
renjiecui 已提交
3883 3884 3885 3886
| observer | Callback&lt;Array&lt;string&gt;&gt;                          | 是   | 指分布式数据库中数据更改事件的观察者。Array&lt;string&gt;为数据库中的数据发生改变的对端设备ID。 |

**示例:**

R
renjiecui 已提交
3887
```js
R
renjiecui 已提交
3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901
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>

R
renjiecui 已提交
3902
on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;ChangeInfo&gt;&gt;): void
3903

R
renjiecui 已提交
3904
注册数据库的数据变更的事件监听。当分布式数据库中的数据发生更改时,将调用回调。
3905 3906 3907 3908 3909 3910 3911 3912

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                                | 必填 | 说明                                        |
| -------- | ----------------------------------- | ---- | ------------------------------------------- |
| event    | string                              | 是   | 取值为'dataChange',表示数据更改。          |
P
PaDaBoo 已提交
3913
| type     | [SubscribeType](#subscribetype)    | 是   | 订阅类型。 |
R
renjiecui 已提交
3914
| observer | Callback&lt;Array&lt;string&gt;&gt; \| Callback&lt;Array&lt;[ChangeInfo](#changeinfo10)&gt;&gt; | 是   | 回调函数。<br>当type为SUBSCRIBE_TYPE_REMOTE,observer类型需为Callback&lt;Array&lt;string&gt;&gt;,其中Array&lt;string&gt;为数据库中的数据发生改变的对端设备ID。<br> 当type为SUBSCRIBE_TYPE_CLOUD,observer类型需为Callback&lt;Array&lt;string&gt;&gt;,其中Array&lt;string&gt;为数据库中的数据发生改变的云端帐号。 <br> 当type为SUBSCRIBE_TYPE_CLOUD_DETAILS,observer类型需为Callback&lt;Array&lt;ChangeInfo&gt;&gt;,其中Array&lt;ChangeInfo&gt;为数据库端云同步过程的详情。 |
3915 3916 3917 3918 3919

**示例:**

```js
function storeObserver(devices) {
3920 3921 3922
  for (let i = 0; i < devices.length; i++) {
    console.info(`device= ${devices[i]} data changed`);
  }
3923 3924
}
try {
3925
  store.on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
3926
} catch (err) {
G
ge-yafang 已提交
3927
  console.error(`Register observer failed, code is ${err.code},message is ${err.message}`);
3928 3929 3930
}
```

L
rdb  
lihuihui 已提交
3931 3932
### on<sup>10+</sup>

L
rdb  
lihuihui 已提交
3933
on(event: string, interProcess: boolean, observer: Callback\<void>): void
L
rdb  
lihuihui 已提交
3934

L
rdb  
lihuihui 已提交
3935
注册数据库的进程内或者进程间事件监听。当调用[emit](#emit10)接口时,将调用回调。
L
rdb  
lihuihui 已提交
3936 3937 3938 3939 3940

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

L
rdb  
lihuihui 已提交
3941 3942 3943 3944 3945
| 参数名       | 类型            | 必填 | 说明                                                         |
| ------------ | --------------- | ---- | ------------------------------------------------------------ |
| event        | string          | 是   | 订阅事件名称。                                               |
| interProcess | boolean         | 是   | 指定是进程间还是本进程订阅。<br/> true:进程间。<br/> false:本进程。 |
| observer     | Callback\<void> | 是   | 回调函数。                                                   |
L
rdb  
lihuihui 已提交
3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                           |
| ------------ | -------------------------------------- |
| 14800000     | Inner error.                           |
| 14800050     | Failed to obtain subscription service. |

**示例:**

```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}`);
}
```

3969
### off('dataChange')
3970

R
renjiecui 已提交
3971 3972
off(event:'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void

R
renjiecui 已提交
3973
取消数据变更的事件监听。
R
renjiecui 已提交
3974 3975 3976 3977 3978 3979 3980 3981

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| event    | string                                                       | 是   | 取值为'dataChange',表示数据更改。                           |
3982
| type     | [SubscribeType](#subscribetype) | 是   | 订阅类型。                                                   |
R
renjiecui 已提交
3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001
| observer | Callback&lt;Array&lt;string&gt;&gt;                          | 是   | 指已注册的数据更改观察者。Array&lt;string&gt;为数据库中的数据发生改变的对端设备ID。 |

**示例:**

```
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>

R
renjiecui 已提交
4002
off(event:'dataChange', type: SubscribeType, observer?: Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;ChangeInfo&gt;&gt;): void
4003

R
renjiecui 已提交
4004
取消数据变更的事件监听。
4005 4006 4007 4008 4009 4010

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型                                | 必填 | 说明                                        |
P
PaDaBoo 已提交
4011
| -------- | ---------------------------------- | ---- | ------------------------------------------ |
4012
| event    | string                              | 是   | 取值为'dataChange',表示数据更改。          |
P
PaDaBoo 已提交
4013
| type     | [SubscribeType](#subscribetype)     | 是   | 订阅类型。                                 |
R
renjiecui 已提交
4014
| observer | Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;[ChangeInfo](#changeinfo10)&gt;&gt; | 否 | 回调函数。<br/>当type为SUBSCRIBE_TYPE_REMOTE,observer类型需为Callback&lt;Array&lt;string&gt;&gt;,其中Array&lt;string&gt;为数据库中的数据发生改变的对端设备ID。<br/> 当type为SUBSCRIBE_TYPE_CLOUD,observer类型需为Callback&lt;Array&lt;string&gt;&gt;,其中Array&lt;string&gt;为数据库中的数据发生改变的云端帐号。 <br/> 当type为SUBSCRIBE_TYPE_CLOUD_DETAILS,observer类型需为Callback&lt;Array&lt;ChangeInfo&gt;&gt;,其中Array&lt;ChangeInfo&gt;为数据库端云同步过程的详情。<br> 当observer没有传入时,表示取消当前type类型下所有数据变更的事件监听。 |
4015 4016 4017 4018 4019

**示例:**

```js
function storeObserver(devices) {
4020 4021 4022
  for (let i = 0; i < devices.length; i++) {
    console.info(`device= ${devices[i]} data changed`);
  }
4023 4024
}
try {
4025
  store.off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
4026
} catch (err) {
G
ge-yafang 已提交
4027
  console.error(`Unregister observer failed, code is ${err.code},message is ${err.message}`);
4028 4029 4030
}
```

L
rdb  
lihuihui 已提交
4031 4032
### off<sup>10+</sup>

L
rdb  
lihuihui 已提交
4033
off(event: string, interProcess: boolean, observer?: Callback\<void>): void
L
rdb  
lihuihui 已提交
4034 4035 4036 4037 4038 4039 4040

取消数据变更的事件监听。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

L
rdb  
lihuihui 已提交
4041 4042 4043 4044 4045
| 参数名       | 类型            | 必填 | 说明                                                         |
| ------------ | --------------- | ---- | ------------------------------------------------------------ |
| event        | string          | 是   | 取消订阅事件名称。                                           |
| interProcess | boolean         | 是   | 指定是进程间还是本进程取消订阅。<br/> true:进程间。<br/> false:本进程。 |
| observer     | Callback\<void> | 否   | 该参数存在,则取消指定Callback监听回调,否则取消该event事件的所有监听回调。 |
L
rdb  
lihuihui 已提交
4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                           |
| ------------ | -------------------------------------- |
| 14800000     | Inner error.                           |
| 14800050     | Failed to obtain subscription service. |

**示例:**

```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>

L
rdb  
lihuihui 已提交
4071
emit(event: string): void
L
rdb  
lihuihui 已提交
4072

L
rdb  
lihuihui 已提交
4073
通知通过[on](#on10)注册的进程间或者进程内监听事件。
L
rdb  
lihuihui 已提交
4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明                 |
| ------ | ------ | ---- | -------------------- |
| event  | string | 是   | 通知订阅事件的名称。 |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                           |
| ------------ | -------------------------------------- |
| 14800000     | Inner error.                           |
| 14800050     | Failed to obtain subscription service. |

**示例:**

```js
L
rdb  
lihuihui 已提交
4095
store.emit('storeObserver');
L
rdb  
lihuihui 已提交
4096 4097
```

4098
## ResultSet
4099 4100 4101 4102 4103

提供通过查询数据库生成的数据库结果集的访问方法。结果集是指用户调用关系型数据库查询接口之后返回的结果集合,提供了多种灵活的数据访问方式,以便用户获取各项数据。

### 使用说明

4104
首先需要获取resultSet对象。
4105 4106

```js
W
wangxiyue 已提交
4107
let resultSet = null;
4108
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
4109
predicates.equalTo("AGE", 18);
4110
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
W
wangxiyue 已提交
4111 4112
promise.then((result) => {
  resultSet = result;
4113 4114
  console.info(`resultSet columnNames: ${resultSet.columnNames}`);
  console.info(`resultSet columnCount: ${resultSet.columnCount}`);
4115 4116 4117
});
```

4118
### 属性
4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

| 名称         | 类型            | 必填 | 说明                             |
| ------------ | ------------------- | ---- | -------------------------------- |
| columnNames  | Array&lt;string&gt; | 是   | 获取结果集中所有列的名称。       |
| columnCount  | number              | 是   | 获取结果集中的列数。             |
| rowCount     | number              | 是   | 获取结果集中的行数。             |
| rowIndex     | number              | 是   | 获取结果集当前行的索引。         |
| isAtFirstRow | boolean             | 是   | 检查结果集是否位于第一行。       |
| isAtLastRow  | boolean             | 是   | 检查结果集是否位于最后一行。     |
| isEnded      | boolean             | 是   | 检查结果集是否位于最后一行之后。 |
| isStarted    | boolean             | 是   | 检查指针是否移动过。             |
| isClosed     | boolean             | 是   | 检查当前结果集是否关闭。         |

4134
### getColumnIndex
4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159

getColumnIndex(columnName: string): number

根据指定的列名获取列索引。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名     | 类型   | 必填 | 说明                       |
| ---------- | ------ | ---- | -------------------------- |
| columnName | string | 是   | 表示结果集中指定列的名称。 |

**返回值:**

| 类型   | 说明               |
| ------ | ------------------ |
| number | 返回指定列的索引。 |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
4160
| 14800013     | The column value is null or the column type is incompatible. |
4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171

**示例:**

  ```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"));
  ```

4172
### getColumnName
4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197

getColumnName(columnIndex: number): string

根据指定的列索引获取列名。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名      | 类型   | 必填 | 说明                       |
| ----------- | ------ | ---- | -------------------------- |
| columnIndex | number | 是   | 表示结果集中指定列的索引。 |

**返回值:**

| 类型   | 说明               |
| ------ | ------------------ |
| string | 返回指定列的名称。 |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
4198
| 14800013     | The column value is null or the column type is incompatible. |
4199 4200 4201 4202 4203 4204 4205 4206 4207

**示例:**

  ```js
const id = resultSet.getColumnName(0);
const name = resultSet.getColumnName(1);
const age = resultSet.getColumnName(2);
  ```

4208
### goTo
4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233

goTo(offset:number): boolean

向前或向后转至结果集的指定行,相对于其当前位置偏移。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名 | 类型   | 必填 | 说明                         |
| ------ | ------ | ---- | ---------------------------- |
| offset | number | 是   | 表示相对于当前位置的偏移量。 |

**返回值:**

| 类型    | 说明                                          |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
L
LiRui 已提交
4234
| 14800012     | The result set is empty or the specified location is invalid. |
4235 4236 4237 4238

**示例:**

  ```js
4239 4240
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise= store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
4241
promise.then((resultSet) => {
4242 4243
  resultSet.goTo(1);
  resultSet.close();
4244
}).catch((err) => {
G
ge-yafang 已提交
4245
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
4246 4247 4248
});
  ```

4249
### goToRow
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

goToRow(position: number): boolean

转到结果集的指定行。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名   | 类型   | 必填 | 说明                     |
| -------- | ------ | ---- | ------------------------ |
| position | number | 是   | 表示要移动到的指定位置。 |

**返回值:**

| 类型    | 说明                                          |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
L
LiRui 已提交
4275
| 14800012     | The result set is empty or the specified location is invalid. |
4276 4277 4278 4279

**示例:**

  ```js
4280 4281
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
4282
promise.then((resultSet) => {
W
wangxiyue 已提交
4283
  resultSet.goToRow(5);
4284
  resultSet.close();
4285
}).catch((err) => {
G
ge-yafang 已提交
4286
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
4287 4288 4289
});
  ```

4290
### goToFirstRow
4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310

goToFirstRow(): boolean


转到结果集的第一行。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**返回值:**

| 类型    | 说明                                          |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
L
LiRui 已提交
4311
| 14800012     | The result set is empty or the specified location is invalid. |
4312 4313 4314 4315

**示例:**

  ```js
4316 4317
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
4318
promise.then((resultSet) => {
4319 4320
  resultSet.goToFirstRow();
  resultSet.close();
4321
}).catch((err) => {
G
ge-yafang 已提交
4322
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
4323 4324 4325
});
  ```

4326
### goToLastRow
4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345

goToLastRow(): boolean

转到结果集的最后一行。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**返回值:**

| 类型    | 说明                                          |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
L
LiRui 已提交
4346
| 14800012     | The result set is empty or the specified location is invalid. |
4347 4348 4349 4350

**示例:**

  ```js
4351 4352
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
4353
promise.then((resultSet) => {
4354 4355
  resultSet.goToLastRow();
  resultSet.close();
4356
}).catch((err) => {
G
ge-yafang 已提交
4357
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
4358 4359 4360
});
  ```

4361
### goToNextRow
4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380

goToNextRow(): boolean

转到结果集的下一行。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**返回值:**

| 类型    | 说明                                          |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
L
LiRui 已提交
4381
| 14800012     | The result set is empty or the specified location is invalid. |
4382 4383 4384 4385

**示例:**

  ```js
4386 4387
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
4388
promise.then((resultSet) => {
4389 4390
  resultSet.goToNextRow();
  resultSet.close();
4391
}).catch((err) => {
G
ge-yafang 已提交
4392
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
4393 4394 4395
});
  ```

4396
### goToPreviousRow
4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415

goToPreviousRow(): boolean

转到结果集的上一行。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**返回值:**

| 类型    | 说明                                          |
| ------- | --------------------------------------------- |
| boolean | 如果成功移动结果集,则为true;否则返回false。 |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
L
LiRui 已提交
4416
| 14800012     | The result set is empty or the specified location is invalid. |
4417 4418 4419 4420

**示例:**

  ```js
4421 4422
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
4423
promise.then((resultSet) => {
4424 4425
  resultSet.goToPreviousRow();
  resultSet.close();
4426
}).catch((err) => {
G
ge-yafang 已提交
4427
  console.error(`query failed, code is ${err.code},message is ${err.message}`);
4428 4429 4430
});
  ```

4431
### getBlob
4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450

getBlob(columnIndex: number): Uint8Array

以字节数组的形式获取当前行中指定列的值。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名      | 类型   | 必填 | 说明                    |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | 是   | 指定的列索引,从0开始。 |

**返回值:**

| 类型       | 说明                             |
| ---------- | -------------------------------- |
| Uint8Array | 以字节数组的形式返回指定列的值。 |

L
LiRui 已提交
4451 4452 4453 4454 4455 4456 4457 4458
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |

4459 4460 4461 4462 4463 4464
**示例:**

  ```js
const codes = resultSet.getBlob(resultSet.getColumnIndex("CODES"));
  ```

4465
### getString
4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484

getString(columnIndex: number): string

以字符串形式获取当前行中指定列的值。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名      | 类型   | 必填 | 说明                    |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | 是   | 指定的列索引,从0开始。 |

**返回值:**

| 类型   | 说明                         |
| ------ | ---------------------------- |
| string | 以字符串形式返回指定列的值。 |

L
LiRui 已提交
4485 4486 4487 4488 4489 4490 4491 4492
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |

4493 4494 4495 4496 4497 4498
**示例:**

  ```js
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
  ```

4499
### getLong
4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514

getLong(columnIndex: number): number

以Long形式获取当前行中指定列的值。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名      | 类型   | 必填 | 说明                    |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | 是   | 指定的列索引,从0开始。 |

**返回值:**

L
int64  
lihuihui 已提交
4515 4516 4517
| 类型   | 说明                                                         |
| ------ | ------------------------------------------------------------ |
| number | 以Long形式返回指定列的值。<br>该接口支持的数据范围是:Number.MIN_SAFE_INTEGER ~ Number.MAX_SAFE_INTEGER,若超出该范围,建议使用[getDouble](#getdouble)。 |
4518

L
LiRui 已提交
4519 4520 4521 4522 4523 4524 4525 4526
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |

4527 4528 4529 4530 4531 4532
**示例:**

  ```js
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
  ```

4533
### getDouble
4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552

getDouble(columnIndex: number): number

以double形式获取当前行中指定列的值。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名      | 类型   | 必填 | 说明                    |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | 是   | 指定的列索引,从0开始。 |

**返回值:**

| 类型   | 说明                         |
| ------ | ---------------------------- |
| number | 以double形式返回指定列的值。 |

L
LiRui 已提交
4553 4554 4555 4556 4557 4558 4559 4560
**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
| 14800013     | The column value is null or the column type is incompatible. |

4561 4562 4563 4564 4565 4566
**示例:**

  ```js
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
  ```

R
renjiecui 已提交
4567 4568
### getAsset<sup>10+</sup>

R
renjiecui 已提交
4569
getAsset(columnIndex: number): Asset
R
renjiecui 已提交
4570

R
renjiecui 已提交
4571
[Asset](#asset10)形式获取当前行中指定列的值。
R
renjiecui 已提交
4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名         | 类型     | 必填  | 说明           |
| ----------- | ------ | --- | ------------ |
| columnIndex | number | 是   | 指定的列索引,从0开始。 |

**返回值:**

| 类型              | 说明                         |
| --------------- | -------------------------- |
R
renjiecui 已提交
4585
| [Asset](#asset10) | 以Asset形式返回指定列的值。 |
R
renjiecui 已提交
4586 4587 4588 4589 4590 4591 4592

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                     |
| --------- | ------------------------------------------------------------ |
R
renjiecui 已提交
4593
| 14800013  | The column value is null or the column type is incompatible. |
R
renjiecui 已提交
4594 4595 4596 4597 4598 4599 4600 4601 4602

**示例:**

```js
const doc = resultSet.getAsset(resultSet.getColumnIndex("DOC"));
```

### getAssets<sup>10+</sup>

R
renjiecui 已提交
4603
getAssets(columnIndex: number): Assets
R
renjiecui 已提交
4604

R
renjiecui 已提交
4605
[Assets](#assets10)形式获取当前行中指定列的值。
R
renjiecui 已提交
4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名         | 类型     | 必填  | 说明           |
| ----------- | ------ | --- | ------------ |
| columnIndex | number | 是   | 指定的列索引,从0开始。 |

**返回值:**

R
renjiecui 已提交
4617 4618
| 类型              | 说明                           |
| ---------------- | ---------------------------- |
R
renjiecui 已提交
4619
| [Assets](#assets10)| 以Assets形式返回指定列的值。 |
R
renjiecui 已提交
4620 4621 4622 4623 4624

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

R
renjiecui 已提交
4625 4626
| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
R
renjiecui 已提交
4627
| 14800013     | The column value is null or the column type is incompatible. |
R
renjiecui 已提交
4628 4629 4630 4631 4632 4633 4634 4635

**示例:**

```js
const docs = resultSet.getAssets(resultSet.getColumnIndex("DOCS"));
```


4636
### isColumnNull
4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661

isColumnNull(columnIndex: number): boolean

检查当前行中指定列的值是否为null。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**参数:**

| 参数名      | 类型   | 必填 | 说明                    |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | 是   | 指定的列索引,从0开始。 |

**返回值:**

| 类型    | 说明                                                      |
| ------- | --------------------------------------------------------- |
| boolean | 如果当前行中指定列的值为null,则返回true,否则返回false。 |

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
4662
| 14800013     | The column value is null or the column type is incompatible. |
4663 4664 4665 4666 4667 4668 4669

**示例:**

  ```js
const isColumnNull = resultSet.isColumnNull(resultSet.getColumnIndex("CODES"));
  ```

4670
### close
4671 4672 4673 4674 4675 4676 4677 4678 4679 4680

close(): void

关闭结果集。

**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core

**示例:**

  ```js
4681 4682
let predicatesClose = new relationalStore.RdbPredicates("EMPLOYEE");
let promiseClose = store.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
4683
promiseClose.then((resultSet) => {
4684
  resultSet.close();
4685
}).catch((err) => {
G
ge-yafang 已提交
4686
  console.error(`resultset close failed, code is ${err.code},message is ${err.message}`);
4687 4688 4689 4690 4691 4692 4693 4694 4695
});
  ```

**错误码:**

以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)

| **错误码ID** | **错误信息**                                                 |
| ------------ | ------------------------------------------------------------ |
L
LiRui 已提交
4696
| 14800012     | The result set is empty or the specified location is invalid. |