• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.data.relationalStore (关系型数据库)
2
3关系型数据库(Relational Database,RDB)是一种基于关系模型来管理数据的数据库。关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制,对外提供了一系列的增、删、改、查等接口,也可以直接运行用户输入的SQL语句来满足复杂的场景需要。支持通过[ResultSet.getSendableRow](#getsendablerow12)方法获取Sendable数据,进行跨线程传递。
4
5为保证插入并读取数据成功,建议一条数据不要超过2M。超出该大小,插入成功,读取失败。
6
7大数据量场景下查询数据可能会导致耗时长甚至应用卡死,如有相关操作可参考文档[批量数据写数据库场景](../../arkts-utils/batch-database-operations-guide.md),且有建议如下:
8- 单次查询数据量不超过5000条。
9- 在[TaskPool](../apis-arkts/js-apis-taskpool.md)中查询。
10- 拼接SQL语句尽量简洁。
11- 合理地分批次查询。
12
13该模块提供以下关系型数据库相关的常用功能:
14
15- [RdbPredicates](#rdbpredicates): 数据库中用来代表数据实体的性质、特征或者数据实体之间关系的词项,主要用来定义数据库的操作条件。
16- [RdbStore](#rdbstore):提供管理关系数据库(RDB)方法的接口。
17- [ResultSet](#resultset):提供用户调用关系型数据库查询接口之后返回的结果集合。
18- [Transaction](#transaction14):提供管理事务对象的接口。
19
20> **说明:**
21>
22> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
23
24## 导入模块
25
26```ts
27import { relationalStore } from '@kit.ArkData';
28```
29
30## relationalStore.getRdbStore
31
32getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback<RdbStore>): void
33
34获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用callback异步回调。
35
36加密参数[encrypt](#storeconfig)只在首次创建数据库时生效,因此在创建数据库时,选择正确的加密参数非常重要,并且在之后无法更改加密参数。
37
38| 当前开库的加密类型  | 首次创建数据库的加密类型           | 结果 |
39| ------- | -------------------------------- | ---- |
40| 非加密 | 加密                          | 将数据库以加密方式打开。   |
41| 加密 | 非加密                          | 将数据库以非加密方式打开。   |
42
43getRdbStore目前不支持多线程并发操作。
44
45**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
46
47**参数:**
48
49| 参数名   | 类型                                           | 必填 | 说明                                                         |
50| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
51| context  | Context                                        | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)。 |
52| config   | [StoreConfig](#storeconfig)               | 是   | 与此RDB存储相关的数据库配置。                                |
53| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | 是   | 指定callback回调函数,返回RdbStore对象。                   |
54
55**错误码:**
56
57以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
58
59| **错误码ID** | **错误信息**   |
60|-----------|---------|
61| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
62| 14800000  | Inner error.     |
63| 14800010  | Invalid database path.   |
64| 14800011  | Database corrupted.    |
65| 14801001  | The operation is supported in the stage model only.    |
66| 14801002  | Invalid data ground ID.     |
67| 14800017  | Config changed.   |
68| 14800020  | The secret key is corrupted or lost.   |
69| 14800021  | SQLite: Generic error.    |
70| 14800022  | SQLite: Callback routine requested an abort.   |
71| 14800023  | SQLite: Access permission denied.    |
72| 14800027  | SQLite: Attempt to write a readonly database.   |
73| 14800028  | SQLite: Some kind of disk I/O error occurred.     |
74| 14800029  | SQLite: The database is full.  |
75| 14800030  | SQLite: Unable to open the database file.   |
76
77**示例:**
78
79FA模型示例:
80
81<!--code_no_check_fa-->
82```js
83import { featureAbility } from '@kit.AbilityKit';
84import { BusinessError } from '@kit.BasicServicesKit';
85
86let store: relationalStore.RdbStore | undefined = undefined;
87let context = featureAbility.getContext();
88
89const STORE_CONFIG: relationalStore.StoreConfig = {
90  name: "RdbTest.db",
91  securityLevel: relationalStore.SecurityLevel.S3
92};
93
94relationalStore.getRdbStore(context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => {
95  store = rdbStore;
96  if (err) {
97    console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
98    return;
99  }
100  console.info('Get RdbStore successfully.');
101})
102```
103
104Stage模型示例:
105
106```ts
107import { UIAbility } from '@kit.AbilityKit';
108import { window } from '@kit.ArkUI';
109import { BusinessError } from '@kit.BasicServicesKit';
110
111let store: relationalStore.RdbStore | undefined = undefined;
112
113class EntryAbility extends UIAbility {
114  onWindowStageCreate(windowStage: window.WindowStage) {
115    const STORE_CONFIG: relationalStore.StoreConfig = {
116      name: "RdbTest.db",
117      securityLevel: relationalStore.SecurityLevel.S3
118    };
119
120    relationalStore.getRdbStore(this.context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => {
121      store = rdbStore;
122      if (err) {
123        console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
124        return;
125      }
126      console.info('Get RdbStore successfully.');
127    })
128  }
129}
130```
131
132## relationalStore.getRdbStore
133
134getRdbStore(context: Context, config: StoreConfig): Promise&lt;RdbStore&gt;
135
136获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用Promise异步回调。
137
138加密参数[encrypt](#storeconfig)只在首次创建数据库时生效,因此在创建数据库时,选择正确的加密参数非常重要,并且在之后无法更改加密参数。
139
140| 当前开库的加密类型  | 首次创建数据库的加密类型           | 结果 |
141| ------- | -------------------------------- | ---- |
142| 非加密 | 加密                          | 将数据库以加密方式打开。   |
143| 加密 | 非加密                          | 将数据库以非加密方式打开。   |
144
145getRdbStore目前不支持多线程并发操作。
146
147**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
148
149**参数:**
150
151| 参数名  | 类型                             | 必填 | 说明                                                         |
152| ------- | -------------------------------- | ---- | ------------------------------------------------------------ |
153| context | Context                          | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)。 |
154| config  | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |
155
156**返回值**:
157
158| 类型                                      | 说明                              |
159| ----------------------------------------- | --------------------------------- |
160| Promise&lt;[RdbStore](#rdbstore)&gt; | Promise对象。返回RdbStore对象。 |
161
162**错误码:**
163
164以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
165
166| **错误码ID** | **错误信息**                                                 |
167|-----------| ------------------------------------------------------------ |
168| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
169| 14800000  | Inner error. |
170| 14800010  | Invalid database path. |
171| 14800011  | Database corrupted.  |
172| 14801001  | The operation is supported in the stage model only.                               |
173| 14801002  | Invalid data ground ID.                             |
174| 14800017  | Config changed. |
175| 14800020  | The secret key is corrupted or lost.   |
176| 14800021  | SQLite: Generic error. |
177| 14800022  | SQLite: Callback routine requested an abort.   |
178| 14800023  | SQLite: Access permission denied.    |
179| 14800027  | SQLite: Attempt to write a readonly database. |
180| 14800028  | SQLite: Some kind of disk I/O error occurred. |
181| 14800029  | SQLite: The database is full. |
182| 14800030  | SQLite: Unable to open the database file. |
183
184**示例:**
185
186FA模型示例:
187
188<!--code_no_check_fa-->
189```js
190import { featureAbility } from '@kit.AbilityKit';
191import { BusinessError } from '@kit.BasicServicesKit';
192
193let store: relationalStore.RdbStore | undefined = undefined;
194let context = featureAbility.getContext();
195
196const STORE_CONFIG: relationalStore.StoreConfig = {
197  name: "RdbTest.db",
198  securityLevel: relationalStore.SecurityLevel.S3
199};
200
201relationalStore.getRdbStore(context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => {
202  store = rdbStore;
203  console.info('Get RdbStore successfully.')
204}).catch((err: BusinessError) => {
205  console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
206})
207```
208
209Stage模型示例:
210
211```ts
212import { UIAbility } from '@kit.AbilityKit';
213import { window } from '@kit.ArkUI';
214import { BusinessError } from '@kit.BasicServicesKit';
215
216let store: relationalStore.RdbStore | undefined = undefined;
217
218class EntryAbility extends UIAbility {
219  onWindowStageCreate(windowStage: window.WindowStage) {
220    const STORE_CONFIG: relationalStore.StoreConfig = {
221      name: "RdbTest.db",
222      securityLevel: relationalStore.SecurityLevel.S3
223    };
224
225    relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => {
226      store = rdbStore;
227      console.info('Get RdbStore successfully.')
228    }).catch((err: BusinessError) => {
229      console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
230    })
231  }
232}
233```
234
235## relationalStore.deleteRdbStore
236
237deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
238
239删除数据库文件,使用callback异步回调。
240
241删除成功后,建议将数据库对象置为null。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则调用此接口进行删库无效,必须使用 [deleteRdbStore](#relationalstoredeleterdbstore10) 接口进行删库。
242
243**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
244
245**参数:**
246
247| 参数名   | 类型                      | 必填 | 说明                                                         |
248| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
249| context  | Context                   | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)。 |
250| name     | string                    | 是   | 数据库名称。                                                 |
251| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。                                       |
252
253**错误码:**
254
255以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
256
257| **错误码ID** | **错误信息**                        |
258|-----------|---------------------------------------|
259| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
260| 14800000  | Inner error.     |
261| 14800010  | Failed to open or delete database by invalid database path. |
262
263**示例:**
264
265FA模型示例:
266
267<!--code_no_check_fa-->
268```js
269import { featureAbility } from '@kit.AbilityKit';
270import { BusinessError } from '@kit.BasicServicesKit';
271
272let store: relationalStore.RdbStore | undefined = undefined;
273let context = featureAbility.getContext();
274
275relationalStore.deleteRdbStore(context, "RdbTest.db", (err: BusinessError) => {
276  if (err) {
277    console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
278    return;
279  }
280  store = undefined;
281  console.info('Delete RdbStore successfully.');
282})
283```
284
285Stage模型示例:
286
287```ts
288import { UIAbility } from '@kit.AbilityKit';
289import { window } from '@kit.ArkUI';
290import { BusinessError } from '@kit.BasicServicesKit';
291
292let store: relationalStore.RdbStore | undefined = undefined;
293
294class EntryAbility extends UIAbility {
295  onWindowStageCreate(windowStage: window.WindowStage){
296    relationalStore.deleteRdbStore(this.context, "RdbTest.db", (err: BusinessError) => {
297      if (err) {
298        console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
299        return;
300      }
301      store = undefined;
302      console.info('Delete RdbStore successfully.');
303    })
304  }
305}
306```
307
308## relationalStore.deleteRdbStore
309
310deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;
311
312使用指定的数据库文件配置删除数据库,使用Promise异步回调。
313
314删除成功后,建议将数据库对象置为null。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则调用此接口进行删库无效,必须使用 [deleteRdbStore](#relationalstoredeleterdbstore10-1) 接口进行删库。
315
316**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
317
318**参数**
319
320| 参数名  | 类型    | 必填 | 说明                                                         |
321| ------- | ------- | ---- | ------------------------------------------------------------ |
322| context | Context | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)。 |
323| name    | string  | 是   | 数据库名称。                                                 |
324
325**返回值**:
326
327| 类型                | 说明                      |
328| ------------------- | ------------------------- |
329| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
330
331**错误码:**
332
333以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
334
335| **错误码ID** | **错误信息**                                                                         |
336|-----------|----------------------------------------------------------------------------------|
337| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
338| 14800000  | Inner error.                                                                     |
339| 14800010  | Invalid database path.                      |
340
341**示例:**
342
343FA模型示例:
344
345<!--code_no_check_fa-->
346```js
347import { featureAbility } from '@kit.AbilityKit';
348import { BusinessError } from '@kit.BasicServicesKit';
349
350let store: relationalStore.RdbStore | undefined = undefined;
351let context = featureAbility.getContext();
352
353relationalStore.deleteRdbStore(context, "RdbTest.db").then(()=>{
354  store = undefined;
355  console.info('Delete RdbStore successfully.');
356}).catch((err: BusinessError) => {
357  console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
358})
359```
360
361Stage模型示例:
362
363```ts
364import { UIAbility } from '@kit.AbilityKit';
365import { window } from '@kit.ArkUI';
366import { BusinessError } from '@kit.BasicServicesKit';
367
368let store: relationalStore.RdbStore | undefined = undefined;
369
370class EntryAbility extends UIAbility {
371  onWindowStageCreate(windowStage: window.WindowStage){
372    relationalStore.deleteRdbStore(this.context, "RdbTest.db").then(()=>{
373      store = undefined;
374      console.info('Delete RdbStore successfully.');
375    }).catch((err: BusinessError) => {
376      console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
377    })
378  }
379}
380```
381
382## relationalStore.deleteRdbStore<sup>10+</sup>
383
384deleteRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback\<void>): void
385
386使用指定的数据库文件配置删除数据库,使用callback异步回调。
387
388删除成功后,建议将数据库对象置为null。若数据库文件处于公共沙箱目录下,则删除数据库时必须使用该接口,当存在多个进程操作同一个数据库的情况,建议向其他进程发送数据库删除通知使其感知并处理。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则必须调用此接口进行删库。
389
390**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
391
392**参数:**
393
394| 参数名   | 类型                        | 必填 | 说明                                                         |
395| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
396| context  | Context                     | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)。 |
397| config   | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |
398| callback | AsyncCallback&lt;void&gt;   | 是   | 指定callback回调函数。                                       |
399
400**错误码:**
401
402以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
403
404| **错误码ID** | **错误信息**          |
405|-----------|----------|
406| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
407| 14800000  | Inner error.        |
408| 14800010  | Failed to open or delete database by invalid database path.        |
409| 14801001  | The operation is supported in the stage model only.         |
410| 14801002  | Invalid data ground ID.        |
411
412**示例:**
413
414FA模型示例:
415
416<!--code_no_check_fa-->
417```js
418import { featureAbility } from '@kit.AbilityKit';
419import { BusinessError } from '@kit.BasicServicesKit';
420
421let store: relationalStore.RdbStore | undefined = undefined;
422let context = featureAbility.getContext();
423
424const STORE_CONFIG: relationalStore.StoreConfig = {
425  name: "RdbTest.db",
426  securityLevel: relationalStore.SecurityLevel.S3
427};
428
429relationalStore.deleteRdbStore(context, STORE_CONFIG, (err: BusinessError) => {
430  if (err) {
431    console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
432    return;
433  }
434  store = undefined;
435  console.info('Delete RdbStore successfully.');
436})
437```
438
439Stage模型示例:
440
441```ts
442import { UIAbility } from '@kit.AbilityKit';
443import { window } from '@kit.ArkUI';
444import { BusinessError } from '@kit.BasicServicesKit';
445
446let store: relationalStore.RdbStore | undefined = undefined;
447
448class EntryAbility extends UIAbility {
449  onWindowStageCreate(windowStage: window.WindowStage){
450    const STORE_CONFIG: relationalStore.StoreConfig = {
451      name: "RdbTest.db",
452      securityLevel: relationalStore.SecurityLevel.S3
453    };
454    relationalStore.deleteRdbStore(this.context, STORE_CONFIG, (err: BusinessError) => {
455      if (err) {
456        console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
457        return;
458      }
459      store = undefined;
460      console.info('Delete RdbStore successfully.');
461    })
462  }
463}
464```
465
466## relationalStore.deleteRdbStore<sup>10+</sup>
467
468deleteRdbStore(context: Context, config: StoreConfig): Promise\<void>
469
470使用指定的数据库文件配置删除数据库,使用Promise异步回调。
471
472删除成功后,建议将数据库对象置为null。若数据库文件处于公共沙箱目录下,则删除数据库时必须使用该接口,当存在多个进程操作同一个数据库的情况,建议向其他进程发送数据库删除通知使其感知并处理。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则必须调用此接口进行删库。
473
474**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
475
476**参数**
477
478| 参数名  | 类型                        | 必填 | 说明                                                         |
479| ------- | --------------------------- | ---- | ------------------------------------------------------------ |
480| context | Context                     | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)。 |
481| config  | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |
482
483**返回值**:
484
485| 类型                | 说明                      |
486| ------------------- | ------------------------- |
487| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
488
489**错误码:**
490
491以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。
492
493| **错误码ID** | **错误信息**             |
494|-----------|---------------------|
495| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
496| 801       | Capability not supported.      |
497| 14800000  | Inner error.      |
498| 14800010  | Invalid database path.   |
499| 14801001  | The operation is supported in the stage model only.   |
500| 14801002  | Invalid data ground ID.   |
501
502
503**示例:**
504
505FA模型示例:
506
507<!--code_no_check_fa-->
508```js
509import { featureAbility } from "@kit.AbilityKit";
510import { BusinessError } from '@kit.BasicServicesKit';
511
512let store: relationalStore.RdbStore | undefined = undefined;
513let context = featureAbility.getContext();
514
515const STORE_CONFIG: relationalStore.StoreConfig = {
516  name: "RdbTest.db",
517  securityLevel: relationalStore.SecurityLevel.S3
518};
519
520relationalStore.deleteRdbStore(context, STORE_CONFIG).then(()=>{
521  store = undefined;
522  console.info('Delete RdbStore successfully.');
523}).catch((err: BusinessError) => {
524  console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
525})
526```
527
528Stage模型示例:
529
530```ts
531import { UIAbility } from '@kit.AbilityKit';
532import { window } from '@kit.ArkUI';
533import { BusinessError } from '@kit.BasicServicesKit';
534
535let store: relationalStore.RdbStore | undefined = undefined;
536
537class EntryAbility extends UIAbility {
538  onWindowStageCreate(windowStage: window.WindowStage){
539    const STORE_CONFIG: relationalStore.StoreConfig = {
540      name: "RdbTest.db",
541      securityLevel: relationalStore.SecurityLevel.S3
542    };
543    relationalStore.deleteRdbStore(this.context, STORE_CONFIG).then(()=>{
544      store = undefined;
545      console.info('Delete RdbStore successfully.');
546    }).catch((err: BusinessError) => {
547      console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
548    })
549  }
550}
551```
552
553## StoreConfig
554
555管理关系数据库配置。
556
557| 名称        | 类型          | 必填 | 说明                                                      |
558| ------------- | ------------- | ---- | --------------------------------------------------------- |
559| name          | string        | 是   | 数据库文件名,也是数据库唯一标识符。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core   |
560| securityLevel | [SecurityLevel](#securitylevel) | 是   | 设置数据库安全级别。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core|
561| encrypt       | boolean       | 否   | 指定数据库是否加密,默认不加密。<br/> true:加密。<br/> false:非加密。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
562| dataGroupId<sup>10+</sup> | string | 否 | 应用组ID,<!--RP3-->暂不支持指定dataGroupId在对应的沙箱路径下创建RdbStore实例。<!--RP3End--><br/>**模型约束:** 此属性仅在Stage模型下可用。<br/>从API version 10开始,支持此可选参数。dataGroupId共沙箱的方式不支持多进程访问加密数据库,当此参数不填时,默认在本应用沙箱目录下创建RdbStore实例。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
563| customDir<sup>11+</sup> | string | 否 | 数据库自定义路径。<br/>**使用约束:** 数据库路径大小限制为128字节,如果超过该大小会开库失败,返回错误。<br/>从API version 11开始,支持此可选参数。数据库将在如下的目录结构中被创建:context.databaseDir + "/rdb/" + customDir,其中context.databaseDir是应用沙箱对应的路径,"/rdb/"表示创建的是关系型数据库,customDir表示自定义的路径。当此参数不填时,默认在本应用沙箱目录下创建RdbStore实例。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
564| autoCleanDirtyData<sup>11+</sup> | boolean | 否 | 指定是否自动清理云端删除后同步到本地的数据,true表示自动清理,false表示手动清理,默认自动清理。<br/>对于端云协同的数据库,当云端删除的数据同步到设备端时,可通过该参数设置设备端是否自动清理。手动清理可以通过[cleanDirtyData<sup>11+</sup>](#cleandirtydata11)接口清理。<br/>从API version 11开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
565| allowRebuild<sup>12+</sup> | boolean | 否 | 指定数据库是否支持异常时自动删除,并重建一个空库空表,默认不删除。<br/>true:自动删除。<br/>false:不自动删除。<br/>从API version 12开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
566| isReadOnly<sup>12+</sup> | boolean | 否 | 指定数据库是否只读,默认为数据库可读写。<br/>true:只允许从数据库读取数据,不允许对数据库进行写操作,否则会返回错误码801。<br/>false:允许对数据库进行读写操作。<br/>从API version 12开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
567| pluginLibs<sup>12+</sup> | Array\<string> | 否 | 表示包含有fts(Full-Text Search,即全文搜索引擎)等能力的动态库名的数组。<br/>**使用约束:** <br/>1. 动态库名的数量限制最多为16个,如果超过该数量会开库失败,返回错误。<br/>2. 动态库名需为本应用沙箱路径下或系统路径下的动态库,如果动态库无法加载会开库失败,返回错误。<br/>3. 动态库名需为完整路径,用于被sqlite加载。<br/>样例:[context.bundleCodeDir+ "/libs/arm64/" + libtokenizer.so],其中context.bundleCodeDir是应用沙箱对应的路径,"/libs/arm64/"表示子目录,libtokenizer.so表示动态库的文件名。当此参数不填时,默认不加载动态库。<br/>4. 动态库需要包含其全部依赖,避免依赖项丢失导致无法运行。<br/>例如:在ndk工程中,使用默认编译参数构建libtokenizer.so,此动态库依赖c++标准库。在加载此动态库时,由于namespace与编译时不一致,链接到了错误的libc++_shared.so,导致`__emutls_get_address`符号找不到。要解决此问题,需在编译时静态链接c++标准库,具体请参见[NDK工程构建概述](../../napi/build-with-ndk-overview.md)。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
568| cryptoParam<sup>14+</sup> | [CryptoParam](#cryptoparam14) | 否 | 指定用户自定义的加密参数。<br/>当此参数不填时,使用默认的加密参数,见[CryptoParam](#cryptoparam14)各参数默认值。<br/>此配置只有在encrypt选项设置为真时才有效。<br/>从API version 14开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
569
570## SecurityLevel
571
572数据库的安全级别枚举。请使用枚举名称而非枚举值。数据库的安全等级仅支持由低向高设置,不支持由高向低设置。
573
574> **说明:**
575>
576> 若需要进行同步操作,数据库安全等级应不高于对端设备安全等级,具体可见[跨设备同步访问控制机制](../../database/sync-app-data-across-devices-overview.md#跨设备同步访问控制机制)。
577
578**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
579
580| 名称 | 值   | 说明                                                         |
581| ---- | ---- | ------------------------------------------------------------ |
582| S1   | 1    | 表示数据库的安全级别为低级别,当数据泄露时会产生较低影响。例如,包含壁纸等系统数据的数据库。 |
583| S2   | 2    | 表示数据库的安全级别为中级别,当数据泄露时会产生较大影响。例如,包含录音、视频等用户生成数据或通话记录等信息的数据库。 |
584| S3   | 3    | 表示数据库的安全级别为高级别,当数据泄露时会产生重大影响。例如,包含用户运动、健康、位置等信息的数据库。 |
585| S4   | 4    | 表示数据库的安全级别为关键级别,当数据泄露时会产生严重影响。例如,包含认证凭据、财务数据等信息的数据库。 |
586
587## CryptoParam<sup>14+</sup>
588
589数据库加密参数配置。此配置只有在StoreConfig的encrypt选项设置为真时才有效。
590
591**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
592
593| 名称          | 类型   | 必填 | 说明                                                         |
594| ------------- | ------ | ---- | ------------------------------------------------------------ |
595| encryptionKey | Uint8Array | 是   | 指定数据库加/解密使用的密钥。<br/>如传入密钥为空,则由数据库负责生成并保存密钥,并使用生成的密钥打开数据库文件。<br/>使用完后用户需要将密钥内容全部置为零。 |
596| iterationCount | number | 否 | 整数类型,指定数据库PBKDF2算法的迭代次数,默认值为10000。<br/>迭代次数应当为大于零的整数,若非整数则向下取整。<br/>不指定此参数或指定为零时,使用默认值10000,并使用默认加密算法AES_256_GCM。 |
597| encryptionAlgo | [EncryptionAlgo](#encryptionalgo14) | 否 | 指定数据库加解密使用的加密算法。如不指定,默认值为 AES_256_GCM。 |
598| hmacAlgo | [HmacAlgo](#hmacalgo14) | 否 | 指定数据库加解密使用的HMAC算法。如不指定,默认值为SHA256。 |
599| kdfAlgo | [KdfAlgo](#kdfalgo14) | 否 | 指定数据库加解密使用的PBKDF2算法。如不指定,默认使用和HMAC算法相等的算法。 |
600| cryptoPageSize | number | 否 | 整数类型,指定数据库加解密使用的页大小。如不指定,默认值为1024字节。<br/>用户指定的页大小应为1024到65536范围内的整数,并且为2<sup>n</sup>。若指定值非整数,则向下取整。 |
601
602## EncryptionAlgo<sup>14+</sup>
603
604数据库的加密算法枚举。请使用枚举名称而非枚举值。
605
606**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
607
608| 名称 | 值   | 说明 |
609| ---- | ---- | ---- |
610| AES_256_GCM |  0    | AES_256_GCM加密算法。     |
611| AES_256_CBC |  1    | AES_256_CBC加密算法。     |
612
613## HmacAlgo<sup>14+</sup>
614
615数据库的HMAC算法枚举。请使用枚举名称而非枚举值。
616
617**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
618
619| 名称 | 值   | 说明 |
620| ---- | ---- | ---- |
621| SHA1 |  0    | HMAC_SHA1算法。     |
622| SHA256 |  1    | HMAC_SHA256算法。     |
623| SHA512 |  2    | HMAC_SHA512算法。    |
624
625## KdfAlgo<sup>14+</sup>
626
627数据库的PBKDF2算法枚举。请使用枚举名称而非枚举值。
628
629**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
630
631| 名称 | 值   | 说明 |
632| ---- | ---- | ---- |
633| KDF_SHA1 |  0    | PBKDF2_HMAC_SHA1算法。     |
634| KDF_SHA256 |  1    | PBKDF2_HMAC_SHA256算法。     |
635| KDF_SHA512 |  2    | PBKDF2_HMAC_SHA512算法。     |
636
637## AssetStatus<sup>10+</sup>
638
639描述资产附件的状态枚举。请使用枚举名称而非枚举值。
640
641**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
642
643| 名称                              | 值   | 说明             |
644| ------------------------------- | --- | -------------- |
645| ASSET_NORMAL     | 1  | 表示资产状态正常。      |
646| ASSET_INSERT | 2 | 表示资产需要插入到云端。 |
647| ASSET_UPDATE | 3 | 表示资产需要更新到云端。 |
648| ASSET_DELETE | 4 | 表示资产需要在云端删除。 |
649| ASSET_ABNORMAL    | 5   | 表示资产状态异常。      |
650| ASSET_DOWNLOADING | 6   | 表示资产正在下载到本地设备。 |
651
652## Asset<sup>10+</sup>
653
654记录资产附件(文件、图片、视频等类型文件)的相关信息。
655
656**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
657
658| 名称          | 类型                          | 必填  | 说明           |
659| ----------- | --------------------------- | --- | ------------ |
660| name        | string                      | 是   | 资产的名称。       |
661| uri         | string                      | 是   | 资产的uri,在系统里的绝对路径。       |
662| path        | string                      | 是   | 资产在应用沙箱里的路径。       |
663| createTime  | string                      | 是   | 资产被创建出来的时间。   |
664| modifyTime  | string                      | 是   | 资产最后一次被修改的时间。 |
665| size        | string                      | 是   | 资产占用空间的大小。    |
666| status      | [AssetStatus](#assetstatus10) | 否   | 资产的状态,默认值为ASSET_NORMAL。        |
667
668## Assets<sup>10+</sup>
669
670type Assets = Asset[]
671
672表示[Asset](#asset10)类型的数组。
673
674**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
675
676| 类型    | 说明                 |
677| ------- | -------------------- |
678| [Asset](#asset10)[] | 表示Asset类型的数组。   |
679
680## ValueType
681
682type ValueType = null | number | string | boolean | Uint8Array | Asset | Assets | Float32Array | bigint
683
684用于表示允许的数据字段类型,接口参数具体类型根据其功能而定。
685
686**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
687
688| 类型    | 说明                 |
689| ------- | -------------------- |
690| null<sup>10+</sup>    | 表示值类型为空。   |
691| number  | 表示值类型为数字。   |
692| string  | 表示值类型为字符串。  |
693| boolean | 表示值类型为布尔值。 |
694| Uint8Array<sup>10+</sup>           | 表示值类型为Uint8类型的数组。            |
695| Asset<sup>10+</sup>  | 表示值类型为附件[Asset](#asset10)。<br/>当字段类型是Asset时,在创建表的sql语句中,类型应当为:ASSET。 |
696| Assets<sup>10+</sup> | 表示值类型为附件数组[Assets](#assets10)。<br/>当字段类型是Assets时,在创建表的sql语句中,类型应当为:ASSETS。 |
697| Float32Array<sup>12+</sup> | 表示值类型为浮点数组。<br/>当字段类型是Float32Array时,在创建表的sql语句中,类型应当为:floatvector(128)。 |
698| bigint<sup>12+</sup> | 表示值类型为任意长度的整数。<br/>当字段类型是bigint时,在创建表的sql语句中,类型应当为:UNLIMITED INT, 详见[通过关系型数据库实现数据持久化](../../database/data-persistence-by-rdb-store.md)。<br/>**说明:** bigint类型当前不支持比较大小,不支持如下谓词:between、notBetween、greaterThanlessThan、greaterThanOrEqualTo、lessThanOrEqualTo、orderByAsc、orderByDesc。<br/>bigint类型字段的数据写入时,需通过BigInt()方法或在数据尾部添加'n'的方式明确为bigint类型,如'let data = BigInt(1234)'或'let data = 1234n'。<br/>bigint字段如果写入number类型的数据,则查询该数据的返回类型为number,而非bigint。 |
699
700## ValuesBucket
701
702type ValuesBucket = Record<string, ValueType>
703
704用于存储键值对的类型。不支持Sendable跨线程传递。
705
706**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
707
708| 类型              | 说明                           |
709| ---------------- | ---------------------------- |
710| Record<string, [ValueType](#valuetype)> | 表示键值对类型。键的类型为string,值的类型为[ValueType](#valuetype)。 |
711
712## PRIKeyType<sup>10+</sup>
713
714type PRIKeyType = number | string
715
716用于表示数据库表某一行主键的数据类型。
717
718**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
719
720| 类型             | 说明                               |
721| ---------------- | ---------------------------------- |
722| number | 主键的类型可以是number。 |
723| string | 主键的类型可以是string。 |
724
725## UTCTime<sup>10+</sup>
726
727type UTCTime = Date
728
729用于表示UTC类型时间的数据类型。
730
731**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
732
733| 类型 | 说明            |
734| ---- | --------------- |
735| Date | UTC类型的时间。 |
736
737## ModifyTime<sup>10+</sup>
738
739type ModifyTime = Map<PRIKeyType, UTCTime>
740
741用于存储数据库表的主键和修改时间的数据类型。
742
743**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
744
745| 类型                                                    | 说明                                                         |
746| ------------------------------------------------------- | ------------------------------------------------------------ |
747| Map<[PRIKeyType](#prikeytype10), [UTCTime](#utctime10)> | 键表示是数据库表某一行的主键,值表示该行的最后修改时间,用UTC格式表示。 |
748
749## SyncMode
750
751指数据库同步模式。请使用枚举名称而非枚举值。
752
753| 名称           | 值   | 说明                               |
754| -------------- | ---- | ---------------------------------- |
755| SYNC_MODE_PUSH                       | 0   | 表示数据从本地设备推送到远程设备。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
756| SYNC_MODE_PULL                       | 1   | 表示数据从远程设备拉至本地设备。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
757| SYNC_MODE_TIME_FIRST<sup>10+</sup>   | 4   | 表示数据从修改时间较近的一端同步到修改时间较远的一端。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
758| SYNC_MODE_NATIVE_FIRST<sup>10+</sup> | 5   | 表示数据从本地设备同步到云端。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
759| SYNC_MODE_CLOUD_FIRST<sup>10+</sup>  | 6   | 表示数据从云端同步到本地设备。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
760
761## Origin<sup>11+</sup>
762
763表示数据来源。请使用枚举名称而非枚举值。
764
765**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
766
767| 名称           | 值   | 说明                               |
768| -------------- | ---- | ---------------------------------- |
769| LOCAL       | 0   | 表示本地数据。      |
770| CLOUD       | 1   | 表示云端同步的数据。     |
771| REMOTE      | 2   | 表示端端同步的数据。 |
772
773## Field<sup>11+</sup>
774
775用于谓词查询条件的特殊字段。请使用枚举名称而非枚举值。
776
777**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
778
779| 名称           | 值   | 说明                               |
780| -------------- | ---- | ---------------------------------- |
781| CURSOR_FIELD        | '#_cursor'     | 用于cursor查找的字段名。|
782| ORIGIN_FIELD        | '#_origin'     | 用于cursor查找时指定数据来源的字段名。    |
783| DELETED_FLAG_FIELD  | '#_deleted_flag' | 用于cursor查找的结果集返回时填充的字段,表示云端删除的数据同步到本地后数据是否清理。<br>返回的结果集中,该字段对应的value为false表示数据未清理,true表示数据已清理。|
784| DATA_STATUS_FIELD<sup>12+</sup>   | '#_data_status' | 用于cursor查找的结果集返回时填充的字段,返回的结果集中,该字段对应的0表示正常数据,1表示退出账号保留数据,2表示云侧同步删除,3表示退出账户删除数据。|
785| OWNER_FIELD  | '#_cloud_owner' | 用于共享表中查找owner时,返回的结果集中填充的字段,表示当前共享记录的共享发起者。|
786| PRIVILEGE_FIELD  | '#_cloud_privilege' | 用于共享表中查找共享数据权限时,返回的结果集中填充的字段,表示当前共享记录的允许的操作权限。|
787| SHARING_RESOURCE_FIELD   | '#_sharing_resource_field' | 用于数据共享查找共享数据的共享资源时,返回的结果集中填充的字段,表示共享数据的共享资源标识。|
788
789## SubscribeType
790
791描述订阅类型。请使用枚举名称而非枚举值。
792
793| 名称                  | 值   | 说明               |
794| --------------------- | ---- | ------------------ |
795| SUBSCRIBE_TYPE_REMOTE | 0    | 订阅远程数据更改。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
796| SUBSCRIBE_TYPE_CLOUD<sup>10+</sup> | 1  | 订阅云端数据更改。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
797| SUBSCRIBE_TYPE_CLOUD_DETAILS<sup>10+</sup> | 2  | 订阅云端数据更改详情。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
798| SUBSCRIBE_TYPE_LOCAL_DETAILS<sup>12+</sup> | 3  | 订阅本地数据更改详情。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
799
800## RebuildType<sup>12+</sup>
801
802描述数据库重建类型的枚举。请使用枚举名称而非枚举值。
803
804**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
805
806| 名称    | 值   | 说明                                                                                                             |
807| ------- | ---- |----------------------------------------------------------------------------------------------------------------|
808| NONE    | 0    | 表示数据库未进行重建。                                                                                                    |
809| REBUILT | 1    | 表示数据库进行了重建并且生成了空数据库,需要应用重新建表和恢复数据。                                                                             |
810| REPAIRED | 2    | 表示数据库进行了修复,恢复了未损坏的数据,<!--RP2-->当前只有[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)具备该能力。<!--RP2End--> |
811
812## ChangeType<sup>10+</sup>
813
814描述数据变更类型的枚举。请使用枚举名称而非枚举值。
815
816**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
817
818| 名称                         | 值   | 说明                         |
819| -------------------------- | --- | -------------------------- |
820| DATA_CHANGE  | 0   | 表示是数据发生变更。   |
821| ASSET_CHANGE | 1   | 表示是资产附件发生了变更。 |
822
823## ChangeInfo<sup>10+</sup>
824
825记录端云同步过程详情。
826
827**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
828
829| 名称     | 类型                               | 必填 | 说明                                                         |
830| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
831| table    | string                             | 是   | 表示发生变化的表的名称。                                     |
832| type     | [ChangeType](#changetype10)        | 是   | 表示发生变化的数据的类型,数据或者资产附件发生变化。         |
833| inserted | Array\<string\> \| Array\<number\> | 是   | 记录插入数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示插入数据的行号。 |
834| updated  | Array\<string\> \| Array\<number\> | 是   | 记录更新数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示更新数据的行号。 |
835| deleted  | Array\<string\> \| Array\<number\> | 是   | 记录删除数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示删除数据的行号。 |
836
837## DistributedType<sup>10+</sup>
838
839描述表的分布式类型的枚举。请使用枚举名称而非枚举值。
840
841| 名称                | 值   | 说明                                                                                                 |
842| ------------------ | --- | -------------------------------------------------------------------------------------------------- |
843| DISTRIBUTED_DEVICE | 0  | 表示在不同设备之间分布式的数据库表。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core               |
844| DISTRIBUTED_CLOUD  | 1   | 表示在设备和云端之间分布式的数据库表。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
845
846## DistributedConfig<sup>10+</sup>
847
848记录表的分布式配置信息。
849
850**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
851
852| 名称     | 类型    | 必填 | 说明                                                         |
853| -------- | ------- | ---- | ------------------------------------------------------------ |
854| autoSync   | boolean | 是   | 该值为true时,表示该表支持自动同步和手动同步;该值为false时,表示该表只支持手动同步,不支持自动同步。 |
855
856## ConflictResolution<sup>10+</sup>
857
858插入和修改接口的冲突解决模式。请使用枚举名称而非枚举值。
859
860**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
861
862| 名称                 | 值   | 说明                                                         |
863| -------------------- | ---- | ------------------------------------------------------------ |
864| ON_CONFLICT_NONE | 0 | 表示当冲突发生时,不做任何处理。 |
865| ON_CONFLICT_ROLLBACK | 1    | 表示当冲突发生时,中止SQL语句并回滚当前事务。                |
866| ON_CONFLICT_ABORT    | 2    | 表示当冲突发生时,中止当前SQL语句,并撤销当前 SQL 语句所做的任何更改,但是由同一事务中先前的 SQL 语句引起的更改被保留并且事务保持活动状态。 |
867| ON_CONFLICT_FAIL     | 3    | 表示当冲突发生时,中止当前 SQL 语句。但它不会撤销失败的 SQL 语句的先前更改,也不会结束事务。 |
868| ON_CONFLICT_IGNORE   | 4    | 表示当冲突发生时,跳过包含违反约束的行并继续处理 SQL 语句的后续行。 |
869| ON_CONFLICT_REPLACE  | 5    | 表示当冲突发生时,在插入或更新当前行之前删除导致约束违例的预先存在的行,并且命令会继续正常执行。 |
870
871## Progress<sup>10+</sup>
872
873描述端云同步过程的枚举。请使用枚举名称而非枚举值。
874
875**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
876
877| 名称             | 值   | 说明                     |
878| ---------------- | ---- | ------------------------ |
879| SYNC_BEGIN       | 0    | 表示端云同步过程开始。   |
880| SYNC_IN_PROGRESS | 1    | 表示正在端云同步过程中。 |
881| SYNC_FINISH      | 2    | 表示端云同步过程已完成。 |
882
883## Statistic<sup>10+</sup>
884
885描述数据库表的端云同步过程的统计信息。
886
887**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
888
889| 名称       | 类型   | 必填 | 说明                                     |
890| ---------- | ------ | ---- | ---------------------------------------- |
891| total      | number | 是   | 表示数据库表中需要端云同步的总行数。     |
892| successful | number | 是   | 表示数据库表中端云同步成功的行数。       |
893| failed     | number | 是   | 表示数据库表中端云同步失败的行数。       |
894| remained   | number | 是   | 表示数据库表中端云同步剩余未执行的行数。 |
895
896## TableDetails<sup>10+</sup>
897
898描述数据库表执行端云同步任务上传和下载的统计信息。
899
900**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
901
902| 名称     | 类型                      | 必填 | 说明                                       |
903| -------- | ------------------------- | ---- | ------------------------------------------ |
904| upload   | [Statistic](#statistic10) | 是   | 表示数据库表中端云同步上传过程的统计信息。 |
905| download | [Statistic](#statistic10) | 是   | 表示数据库表中端云同步下载过程的统计信息。 |
906
907## ProgressCode<sup>10+</sup>
908
909表示端云同步过程的状态。请使用枚举名称而非枚举值。
910
911**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
912
913| 名称                  | 值   | 说明                                                         |
914| --------------------- | ---- | ------------------------------------------------------------ |
915| SUCCESS               | 0    | 表示端云同步过程成功。                                       |
916| UNKNOWN_ERROR         | 1    | 表示端云同步过程遇到未知错误。                               |
917| NETWORK_ERROR         | 2    | 表示端云同步过程遇到网络错误。                               |
918| CLOUD_DISABLED        | 3    | 表示云端不可用。                                             |
919| LOCKED_BY_OTHERS      | 4    | 表示有其他设备正在端云同步,本设备无法进行端云同步。<br>请确保无其他设备占用云端资源后,再使用本设备进行端云同步任务。 |
920| RECORD_LIMIT_EXCEEDED | 5    | 表示本次端云同步需要同步的条目或大小超出最大值。由云端配置最大值。 |
921| NO_SPACE_FOR_ASSET    | 6    | 表示云空间剩余空间小于待同步的资产大小。                     |
922| BLOCKED_BY_NETWORK_STRATEGY<sup>12+</sup>    | 7    | 表示端云同步被网络策略限制。                     |
923
924## ProgressDetails<sup>10+</sup>
925
926描述数据库整体执行端云同步任务上传和下载的统计信息。
927
928**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
929
930| 名称     | 类型                                              | 必填 | 说明                                                         |
931| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
932| schedule | [Progress](#progress10)                           | 是   | 表示端云同步过程。                                           |
933| code     | [ProgressCode](#progresscode10)                   | 是   | 表示端云同步过程的状态。                                     |
934| details  | Record<string, [TableDetails](#tabledetails10)> | 是   | 表示端云同步各表的统计信息。<br>键表示表名,值表示该表的端云同步过程统计信息。 |
935
936## SqlExecutionInfo<sup>12+</sup>
937
938描述数据库执行的SQL语句的统计信息。
939
940**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
941
942| 名称     | 类型                                               | 只读 | 可选  |说明                                                         |
943| -------- | ------------------------------------------------- | ---- | ---- | -------------------------------------------------------- |
944| sql<sup>12+</sup>           | Array&lt;string&gt;            | 是   |   否   | 表示执行的SQL语句的数组。当[batchInsert](#batchinsert)的参数太大时,可能有多个SQL。      |
945| totalTime<sup>12+</sup>      | number                        | 是   |   否   | 表示执行SQL语句的总时间,单位为μs。                                    |
946| waitTime<sup>12+</sup>       | number                        | 是   |   否   | 表示获取句柄的时间,单位为μs。                                         |
947| prepareTime<sup>12+</sup>    | number                        | 是   |   否   | 表示准备SQL和绑定参数的时间,单位为μs。                                 |
948| executeTime<sup>12+</sup>    | number                        | 是   |   否   | 表示执行SQL语句的时间,单位为μs。 |
949
950## TransactionType<sup>14+</sup>
951
952描述创建事务对象的枚举。请使用枚举名称而非枚举值。
953
954**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
955
956| 名称             | 值   | 说明                     |
957| ---------------- | ---- | ------------------------ |
958| DEFERRED       | 0    | 表示创建一个DEFERRED类型的事务对象,该类型的事务对象在创建时只会关闭自动提交而不会真正开始事务,只有在首次读或写操作时会真正开始一个读或写事务。   |
959| IMMEDIATE | 1    | 表示创建一个IMMEDIATE类型的事务对象,该类型的事务对象在创建时会真正开始一个写事务;如果有别的写事务未提交,则会创建失败,返回错误码14800024。 |
960| EXCLUSIVE      | 2    | 表示创建一个EXCLUSIVE类型的事务对象,该类型的事务在WAL模式下和IMMEDIATE相同,但在其它日志模式下能够防止事务期间有其它连接读取数据库。 |
961
962## TransactionOptions<sup>14+</sup>
963
964事务对象的配置信息。
965
966**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
967
968| 名称        | 类型          | 必填 | 说明                                                      |
969| ------------- | ------------- | ---- | --------------------------------------------------------- |
970| transactionType          | [TransactionType](#transactiontype14)        | 否   | 事务类型。默认为DEFERRED。  |
971
972## RdbPredicates
973
974表示关系型数据库(RDB)的谓词。该类确定RDB中条件表达式的值是true还是false。谓词间支持多语句拼接,拼接时默认使用and()连接。不支持Sendable跨线程传递。
975
976### constructor
977
978constructor(name: string)
979
980构造函数。
981
982**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
983
984**参数:**
985
986| 参数名 | 类型   | 必填 | 说明         |
987| ------ | ------ | ---- | ------------ |
988| name   | string | 是   | 数据库表名。 |
989
990**错误码:**
991
992以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
993
994| **错误码ID** | **错误信息**                                                                                                       |
995| --------- |----------------------------------------------------------------------------------------------------------------|
996| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
997
998**示例:**
999
1000```ts
1001let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1002```
1003
1004### inDevices
1005
1006inDevices(devices: Array&lt;string&gt;): RdbPredicates
1007
1008同步分布式数据库时连接到组网内指定的远程设备。
1009
1010> **说明:**
1011>
1012> 其中devices通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
1013数据库同步时调用Sync接口,需要在入参谓词中调用inDevices接口选择设备。如果不调用inDevices接口即默认连接组网内所有的设备。
1014
1015**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1016
1017**参数:**
1018
1019| 参数名  | 类型                | 必填 | 说明                       |
1020| ------- | ------------------- | ---- | -------------------------- |
1021| devices | Array&lt;string&gt; | 是   | 指定的组网内的远程设备ID。 |
1022
1023**返回值**:
1024
1025| 类型                                 | 说明                       |
1026| ------------------------------------ | -------------------------- |
1027| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1028
1029**错误码:**
1030
1031以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1032
1033| **错误码ID** | **错误信息**                                                                                                       |
1034| --------- |----------------------------------------------------------------------------------------------------------------|
1035| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1036
1037**示例:**
1038
1039```ts
1040import { distributedDeviceManager } from '@kit.DistributedServiceKit';
1041import { BusinessError } from '@kit.BasicServicesKit';
1042
1043let dmInstance: distributedDeviceManager.DeviceManager;
1044let deviceIds: Array<string> = [];
1045
1046try {
1047  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
1048  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
1049  for (let i = 0; i < devices.length; i++) {
1050    deviceIds[i] = devices[i].networkId!;
1051  }
1052} catch (err) {
1053  let code = (err as BusinessError).code;
1054  let message = (err as BusinessError).message
1055  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
1056}
1057
1058let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1059predicates.inDevices(deviceIds);
1060```
1061
1062### inAllDevices
1063
1064inAllDevices(): RdbPredicates
1065
1066同步分布式数据库时连接到组网内所有的远程设备。
1067
1068
1069**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1070
1071**返回值**:
1072
1073| 类型                                 | 说明                       |
1074| ------------------------------------ | -------------------------- |
1075| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1076
1077**示例:**
1078
1079```ts
1080let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1081predicates.inAllDevices();
1082```
1083
1084### equalTo
1085
1086equalTo(field: string, value: ValueType): RdbPredicates
1087
1088配置谓词以匹配数据表的field列中值为value的字段。
1089
1090**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1091
1092**参数:**
1093
1094| 参数名 | 类型                    | 必填 | 说明                   |
1095| ------ | ----------------------- | ---- | ---------------------- |
1096| field  | string                  | 是   | 数据库表中的列名。     |
1097| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1098
1099**返回值**:
1100
1101| 类型                                 | 说明                       |
1102| ------------------------------------ | -------------------------- |
1103| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1104
1105**错误码:**
1106
1107以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1108
1109| **错误码ID** | **错误信息**                                                                                                       |
1110| --------- |----------------------------------------------------------------------------------------------------------------|
1111| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1112
1113**示例:**
1114
1115```ts
1116// 匹配数据表的"NAME"列中值为"Lisa"的字段
1117let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1118predicates.equalTo("NAME", "Lisa");
1119```
1120
1121
1122### notEqualTo
1123
1124notEqualTo(field: string, value: ValueType): RdbPredicates
1125
1126配置谓词以匹配数据表的field列中值不为value的字段。
1127
1128**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1129
1130**参数:**
1131
1132| 参数名 | 类型                    | 必填 | 说明                   |
1133| ------ | ----------------------- | ---- | ---------------------- |
1134| field  | string                  | 是   | 数据库表中的列名。     |
1135| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1136
1137**返回值**:
1138
1139| 类型                                 | 说明                       |
1140| ------------------------------------ | -------------------------- |
1141| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1142
1143**错误码:**
1144
1145以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1146
1147| **错误码ID** | **错误信息**                                                                                                       |
1148| --------- |----------------------------------------------------------------------------------------------------------------|
1149| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1150
1151**示例:**
1152
1153```ts
1154// 匹配数据表的"NAME"列中值不为"Lisa"的字段
1155let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1156predicates.notEqualTo("NAME", "Lisa");
1157```
1158
1159
1160### beginWrap
1161
1162beginWrap(): RdbPredicates
1163
1164向谓词添加左括号。
1165
1166**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1167
1168**返回值**:
1169
1170| 类型                                 | 说明                      |
1171| ------------------------------------ | ------------------------- |
1172| [RdbPredicates](#rdbpredicates) | 返回带有左括号的Rdb谓词。 |
1173
1174**示例:**
1175
1176```ts
1177let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1178predicates.equalTo("NAME", "Lisa")
1179    .beginWrap()
1180    .equalTo("AGE", 18)
1181    .or()
1182    .equalTo("SALARY", 200.5)
1183    .endWrap()
1184```
1185
1186### endWrap
1187
1188endWrap(): RdbPredicates
1189
1190向谓词添加右括号。
1191
1192**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1193
1194**返回值**:
1195
1196| 类型                                 | 说明                      |
1197| ------------------------------------ | ------------------------- |
1198| [RdbPredicates](#rdbpredicates) | 返回带有右括号的Rdb谓词。 |
1199
1200**示例:**
1201
1202```ts
1203let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1204predicates.equalTo("NAME", "Lisa")
1205    .beginWrap()
1206    .equalTo("AGE", 18)
1207    .or()
1208    .equalTo("SALARY", 200.5)
1209    .endWrap()
1210```
1211
1212### or
1213
1214or(): RdbPredicates
1215
1216将或条件添加到谓词中。
1217
1218**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1219
1220**返回值**:
1221
1222| 类型                                 | 说明                      |
1223| ------------------------------------ | ------------------------- |
1224| [RdbPredicates](#rdbpredicates) | 返回带有或条件的Rdb谓词。 |
1225
1226**示例:**
1227
1228```ts
1229// 匹配数据表的"NAME"列中值为"Lisa"或"Rose"的字段
1230let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1231predicates.equalTo("NAME", "Lisa")
1232    .or()
1233    .equalTo("NAME", "Rose")
1234```
1235
1236### and
1237
1238and(): RdbPredicates
1239
1240向谓词添加和条件。
1241
1242**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1243
1244**返回值**:
1245
1246| 类型                                 | 说明                      |
1247| ------------------------------------ | ------------------------- |
1248| [RdbPredicates](#rdbpredicates) | 返回带有和条件的Rdb谓词。 |
1249
1250**示例:**
1251
1252```ts
1253// 匹配数据表的"NAME"列中值为"Lisa"且"SALARY"列中值为"200.5"的字段
1254let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1255predicates.equalTo("NAME", "Lisa")
1256    .and()
1257    .equalTo("SALARY", 200.5)
1258```
1259
1260### contains
1261
1262contains(field: string, value: string): RdbPredicates
1263
1264配置谓词以匹配数据表的field列中包含value的字段。
1265
1266**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1267
1268**参数:**
1269
1270| 参数名 | 类型   | 必填 | 说明                   |
1271| ------ | ------ | ---- | ---------------------- |
1272| field  | string | 是   | 数据库表中的列名。     |
1273| value  | string | 是   | 指示要与谓词匹配的值。 |
1274
1275**返回值**:
1276
1277| 类型                                 | 说明                       |
1278| ------------------------------------ | -------------------------- |
1279| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1280
1281**错误码:**
1282
1283以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1284
1285| **错误码ID** | **错误信息**                                                                                                       |
1286| --------- |----------------------------------------------------------------------------------------------------------------|
1287| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1288
1289**示例:**
1290
1291```ts
1292// 匹配数据表的"NAME"列中包含"os"的字段,如"Rose"
1293let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1294predicates.contains("NAME", "os");
1295```
1296
1297### beginsWith
1298
1299beginsWith(field: string, value: string): RdbPredicates
1300
1301配置谓词以匹配数据表的field列中以value开头的字段。
1302
1303**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1304
1305**参数:**
1306
1307| 参数名 | 类型   | 必填 | 说明                   |
1308| ------ | ------ | ---- | ---------------------- |
1309| field  | string | 是   | 数据库表中的列名。     |
1310| value  | string | 是   | 指示要与谓词匹配的值。 |
1311
1312**返回值**:
1313
1314| 类型                                 | 说明                       |
1315| ------------------------------------ | -------------------------- |
1316| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1317
1318**错误码:**
1319
1320以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1321
1322| **错误码ID** | **错误信息**                                                                                                       |
1323| --------- |----------------------------------------------------------------------------------------------------------------|
1324| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1325
1326**示例:**
1327
1328```ts
1329// 匹配数据表的"NAME"列中以"Li"开头的字段,如"Lisa"
1330let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1331predicates.beginsWith("NAME", "Li");
1332```
1333
1334### endsWith
1335
1336endsWith(field: string, value: string): RdbPredicates
1337
1338配置谓词以匹配数据表的field列中以value结尾的字段。
1339
1340**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1341
1342**参数:**
1343
1344| 参数名 | 类型   | 必填 | 说明                   |
1345| ------ | ------ | ---- | ---------------------- |
1346| field  | string | 是   | 数据库表中的列名。     |
1347| value  | string | 是   | 指示要与谓词匹配的值。 |
1348
1349**返回值**:
1350
1351| 类型                                 | 说明                       |
1352| ------------------------------------ | -------------------------- |
1353| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1354
1355**错误码:**
1356
1357以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1358
1359| **错误码ID** | **错误信息**                                                                                                       |
1360| --------- |----------------------------------------------------------------------------------------------------------------|
1361| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1362
1363**示例:**
1364
1365```ts
1366// 匹配数据表的"NAME"列中以"se"结尾的字段,如"Rose"
1367let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1368predicates.endsWith("NAME", "se");
1369```
1370
1371### isNull
1372
1373isNull(field: string): RdbPredicates
1374
1375配置谓词以匹配数据表的field列中值为null的字段。
1376
1377**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1378
1379**参数:**
1380
1381| 参数名 | 类型   | 必填 | 说明               |
1382| ------ | ------ | ---- | ------------------ |
1383| field  | string | 是   | 数据库表中的列名。 |
1384
1385**返回值**:
1386
1387| 类型                                 | 说明                       |
1388| ------------------------------------ | -------------------------- |
1389| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1390
1391**错误码:**
1392
1393以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1394
1395| **错误码ID** | **错误信息**                                                                                                       |
1396| --------- |----------------------------------------------------------------------------------------------------------------|
1397| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1398
1399**示例**:
1400
1401```ts
1402let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1403predicates.isNull("NAME");
1404```
1405
1406### isNotNull
1407
1408isNotNull(field: string): RdbPredicates
1409
1410配置谓词以匹配数据表的field列中值不为null的字段。
1411
1412**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1413
1414**参数:**
1415
1416| 参数名 | 类型   | 必填 | 说明               |
1417| ------ | ------ | ---- | ------------------ |
1418| field  | string | 是   | 数据库表中的列名。 |
1419
1420**返回值**:
1421
1422| 类型                                 | 说明                       |
1423| ------------------------------------ | -------------------------- |
1424| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1425
1426**错误码:**
1427
1428以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1429
1430| **错误码ID** | **错误信息**                                                                                                       |
1431| --------- |----------------------------------------------------------------------------------------------------------------|
1432| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1433
1434**示例:**
1435
1436```ts
1437let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1438predicates.isNotNull("NAME");
1439```
1440
1441### like
1442
1443like(field: string, value: string): RdbPredicates
1444
1445配置谓词以匹配数据表的field列中值类似于value的字段。
1446
1447**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1448
1449**参数:**
1450
1451| 参数名 | 类型   | 必填 | 说明                   |
1452| ------ | ------ | ---- | ---------------------- |
1453| field  | string | 是   | 数据库表中的列名。     |
1454| value  | string | 是   | 指示要与谓词匹配的值。 |
1455
1456**返回值**:
1457
1458| 类型                                 | 说明                       |
1459| ------------------------------------ | -------------------------- |
1460| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1461
1462**错误码:**
1463
1464以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1465
1466| **错误码ID** | **错误信息**                                                                                                       |
1467| --------- |----------------------------------------------------------------------------------------------------------------|
1468| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1469
1470**示例:**
1471
1472```ts
1473// 匹配数据表的"NAME"列中值类似于"os"的字段,如"Rose"
1474let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1475predicates.like("NAME", "%os%");
1476```
1477
1478### glob
1479
1480glob(field: string, value: string): RdbPredicates
1481
1482配置谓词匹配数据字段为string的指定字段。
1483
1484**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1485
1486**参数:**
1487
1488| 参数名 | 类型   | 必填 | 说明                                                         |
1489| ------ | ------ | ---- | ------------------------------------------------------------ |
1490| field  | string | 是   | 数据库表中的列名。                                           |
1491| value  | string | 是   | 指示要与谓词匹配的值。<br>支持通配符,*表示0个、1个或多个数字或字符,?表示1个数字或字符。 |
1492
1493**返回值**:
1494
1495| 类型                                 | 说明                       |
1496| ------------------------------------ | -------------------------- |
1497| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1498
1499**错误码:**
1500
1501以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1502
1503| **错误码ID** | **错误信息**                                                                                                       |
1504| --------- |----------------------------------------------------------------------------------------------------------------|
1505| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1506
1507**示例:**
1508
1509```ts
1510// 匹配数据表的"NAME"列中类型为string且值为"?h*g"的字段
1511let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1512predicates.glob("NAME", "?h*g");
1513```
1514
1515### between
1516
1517between(field: string, low: ValueType, high: ValueType): RdbPredicates
1518
1519配置谓词以匹配数据表的field列中值在给定范围内的字段(包含范围边界)。
1520
1521**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1522
1523**参数:**
1524
1525| 参数名 | 类型                    | 必填 | 说明                       |
1526| ------ | ----------------------- | ---- | -------------------------- |
1527| field  | string                  | 是   | 数据库表中的列名。         |
1528| low    | [ValueType](#valuetype) | 是   | 指示与谓词匹配的最小值。   |
1529| high   | [ValueType](#valuetype) | 是   | 指示与谓词匹配的最大值。 |
1530
1531**返回值**:
1532
1533| 类型                                 | 说明                       |
1534| ------------------------------------ | -------------------------- |
1535| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1536
1537**错误码:**
1538
1539以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1540
1541| **错误码ID** | **错误信息**                                                                                                       |
1542| --------- |----------------------------------------------------------------------------------------------------------------|
1543| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1544
1545**示例:**
1546
1547```ts
1548// 匹配数据表的"AGE"列中大于等于10且小于等于50的值
1549let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1550predicates.between("AGE", 10, 50);
1551```
1552
1553### notBetween
1554
1555notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates
1556
1557配置谓词以匹配数据表的field列中值超出给定范围的字段(不包含范围边界)。
1558
1559**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1560
1561**参数:**
1562
1563| 参数名 | 类型                    | 必填 | 说明                       |
1564| ------ | ----------------------- | ---- | -------------------------- |
1565| field  | string                  | 是   | 数据库表中的列名。         |
1566| low    | [ValueType](#valuetype) | 是   | 指示与谓词匹配的最小值。   |
1567| high   | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的最大值。 |
1568
1569**返回值**:
1570
1571| 类型                                 | 说明                       |
1572| ------------------------------------ | -------------------------- |
1573| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1574
1575**错误码:**
1576
1577以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1578
1579| **错误码ID** | **错误信息**                                                                                                       |
1580| --------- |----------------------------------------------------------------------------------------------------------------|
1581| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1582
1583**示例:**
1584
1585```ts
1586// 匹配数据表的"AGE"列中小于10或大于50的值
1587let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1588predicates.notBetween("AGE", 10, 50);
1589```
1590
1591### greaterThan
1592
1593greaterThan(field: string, value: ValueType): RdbPredicates
1594
1595配置谓词以匹配数据表的field列中值大于value的字段。
1596
1597**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1598
1599**参数:**
1600
1601| 参数名 | 类型                    | 必填 | 说明                   |
1602| ------ | ----------------------- | ---- | ---------------------- |
1603| field  | string                  | 是   | 数据库表中的列名。     |
1604| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1605
1606**返回值**:
1607
1608| 类型                                 | 说明                       |
1609| ------------------------------------ | -------------------------- |
1610| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1611
1612**错误码:**
1613
1614以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1615
1616| **错误码ID** | **错误信息**                                                                                                       |
1617| --------- |----------------------------------------------------------------------------------------------------------------|
1618| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1619
1620**示例:**
1621
1622```ts
1623// 匹配数据表的"AGE"列中大于18的值
1624let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1625predicates.greaterThan("AGE", 18);
1626```
1627
1628### lessThan
1629
1630lessThan(field: string, value: ValueType): RdbPredicates
1631
1632配置谓词以匹配数据表的field列中值小于value的字段。
1633
1634**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1635
1636**参数:**
1637
1638| 参数名 | 类型                    | 必填 | 说明                   |
1639| ------ | ----------------------- | ---- | ---------------------- |
1640| field  | string                  | 是   | 数据库表中的列名。     |
1641| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1642
1643**返回值**:
1644
1645| 类型                                 | 说明                       |
1646| ------------------------------------ | -------------------------- |
1647| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1648
1649**错误码:**
1650
1651以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1652
1653| **错误码ID** | **错误信息**                                                                                                       |
1654| --------- |----------------------------------------------------------------------------------------------------------------|
1655| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1656
1657**示例:**
1658
1659```ts
1660// 匹配数据表的"AGE"列中小于20的值
1661let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1662predicates.lessThan("AGE", 20);
1663```
1664
1665### greaterThanOrEqualTo
1666
1667greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates
1668
1669配置谓词以匹配数据表的field列中值大于或者等于value的字段。
1670
1671**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1672
1673**参数:**
1674
1675| 参数名 | 类型                    | 必填 | 说明                   |
1676| ------ | ----------------------- | ---- | ---------------------- |
1677| field  | string                  | 是   | 数据库表中的列名。     |
1678| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1679
1680**返回值**:
1681
1682| 类型                                 | 说明                       |
1683| ------------------------------------ | -------------------------- |
1684| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1685
1686**错误码:**
1687
1688以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1689
1690| **错误码ID** | **错误信息**                                                                                                       |
1691| --------- |----------------------------------------------------------------------------------------------------------------|
1692| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1693
1694**示例:**
1695
1696```ts
1697// 匹配数据表的"AGE"列中大于等于18的值
1698let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1699predicates.greaterThanOrEqualTo("AGE", 18);
1700```
1701
1702### lessThanOrEqualTo
1703
1704lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates
1705
1706配置谓词以匹配数据表的field列中值小于或者等于value的字段。
1707
1708**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1709
1710**参数:**
1711
1712| 参数名 | 类型                    | 必填 | 说明                   |
1713| ------ | ----------------------- | ---- | ---------------------- |
1714| field  | string                  | 是   | 数据库表中的列名。     |
1715| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1716
1717**返回值**:
1718
1719| 类型                                 | 说明                       |
1720| ------------------------------------ | -------------------------- |
1721| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1722
1723**错误码:**
1724
1725以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1726
1727| **错误码ID** | **错误信息**                                                                                                       |
1728| --------- |----------------------------------------------------------------------------------------------------------------|
1729| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1730
1731**示例:**
1732
1733```ts
1734// 匹配数据表的"AGE"列中小于等于20的值
1735let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1736predicates.lessThanOrEqualTo("AGE", 20);
1737```
1738
1739### orderByAsc
1740
1741orderByAsc(field: string): RdbPredicates
1742
1743配置谓词以匹配数据表的field列中值按升序排序的列。
1744
1745**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1746
1747**参数:**
1748
1749| 参数名 | 类型   | 必填 | 说明               |
1750| ------ | ------ | ---- | ------------------ |
1751| field  | string | 是   | 数据库表中的列名。 |
1752
1753**返回值**:
1754
1755| 类型                                 | 说明                       |
1756| ------------------------------------ | -------------------------- |
1757| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1758
1759**错误码:**
1760
1761以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1762
1763| **错误码ID** | **错误信息**                                                                                                       |
1764| --------- |----------------------------------------------------------------------------------------------------------------|
1765| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1766
1767**示例:**
1768
1769```ts
1770let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1771predicates.orderByAsc("NAME");
1772```
1773
1774### orderByDesc
1775
1776orderByDesc(field: string): RdbPredicates
1777
1778配置谓词以匹配数据表的field列中值按降序排序的列。
1779
1780**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1781
1782**参数:**
1783
1784| 参数名 | 类型   | 必填 | 说明               |
1785| ------ | ------ | ---- | ------------------ |
1786| field  | string | 是   | 数据库表中的列名。 |
1787
1788**返回值**:
1789
1790| 类型                                 | 说明                       |
1791| ------------------------------------ | -------------------------- |
1792| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1793
1794**错误码:**
1795
1796以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1797
1798| **错误码ID** | **错误信息**                                                                                                       |
1799| --------- |----------------------------------------------------------------------------------------------------------------|
1800| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1801
1802**示例:**
1803
1804```ts
1805let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1806predicates.orderByDesc("AGE");
1807```
1808
1809### distinct
1810
1811distinct(): RdbPredicates
1812
1813配置谓词以过滤重复记录并仅保留其中一个。
1814
1815**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1816
1817**返回值**:
1818
1819| 类型                                 | 说明                           |
1820| ------------------------------------ | ------------------------------ |
1821| [RdbPredicates](#rdbpredicates) | 返回可用于过滤重复记录的谓词。 |
1822
1823**示例:**
1824
1825```ts
1826let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1827predicates.equalTo("NAME", "Rose").distinct();
1828```
1829
1830### limitAs
1831
1832limitAs(value: number): RdbPredicates
1833
1834设置最大数据记录数的谓词。
1835
1836**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1837
1838**参数:**
1839
1840| 参数名 | 类型   | 必填 | 说明             |
1841| ------ | ------ | ---- | ---------------- |
1842| value  | number | 是   | 最大数据记录数。 |
1843
1844**返回值**:
1845
1846| 类型                                 | 说明                                 |
1847| ------------------------------------ | ------------------------------------ |
1848| [RdbPredicates](#rdbpredicates) | 返回可用于设置最大数据记录数的谓词。 |
1849
1850**错误码:**
1851
1852以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1853
1854| **错误码ID** | **错误信息**               |
1855| --------- |--------------------------|
1856| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1857
1858**示例:**
1859
1860```ts
1861let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1862predicates.equalTo("NAME", "Rose").limitAs(3);
1863```
1864
1865### offsetAs
1866
1867offsetAs(rowOffset: number): RdbPredicates
1868
1869配置谓词以指定返回结果的起始位置。
1870
1871**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1872
1873**参数:**
1874
1875| 参数名    | 类型   | 必填 | 说明                               |
1876| --------- | ------ | ---- | ---------------------------------- |
1877| rowOffset | number | 是   | 返回结果的起始位置,取值为正整数。 |
1878
1879**返回值**:
1880
1881| 类型                                 | 说明                                 |
1882| ------------------------------------ | ------------------------------------ |
1883| [RdbPredicates](#rdbpredicates) | 返回具有指定返回结果起始位置的谓词。 |
1884
1885**错误码:**
1886
1887以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1888
1889| **错误码ID** | **错误信息**                                                                                                       |
1890| --------- |----------------------------------------------------------------------------------------------------------------|
1891| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1892
1893**示例:**
1894
1895```ts
1896let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1897predicates.equalTo("NAME", "Rose").offsetAs(3);
1898```
1899
1900### groupBy
1901
1902groupBy(fields: Array&lt;string&gt;): RdbPredicates
1903
1904配置谓词按指定列分组查询结果。
1905
1906**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1907
1908**参数:**
1909
1910| 参数名 | 类型                | 必填 | 说明                 |
1911| ------ | ------------------- | ---- | -------------------- |
1912| fields | Array&lt;string&gt; | 是   | 指定分组依赖的列名。 |
1913
1914**返回值**:
1915
1916| 类型                                 | 说明                   |
1917| ------------------------------------ | ---------------------- |
1918| [RdbPredicates](#rdbpredicates) | 返回分组查询列的谓词。 |
1919
1920**错误码:**
1921
1922以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1923
1924| **错误码ID** | **错误信息**                                                                                                       |
1925| --------- |----------------------------------------------------------------------------------------------------------------|
1926| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1927
1928**示例:**
1929
1930```ts
1931let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1932predicates.groupBy(["AGE", "NAME"]);
1933```
1934
1935### indexedBy
1936
1937indexedBy(field: string): RdbPredicates
1938
1939配置谓词以指定索引列。
1940
1941**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1942
1943**参数:**
1944
1945| 参数名 | 类型   | 必填 | 说明           |
1946| ------ | ------ | ---- | -------------- |
1947| field  | string | 是   | 索引列的名称。 |
1948
1949**返回值**:
1950
1951
1952| 类型                                 | 说明                                  |
1953| ------------------------------------ | ------------------------------------- |
1954| [RdbPredicates](#rdbpredicates) | 返回具有指定索引列的RdbPredicates。 |
1955
1956**错误码:**
1957
1958以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1959
1960| **错误码ID** | **错误信息**                                                                                                       |
1961| --------- |----------------------------------------------------------------------------------------------------------------|
1962| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1963
1964**示例:**
1965
1966```ts
1967let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1968predicates.indexedBy("SALARY");
1969```
1970
1971### in
1972
1973in(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
1974
1975配置谓词以匹配数据表的field列中值在给定范围内的字段。
1976
1977**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1978
1979**参数:**
1980
1981| 参数名 | 类型                                 | 必填 | 说明                                    |
1982| ------ | ------------------------------------ | ---- | --------------------------------------- |
1983| field  | string                               | 是   | 数据库表中的列名。                      |
1984| value  | Array&lt;[ValueType](#valuetype)&gt; | 是   | 以ValueType型数组形式指定的要匹配的值。 |
1985
1986**返回值**:
1987
1988| 类型                                 | 说明                       |
1989| ------------------------------------ | -------------------------- |
1990| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1991
1992**错误码:**
1993
1994以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1995
1996| **错误码ID** | **错误信息**                                                                                                       |
1997| --------- |----------------------------------------------------------------------------------------------------------------|
1998| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1999
2000**示例:**
2001
2002```ts
2003// 匹配数据表的"AGE"列中在[18,20]中的值
2004let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2005predicates.in("AGE", [18, 20]);
2006```
2007
2008### notIn
2009
2010notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
2011
2012将谓词配置为匹配数据字段为ValueType且值超出给定范围的指定字段。
2013
2014**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2015
2016**参数:**
2017
2018| 参数名 | 类型                                 | 必填 | 说明                                  |
2019| ------ | ------------------------------------ | ---- | ------------------------------------- |
2020| field  | string                               | 是   | 数据库表中的列名。                    |
2021| value  | Array&lt;[ValueType](#valuetype)&gt; | 是   | 以ValueType数组形式指定的要匹配的值。 |
2022
2023**返回值**:
2024
2025| 类型                                 | 说明                       |
2026| ------------------------------------ | -------------------------- |
2027| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
2028
2029**错误码:**
2030
2031以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2032
2033| **错误码ID** | **错误信息**                                                                                                       |
2034| --------- |----------------------------------------------------------------------------------------------------------------|
2035| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
2036
2037**示例:**
2038
2039```ts
2040// 匹配数据表的"NAME"列中不在["Lisa", "Rose"]中的值
2041let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2042predicates.notIn("NAME", ["Lisa", "Rose"]);
2043```
2044
2045### notContains<sup>12+</sup>
2046
2047notContains(field: string, value: string): RdbPredicates
2048
2049配置谓词以匹配数据表的field列中不包含value的字段。
2050
2051**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2052
2053**参数:**
2054
2055| 参数名 | 类型   | 必填 | 说明                   |
2056| ------ | ------ | ---- | ---------------------- |
2057| field  | string | 是   | 数据库表中的列名。     |
2058| value  | string | 是   | 指示要与谓词匹配的值。 |
2059
2060**返回值**:
2061
2062| 类型                            | 说明                       |
2063| ------------------------------- | -------------------------- |
2064| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
2065
2066**错误码:**
2067
2068以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2069
2070| **错误码ID** | **错误信息**                                                                                                       |
2071| --------- |----------------------------------------------------------------------------------------------------------------|
2072| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
2073
2074**示例:**
2075
2076```ts
2077// 匹配数据表的"NAME"列中不包含"os"的字段,如列表中的"Lisa"
2078let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2079predicates.notContains("NAME", "os");
2080```
2081
2082### notLike<sup>12+</sup>
2083
2084notLike(field: string, value: string): RdbPredicates
2085
2086配置谓词以匹配数据表的field列中值不存在类似于value的字段。
2087
2088**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2089
2090**参数:**
2091
2092| 参数名 | 类型   | 必填 | 说明                   |
2093| ------ | ------ | ---- | ---------------------- |
2094| field  | string | 是   | 数据库表中的列名。     |
2095| value  | string | 是   | 指示要与谓词匹配的值。 |
2096
2097**返回值**:
2098
2099| 类型                            | 说明                       |
2100| ------------------------------- | -------------------------- |
2101| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
2102
2103**错误码:**
2104
2105以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2106
2107| **错误码ID** | **错误信息**                                                                                                       |
2108| --------- |----------------------------------------------------------------------------------------------------------------|
2109| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
2110
2111**示例:**
2112
2113```ts
2114// 匹配数据表的"NAME"列中不等于"os"的字段,如列表中的"Rose"
2115let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2116predicates.notLike("NAME", "os");
2117```
2118
2119
2120
2121## RdbStore
2122
2123提供管理关系数据库(RDB)方法的接口。
2124
2125在使用以下相关接口前,请使用[executeSql](#executesql)接口初始化数据库表结构和相关数据。
2126
2127### 属性
2128
2129**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2130
2131| 名称         | 类型            | 只读       | 可选 | 说明                             |
2132| ------------ | ----------- | ---- | -------------------------------- | -------------------------------- |
2133| version<sup>10+</sup>  | number | 否 | 否   | 设置和获取数据库版本,值为大于0的正整数。       |
2134| rebuilt<sup>12+</sup> | [RebuildType](#rebuildtype12) | 是 | 否 | 用于获取数据库是否进行过重建或修复。 |
2135
2136**错误码:**
2137
2138以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
2139
2140| **错误码ID** | **错误信息**                                                 |
2141|-----------| ------------------------------------------------------------ |
2142| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2143| 801       | Capability not supported. |
2144| 14800000  | Inner error. |
2145| 14800014  | Already closed. |
2146| 14800015  | The database does not respond. |
2147| 14800021  | SQLite: Generic error. |
2148| 14800023  | SQLite: Access permission denied. |
2149| 14800024  | SQLite: The database file is locked. |
2150| 14800025  | SQLite: A table in the database is locked. |
2151| 14800026  | SQLite: The database is out of memory. |
2152| 14800027  | SQLite: Attempt to write a readonly database. |
2153| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2154| 14800029  | SQLite: The database is full. |
2155| 14800030  | SQLite: Unable to open the database file. |
2156
2157**示例:**
2158
2159```ts
2160import { UIAbility } from '@kit.AbilityKit';
2161import { BusinessError } from '@kit.BasicServicesKit';
2162import { window } from '@kit.ArkUI';
2163
2164let store: relationalStore.RdbStore | undefined = undefined;
2165
2166class EntryAbility extends UIAbility {
2167  onWindowStageCreate(windowStage: window.WindowStage) {
2168    const STORE_CONFIG: relationalStore.StoreConfig = {
2169      name: "RdbTest.db",
2170      securityLevel: relationalStore.SecurityLevel.S3,
2171    };
2172
2173    relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => {
2174      store = rdbStore;
2175      console.info('Get RdbStore successfully.')
2176    }).catch((err: BusinessError) => {
2177      console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
2178    })
2179
2180    // 设置数据库版本
2181    if(store != undefined) {
2182      (store as relationalStore.RdbStore).version = 3;
2183      // 获取数据库版本
2184      console.info(`RdbStore version is ${store.version}`);
2185      // 获取数据库是否重建
2186      console.info(`RdbStore rebuilt is ${store.rebuilt}`);
2187    }
2188  }
2189}
2190```
2191
2192### insert
2193
2194insert(table: string, values: ValuesBucket, callback: AsyncCallback&lt;number&gt;):void
2195
2196向目标表中插入一行数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2197
2198**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2199
2200**参数:**
2201
2202| 参数名   | 类型                          | 必填 | 说明                                                       |
2203| -------- | ----------------------------- | ---- | ---------------------------------------------------------- |
2204| table    | string                        | 是   | 指定的目标表名。                                           |
2205| values   | [ValuesBucket](#valuesbucket) | 是   | 表示要插入到表中的数据行。                                 |
2206| callback | AsyncCallback&lt;number&gt;   | 是   | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 |
2207
2208**错误码:**
2209
2210以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2211
2212| **错误码ID** | **错误信息**                                                 |
2213|-----------| ------------------------------------------------------------ |
2214| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2215| 14800000  | Inner error. |
2216| 14800011  | Database corrupted. |
2217| 14800014  | Already closed. |
2218| 14800015  | The database does not respond. |
2219| 14800021  | SQLite: Generic error. |
2220| 14800022  | SQLite: Callback routine requested an abort. |
2221| 14800023  | SQLite: Access permission denied. |
2222| 14800024  | SQLite: The database file is locked. |
2223| 14800025  | SQLite: A table in the database is locked. |
2224| 14800026  | SQLite: The database is out of memory. |
2225| 14800027  | SQLite: Attempt to write a readonly database. |
2226| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2227| 14800029  | SQLite: The database is full. |
2228| 14800030  | SQLite: Unable to open the database file. |
2229| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2230| 14800032  | SQLite: Abort due to constraint violation. |
2231| 14800033  | SQLite: Data type mismatch. |
2232| 14800034  | SQLite: Library used incorrectly. |
2233| 14800047  | The WAL file size exceeds the default limit. |
2234
2235**示例:**
2236
2237```ts
2238let value1 = "Lisa";
2239let value2 = 18;
2240let value3 = 100.5;
2241let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2242
2243// 以下三种方式可用
2244const valueBucket1: relationalStore.ValuesBucket = {
2245  'NAME': value1,
2246  'AGE': value2,
2247  'SALARY': value3,
2248  'CODES': value4,
2249};
2250const valueBucket2: relationalStore.ValuesBucket = {
2251  NAME: value1,
2252  AGE: value2,
2253  SALARY: value3,
2254  CODES: value4,
2255};
2256const valueBucket3: relationalStore.ValuesBucket = {
2257  "NAME": value1,
2258  "AGE": value2,
2259  "SALARY": value3,
2260  "CODES": value4,
2261};
2262
2263if(store != undefined) {
2264  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, (err: BusinessError, rowId: number) => {
2265    if (err) {
2266      console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2267      return;
2268    }
2269    console.info(`Insert is successful, rowId = ${rowId}`);
2270  })
2271}
2272```
2273
2274### insert<sup>10+</sup>
2275
2276insert(table: string, values: ValuesBucket,  conflict: ConflictResolution, callback: AsyncCallback&lt;number&gt;):void
2277
2278向目标表中插入一行数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2279
2280**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2281
2282**参数:**
2283
2284| 参数名   | 类型                                        | 必填 | 说明                                                       |
2285| -------- | ------------------------------------------- | ---- | ---------------------------------------------------------- |
2286| table    | string                                      | 是   | 指定的目标表名。                                           |
2287| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。                                 |
2288| conflict | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。                                         |
2289| callback | AsyncCallback&lt;number&gt;                 | 是   | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 |
2290
2291**错误码:**
2292
2293以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2294
2295| **错误码ID** | **错误信息**                                                 |
2296|-----------| ---------------------------------------------------- |
2297| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2298| 14800000  | Inner error. |
2299| 14800011  | Database corrupted. |
2300| 14800014  | Already closed. |
2301| 14800015  | The database does not respond. |
2302| 14800021  | SQLite: Generic error. |
2303| 14800022  | SQLite: Callback routine requested an abort. |
2304| 14800023  | SQLite: Access permission denied. |
2305| 14800024  | SQLite: The database file is locked. |
2306| 14800025  | SQLite: A table in the database is locked. |
2307| 14800026  | SQLite: The database is out of memory. |
2308| 14800027  | SQLite: Attempt to write a readonly database. |
2309| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2310| 14800029  | SQLite: The database is full. |
2311| 14800030  | SQLite: Unable to open the database file. |
2312| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2313| 14800032  | SQLite: Abort due to constraint violation. |
2314| 14800033  | SQLite: Data type mismatch. |
2315| 14800034  | SQLite: Library used incorrectly. |
2316| 14800047  | The WAL file size exceeds the default limit. |
2317
2318**示例:**
2319
2320```ts
2321let value1 = "Lisa";
2322let value2 = 18;
2323let value3 = 100.5;
2324let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2325
2326// 以下三种方式可用
2327const valueBucket1: relationalStore.ValuesBucket = {
2328  'NAME': value1,
2329  'AGE': value2,
2330  'SALARY': value3,
2331  'CODES': value4,
2332};
2333const valueBucket2: relationalStore.ValuesBucket = {
2334  NAME: value1,
2335  AGE: value2,
2336  SALARY: value3,
2337  CODES: value4,
2338};
2339const valueBucket3: relationalStore.ValuesBucket = {
2340  "NAME": value1,
2341  "AGE": value2,
2342  "SALARY": value3,
2343  "CODES": value4,
2344};
2345
2346if(store != undefined) {
2347  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE,
2348    (err: BusinessError, rowId: number) => {
2349      if (err) {
2350        console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2351        return;
2352      }
2353      console.info(`Insert is successful, rowId = ${rowId}`);
2354  })
2355}
2356```
2357
2358### insert
2359
2360insert(table: string, values: ValuesBucket):Promise&lt;number&gt;
2361
2362向目标表中插入一行数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2363
2364**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2365
2366**参数:**
2367
2368| 参数名 | 类型                          | 必填 | 说明                       |
2369| ------ | ----------------------------- | ---- | -------------------------- |
2370| table  | string                        | 是   | 指定的目标表名。           |
2371| values | [ValuesBucket](#valuesbucket) | 是   | 表示要插入到表中的数据行。 |
2372
2373**返回值**:
2374
2375| 类型                  | 说明                                              |
2376| --------------------- | ------------------------------------------------- |
2377| Promise&lt;number&gt; | Promise对象。如果操作成功,返回行ID;否则返回-1。 |
2378
2379**错误码:**
2380
2381以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2382
2383| **错误码ID** | **错误信息**                                                 |
2384|-----------| ------------------------------------------------------------ |
2385| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2386| 14800000  | Inner error. |
2387| 14800011  | Database corrupted. |
2388| 14800014  | Already closed. |
2389| 14800015  | The database does not respond. |
2390| 14800021  | SQLite: Generic error. |
2391| 14800022  | SQLite: Callback routine requested an abort. |
2392| 14800023  | SQLite: Access permission denied. |
2393| 14800024  | SQLite: The database file is locked. |
2394| 14800025  | SQLite: A table in the database is locked. |
2395| 14800026  | SQLite: The database is out of memory. |
2396| 14800027  | SQLite: Attempt to write a readonly database. |
2397| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2398| 14800029  | SQLite: The database is full. |
2399| 14800030  | SQLite: Unable to open the database file. |
2400| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2401| 14800032  | SQLite: Abort due to constraint violation. |
2402| 14800033  | SQLite: Data type mismatch. |
2403| 14800034  | SQLite: Library used incorrectly. |
2404| 14800047  | The WAL file size exceeds the default limit. |
2405
2406**示例:**
2407
2408```ts
2409import { BusinessError } from '@kit.BasicServicesKit';
2410
2411let value1 = "Lisa";
2412let value2 = 18;
2413let value3 = 100.5;
2414let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2415
2416// 以下三种方式可用
2417const valueBucket1: relationalStore.ValuesBucket = {
2418  'NAME': value1,
2419  'AGE': value2,
2420  'SALARY': value3,
2421  'CODES': value4,
2422};
2423const valueBucket2: relationalStore.ValuesBucket = {
2424  NAME: value1,
2425  AGE: value2,
2426  SALARY: value3,
2427  CODES: value4,
2428};
2429const valueBucket3: relationalStore.ValuesBucket = {
2430  "NAME": value1,
2431  "AGE": value2,
2432  "SALARY": value3,
2433  "CODES": value4,
2434};
2435
2436if(store != undefined) {
2437  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1).then((rowId: number) => {
2438    console.info(`Insert is successful, rowId = ${rowId}`);
2439  }).catch((err: BusinessError) => {
2440    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2441  })
2442}
2443```
2444
2445### insert<sup>10+</sup>
2446
2447insert(table: string, values: ValuesBucket,  conflict: ConflictResolution):Promise&lt;number&gt;
2448
2449向目标表中插入一行数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2450
2451**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2452
2453**参数:**
2454
2455| 参数名   | 类型                                        | 必填 | 说明                       |
2456| -------- | ------------------------------------------- | ---- | -------------------------- |
2457| table    | string                                      | 是   | 指定的目标表名。           |
2458| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。 |
2459| conflict | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。         |
2460
2461**返回值**:
2462
2463| 类型                  | 说明                                              |
2464| --------------------- | ------------------------------------------------- |
2465| Promise&lt;number&gt; | Promise对象。如果操作成功,返回行ID;否则返回-1。 |
2466
2467**错误码:**
2468
2469以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2470
2471| **错误码ID** | **错误信息**                                                 |
2472|-----------| ------------------------------------------------------------ |
2473| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2474| 14800000  | Inner error. |
2475| 14800011  | Database corrupted. |
2476| 14800014  | Already closed. |
2477| 14800015  | The database does not respond. |
2478| 14800021  | SQLite: Generic error. |
2479| 14800022  | SQLite: Callback routine requested an abort. |
2480| 14800023  | SQLite: Access permission denied. |
2481| 14800024  | SQLite: The database file is locked. |
2482| 14800025  | SQLite: A table in the database is locked. |
2483| 14800026  | SQLite: The database is out of memory. |
2484| 14800027  | SQLite: Attempt to write a readonly database. |
2485| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2486| 14800029  | SQLite: The database is full. |
2487| 14800030  | SQLite: Unable to open the database file. |
2488| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2489| 14800032  | SQLite: Abort due to constraint violation. |
2490| 14800033  | SQLite: Data type mismatch. |
2491| 14800034  | SQLite: Library used incorrectly. |
2492| 14800047  | The WAL file size exceeds the default limit. |
2493
2494**示例:**
2495
2496```ts
2497import { BusinessError } from '@kit.BasicServicesKit';
2498
2499let value1 = "Lisa";
2500let value2 = 18;
2501let value3 = 100.5;
2502let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2503
2504// 以下三种方式可用
2505const valueBucket1: relationalStore.ValuesBucket = {
2506  'NAME': value1,
2507  'AGE': value2,
2508  'SALARY': value3,
2509  'CODES': value4,
2510};
2511const valueBucket2: relationalStore.ValuesBucket = {
2512  NAME: value1,
2513  AGE: value2,
2514  SALARY: value3,
2515  CODES: value4,
2516};
2517const valueBucket3: relationalStore.ValuesBucket = {
2518  "NAME": value1,
2519  "AGE": value2,
2520  "SALARY": value3,
2521  "CODES": value4,
2522};
2523
2524if(store != undefined) {
2525  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => {
2526    console.info(`Insert is successful, rowId = ${rowId}`);
2527  }).catch((err: BusinessError) => {
2528    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2529  })
2530}
2531```
2532
2533### insertSync<sup>12+</sup>
2534
2535insertSync(table: string, values: ValuesBucket,  conflict?: ConflictResolution):number
2536
2537向目标表中插入一行数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2538
2539**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2540
2541**参数:**
2542
2543| 参数名   | 类型                                        | 必填 | 说明                                                         |
2544| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
2545| table    | string                                      | 是   | 指定的目标表名。                                             |
2546| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。                                   |
2547| conflict | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
2548
2549**返回值**:
2550
2551| 类型   | 说明                                 |
2552| ------ | ------------------------------------ |
2553| number | 如果操作成功,返回行ID;否则返回-1。 |
2554
2555**错误码:**
2556
2557以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2558
2559| **错误码ID** | **错误信息**                                                 |
2560| ------------ | ------------------------------------------------------------ |
2561| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2562| 14800000     | Inner error.                                                 |
2563| 14800011     | Database corrupted.                                          |
2564| 14800014     | Already closed.                                              |
2565| 14800015     | The database does not respond.                                        |
2566| 14800021     | SQLite: Generic error.                                       |
2567| 14800022     | SQLite: Callback routine requested an abort.                 |
2568| 14800023     | SQLite: Access permission denied.                            |
2569| 14800024     | SQLite: The database file is locked.                         |
2570| 14800025     | SQLite: A table in the database is locked.                   |
2571| 14800026     | SQLite: The database is out of memory.                       |
2572| 14800027     | SQLite: Attempt to write a readonly database.                |
2573| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
2574| 14800029     | SQLite: The database is full.                                |
2575| 14800030     | SQLite: Unable to open the database file.                    |
2576| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
2577| 14800032     | SQLite: Abort due to constraint violation.                   |
2578| 14800033     | SQLite: Data type mismatch.                                  |
2579| 14800034     | SQLite: Library used incorrectly.                            |
2580| 14800047     | The WAL file size exceeds the default limit.                 |
2581
2582**示例:**
2583
2584```ts
2585import { BusinessError } from '@kit.BasicServicesKit';
2586
2587let value1 = "Lisa";
2588let value2 = 18;
2589let value3 = 100.5;
2590let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2591
2592// 以下三种方式可用
2593const valueBucket1: relationalStore.ValuesBucket = {
2594  'NAME': value1,
2595  'AGE': value2,
2596  'SALARY': value3,
2597  'CODES': value4,
2598};
2599const valueBucket2: relationalStore.ValuesBucket = {
2600  NAME: value1,
2601  AGE: value2,
2602  SALARY: value3,
2603  CODES: value4,
2604};
2605const valueBucket3: relationalStore.ValuesBucket = {
2606  "NAME": value1,
2607  "AGE": value2,
2608  "SALARY": value3,
2609  "CODES": value4,
2610};
2611
2612if(store != undefined) {
2613  try {
2614    let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
2615    console.info(`Insert is successful, rowId = ${rowId}`);
2616  } catch (error) {
2617      console.error(`Insert is failed, code is ${error.code},message is ${error.message}`);
2618  }
2619}
2620```
2621
2622### insertSync<sup>12+</sup>
2623
2624insertSync(table: string, values: sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution):number
2625
2626传入Sendable数据,向目标表中插入一行数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2627
2628**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2629
2630**参数:**
2631
2632| 参数名   | 类型                                                                                           | 必填 | 说明                                                                            |
2633| -------- | ---------------------------------------------------------------------------------------------- | ---- | ------------------------------------------------------------------------------- |
2634| table    | string                                                                                         | 是   | 指定的目标表名。                                                                |
2635| values   | [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | 是   | 表示要插入到表中的可跨线程传递数据。                                            |
2636| conflict | [ConflictResolution](#conflictresolution10)                                                    | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
2637
2638**返回值**:
2639
2640| 类型   | 说明                                 |
2641| ------ | ------------------------------------ |
2642| number | 如果操作成功,返回行ID;否则返回-1。 |
2643
2644**错误码:**
2645
2646以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2647
2648| **错误码ID** | **错误信息**                                                 |
2649| ------------ | ------------------------------------------------------------ |
2650| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2651| 14800000     | Inner error.                                                 |
2652| 14800011     | Database corrupted.                                          |
2653| 14800014     | Already closed.                                              |
2654| 14800015     | The database does not respond.                                        |
2655| 14800021     | SQLite: Generic error.                                       |
2656| 14800022     | SQLite: Callback routine requested an abort.                 |
2657| 14800023     | SQLite: Access permission denied.                            |
2658| 14800024     | SQLite: The database file is locked.                         |
2659| 14800025     | SQLite: A table in the database is locked.                   |
2660| 14800026     | SQLite: The database is out of memory.                       |
2661| 14800027     | SQLite: Attempt to write a readonly database.                |
2662| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
2663| 14800029     | SQLite: The database is full.                                |
2664| 14800030     | SQLite: Unable to open the database file.                    |
2665| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
2666| 14800032     | SQLite: Abort due to constraint violation.                   |
2667| 14800033     | SQLite: Data type mismatch.                                  |
2668| 14800034     | SQLite: Library used incorrectly.                            |
2669| 14800047     | The WAL file size exceeds the default limit.                 |
2670
2671**示例:**
2672
2673```ts
2674import { sendableRelationalStore } from '@kit.ArkData';
2675
2676const valuesBucket: relationalStore.ValuesBucket = {
2677  "NAME": 'hangman',
2678  "AGE": 18,
2679  "SALARY": 100.5,
2680  "CODES": new Uint8Array([1,2,3]),
2681};
2682const sendableValuesBucket = sendableRelationalStore.toSendableValuesBucket(valuesBucket);
2683
2684if(store != undefined) {
2685  try {
2686    let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", sendableValuesBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
2687    console.info(`Insert is successful, rowId = ${rowId}`);
2688  } catch (error) {
2689    console.error(`Insert is failed, code is ${error.code},message is ${error.message}`);
2690  }
2691}
2692```
2693
2694### batchInsert
2695
2696batchInsert(table: string, values: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;):void
2697
2698向目标表中插入一组数据,使用callback异步回调。
2699
2700**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2701
2702**参数:**
2703
2704| 参数名   | 类型                                       | 必填 | 说明                                                         |
2705| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
2706| table    | string                                     | 是   | 指定的目标表名。                                             |
2707| values   | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。             |
2708| callback | AsyncCallback&lt;number&gt;                | 是   | 指定callback回调函数。如果操作成功,返回插入的数据个数,否则返回-1。 |
2709
2710**错误码:**
2711
2712以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2713
2714| **错误码ID** | **错误信息**                                                 |
2715|-----------| ------------------------------------------------------------ |
2716| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2717| 14800000  | Inner error. |
2718| 14800011  | Database corrupted. |
2719| 14800014  | Already closed. |
2720| 14800015  | The database does not respond. |
2721| 14800021  | SQLite: Generic error. |
2722| 14800022  | SQLite: Callback routine requested an abort. |
2723| 14800023  | SQLite: Access permission denied. |
2724| 14800024  | SQLite: The database file is locked. |
2725| 14800025  | SQLite: A table in the database is locked. |
2726| 14800026  | SQLite: The database is out of memory. |
2727| 14800027  | SQLite: Attempt to write a readonly database. |
2728| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2729| 14800029  | SQLite: The database is full. |
2730| 14800030  | SQLite: Unable to open the database file. |
2731| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2732| 14800032  | SQLite: Abort due to constraint violation. |
2733| 14800033  | SQLite: Data type mismatch. |
2734| 14800034  | SQLite: Library used incorrectly. |
2735| 14800047  | The WAL file size exceeds the default limit. |
2736
2737**示例:**
2738
2739```ts
2740
2741let value1 = "Lisa";
2742let value2 = 18;
2743let value3 = 100.5;
2744let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2745let value5 = "Jack";
2746let value6 = 19;
2747let value7 = 101.5;
2748let value8 = new Uint8Array([6, 7, 8, 9, 10]);
2749let value9 = "Tom";
2750let value10 = 20;
2751let value11 = 102.5;
2752let value12 = new Uint8Array([11, 12, 13, 14, 15]);
2753
2754const valueBucket1: relationalStore.ValuesBucket = {
2755  'NAME': value1,
2756  'AGE': value2,
2757  'SALARY': value3,
2758  'CODES': value4,
2759};
2760const valueBucket2: relationalStore.ValuesBucket = {
2761  'NAME': value5,
2762  'AGE': value6,
2763  'SALARY': value7,
2764  'CODES': value8,
2765};
2766const valueBucket3: relationalStore.ValuesBucket = {
2767  'NAME': value9,
2768  'AGE': value10,
2769  'SALARY': value11,
2770  'CODES': value12,
2771};
2772
2773let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
2774if(store != undefined) {
2775  (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets, (err, insertNum) => {
2776    if (err) {
2777      console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
2778      return;
2779    }
2780    console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
2781  })
2782}
2783```
2784
2785### batchInsert
2786
2787batchInsert(table: string, values: Array&lt;ValuesBucket&gt;):Promise&lt;number&gt;
2788
2789向目标表中插入一组数据,使用Promise异步回调。
2790
2791**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2792
2793**参数:**
2794
2795| 参数名 | 类型                                       | 必填 | 说明                         |
2796| ------ | ------------------------------------------ | ---- | ---------------------------- |
2797| table  | string                                     | 是   | 指定的目标表名。             |
2798| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。|
2799
2800**返回值**:
2801
2802| 类型                  | 说明                                                        |
2803| --------------------- | ----------------------------------------------------------- |
2804| Promise&lt;number&gt; | Promise对象。如果操作成功,返回插入的数据个数,否则返回-1。 |
2805
2806**错误码:**
2807
2808以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2809
2810| **错误码ID** | **错误信息**                                                 |
2811|-----------| ------------------------------------------------------------ |
2812| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2813| 14800000  | Inner error. |
2814| 14800011  | Database corrupted. |
2815| 14800014  | Already closed. |
2816| 14800015  | The database does not respond. |
2817| 14800021  | SQLite: Generic error. |
2818| 14800022  | SQLite: Callback routine requested an abort. |
2819| 14800023  | SQLite: Access permission denied. |
2820| 14800024  | SQLite: The database file is locked. |
2821| 14800025  | SQLite: A table in the database is locked. |
2822| 14800026  | SQLite: The database is out of memory. |
2823| 14800027  | SQLite: Attempt to write a readonly database. |
2824| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2825| 14800029  | SQLite: The database is full. |
2826| 14800030  | SQLite: Unable to open the database file. |
2827| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2828| 14800032  | SQLite: Abort due to constraint violation. |
2829| 14800033  | SQLite: Data type mismatch. |
2830| 14800034  | SQLite: Library used incorrectly. |
2831| 14800047  | The WAL file size exceeds the default limit. |
2832
2833**示例:**
2834
2835```ts
2836import { BusinessError } from '@kit.BasicServicesKit';
2837
2838let value1 = "Lisa";
2839let value2 = 18;
2840let value3 = 100.5;
2841let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2842let value5 = "Jack";
2843let value6 = 19;
2844let value7 = 101.5;
2845let value8 = new Uint8Array([6, 7, 8, 9, 10]);
2846let value9 = "Tom";
2847let value10 = 20;
2848let value11 = 102.5;
2849let value12 = new Uint8Array([11, 12, 13, 14, 15]);
2850
2851const valueBucket1: relationalStore.ValuesBucket = {
2852  'NAME': value1,
2853  'AGE': value2,
2854  'SALARY': value3,
2855  'CODES': value4,
2856};
2857const valueBucket2: relationalStore.ValuesBucket = {
2858  'NAME': value5,
2859  'AGE': value6,
2860  'SALARY': value7,
2861  'CODES': value8,
2862};
2863const valueBucket3: relationalStore.ValuesBucket = {
2864  'NAME': value9,
2865  'AGE': value10,
2866  'SALARY': value11,
2867  'CODES': value12,
2868};
2869
2870let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
2871if(store != undefined) {
2872  (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => {
2873    console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
2874  }).catch((err: BusinessError) => {
2875    console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
2876  })
2877}
2878```
2879
2880### batchInsertSync<sup>12+</sup>
2881
2882batchInsertSync(table: string, values: Array&lt;ValuesBucket&gt;):number
2883
2884向目标表中插入一组数据。
2885
2886**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2887
2888**参数:**
2889
2890| 参数名 | 类型                                       | 必填 | 说明                         |
2891| ------ | ------------------------------------------ | ---- | ---------------------------- |
2892| table  | string                                     | 是   | 指定的目标表名。             |
2893| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。 |
2894
2895**返回值**:
2896
2897| 类型   | 说明                                           |
2898| ------ | ---------------------------------------------- |
2899| number | 如果操作成功,返回插入的数据个数,否则返回-1。 |
2900
2901**错误码:**
2902
2903以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2904
2905| **错误码ID** | **错误信息**                                                 |
2906| ------------ | ------------------------------------------------------------ |
2907| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2908| 14800000     | Inner error.                                                 |
2909| 14800011     | Database corrupted.                                          |
2910| 14800014     | Already closed.                                              |
2911| 14800015     | The database does not respond.                                        |
2912| 14800021     | SQLite: Generic error.                                       |
2913| 14800022     | SQLite: Callback routine requested an abort.                 |
2914| 14800023     | SQLite: Access permission denied.                            |
2915| 14800024     | SQLite: The database file is locked.                         |
2916| 14800025     | SQLite: A table in the database is locked.                   |
2917| 14800026     | SQLite: The database is out of memory.                       |
2918| 14800027     | SQLite: Attempt to write a readonly database.                |
2919| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
2920| 14800029     | SQLite: The database is full.                                |
2921| 14800030     | SQLite: Unable to open the database file.                    |
2922| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
2923| 14800032     | SQLite: Abort due to constraint violation.                   |
2924| 14800033     | SQLite: Data type mismatch.                                  |
2925| 14800034     | SQLite: Library used incorrectly.                            |
2926| 14800047     | The WAL file size exceeds the default limit.                 |
2927
2928**示例:**
2929
2930```ts
2931import { BusinessError } from '@kit.BasicServicesKit';
2932
2933let value1 = "Lisa";
2934let value2 = 18;
2935let value3 = 100.5;
2936let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2937let value5 = "Jack";
2938let value6 = 19;
2939let value7 = 101.5;
2940let value8 = new Uint8Array([6, 7, 8, 9, 10]);
2941let value9 = "Tom";
2942let value10 = 20;
2943let value11 = 102.5;
2944let value12 = new Uint8Array([11, 12, 13, 14, 15]);
2945
2946const valueBucket1: relationalStore.ValuesBucket = {
2947  'NAME': value1,
2948  'AGE': value2,
2949  'SALARY': value3,
2950  'CODES': value4,
2951};
2952const valueBucket2: relationalStore.ValuesBucket = {
2953  'NAME': value5,
2954  'AGE': value6,
2955  'SALARY': value7,
2956  'CODES': value8,
2957};
2958const valueBucket3: relationalStore.ValuesBucket = {
2959  'NAME': value9,
2960  'AGE': value10,
2961  'SALARY': value11,
2962  'CODES': value12,
2963};
2964
2965let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
2966if(store != undefined) {
2967  try {
2968    let insertNum: number = (store as relationalStore.RdbStore).batchInsertSync("EMPLOYEE", valueBuckets);
2969    console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
2970  } catch (err) {
2971      console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
2972  }
2973}
2974```
2975
2976### update
2977
2978update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
2979
2980根据RdbPredicates的指定实例对象更新数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2981
2982**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2983
2984**参数:**
2985
2986| 参数名     | 类型                                 | 必填 | 说明                                                         |
2987| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
2988| values     | [ValuesBucket](#valuesbucket)        | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
2989| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的更新条件。                    |
2990| callback   | AsyncCallback&lt;number&gt;          | 是   | 指定的callback回调方法。返回受影响的行数。                   |
2991
2992**错误码:**
2993
2994以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2995
2996| **错误码ID** | **错误信息**                                                 |
2997|-----------| ------------------------------------------------------------ |
2998| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2999| 14800000  | Inner error. |
3000| 14800011  | Database corrupted. |
3001| 14800014  | Already closed. |
3002| 14800015  | The database does not respond. |
3003| 14800021  | SQLite: Generic error. |
3004| 14800022  | SQLite: Callback routine requested an abort. |
3005| 14800023  | SQLite: Access permission denied. |
3006| 14800024  | SQLite: The database file is locked. |
3007| 14800025  | SQLite: A table in the database is locked. |
3008| 14800026  | SQLite: The database is out of memory. |
3009| 14800027  | SQLite: Attempt to write a readonly database. |
3010| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3011| 14800029  | SQLite: The database is full. |
3012| 14800030  | SQLite: Unable to open the database file. |
3013| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3014| 14800032  | SQLite: Abort due to constraint violation. |
3015| 14800033  | SQLite: Data type mismatch. |
3016| 14800034  | SQLite: Library used incorrectly. |
3017| 14800047  | The WAL file size exceeds the default limit. |
3018
3019**示例:**
3020
3021```ts
3022
3023let value1 = "Rose";
3024let value2 = 22;
3025let value3 = 200.5;
3026let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3027
3028// 以下三种方式可用
3029const valueBucket1: relationalStore.ValuesBucket = {
3030  'NAME': value1,
3031  'AGE': value2,
3032  'SALARY': value3,
3033  'CODES': value4,
3034};
3035const valueBucket2: relationalStore.ValuesBucket = {
3036  NAME: value1,
3037  AGE: value2,
3038  SALARY: value3,
3039  CODES: value4,
3040};
3041const valueBucket3: relationalStore.ValuesBucket = {
3042  "NAME": value1,
3043  "AGE": value2,
3044  "SALARY": value3,
3045  "CODES": value4,
3046};
3047
3048let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3049predicates.equalTo("NAME", "Lisa");
3050if(store != undefined) {
3051  (store as relationalStore.RdbStore).update(valueBucket1, predicates,(err, rows) => {
3052    if (err) {
3053      console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3054      return;
3055    }
3056    console.info(`Updated row count: ${rows}`);
3057  })
3058}
3059```
3060
3061### update<sup>10+</sup>
3062
3063update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution, callback: AsyncCallback&lt;number&gt;):void
3064
3065根据RdbPredicates的指定实例对象更新数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3066
3067**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3068
3069**参数:**
3070
3071| 参数名     | 类型                                        | 必填 | 说明                                                         |
3072| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
3073| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3074| predicates | [RdbPredicates](#rdbpredicates)            | 是   | RdbPredicates的实例对象指定的更新条件。                      |
3075| conflict   | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。                                           |
3076| callback   | AsyncCallback&lt;number&gt;                 | 是   | 指定的callback回调方法。返回受影响的行数。                   |
3077
3078**错误码:**
3079
3080以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3081
3082| **错误码ID** | **错误信息**                                                 |
3083|-----------| ------------------------------------------------------------ |
3084| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3085| 14800000  | Inner error. |
3086| 14800011  | Database corrupted. |
3087| 14800014  | Already closed. |
3088| 14800015  | The database does not respond. |
3089| 14800021  | SQLite: Generic error. |
3090| 14800022  | SQLite: Callback routine requested an abort. |
3091| 14800023  | SQLite: Access permission denied. |
3092| 14800024  | SQLite: The database file is locked. |
3093| 14800025  | SQLite: A table in the database is locked. |
3094| 14800026  | SQLite: The database is out of memory. |
3095| 14800027  | SQLite: Attempt to write a readonly database. |
3096| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3097| 14800029  | SQLite: The database is full. |
3098| 14800030  | SQLite: Unable to open the database file. |
3099| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3100| 14800032  | SQLite: Abort due to constraint violation. |
3101| 14800033  | SQLite: Data type mismatch. |
3102| 14800034  | SQLite: Library used incorrectly. |
3103| 14800047  | The WAL file size exceeds the default limit. |
3104
3105**示例:**
3106
3107```ts
3108
3109let value1 = "Rose";
3110let value2 = 22;
3111let value3 = 200.5;
3112let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3113
3114// 以下三种方式可用
3115const valueBucket1: relationalStore.ValuesBucket = {
3116  'NAME': value1,
3117  'AGE': value2,
3118  'SALARY': value3,
3119  'CODES': value4,
3120};
3121const valueBucket2: relationalStore.ValuesBucket = {
3122  NAME: value1,
3123  AGE: value2,
3124  SALARY: value3,
3125  CODES: value4,
3126};
3127const valueBucket3: relationalStore.ValuesBucket = {
3128  "NAME": value1,
3129  "AGE": value2,
3130  "SALARY": value3,
3131  "CODES": value4,
3132};
3133
3134let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3135predicates.equalTo("NAME", "Lisa");
3136if(store != undefined) {
3137  (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, (err, rows) => {
3138    if (err) {
3139      console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3140      return;
3141    }
3142    console.info(`Updated row count: ${rows}`);
3143  })
3144}
3145```
3146
3147### update
3148
3149update(values: ValuesBucket, predicates: RdbPredicates):Promise&lt;number&gt;
3150
3151根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3152
3153**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3154
3155**参数:**
3156
3157| 参数名       | 类型                                 | 必填 | 说明                                                         |
3158| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
3159| values       | [ValuesBucket](#valuesbucket)        | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3160| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的更新条件。                    |
3161
3162**返回值**:
3163
3164| 类型                  | 说明                                      |
3165| --------------------- | ----------------------------------------- |
3166| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |
3167
3168**错误码:**
3169
3170以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3171
3172| **错误码ID** | **错误信息**                                                 |
3173|-----------| ------------------------------------------------------------ |
3174| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3175| 14800000  | Inner error. |
3176| 14800011  | Database corrupted. |
3177| 14800014  | Already closed. |
3178| 14800015  | The database does not respond. |
3179| 14800021  | SQLite: Generic error. |
3180| 14800022  | SQLite: Callback routine requested an abort. |
3181| 14800023  | SQLite: Access permission denied. |
3182| 14800024  | SQLite: The database file is locked. |
3183| 14800025  | SQLite: A table in the database is locked. |
3184| 14800026  | SQLite: The database is out of memory. |
3185| 14800027  | SQLite: Attempt to write a readonly database. |
3186| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3187| 14800029  | SQLite: The database is full. |
3188| 14800030  | SQLite: Unable to open the database file. |
3189| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3190| 14800032  | SQLite: Abort due to constraint violation. |
3191| 14800033  | SQLite: Data type mismatch. |
3192| 14800034  | SQLite: Library used incorrectly. |
3193| 14800047  | The WAL file size exceeds the default limit. |
3194
3195**示例:**
3196
3197```ts
3198import { BusinessError } from '@kit.BasicServicesKit';
3199
3200let value1 = "Rose";
3201let value2 = 22;
3202let value3 = 200.5;
3203let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3204
3205// 以下三种方式可用
3206const valueBucket1: relationalStore.ValuesBucket = {
3207  'NAME': value1,
3208  'AGE': value2,
3209  'SALARY': value3,
3210  'CODES': value4,
3211};
3212const valueBucket2: relationalStore.ValuesBucket = {
3213  NAME: value1,
3214  AGE: value2,
3215  SALARY: value3,
3216  CODES: value4,
3217};
3218const valueBucket3: relationalStore.ValuesBucket = {
3219  "NAME": value1,
3220  "AGE": value2,
3221  "SALARY": value3,
3222  "CODES": value4,
3223};
3224
3225let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3226predicates.equalTo("NAME", "Lisa");
3227if(store != undefined) {
3228  (store as relationalStore.RdbStore).update(valueBucket1, predicates).then(async (rows: Number) => {
3229    console.info(`Updated row count: ${rows}`);
3230  }).catch((err: BusinessError) => {
3231    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3232  })
3233}
3234```
3235
3236### update<sup>10+</sup>
3237
3238update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution):Promise&lt;number&gt;
3239
3240根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3241
3242**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3243
3244**参数:**
3245
3246| 参数名     | 类型                                        | 必填 | 说明                                                         |
3247| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
3248| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3249| predicates | [RdbPredicates](#rdbpredicates)            | 是   | RdbPredicates的实例对象指定的更新条件。                      |
3250| conflict   | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。                                           |
3251
3252**返回值**:
3253
3254| 类型                  | 说明                                      |
3255| --------------------- | ----------------------------------------- |
3256| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |
3257
3258**错误码:**
3259
3260以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3261
3262| **错误码ID** | **错误信息**                                                 |
3263|-----------| ------------------------------------------------------------ |
3264| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3265| 14800000  | Inner error. |
3266| 14800011  | Database corrupted. |
3267| 14800014  | Already closed. |
3268| 14800015  | The database does not respond. |
3269| 14800021  | SQLite: Generic error. |
3270| 14800022  | SQLite: Callback routine requested an abort. |
3271| 14800023  | SQLite: Access permission denied. |
3272| 14800024  | SQLite: The database file is locked. |
3273| 14800025  | SQLite: A table in the database is locked. |
3274| 14800026  | SQLite: The database is out of memory. |
3275| 14800027  | SQLite: Attempt to write a readonly database. |
3276| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3277| 14800029  | SQLite: The database is full. |
3278| 14800030  | SQLite: Unable to open the database file. |
3279| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3280| 14800032  | SQLite: Abort due to constraint violation. |
3281| 14800033  | SQLite: Data type mismatch. |
3282| 14800034  | SQLite: Library used incorrectly. |
3283| 14800047  | The WAL file size exceeds the default limit. |
3284
3285**示例:**
3286
3287```ts
3288import { BusinessError } from '@kit.BasicServicesKit';
3289
3290let value1 = "Rose";
3291let value2 = 22;
3292let value3 = 200.5;
3293let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3294
3295// 以下三种方式可用
3296const valueBucket1: relationalStore.ValuesBucket = {
3297  'NAME': value1,
3298  'AGE': value2,
3299  'SALARY': value3,
3300  'CODES': value4,
3301};
3302const valueBucket2: relationalStore.ValuesBucket = {
3303  NAME: value1,
3304  AGE: value2,
3305  SALARY: value3,
3306  CODES: value4,
3307};
3308const valueBucket3: relationalStore.ValuesBucket = {
3309  "NAME": value1,
3310  "AGE": value2,
3311  "SALARY": value3,
3312  "CODES": value4,
3313};
3314
3315let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3316predicates.equalTo("NAME", "Lisa");
3317if(store != undefined) {
3318  (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => {
3319    console.info(`Updated row count: ${rows}`);
3320  }).catch((err: BusinessError) => {
3321    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3322  })
3323}
3324```
3325
3326### updateSync<sup>12+</sup>
3327
3328updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution):number
3329
3330根据RdbPredicates的指定实例对象更新数据库中的数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3331
3332**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3333
3334**参数:**
3335
3336| 参数名     | 类型                                        | 必填 | 说明                                                         |
3337| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
3338| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3339| predicates | [RdbPredicates](#rdbpredicates)             | 是   | RdbPredicates的实例对象指定的更新条件。                      |
3340| conflict   | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
3341
3342**返回值**:
3343
3344| 类型   | 说明               |
3345| ------ | ------------------ |
3346| number | 返回受影响的行数。 |
3347
3348**错误码:**
3349
3350以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3351
3352| **错误码ID** | **错误信息**                                                 |
3353| ------------ | ------------------------------------------------------------ |
3354| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3355| 14800000     | Inner error.                                                 |
3356| 14800011     | Database corrupted.                                          |
3357| 14800014     | Already closed.                                              |
3358| 14800015     | The database does not respond.                                        |
3359| 14800021     | SQLite: Generic error.                                       |
3360| 14800022     | SQLite: Callback routine requested an abort.                 |
3361| 14800023     | SQLite: Access permission denied.                            |
3362| 14800024     | SQLite: The database file is locked.                         |
3363| 14800025     | SQLite: A table in the database is locked.                   |
3364| 14800026     | SQLite: The database is out of memory.                       |
3365| 14800027     | SQLite: Attempt to write a readonly database.                |
3366| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
3367| 14800029     | SQLite: The database is full.                                |
3368| 14800030     | SQLite: Unable to open the database file.                    |
3369| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
3370| 14800032     | SQLite: Abort due to constraint violation.                   |
3371| 14800033     | SQLite: Data type mismatch.                                  |
3372| 14800034     | SQLite: Library used incorrectly.                            |
3373| 14800047     | The WAL file size exceeds the default limit.                 |
3374
3375**示例:**
3376
3377```ts
3378import { BusinessError } from '@kit.BasicServicesKit';
3379
3380let value1 = "Rose";
3381let value2 = 22;
3382let value3 = 200.5;
3383let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3384
3385// 以下三种方式可用
3386const valueBucket1: relationalStore.ValuesBucket = {
3387  'NAME': value1,
3388  'AGE': value2,
3389  'SALARY': value3,
3390  'CODES': value4,
3391};
3392const valueBucket2: relationalStore.ValuesBucket = {
3393  NAME: value1,
3394  AGE: value2,
3395  SALARY: value3,
3396  CODES: value4,
3397};
3398const valueBucket3: relationalStore.ValuesBucket = {
3399  "NAME": value1,
3400  "AGE": value2,
3401  "SALARY": value3,
3402  "CODES": value4,
3403};
3404
3405let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3406predicates.equalTo("NAME", "Lisa");
3407if(store != undefined) {
3408  try {
3409    let rows: Number = (store as relationalStore.RdbStore).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
3410    console.info(`Updated row count: ${rows}`);
3411  } catch (error) {
3412    console.error(`Updated failed, code is ${error.code},message is ${error.message}`);
3413  }
3414}
3415```
3416
3417### delete
3418
3419delete(predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
3420
3421根据RdbPredicates的指定实例对象从数据库中删除数据,使用callback异步回调。
3422
3423**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3424
3425**参数:**
3426
3427| 参数名     | 类型                                 | 必填 | 说明                                      |
3428| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
3429| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
3430| callback   | AsyncCallback&lt;number&gt;          | 是   | 指定callback回调函数。返回受影响的行数。  |
3431
3432**错误码:**
3433
3434以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3435
3436| **错误码ID** | **错误信息**                                                 |
3437|-----------| ------------------------------------------------------------ |
3438| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3439| 14800000  | Inner error. |
3440| 14800011  | Database corrupted. |
3441| 14800014  | Already closed. |
3442| 14800015  | The database does not respond. |
3443| 14800021  | SQLite: Generic error. |
3444| 14800022  | SQLite: Callback routine requested an abort. |
3445| 14800023  | SQLite: Access permission denied. |
3446| 14800024  | SQLite: The database file is locked. |
3447| 14800025  | SQLite: A table in the database is locked. |
3448| 14800026  | SQLite: The database is out of memory. |
3449| 14800027  | SQLite: Attempt to write a readonly database. |
3450| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3451| 14800029  | SQLite: The database is full. |
3452| 14800030  | SQLite: Unable to open the database file. |
3453| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3454| 14800032  | SQLite: Abort due to constraint violation. |
3455| 14800033  | SQLite: Data type mismatch. |
3456| 14800034  | SQLite: Library used incorrectly. |
3457| 14800047  | The WAL file size exceeds the default limit. |
3458
3459**示例:**
3460
3461```ts
3462let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3463predicates.equalTo("NAME", "Lisa");
3464if(store != undefined) {
3465  (store as relationalStore.RdbStore).delete(predicates, (err, rows) => {
3466    if (err) {
3467      console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
3468      return;
3469    }
3470    console.info(`Delete rows: ${rows}`);
3471  })
3472}
3473```
3474
3475### delete
3476
3477delete(predicates: RdbPredicates):Promise&lt;number&gt;
3478
3479根据RdbPredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。
3480
3481**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3482
3483**参数:**
3484
3485| 参数名     | 类型                                 | 必填 | 说明                                      |
3486| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
3487| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
3488
3489**返回值**:
3490
3491| 类型                  | 说明                            |
3492| --------------------- | ------------------------------- |
3493| Promise&lt;number&gt; | Promise对象。返回受影响的行数。 |
3494
3495**错误码:**
3496
3497以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3498
3499| **错误码ID** | **错误信息**                                                 |
3500|-----------| ------------------------------------------------------------ |
3501| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3502| 14800000  | Inner error. |
3503| 14800011  | Database corrupted. |
3504| 14800014  | Already closed. |
3505| 14800015  | The database does not respond. |
3506| 14800021  | SQLite: Generic error. |
3507| 14800022  | SQLite: Callback routine requested an abort. |
3508| 14800023  | SQLite: Access permission denied. |
3509| 14800024  | SQLite: The database file is locked. |
3510| 14800025  | SQLite: A table in the database is locked. |
3511| 14800026  | SQLite: The database is out of memory. |
3512| 14800027  | SQLite: Attempt to write a readonly database. |
3513| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3514| 14800029  | SQLite: The database is full. |
3515| 14800030  | SQLite: Unable to open the database file. |
3516| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3517| 14800032  | SQLite: Abort due to constraint violation. |
3518| 14800033  | SQLite: Data type mismatch. |
3519| 14800034  | SQLite: Library used incorrectly. |
3520| 14800047  | The WAL file size exceeds the default limit. |
3521
3522**示例:**
3523
3524```ts
3525import { BusinessError } from '@kit.BasicServicesKit';
3526
3527let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3528predicates.equalTo("NAME", "Lisa");
3529if(store != undefined) {
3530  (store as relationalStore.RdbStore).delete(predicates).then((rows: Number) => {
3531    console.info(`Delete rows: ${rows}`);
3532  }).catch((err: BusinessError) => {
3533    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
3534  })
3535}
3536```
3537
3538### deleteSync<sup>12+</sup>
3539
3540deleteSync(predicates: RdbPredicates):number
3541
3542根据RdbPredicates的指定实例对象从数据库中删除数据。
3543
3544**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3545
3546**参数:**
3547
3548| 参数名     | 类型                            | 必填 | 说明                                    |
3549| ---------- | ------------------------------- | ---- | --------------------------------------- |
3550| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
3551
3552**返回值**:
3553
3554| 类型   | 说明               |
3555| ------ | ------------------ |
3556| number | 返回受影响的行数。 |
3557
3558**错误码:**
3559
3560以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3561
3562| **错误码ID** | **错误信息**                                                 |
3563| ------------ | ------------------------------------------------------------ |
3564| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3565| 14800000     | Inner error.                                                 |
3566| 14800011     | Database corrupted.                                          |
3567| 14800014     | Already closed.                                              |
3568| 14800015     | The database does not respond.                                        |
3569| 14800021     | SQLite: Generic error.                                       |
3570| 14800022     | SQLite: Callback routine requested an abort.                 |
3571| 14800023     | SQLite: Access permission denied.                            |
3572| 14800024     | SQLite: The database file is locked.                         |
3573| 14800025     | SQLite: A table in the database is locked.                   |
3574| 14800026     | SQLite: The database is out of memory.                       |
3575| 14800027     | SQLite: Attempt to write a readonly database.                |
3576| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
3577| 14800029     | SQLite: The database is full.                                |
3578| 14800030     | SQLite: Unable to open the database file.                    |
3579| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
3580| 14800032     | SQLite: Abort due to constraint violation.                   |
3581| 14800033     | SQLite: Data type mismatch.                                  |
3582| 14800034     | SQLite: Library used incorrectly.                            |
3583| 14800047     | The WAL file size exceeds the default limit.                 |
3584
3585**示例:**
3586
3587```ts
3588import { BusinessError } from '@kit.BasicServicesKit';
3589
3590let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3591predicates.equalTo("NAME", "Lisa");
3592if(store != undefined) {
3593  try {
3594    let rows: Number = (store as relationalStore.RdbStore).deleteSync(predicates)
3595    console.info(`Delete rows: ${rows}`);
3596  } catch (err) {
3597    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
3598  }
3599}
3600```
3601
3602### query<sup>10+</sup>
3603
3604query(predicates: RdbPredicates, callback: AsyncCallback&lt;ResultSet&gt;):void
3605
3606根据指定条件查询数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3607
3608**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3609
3610**参数:**
3611
3612| 参数名     | 类型                                                         | 必填 | 说明                                                        |
3613| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
3614| predicates | [RdbPredicates](#rdbpredicates)                         | 是   | RdbPredicates的实例对象指定的查询条件。                   |
3615| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
3616
3617**错误码:**
3618
3619以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3620
3621| **错误码ID** | **错误信息**                                                 |
3622|-----------| ------------------------------------------------------------ |
3623| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3624| 14800000  | Inner error. |
3625| 14800014  | Already closed. |
3626| 14800015  | The database does not respond. |
3627
3628**示例:**
3629
3630```ts
3631let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3632predicates.equalTo("NAME", "Rose");
3633if(store != undefined) {
3634  (store as relationalStore.RdbStore).query(predicates, (err, resultSet) => {
3635    if (err) {
3636      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
3637      return;
3638    }
3639    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3640    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3641    while (resultSet.goToNextRow()) {
3642      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3643      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3644      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3645      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3646      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3647    }
3648    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3649    resultSet.close();
3650  })
3651}
3652```
3653
3654### query
3655
3656query(predicates: RdbPredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
3657
3658根据指定条件查询数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3659
3660**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3661
3662**参数:**
3663
3664| 参数名     | 类型                                                         | 必填 | 说明                                                        |
3665| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
3666| predicates | [RdbPredicates](#rdbpredicates)                         | 是   | RdbPredicates的实例对象指定的查询条件。                   |
3667| columns    | Array&lt;string&gt;                                          | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。            |
3668| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
3669
3670**错误码:**
3671
3672以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3673
3674| **错误码ID** | **错误信息**                                                 |
3675|-----------| ------------------------------------------------------------ |
3676| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3677| 14800000  | Inner error. |
3678| 14800014  | Already closed. |
3679| 14800015  | The database does not respond. |
3680
3681**示例:**
3682
3683```ts
3684let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3685predicates.equalTo("NAME", "Rose");
3686if(store != undefined) {
3687  (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], (err, resultSet) => {
3688    if (err) {
3689      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
3690      return;
3691    }
3692    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3693    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3694    while (resultSet.goToNextRow()) {
3695      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3696      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3697      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3698      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3699      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3700    }
3701    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3702    resultSet.close();
3703  })
3704}
3705```
3706
3707### query
3708
3709query(predicates: RdbPredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
3710
3711根据指定条件查询数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3712
3713**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3714
3715**参数:**
3716
3717| 参数名     | 类型                                 | 必填 | 说明                                             |
3718| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
3719| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。        |
3720| columns    | Array&lt;string&gt;                  | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
3721
3722**错误码:**
3723
3724以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3725
3726| **错误码ID** | **错误信息**                                                 |
3727|-----------| ------------------------------------------------------------ |
3728| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3729| 14800000  | Inner error. |
3730| 14800014  | Already closed. |
3731| 14800015  | The database does not respond. |
3732
3733**返回值**:
3734
3735| 类型                                                    | 说明                                               |
3736| ------------------------------------------------------- | -------------------------------------------------- |
3737| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
3738
3739**示例:**
3740
3741```ts
3742import { BusinessError } from '@kit.BasicServicesKit';
3743
3744let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3745predicates.equalTo("NAME", "Rose");
3746if(store != undefined) {
3747  (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => {
3748    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3749    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3750    while (resultSet.goToNextRow()) {
3751      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3752      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3753      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3754      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3755      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3756    }
3757    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3758    resultSet.close();
3759  }).catch((err: BusinessError) => {
3760    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
3761  })
3762}
3763```
3764
3765### querySync<sup>12+</sup>
3766
3767querySync(predicates: RdbPredicates, columns?: Array&lt;string&gt;):ResultSet
3768
3769根据指定条件查询数据库中的数据。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
3770
3771**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3772
3773**参数:**
3774
3775| 参数名     | 类型                            | 必填 | 说明                                                         |
3776| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ |
3777| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。                      |
3778| columns    | Array&lt;string&gt;             | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。默认值为空。 |
3779
3780**错误码:**
3781
3782以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3783
3784| **错误码ID** | **错误信息**                                                 |
3785| ------------ | ------------------------------------------------------------ |
3786| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3787| 14800000     | Inner error.                                                 |
3788| 14800014     | Already closed.                                              |
3789| 14800015     | The database does not respond.                                        |
3790
3791**返回值**:
3792
3793| 类型                    | 说明                                |
3794| ----------------------- | ----------------------------------- |
3795| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
3796
3797**示例:**
3798
3799```ts
3800import { BusinessError } from '@kit.BasicServicesKit';
3801
3802let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3803predicates.equalTo("NAME", "Rose");
3804if(store != undefined) {
3805  try {
3806    let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
3807    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3808    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3809    while (resultSet.goToNextRow()) {
3810      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3811      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3812      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3813      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3814      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3815    }
3816    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3817    resultSet.close();
3818  } catch (err) {
3819    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
3820  }
3821}
3822```
3823
3824### remoteQuery
3825
3826remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt; , callback: AsyncCallback&lt;ResultSet&gt;): void
3827
3828根据指定条件查询远程设备数据库中的数据。使用callback异步回调。
3829
3830> **说明:**
3831>
3832> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
3833
3834**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3835
3836**参数:**
3837
3838| 参数名     | 类型                                         | 必填 | 说明                                                      |
3839| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- |
3840| device     | string                                       | 是   | 指定的远程设备ID。                                        |
3841| table      | string                                       | 是   | 指定的目标表名。                                          |
3842| predicates | [RdbPredicates](#rdbpredicates)              | 是   | RdbPredicates的实例对象,指定查询的条件。                 |
3843| columns    | Array&lt;string&gt;                          | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。          |
3844| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
3845
3846**错误码:**
3847
3848以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3849
3850| **错误码ID** | **错误信息**                                                 |
3851|-----------| ------------------------------------------------------------ |
3852| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3853| 801       | Capability not supported. |
3854| 14800000  | Inner error. |
3855| 14800014  | Already closed. |
3856
3857**示例:**
3858
3859```ts
3860import { distributedDeviceManager } from '@kit.DistributedServiceKit';
3861import { BusinessError } from '@kit.BasicServicesKit';
3862
3863let dmInstance: distributedDeviceManager.DeviceManager;
3864let deviceId: string | undefined = undefined;
3865
3866try {
3867  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
3868  let devices = dmInstance.getAvailableDeviceListSync();
3869  if(deviceId != undefined) {
3870    deviceId = devices[0].networkId;
3871  }
3872} catch (err) {
3873  let code = (err as BusinessError).code;
3874  let message = (err as BusinessError).message;
3875  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
3876}
3877
3878let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
3879predicates.greaterThan("id", 0);
3880if(store != undefined && deviceId != undefined) {
3881  (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => {
3882    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3883    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3884    while (resultSet.goToNextRow()) {
3885      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3886      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3887      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3888      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3889      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3890    }
3891    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3892    resultSet.close();
3893  }).catch((err: BusinessError) => {
3894    console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
3895  })
3896}
3897```
3898
3899### remoteQuery
3900
3901remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt;): Promise&lt;ResultSet&gt;
3902
3903根据指定条件查询远程设备数据库中的数据。使用Promise异步回调。
3904
3905> **说明:**
3906>
3907> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
3908
3909**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3910
3911**参数:**
3912
3913| 参数名     | 类型                                 | 必填 | 说明                                             |
3914| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
3915| device     | string                               | 是   | 指定的远程设备ID。                   |
3916| table      | string                               | 是   | 指定的目标表名。                                 |
3917| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象,指定查询的条件。      |
3918| columns    | Array&lt;string&gt;                  | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
3919
3920**返回值**:
3921
3922| 类型                                                         | 说明                                               |
3923| ------------------------------------------------------------ | -------------------------------------------------- |
3924| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
3925
3926**错误码:**
3927
3928以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3929
3930| **错误码ID** | **错误信息**                                                 |
3931|-----------| ------------------------------------------------------------ |
3932| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3933| 801       | Capability not supported. |
3934| 14800000  | Inner error. |
3935| 14800014  | Already closed. |
3936
3937**示例:**
3938
3939```ts
3940import { distributedDeviceManager } from '@kit.DistributedServiceKit';
3941import { BusinessError } from '@kit.BasicServicesKit';
3942
3943let dmInstance: distributedDeviceManager.DeviceManager;
3944let deviceId: string | undefined = undefined;
3945
3946try {
3947  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
3948  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
3949  if(devices != undefined) {
3950    deviceId = devices[0].networkId;
3951  }
3952} catch (err) {
3953  let code = (err as BusinessError).code;
3954  let message = (err as BusinessError).message;
3955  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
3956}
3957
3958let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
3959predicates.greaterThan("id", 0);
3960if(store != undefined && deviceId != undefined) {
3961  (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => {
3962    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3963    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3964    while (resultSet.goToNextRow()) {
3965      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3966      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3967      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3968      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3969      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3970    }
3971    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3972    resultSet.close();
3973  }).catch((err: BusinessError) => {
3974    console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
3975  })
3976}
3977```
3978
3979### querySql<sup>10+</sup>
3980
3981querySql(sql: string, callback: AsyncCallback&lt;ResultSet&gt;):void
3982
3983根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
3984
3985**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3986
3987**参数:**
3988
3989| 参数名   | 类型                                         | 必填 | 说明                                    |
3990| -------- | -------------------------------------------- | ---- |---------------------------------------|
3991| sql      | string                                       | 是   | 指定要执行的SQL语句。                          |
3992| callback | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
3993
3994**错误码:**
3995
3996以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3997
3998| **错误码ID** | **错误信息**                                                 |
3999|-----------| ------------------------------------------------------------ |
4000| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4001| 14800000  | Inner error. |
4002| 14800014  | Already closed. |
4003| 14800015  | The database does not respond. |
4004
4005**示例:**
4006
4007```ts
4008if(store != undefined) {
4009  (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'", (err, resultSet) => {
4010    if (err) {
4011      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4012      return;
4013    }
4014    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4015    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4016    while (resultSet.goToNextRow()) {
4017      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4018      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4019      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4020      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4021      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4022    }
4023    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4024    resultSet.close();
4025  })
4026}
4027```
4028
4029### querySql
4030
4031querySql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
4032
4033根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
4034
4035**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4036
4037**参数:**
4038
4039| 参数名   | 类型                                         | 必填 | 说明                                                         |
4040| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
4041| sql      | string                                       | 是   | 指定要执行的SQL语句。                                        |
4042| bindArgs | Array&lt;[ValueType](#valuetype)&gt;         | 是   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数需为空数组。 |
4043| callback | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。    |
4044
4045**错误码:**
4046
4047以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4048
4049| **错误码ID** | **错误信息**                                                 |
4050|-----------| ------------------------------------------------------------ |
4051| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4052| 14800000  | Inner error. |
4053| 14800014  | Already closed. |
4054| 14800015  | The database does not respond. |
4055
4056**示例:**
4057
4058```ts
4059if(store != undefined) {
4060  (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], (err, resultSet) => {
4061    if (err) {
4062      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4063      return;
4064    }
4065    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4066    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4067    while (resultSet.goToNextRow()) {
4068      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4069      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4070      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4071      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4072      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4073    }
4074    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4075    resultSet.close();
4076  })
4077}
4078```
4079
4080### querySql
4081
4082querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt;
4083
4084根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
4085
4086**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4087
4088**参数:**
4089
4090| 参数名   | 类型                                 | 必填 | 说明                                                         |
4091| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4092| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4093| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
4094
4095**返回值**:
4096
4097| 类型                                                    | 说明                                               |
4098| ------------------------------------------------------- | -------------------------------------------------- |
4099| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
4100
4101**错误码:**
4102
4103以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4104
4105| **错误码ID** | **错误信息**                                                 |
4106|-----------| ------------------------------------------------------------ |
4107| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4108| 14800000  | Inner error. |
4109| 14800014  | Already closed. |
4110| 14800015  | The database does not respond. |
4111
4112**示例:**
4113
4114```ts
4115import { BusinessError } from '@kit.BasicServicesKit';
4116
4117if(store != undefined) {
4118  (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then((resultSet: relationalStore.ResultSet) => {
4119    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4120    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4121    while (resultSet.goToNextRow()) {
4122      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4123      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4124      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4125      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4126      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4127    }
4128    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4129    resultSet.close();
4130  }).catch((err: BusinessError) => {
4131    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4132  })
4133}
4134```
4135
4136### querySqlSync<sup>12+</sup>
4137
4138querySqlSync(sql: string, bindArgs?: Array&lt;ValueType&gt;):ResultSet
4139
4140根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
4141
4142**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4143
4144**参数:**
4145
4146| 参数名   | 类型                                 | 必填 | 说明                                                         |
4147| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4148| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4149| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。默认值为空。 |
4150
4151**返回值**:
4152
4153| 类型                    | 说明                                |
4154| ----------------------- | ----------------------------------- |
4155| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
4156
4157**错误码:**
4158
4159以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4160
4161| **错误码ID** | **错误信息**                                                 |
4162| ------------ | ------------------------------------------------------------ |
4163| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4164| 14800000     | Inner error.                                                 |
4165| 14800014     | Already closed.                                              |
4166| 14800015     | The database does not respond.                                        |
4167
4168**示例:**
4169
4170```ts
4171import { BusinessError } from '@kit.BasicServicesKit';
4172
4173if(store != undefined) {
4174  try {
4175    let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'");
4176    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4177    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4178    while (resultSet.goToNextRow()) {
4179      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4180      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4181      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4182      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4183      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4184    }
4185    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4186    resultSet.close();
4187  } catch (err) {
4188    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4189  }
4190}
4191```
4192
4193### executeSql<sup>10+</sup>
4194
4195executeSql(sql: string, callback: AsyncCallback&lt;void&gt;):void
4196
4197执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
4198
4199此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4200
4201不支持分号分隔的多条语句。
4202
4203**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4204
4205**参数:**
4206
4207| 参数名   | 类型                                 | 必填 | 说明                                                         |
4208| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4209| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4210| callback | AsyncCallback&lt;void&gt;            | 是   | 指定callback回调函数。                                       |
4211
4212**错误码:**
4213
4214以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4215
4216| **错误码ID** | **错误信息**                                                 |
4217|-----------| ------------------------------------------------------------ |
4218| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4219| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4220| 14800000  | Inner error. |
4221| 14800011  | Database corrupted. |
4222| 14800014  | Already closed. |
4223| 14800015  | The database does not respond. |
4224| 14800021  | SQLite: Generic error. |
4225| 14800022  | SQLite: Callback routine requested an abort. |
4226| 14800023  | SQLite: Access permission denied. |
4227| 14800024  | SQLite: The database file is locked. |
4228| 14800025  | SQLite: A table in the database is locked. |
4229| 14800026  | SQLite: The database is out of memory. |
4230| 14800027  | SQLite: Attempt to write a readonly database. |
4231| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4232| 14800029  | SQLite: The database is full. |
4233| 14800030  | SQLite: Unable to open the database file. |
4234| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4235| 14800032  | SQLite: Abort due to constraint violation. |
4236| 14800033  | SQLite: Data type mismatch. |
4237| 14800034  | SQLite: Library used incorrectly. |
4238| 14800047  | The WAL file size exceeds the default limit. |
4239
4240**示例:**
4241
4242```ts
4243const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"
4244if(store != undefined) {
4245  (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, (err) => {
4246    if (err) {
4247      console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
4248      return;
4249    }
4250    console.info('Delete table done.');
4251  })
4252}
4253```
4254
4255### executeSql
4256
4257executeSql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;void&gt;):void
4258
4259执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
4260
4261此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4262
4263不支持分号分隔的多条语句。
4264
4265**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4266
4267**参数:**
4268
4269| 参数名   | 类型                                 | 必填 | 说明                                                         |
4270| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4271| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4272| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 是   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数需为空数组。 |
4273| callback | AsyncCallback&lt;void&gt;            | 是   | 指定callback回调函数。                                       |
4274
4275**错误码:**
4276
4277以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4278
4279| **错误码ID** | **错误信息**                                                 |
4280|-----------| ------------------------------------------------------------ |
4281| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4282| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4283| 14800000  | Inner error. |
4284| 14800011  | Database corrupted. |
4285| 14800014  | Already closed. |
4286| 14800015  | The database does not respond. |
4287| 14800021  | SQLite: Generic error. |
4288| 14800022  | SQLite: Callback routine requested an abort. |
4289| 14800023  | SQLite: Access permission denied. |
4290| 14800024  | SQLite: The database file is locked. |
4291| 14800025  | SQLite: A table in the database is locked. |
4292| 14800026  | SQLite: The database is out of memory. |
4293| 14800027  | SQLite: Attempt to write a readonly database. |
4294| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4295| 14800029  | SQLite: The database is full. |
4296| 14800030  | SQLite: Unable to open the database file. |
4297| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4298| 14800032  | SQLite: Abort due to constraint violation. |
4299| 14800033  | SQLite: Data type mismatch. |
4300| 14800034  | SQLite: Library used incorrectly. |
4301| 14800047  | The WAL file size exceeds the default limit. |
4302
4303**示例:**
4304
4305```ts
4306const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?"
4307if(store != undefined) {
4308  (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, ['zhangsan'], (err) => {
4309    if (err) {
4310      console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
4311      return;
4312    }
4313    console.info('Delete table done.');
4314  })
4315}
4316```
4317
4318### executeSql
4319
4320executeSql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;void&gt;
4321
4322执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
4323
4324此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4325
4326不支持分号分隔的多条语句。
4327
4328**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4329
4330**参数:**
4331
4332| 参数名   | 类型                                 | 必填 | 说明                                                         |
4333| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4334| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4335| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
4336
4337**返回值**:
4338
4339| 类型                | 说明                      |
4340| ------------------- | ------------------------- |
4341| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4342
4343**错误码:**
4344
4345以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4346
4347| **错误码ID** | **错误信息**                                                 |
4348|-----------| ------------------------------------------------------------ |
4349| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4350| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4351| 14800000  | Inner error. |
4352| 14800011  | Database corrupted. |
4353| 14800014  | Already closed. |
4354| 14800015  | The database does not respond. |
4355| 14800021  | SQLite: Generic error. |
4356| 14800022  | SQLite: Callback routine requested an abort. |
4357| 14800023  | SQLite: Access permission denied. |
4358| 14800024  | SQLite: The database file is locked. |
4359| 14800025  | SQLite: A table in the database is locked. |
4360| 14800026  | SQLite: The database is out of memory. |
4361| 14800027  | SQLite: Attempt to write a readonly database. |
4362| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4363| 14800029  | SQLite: The database is full. |
4364| 14800030  | SQLite: Unable to open the database file. |
4365| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4366| 14800032  | SQLite: Abort due to constraint violation. |
4367| 14800033  | SQLite: Data type mismatch. |
4368| 14800034  | SQLite: Library used incorrectly. |
4369| 14800047  | The WAL file size exceeds the default limit. |
4370
4371**示例:**
4372
4373```ts
4374import { BusinessError } from '@kit.BasicServicesKit';
4375
4376const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"
4377if(store != undefined) {
4378  (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE).then(() => {
4379    console.info('Delete table done.');
4380  }).catch((err: BusinessError) => {
4381    console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
4382  })
4383}
4384```
4385
4386### execute<sup>12+</sup>
4387
4388execute(sql: string, args?: Array&lt;ValueType&gt;):Promise&lt;ValueType&gt;
4389
4390执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType,使用Promise异步回调。
4391
4392该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
4393
4394此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4395
4396不支持分号分隔的多条语句。
4397
4398**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4399
4400**参数:**
4401
4402| 参数名   | 类型                                 | 必填 | 说明                                                         |
4403| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4404| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4405| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
4406
4407**返回值**:
4408
4409| 类型                | 说明                      |
4410| ------------------- | ------------------------- |
4411| Promise&lt;[ValueType](#valuetype)&gt; | Promise对象,返回sql执行后的结果。 |
4412
4413**错误码:**
4414
4415以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4416
4417| **错误码ID** | **错误信息**                                                 |
4418|-----------| ------------------------------------------------------------ |
4419| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4420| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4421| 14800000  | Inner error. |
4422| 14800011  | Database corrupted. |
4423| 14800014  | Already closed. |
4424| 14800015  | The database does not respond. |
4425| 14800021  | SQLite: Generic error. |
4426| 14800022  | SQLite: Callback routine requested an abort. |
4427| 14800023  | SQLite: Access permission denied. |
4428| 14800024  | SQLite: The database file is locked. |
4429| 14800025  | SQLite: A table in the database is locked. |
4430| 14800026  | SQLite: The database is out of memory. |
4431| 14800027  | SQLite: Attempt to write a readonly database. |
4432| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4433| 14800029  | SQLite: The database is full. |
4434| 14800030  | SQLite: Unable to open the database file. |
4435| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4436| 14800032  | SQLite: Abort due to constraint violation. |
4437| 14800033  | SQLite: Data type mismatch. |
4438| 14800034  | SQLite: Library used incorrectly. |
4439| 14800047  | The WAL file size exceeds the default limit. |
4440
4441**示例:**
4442
4443```ts
4444import { BusinessError } from '@kit.BasicServicesKit';
4445
4446// 校验数据库完整性
4447if(store != undefined) {
4448  const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check';
4449  (store as relationalStore.RdbStore).execute(SQL_CHECK_INTEGRITY).then((data) => {
4450    console.info(`check result: ${data}`);
4451  }).catch((err: BusinessError) => {
4452    console.error(`check failed, code is ${err.code}, message is ${err.message}`);
4453  })
4454}
4455
4456// 删除表中所有数据
4457if(store != undefined) {
4458  const SQL_DELETE_TABLE = 'DELETE FROM test';
4459  (store as relationalStore.RdbStore).execute(SQL_DELETE_TABLE).then((data) => {
4460    console.info(`delete result: ${data}`);
4461  }).catch((err: BusinessError) => {
4462    console.error(`delete failed, code is ${err.code}, message is ${err.message}`);
4463  })
4464}
4465
4466// 删表
4467if(store != undefined) {
4468  const SQL_DROP_TABLE = 'DROP TABLE test';
4469  (store as relationalStore.RdbStore).execute(SQL_DROP_TABLE).then((data) => {
4470    console.info(`drop result: ${data}`);
4471  }).catch((err: BusinessError) => {
4472    console.error(`drop failed, code is ${err.code}, message is ${err.message}`);
4473  })
4474}
4475```
4476
4477### execute<sup>12+</sup>
4478
4479execute(sql: string, txId: number, args?: Array&lt;ValueType&gt;): Promise&lt;ValueType&gt;
4480
4481执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
4482
4483<!--RP1-->
4484该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End-->
4485
4486此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4487
4488不支持分号分隔的多条语句。
4489
4490**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4491
4492**参数:**
4493
4494| 参数名   | 类型                                 | 必填 | 说明                                                         |
4495| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4496| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4497| txId      | number                               | 是   | 通过[beginTrans](#begintrans12)获取的事务ID,如果传0,该语句默认在单独事务内。                                      |
4498| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。该参数不填,填null或者填undefined,都认为是sql参数语句完整。 |
4499
4500**返回值**:
4501
4502| 类型                | 说明                      |
4503| ------------------- | ------------------------- |
4504| Promise&lt;[ValueType](#valuetype)&gt; | Promise对象,返回null。 |
4505
4506**错误码:**
4507
4508以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4509
4510| **错误码ID** | **错误信息**                                                 |
4511|-----------| ------------------------------------------------------------ |
4512| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4513| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4514| 14800000  | Inner error. |
4515| 14800011  | Database corrupted. |
4516| 14800014  | Already closed. |
4517| 14800015  | The database does not respond. |
4518| 14800021  | SQLite: Generic error. |
4519| 14800022  | SQLite: Callback routine requested an abort. |
4520| 14800023  | SQLite: Access permission denied. |
4521| 14800024  | SQLite: The database file is locked. |
4522| 14800025  | SQLite: A table in the database is locked. |
4523| 14800026  | SQLite: The database is out of memory. |
4524| 14800027  | SQLite: Attempt to write a readonly database. |
4525| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4526| 14800029  | SQLite: The database is full. |
4527| 14800030  | SQLite: Unable to open the database file. |
4528| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4529| 14800032  | SQLite: Abort due to constraint violation. |
4530| 14800033  | SQLite: Data type mismatch. |
4531| 14800034  | SQLite: Library used incorrectly. |
4532| 14800047  | The WAL file size exceeds the default limit. |
4533
4534**示例:**
4535
4536```ts
4537import { BusinessError } from '@kit.BasicServicesKit';
4538if(store != null) {
4539  let txId : number;
4540  (store as relationalStore.RdbStore).beginTrans().then((txId : number) => {
4541    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
4542      .then(() => {
4543        (store as relationalStore.RdbStore).commit(txId);
4544    })
4545    .catch((err: BusinessError) => {
4546      (store as relationalStore.RdbStore).rollback(txId)
4547      console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
4548    });
4549  });
4550}
4551```
4552
4553### executeSync<sup>12+</sup>
4554
4555executeSync(sql: string, args?: Array&lt;ValueType&gt;): ValueType
4556
4557执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType。
4558
4559该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
4560
4561此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4562
4563不支持分号分隔的多条语句。
4564
4565**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4566
4567**参数:**
4568
4569| 参数名 | 类型                                 | 必填 | 说明                                                         |
4570| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
4571| sql    | string                               | 是   | 指定要执行的SQL语句。                                        |
4572| args   | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。该参数不填,或者填null或undefined,都认为是sql参数语句完整。默认值为空。 |
4573
4574**返回值**:
4575
4576| 类型                    | 说明                |
4577| ----------------------- | ------------------- |
4578| [ValueType](#valuetype) | 返回sql执行后的结果 |
4579
4580**错误码:**
4581
4582以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4583
4584| **错误码ID** | **错误信息**                                                 |
4585| ------------ | ------------------------------------------------------------ |
4586| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4587| 14800000     | Inner error.                                                 |
4588| 14800011     | Database corrupted.                                          |
4589| 14800014     | Already closed.                                              |
4590| 14800015     | The database does not respond.                               |
4591| 14800021     | SQLite: Generic error.                                       |
4592| 14800022     | SQLite: Callback routine requested an abort.                 |
4593| 14800023     | SQLite: Access permission denied.                            |
4594| 14800024     | SQLite: The database file is locked.                         |
4595| 14800025     | SQLite: A table in the database is locked.                   |
4596| 14800026     | SQLite: The database is out of memory.                       |
4597| 14800027     | SQLite: Attempt to write a readonly database.                |
4598| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
4599| 14800029     | SQLite: The database is full.                                |
4600| 14800030     | SQLite: Unable to open the database file.                    |
4601| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
4602| 14800032     | SQLite: Abort due to constraint violation.                   |
4603| 14800033     | SQLite: Data type mismatch.                                  |
4604| 14800034     | SQLite: Library used incorrectly.                            |
4605| 14800047     | The WAL file size exceeds the default limit.                 |
4606
4607**示例:**
4608
4609```ts
4610import { BusinessError } from '@kit.BasicServicesKit';
4611
4612// 校验数据库完整性
4613if(store != undefined) {
4614  const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check';
4615  try {
4616    let data = (store as relationalStore.RdbStore).executeSync(SQL_CHECK_INTEGRITY)
4617    console.info(`check result: ${data}`);
4618  } catch (err) {
4619    console.error(`check failed, code is ${err.code}, message is ${err.message}`);
4620  }
4621}
4622
4623// 删除表中所有数据
4624if(store != undefined) {
4625  const SQL_DELETE_TABLE = 'DELETE FROM test';
4626  try {
4627    let data = (store as relationalStore.RdbStore).executeSync(SQL_DELETE_TABLE)
4628    console.info(`delete result: ${data}`);
4629  } catch (err) {
4630    console.error(`delete failed, code is ${err.code}, message is ${err.message}`);
4631  }
4632}
4633
4634// 删表
4635if(store != undefined) {
4636  const SQL_DROP_TABLE = 'DROP TABLE test';
4637  try {
4638    let data = (store as relationalStore.RdbStore).executeSync(SQL_DROP_TABLE)
4639    console.info(`drop result: ${data}`);
4640  } catch (err) {
4641    console.error(`drop failed, code is ${err.code}, message is ${err.message}`);
4642  }
4643}
4644```
4645
4646### getModifyTime<sup>10+</sup>
4647
4648getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[], callback: AsyncCallback&lt;ModifyTime&gt;): void
4649
4650获取数据库表中数据的最后修改时间,使用callback异步回调。
4651
4652**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4653
4654**参数:**
4655
4656| 参数名      | 类型                                             | 必填 | 说明                                                         |
4657| ----------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
4658| table       | string                                           | 是   | 指定要查询的数据库表的表名。                                 |
4659| columnName  | string                                           | 是   | 指定要查询的数据库表的列名。                                 |
4660| primaryKeys | [PRIKeyType](#prikeytype10)[]                    | 是   | 指定要查询的行的主键。<br>如果数据库表无主键,参数columnName需传入"rowid",此时primaryKeys为要查询的数据库表的行号。<br>如果数据库表无主键,参数columnName传入不为"rowid",返回对应的错误码。 |
4661| callback    | AsyncCallback&lt;[ModifyTime](#modifytime10)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ModifyTime对象,表示数据的最后修改时间。 |
4662
4663**错误码:**
4664
4665以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4666
4667| **错误码ID** | **错误信息**                                                 |
4668|-----------| ------------------------------------------------------------ |
4669| 401       | Parameter error. Possible causes: 1. Need 3 - 4  parameter(s)! 2. The RdbStore must be not nullptr.3. The tablesNames must be not empty string. 4. The columnName must be not empty string. 5. The PRIKey must be number or string. |
4670| 801       | Capability not supported. |
4671| 14800000  | Inner error. |
4672| 14800011  | Database corrupted. |
4673| 14800014  | Already closed. |
4674| 14800015  | The database does not respond. |
4675| 14800021  | SQLite: Generic error. |
4676| 14800022  | SQLite: Callback routine requested an abort. |
4677| 14800023  | SQLite: Access permission denied. |
4678| 14800024  | SQLite: The database file is locked. |
4679| 14800025  | SQLite: A table in the database is locked. |
4680| 14800026  | SQLite: The database is out of memory. |
4681| 14800027  | SQLite: Attempt to write a readonly database. |
4682| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4683| 14800029  | SQLite: The database is full. |
4684| 14800030  | SQLite: Unable to open the database file. |
4685| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4686| 14800032  | SQLite: Abort due to constraint violation. |
4687| 14800033  | SQLite: Data type mismatch. |
4688| 14800034  | SQLite: Library used incorrectly. |
4689
4690**示例:**
4691
4692```ts
4693let PRIKey = [1, 4, 2, 3];
4694if(store != undefined) {
4695  (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey, (err, modifyTime: relationalStore.ModifyTime) => {
4696    if (err) {
4697      console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`);
4698      return;
4699    }
4700    let size = modifyTime.size;
4701  });
4702}
4703```
4704
4705### getModifyTime<sup>10+</sup>
4706
4707getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[]): Promise&lt;ModifyTime&gt;
4708
4709获取数据库表中数据的最后修改时间,使用Promise异步回调。
4710
4711**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4712
4713**参数:**
4714
4715| 参数名      | 类型                          | 必填 | 说明                                                         |
4716| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ |
4717| table       | string                        | 是   | 指定要查询的数据库表的表名。                                 |
4718| columnName  | string                        | 是   | 指定要查询的数据库表的列名。                                 |
4719| primaryKeys | [PRIKeyType](#prikeytype10)[] | 是   | 指定要查询的行的主键。<br>如果数据库表无主键,参数columnName需传入"rowid",此时primaryKeys为要查询的数据库表的行号。<br>如果数据库表无主键,参数columnName传入不为"rowid",返回对应的错误码。 |
4720
4721**返回值**:
4722
4723| 类型                                       | 说明                                                      |
4724| ------------------------------------------ | --------------------------------------------------------- |
4725| Promise&lt;[ModifyTime](#modifytime10)&gt; | 返回ModifyTime类型的Promise对象,表示数据最后的修改时间。 |
4726
4727**错误码:**
4728
4729以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4730
4731| **错误码ID** | **错误信息**                                                 |
4732|-----------| ------------------------------------------------------------ |
4733| 401       | Parameter error. Possible causes: 1. Need 3 - 4  parameter(s)! 2. The RdbStore must be not nullptr.3. The tablesNames must be not empty string. 4. The columnName must be not empty string. 5. The PRIKey must be number or string. |
4734| 801       | Capability not supported. |
4735| 14800000  | Inner error. |
4736| 14800011  | Database corrupted. |
4737| 14800014  | Already closed. |
4738| 14800015  | The database does not respond. |
4739| 14800021  | SQLite: Generic error. |
4740| 14800022  | SQLite: Callback routine requested an abort. |
4741| 14800023  | SQLite: Access permission denied. |
4742| 14800024  | SQLite: The database file is locked. |
4743| 14800025  | SQLite: A table in the database is locked. |
4744| 14800026  | SQLite: The database is out of memory. |
4745| 14800027  | SQLite: Attempt to write a readonly database. |
4746| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4747| 14800029  | SQLite: The database is full. |
4748| 14800030  | SQLite: Unable to open the database file. |
4749| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4750| 14800032  | SQLite: Abort due to constraint violation. |
4751| 14800033  | SQLite: Data type mismatch. |
4752| 14800034  | SQLite: Library used incorrectly. |
4753
4754**示例:**
4755
4756```ts
4757import { BusinessError } from '@kit.BasicServicesKit';
4758
4759let PRIKey = [1, 2, 3];
4760if(store != undefined) {
4761  (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey)
4762    .then((modifyTime: relationalStore.ModifyTime) => {
4763      let size = modifyTime.size;
4764    })
4765    .catch((err: BusinessError) => {
4766      console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`);
4767    });
4768}
4769```
4770
4771### beginTransaction
4772
4773beginTransaction():void
4774
4775在开始执行SQL语句之前,开始事务。
4776此接口不允许嵌套事务,且不支持在多进程或多线程中使用。
4777
4778**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4779
4780**错误码:**
4781
4782以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4783
4784| **错误码ID** | **错误信息**                                                 |
4785|-----------| ------------------------------------------------------------ |
4786| 401       | Parameter error. The store must not be nullptr. |
4787| 14800000  | Inner error. |
4788| 14800011  | Database corrupted. |
4789| 14800014  | Already closed. |
4790| 14800015  | The database does not respond. |
4791| 14800021  | SQLite: Generic error. |
4792| 14800022  | SQLite: Callback routine requested an abort. |
4793| 14800023  | SQLite: Access permission denied. |
4794| 14800024  | SQLite: The database file is locked. |
4795| 14800025  | SQLite: A table in the database is locked. |
4796| 14800026  | SQLite: The database is out of memory. |
4797| 14800027  | SQLite: Attempt to write a readonly database. |
4798| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4799| 14800029  | SQLite: The database is full. |
4800| 14800030  | SQLite: Unable to open the database file. |
4801| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4802| 14800032  | SQLite: Abort due to constraint violation. |
4803| 14800033  | SQLite: Data type mismatch. |
4804| 14800034  | SQLite: Library used incorrectly. |
4805| 14800047  | The WAL file size exceeds the default limit. |
4806
4807**示例:**
4808
4809```ts
4810
4811let value1 = "Lisa";
4812let value2 = 18;
4813let value3 = 100.5;
4814let value4 = new Uint8Array([1, 2, 3]);
4815
4816if(store != undefined) {
4817  (store as relationalStore.RdbStore).beginTransaction();
4818  const valueBucket: relationalStore.ValuesBucket = {
4819    'NAME': value1,
4820    'AGE': value2,
4821    'SALARY': value3,
4822    'CODES': value4,
4823  };
4824  (store as relationalStore.RdbStore).insert("test", valueBucket);
4825  (store as relationalStore.RdbStore).commit();
4826}
4827```
4828
4829### beginTrans<sup>12+</sup>
4830
4831beginTrans(): Promise&lt;number&gt;
4832
4833在开始执行SQL语句之前,开始事务,使用Promise异步回调。
4834
4835与[beginTransaction](#begintransaction)的区别在于:该接口会返回事务ID,[execute](#execute12-1)可以指定不同事务ID达到事务隔离目的。
4836
4837<!--RP1-->
4838该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End-->
4839
4840**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4841
4842**返回值**:
4843
4844| 类型                | 说明                      |
4845| ------------------- | ------------------------- |
4846| Promise&lt;number&gt; | Promise对象,返回事务ID。 |
4847
4848**错误码:**
4849
4850以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4851
4852| **错误码ID** | **错误信息**                                                 |
4853|-----------| ------------------------------------------------------------ |
4854| 401       | Parameter error. The store must not be nullptr. |
4855| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4856| 14800000  | Inner error. |
4857| 14800011  | Database corrupted. |
4858| 14800014  | Already closed. |
4859| 14800015  | The database does not respond. |
4860| 14800021  | SQLite: Generic error. |
4861| 14800022  | SQLite: Callback routine requested an abort. |
4862| 14800023  | SQLite: Access permission denied. |
4863| 14800024  | SQLite: The database file is locked. |
4864| 14800025  | SQLite: A table in the database is locked. |
4865| 14800026  | SQLite: The database is out of memory. |
4866| 14800027  | SQLite: Attempt to write a readonly database. |
4867| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4868| 14800029  | SQLite: The database is full. |
4869| 14800030  | SQLite: Unable to open the database file. |
4870| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4871| 14800032  | SQLite: Abort due to constraint violation. |
4872| 14800033  | SQLite: Data type mismatch. |
4873| 14800034  | SQLite: Library used incorrectly. |
4874| 14800047  | The WAL file size exceeds the default limit. |
4875
4876**示例:**
4877
4878```ts
4879import { BusinessError } from '@kit.BasicServicesKit';
4880if(store != null) {
4881  let txId : number;
4882  (store as relationalStore.RdbStore).beginTrans().then((txId : number) => {
4883    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
4884      .then(() => {
4885        (store as relationalStore.RdbStore).commit(txId);
4886    })
4887    .catch((err: BusinessError) => {
4888      (store as relationalStore.RdbStore).rollback(txId)
4889      console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
4890    });
4891  });
4892}
4893```
4894
4895### createTransaction<sup>14+</sup>
4896
4897createTransaction(options?: TransactionOptions): Promise&lt;Transaction&gt;
4898
4899创建一个事务对象并开始事务,使用Promise异步回调。
4900
4901与[beginTransaction](#begintransaction)的区别在于:createTransaction接口会返回一个事务对象,不同事务对象之间是隔离的。使用事务对象进行插入、删除或更新数据等操作,无法被注册数据变更通知监听到。
4902
4903一个store最多支持同时存在四个事务对象,超过后会返回14800015错误码,此时需要检查是否持有事务对象时间过长或并发事务过多。如果已无法优化,可以等其它事务释放后再次尝试创建事务对象。
4904
4905优先使用createTransaction,不再推荐使用beginTransaction。
4906
4907**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4908
4909**参数:**
4910
4911| 参数名      | 类型                          | 必填 | 说明                                                         |
4912| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ |
4913| options       | [TransactionOptions](#transactionoptions14)           | 否   | 表示事务对象的配置信息。                                 |
4914
4915**返回值**:
4916
4917| 类型                | 说明                      |
4918| ------------------- | ------------------------- |
4919| Promise&lt;[Transaction](#transaction14)&gt; | Promise对象,返回事务对象。 |
4920
4921**错误码:**
4922
4923以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4924
4925| **错误码ID** | **错误信息**                                                 |
4926|-----------| ------------------------------------------------------------ |
4927| 14800000  | Inner error. |
4928| 14800011  | Database corrupted. |
4929| 14800014  | Already closed. |
4930| 14800015  | The database is busy.              |
4931| 14800023  | SQLite: Access permission denied. |
4932| 14800024  | SQLite: The database file is locked. |
4933| 14800026  | SQLite: The database is out of memory. |
4934| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4935| 14800029  | SQLite: The database is full. |
4936| 14800030  | SQLite: Unable to open the database file. |
4937
4938**示例:**
4939
4940```ts
4941import { BusinessError } from '@kit.BasicServicesKit';
4942
4943if(store != undefined) {
4944  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
4945    transaction.execute("DELETE FROM test WHERE age = ? OR age = ?", [21, 20]).then(() => {
4946      transaction.commit();
4947    }).catch((e: BusinessError) => {
4948      transaction.rollback();
4949      console.error(`execute sql failed, code is ${e.code},message is ${e.message}`);
4950    });
4951  }).catch((err: BusinessError) => {
4952    console.error(`createTransaction faided, code is ${err.code},message is ${err.message}`);
4953  });
4954}
4955```
4956
4957### commit
4958
4959commit():void
4960
4961提交已执行的SQL语句,跟[beginTransaction](#begintransaction)配合使用。
4962此接口不允许嵌套事务,且不支持在多进程或多线程中使用。
4963
4964**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4965
4966**错误码:**
4967
4968以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4969
4970| **错误码ID** | **错误信息**                                                 |
4971|-----------| ------------------------------------------------------------ |
4972| 401       | Parameter error. The store must not be nullptr. |
4973| 14800000  | Inner error. |
4974| 14800011  | Database corrupted. |
4975| 14800014  | Already closed. |
4976| 14800015  | The database does not respond. |
4977| 14800021  | SQLite: Generic error. |
4978| 14800022  | SQLite: Callback routine requested an abort. |
4979| 14800023  | SQLite: Access permission denied. |
4980| 14800024  | SQLite: The database file is locked. |
4981| 14800025  | SQLite: A table in the database is locked. |
4982| 14800026  | SQLite: The database is out of memory. |
4983| 14800027  | SQLite: Attempt to write a readonly database. |
4984| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4985| 14800029  | SQLite: The database is full. |
4986| 14800030  | SQLite: Unable to open the database file. |
4987| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4988| 14800032  | SQLite: Abort due to constraint violation. |
4989| 14800033  | SQLite: Data type mismatch. |
4990| 14800034  | SQLite: Library used incorrectly. |
4991
4992**示例:**
4993
4994```ts
4995
4996let value1 = "Lisa";
4997let value2 = 18;
4998let value3 = 100.5;
4999let value4 = new Uint8Array([1, 2, 3]);
5000
5001if(store != undefined) {
5002  (store as relationalStore.RdbStore).beginTransaction();
5003  const valueBucket: relationalStore.ValuesBucket = {
5004    'NAME': value1,
5005    'AGE': value2,
5006    'SALARY': value3,
5007    'CODES': value4,
5008  };
5009  (store as relationalStore.RdbStore).insert("test", valueBucket);
5010  (store as relationalStore.RdbStore).commit();
5011}
5012```
5013
5014### commit<sup>12+</sup>
5015
5016commit(txId : number):Promise&lt;void&gt;
5017
5018提交已执行的SQL语句,跟[beginTrans](#begintrans12)配合使用。
5019
5020<!--RP1-->
5021该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End-->
5022
5023**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5024
5025**参数:**
5026
5027| 参数名   | 类型                                 | 必填 | 说明                                                         |
5028| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
5029| txId      | number                               | 是   | 通过[beginTrans](#begintrans12)获取的事务ID。                                        |
5030
5031**返回值**:
5032
5033| 类型                | 说明                      |
5034| ------------------- | ------------------------- |
5035| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5036
5037**错误码:**
5038
5039以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5040
5041| **错误码ID** | **错误信息**                                                 |
5042|-----------| ------------------------------------------------------------ |
5043| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5044| 14800000  | Inner error. |
5045| 14800011  | Database corrupted. |
5046| 14800014  | Already closed. |
5047| 14800015  | The database does not respond. |
5048| 14800021  | SQLite: Generic error. |
5049| 14800022  | SQLite: Callback routine requested an abort. |
5050| 14800023  | SQLite: Access permission denied. |
5051| 14800024  | SQLite: The database file is locked. |
5052| 14800025  | SQLite: A table in the database is locked. |
5053| 14800026  | SQLite: The database is out of memory. |
5054| 14800027  | SQLite: Attempt to write a readonly database. |
5055| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5056| 14800029  | SQLite: The database is full. |
5057| 14800030  | SQLite: Unable to open the database file. |
5058| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5059| 14800032  | SQLite: Abort due to constraint violation. |
5060| 14800033  | SQLite: Data type mismatch. |
5061| 14800034  | SQLite: Library used incorrectly. |
5062
5063**示例:**
5064
5065```ts
5066import { BusinessError } from '@kit.BasicServicesKit';
5067if(store != null) {
5068  let txId : number;
5069  (store as relationalStore.RdbStore).beginTrans().then((txId : number) => {
5070    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
5071      .then(() => {
5072        (store as relationalStore.RdbStore).commit(txId);
5073    })
5074    .catch((err: BusinessError) => {
5075      (store as relationalStore.RdbStore).rollback(txId)
5076      console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
5077    });
5078  });
5079}
5080```
5081
5082### rollBack
5083
5084rollBack():void
5085
5086回滚已经执行的SQL语句。
5087此接口不允许嵌套事务,且不支持在多进程或多线程中使用。
5088
5089**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5090
5091**错误码:**
5092
5093以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5094
5095| **错误码ID** | **错误信息**                                                 |
5096|-----------| ------------------------------------------------------------ |
5097| 401       | Parameter error. The store must not be nullptr. |
5098| 14800000  | Inner error. |
5099| 14800011  | Database corrupted. |
5100| 14800014  | Already closed. |
5101| 14800015  | The database does not respond. |
5102| 14800021  | SQLite: Generic error. |
5103| 14800022  | SQLite: Callback routine requested an abort. |
5104| 14800023  | SQLite: Access permission denied. |
5105| 14800024  | SQLite: The database file is locked. |
5106| 14800025  | SQLite: A table in the database is locked. |
5107| 14800026  | SQLite: The database is out of memory. |
5108| 14800027  | SQLite: Attempt to write a readonly database. |
5109| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5110| 14800029  | SQLite: The database is full. |
5111| 14800030  | SQLite: Unable to open the database file. |
5112| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5113| 14800032  | SQLite: Abort due to constraint violation. |
5114| 14800033  | SQLite: Data type mismatch. |
5115| 14800034  | SQLite: Library used incorrectly. |
5116
5117**示例:**
5118
5119```ts
5120import { BusinessError } from '@kit.BasicServicesKit';
5121
5122let value1 = "Lisa";
5123let value2 = 18;
5124let value3 = 100.5;
5125let value4 = new Uint8Array([1, 2, 3]);
5126
5127if(store != undefined) {
5128  try {
5129    (store as relationalStore.RdbStore).beginTransaction()
5130    const valueBucket: relationalStore.ValuesBucket = {
5131      'NAME': value1,
5132      'AGE': value2,
5133      'SALARY': value3,
5134      'CODES': value4,
5135    };
5136    (store as relationalStore.RdbStore).insert("test", valueBucket);
5137    (store as relationalStore.RdbStore).commit();
5138  } catch (err) {
5139    let code = (err as BusinessError).code;
5140    let message = (err as BusinessError).message
5141    console.error(`Transaction failed, code is ${code},message is ${message}`);
5142    (store as relationalStore.RdbStore).rollBack();
5143  }
5144}
5145```
5146
5147### rollback<sup>12+</sup>
5148
5149rollback(txId : number):Promise&lt;void&gt;
5150
5151回滚已经执行的SQL语句,跟[beginTrans](#begintrans12)配合使用。
5152
5153<!--RP1-->
5154该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End-->
5155
5156**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5157
5158**参数:**
5159
5160| 参数名   | 类型                                 | 必填 | 说明                                                         |
5161| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
5162| txId      | number                               | 是   | 通过[beginTrans](#begintrans12)获取的事务ID。                                        |
5163
5164**返回值**:
5165
5166| 类型                | 说明                      |
5167| ------------------- | ------------------------- |
5168| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5169
5170**错误码:**
5171
5172以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5173
5174| **错误码ID** | **错误信息**                                                 |
5175|-----------| ------------------------------------------------------------ |
5176| 401       | Parameter error. The store must not be nullptr. |
5177| 14800000  | Inner error. |
5178| 14800011  | Database corrupted. |
5179| 14800014  | Already closed. |
5180| 14800015  | The database does not respond. |
5181| 14800021  | SQLite: Generic error. |
5182| 14800022  | SQLite: Callback routine requested an abort. |
5183| 14800023  | SQLite: Access permission denied. |
5184| 14800024  | SQLite: The database file is locked. |
5185| 14800025  | SQLite: A table in the database is locked. |
5186| 14800026  | SQLite: The database is out of memory. |
5187| 14800027  | SQLite: Attempt to write a readonly database. |
5188| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5189| 14800029  | SQLite: The database is full. |
5190| 14800030  | SQLite: Unable to open the database file. |
5191| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5192| 14800032  | SQLite: Abort due to constraint violation. |
5193| 14800033  | SQLite: Data type mismatch. |
5194| 14800034  | SQLite: Library used incorrectly. |
5195
5196**示例:**
5197
5198```ts
5199import { BusinessError } from '@kit.BasicServicesKit';
5200if(store != null) {
5201  let txId : number;
5202  (store as relationalStore.RdbStore).beginTrans().then((txId : number) => {
5203    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
5204      .then(() => {
5205        (store as relationalStore.RdbStore).commit(txId);
5206    })
5207    .catch((err: BusinessError) => {
5208      (store as relationalStore.RdbStore).rollback(txId)
5209      console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
5210    });
5211  });
5212}
5213```
5214
5215### backup
5216
5217backup(destName:string, callback: AsyncCallback&lt;void&gt;):void
5218
5219以指定名称备份数据库,使用callback异步回调。
5220
5221**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5222
5223**参数:**
5224
5225| 参数名   | 类型                      | 必填 | 说明                     |
5226| -------- | ------------------------- | ---- | ------------------------ |
5227| destName | string                    | 是   | 指定数据库的备份文件名。 |
5228| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。   |
5229
5230**错误码:**
5231
5232以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5233
5234| **错误码ID** | **错误信息**                                                 |
5235|-----------| ------------------------------------------------------------ |
5236| 401       | Parameter error. The store must not be nullptr. |
5237| 14800000  | Inner error. |
5238| 14800010  | Invalid database path. |
5239| 14800011  | Database corrupted. |
5240| 14800014  | Already closed. |
5241| 14800015  | The database does not respond. |
5242| 14800021  | SQLite: Generic error. |
5243| 14800022  | SQLite: Callback routine requested an abort. |
5244| 14800023  | SQLite: Access permission denied. |
5245| 14800024  | SQLite: The database file is locked. |
5246| 14800025  | SQLite: A table in the database is locked. |
5247| 14800026  | SQLite: The database is out of memory. |
5248| 14800027  | SQLite: Attempt to write a readonly database. |
5249| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5250| 14800029  | SQLite: The database is full. |
5251| 14800030  | SQLite: Unable to open the database file. |
5252| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5253| 14800032  | SQLite: Abort due to constraint violation. |
5254| 14800033  | SQLite: Data type mismatch. |
5255| 14800034  | SQLite: Library used incorrectly. |
5256
5257**示例:**
5258
5259```ts
5260if(store != undefined) {
5261  (store as relationalStore.RdbStore).backup("dbBackup.db", (err) => {
5262    if (err) {
5263      console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
5264      return;
5265    }
5266    console.info('Backup success.');
5267  })
5268}
5269```
5270
5271### backup
5272
5273backup(destName:string): Promise&lt;void&gt;
5274
5275以指定名称备份数据库,使用Promise异步回调。
5276
5277**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5278
5279**参数:**
5280
5281| 参数名   | 类型   | 必填 | 说明                     |
5282| -------- | ------ | ---- | ------------------------ |
5283| destName | string | 是   | 指定数据库的备份文件名。 |
5284
5285**返回值**:
5286
5287| 类型                | 说明                      |
5288| ------------------- | ------------------------- |
5289| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5290
5291**错误码:**
5292
5293以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5294
5295| **错误码ID** | **错误信息**                                                 |
5296|-----------| ------------------------------------------------------------ |
5297| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5298| 14800000  | Inner error. |
5299| 14800011  | Database corrupted. |
5300| 14800014  | Already closed. |
5301| 14800015  | The database does not respond. |
5302| 14800021  | SQLite: Generic error. |
5303| 14800022  | SQLite: Callback routine requested an abort. |
5304| 14800023  | SQLite: Access permission denied. |
5305| 14800024  | SQLite: The database file is locked. |
5306| 14800025  | SQLite: A table in the database is locked. |
5307| 14800026  | SQLite: The database is out of memory. |
5308| 14800027  | SQLite: Attempt to write a readonly database. |
5309| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5310| 14800029  | SQLite: The database is full. |
5311| 14800030  | SQLite: Unable to open the database file. |
5312| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5313| 14800032  | SQLite: Abort due to constraint violation. |
5314| 14800033  | SQLite: Data type mismatch. |
5315| 14800034  | SQLite: Library used incorrectly. |
5316
5317**示例:**
5318
5319```ts
5320import { BusinessError } from '@kit.BasicServicesKit';
5321
5322if(store != undefined) {
5323  let promiseBackup = (store as relationalStore.RdbStore).backup("dbBackup.db");
5324  promiseBackup.then(() => {
5325    console.info('Backup success.');
5326  }).catch((err: BusinessError) => {
5327    console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
5328  })
5329}
5330```
5331
5332### restore
5333
5334restore(srcName:string, callback: AsyncCallback&lt;void&gt;):void
5335
5336从指定的数据库备份文件恢复数据库,使用callback异步回调。
5337
5338**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5339
5340**参数:**
5341
5342| 参数名   | 类型                      | 必填 | 说明                     |
5343| -------- | ------------------------- | ---- | ------------------------ |
5344| srcName  | string                    | 是   | 指定数据库的备份文件名。 |
5345| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。   |
5346
5347**错误码:**
5348
5349以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5350
5351| **错误码ID** | **错误信息**                                                 |
5352|-----------| ------------------------------------------------------------ |
5353| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5354| 14800000  | Inner error. |
5355| 14800011  | Database corrupted. |
5356| 14800014  | Already closed. |
5357| 14800015  | The database does not respond. |
5358| 14800021  | SQLite: Generic error. |
5359| 14800022  | SQLite: Callback routine requested an abort. |
5360| 14800023  | SQLite: Access permission denied. |
5361| 14800024  | SQLite: The database file is locked. |
5362| 14800025  | SQLite: A table in the database is locked. |
5363| 14800026  | SQLite: The database is out of memory. |
5364| 14800027  | SQLite: Attempt to write a readonly database. |
5365| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5366| 14800029  | SQLite: The database is full. |
5367| 14800030  | SQLite: Unable to open the database file. |
5368| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5369| 14800032  | SQLite: Abort due to constraint violation. |
5370| 14800033  | SQLite: Data type mismatch. |
5371| 14800034  | SQLite: Library used incorrectly. |
5372
5373**示例:**
5374
5375```ts
5376if(store != undefined) {
5377  (store as relationalStore.RdbStore).restore("dbBackup.db", (err) => {
5378    if (err) {
5379      console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
5380      return;
5381    }
5382    console.info('Restore success.');
5383  })
5384}
5385```
5386
5387### restore
5388
5389restore(srcName:string): Promise&lt;void&gt;
5390
5391从指定的数据库备份文件恢复数据库,使用Promise异步回调。
5392
5393**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5394
5395**参数:**
5396
5397| 参数名  | 类型   | 必填 | 说明                     |
5398| ------- | ------ | ---- | ------------------------ |
5399| srcName | string | 是   | 指定数据库的备份文件名。 |
5400
5401**返回值**:
5402
5403| 类型                | 说明                      |
5404| ------------------- | ------------------------- |
5405| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5406
5407**错误码:**
5408
5409以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5410
5411| **错误码ID** | **错误信息**                                                 |
5412|-----------| ------------------------------------------------------------ |
5413| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5414| 14800000  | Inner error. |
5415| 14800011  | Database corrupted. |
5416| 14800014  | Already closed. |
5417| 14800015  | The database does not respond. |
5418| 14800021  | SQLite: Generic error. |
5419| 14800022  | SQLite: Callback routine requested an abort. |
5420| 14800023  | SQLite: Access permission denied. |
5421| 14800024  | SQLite: The database file is locked. |
5422| 14800025  | SQLite: A table in the database is locked. |
5423| 14800026  | SQLite: The database is out of memory. |
5424| 14800027  | SQLite: Attempt to write a readonly database. |
5425| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5426| 14800029  | SQLite: The database is full. |
5427| 14800030  | SQLite: Unable to open the database file. |
5428| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5429| 14800032  | SQLite: Abort due to constraint violation. |
5430| 14800033  | SQLite: Data type mismatch. |
5431| 14800034  | SQLite: Library used incorrectly. |
5432
5433**示例:**
5434
5435```ts
5436import { BusinessError } from '@kit.BasicServicesKit';
5437
5438if(store != undefined) {
5439  let promiseRestore = (store as relationalStore.RdbStore).restore("dbBackup.db");
5440  promiseRestore.then(() => {
5441    console.info('Restore success.');
5442  }).catch((err: BusinessError) => {
5443    console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
5444  })
5445}
5446```
5447
5448### setDistributedTables
5449
5450setDistributedTables(tables: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
5451
5452设置分布式数据库表,使用callback异步回调。
5453
5454**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5455
5456**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5457
5458**参数:**
5459
5460| 参数名   | 类型                      | 必填 | 说明                   |
5461| -------- | ------------------------- | ---- | ---------------------- |
5462| tables   | Array&lt;string&gt;       | 是   | 要设置的分布式数据库表表名。 |
5463| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。 |
5464
5465**错误码:**
5466
5467以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5468
5469| **错误码ID** | **错误信息**                                                 |
5470|-----------| ------------------------------------------------------------ |
5471| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5472| 801       | Capability not supported. |
5473| 14800000  | Inner error. |
5474| 14800014  | Already closed. |
5475
5476**示例:**
5477
5478```ts
5479if(store != undefined) {
5480  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], (err) => {
5481    if (err) {
5482      console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5483      return;
5484    }
5485    console.info('SetDistributedTables successfully.');
5486  })
5487}
5488```
5489
5490### setDistributedTables
5491
5492 setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt;
5493
5494设置分布式数据库表,使用Promise异步回调。
5495
5496**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5497
5498**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5499
5500**参数:**
5501
5502| 参数名 | 类型                     | 必填 | 说明                     |
5503| ------ | ------------------------ | ---- | ------------------------ |
5504| tables | ArrayArray&lt;string&gt; | 是   | 要设置的分布式数据库表表名。 |
5505
5506**返回值**:
5507
5508| 类型                | 说明                      |
5509| ------------------- | ------------------------- |
5510| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5511
5512**错误码:**
5513
5514以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5515
5516| **错误码ID** | **错误信息**                                                 |
5517|-----------| ------------------------------------------------------------ |
5518| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5519| 801       | Capability not supported. |
5520| 14800000  | Inner error. |
5521| 14800014  | Already closed. |
5522
5523**示例:**
5524
5525```ts
5526import { BusinessError } from '@kit.BasicServicesKit';
5527
5528if(store != undefined) {
5529  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"]).then(() => {
5530    console.info('SetDistributedTables successfully.');
5531  }).catch((err: BusinessError) => {
5532    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5533  })
5534}
5535```
5536
5537### setDistributedTables<sup>10+</sup>
5538
5539setDistributedTables(tables: Array&lt;string&gt;, type: DistributedType, callback: AsyncCallback&lt;void&gt;): void
5540
5541设置分布式数据库表,使用callback异步回调。
5542
5543**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5544
5545**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5546
5547**参数:**
5548
5549| 参数名   | 类型                                  | 必填 | 说明                         |
5550| -------- | ------------------------------------- | ---- | ---------------------------- |
5551| tables   | Array&lt;string&gt;                   | 是   | 要设置的分布式数据库表表名。 |
5552| type     | [DistributedType](#distributedtype10) | 是   | 表的分布式类型。             |
5553| callback | AsyncCallback&lt;void&gt;             | 是   | 指定callback回调函数。       |
5554
5555**错误码:**
5556
5557以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5558
5559| **错误码ID** | **错误信息**                                                 |
5560|-----------| ------------------------------------------------------------ |
5561| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5562| 801       | Capability not supported. |
5563| 14800000  | Inner error. |
5564| 14800014  | Already closed. |
5565| 14800051  | The type of the distributed table does not match. |
5566
5567**示例:**
5568
5569```ts
5570if(store != undefined) {
5571  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, (err) => {
5572    if (err) {
5573      console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5574      return;
5575    }
5576    console.info('SetDistributedTables successfully.');
5577  })
5578}
5579```
5580
5581### setDistributedTables<sup>10+</sup>
5582
5583setDistributedTables(tables: Array&lt;string&gt;, type: DistributedType, config: DistributedConfig, callback: AsyncCallback&lt;void&gt;): void
5584
5585设置分布式数据库表,使用callback异步回调。
5586
5587**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5588
5589**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5590
5591**参数:**
5592
5593| 参数名      | 类型                                  | 必填  | 说明              |
5594| -------- | ----------------------------------- | --- | --------------- |
5595| tables   | Array&lt;string&gt;                 | 是   | 要设置的分布式数据库表表名。     |
5596| type     | [DistributedType](#distributedtype10) | 是   | 表的分布式类型。 |
5597| config | [DistributedConfig](#distributedconfig10) | 是 | 表的分布式配置信息。 |
5598| callback | AsyncCallback&lt;void&gt;           | 是   | 指定callback回调函数。 |
5599
5600**错误码:**
5601
5602以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5603
5604| **错误码ID** | **错误信息**                                                 |
5605|-----------| ------------------------------------------------------------ |
5606| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5607| 801       | Capability not supported. |
5608| 14800000  | Inner error. |
5609| 14800014  | Already closed. |
5610| 14800051  | The type of the distributed table does not match. |
5611
5612**示例:**
5613
5614```ts
5615if(store != undefined) {
5616  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, {
5617    autoSync: true
5618  }, (err) => {
5619    if (err) {
5620      console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5621      return;
5622    }
5623    console.info('SetDistributedTables successfully.');
5624  })
5625}
5626```
5627
5628### setDistributedTables<sup>10+</sup>
5629
5630 setDistributedTables(tables: Array&lt;string>, type?: DistributedType, config?: DistributedConfig): Promise&lt;void>
5631
5632设置分布式数据库表,使用Promise异步回调。
5633
5634**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5635
5636**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5637
5638**参数:**
5639
5640| 参数名 | 类型                                      | 必填 | 说明                                                         |
5641| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ |
5642| tables | Array&lt;string&gt;                       | 是   | 要设置的分布式数据库表表名。                                 |
5643| type   | [DistributedType](#distributedtype10)     | 否   | 表的分布式类型。默认值是relationalStore.DistributedType.DISTRIBUTED_DEVICE。 |
5644| config | [DistributedConfig](#distributedconfig10) | 否   | 表的分布式配置信息。不传入时默认autoSync为false,即只支持手动同步。 |
5645
5646**返回值**:
5647
5648| 类型                | 说明                      |
5649| ------------------- | ------------------------- |
5650| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5651
5652**错误码:**
5653
5654以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5655
5656| **错误码ID** | **错误信息**                                                 |
5657|-----------| ------------------------------------------------------------ |
5658| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5659| 801       | Capability not supported. |
5660| 14800000  | Inner error. |
5661| 14800014  | Already closed. |
5662| 14800051  | The type of the distributed table does not match. |
5663
5664**示例:**
5665
5666```ts
5667import { BusinessError } from '@kit.BasicServicesKit';
5668
5669if(store != undefined) {
5670  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, {
5671    autoSync: true
5672  }).then(() => {
5673    console.info('SetDistributedTables successfully.');
5674  }).catch((err: BusinessError) => {
5675    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5676  })
5677}
5678```
5679
5680### obtainDistributedTableName
5681
5682obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void
5683
5684根据远程设备的本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名,使用callback异步回调。
5685
5686> **说明:**
5687>
5688> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
5689
5690**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5691
5692**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5693
5694**参数:**
5695
5696| 参数名   | 类型                        | 必填 | 说明                                                         |
5697| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
5698| device   | string                      | 是   | 远程设备ID 。                                                |
5699| table    | string                      | 是   | 远程设备的本地表名。                                         |
5700| callback | AsyncCallback&lt;string&gt; | 是   | 指定的callback回调函数。如果操作成功,返回远程设备的分布式表名。 |
5701
5702**错误码:**
5703
5704以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5705
5706| **错误码ID** | **错误信息**                                                 |
5707|-----------| ------------------------------------------------------------ |
5708| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5709| 801       | Capability not supported. |
5710| 14800000  | Inner error. |
5711| 14800014  | Already closed. |
5712
5713**示例:**
5714
5715```ts
5716import { distributedDeviceManager } from '@kit.DistributedServiceKit';
5717import { BusinessError } from '@kit.BasicServicesKit';
5718
5719let dmInstance: distributedDeviceManager.DeviceManager;
5720let deviceId: string | undefined = undefined;
5721
5722try {
5723  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
5724  let devices = dmInstance.getAvailableDeviceListSync();
5725  deviceId = devices[0].networkId;
5726} catch (err) {
5727  let code = (err as BusinessError).code;
5728  let message = (err as BusinessError).message
5729  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
5730}
5731
5732if(store != undefined && deviceId != undefined) {
5733  (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE", (err, tableName) => {
5734    if (err) {
5735      console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
5736      return;
5737    }
5738    console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
5739  })
5740}
5741```
5742
5743### obtainDistributedTableName
5744
5745 obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt;
5746
5747根据远程设备的本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名,使用Promise异步回调。
5748
5749> **说明:**
5750>
5751> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
5752
5753**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5754
5755**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5756
5757**参数:**
5758
5759| 参数名 | 类型   | 必填 | 说明                 |
5760| ------ | ------ | ---- | -------------------- |
5761| device | string | 是   | 远程设备ID。         |
5762| table  | string | 是   | 远程设备的本地表名。 |
5763
5764**返回值**:
5765
5766| 类型                  | 说明                                                  |
5767| --------------------- | ----------------------------------------------------- |
5768| Promise&lt;string&gt; | Promise对象。如果操作成功,返回远程设备的分布式表名。 |
5769
5770**错误码:**
5771
5772以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5773
5774| **错误码ID** | **错误信息**                                                 |
5775|-----------| ------------------------------------------------------------ |
5776| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5777| 801       | Capability not supported. |
5778| 14800000  | Inner error. |
5779| 14800014  | Already closed. |
5780
5781**示例:**
5782
5783```ts
5784import { distributedDeviceManager } from '@kit.DistributedServiceKit';
5785import { BusinessError } from '@kit.BasicServicesKit';
5786
5787let dmInstance: distributedDeviceManager.DeviceManager;
5788let deviceId: string | undefined = undefined;
5789
5790try {
5791  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
5792  let devices = dmInstance.getAvailableDeviceListSync();
5793  deviceId = devices[0].networkId;
5794} catch (err) {
5795  let code = (err as BusinessError).code;
5796  let message = (err as BusinessError).message
5797  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
5798}
5799
5800if(store != undefined && deviceId != undefined) {
5801  (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE").then((tableName: string) => {
5802    console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
5803  }).catch((err: BusinessError) => {
5804    console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
5805  })
5806}
5807```
5808
5809### sync
5810
5811sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback&lt;Array&lt;[string, number]&gt;&gt;): void
5812
5813在设备之间同步数据,使用callback异步回调。
5814
5815**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5816
5817**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5818
5819**参数:**
5820
5821| 参数名     | 类型                                               | 必填 | 说明                                                         |
5822| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
5823| mode       | [SyncMode](#syncmode)                             | 是   | 指同步模式。该值可以是relationalStore.SyncMode.SYNC_MODE_PUSHrelationalStore.SyncMode.SYNC_MODE_PULL。                               |
5824| predicates | [RdbPredicates](#rdbpredicates)               | 是   | 约束同步数据和设备。                                         |
5825| callback   | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | 是   | 指定的callback回调函数,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 |
5826
5827**错误码:**
5828
5829以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5830
5831| **错误码ID** | **错误信息**                                                 |
5832|-----------| ------------------------------------------------------------ |
5833| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5834| 801       | Capability not supported. |
5835| 14800000  | Inner error. |
5836| 14800014  | Already closed. |
5837
5838**示例:**
5839
5840```ts
5841import { distributedDeviceManager } from '@kit.DistributedServiceKit';
5842import { BusinessError } from '@kit.BasicServicesKit';
5843
5844let dmInstance: distributedDeviceManager.DeviceManager;
5845let deviceIds: Array<string> = [];
5846
5847try {
5848  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
5849  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
5850  for (let i = 0; i < devices.length; i++) {
5851    deviceIds[i] = devices[i].networkId!;
5852  }
5853} catch (err) {
5854  let code = (err as BusinessError).code;
5855  let message = (err as BusinessError).message
5856  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
5857}
5858
5859let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
5860predicates.inDevices(deviceIds);
5861if(store != undefined) {
5862  (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, (err, result) => {
5863    if (err) {
5864      console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
5865      return;
5866    }
5867    console.info('Sync done.');
5868    for (let i = 0; i < result.length; i++) {
5869      console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
5870    }
5871  })
5872}
5873```
5874
5875### sync
5876
5877 sync(mode: SyncMode, predicates: RdbPredicates): Promise&lt;Array&lt;[string, number]&gt;&gt;
5878
5879在设备之间同步数据,使用Promise异步回调。
5880
5881**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5882
5883**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5884
5885**参数:**
5886
5887| 参数名     | 类型                                 | 必填 | 说明                           |
5888| ---------- | ------------------------------------ | ---- | ------------------------------ |
5889| mode       | [SyncMode](#syncmode)               | 是   | 指同步模式。该值可以是relationalStore.SyncMode.SYNC_MODE_PUSHrelationalStore.SyncMode.SYNC_MODE_PULL。 |
5890| predicates | [RdbPredicates](#rdbpredicates) | 是   | 约束同步数据和设备。           |
5891
5892**返回值**:
5893
5894| 类型                                         | 说明                                                         |
5895| -------------------------------------------- | ------------------------------------------------------------ |
5896| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise对象,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 |
5897
5898**错误码:**
5899
5900以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5901
5902| **错误码ID** | **错误信息**                                                 |
5903|-----------| ------------------------------------------------------------ |
5904| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5905| 801       | Capability not supported. |
5906| 14800000  | Inner error. |
5907| 14800014  | Already closed. |
5908
5909**示例:**
5910
5911```ts
5912import { distributedDeviceManager } from '@kit.DistributedServiceKit';
5913import { BusinessError } from '@kit.BasicServicesKit';
5914
5915let dmInstance: distributedDeviceManager.DeviceManager;
5916let deviceIds: Array<string> = [];
5917
5918try {
5919  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
5920  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
5921  for (let i = 0; i < devices.length; i++) {
5922    deviceIds[i] = devices[i].networkId!;
5923  }
5924} catch (err) {
5925  let code = (err as BusinessError).code;
5926  let message = (err as BusinessError).message
5927  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
5928}
5929
5930let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
5931predicates.inDevices(deviceIds);
5932if(store != undefined) {
5933  (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates).then((result: Object[][]) => {
5934    console.info('Sync done.');
5935    for (let i = 0; i < result.length; i++) {
5936      console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
5937    }
5938  }).catch((err: BusinessError) => {
5939    console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
5940  })
5941}
5942```
5943
5944### cloudSync<sup>10+</sup>
5945
5946cloudSync(mode: SyncMode, progress: Callback&lt;ProgressDetails&gt;, callback: AsyncCallback&lt;void&gt;): void
5947
5948手动执行对所有分布式表的端云同步,使用callback异步回调。使用该接口需要实现云服务功能。
5949
5950**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
5951
5952**参数:**
5953
5954| 参数名   | 类型                                                  | 必填 | 说明                                               |
5955| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
5956| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                             |
5957| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。             |
5958| callback | AsyncCallback&lt;void&gt;                             | 是   | 指定的callback回调函数,用于向调用者发送同步结果。 |
5959
5960**错误码:**
5961
5962以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5963
5964| **错误码ID** | **错误信息**        |
5965|-----------|-------|
5966| 401       | Parameter error. Possible causes: 1. Need 2 - 4  parameter(s). 2. The RdbStore must be not nullptr. 3. The mode must be a SyncMode of cloud. 4. The progress must be a callback type. 5. The callback must be a function. |
5967| 801       | Capability not supported.       |
5968| 14800014  | Already closed.        |
5969
5970**示例:**
5971
5972```ts
5973if(store != undefined) {
5974  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetails) => {
5975    console.info(`Progess: ${progressDetails}`);
5976  }, (err) => {
5977    if (err) {
5978      console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`);
5979      return;
5980    }
5981    console.info('Cloud sync succeeded');
5982  });
5983}
5984```
5985
5986### cloudSync<sup>10+</sup>
5987
5988cloudSync(mode: SyncMode, progress: Callback&lt;ProgressDetails&gt;): Promise&lt;void&gt;
5989
5990手动执行对所有分布式表的端云同步,使用Promise异步回调。使用该接口需要实现云服务功能。
5991
5992**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
5993
5994**参数:**
5995
5996| 参数名   | 类型                                                  | 必填 | 说明                                   |
5997| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
5998| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                 |
5999| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。 |
6000
6001**返回值**:
6002
6003| 类型                | 说明                                    |
6004| ------------------- | --------------------------------------- |
6005| Promise&lt;void&gt; | Promise对象,用于向调用者发送同步结果。 |
6006
6007**错误码:**
6008
6009以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6010
6011| **错误码ID** | **错误信息**    |
6012|-----------|------------------|
6013| 401       | Parameter error. Possible causes: 1. Need 2 - 4  parameter(s). 2. The RdbStore must be not nullptr. 3. The mode must be a SyncMode of cloud. 4. The progress must be a callback type. |
6014| 801       | Capability not supported.   |
6015| 14800014  | Already closed.           |
6016
6017**示例:**
6018
6019```ts
6020import { BusinessError } from '@kit.BasicServicesKit';
6021
6022if(store != undefined) {
6023  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetail: relationalStore.ProgressDetails) => {
6024    console.info(`progress: ${progressDetail}`);
6025  }).then(() => {
6026    console.info('Cloud sync succeeded');
6027  }).catch((err: BusinessError) => {
6028    console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`);
6029  });
6030}
6031```
6032
6033### cloudSync<sup>10+</sup>
6034
6035cloudSync(mode: SyncMode, tables: string[], progress: Callback&lt;ProgressDetails&gt;, callback: AsyncCallback&lt;void&gt;): void
6036
6037手动执行对指定表的端云同步,使用callback异步回调。使用该接口需要实现云服务功能。
6038
6039**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6040
6041**参数:**
6042
6043| 参数名   | 类型                                                  | 必填 | 说明                                               |
6044| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
6045| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                             |
6046| tables   | string[]                                              | 是   | 指定同步的表名。                                   |
6047| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。             |
6048| callback | AsyncCallback&lt;void&gt;                             | 是   | 指定的callback回调函数,用于向调用者发送同步结果。 |
6049
6050**错误码:**
6051
6052以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6053
6054| **错误码ID** | **错误信息**                                                                                                                                                                                                                  |
6055|-----------|-------|
6056| 401       | Parameter error. Possible causes: 1. Need 2 - 4  parameter(s). 2. The RdbStore must be not nullptr. 3. The mode must be a SyncMode of cloud. 4. The tablesNames must be not empty. 5. The progress must be a callback type. 6.The callback must be a function.|
6057| 801       | Capability not supported.   |
6058| 14800014  | Already closed.   |
6059
6060**示例:**
6061
6062```ts
6063const tables = ["table1", "table2"];
6064
6065if(store != undefined) {
6066  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => {
6067    console.info(`Progess: ${progressDetail}`);
6068  }, (err) => {
6069    if (err) {
6070      console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`);
6071      return;
6072    }
6073    console.info('Cloud sync succeeded');
6074  });
6075};
6076```
6077
6078### cloudSync<sup>10+</sup>
6079
6080cloudSync(mode: SyncMode, tables: string[], progress: Callback&lt;ProgressDetails&gt;): Promise&lt;void&gt;
6081
6082手动执行对指定表的端云同步,使用Promise异步回调。使用该接口需要实现云服务功能。
6083
6084**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6085
6086**参数:**
6087
6088| 参数名   | 类型                                                  | 必填 | 说明                                   |
6089| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
6090| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                 |
6091| tables   | string[]                                              | 是   | 指定同步的表名。                       |
6092| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。 |
6093
6094**返回值**:
6095
6096| 类型                | 说明                                    |
6097| ------------------- | --------------------------------------- |
6098| Promise&lt;void&gt; | Promise对象,用于向调用者发送同步结果。 |
6099
6100**错误码:**
6101
6102以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6103
6104| **错误码ID** | **错误信息**     |
6105|-----------|---------------|
6106| 401       | Parameter error. Possible causes: 1. Need 2 - 4  parameter(s). 2. The RdbStore must be not nullptr. 3. The mode must be a SyncMode of cloud. 4. The tablesNames must be not empty. 5. The progress must be a callback type |
6107| 801       | Capability not supported.    |
6108| 14800014  | Already closed.  |
6109
6110**示例:**
6111
6112```ts
6113import { BusinessError } from '@kit.BasicServicesKit';
6114
6115const tables = ["table1", "table2"];
6116
6117if(store != undefined) {
6118  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => {
6119    console.info(`progress: ${progressDetail}`);
6120  }).then(() => {
6121    console.info('Cloud sync succeeded');
6122  }).catch((err: BusinessError) => {
6123    console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`);
6124  });
6125};
6126```
6127
6128### on('dataChange')
6129
6130on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
6131
6132注册数据库的数据变更的事件监听。当分布式数据库中的数据发生更改时,将调用回调。
6133
6134**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6135
6136**参数:**
6137
6138| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6139| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6140| event    | string                                                       | 是   | 取值为'dataChange',表示数据更改。                           |
6141| type     | [SubscribeType](#subscribetype)                              | 是   | 订阅类型。                                                   |
6142| observer | Callback&lt;Array&lt;string&gt;&gt;                          | 是   | 指分布式数据库中数据更改事件的观察者。Array&lt;string&gt;为数据库中的数据发生改变的对端设备ID。 |
6143
6144**错误码:**
6145
6146以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6147
6148| **错误码ID** | **错误信息**        |
6149|-----------|-------------|
6150| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6151| 801       | Capability not supported. |
6152| 14800014  | Already closed.    |
6153
6154**示例:**
6155
6156```ts
6157import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6158import { BusinessError } from '@kit.BasicServicesKit';
6159
6160let storeObserver = (devices: Array<string>) => {
6161  if (devices != undefined) {
6162    for (let i = 0; i < devices.length; i++) {
6163      console.info(`device= ${devices[i]} data changed`);
6164    }
6165  }
6166}
6167
6168try {
6169  if (store != undefined) {
6170    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
6171  }
6172} catch (err) {
6173    let code = (err as BusinessError).code;
6174    let message = (err as BusinessError).message
6175    console.error(`Register observer failed, code is ${code},message is ${message}`);
6176}
6177```
6178
6179### on('dataChange')<sup>10+</sup>
6180
6181on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;ChangeInfo&gt;&gt;): void
6182
6183注册数据库的数据变更的事件监听。当分布式数据库或本地数据库中的数据发生更改时,将调用回调。
6184
6185**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6186
6187**参数:**
6188
6189| 参数名   | 类型                                | 必填 | 说明                                        |
6190| -------- | ----------------------------------- | ---- | ------------------------------------------- |
6191| event    | string                              | 是   | 取值为'dataChange',表示数据更改。          |
6192| type     | [SubscribeType](#subscribetype)    | 是   | 订阅类型。 |
6193| 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>当type为SUBSCRIBE_TYPE_LOCAL_DETAILS,observer类型需为Callback&lt;Array&lt;ChangeInfo&gt;&gt;,其中Array&lt;ChangeInfo&gt;为本地数据库中的数据更改的详情。 |
6194
6195**错误码:**
6196
6197以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6198
6199| **错误码ID** | **错误信息**        |
6200|-----------|-------------|
6201| 202       | Permission verification failed, application which is not a system application uses system API. |
6202| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6203| 801       | Capability not supported. |
6204| 14800014  | Already closed.    |
6205
6206**示例1:type为SUBSCRIBE_TYPE_REMOTE**
6207
6208```ts
6209import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6210import { BusinessError } from '@kit.BasicServicesKit';
6211
6212let storeObserver = (devices: Array<string>) => {
6213  if (devices != undefined) {
6214    for (let i = 0; i < devices.length; i++) {
6215      console.info(`device= ${devices[i]} data changed`);
6216    }
6217  }
6218}
6219
6220try {
6221  if(store != undefined) {
6222    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6223  }
6224} catch (err) {
6225  let code = (err as BusinessError).code;
6226  let message = (err as BusinessError).message;
6227  console.error(`Register observer failed, code is ${code},message is ${message}`);
6228}
6229```
6230
6231**示例2:type为SUBSCRIBE_TYPE_LOCAL_DETAILS**
6232
6233```ts
6234import { BusinessError } from '@kit.BasicServicesKit';
6235
6236let changeInfos = (changeInfos: Array<relationalStore.ChangeInfo>) => {
6237  for (let i = 0; i < changeInfos.length; i++) {
6238    console.info(`changeInfos = ${changeInfos[i]}`);
6239  }
6240}
6241
6242try {
6243  if(store != undefined) {
6244    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_LOCAL_DETAILS, changeInfos);
6245  }
6246} catch (err) {
6247  let code = (err as BusinessError).code;
6248  let message = (err as BusinessError).message;
6249  console.error(`on dataChange fail, code is ${code},message is ${message}`);
6250}
6251
6252let value1 = "Lisa";
6253let value2 = 18;
6254let value3 = 100.5;
6255let value4 = new Uint8Array([1, 2, 3]);
6256
6257try {
6258  const valueBucket: relationalStore.ValuesBucket = {
6259    'name': value1,
6260    'age': value2,
6261    'salary': value3,
6262    'blobType': value4,
6263  };
6264
6265  if(store != undefined) {
6266    (store as relationalStore.RdbStore).insert('test', valueBucket);
6267  }
6268} catch (err) {
6269  let code = (err as BusinessError).code;
6270  let message = (err as BusinessError).message;
6271  console.error(`insert fail, code is ${code},message is ${message}`);
6272}
6273```
6274
6275### on<sup>10+</sup>
6276
6277on(event: string, interProcess: boolean, observer: Callback\<void>): void
6278
6279注册数据库的进程内或者进程间事件监听。当调用[emit](#emit10)接口时,将调用回调。
6280
6281**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6282
6283**参数:**
6284
6285| 参数名       | 类型            | 必填 | 说明                                                         |
6286| ------------ | --------------- | ---- | ------------------------------------------------------------ |
6287| event        | string          | 是   | 订阅事件名称。                                               |
6288| interProcess | boolean         | 是   | 指定是进程间还是本进程订阅。<br/> true:进程间。<br/> false:本进程。 |
6289| observer     | Callback\<void> | 是   | 回调函数。                                                   |
6290
6291**错误码:**
6292
6293以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6294
6295| **错误码ID** | **错误信息**        |
6296|-----------|-------------|
6297| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6298| 801       | Capability not supported. |
6299| 14800000  | Inner error.    |
6300| 14800014  | Already closed.    |
6301| 14800050  | Failed to obtain the subscription service.    |
6302
6303**示例:**
6304
6305```ts
6306import { BusinessError } from '@kit.BasicServicesKit';
6307
6308let storeObserver = () => {
6309  console.info(`storeObserver`);
6310}
6311
6312try {
6313  if(store != undefined) {
6314    (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver);
6315  }
6316} catch (err) {
6317  let code = (err as BusinessError).code;
6318  let message = (err as BusinessError).message
6319  console.error(`Register observer failed, code is ${code},message is ${message}`);
6320}
6321```
6322
6323### on('autoSyncProgress')<sup>11+</sup>
6324
6325on(event: 'autoSyncProgress', progress: Callback&lt;ProgressDetails&gt;): void
6326
6327在已打开端云同步,并且网络状态正常的条件下,注册自动同步进度通知,自动同步进行时调用回调。
6328
6329**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6330
6331**参数:**
6332
6333| 参数名       | 类型                              | 必填 | 说明                                |
6334| ------------ |---------------------------------| ---- |-----------------------------------|
6335| event        | string                          | 是   | 取值为'autoSyncProgress',表示自动同步进度通知。 |
6336| progress     | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 回调函数。                             |
6337
6338**错误码:**
6339
6340以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6341
6342| **错误码ID** | **错误信息**    |
6343|-----------|--------|
6344| 401       | Parameter error. Possible causes: 1. Need 2 - 3  parameter(s)! 2. The RdbStore must be valid. 3. The event must be a not empty string. 4. The progress must be function. |
6345| 801       | Capability not supported.  |
6346| 14800014  | Already closed.     |
6347
6348**示例:**
6349
6350```ts
6351import { BusinessError } from '@kit.BasicServicesKit';
6352
6353let progressDetail = (progressDetail: relationalStore.ProgressDetails) => {
6354  console.info(`progress: ${progressDetail}`);
6355}
6356
6357try {
6358  if(store != undefined) {
6359    (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail)
6360  }
6361} catch (err) {
6362  let code = (err as BusinessError).code;
6363  let message = (err as BusinessError).message
6364  console.error(`Register observer failed, code is ${code},message is ${message}`);
6365}
6366```
6367
6368### on('statistics')<sup>12+</sup>
6369
6370on(event: 'statistics', observer: Callback&lt;SqlExecutionInfo&gt;): void
6371
6372订阅SQL统计信息。
6373
6374**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6375
6376**参数:**
6377
6378| 参数名       | 类型                              | 必填 | 说明                                |
6379| ------------ |---------------------------------| ---- |-----------------------------------|
6380| event        | string                          | 是   | 订阅事件名称,取值为'statistics',表示sql执行时间的统计。 |
6381| observer     | Callback&lt;[SqlExecutionInfo](#sqlexecutioninfo12)&gt; | 是   | 回调函数。用于返回数据库中SQL执行时间的统计信息。  |
6382
6383**错误码:**
6384
6385以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6386
6387| **错误码ID** | **错误信息**    |
6388|-----------|--------|
6389| 401       | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
6390| 801       | Capability not supported.  |
6391| 14800000  | Inner error.  |
6392| 14800014  | Already closed.     |
6393
6394**示例:**
6395
6396```ts
6397import { BusinessError } from '@kit.BasicServicesKit';
6398
6399let sqlExecutionInfo = (sqlExecutionInfo: relationalStore.SqlExecutionInfo) => {
6400  console.info(`sql: ${sqlExecutionInfo.sql[0]}`);
6401  console.info(`totalTime: ${sqlExecutionInfo.totalTime}`);
6402  console.info(`waitTime: ${sqlExecutionInfo.waitTime}`);
6403  console.info(`prepareTime: ${sqlExecutionInfo.prepareTime}`);
6404  console.info(`executeTime: ${sqlExecutionInfo.executeTime}`);
6405}
6406
6407try {
6408  if(store != undefined) {
6409    (store as relationalStore.RdbStore).on('statistics', sqlExecutionInfo);
6410  }
6411} catch (err) {
6412  let code = (err as BusinessError).code;
6413  let message = (err as BusinessError).message;
6414  console.error(`Register observer failed, code is ${code},message is ${message}`);
6415}
6416
6417try {
6418  let value1 = "Lisa";
6419  let value2 = 18;
6420  let value3 = 100.5;
6421  let value4 = new Uint8Array([1, 2, 3, 4, 5]);
6422
6423  const valueBucket: relationalStore.ValuesBucket = {
6424    'NAME': value1,
6425    'AGE': value2,
6426    'SALARY': value3,
6427    'CODES': value4,
6428  };
6429  if(store != undefined) {
6430    (store as relationalStore.RdbStore).insert('test', valueBucket);
6431  }
6432} catch (err) {
6433  console.error(`insert fail, code:${err.code}, message: ${err.message}`);
6434}
6435```
6436
6437### off('dataChange')
6438
6439off(event:'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
6440
6441取消数据变更的事件监听。
6442
6443**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6444
6445**参数:**
6446
6447| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6448| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6449| event    | string                                                       | 是   | 取值为'dataChange',表示数据更改。                           |
6450| type     | [SubscribeType](#subscribetype) | 是   | 订阅类型。                                                   |
6451| observer | Callback&lt;Array&lt;string&gt;&gt;                          | 是   | 指已注册的数据更改观察者。Array&lt;string&gt;为数据库中的数据发生改变的对端设备ID。 |
6452
6453**错误码:**
6454
6455以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6456
6457| **错误码ID** | **错误信息**        |
6458|-----------|-------------|
6459| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6460| 801       | Capability not supported. |
6461| 14800014  | Already closed.    |
6462
6463**示例:**
6464
6465```ts
6466import { BusinessError } from '@kit.BasicServicesKit';
6467
6468let storeObserver = (devices: Array<string>) => {
6469  if (devices != undefined) {
6470    for (let i = 0; i < devices.length; i++) {
6471      console.info(`device= ${devices[i]} data changed`);
6472    }
6473  }
6474}
6475
6476try {
6477  if (store != undefined) {
6478    // 此处不能使用Lambda表达式
6479    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
6480  }
6481} catch (err) {
6482    let code = (err as BusinessError).code;
6483    let message = (err as BusinessError).message
6484    console.error(`Register observer failed, code is ${code},message is ${message}`);
6485}
6486
6487try {
6488  if(store != undefined) {
6489    (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6490  }
6491} catch (err) {
6492  let code = (err as BusinessError).code;
6493  let message = (err as BusinessError).message
6494  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
6495}
6496```
6497
6498### off('dataChange')<sup>10+</sup>
6499
6500off(event:'dataChange', type: SubscribeType, observer?: Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;ChangeInfo&gt;&gt;): void
6501
6502取消数据变更的事件监听。
6503
6504**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6505
6506**参数:**
6507
6508| 参数名   | 类型                                | 必填 | 说明                                        |
6509| -------- | ---------------------------------- | ---- | ------------------------------------------ |
6510| event    | string                              | 是   | 取值为'dataChange',表示数据更改。          |
6511| type     | [SubscribeType](#subscribetype)     | 是   | 订阅类型。                                 |
6512| 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>当type为SUBSCRIBE_TYPE_LOCAL_DETAILS,observer类型需为Callback&lt;Array&lt;ChangeInfo&gt;&gt;,其中Array&lt;ChangeInfo&gt;为本地数据库中的数据更改的详情。<br> 当observer没有传入时,表示取消当前type类型下所有数据变更的事件监听。 |
6513
6514**错误码:**
6515
6516以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6517
6518| **错误码ID** | **错误信息**        |
6519|-----------|-------------|
6520| 202       | Permission verification failed, application which is not a system application uses system API. |
6521| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6522| 801       | Capability not supported. |
6523| 14800014  | Already closed.    |
6524
6525**示例:**
6526
6527```ts
6528import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6529import { BusinessError } from '@kit.BasicServicesKit';
6530
6531let storeObserver = (devices: Array<string>) => {
6532  if (devices != undefined) {
6533    for (let i = 0; i < devices.length; i++) {
6534      console.info(`device= ${devices[i]} data changed`);
6535    }
6536  }
6537}
6538
6539try {
6540  if(store != undefined) {
6541    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6542  }
6543} catch (err) {
6544  let code = (err as BusinessError).code;
6545  let message = (err as BusinessError).message;
6546  console.error(`Register observer failed, code is ${code},message is ${message}`);
6547}
6548
6549try {
6550  if(store != undefined) {
6551    (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6552  }
6553} catch (err) {
6554  let code = (err as BusinessError).code;
6555  let message = (err as BusinessError).message
6556  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
6557}
6558```
6559
6560### off<sup>10+</sup>
6561
6562off(event: string, interProcess: boolean, observer?: Callback\<void>): void
6563
6564取消数据变更的事件监听。
6565
6566**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6567
6568**参数:**
6569
6570| 参数名       | 类型            | 必填 | 说明                                                         |
6571| ------------ | --------------- | ---- | ------------------------------------------------------------ |
6572| event        | string          | 是   | 取消订阅事件名称。                                           |
6573| interProcess | boolean         | 是   | 指定是进程间还是本进程取消订阅。<br/> true:进程间。<br/> false:本进程。 |
6574| observer     | Callback\<void> | 否   | 该参数存在,则取消指定Callback监听回调,否则取消该event事件的所有监听回调。 |
6575
6576**错误码:**
6577
6578以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6579
6580| **错误码ID** | **错误信息**                           |
6581| ------------ | -------------------------------------- |
6582| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6583| 801       | Capability not supported. |
6584| 14800000     | Inner error.                           |
6585| 14800014  | Already closed.    |
6586| 14800050     | Failed to obtain the subscription service. |
6587
6588**示例:**
6589
6590```ts
6591import { BusinessError } from '@kit.BasicServicesKit';
6592
6593let storeObserver = () => {
6594  console.info(`storeObserver`);
6595}
6596
6597try {
6598  if(store != undefined) {
6599    (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver);
6600  }
6601} catch (err) {
6602  let code = (err as BusinessError).code;
6603  let message = (err as BusinessError).message
6604  console.error(`Register observer failed, code is ${code},message is ${message}`);
6605}
6606
6607try {
6608  if(store != undefined) {
6609    (store as relationalStore.RdbStore).off('storeObserver', false, storeObserver);
6610  }
6611} catch (err) {
6612  let code = (err as BusinessError).code;
6613  let message = (err as BusinessError).message
6614  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
6615}
6616```
6617
6618### off('autoSyncProgress')<sup>11+</sup>
6619
6620off(event: 'autoSyncProgress', progress?: Callback&lt;ProgressDetails&gt;): void
6621
6622取消订阅自动同步进度的通知。
6623
6624**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6625
6626**参数:**
6627
6628| 参数名       | 类型                              | 必填 | 说明                                                               |
6629| ------------ |---------------------------------| ---- |------------------------------------------------------------------|
6630| event        | string                          | 是   | 取值为'autoSyncProgress',表示自动同步进度通知。                                |
6631| progress     | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 否   | 指已注册的自动同步进度观察者。该参数存在,则取消订阅指定回调,该参数为null或undefined或不存在,则取消订阅所有回调。 |
6632
6633**错误码:**
6634
6635以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6636
6637| **错误码ID** | **错误信息**         |
6638| ------------ |--------------------|
6639| 401       | Parameter error. Possible causes: 1. Need 1 - 3  parameter(s)! 2. The RdbStore must be valid. 3. The event must be a not empty string. 4. The progress must be function. |
6640| 801       | Capability not supported.  |
6641| 14800014  | Already closed.       |
6642
6643**示例:**
6644
6645```ts
6646import { BusinessError } from '@kit.BasicServicesKit';
6647
6648let progressDetail = (progressDetail: relationalStore.ProgressDetails) => {
6649  console.info(`progress: ${progressDetail}`);
6650}
6651
6652try {
6653  if(store != undefined) {
6654    (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail)
6655  }
6656} catch (err) {
6657  let code = (err as BusinessError).code;
6658  let message = (err as BusinessError).message
6659  console.error(`Register observer failed, code is ${code},message is ${message}`);
6660}
6661
6662try {
6663  if(store != undefined) {
6664    (store as relationalStore.RdbStore).off('autoSyncProgress', progressDetail);
6665  }
6666} catch (err) {
6667  let code = (err as BusinessError).code;
6668  let message = (err as BusinessError).message;
6669  console.error(`Unregister failed, code is ${code},message is ${message}`);
6670}
6671```
6672
6673### off('statistics')<sup>12+</sup>
6674
6675off(event: 'statistics', observer?: Callback&lt;SqlExecutionInfo&gt;): void
6676
6677取消订阅SQL统计信息。
6678
6679**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6680
6681**参数:**
6682
6683| 参数名       | 类型                              | 必填 | 说明                                |
6684| ------------ |---------------------------------| ---- |-----------------------------------|
6685| event        | string                          | 是   | 取消订阅事件名称。取值为'statistics',表示sql执行时间的统计。 |
6686| observer     | Callback&lt;[SqlExecutionInfo](#sqlexecutioninfo12)&gt; | 否   | 回调函数。该参数存在,则取消指定Callback监听回调,否则取消该event事件的所有监听回调。  |
6687
6688
6689**错误码:**
6690
6691以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6692
6693| **错误码ID** | **错误信息**    |
6694|-----------|--------|
6695| 401       | Parameter error.  |
6696| 801       | Capability not supported.  |
6697| 14800000  | Inner error.  |
6698| 14800014  | Already closed.     |
6699
6700```ts
6701import { BusinessError } from '@kit.BasicServicesKit';
6702
6703try {
6704  if(store != undefined) {
6705    (store as relationalStore.RdbStore).off('statistics');
6706  }
6707} catch (err) {
6708  let code = (err as BusinessError).code;
6709  let message = (err as BusinessError).message;
6710  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
6711}
6712```
6713
6714### emit<sup>10+</sup>
6715
6716emit(event: string): void
6717
6718通知通过[on](#on10)注册的进程间或者进程内监听事件。
6719
6720**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6721
6722**参数:**
6723
6724| 参数名 | 类型   | 必填 | 说明                 |
6725| ------ | ------ | ---- | -------------------- |
6726| event  | string | 是   | 通知订阅事件的名称。 |
6727
6728**错误码:**
6729
6730以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6731
6732| **错误码ID** | **错误信息**                                                                                                      |
6733| --------- |---------------------------------------------------------------------------------------------------------------|
6734| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6735| 801       | Capability not supported.     |
6736| 14800000  | Inner error.   |
6737| 14800014  | Already closed.     |
6738| 14800050  | Failed to obtain the subscription service.    |
6739
6740
6741**示例:**
6742
6743```ts
6744if(store != undefined) {
6745  (store as relationalStore.RdbStore).emit('storeObserver');
6746}
6747```
6748
6749### cleanDirtyData<sup>11+</sup>
6750
6751cleanDirtyData(table: string, cursor: number, callback: AsyncCallback&lt;void&gt;): void
6752
6753清理云端删除的数据同步到本地后,未自动清理的,且数据的游标(cursor)小于指定游标的数据。
6754
6755**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6756
6757**参数:**
6758
6759| 参数名   | 类型                                                  | 必填 | 说明                                               |
6760| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
6761| table     | string                        | 是   | 表示当前数据库的表的名称。                             |
6762| cursor    | number                        | 是   | 整数类型,表示数据游标,小于此游标的脏数据将被清理。     |
6763| callback  | AsyncCallback&lt;void&gt;     | 是   | 指定的callback回调函数。 |
6764
6765**错误码:**
6766
6767以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
6768
6769| **错误码ID** | **错误信息**     |
6770|-----------|---------------|
6771| 401       | Parameter error. Possible causes: 1. Need 1 - 3  parameter(s)! 2. The RdbStore must be not nullptr. 3. The tablesNames must be not empty string. 4. The cursor must be valid cursor. |
6772| 801       | Capability not supported. |
6773| 14800000  | Inner error. |
6774| 14800011  | Database corrupted. |
6775| 14800014  | Already closed. |
6776| 14800015  | The database does not respond. |
6777| 14800021  | SQLite: Generic error. |
6778| 14800022  | SQLite: Callback routine requested an abort. |
6779| 14800023  | SQLite: Access permission denied. |
6780| 14800024  | SQLite: The database file is locked. |
6781| 14800025  | SQLite: A table in the database is locked. |
6782| 14800026  | SQLite: The database is out of memory. |
6783| 14800027  | SQLite: Attempt to write a readonly database. |
6784| 14800028  | SQLite: Some kind of disk I/O error occurred. |
6785| 14800029  | SQLite: The database is full. |
6786| 14800030  | SQLite: Unable to open the database file. |
6787| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
6788| 14800032  | SQLite: Abort due to constraint violation. |
6789| 14800033  | SQLite: Data type mismatch. |
6790| 14800034  | SQLite: Library used incorrectly. |
6791
6792**示例:**
6793
6794```ts
6795if(store != undefined) {
6796 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100, (err) => {
6797    if (err) {
6798      console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`);
6799      return;
6800    }
6801    console.info('clean dirty data succeeded');
6802  })
6803}
6804```
6805
6806### cleanDirtyData<sup>11+</sup>
6807
6808cleanDirtyData(table: string, callback: AsyncCallback&lt;void&gt;): void
6809
6810清理云端删除的数据同步到本地后,未自动清理的所有数据。
6811
6812**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6813
6814**参数:**
6815
6816| 参数名   | 类型                                                  | 必填 | 说明                                               |
6817| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
6818| table     | string                        | 是   | 表示当前数据库的表的名称。 |
6819| callback  | AsyncCallback&lt;void&gt;     | 是   | 指定的callback回调函数。 |
6820
6821**错误码:**
6822
6823以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
6824
6825| **错误码ID** | **错误信息**       |
6826|-----------|---------|
6827| 401       | Parameter error. Possible causes: 1. Need 1 - 3  parameter(s). 2. The RdbStore must be not nullptr. 3. The tablesNames must be not empty string. |
6828| 801       | Capability not supported.    |
6829| 14800000  | Inner error.        |
6830| 14800011  | Database corrupted.   |
6831| 14800014  | Already closed.       |
6832| 14800015  | The database does not respond.      |
6833| 14800021  | SQLite: Generic error.     |
6834| 14800022  | SQLite: Callback routine requested an abort. |
6835| 14800023  | SQLite: Access permission denied.           |
6836| 14800024  | SQLite: The database file is locked.        |
6837| 14800025  | SQLite: A table in the database is locked.  |
6838| 14800026  | SQLite: The database is out of memory.      |
6839| 14800027  | SQLite: Attempt to write a readonly database.   |
6840| 14800028  | SQLite: Some kind of disk I/O error occurred.  |
6841| 14800029  | SQLite: The database is full.                |
6842| 14800030  | SQLite: Unable to open the database file.            |
6843| 14800031  | SQLite: TEXT or BLOB exceeds size limit.             |
6844| 14800032  | SQLite: Abort due to constraint violation.   |
6845| 14800033  | SQLite: Data type mismatch.                  |
6846| 14800034  | SQLite: Library used incorrectly.          |
6847
6848**示例:**
6849
6850```ts
6851if(store != undefined) {
6852  (store as relationalStore.RdbStore).cleanDirtyData('test_table', (err) => {
6853    if (err) {
6854      console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`);
6855      return;
6856    }
6857    console.info('clean dirty data succeeded');
6858  })
6859}
6860```
6861
6862### cleanDirtyData<sup>11+</sup>
6863
6864cleanDirtyData(table: string, cursor?: number): Promise&lt;void&gt;
6865
6866清理云端删除的数据同步到本地后,未自动清理的,且数据的游标(cursor)小于指定游标的数据。若无cursor参数,将全部清理。
6867
6868**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6869
6870**参数:**
6871
6872| 参数名   | 类型                                                  | 必填 | 说明                                               |
6873| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
6874| table     | string           | 是   | 表示当前数据库的表的名称。           |
6875| cursor    | number           | 否   | 整数类型,表示数据游标,小于此游标的脏数据将被清理。当此参数不填时,清理当前表的所有脏数据。 |
6876
6877**返回值:**
6878| 参数名    | 说明                                               |
6879| -------- | ------------------------------------------------- |
6880| Promise\<void> | 无返回结果的Promise对象。        |
6881
6882**错误码:**
6883
6884以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
6885
6886| **错误码ID** | **错误信息**                                                                                                                                                                      |
6887|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
6888| 401       | Parameter error. Possible causes: 1. Need 1 - 3  parameter(s)! 2. The RdbStore must be not nullptr. 3. The tablesNames must be not empty string. 4. The cursor must be valid cursor. |
6889| 801       | Capability not supported. |
6890| 14800000  | Inner error.            |
6891| 14800011  | Database corrupted.   |
6892| 14800014  | Already closed. |
6893| 14800015  | The database does not respond.   |
6894| 14800021  | SQLite: Generic error.   |
6895| 14800022  | SQLite: Callback routine requested an abort. |
6896| 14800023  | SQLite: Access permission denied.          |
6897| 14800024  | SQLite: The database file is locked.      |
6898| 14800025  | SQLite: A table in the database is locked. |
6899| 14800026  | SQLite: The database is out of memory.   |
6900| 14800027  | SQLite: Attempt to write a readonly database. |
6901| 14800028  | SQLite: Some kind of disk I/O error occurred. |
6902| 14800029  | SQLite: The database is full.   |
6903| 14800030  | SQLite: Unable to open the database file. |
6904| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
6905| 14800032  | SQLite: Abort due to constraint violation. |
6906| 14800033  | SQLite: Data type mismatch. |
6907| 14800034  | SQLite: Library used incorrectly. |
6908
6909**示例:**
6910
6911```ts
6912import { BusinessError } from '@kit.BasicServicesKit';
6913
6914if(store != undefined) {
6915    (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100).then(() => {
6916        console.info('clean dirty data  succeeded');
6917    }).catch ((err: BusinessError) => {
6918        console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`);
6919    })
6920}
6921```
6922
6923### attach<sup>12+</sup>
6924
6925attach(fullPath: string, attachName: string, waitTime?: number) : Promise&lt;number&gt;
6926
6927将一个数据库文件附加到当前数据库中,以便在SQL语句中可以直接访问附加数据库中的数据。
6928
6929数据库文件来自文件,且此API不支持附加加密数据库。调用attach接口后,数据库切换为非WAL模式,性能会存在一定的劣化。
6930
6931attach的时候,数据库会切换为非WAL模式,切换模式需要确保所有的ResultSet都已经Close,所有的写操作已经结束,否则会报错14800015。
6932
6933attach不能并发调用,可能出现未响应情况,报错14800015,需要重试。
6934
6935**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6936
6937**参数:**
6938
6939| 参数名        | 类型     | 必填  | 说明           |
6940| ----------- | ------ | --- | ------------ |
6941| fullPath | string | 是   | 表示要附加的数据库的路径。 |
6942| attachName | string | 是   | 表示附加后的数据库的别名。 |
6943| waitTime | number | 否   | 表示附加数据库文件的等待时长。默认值2s,最小值1s,最大值300s。 |
6944
6945**返回值:**
6946
6947| 类型              | 说明                           |
6948| ---------------- | ---------------------------- |
6949|  Promise&lt;number&gt; | Promise对象。返回附加数据库的数量。 |
6950
6951**错误码:**
6952
6953以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
6954
6955| **错误码ID** | **错误信息**                                                 |
6956|-----------| ------------------------------------------------------------ |
6957| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6958| 801       | Capability not supported. |
6959| 14800000  | Inner error. |
6960| 14800010  | Invalid database path.               |
6961| 14800011  | Database corrupted. |
6962| 14800014  | Already closed. |
6963| 14800015  | The database does not respond.                 |
6964| 14800016  | The database alias already exists.                |
6965| 14800021  | SQLite: Generic error. |
6966| 14800022  | SQLite: Callback routine requested an abort. |
6967| 14800023  | SQLite: Access permission denied. |
6968| 14800024  | SQLite: The database file is locked. |
6969| 14800025  | SQLite: A table in the database is locked. |
6970| 14800026  | SQLite: The database is out of memory. |
6971| 14800027  | SQLite: Attempt to write a readonly database. |
6972| 14800028  | SQLite: Some kind of disk I/O error occurred. |
6973| 14800029  | SQLite: The database is full. |
6974| 14800030  | SQLite: Unable to open the database file. |
6975| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
6976| 14800032  | SQLite: Abort due to constraint violation. |
6977| 14800033  | SQLite: Data type mismatch. |
6978| 14800034  | SQLite: Library used incorrectly. |
6979
6980**示例:**
6981
6982```ts
6983// 非加密数据库附加非加密数据库。
6984import { BusinessError } from '@kit.BasicServicesKit';
6985
6986if(store != undefined) {
6987    (store as relationalStore.RdbStore).attach("/path/rdbstore1.db", "attachDB").then((number: number) => {
6988        console.info('attach succeeded');
6989    }).catch ((err: BusinessError) => {
6990        console.error(`attach failed, code is ${err.code},message is ${err.message}`);
6991    })
6992}
6993```
6994
6995### attach<sup>12+</sup>
6996
6997attach(context: Context, config: StoreConfig, attachName: string, waitTime?: number) : Promise&lt;number&gt;
6998
6999将一个当前应用的数据库附加到当前数据库中,以便在SQL语句中可以直接访问附加数据库中的数据。
7000
7001此API不支持加密数据库附加非加密数据库的场景。调用attach接口后,数据库切换为非WAL模式,性能会存在一定的劣化。
7002
7003attach的时候,数据库会切换为非WAL模式,切换模式需要确保所有的ResultSet都已经Close,所有的写操作已经结束,否则会报错14800015。
7004
7005attach不能并发调用,可能出现未响应情况,报错14800015,需要重试。除此之外,attach附加加密数据库时,可能受到并发的影响,出现解密失败的情况,报错14800011,需要显式指定加密参数并重试。
7006
7007**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7008
7009**参数:**
7010
7011| 参数名        | 类型     | 必填  | 说明           |
7012| ----------- | ------ | --- | ------------ |
7013| context | Context                          | 是   | 应用的上下文。 <br>FA模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)。 |
7014| config  | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |
7015| attachName | string | 是   | 表示附加后的数据库的别名。 |
7016| waitTime | number | 否   | 表示附加数据库文件的等待时长。默认值2s,最小值1s,最大值300s。 |
7017
7018**返回值:**
7019
7020| 类型              | 说明                           |
7021| ---------------- | ---------------------------- |
7022|  Promise&lt;number&gt; | Promise对象。返回附加数据库的数量。 |
7023
7024**错误码:**
7025
7026以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7027
7028| **错误码ID** | **错误信息**                                                 |
7029|-----------| ------------------------------------------------------------ |
7030| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7031| 801       | Capability not supported. |
7032| 14800000  | Inner error. |
7033| 14800010  | Invalid database path.               |
7034| 14800011  | Database corrupted. |
7035| 14800014  | Already closed. |
7036| 14800015  | The database does not respond.                 |
7037| 14800016  | The database alias already exists.                |
7038| 14801001  | The operation is supported in the stage model only.                 |
7039| 14801002  | Invalid data ground ID.                |
7040| 14800021  | SQLite: Generic error. |
7041| 14800022  | SQLite: Callback routine requested an abort. |
7042| 14800023  | SQLite: Access permission denied. |
7043| 14800024  | SQLite: The database file is locked. |
7044| 14800025  | SQLite: A table in the database is locked. |
7045| 14800026  | SQLite: The database is out of memory. |
7046| 14800027  | SQLite: Attempt to write a readonly database. |
7047| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7048| 14800029  | SQLite: The database is full. |
7049| 14800030  | SQLite: Unable to open the database file. |
7050| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7051| 14800032  | SQLite: Abort due to constraint violation. |
7052| 14800033  | SQLite: Data type mismatch. |
7053| 14800034  | SQLite: Library used incorrectly. |
7054
7055**示例1:非加密数据库附加非加密数据库**
7056
7057```ts
7058import { BusinessError } from '@kit.BasicServicesKit';
7059
7060let attachStore: relationalStore.RdbStore | undefined = undefined;
7061
7062const STORE_CONFIG1: relationalStore.StoreConfig = {
7063    name: "rdbstore1.db",
7064    securityLevel: relationalStore.SecurityLevel.S3,
7065}
7066
7067relationalStore.getRdbStore(this.context, STORE_CONFIG1).then(async (rdbStore: relationalStore.RdbStore) => {
7068    attachStore = rdbStore;
7069    console.info('Get RdbStore successfully.')
7070}).catch((err: BusinessError) => {
7071    console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
7072})
7073
7074if(store != undefined) {
7075    (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG1, "attachDB").then((number: number) => {
7076        console.info(`attach succeeded, number is ${number}`);
7077    }).catch ((err: BusinessError) => {
7078        console.error(`attach failed, code is ${err.code},message is ${err.message}`);
7079    })
7080}
7081```
7082
7083**示例2:非加密数据库附加加密数据库**
7084
7085```ts
7086import { BusinessError } from '@kit.BasicServicesKit';
7087
7088let attachStore: relationalStore.RdbStore | undefined = undefined;
7089
7090
7091const STORE_CONFIG2: relationalStore.StoreConfig = {
7092    name: "rdbstore2.db",
7093    encrypt: true,
7094    securityLevel: relationalStore.SecurityLevel.S3,
7095}
7096
7097relationalStore.getRdbStore(this.context, STORE_CONFIG2).then(async (rdbStore: relationalStore.RdbStore) => {
7098    attachStore = rdbStore;
7099    console.info('Get RdbStore successfully.')
7100}).catch((err: BusinessError) => {
7101    console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
7102})
7103
7104if(store != undefined) {
7105    (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG2, "attachDB2", 10).then((number: number) => {
7106        console.info(`attach succeeded, number is ${number}`);
7107    }).catch ((err: BusinessError) => {
7108        console.error(`attach failed, code is ${err.code},message is ${err.message}`);
7109    })
7110}
7111```
7112
7113### detach<sup>12+</sup>
7114
7115detach(attachName: string, waitTime?: number) : Promise&lt;number&gt;
7116
7117将附加的数据库从当前数据库中分离。
7118
7119当所有的附加的数据库被分离后,数据库会重新切换为WAL模式。
7120
7121在detach之前,所有的数据库操作要确保已经结束,所有的ResultSet已经Close。并且不能并发调用,可能出现未响应情况,需要重试。
7122
7123**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7124
7125**参数:**
7126
7127| 参数名        | 类型     | 必填  | 说明           |
7128| ----------- | ------ | --- | ------------ |
7129| attachName | string | 是   | 表示附加后的数据库的别名。 |
7130| waitTime | number | 否   | 表示分离数据库的等待时长。默认值2s,最小值1s,最大值300s。 |
7131
7132**返回值:**
7133
7134| 类型              | 说明                           |
7135| ---------------- | ---------------------------- |
7136|  Promise&lt;number&gt; | Promise对象。返回分离后剩余附加的数据库的数量。 |
7137
7138**错误码:**
7139
7140以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7141
7142| **错误码ID** | **错误信息**       |
7143|-----------|------------------------|
7144| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7145| 14800000  | Inner error.            |
7146| 14800011  | Database corrupted.         |
7147| 14800014  | Already closed.        |
7148| 14800015  | The database does not respond.         |
7149| 14800021  | SQLite: Generic error.            |
7150| 14800022  | SQLite: Callback routine requested an abort.       |
7151| 14800023  | SQLite: Access permission denied.           |
7152| 14800024  | SQLite: The database file is locked.        |
7153| 14800025  | SQLite: A table in the database is locked.       |
7154| 14800026  | SQLite: The database is out of memory.     |
7155| 14800027  | SQLite: Attempt to write a readonly database.        |
7156| 14800028  | SQLite: Some kind of disk I/O error occurred.    |
7157| 14800029  | SQLite: The database is full.      |
7158| 14800030  | SQLite: Unable to open the database file.       |
7159| 14800031  | SQLite: TEXT or BLOB exceeds size limit.      |
7160| 14800032  | SQLite: Abort due to constraint violation.    |
7161| 14800033  | SQLite: Data type mismatch.       |
7162| 14800034  | SQLite: Library used incorrectly.       |
7163
7164**示例:**
7165
7166```ts
7167import { BusinessError } from '@kit.BasicServicesKit';
7168
7169if(store != undefined) {
7170    (store as relationalStore.RdbStore).detach("attachDB").then((number: number) => {
7171        console.info(`detach succeeded, number is ${number}`);
7172    }).catch ((err: BusinessError) => {
7173        console.error(`detach failed, code is ${err.code},message is ${err.message}`);
7174    })
7175}
7176```
7177
7178### lockRow<sup>12+</sup>
7179
7180lockRow(predicates: RdbPredicates):Promise&lt;void&gt;
7181
7182根据RdbPredicates的指定实例对象从数据库中锁定数据,锁定数据不执行端云同步,使用Promise异步回调。
7183
7184该接口只支持主键为基本类型的表、不支持共享表、无主键表和复合类型主键表。
7185该接口不支持依赖关系表之间的锁传递,如果表存在依赖关系,需要根据依赖关系手动调用该接口。
7186该接口不支持对已删除数据的操作。
7187
7188**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7189
7190**参数:**
7191
7192| 参数名     | 类型                                 | 必填 | 说明                                      |
7193| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
7194| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的锁定条件。 |
7195
7196**返回值**:
7197
7198| 类型                  | 说明                            |
7199| --------------------- | ------------------------------- |
7200| Promise&lt;void&gt;   | 无返回结果的Promise对象。        |
7201
7202**错误码:**
7203
7204以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7205
7206| **错误码ID** | **错误信息**                                                                                     |
7207|-----------|----------------------------------------------------------------------------------------------|
7208| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7209| 14800000  | Inner error.                                                                                 |
7210| 14800011  | Database corrupted.                                                                          |
7211| 14800014  | Already closed.                                                                              |
7212| 14800015  | The database does not respond.                                                                        |
7213| 14800018  | No data meets the condition.                                                                 |
7214| 14800021  | SQLite: Generic error.                                                                       |
7215| 14800022  | SQLite: Callback routine requested an abort.                                                 |
7216| 14800023  | SQLite: Access permission denied.                                                            |
7217| 14800024  | SQLite: The database file is locked.                                                         |
7218| 14800025  | SQLite: A table in the database is locked.                                                   |
7219| 14800026  | SQLite: The database is out of memory.                                                       |
7220| 14800027  | SQLite: Attempt to write a readonly database.                                                |
7221| 14800028  | SQLite: Some kind of disk I/O error occurred.                                                |
7222| 14800029  | SQLite: The database is full.                                                                |
7223| 14800030  | SQLite: Unable to open the database file.                                                    |
7224| 14800031  | SQLite: TEXT or BLOB exceeds size limit.                                                     |
7225| 14800032  | SQLite: Abort due to constraint violation.                                                   |
7226| 14800033  | SQLite: Data type mismatch.                                                                  |
7227| 14800034  | SQLite: Library used incorrectly.                                                            |
7228
7229**示例:**
7230
7231```ts
7232import { BusinessError } from '@kit.BasicServicesKit';
7233
7234let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
7235predicates.equalTo("NAME", "Lisa");
7236if(store != undefined) {
7237  (store as relationalStore.RdbStore).lockRow(predicates).then(() => {
7238    console.info(`Lock success`);
7239  }).catch((err: BusinessError) => {
7240    console.error(`Lock failed, code is ${err.code},message is ${err.message}`);
7241  })
7242}
7243```
7244
7245### unlockRow<sup>12+</sup>
7246
7247unlockRow(predicates: RdbPredicates):Promise&lt;void&gt;
7248
7249根据RdbPredicates的指定实例对象从数据库中解锁数据,使用Promise异步回调。
7250
7251该接口只支持主键为基本类型的表、不支持共享表、无主键表和复合类型主键表。
7252该接口不支持依赖关系表之间的锁传递,如果表存在依赖关系,需要根据依赖关系手动调用该接口。
7253该接口不支持对已删除数据的操作。
7254
7255**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7256
7257**参数:**
7258
7259| 参数名     | 类型                                 | 必填 | 说明                                      |
7260| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
7261| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的锁定条件。 |
7262
7263**返回值**:
7264
7265| 类型                  | 说明                            |
7266| --------------------- | ------------------------------- |
7267| Promise&lt;void&gt;   | 无返回结果的Promise对象。        |
7268
7269**错误码:**
7270
7271以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7272
7273| **错误码ID** | **错误信息**                                                 |
7274|-----------| ------------------------------------------------------------ |
7275| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7276| 14800000  | Inner error. |
7277| 14800011  | Database corrupted. |
7278| 14800014  | Already closed. |
7279| 14800015  | The database does not respond.                 |
7280| 14800018  | No data meets the condition.                |
7281| 14800021  | SQLite: Generic error. |
7282| 14800022  | SQLite: Callback routine requested an abort. |
7283| 14800023  | SQLite: Access permission denied. |
7284| 14800024  | SQLite: The database file is locked. |
7285| 14800025  | SQLite: A table in the database is locked. |
7286| 14800026  | SQLite: The database is out of memory. |
7287| 14800027  | SQLite: Attempt to write a readonly database. |
7288| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7289| 14800029  | SQLite: The database is full. |
7290| 14800030  | SQLite: Unable to open the database file. |
7291| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7292| 14800032  | SQLite: Abort due to constraint violation. |
7293| 14800033  | SQLite: Data type mismatch. |
7294| 14800034  | SQLite: Library used incorrectly. |
7295
7296**示例:**
7297
7298```ts
7299import { BusinessError } from '@kit.BasicServicesKit';
7300
7301let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
7302predicates.equalTo("NAME", "Lisa");
7303if(store != undefined) {
7304  (store as relationalStore.RdbStore).unlockRow(predicates).then(() => {
7305    console.info(`Unlock success`);
7306  }).catch((err: BusinessError) => {
7307    console.error(`Unlock failed, code is ${err.code},message is ${err.message}`);
7308  })
7309}
7310```
7311
7312### queryLockedRow<sup>12+</sup>
7313
7314queryLockedRow(predicates: RdbPredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
7315
7316根据指定条件查询数据库中锁定的数据,使用Promise异步回调。
7317由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
7318
7319**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7320
7321**参数:**
7322
7323| 参数名     | 类型                                 | 必填 | 说明                                             |
7324| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
7325| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。        |
7326| columns    | Array&lt;string&gt;                  | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
7327
7328**错误码:**
7329
7330以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7331
7332| **错误码ID** | **错误信息**                                                 |
7333|-----------| ------------------------------------------------------------ |
7334| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7335| 14800000  | Inner error. |
7336| 14800011  | Database corrupted. |
7337| 14800014  | Already closed. |
7338| 14800015  | The database does not respond.                 |
7339| 14800021  | SQLite: Generic error. |
7340| 14800022  | SQLite: Callback routine requested an abort. |
7341| 14800023  | SQLite: Access permission denied. |
7342| 14800024  | SQLite: The database file is locked. |
7343| 14800025  | SQLite: A table in the database is locked. |
7344| 14800026  | SQLite: The database is out of memory. |
7345| 14800027  | SQLite: Attempt to write a readonly database. |
7346| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7347| 14800029  | SQLite: The database is full. |
7348| 14800030  | SQLite: Unable to open the database file. |
7349| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7350| 14800032  | SQLite: Abort due to constraint violation. |
7351| 14800033  | SQLite: Data type mismatch. |
7352| 14800034  | SQLite: Library used incorrectly. |
7353
7354**返回值**:
7355
7356| 类型                                                    | 说明                                               |
7357| ------------------------------------------------------- | -------------------------------------------------- |
7358| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
7359
7360**示例:**
7361
7362```ts
7363import { BusinessError } from '@kit.BasicServicesKit';
7364
7365let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
7366predicates.equalTo("NAME", "Rose");
7367if(store != undefined) {
7368  (store as relationalStore.RdbStore).queryLockedRow(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => {
7369    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
7370    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
7371    while (resultSet.goToNextRow()) {
7372      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
7373      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
7374      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
7375      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
7376      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
7377    }
7378    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
7379    resultSet.close();
7380  }).catch((err: BusinessError) => {
7381    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
7382  })
7383}
7384```
7385### close<sup>12+</sup>
7386
7387close(): Promise&lt;void&gt;
7388
7389关闭数据库,使用Promise异步回调。
7390
7391**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7392
7393**返回值:**
7394
7395| 类型                | 说明          |
7396| ------------------- | ------------- |
7397| Promise&lt;void&gt; | Promise对象。 |
7398
7399**错误码:**
7400
7401以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
7402
7403| **错误码ID** | **错误信息**                                    |
7404| ------------ | ----------------------------------------------- |
7405| 401          | Parameter error. The store must not be nullptr. |
7406| 14800000     | Inner error.                                    |
7407
7408**示例:**
7409
7410```ts
7411import { BusinessError } from '@kit.BasicServicesKit';
7412
7413if(store != undefined) {
7414    (store as relationalStore.RdbStore).close().then(() => {
7415        console.info(`close succeeded`);
7416    }).catch ((err: BusinessError) => {
7417        console.error(`close failed, code is ${err.code},message is ${err.message}`);
7418    })
7419}
7420```
7421
7422## ResultSet
7423
7424提供通过查询数据库生成的数据库结果集的访问方法。结果集是指用户调用关系型数据库查询接口之后返回的结果集合,提供了多种灵活的数据访问方式,以便用户获取各项数据。
7425
7426### 使用说明
7427
7428首先需要获取resultSet对象。
7429
7430**示例:**
7431
7432<!--code_no_check-->
7433```ts
7434import { UIAbility } from '@kit.AbilityKit';
7435import { BusinessError } from '@kit.BasicServicesKit';
7436import { window } from '@kit.ArkUI';
7437
7438let store: relationalStore.RdbStore | undefined = undefined;
7439
7440class EntryAbility extends UIAbility {
7441  onWindowStageCreate(windowStage: window.WindowStage) {
7442    const STORE_CONFIG: relationalStore.StoreConfig = {
7443      name: "RdbTest.db",
7444      securityLevel: relationalStore.SecurityLevel.S3,
7445    };
7446
7447    relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => {
7448      store = rdbStore;
7449      console.info('Get RdbStore successfully.')
7450    }).catch((err: BusinessError) => {
7451      console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
7452    })
7453
7454    let resultSet: relationalStore.ResultSet | undefined = undefined;
7455    let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
7456    predicates.equalTo("AGE", 18);
7457    if(store != undefined) {
7458      (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((result: relationalStore.ResultSet) => {
7459        resultSet = result;
7460        console.info(`resultSet columnNames: ${resultSet.columnNames}`);
7461        console.info(`resultSet columnCount: ${resultSet.columnCount}`);
7462      });
7463    }
7464  }
7465}
7466```
7467
7468### 属性
7469
7470**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7471
7472| 名称         | 类型            | 必填 | 说明                             |
7473| ------------ | ------------------- | ---- | -------------------------------- |
7474| columnNames  | Array&lt;string&gt; | 是   | 获取结果集中所有列的名称。       |
7475| columnCount  | number              | 是   | 获取结果集中的列数。             |
7476| rowCount     | number              | 是   | 获取结果集中的行数。             |
7477| rowIndex     | number              | 是   | 获取结果集当前行的索引。         |
7478| isAtFirstRow | boolean             | 是   | 检查结果集是否位于第一行。       |
7479| isAtLastRow  | boolean             | 是   | 检查结果集是否位于最后一行。     |
7480| isEnded      | boolean             | 是   | 检查结果集是否位于最后一行之后。 |
7481| isStarted    | boolean             | 是   | 检查指针是否移动过。             |
7482| isClosed     | boolean             | 是   | 检查当前结果集是否关闭。         |
7483
7484### getColumnIndex
7485
7486getColumnIndex(columnName: string): number
7487
7488根据指定的列名获取列索引。
7489
7490**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7491
7492**参数:**
7493
7494| 参数名     | 类型   | 必填 | 说明                       |
7495| ---------- | ------ | ---- | -------------------------- |
7496| columnName | string | 是   | 表示结果集中指定列的名称。 |
7497
7498**返回值:**
7499
7500| 类型   | 说明               |
7501| ------ | ------------------ |
7502| number | 返回指定列的索引。 |
7503
7504**错误码:**
7505
7506以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7507
7508| **错误码ID** | **错误信息**                                                 |
7509|-----------| ------------------------------------------------------------ |
7510| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7511| 14800000  | Inner error. |
7512| 14800011  | Database corrupted. |
7513| 14800013  | Column out of bounds. |
7514| 14800014  | Already closed. |
7515| 14800019  | The SQL must be a query statement. |
7516| 14800021  | SQLite: Generic error. |
7517| 14800022  | SQLite: Callback routine requested an abort. |
7518| 14800023  | SQLite: Access permission denied. |
7519| 14800024  | SQLite: The database file is locked. |
7520| 14800025  | SQLite: A table in the database is locked. |
7521| 14800026  | SQLite: The database is out of memory. |
7522| 14800027  | SQLite: Attempt to write a readonly database. |
7523| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7524| 14800029  | SQLite: The database is full. |
7525| 14800030  | SQLite: Unable to open the database file. |
7526| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7527| 14800032  | SQLite: Abort due to constraint violation. |
7528| 14800033  | SQLite: Data type mismatch. |
7529| 14800034  | SQLite: Library used incorrectly. |
7530
7531**示例:**
7532
7533```ts
7534if(resultSet != undefined) {
7535  const id = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("ID"));
7536  const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME"));
7537  const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE"));
7538  const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY"));
7539}
7540```
7541
7542### getColumnName
7543
7544getColumnName(columnIndex: number): string
7545
7546根据指定的列索引获取列名。
7547
7548**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7549
7550**参数:**
7551
7552| 参数名      | 类型   | 必填 | 说明                       |
7553| ----------- | ------ | ---- | -------------------------- |
7554| columnIndex | number | 是   | 表示结果集中指定列的索引。 |
7555
7556**返回值:**
7557
7558| 类型   | 说明               |
7559| ------ | ------------------ |
7560| string | 返回指定列的名称。 |
7561
7562**错误码:**
7563
7564以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7565
7566| **错误码ID** | **错误信息**                                                 |
7567|-----------| ------------------------------------------------------------ |
7568| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7569| 14800000  | Inner error. |
7570| 14800011  | Database corrupted. |
7571| 14800013  | Column out of bounds. |
7572| 14800014  | Already closed. |
7573| 14800019  | The SQL must be a query statement. |
7574| 14800021  | SQLite: Generic error. |
7575| 14800022  | SQLite: Callback routine requested an abort. |
7576| 14800023  | SQLite: Access permission denied. |
7577| 14800024  | SQLite: The database file is locked. |
7578| 14800025  | SQLite: A table in the database is locked. |
7579| 14800026  | SQLite: The database is out of memory. |
7580| 14800027  | SQLite: Attempt to write a readonly database. |
7581| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7582| 14800029  | SQLite: The database is full. |
7583| 14800030  | SQLite: Unable to open the database file. |
7584| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7585| 14800032  | SQLite: Abort due to constraint violation. |
7586| 14800033  | SQLite: Data type mismatch. |
7587| 14800034  | SQLite: Library used incorrectly. |
7588
7589**示例:**
7590
7591```ts
7592if(resultSet != undefined) {
7593  const id = (resultSet as relationalStore.ResultSet).getColumnName(0);
7594  const name = (resultSet as relationalStore.ResultSet).getColumnName(1);
7595  const age = (resultSet as relationalStore.ResultSet).getColumnName(2);
7596}
7597```
7598
7599### goTo
7600
7601goTo(offset:number): boolean
7602
7603向前或向后转至结果集的指定行,相对于其当前位置偏移。
7604
7605**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7606
7607**参数:**
7608
7609| 参数名 | 类型   | 必填 | 说明                         |
7610| ------ | ------ | ---- | ---------------------------- |
7611| offset | number | 是   | 表示相对于当前位置的偏移量。 |
7612
7613**返回值:**
7614
7615| 类型    | 说明                                          |
7616| ------- | --------------------------------------------- |
7617| boolean | 如果成功移动结果集,则为true;否则返回false。 |
7618
7619**错误码:**
7620
7621以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7622
7623| **错误码ID** | **错误信息**                                                 |
7624|-----------| ------------------------------------------------------------ |
7625| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7626| 14800000  | Inner error. |
7627| 14800011  | Database corrupted. |
7628| 14800012  | Row out of bounds. |
7629| 14800014  | Already closed. |
7630| 14800019  | The SQL must be a query statement. |
7631| 14800021  | SQLite: Generic error. |
7632| 14800022  | SQLite: Callback routine requested an abort. |
7633| 14800023  | SQLite: Access permission denied. |
7634| 14800024  | SQLite: The database file is locked. |
7635| 14800025  | SQLite: A table in the database is locked. |
7636| 14800026  | SQLite: The database is out of memory. |
7637| 14800027  | SQLite: Attempt to write a readonly database. |
7638| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7639| 14800029  | SQLite: The database is full. |
7640| 14800030  | SQLite: Unable to open the database file. |
7641| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7642| 14800032  | SQLite: Abort due to constraint violation. |
7643| 14800033  | SQLite: Data type mismatch. |
7644| 14800034  | SQLite: Library used incorrectly. |
7645
7646**示例:**
7647
7648```ts
7649if(resultSet != undefined) {
7650  (resultSet as relationalStore.ResultSet).goTo(1);
7651}
7652```
7653
7654### goToRow
7655
7656goToRow(position: number): boolean
7657
7658转到结果集的指定行。
7659
7660**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7661
7662**参数:**
7663
7664| 参数名   | 类型   | 必填 | 说明                     |
7665| -------- | ------ | ---- | ------------------------ |
7666| position | number | 是   | 表示要移动到的指定位置。 |
7667
7668**返回值:**
7669
7670| 类型    | 说明                                          |
7671| ------- | --------------------------------------------- |
7672| boolean | 如果成功移动结果集,则为true;否则返回false。 |
7673
7674**错误码:**
7675
7676以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7677
7678| **错误码ID** | **错误信息**                                                 |
7679|-----------| ------------------------------------------------------------ |
7680| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7681| 14800000  | Inner error. |
7682| 14800011  | Database corrupted. |
7683| 14800012  | Row out of bounds. |
7684| 14800014  | Already closed. |
7685| 14800019  | The SQL must be a query statement. |
7686| 14800021  | SQLite: Generic error. |
7687| 14800022  | SQLite: Callback routine requested an abort. |
7688| 14800023  | SQLite: Access permission denied. |
7689| 14800024  | SQLite: The database file is locked. |
7690| 14800025  | SQLite: A table in the database is locked. |
7691| 14800026  | SQLite: The database is out of memory. |
7692| 14800027  | SQLite: Attempt to write a readonly database. |
7693| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7694| 14800029  | SQLite: The database is full. |
7695| 14800030  | SQLite: Unable to open the database file. |
7696| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7697| 14800032  | SQLite: Abort due to constraint violation. |
7698| 14800033  | SQLite: Data type mismatch. |
7699| 14800034  | SQLite: Library used incorrectly. |
7700
7701**示例:**
7702
7703```ts
7704if(resultSet != undefined) {
7705  (resultSet as relationalStore.ResultSet).goToRow(5);
7706}
7707```
7708
7709### goToFirstRow
7710
7711goToFirstRow(): boolean
7712
7713
7714转到结果集的第一行。
7715
7716**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7717
7718**返回值:**
7719
7720| 类型    | 说明                                          |
7721| ------- | --------------------------------------------- |
7722| boolean | 如果成功移动结果集,则为true;否则返回false。 |
7723
7724**错误码:**
7725
7726以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7727
7728| **错误码ID** | **错误信息**                                                 |
7729|-----------| ------------------------------------------------------------ |
7730| 14800000  | Inner error. |
7731| 14800011  | Database corrupted. |
7732| 14800012  | Row out of bounds. |
7733| 14800014  | Already closed. |
7734| 14800019  | The SQL must be a query statement. |
7735| 14800021  | SQLite: Generic error. |
7736| 14800022  | SQLite: Callback routine requested an abort. |
7737| 14800023  | SQLite: Access permission denied. |
7738| 14800024  | SQLite: The database file is locked. |
7739| 14800025  | SQLite: A table in the database is locked. |
7740| 14800026  | SQLite: The database is out of memory. |
7741| 14800027  | SQLite: Attempt to write a readonly database. |
7742| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7743| 14800029  | SQLite: The database is full. |
7744| 14800030  | SQLite: Unable to open the database file. |
7745| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7746| 14800032  | SQLite: Abort due to constraint violation. |
7747| 14800033  | SQLite: Data type mismatch. |
7748| 14800034  | SQLite: Library used incorrectly. |
7749
7750**示例:**
7751
7752```ts
7753if(resultSet != undefined) {
7754  (resultSet as relationalStore.ResultSet).goToFirstRow();
7755}
7756```
7757
7758### goToLastRow
7759
7760goToLastRow(): boolean
7761
7762转到结果集的最后一行。
7763
7764**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7765
7766**返回值:**
7767
7768| 类型    | 说明                                          |
7769| ------- | --------------------------------------------- |
7770| boolean | 如果成功移动结果集,则为true;否则返回false。 |
7771
7772**错误码:**
7773
7774以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7775
7776| **错误码ID** | **错误信息**                                                 |
7777|-----------| ------------------------------------------------------------ |
7778| 14800000  | Inner error. |
7779| 14800011  | Database corrupted. |
7780| 14800012  | Row out of bounds. |
7781| 14800014  | Already closed. |
7782| 14800019  | The SQL must be a query statement. |
7783| 14800021  | SQLite: Generic error. |
7784| 14800022  | SQLite: Callback routine requested an abort. |
7785| 14800023  | SQLite: Access permission denied. |
7786| 14800024  | SQLite: The database file is locked. |
7787| 14800025  | SQLite: A table in the database is locked. |
7788| 14800026  | SQLite: The database is out of memory. |
7789| 14800027  | SQLite: Attempt to write a readonly database. |
7790| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7791| 14800029  | SQLite: The database is full. |
7792| 14800030  | SQLite: Unable to open the database file. |
7793| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7794| 14800032  | SQLite: Abort due to constraint violation. |
7795| 14800033  | SQLite: Data type mismatch. |
7796| 14800034  | SQLite: Library used incorrectly. |
7797
7798**示例:**
7799
7800```ts
7801if(resultSet != undefined) {
7802  (resultSet as relationalStore.ResultSet).goToLastRow();
7803}
7804```
7805
7806### goToNextRow
7807
7808goToNextRow(): boolean
7809
7810转到结果集的下一行。
7811
7812**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7813
7814**返回值:**
7815
7816| 类型    | 说明                                          |
7817| ------- | --------------------------------------------- |
7818| boolean | 如果成功移动结果集,则为true;否则返回false。 |
7819
7820**错误码:**
7821
7822以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7823
7824| **错误码ID** | **错误信息**                                                 |
7825|-----------| ------------------------------------------------------------ |
7826| 14800000  | Inner error. |
7827| 14800011  | Database corrupted. |
7828| 14800012  | Row out of bounds. |
7829| 14800014  | Already closed. |
7830| 14800019  | The SQL must be a query statement. |
7831| 14800021  | SQLite: Generic error. |
7832| 14800022  | SQLite: Callback routine requested an abort. |
7833| 14800023  | SQLite: Access permission denied. |
7834| 14800024  | SQLite: The database file is locked. |
7835| 14800025  | SQLite: A table in the database is locked. |
7836| 14800026  | SQLite: The database is out of memory. |
7837| 14800027  | SQLite: Attempt to write a readonly database. |
7838| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7839| 14800029  | SQLite: The database is full. |
7840| 14800030  | SQLite: Unable to open the database file. |
7841| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7842| 14800032  | SQLite: Abort due to constraint violation. |
7843| 14800033  | SQLite: Data type mismatch. |
7844| 14800034  | SQLite: Library used incorrectly. |
7845
7846**示例:**
7847
7848```ts
7849if(resultSet != undefined) {
7850  (resultSet as relationalStore.ResultSet).goToNextRow();
7851}
7852```
7853
7854### goToPreviousRow
7855
7856goToPreviousRow(): boolean
7857
7858转到结果集的上一行。
7859
7860**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7861
7862**返回值:**
7863
7864| 类型    | 说明                                          |
7865| ------- | --------------------------------------------- |
7866| boolean | 如果成功移动结果集,则为true;否则返回false。 |
7867
7868**错误码:**
7869
7870以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7871
7872| **错误码ID** | **错误信息**                                                 |
7873|-----------| ------------------------------------------------------------ |
7874| 14800000  | Inner error. |
7875| 14800011  | Database corrupted. |
7876| 14800012  | Row out of bounds. |
7877| 14800014  | Already closed. |
7878| 14800019  | The SQL must be a query statement. |
7879| 14800021  | SQLite: Generic error. |
7880| 14800022  | SQLite: Callback routine requested an abort. |
7881| 14800023  | SQLite: Access permission denied. |
7882| 14800024  | SQLite: The database file is locked. |
7883| 14800025  | SQLite: A table in the database is locked. |
7884| 14800026  | SQLite: The database is out of memory. |
7885| 14800027  | SQLite: Attempt to write a readonly database. |
7886| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7887| 14800029  | SQLite: The database is full. |
7888| 14800030  | SQLite: Unable to open the database file. |
7889| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7890| 14800032  | SQLite: Abort due to constraint violation. |
7891| 14800033  | SQLite: Data type mismatch. |
7892| 14800034  | SQLite: Library used incorrectly. |
7893
7894**示例:**
7895
7896```ts
7897if(resultSet != undefined) {
7898  (resultSet as relationalStore.ResultSet).goToPreviousRow();
7899}
7900```
7901
7902### getValue<sup>12+</sup>
7903
7904getValue(columnIndex: number): ValueType
7905
7906获取当前行中指定列的值,值类型如果是ValueType指定的任意类型,则会以对应类型返回指定类的值,否则返回14800000。
7907
7908**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7909
7910**参数:**
7911
7912| 参数名      | 类型   | 必填 | 说明                    |
7913| ----------- | ------ | ---- | ----------------------- |
7914| columnIndex | number | 是   | 指定的列索引,从0开始。 |
7915
7916**返回值:**
7917
7918| 类型       | 说明                             |
7919| ---------- | -------------------------------- |
7920| [ValueType](#valuetype) | 表示允许的数据字段类型。 |
7921
7922**错误码:**
7923
7924以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7925
7926| **错误码ID** | **错误信息**     |
7927|-----------|---------|
7928| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7929| 14800000  | Inner error.      |
7930| 14800011  | Database corrupted.        |
7931| 14800012  | Row out of bounds.       |
7932| 14800013  | Column out of bounds.   |
7933| 14800014  | Already closed.       |
7934| 14800021  | SQLite: Generic error.    |
7935| 14800022  | SQLite: Callback routine requested an abort.     |
7936| 14800023  | SQLite: Access permission denied.    |
7937| 14800024  | SQLite: The database file is locked.    |
7938| 14800025  | SQLite: A table in the database is locked.  |
7939| 14800026  | SQLite: The database is out of memory.    |
7940| 14800027  | SQLite: Attempt to write a readonly database.    |
7941| 14800028  | SQLite: Some kind of disk I/O error occurred.    |
7942| 14800029  | SQLite: The database is full.   |
7943| 14800030  | SQLite: Unable to open the database file.    |
7944| 14800031  | SQLite: TEXT or BLOB exceeds size limit.    |
7945| 14800032  | SQLite: Abort due to constraint violation.   |
7946| 14800033  | SQLite: Data type mismatch.      |
7947| 14800034  | SQLite: Library used incorrectly.    |
7948
7949**示例:**
7950
7951```ts
7952if(resultSet != undefined) {
7953  const codes = (resultSet as relationalStore.ResultSet).getValue((resultSet as relationalStore.ResultSet).getColumnIndex("BIGINT_COLUMN"));
7954}
7955```
7956
7957### getBlob
7958
7959getBlob(columnIndex: number): Uint8Array
7960
7961
7962以字节数组的形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成字节数组类型返回指定值,如果该列内容为空时,会返回空字节数组,其他类型则返回14800000。
7963
7964**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7965
7966**参数:**
7967
7968| 参数名      | 类型   | 必填 | 说明                    |
7969| ----------- | ------ | ---- | ----------------------- |
7970| columnIndex | number | 是   | 指定的列索引,从0开始。 |
7971
7972**返回值:**
7973
7974| 类型       | 说明                             |
7975| ---------- | -------------------------------- |
7976| Uint8Array | 以字节数组的形式返回指定列的值。 |
7977
7978**错误码:**
7979
7980以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7981
7982| **错误码ID** | **错误信息**                                                 |
7983|-----------| ------------------------------------------------------------ |
7984| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7985| 14800000  | Inner error. |
7986| 14800011  | Database corrupted. |
7987| 14800012  | Row out of bounds. |
7988| 14800013  | Column out of bounds. |
7989| 14800014  | Already closed. |
7990| 14800021  | SQLite: Generic error. |
7991| 14800022  | SQLite: Callback routine requested an abort. |
7992| 14800023  | SQLite: Access permission denied. |
7993| 14800024  | SQLite: The database file is locked. |
7994| 14800025  | SQLite: A table in the database is locked. |
7995| 14800026  | SQLite: The database is out of memory. |
7996| 14800027  | SQLite: Attempt to write a readonly database. |
7997| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7998| 14800029  | SQLite: The database is full. |
7999| 14800030  | SQLite: Unable to open the database file. |
8000| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8001| 14800032  | SQLite: Abort due to constraint violation. |
8002| 14800033  | SQLite: Data type mismatch. |
8003| 14800034  | SQLite: Library used incorrectly. |
8004
8005**示例:**
8006
8007```ts
8008if(resultSet != undefined) {
8009  const codes = (resultSet as relationalStore.ResultSet).getBlob((resultSet as relationalStore.ResultSet).getColumnIndex("CODES"));
8010}
8011```
8012
8013### getString
8014
8015getString(columnIndex: number): string
8016
8017以字符串形式获取当前行中指定列的值,如果当前列中的值为INTEGER、DOUBLE、TEXT、BLOB类型,会以字符串形式返回指定值,如果是当前列中的值为INTEGER,并且为空,则会返回空字符串"",其他类型则返回14800000。如果当前列中的值为DOUBLE类型,可能存在精度的丢失,建议使用[getDouble](#getdouble)接口获取。
8018
8019**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8020
8021**参数:**
8022
8023| 参数名      | 类型   | 必填 | 说明                    |
8024| ----------- | ------ | ---- | ----------------------- |
8025| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8026
8027**返回值:**
8028
8029| 类型   | 说明                         |
8030| ------ | ---------------------------- |
8031| string | 以字符串形式返回指定列的值。 |
8032
8033**错误码:**
8034
8035以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8036
8037| **错误码ID** | **错误信息**                                                 |
8038|-----------| ------------------------------------------------------------ |
8039| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8040| 14800000  | Inner error. |
8041| 14800011  | Database corrupted. |
8042| 14800012  | Row out of bounds. |
8043| 14800013  | Column out of bounds. |
8044| 14800014  | Already closed. |
8045| 14800021  | SQLite: Generic error. |
8046| 14800022  | SQLite: Callback routine requested an abort. |
8047| 14800023  | SQLite: Access permission denied. |
8048| 14800024  | SQLite: The database file is locked. |
8049| 14800025  | SQLite: A table in the database is locked. |
8050| 14800026  | SQLite: The database is out of memory. |
8051| 14800027  | SQLite: Attempt to write a readonly database. |
8052| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8053| 14800029  | SQLite: The database is full. |
8054| 14800030  | SQLite: Unable to open the database file. |
8055| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8056| 14800032  | SQLite: Abort due to constraint violation. |
8057| 14800033  | SQLite: Data type mismatch. |
8058| 14800034  | SQLite: Library used incorrectly. |
8059
8060**示例:**
8061
8062```ts
8063if(resultSet != undefined) {
8064  const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME"));
8065}
8066```
8067
8068### getLong
8069
8070getLong(columnIndex: number): number
8071
8072以Long形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成Long类型返回指定值,如果该列内容为空时,会返回0,其他类型则返回14800000。
8073
8074**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8075
8076**参数:**
8077
8078| 参数名      | 类型   | 必填 | 说明                    |
8079| ----------- | ------ | ---- | ----------------------- |
8080| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8081
8082**返回值:**
8083
8084| 类型   | 说明                                                         |
8085| ------ | ------------------------------------------------------------ |
8086| number | 以Long形式返回指定列的值。<br>该接口支持的数据范围是:Number.MIN_SAFE_INTEGER ~ Number.MAX_SAFE_INTEGER,若超出该范围,建议使用[getDouble](#getdouble)。 |
8087
8088**错误码:**
8089
8090以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8091
8092| **错误码ID** | **错误信息**                                                 |
8093|-----------| ------------------------------------------------------------ |
8094| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8095| 14800000  | Inner error. |
8096| 14800011  | Database corrupted. |
8097| 14800012  | Row out of bounds. |
8098| 14800013  | Column out of bounds. |
8099| 14800014  | Already closed. |
8100| 14800021  | SQLite: Generic error. |
8101| 14800022  | SQLite: Callback routine requested an abort. |
8102| 14800023  | SQLite: Access permission denied. |
8103| 14800024  | SQLite: The database file is locked. |
8104| 14800025  | SQLite: A table in the database is locked. |
8105| 14800026  | SQLite: The database is out of memory. |
8106| 14800027  | SQLite: Attempt to write a readonly database. |
8107| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8108| 14800029  | SQLite: The database is full. |
8109| 14800030  | SQLite: Unable to open the database file. |
8110| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8111| 14800032  | SQLite: Abort due to constraint violation. |
8112| 14800033  | SQLite: Data type mismatch. |
8113| 14800034  | SQLite: Library used incorrectly. |
8114
8115**示例:**
8116
8117```ts
8118if(resultSet != undefined) {
8119  const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE"));
8120 }
8121```
8122
8123### getDouble
8124
8125getDouble(columnIndex: number): number
8126
8127以double形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成double类型返回指定值,如果该列内容为空时,会返回0.0,其他类型则返回14800000。
8128
8129**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8130
8131**参数:**
8132
8133| 参数名      | 类型   | 必填 | 说明                    |
8134| ----------- | ------ | ---- | ----------------------- |
8135| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8136
8137**返回值:**
8138
8139| 类型   | 说明                         |
8140| ------ | ---------------------------- |
8141| number | 以double形式返回指定列的值。 |
8142
8143**错误码:**
8144
8145以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8146
8147| **错误码ID** | **错误信息**                                                 |
8148|-----------| ------------------------------------------------------------ |
8149| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8150| 14800000  | Inner error. |
8151| 14800011  | Database corrupted. |
8152| 14800012  | Row out of bounds. |
8153| 14800013  | Column out of bounds. |
8154| 14800014  | Already closed. |
8155| 14800021  | SQLite: Generic error. |
8156| 14800022  | SQLite: Callback routine requested an abort. |
8157| 14800023  | SQLite: Access permission denied. |
8158| 14800024  | SQLite: The database file is locked. |
8159| 14800025  | SQLite: A table in the database is locked. |
8160| 14800026  | SQLite: The database is out of memory. |
8161| 14800027  | SQLite: Attempt to write a readonly database. |
8162| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8163| 14800029  | SQLite: The database is full. |
8164| 14800030  | SQLite: Unable to open the database file. |
8165| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8166| 14800032  | SQLite: Abort due to constraint violation. |
8167| 14800033  | SQLite: Data type mismatch. |
8168| 14800034  | SQLite: Library used incorrectly. |
8169
8170**示例:**
8171
8172```ts
8173if(resultSet != undefined) {
8174  const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY"));
8175}
8176```
8177
8178### getAsset<sup>10+</sup>
8179
8180getAsset(columnIndex: number): Asset
8181
8182以[Asset](#asset10)形式获取当前行中指定列的值,如果当前列的数据类型为Asset类型,会以Asset类型返回指定值,如果当前列中的值为null时,会返回null,其他类型则返回14800000。
8183
8184**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8185
8186**参数:**
8187
8188| 参数名         | 类型     | 必填  | 说明           |
8189| ----------- | ------ | --- | ------------ |
8190| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8191
8192**返回值:**
8193
8194| 类型              | 说明                         |
8195| --------------- | -------------------------- |
8196| [Asset](#asset10) | 以Asset形式返回指定列的值。 |
8197
8198**错误码:**
8199
8200以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8201
8202| **错误码ID** | **错误信息**                                                 |
8203|-----------| ------------------------------------------------------------ |
8204| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8205| 14800000  | Inner error. |
8206| 14800011  | Database corrupted. |
8207| 14800012  | Row out of bounds. |
8208| 14800013  | Column out of bounds. |
8209| 14800014  | Already closed. |
8210| 14800021  | SQLite: Generic error. |
8211| 14800022  | SQLite: Callback routine requested an abort. |
8212| 14800023  | SQLite: Access permission denied. |
8213| 14800024  | SQLite: The database file is locked. |
8214| 14800025  | SQLite: A table in the database is locked. |
8215| 14800026  | SQLite: The database is out of memory. |
8216| 14800027  | SQLite: Attempt to write a readonly database. |
8217| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8218| 14800029  | SQLite: The database is full. |
8219| 14800030  | SQLite: Unable to open the database file. |
8220| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8221| 14800032  | SQLite: Abort due to constraint violation. |
8222| 14800033  | SQLite: Data type mismatch. |
8223| 14800034  | SQLite: Library used incorrectly. |
8224
8225**示例:**
8226
8227```ts
8228if(resultSet != undefined) {
8229  const doc = (resultSet as relationalStore.ResultSet).getAsset((resultSet as relationalStore.ResultSet).getColumnIndex("DOC"));
8230}
8231```
8232
8233### getAssets<sup>10+</sup>
8234
8235getAssets(columnIndex: number): Assets
8236
8237以[Assets](#assets10)形式获取当前行中指定列的值,如果当前列的数据类型为Assets类型,会以Assets类型返回指定值,如果当前列中的值为null时,会返回null,其他类型则返回14800000。
8238
8239**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8240
8241**参数:**
8242
8243| 参数名         | 类型     | 必填  | 说明           |
8244| ----------- | ------ | --- | ------------ |
8245| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8246
8247**返回值:**
8248
8249| 类型              | 说明                           |
8250| ---------------- | ---------------------------- |
8251| [Assets](#assets10)| 以Assets形式返回指定列的值。 |
8252
8253**错误码:**
8254
8255以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8256
8257| **错误码ID** | **错误信息**                                                 |
8258|-----------| ------------------------------------------------------------ |
8259| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8260| 14800000  | Inner error. |
8261| 14800011  | Database corrupted. |
8262| 14800012  | Row out of bounds. |
8263| 14800013  | Column out of bounds. |
8264| 14800014  | Already closed. |
8265| 14800021  | SQLite: Generic error. |
8266| 14800022  | SQLite: Callback routine requested an abort. |
8267| 14800023  | SQLite: Access permission denied. |
8268| 14800024  | SQLite: The database file is locked. |
8269| 14800025  | SQLite: A table in the database is locked. |
8270| 14800026  | SQLite: The database is out of memory. |
8271| 14800027  | SQLite: Attempt to write a readonly database. |
8272| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8273| 14800029  | SQLite: The database is full. |
8274| 14800030  | SQLite: Unable to open the database file. |
8275| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8276| 14800032  | SQLite: Abort due to constraint violation. |
8277| 14800033  | SQLite: Data type mismatch. |
8278| 14800034  | SQLite: Library used incorrectly. |
8279
8280**示例:**
8281
8282```ts
8283if(resultSet != undefined) {
8284  const docs = (resultSet as relationalStore.ResultSet).getAssets((resultSet as relationalStore.ResultSet).getColumnIndex("DOCS"));
8285}
8286```
8287
8288### getRow<sup>11+</sup>
8289
8290getRow(): ValuesBucket
8291
8292获取当前行。
8293
8294**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8295
8296**返回值:**
8297
8298| 类型              | 说明                           |
8299| ---------------- | ---------------------------- |
8300| [ValuesBucket](#valuesbucket) | 返回指定行的值。 |
8301
8302**错误码:**
8303
8304以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8305
8306| **错误码ID** | **错误信息**                                                 |
8307|-----------| ------------------------------------------------------------ |
8308| 14800000  | Inner error. |
8309| 14800011  | Database corrupted. |
8310| 14800012  | Row out of bounds. |
8311| 14800013  | Column out of bounds. |
8312| 14800014  | Already closed. |
8313| 14800021  | SQLite: Generic error. |
8314| 14800022  | SQLite: Callback routine requested an abort. |
8315| 14800023  | SQLite: Access permission denied. |
8316| 14800024  | SQLite: The database file is locked. |
8317| 14800025  | SQLite: A table in the database is locked. |
8318| 14800026  | SQLite: The database is out of memory. |
8319| 14800027  | SQLite: Attempt to write a readonly database. |
8320| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8321| 14800029  | SQLite: The database is full. |
8322| 14800030  | SQLite: Unable to open the database file. |
8323| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8324| 14800032  | SQLite: Abort due to constraint violation. |
8325| 14800033  | SQLite: Data type mismatch. |
8326| 14800034  | SQLite: Library used incorrectly. |
8327
8328**示例:**
8329
8330```ts
8331if(resultSet != undefined) {
8332  const row = (resultSet as relationalStore.ResultSet).getRow();
8333}
8334```
8335
8336### getSendableRow<sup>12+</sup>
8337
8338getSendableRow(): sendableRelationalStore.ValuesBucket
8339
8340获取当前行数据的sendable形式,用于跨线程传递使用。
8341
8342**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8343
8344**返回值:**
8345
8346| 类型                                                                                           | 说明                                           |
8347| ---------------------------------------------------------------------------------------------- | ---------------------------------------------- |
8348| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | 当前行数据的sendable形式,用于跨线程传递使用。 |
8349
8350**错误码:**
8351
8352以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8353
8354| **错误码ID** | **错误信息**                                  |
8355| ------------ | --------------------------------------------- |
8356| 14800000     | Inner error.                                  |
8357| 14800011     | Database corrupted.                           |
8358| 14800012     | Row out of bounds.                            |
8359| 14800013     | Column out of bounds.                         |
8360| 14800014     | Already closed.                               |
8361| 14800021     | SQLite: Generic error.                        |
8362| 14800022     | SQLite: Callback routine requested an abort.  |
8363| 14800023     | SQLite: Access permission denied.             |
8364| 14800024     | SQLite: The database file is locked.          |
8365| 14800025     | SQLite: A table in the database is locked.    |
8366| 14800026     | SQLite: The database is out of memory.        |
8367| 14800027     | SQLite: Attempt to write a readonly database. |
8368| 14800028     | SQLite: Some kind of disk I/O error occurred. |
8369| 14800029     | SQLite: The database is full.                 |
8370| 14800030     | SQLite: Unable to open the database file.     |
8371| 14800031     | SQLite: TEXT or BLOB exceeds size limit.      |
8372| 14800032     | SQLite: Abort due to constraint violation.    |
8373| 14800033     | SQLite: Data type mismatch.                   |
8374| 14800034     | SQLite: Library used incorrectly.             |
8375
8376**示例:**
8377
8378```ts
8379import { taskpool } from '@kit.ArkTS';
8380import type ctx from '@ohos.app.ability.common';
8381import { sendableRelationalStore } from '@kit.ArkData';
8382
8383@Concurrent
8384async function getDataByName(name: string, context: ctx.UIAbilityContext) {
8385  const STORE_CONFIG: relationalStore.StoreConfig = {
8386    name: "RdbTest.db",
8387    securityLevel: relationalStore.SecurityLevel.S3
8388  };
8389  const store = await relationalStore.getRdbStore(context, STORE_CONFIG);
8390  const predicates = new relationalStore.RdbPredicates("EMPLOYEE");
8391  predicates.equalTo("NAME", name);
8392  const resultSet = store.querySync(predicates);
8393
8394  if (resultSet.rowCount > 0) {
8395    resultSet.goToFirstRow();
8396    const sendableValuesBucket = resultSet.getSendableRow();
8397    return sendableValuesBucket;
8398  } else {
8399    return null;
8400  }
8401}
8402
8403async function run() {
8404  const task = new taskpool.Task(getDataByName, 'Lisa', getContext());
8405  const sendableValuesBucket  = await taskpool.execute(task) as sendableRelationalStore.ValuesBucket;
8406
8407  if (sendableValuesBucket) {
8408    const columnCount = sendableValuesBucket.size;
8409    const age = sendableValuesBucket.get('age');
8410    const name = sendableValuesBucket.get('name');
8411    console.info(`Query data in taskpool succeeded, name is "${name}", age is "${age}"`)
8412  }
8413}
8414
8415run()
8416```
8417
8418### isColumnNull
8419
8420isColumnNull(columnIndex: number): boolean
8421
8422检查当前行中指定列的值是否为null。
8423
8424**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8425
8426**参数:**
8427
8428| 参数名      | 类型   | 必填 | 说明                    |
8429| ----------- | ------ | ---- | ----------------------- |
8430| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8431
8432**返回值:**
8433
8434| 类型    | 说明                                                      |
8435| ------- | --------------------------------------------------------- |
8436| boolean | 如果当前行中指定列的值为null,则返回true,否则返回false。 |
8437
8438**错误码:**
8439
8440以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8441
8442| **错误码ID** | **错误信息**                                                 |
8443|-----------| ------------------------------------------------------- |
8444| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8445| 14800000  | Inner error. |
8446| 14800011  | Database corrupted. |
8447| 14800012  | Row out of bounds. |
8448| 14800013  | Column out of bounds. |
8449| 14800014  | Already closed. |
8450| 14800021  | SQLite: Generic error. |
8451| 14800022  | SQLite: Callback routine requested an abort. |
8452| 14800023  | SQLite: Access permission denied. |
8453| 14800024  | SQLite: The database file is locked. |
8454| 14800025  | SQLite: A table in the database is locked. |
8455| 14800026  | SQLite: The database is out of memory. |
8456| 14800027  | SQLite: Attempt to write a readonly database. |
8457| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8458| 14800029  | SQLite: The database is full. |
8459| 14800030  | SQLite: Unable to open the database file. |
8460| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8461| 14800032  | SQLite: Abort due to constraint violation. |
8462| 14800033  | SQLite: Data type mismatch. |
8463| 14800034  | SQLite: Library used incorrectly. |
8464
8465**示例:**
8466
8467```ts
8468if(resultSet != undefined) {
8469  const isColumnNull = (resultSet as relationalStore.ResultSet).isColumnNull((resultSet as relationalStore.ResultSet).getColumnIndex("CODES"));
8470}
8471```
8472
8473### close
8474
8475close(): void
8476
8477关闭结果集,若不关闭可能会引起fd泄露和内存泄露。
8478
8479**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8480
8481**示例:**
8482
8483```ts
8484if(resultSet != undefined) {
8485  (resultSet as relationalStore.ResultSet).close();
8486}
8487```
8488
8489**错误码:**
8490
8491以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。
8492
8493| **错误码ID** | **错误信息**                                                 |
8494|-----------| ------------------------------------------------------------ |
8495| 14800000  | Inner error. |
8496| 14800012  | Row out of bounds. |
8497
8498## Transaction<sup>14+</sup>
8499
8500提供以事务方式管理数据库的方法。事务对象是通过[createTransaction](#createtransaction14)接口创建的,不同事务对象之间的操作是隔离的,不同类型事务的区别见[TransactionType](#transactiontype14) 。
8501
8502当前关系型数据库同一时刻只支持一个写事务,所以如果当前[RdbStore](#rdbstore)存在写事务未释放,创建IMMEDIATE或EXCLUSIVE事务会返回14800024错误码。如果是创建的DEFERRED事务,则可能在首次使用DEFERRED事务调用写操作时返回14800024错误码。通过IMMEDIATE或EXCLUSIVE创建写事务或者DEFERRED事务升级到写事务之后,[RdbStore](#rdbstore)的写操作也会返回14800024错误码。
8503
8504当事务并发量较高且写事务持续时间较长时,返回14800024错误码的次数可能会变多,开发者可以通过减少事务占用时长减少14800024出现的次数,也可以通过重试的方式处理14800024错误码。
8505
8506**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8507
8508**示例:**
8509
8510```ts
8511import { UIAbility } from '@kit.AbilityKit';
8512import { BusinessError } from '@kit.BasicServicesKit';
8513import { window } from '@kit.ArkUI';
8514
8515let store: relationalStore.RdbStore | undefined = undefined;
8516
8517class EntryAbility extends UIAbility {
8518  onWindowStageCreate(windowStage: window.WindowStage) {
8519    const STORE_CONFIG: relationalStore.StoreConfig = {
8520      name: "RdbTest.db",
8521      securityLevel: relationalStore.SecurityLevel.S3,
8522    };
8523
8524    relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => {
8525      store = rdbStore;
8526      console.info('Get RdbStore successfully.')
8527    }).catch((err: BusinessError) => {
8528      console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
8529    })
8530
8531    if(store != undefined) {
8532      (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8533        console.info(`createTransaction success`);
8534      }).catch((err: BusinessError) => {
8535        console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8536      });
8537    }
8538  }
8539}
8540```
8541
8542### commit<sup>14+</sup>
8543
8544commit(): Promise&lt;void&gt;
8545
8546提交已执行的SQL语句。如果是使用异步接口执行sql语句,请确保异步接口执行完成之后再调用commit接口,否则可能会丢失SQL操作。调用commit接口之后,该Transaction对象及创建的ResultSet对象都会被关闭。
8547
8548**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8549
8550**返回值**:
8551
8552| 类型                | 说明                      |
8553| ------------------- | ------------------------- |
8554| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8555
8556**错误码:**
8557
8558以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8559
8560| **错误码ID** | **错误信息**                                                 |
8561|-----------| ------------------------------------------------------------ |
8562| 14800000  | Inner error. |
8563| 14800011  | Database corrupted. |
8564| 14800014  | Already closed. |
8565| 14800023  | SQLite: Access permission denied. |
8566| 14800024  | SQLite: The database file is locked. |
8567| 14800026  | SQLite: The database is out of memory. |
8568| 14800027  | SQLite: Attempt to write a readonly database. |
8569| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8570| 14800029  | SQLite: The database is full. |
8571
8572**示例:**
8573
8574```ts
8575let value1 = "Lisa";
8576let value2 = 18;
8577let value3 = 100.5;
8578let value4 = new Uint8Array([1, 2, 3]);
8579
8580if(store != undefined) {
8581  const valueBucket: relationalStore.ValuesBucket = {
8582    'NAME': value1,
8583    'AGE': value2,
8584    'SALARY': value3,
8585    'CODES': value4,
8586  };
8587  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8588    transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => {
8589      transaction.commit();
8590    }).catch((e: BusinessError) => {
8591      transaction.rollback();
8592      console.error(`execute sql failed, code is ${e.code},message is ${e.message}`);
8593    });
8594  }).catch((err: BusinessError) => {
8595    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8596  });
8597}
8598```
8599
8600### rollback<sup>14+</sup>
8601
8602rollback(): Promise&lt;void&gt;
8603
8604回滚已经执行的SQL语句。调用rollback接口之后,该Transaction对象及创建的ResultSet对象都会被关闭。
8605
8606**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8607
8608**返回值**:
8609
8610| 类型                | 说明                      |
8611| ------------------- | ------------------------- |
8612| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8613
8614**错误码:**
8615
8616以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8617
8618| **错误码ID** | **错误信息**                                                 |
8619|-----------| ------------------------------------------------------------ |
8620| 14800000  | Inner error. |
8621| 14800011  | Database corrupted. |
8622| 14800014  | Already closed. |
8623| 14800023  | SQLite: Access permission denied. |
8624| 14800024  | SQLite: The database file is locked. |
8625| 14800026  | SQLite: The database is out of memory. |
8626| 14800027  | SQLite: Attempt to write a readonly database. |
8627| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8628| 14800029  | SQLite: The database is full. |
8629
8630**示例:**
8631
8632```ts
8633if(store != undefined) {
8634  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8635    transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => {
8636      transaction.commit();
8637    }).catch((e: BusinessError) => {
8638      transaction.rollback();
8639      console.error(`execute sql failed, code is ${e.code},message is ${e.message}`);
8640    });
8641  }).catch((err: BusinessError) => {
8642    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8643  });
8644}
8645
8646```
8647
8648### insert<sup>14+</sup>
8649
8650insert(table: string, values: ValuesBucket, conflict?: ConflictResolution): Promise&lt;number&gt;
8651
8652向目标表中插入一行数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
8653
8654**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8655
8656**参数:**
8657
8658| 参数名   | 类型                                        | 必填 | 说明                       |
8659| -------- | ------------------------------------------- | ---- | -------------------------- |
8660| table    | string                                      | 是   | 指定的目标表名。           |
8661| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。 |
8662| conflict | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。         |
8663
8664**返回值**:
8665
8666| 类型                  | 说明                                              |
8667| --------------------- | ------------------------------------------------- |
8668| Promise&lt;number&gt; | Promise对象。如果操作成功,返回行ID;否则返回-1。 |
8669
8670**错误码:**
8671
8672以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8673
8674| **错误码ID** | **错误信息**                                                 |
8675|-----------| ------------------------------------------------------------ |
8676| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8677| 14800000  | Inner error. |
8678| 14800011  | Database corrupted. |
8679| 14800014  | Already closed. |
8680| 14800021  | SQLite: Generic error. |
8681| 14800023  | SQLite: Access permission denied. |
8682| 14800024  | SQLite: The database file is locked. |
8683| 14800025  | SQLite: A table in the database is locked. |
8684| 14800026  | SQLite: The database is out of memory. |
8685| 14800027  | SQLite: Attempt to write a readonly database. |
8686| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8687| 14800029  | SQLite: The database is full. |
8688| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8689| 14800033  | SQLite: Data type mismatch. |
8690| 14800047  | The WAL file size exceeds the default limit. |
8691
8692**示例:**
8693
8694```ts
8695let value1 = "Lisa";
8696let value2 = 18;
8697let value3 = 100.5;
8698let value4 = new Uint8Array([1, 2, 3, 4, 5]);
8699
8700// 以下三种方式可用
8701const valueBucket1: relationalStore.ValuesBucket = {
8702  'NAME': value1,
8703  'AGE': value2,
8704  'SALARY': value3,
8705  'CODES': value4,
8706};
8707const valueBucket2: relationalStore.ValuesBucket = {
8708  NAME: value1,
8709  AGE: value2,
8710  SALARY: value3,
8711  CODES: value4,
8712};
8713const valueBucket3: relationalStore.ValuesBucket = {
8714  "NAME": value1,
8715  "AGE": value2,
8716  "SALARY": value3,
8717  "CODES": value4,
8718};
8719
8720if(store != undefined) {
8721  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8722    transaction.insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => {
8723      transaction.commit();
8724      console.info(`Insert is successful, rowId = ${rowId}`);
8725    }).catch((e: BusinessError) => {
8726      transaction.rollback();
8727      console.error(`Insert is failed, code is ${e.code},message is ${e.message}`);
8728    });
8729  }).catch((err: BusinessError) => {
8730    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8731  });
8732}
8733```
8734
8735### insertSync<sup>14+</sup>
8736
8737insertSync(table: string, values: ValuesBucket | sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution): number
8738
8739向目标表中插入一行数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
8740
8741**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8742
8743**参数:**
8744
8745| 参数名   | 类型                                        | 必填 | 说明                                                         |
8746| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
8747| table    | string                                      | 是   | 指定的目标表名。                                             |
8748| values   | [ValuesBucket](#valuesbucket) \| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket)   | 是   | 表示要插入到表中的数据行。                                   |
8749| conflict | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
8750
8751**返回值**:
8752
8753| 类型   | 说明                                 |
8754| ------ | ------------------------------------ |
8755| number | 如果操作成功,返回行ID;否则返回-1。 |
8756
8757**错误码:**
8758
8759以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8760
8761| **错误码ID** | **错误信息**                                                 |
8762| ------------ | ------------------------------------------------------------ |
8763| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8764| 14800000     | Inner error.                                                 |
8765| 14800011     | Database corrupted.                                          |
8766| 14800014     | Already closed.                                              |
8767| 14800021     | SQLite: Generic error.                                       |
8768| 14800023     | SQLite: Access permission denied.                            |
8769| 14800024     | SQLite: The database file is locked.                         |
8770| 14800025     | SQLite: A table in the database is locked.                   |
8771| 14800026     | SQLite: The database is out of memory.                       |
8772| 14800027     | SQLite: Attempt to write a readonly database.                |
8773| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
8774| 14800029     | SQLite: The database is full.                                |
8775| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
8776| 14800033     | SQLite: Data type mismatch.                                  |
8777| 14800047     | The WAL file size exceeds the default limit.                 |
8778
8779**示例:**
8780
8781```ts
8782let value1 = "Lisa";
8783let value2 = 18;
8784let value3 = 100.5;
8785let value4 = new Uint8Array([1, 2, 3, 4, 5]);
8786
8787// 以下三种方式可用
8788const valueBucket1: relationalStore.ValuesBucket = {
8789  'NAME': value1,
8790  'AGE': value2,
8791  'SALARY': value3,
8792  'CODES': value4,
8793};
8794const valueBucket2: relationalStore.ValuesBucket = {
8795  NAME: value1,
8796  AGE: value2,
8797  SALARY: value3,
8798  CODES: value4,
8799};
8800const valueBucket3: relationalStore.ValuesBucket = {
8801  "NAME": value1,
8802  "AGE": value2,
8803  "SALARY": value3,
8804  "CODES": value4,
8805};
8806
8807if(store != undefined) {
8808  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8809    try {
8810      let rowId: number = (transaction as relationalStore.Transaction).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
8811      transaction.commit();
8812      console.info(`Insert is successful, rowId = ${rowId}`);
8813    } catch (e: BusinessError) {
8814      transaction.rollback();
8815      console.error(`Insert is failed, code is ${e.code},message is ${e.message}`);
8816    };
8817  }).catch((err: BusinessError) => {
8818    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8819  });
8820}
8821```
8822
8823### batchInsert<sup>14+</sup>
8824
8825batchInsert(table: string, values: Array&lt;ValuesBucket&gt;): Promise&lt;number&gt;
8826
8827向目标表中插入一组数据,使用Promise异步回调。
8828
8829**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8830
8831**参数:**
8832
8833| 参数名 | 类型                                       | 必填 | 说明                         |
8834| ------ | ------------------------------------------ | ---- | ---------------------------- |
8835| table  | string                                     | 是   | 指定的目标表名。             |
8836| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。|
8837
8838**返回值**:
8839
8840| 类型                  | 说明                                                        |
8841| --------------------- | ----------------------------------------------------------- |
8842| Promise&lt;number&gt; | Promise对象。如果操作成功,返回插入的数据个数,否则返回-1。 |
8843
8844**错误码:**
8845
8846以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8847
8848| **错误码ID** | **错误信息**                                                 |
8849|-----------| ------------------------------------------------------------ |
8850| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8851| 14800000  | Inner error. |
8852| 14800011  | Database corrupted. |
8853| 14800014  | Already closed. |
8854| 14800021  | SQLite: Generic error. |
8855| 14800023  | SQLite: Access permission denied. |
8856| 14800024  | SQLite: The database file is locked. |
8857| 14800025  | SQLite: A table in the database is locked. |
8858| 14800026  | SQLite: The database is out of memory. |
8859| 14800027  | SQLite: Attempt to write a readonly database. |
8860| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8861| 14800029  | SQLite: The database is full. |
8862| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8863| 14800033  | SQLite: Data type mismatch. |
8864| 14800047  | The WAL file size exceeds the default limit. |
8865
8866**示例:**
8867
8868```ts
8869let value1 = "Lisa";
8870let value2 = 18;
8871let value3 = 100.5;
8872let value4 = new Uint8Array([1, 2, 3, 4, 5]);
8873let value5 = "Jack";
8874let value6 = 19;
8875let value7 = 101.5;
8876let value8 = new Uint8Array([6, 7, 8, 9, 10]);
8877let value9 = "Tom";
8878let value10 = 20;
8879let value11 = 102.5;
8880let value12 = new Uint8Array([11, 12, 13, 14, 15]);
8881
8882const valueBucket1: relationalStore.ValuesBucket = {
8883  'NAME': value1,
8884  'AGE': value2,
8885  'SALARY': value3,
8886  'CODES': value4,
8887};
8888const valueBucket2: relationalStore.ValuesBucket = {
8889  'NAME': value5,
8890  'AGE': value6,
8891  'SALARY': value7,
8892  'CODES': value8,
8893};
8894const valueBucket3: relationalStore.ValuesBucket = {
8895  'NAME': value9,
8896  'AGE': value10,
8897  'SALARY': value11,
8898  'CODES': value12,
8899};
8900
8901let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
8902if(store != undefined) {
8903  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8904    transaction.batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => {
8905      transaction.commit();
8906      console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
8907    }).catch((e: BusinessError) => {
8908      transaction.rollback();
8909      console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`);
8910    });
8911  }).catch((err: BusinessError) => {
8912    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8913  });
8914}
8915```
8916
8917### batchInsertSync<sup>14+</sup>
8918
8919batchInsertSync(table: string, values: Array&lt;ValuesBucket&gt;): number
8920
8921向目标表中插入一组数据。
8922
8923**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8924
8925**参数:**
8926
8927| 参数名 | 类型                                       | 必填 | 说明                         |
8928| ------ | ------------------------------------------ | ---- | ---------------------------- |
8929| table  | string                                     | 是   | 指定的目标表名。             |
8930| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。 |
8931
8932**返回值**:
8933
8934| 类型   | 说明                                           |
8935| ------ | ---------------------------------------------- |
8936| number | 如果操作成功,返回插入的数据个数,否则返回-1。 |
8937
8938**错误码:**
8939
8940以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8941
8942| **错误码ID** | **错误信息**                                                 |
8943| ------------ | ------------------------------------------------------------ |
8944| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8945| 14800000     | Inner error.                                                 |
8946| 14800011     | Database corrupted.                                          |
8947| 14800014     | Already closed.                                              |
8948| 14800021     | SQLite: Generic error.                                       |
8949| 14800023     | SQLite: Access permission denied.                            |
8950| 14800024     | SQLite: The database file is locked.                         |
8951| 14800025     | SQLite: A table in the database is locked.                   |
8952| 14800026     | SQLite: The database is out of memory.                       |
8953| 14800027     | SQLite: Attempt to write a readonly database.                |
8954| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
8955| 14800029     | SQLite: The database is full.                                |
8956| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
8957| 14800033     | SQLite: Data type mismatch.                                  |
8958| 14800047     | The WAL file size exceeds the default limit.                 |
8959
8960**示例:**
8961
8962```ts
8963let value1 = "Lisa";
8964let value2 = 18;
8965let value3 = 100.5;
8966let value4 = new Uint8Array([1, 2, 3, 4, 5]);
8967let value5 = "Jack";
8968let value6 = 19;
8969let value7 = 101.5;
8970let value8 = new Uint8Array([6, 7, 8, 9, 10]);
8971let value9 = "Tom";
8972let value10 = 20;
8973let value11 = 102.5;
8974let value12 = new Uint8Array([11, 12, 13, 14, 15]);
8975
8976const valueBucket1: relationalStore.ValuesBucket = {
8977  'NAME': value1,
8978  'AGE': value2,
8979  'SALARY': value3,
8980  'CODES': value4,
8981};
8982const valueBucket2: relationalStore.ValuesBucket = {
8983  'NAME': value5,
8984  'AGE': value6,
8985  'SALARY': value7,
8986  'CODES': value8,
8987};
8988const valueBucket3: relationalStore.ValuesBucket = {
8989  'NAME': value9,
8990  'AGE': value10,
8991  'SALARY': value11,
8992  'CODES': value12,
8993};
8994
8995let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
8996if(store != undefined) {
8997  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8998    try {
8999      let insertNum: number = (transaction as relationalStore.Transaction).batchInsertSync("EMPLOYEE", valueBuckets);
9000      transaction.commit();
9001      console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
9002    } catch (e) {
9003      transaction.rollback();
9004      console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`);
9005    };
9006  }).catch((err: BusinessError) => {
9007    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9008  });
9009}
9010```
9011
9012### update<sup>14+</sup>
9013
9014update(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): Promise&lt;number&gt;
9015
9016根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
9017
9018**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9019
9020**参数:**
9021
9022| 参数名     | 类型                                        | 必填 | 说明                                                         |
9023| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
9024| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
9025| predicates | [RdbPredicates](#rdbpredicates)            | 是   | RdbPredicates的实例对象指定的更新条件。                      |
9026| conflict   | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。 默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。                                          |
9027
9028**返回值**:
9029
9030| 类型                  | 说明                                      |
9031| --------------------- | ----------------------------------------- |
9032| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |
9033
9034**错误码:**
9035
9036以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9037
9038| **错误码ID** | **错误信息**                                                 |
9039|-----------| ------------------------------------------------------------ |
9040| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9041| 14800000  | Inner error. |
9042| 14800011  | Database corrupted. |
9043| 14800014  | Already closed. |
9044| 14800021  | SQLite: Generic error. |
9045| 14800023  | SQLite: Access permission denied. |
9046| 14800024  | SQLite: The database file is locked. |
9047| 14800025  | SQLite: A table in the database is locked. |
9048| 14800026  | SQLite: The database is out of memory. |
9049| 14800027  | SQLite: Attempt to write a readonly database. |
9050| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9051| 14800029  | SQLite: The database is full. |
9052| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9053| 14800033  | SQLite: Data type mismatch. |
9054| 14800047  | The WAL file size exceeds the default limit. |
9055
9056**示例:**
9057
9058```ts
9059let value1 = "Rose";
9060let value2 = 22;
9061let value3 = 200.5;
9062let value4 = new Uint8Array([1, 2, 3, 4, 5]);
9063
9064// 以下三种方式可用
9065const valueBucket1: relationalStore.ValuesBucket = {
9066  'NAME': value1,
9067  'AGE': value2,
9068  'SALARY': value3,
9069  'CODES': value4,
9070};
9071const valueBucket2: relationalStore.ValuesBucket = {
9072  NAME: value1,
9073  AGE: value2,
9074  SALARY: value3,
9075  CODES: value4,
9076};
9077const valueBucket3: relationalStore.ValuesBucket = {
9078  "NAME": value1,
9079  "AGE": value2,
9080  "SALARY": value3,
9081  "CODES": value4,
9082};
9083
9084let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
9085predicates.equalTo("NAME", "Lisa");
9086
9087if(store != undefined) {
9088  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9089    transaction.update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => {
9090      transaction.commit();
9091      console.info(`Updated row count: ${rows}`);
9092    }).catch((e: BusinessError) => {
9093      transaction.rollback();
9094      console.error(`Updated failed, code is ${e.code},message is ${e.message}`);
9095    });
9096  }).catch((err: BusinessError) => {
9097    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9098  });
9099}
9100```
9101
9102### updateSync<sup>14+</sup>
9103
9104updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): number
9105
9106根据RdbPredicates的指定实例对象更新数据库中的数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
9107
9108**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9109
9110**参数:**
9111
9112| 参数名     | 类型                                        | 必填 | 说明                                                         |
9113| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
9114| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
9115| predicates | [RdbPredicates](#rdbpredicates)             | 是   | RdbPredicates的实例对象指定的更新条件。                      |
9116| conflict   | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
9117
9118**返回值**:
9119
9120| 类型   | 说明               |
9121| ------ | ------------------ |
9122| number | 返回受影响的行数。 |
9123
9124**错误码:**
9125
9126以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9127
9128| **错误码ID** | **错误信息**                                                 |
9129| ------------ | ------------------------------------------------------------ |
9130| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9131| 14800000     | Inner error.                                                 |
9132| 14800011     | Database corrupted.                                          |
9133| 14800014     | Already closed.                                              |
9134| 14800021     | SQLite: Generic error.                                       |
9135| 14800023     | SQLite: Access permission denied.                            |
9136| 14800024     | SQLite: The database file is locked.                         |
9137| 14800025     | SQLite: A table in the database is locked.                   |
9138| 14800026     | SQLite: The database is out of memory.                       |
9139| 14800027     | SQLite: Attempt to write a readonly database.                |
9140| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
9141| 14800029     | SQLite: The database is full.                                |
9142| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
9143| 14800033     | SQLite: Data type mismatch.                                  |
9144| 14800047     | The WAL file size exceeds the default limit.                 |
9145
9146**示例:**
9147
9148```ts
9149let value1 = "Rose";
9150let value2 = 22;
9151let value3 = 200.5;
9152let value4 = new Uint8Array([1, 2, 3, 4, 5]);
9153
9154// 以下三种方式可用
9155const valueBucket1: relationalStore.ValuesBucket = {
9156  'NAME': value1,
9157  'AGE': value2,
9158  'SALARY': value3,
9159  'CODES': value4,
9160};
9161const valueBucket2: relationalStore.ValuesBucket = {
9162  NAME: value1,
9163  AGE: value2,
9164  SALARY: value3,
9165  CODES: value4,
9166};
9167const valueBucket3: relationalStore.ValuesBucket = {
9168  "NAME": value1,
9169  "AGE": value2,
9170  "SALARY": value3,
9171  "CODES": value4,
9172};
9173
9174let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
9175predicates.equalTo("NAME", "Lisa");
9176
9177if(store != undefined) {
9178  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9179    try {
9180      let rows: Number = (transaction as relationalStore.Transaction).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
9181      transaction.commit();
9182      console.info(`Updated row count: ${rows}`);
9183    } catch (e) {
9184      transaction.rollback();
9185      console.error(`Updated failed, code is ${e.code},message is ${e.message}`);
9186    };
9187  }).catch((err: BusinessError) => {
9188    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9189  });
9190}
9191```
9192
9193### delete<sup>14+</sup>
9194
9195delete(predicates: RdbPredicates):Promise&lt;number&gt;
9196
9197根据RdbPredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。
9198
9199**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9200
9201**参数:**
9202
9203| 参数名     | 类型                                 | 必填 | 说明                                      |
9204| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
9205| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
9206
9207**返回值**:
9208
9209| 类型                  | 说明                            |
9210| --------------------- | ------------------------------- |
9211| Promise&lt;number&gt; | Promise对象。返回受影响的行数。 |
9212
9213**错误码:**
9214
9215以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9216
9217| **错误码ID** | **错误信息**                                                 |
9218|-----------| ------------------------------------------------------------ |
9219| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9220| 14800000  | Inner error. |
9221| 14800011  | Database corrupted. |
9222| 14800014  | Already closed. |
9223| 14800021  | SQLite: Generic error. |
9224| 14800023  | SQLite: Access permission denied. |
9225| 14800024  | SQLite: The database file is locked. |
9226| 14800025  | SQLite: A table in the database is locked. |
9227| 14800026  | SQLite: The database is out of memory. |
9228| 14800027  | SQLite: Attempt to write a readonly database. |
9229| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9230| 14800029  | SQLite: The database is full. |
9231| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9232| 14800033  | SQLite: Data type mismatch. |
9233| 14800047  | The WAL file size exceeds the default limit. |
9234
9235**示例:**
9236
9237```ts
9238let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
9239predicates.equalTo("NAME", "Lisa");
9240
9241if(store != undefined) {
9242  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9243    transaction.delete(predicates).then((rows: Number) => {
9244      transaction.commit();
9245      console.info(`Delete rows: ${rows}`);
9246    }).catch((e: BusinessError) => {
9247      transaction.rollback();
9248      console.error(`Delete failed, code is ${e.code},message is ${e.message}`);
9249    });
9250  }).catch((err: BusinessError) => {
9251    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9252  });
9253}
9254```
9255
9256### deleteSync<sup>14+</sup>
9257
9258deleteSync(predicates: RdbPredicates): number
9259
9260根据RdbPredicates的指定实例对象从数据库中删除数据。
9261
9262**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9263
9264**参数:**
9265
9266| 参数名     | 类型                            | 必填 | 说明                                    |
9267| ---------- | ------------------------------- | ---- | --------------------------------------- |
9268| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
9269
9270**返回值**:
9271
9272| 类型   | 说明               |
9273| ------ | ------------------ |
9274| number | 返回受影响的行数。 |
9275
9276**错误码:**
9277
9278以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9279
9280| **错误码ID** | **错误信息**                                                 |
9281| ------------ | ------------------------------------------------------------ |
9282| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9283| 14800000  | Inner error. |
9284| 14800011  | Database corrupted. |
9285| 14800014  | Already closed. |
9286| 14800021  | SQLite: Generic error. |
9287| 14800023  | SQLite: Access permission denied. |
9288| 14800024  | SQLite: The database file is locked. |
9289| 14800025  | SQLite: A table in the database is locked. |
9290| 14800026  | SQLite: The database is out of memory. |
9291| 14800027  | SQLite: Attempt to write a readonly database. |
9292| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9293| 14800029  | SQLite: The database is full. |
9294| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9295| 14800033  | SQLite: Data type mismatch. |
9296| 14800047  | The WAL file size exceeds the default limit. |
9297
9298**示例:**
9299
9300```ts
9301let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
9302predicates.equalTo("NAME", "Lisa");
9303
9304if(store != undefined) {
9305  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9306    try {
9307      let rows: Number = (transaction as relationalStore.Transaction).deleteSync(predicates);
9308      transaction.commit();
9309      console.info(`Delete rows: ${rows}`);
9310    } catch (e) {
9311      transaction.rollback();
9312      console.error(`Delete failed, code is ${e.code},message is ${e.message}`);
9313    };
9314  }).catch((err: BusinessError) => {
9315    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9316  });
9317}
9318```
9319
9320### query<sup>14+</sup>
9321
9322query(predicates: RdbPredicates, columns?: Array&lt;string&gt;): Promise&lt;ResultSet&gt;
9323
9324根据指定条件查询数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
9325
9326**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9327
9328**参数:**
9329
9330| 参数名     | 类型                                 | 必填 | 说明                                             |
9331| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
9332| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。        |
9333| columns    | Array&lt;string&gt;                  | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
9334
9335**错误码:**
9336
9337以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
9338
9339| **错误码ID** | **错误信息**                                                 |
9340|-----------| ------------------------------------------------------------ |
9341| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9342| 14800000  | Inner error. |
9343| 14800011  | Database corrupted. |
9344| 14800014  | Already closed. |
9345| 14800021  | SQLite: Generic error. |
9346| 14800023  | SQLite: Access permission denied. |
9347| 14800024  | SQLite: The database file is locked. |
9348| 14800026  | SQLite: The database is out of memory. |
9349| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9350| 14800047  | The WAL file size exceeds the default limit. |
9351
9352**返回值**:
9353
9354| 类型                                                    | 说明                                               |
9355| ------------------------------------------------------- | -------------------------------------------------- |
9356| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
9357
9358**示例:**
9359
9360```ts
9361let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
9362predicates.equalTo("NAME", "Rose");
9363
9364if(store != undefined) {
9365  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9366    transaction.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => {
9367      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
9368      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
9369      while (resultSet.goToNextRow()) {
9370        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
9371        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
9372        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
9373        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
9374        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
9375      }
9376      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
9377      resultSet.close();
9378      transaction.commit();
9379    }).catch((e: BusinessError) => {
9380      transaction.rollback();
9381      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
9382    });
9383  }).catch((err: BusinessError) => {
9384    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9385  });
9386}
9387```
9388
9389### querySync<sup>14+</sup>
9390
9391querySync(predicates: RdbPredicates, columns?: Array&lt;string&gt;): ResultSet
9392
9393根据指定条件查询数据库中的数据。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
9394
9395**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9396
9397**参数:**
9398
9399| 参数名     | 类型                            | 必填 | 说明                                                         |
9400| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ |
9401| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。                      |
9402| columns    | Array&lt;string&gt;             | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。默认值为空。 |
9403
9404**错误码:**
9405
9406以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
9407
9408| **错误码ID** | **错误信息**                                                 |
9409| ------------ | ------------------------------------------------------------ |
9410| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9411| 14800000  | Inner error. |
9412| 14800011  | Database corrupted. |
9413| 14800014  | Already closed. |
9414| 14800021  | SQLite: Generic error. |
9415| 14800023  | SQLite: Access permission denied. |
9416| 14800024  | SQLite: The database file is locked. |
9417| 14800025  | SQLite: A table in the database is locked. |
9418| 14800026  | SQLite: The database is out of memory. |
9419| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9420| 14800047  | The WAL file size exceeds the default limit. |
9421
9422**返回值**:
9423
9424| 类型                    | 说明                                |
9425| ----------------------- | ----------------------------------- |
9426| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
9427
9428**示例:**
9429
9430```ts
9431let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
9432predicates.equalTo("NAME", "Rose");
9433
9434if(store != undefined) {
9435  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9436    try {
9437      let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
9438      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
9439      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
9440      while (resultSet.goToNextRow()) {
9441        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
9442        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
9443        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
9444        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
9445        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
9446      }
9447      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
9448      resultSet.close();
9449      transaction.commit();
9450    } catch (e) {
9451      transaction.rollback();
9452      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
9453    };
9454  }).catch((err: BusinessError) => {
9455    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9456  });
9457}
9458```
9459
9460### querySql<sup>14+</sup>
9461
9462querySql(sql: string, args?: Array&lt;ValueType&gt;): Promise&lt;ResultSet&gt;
9463
9464根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
9465
9466**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9467
9468**参数:**
9469
9470| 参数名   | 类型                                 | 必填 | 说明                                                         |
9471| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
9472| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
9473| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
9474
9475**返回值**:
9476
9477| 类型                                                    | 说明                                               |
9478| ------------------------------------------------------- | -------------------------------------------------- |
9479| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
9480
9481**错误码:**
9482
9483以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
9484
9485| **错误码ID** | **错误信息**                                                 |
9486|-----------| ------------------------------------------------------------ |
9487| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9488| 14800000  | Inner error. |
9489| 14800011  | Database corrupted. |
9490| 14800014  | Already closed. |
9491| 14800021  | SQLite: Generic error. |
9492| 14800023  | SQLite: Access permission denied. |
9493| 14800024  | SQLite: The database file is locked. |
9494| 14800025  | SQLite: A table in the database is locked. |
9495| 14800026  | SQLite: The database is out of memory. |
9496| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9497| 14800047  | The WAL file size exceeds the default limit. |
9498
9499**示例:**
9500
9501```ts
9502if(store != undefined) {
9503  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9504    transaction.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then((resultSet: relationalStore.ResultSet) => {
9505      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
9506      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
9507      while (resultSet.goToNextRow()) {
9508        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
9509        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
9510        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
9511        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
9512        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
9513      }
9514      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
9515      resultSet.close();
9516      transaction.commit();
9517    }).catch((e: BusinessError) => {
9518      transaction.rollback();
9519      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
9520    });
9521  }).catch((err: BusinessError) => {
9522    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9523  });
9524}
9525```
9526
9527### querySqlSync<sup>14+</sup>
9528
9529querySqlSync(sql: string, args?: Array&lt;ValueType&gt;): ResultSet
9530
9531根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
9532
9533**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9534
9535**参数:**
9536
9537| 参数名   | 类型                                 | 必填 | 说明                                                         |
9538| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
9539| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
9540| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。默认值为空。 |
9541
9542**返回值**:
9543
9544| 类型                    | 说明                                |
9545| ----------------------- | ----------------------------------- |
9546| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
9547
9548**错误码:**
9549
9550以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
9551
9552| **错误码ID** | **错误信息**                                                 |
9553| ------------ | ------------------------------------------------------------ |
9554| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9555| 14800000  | Inner error. |
9556| 14800011  | Database corrupted. |
9557| 14800014  | Already closed. |
9558| 14800021  | SQLite: Generic error. |
9559| 14800023  | SQLite: Access permission denied. |
9560| 14800024  | SQLite: The database file is locked. |
9561| 14800025  | SQLite: A table in the database is locked. |
9562| 14800026  | SQLite: The database is out of memory. |
9563| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9564| 14800047  | The WAL file size exceeds the default limit. |
9565
9566**示例:**
9567
9568```ts
9569if(store != undefined) {
9570  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9571    try {
9572      let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'");
9573      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
9574      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
9575      while (resultSet.goToNextRow()) {
9576        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
9577        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
9578        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
9579        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
9580        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
9581      }
9582      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
9583      resultSet.close();
9584      transaction.commit();
9585    } catch (e) {
9586      transaction.rollback();
9587      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
9588    };
9589  }).catch((err: BusinessError) => {
9590    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9591  });
9592}
9593```
9594
9595### execute<sup>14+</sup>
9596
9597execute(sql: string, args?: Array&lt;ValueType&gt;): Promise&lt;ValueType&gt;
9598
9599执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType,使用Promise异步回调。
9600
9601该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
9602
9603此接口不支持执行查询、附加数据库和事务操作,查询可以使用[querySql](#querysql14)、[query](#query14)接口代替、附加数据库可以使用[attach](#attach12)接口代替。
9604
9605不支持分号分隔的多条语句。
9606
9607**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9608
9609**参数:**
9610
9611| 参数名   | 类型                                 | 必填 | 说明                                                         |
9612| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
9613| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
9614| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
9615
9616**返回值**:
9617
9618| 类型                | 说明                      |
9619| ------------------- | ------------------------- |
9620| Promise&lt;[ValueType](#valuetype)&gt; | Promise对象,返回sql执行后的结果。 |
9621
9622**错误码:**
9623
9624以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9625
9626| **错误码ID** | **错误信息**                                                 |
9627|-----------| ------------------------------------------------------------ |
9628| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9629| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
9630| 14800000  | Inner error. |
9631| 14800011  | Database corrupted. |
9632| 14800014  | Already closed. |
9633| 14800021  | SQLite: Generic error. |
9634| 14800023  | SQLite: Access permission denied. |
9635| 14800024  | SQLite: The database file is locked. |
9636| 14800025  | SQLite: A table in the database is locked. |
9637| 14800026  | SQLite: The database is out of memory. |
9638| 14800027  | SQLite: Attempt to write a readonly database. |
9639| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9640| 14800029  | SQLite: The database is full. |
9641| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9642| 14800033  | SQLite: Data type mismatch. |
9643| 14800047  | The WAL file size exceeds the default limit. |
9644
9645**示例:**
9646
9647```ts
9648// 删除表中所有数据
9649if(store != undefined) {
9650  const SQL_DELETE_TABLE = 'DELETE FROM test';
9651  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9652    transaction.execute(SQL_DELETE_TABLE).then((data) => {
9653      transaction.commit();
9654      console.info(`delete result: ${data}`);
9655    }).catch((e: BusinessError) => {
9656      transaction.rollback();
9657      console.error(`delete failed, code is ${e.code}, message is ${e.message}`);
9658    });
9659  }).catch((err: BusinessError) => {
9660    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9661  });
9662}
9663```
9664
9665### executeSync<sup>14+</sup>
9666
9667executeSync(sql: string, args?: Array&lt;ValueType&gt;): ValueType
9668
9669执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType。
9670
9671该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
9672
9673此接口不支持执行查询、附加数据库和事务操作,查询可以使用[querySql](#querysql14)、[query](#query14)接口代替、附加数据库可以使用[attach](#attach12)接口代替。
9674
9675不支持分号分隔的多条语句。
9676
9677**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9678
9679**参数:**
9680
9681| 参数名 | 类型                                 | 必填 | 说明                                                         |
9682| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
9683| sql    | string                               | 是   | 指定要执行的SQL语句。                                        |
9684| args   | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。该参数不填,或者填null或undefined,都认为是sql参数语句完整。默认值为空。 |
9685
9686**返回值**:
9687
9688| 类型                    | 说明                |
9689| ----------------------- | ------------------- |
9690| [ValueType](#valuetype) | 返回sql执行后的结果。 |
9691
9692**错误码:**
9693
9694以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9695
9696| **错误码ID** | **错误信息**                                                 |
9697| ------------ | ------------------------------------------------------------ |
9698| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9699| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
9700| 14800000     | Inner error.                                                 |
9701| 14800011     | Database corrupted.                                          |
9702| 14800014     | Already closed.                                              |
9703| 14800021     | SQLite: Generic error.                                       |
9704| 14800023     | SQLite: Access permission denied.                            |
9705| 14800024     | SQLite: The database file is locked.                         |
9706| 14800025     | SQLite: A table in the database is locked.                   |
9707| 14800026     | SQLite: The database is out of memory.                       |
9708| 14800027     | SQLite: Attempt to write a readonly database.                |
9709| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
9710| 14800029     | SQLite: The database is full.                                |
9711| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
9712| 14800033     | SQLite: Data type mismatch.                                  |
9713| 14800047     | The WAL file size exceeds the default limit.                 |
9714
9715**示例:**
9716
9717```ts
9718// 删除表中所有数据
9719if(store != undefined) {
9720  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9721    const SQL_DELETE_TABLE = 'DELETE FROM test';
9722    try {
9723      let data = (transaction as relationalStore.Transaction).executeSync(SQL_DELETE_TABLE);
9724      transaction.commit();
9725      console.info(`delete result: ${data}`);
9726    } catch (e) {
9727      transaction.rollback();
9728      console.error(`delete failed, code is ${e.code}, message is ${e.message}`);
9729    };
9730  }).catch((err: BusinessError) => {
9731    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9732  });
9733}
9734```