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<sup>10+</sup>](#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<sup>10+</sup>](#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,需要向应用市场获取,暂不支持。<br/>**模型约束:** 此属性仅在Stage模型下可用。<br/>从API version 10开始,支持此可选参数。指定在此dataGroupId对应的沙箱路径下创建RdbStore实例,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
2160// 设置数据库版本
2161if(store != undefined) {
2162  (store as relationalStore.RdbStore).version = 3;
2163  // 获取数据库版本
2164  console.info(`RdbStore version is ${store.version}`);
2165  // 获取数据库是否重建
2166  console.info(`RdbStore rebuilt is ${store.rebuilt}`);
2167}
2168```
2169
2170### insert
2171
2172insert(table: string, values: ValuesBucket, callback: AsyncCallback&lt;number&gt;):void
2173
2174向目标表中插入一行数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2175
2176**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2177
2178**参数:**
2179
2180| 参数名   | 类型                          | 必填 | 说明                                                       |
2181| -------- | ----------------------------- | ---- | ---------------------------------------------------------- |
2182| table    | string                        | 是   | 指定的目标表名。                                           |
2183| values   | [ValuesBucket](#valuesbucket) | 是   | 表示要插入到表中的数据行。                                 |
2184| callback | AsyncCallback&lt;number&gt;   | 是   | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 |
2185
2186**错误码:**
2187
2188以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2189
2190| **错误码ID** | **错误信息**                                                 |
2191|-----------| ------------------------------------------------------------ |
2192| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2193| 14800000  | Inner error. |
2194| 14800011  | Database corrupted. |
2195| 14800014  | Already closed. |
2196| 14800015  | The database does not respond. |
2197| 14800021  | SQLite: Generic error. |
2198| 14800022  | SQLite: Callback routine requested an abort. |
2199| 14800023  | SQLite: Access permission denied. |
2200| 14800024  | SQLite: The database file is locked. |
2201| 14800025  | SQLite: A table in the database is locked. |
2202| 14800026  | SQLite: The database is out of memory. |
2203| 14800027  | SQLite: Attempt to write a readonly database. |
2204| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2205| 14800029  | SQLite: The database is full. |
2206| 14800030  | SQLite: Unable to open the database file. |
2207| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2208| 14800032  | SQLite: Abort due to constraint violation. |
2209| 14800033  | SQLite: Data type mismatch. |
2210| 14800034  | SQLite: Library used incorrectly. |
2211| 14800047  | The WAL file size exceeds the default limit. |
2212
2213**示例:**
2214
2215```ts
2216let value1 = "Lisa";
2217let value2 = 18;
2218let value3 = 100.5;
2219let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2220
2221// 以下三种方式可用
2222const valueBucket1: relationalStore.ValuesBucket = {
2223  'NAME': value1,
2224  'AGE': value2,
2225  'SALARY': value3,
2226  'CODES': value4,
2227};
2228const valueBucket2: relationalStore.ValuesBucket = {
2229  NAME: value1,
2230  AGE: value2,
2231  SALARY: value3,
2232  CODES: value4,
2233};
2234const valueBucket3: relationalStore.ValuesBucket = {
2235  "NAME": value1,
2236  "AGE": value2,
2237  "SALARY": value3,
2238  "CODES": value4,
2239};
2240
2241if(store != undefined) {
2242  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, (err: BusinessError, rowId: number) => {
2243    if (err) {
2244      console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2245      return;
2246    }
2247    console.info(`Insert is successful, rowId = ${rowId}`);
2248  })
2249}
2250```
2251
2252### insert<sup>10+</sup>
2253
2254insert(table: string, values: ValuesBucket,  conflict: ConflictResolution, callback: AsyncCallback&lt;number&gt;):void
2255
2256向目标表中插入一行数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2257
2258**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2259
2260**参数:**
2261
2262| 参数名   | 类型                                        | 必填 | 说明                                                       |
2263| -------- | ------------------------------------------- | ---- | ---------------------------------------------------------- |
2264| table    | string                                      | 是   | 指定的目标表名。                                           |
2265| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。                                 |
2266| conflict | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。                                         |
2267| callback | AsyncCallback&lt;number&gt;                 | 是   | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 |
2268
2269**错误码:**
2270
2271以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2272
2273| **错误码ID** | **错误信息**                                                 |
2274|-----------| ---------------------------------------------------- |
2275| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2276| 14800000  | Inner error. |
2277| 14800011  | Database corrupted. |
2278| 14800014  | Already closed. |
2279| 14800015  | The database does not respond. |
2280| 14800021  | SQLite: Generic error. |
2281| 14800022  | SQLite: Callback routine requested an abort. |
2282| 14800023  | SQLite: Access permission denied. |
2283| 14800024  | SQLite: The database file is locked. |
2284| 14800025  | SQLite: A table in the database is locked. |
2285| 14800026  | SQLite: The database is out of memory. |
2286| 14800027  | SQLite: Attempt to write a readonly database. |
2287| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2288| 14800029  | SQLite: The database is full. |
2289| 14800030  | SQLite: Unable to open the database file. |
2290| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2291| 14800032  | SQLite: Abort due to constraint violation. |
2292| 14800033  | SQLite: Data type mismatch. |
2293| 14800034  | SQLite: Library used incorrectly. |
2294| 14800047  | The WAL file size exceeds the default limit. |
2295
2296**示例:**
2297
2298```ts
2299let value1 = "Lisa";
2300let value2 = 18;
2301let value3 = 100.5;
2302let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2303
2304// 以下三种方式可用
2305const valueBucket1: relationalStore.ValuesBucket = {
2306  'NAME': value1,
2307  'AGE': value2,
2308  'SALARY': value3,
2309  'CODES': value4,
2310};
2311const valueBucket2: relationalStore.ValuesBucket = {
2312  NAME: value1,
2313  AGE: value2,
2314  SALARY: value3,
2315  CODES: value4,
2316};
2317const valueBucket3: relationalStore.ValuesBucket = {
2318  "NAME": value1,
2319  "AGE": value2,
2320  "SALARY": value3,
2321  "CODES": value4,
2322};
2323
2324if(store != undefined) {
2325  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE,
2326    (err: BusinessError, rowId: number) => {
2327      if (err) {
2328        console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2329        return;
2330      }
2331      console.info(`Insert is successful, rowId = ${rowId}`);
2332  })
2333}
2334```
2335
2336### insert
2337
2338insert(table: string, values: ValuesBucket):Promise&lt;number&gt;
2339
2340向目标表中插入一行数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2341
2342**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2343
2344**参数:**
2345
2346| 参数名 | 类型                          | 必填 | 说明                       |
2347| ------ | ----------------------------- | ---- | -------------------------- |
2348| table  | string                        | 是   | 指定的目标表名。           |
2349| values | [ValuesBucket](#valuesbucket) | 是   | 表示要插入到表中的数据行。 |
2350
2351**返回值**:
2352
2353| 类型                  | 说明                                              |
2354| --------------------- | ------------------------------------------------- |
2355| Promise&lt;number&gt; | Promise对象。如果操作成功,返回行ID;否则返回-1。 |
2356
2357**错误码:**
2358
2359以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2360
2361| **错误码ID** | **错误信息**                                                 |
2362|-----------| ------------------------------------------------------------ |
2363| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2364| 14800000  | Inner error. |
2365| 14800011  | Database corrupted. |
2366| 14800014  | Already closed. |
2367| 14800015  | The database does not respond. |
2368| 14800021  | SQLite: Generic error. |
2369| 14800022  | SQLite: Callback routine requested an abort. |
2370| 14800023  | SQLite: Access permission denied. |
2371| 14800024  | SQLite: The database file is locked. |
2372| 14800025  | SQLite: A table in the database is locked. |
2373| 14800026  | SQLite: The database is out of memory. |
2374| 14800027  | SQLite: Attempt to write a readonly database. |
2375| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2376| 14800029  | SQLite: The database is full. |
2377| 14800030  | SQLite: Unable to open the database file. |
2378| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2379| 14800032  | SQLite: Abort due to constraint violation. |
2380| 14800033  | SQLite: Data type mismatch. |
2381| 14800034  | SQLite: Library used incorrectly. |
2382| 14800047  | The WAL file size exceeds the default limit. |
2383
2384**示例:**
2385
2386```ts
2387import { BusinessError } from '@kit.BasicServicesKit';
2388
2389let value1 = "Lisa";
2390let value2 = 18;
2391let value3 = 100.5;
2392let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2393
2394// 以下三种方式可用
2395const valueBucket1: relationalStore.ValuesBucket = {
2396  'NAME': value1,
2397  'AGE': value2,
2398  'SALARY': value3,
2399  'CODES': value4,
2400};
2401const valueBucket2: relationalStore.ValuesBucket = {
2402  NAME: value1,
2403  AGE: value2,
2404  SALARY: value3,
2405  CODES: value4,
2406};
2407const valueBucket3: relationalStore.ValuesBucket = {
2408  "NAME": value1,
2409  "AGE": value2,
2410  "SALARY": value3,
2411  "CODES": value4,
2412};
2413
2414if(store != undefined) {
2415  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1).then((rowId: number) => {
2416    console.info(`Insert is successful, rowId = ${rowId}`);
2417  }).catch((err: BusinessError) => {
2418    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2419  })
2420}
2421```
2422
2423### insert<sup>10+</sup>
2424
2425insert(table: string, values: ValuesBucket,  conflict: ConflictResolution):Promise&lt;number&gt;
2426
2427向目标表中插入一行数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2428
2429**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2430
2431**参数:**
2432
2433| 参数名   | 类型                                        | 必填 | 说明                       |
2434| -------- | ------------------------------------------- | ---- | -------------------------- |
2435| table    | string                                      | 是   | 指定的目标表名。           |
2436| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。 |
2437| conflict | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。         |
2438
2439**返回值**:
2440
2441| 类型                  | 说明                                              |
2442| --------------------- | ------------------------------------------------- |
2443| Promise&lt;number&gt; | Promise对象。如果操作成功,返回行ID;否则返回-1。 |
2444
2445**错误码:**
2446
2447以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2448
2449| **错误码ID** | **错误信息**                                                 |
2450|-----------| ------------------------------------------------------------ |
2451| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2452| 14800000  | Inner error. |
2453| 14800011  | Database corrupted. |
2454| 14800014  | Already closed. |
2455| 14800015  | The database does not respond. |
2456| 14800021  | SQLite: Generic error. |
2457| 14800022  | SQLite: Callback routine requested an abort. |
2458| 14800023  | SQLite: Access permission denied. |
2459| 14800024  | SQLite: The database file is locked. |
2460| 14800025  | SQLite: A table in the database is locked. |
2461| 14800026  | SQLite: The database is out of memory. |
2462| 14800027  | SQLite: Attempt to write a readonly database. |
2463| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2464| 14800029  | SQLite: The database is full. |
2465| 14800030  | SQLite: Unable to open the database file. |
2466| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2467| 14800032  | SQLite: Abort due to constraint violation. |
2468| 14800033  | SQLite: Data type mismatch. |
2469| 14800034  | SQLite: Library used incorrectly. |
2470| 14800047  | The WAL file size exceeds the default limit. |
2471
2472**示例:**
2473
2474```ts
2475import { BusinessError } from '@kit.BasicServicesKit';
2476
2477let value1 = "Lisa";
2478let value2 = 18;
2479let value3 = 100.5;
2480let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2481
2482// 以下三种方式可用
2483const valueBucket1: relationalStore.ValuesBucket = {
2484  'NAME': value1,
2485  'AGE': value2,
2486  'SALARY': value3,
2487  'CODES': value4,
2488};
2489const valueBucket2: relationalStore.ValuesBucket = {
2490  NAME: value1,
2491  AGE: value2,
2492  SALARY: value3,
2493  CODES: value4,
2494};
2495const valueBucket3: relationalStore.ValuesBucket = {
2496  "NAME": value1,
2497  "AGE": value2,
2498  "SALARY": value3,
2499  "CODES": value4,
2500};
2501
2502if(store != undefined) {
2503  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => {
2504    console.info(`Insert is successful, rowId = ${rowId}`);
2505  }).catch((err: BusinessError) => {
2506    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2507  })
2508}
2509```
2510
2511### insertSync<sup>12+</sup>
2512
2513insertSync(table: string, values: ValuesBucket,  conflict?: ConflictResolution):number
2514
2515向目标表中插入一行数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2516
2517**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2518
2519**参数:**
2520
2521| 参数名   | 类型                                        | 必填 | 说明                                                         |
2522| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
2523| table    | string                                      | 是   | 指定的目标表名。                                             |
2524| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。                                   |
2525| conflict | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
2526
2527**返回值**:
2528
2529| 类型   | 说明                                 |
2530| ------ | ------------------------------------ |
2531| number | 如果操作成功,返回行ID;否则返回-1。 |
2532
2533**错误码:**
2534
2535以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2536
2537| **错误码ID** | **错误信息**                                                 |
2538| ------------ | ------------------------------------------------------------ |
2539| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2540| 14800000     | Inner error.                                                 |
2541| 14800011     | Database corrupted.                                          |
2542| 14800014     | Already closed.                                              |
2543| 14800015     | The database does not respond.                                        |
2544| 14800021     | SQLite: Generic error.                                       |
2545| 14800022     | SQLite: Callback routine requested an abort.                 |
2546| 14800023     | SQLite: Access permission denied.                            |
2547| 14800024     | SQLite: The database file is locked.                         |
2548| 14800025     | SQLite: A table in the database is locked.                   |
2549| 14800026     | SQLite: The database is out of memory.                       |
2550| 14800027     | SQLite: Attempt to write a readonly database.                |
2551| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
2552| 14800029     | SQLite: The database is full.                                |
2553| 14800030     | SQLite: Unable to open the database file.                    |
2554| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
2555| 14800032     | SQLite: Abort due to constraint violation.                   |
2556| 14800033     | SQLite: Data type mismatch.                                  |
2557| 14800034     | SQLite: Library used incorrectly.                            |
2558| 14800047     | The WAL file size exceeds the default limit.                 |
2559
2560**示例:**
2561
2562```ts
2563import { BusinessError } from '@kit.BasicServicesKit';
2564
2565let value1 = "Lisa";
2566let value2 = 18;
2567let value3 = 100.5;
2568let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2569
2570// 以下三种方式可用
2571const valueBucket1: relationalStore.ValuesBucket = {
2572  'NAME': value1,
2573  'AGE': value2,
2574  'SALARY': value3,
2575  'CODES': value4,
2576};
2577const valueBucket2: relationalStore.ValuesBucket = {
2578  NAME: value1,
2579  AGE: value2,
2580  SALARY: value3,
2581  CODES: value4,
2582};
2583const valueBucket3: relationalStore.ValuesBucket = {
2584  "NAME": value1,
2585  "AGE": value2,
2586  "SALARY": value3,
2587  "CODES": value4,
2588};
2589
2590if(store != undefined) {
2591  try {
2592    let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
2593    console.info(`Insert is successful, rowId = ${rowId}`);
2594  } catch (error) {
2595      console.error(`Insert is failed, code is ${error.code},message is ${error.message}`);
2596  }
2597}
2598```
2599
2600### insertSync<sup>12+</sup>
2601
2602insertSync(table: string, values: sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution):number
2603
2604传入Sendable数据,向目标表中插入一行数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2605
2606**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2607
2608**参数:**
2609
2610| 参数名   | 类型                                                                                           | 必填 | 说明                                                                            |
2611| -------- | ---------------------------------------------------------------------------------------------- | ---- | ------------------------------------------------------------------------------- |
2612| table    | string                                                                                         | 是   | 指定的目标表名。                                                                |
2613| values   | [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | 是   | 表示要插入到表中的可跨线程传递数据。                                            |
2614| conflict | [ConflictResolution](#conflictresolution10)                                                    | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
2615
2616**返回值**:
2617
2618| 类型   | 说明                                 |
2619| ------ | ------------------------------------ |
2620| number | 如果操作成功,返回行ID;否则返回-1。 |
2621
2622**错误码:**
2623
2624以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2625
2626| **错误码ID** | **错误信息**                                                 |
2627| ------------ | ------------------------------------------------------------ |
2628| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2629| 14800000     | Inner error.                                                 |
2630| 14800011     | Database corrupted.                                          |
2631| 14800014     | Already closed.                                              |
2632| 14800015     | The database does not respond.                                        |
2633| 14800021     | SQLite: Generic error.                                       |
2634| 14800022     | SQLite: Callback routine requested an abort.                 |
2635| 14800023     | SQLite: Access permission denied.                            |
2636| 14800024     | SQLite: The database file is locked.                         |
2637| 14800025     | SQLite: A table in the database is locked.                   |
2638| 14800026     | SQLite: The database is out of memory.                       |
2639| 14800027     | SQLite: Attempt to write a readonly database.                |
2640| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
2641| 14800029     | SQLite: The database is full.                                |
2642| 14800030     | SQLite: Unable to open the database file.                    |
2643| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
2644| 14800032     | SQLite: Abort due to constraint violation.                   |
2645| 14800033     | SQLite: Data type mismatch.                                  |
2646| 14800034     | SQLite: Library used incorrectly.                            |
2647| 14800047     | The WAL file size exceeds the default limit.                 |
2648
2649**示例:**
2650
2651```ts
2652import { sendableRelationalStore } from '@kit.ArkData';
2653
2654const valuesBucket: relationalStore.ValuesBucket = {
2655  "NAME": 'hangman',
2656  "AGE": 18,
2657  "SALARY": 100.5,
2658  "CODES": new Uint8Array([1,2,3]),
2659};
2660const sendableValuesBucket = sendableRelationalStore.toSendableValuesBucket(valuesBucket);
2661
2662if(store != undefined) {
2663  try {
2664    let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", sendableValuesBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
2665    console.info(`Insert is successful, rowId = ${rowId}`);
2666  } catch (error) {
2667    console.error(`Insert is failed, code is ${error.code},message is ${error.message}`);
2668  }
2669}
2670```
2671
2672### batchInsert
2673
2674batchInsert(table: string, values: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;):void
2675
2676向目标表中插入一组数据,使用callback异步回调。
2677
2678**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2679
2680**参数:**
2681
2682| 参数名   | 类型                                       | 必填 | 说明                                                         |
2683| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
2684| table    | string                                     | 是   | 指定的目标表名。                                             |
2685| values   | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。             |
2686| callback | AsyncCallback&lt;number&gt;                | 是   | 指定callback回调函数。如果操作成功,返回插入的数据个数,否则返回-1。 |
2687
2688**错误码:**
2689
2690以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2691
2692| **错误码ID** | **错误信息**                                                 |
2693|-----------| ------------------------------------------------------------ |
2694| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2695| 14800000  | Inner error. |
2696| 14800011  | Database corrupted. |
2697| 14800014  | Already closed. |
2698| 14800015  | The database does not respond. |
2699| 14800021  | SQLite: Generic error. |
2700| 14800022  | SQLite: Callback routine requested an abort. |
2701| 14800023  | SQLite: Access permission denied. |
2702| 14800024  | SQLite: The database file is locked. |
2703| 14800025  | SQLite: A table in the database is locked. |
2704| 14800026  | SQLite: The database is out of memory. |
2705| 14800027  | SQLite: Attempt to write a readonly database. |
2706| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2707| 14800029  | SQLite: The database is full. |
2708| 14800030  | SQLite: Unable to open the database file. |
2709| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2710| 14800032  | SQLite: Abort due to constraint violation. |
2711| 14800033  | SQLite: Data type mismatch. |
2712| 14800034  | SQLite: Library used incorrectly. |
2713| 14800047  | The WAL file size exceeds the default limit. |
2714
2715**示例:**
2716
2717```ts
2718
2719let value1 = "Lisa";
2720let value2 = 18;
2721let value3 = 100.5;
2722let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2723let value5 = "Jack";
2724let value6 = 19;
2725let value7 = 101.5;
2726let value8 = new Uint8Array([6, 7, 8, 9, 10]);
2727let value9 = "Tom";
2728let value10 = 20;
2729let value11 = 102.5;
2730let value12 = new Uint8Array([11, 12, 13, 14, 15]);
2731
2732const valueBucket1: relationalStore.ValuesBucket = {
2733  'NAME': value1,
2734  'AGE': value2,
2735  'SALARY': value3,
2736  'CODES': value4,
2737};
2738const valueBucket2: relationalStore.ValuesBucket = {
2739  'NAME': value5,
2740  'AGE': value6,
2741  'SALARY': value7,
2742  'CODES': value8,
2743};
2744const valueBucket3: relationalStore.ValuesBucket = {
2745  'NAME': value9,
2746  'AGE': value10,
2747  'SALARY': value11,
2748  'CODES': value12,
2749};
2750
2751let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
2752if(store != undefined) {
2753  (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets, (err, insertNum) => {
2754    if (err) {
2755      console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
2756      return;
2757    }
2758    console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
2759  })
2760}
2761```
2762
2763### batchInsert
2764
2765batchInsert(table: string, values: Array&lt;ValuesBucket&gt;):Promise&lt;number&gt;
2766
2767向目标表中插入一组数据,使用Promise异步回调。
2768
2769**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2770
2771**参数:**
2772
2773| 参数名 | 类型                                       | 必填 | 说明                         |
2774| ------ | ------------------------------------------ | ---- | ---------------------------- |
2775| table  | string                                     | 是   | 指定的目标表名。             |
2776| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。|
2777
2778**返回值**:
2779
2780| 类型                  | 说明                                                        |
2781| --------------------- | ----------------------------------------------------------- |
2782| Promise&lt;number&gt; | Promise对象。如果操作成功,返回插入的数据个数,否则返回-1。 |
2783
2784**错误码:**
2785
2786以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2787
2788| **错误码ID** | **错误信息**                                                 |
2789|-----------| ------------------------------------------------------------ |
2790| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2791| 14800000  | Inner error. |
2792| 14800011  | Database corrupted. |
2793| 14800014  | Already closed. |
2794| 14800015  | The database does not respond. |
2795| 14800021  | SQLite: Generic error. |
2796| 14800022  | SQLite: Callback routine requested an abort. |
2797| 14800023  | SQLite: Access permission denied. |
2798| 14800024  | SQLite: The database file is locked. |
2799| 14800025  | SQLite: A table in the database is locked. |
2800| 14800026  | SQLite: The database is out of memory. |
2801| 14800027  | SQLite: Attempt to write a readonly database. |
2802| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2803| 14800029  | SQLite: The database is full. |
2804| 14800030  | SQLite: Unable to open the database file. |
2805| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2806| 14800032  | SQLite: Abort due to constraint violation. |
2807| 14800033  | SQLite: Data type mismatch. |
2808| 14800034  | SQLite: Library used incorrectly. |
2809| 14800047  | The WAL file size exceeds the default limit. |
2810
2811**示例:**
2812
2813```ts
2814import { BusinessError } from '@kit.BasicServicesKit';
2815
2816let value1 = "Lisa";
2817let value2 = 18;
2818let value3 = 100.5;
2819let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2820let value5 = "Jack";
2821let value6 = 19;
2822let value7 = 101.5;
2823let value8 = new Uint8Array([6, 7, 8, 9, 10]);
2824let value9 = "Tom";
2825let value10 = 20;
2826let value11 = 102.5;
2827let value12 = new Uint8Array([11, 12, 13, 14, 15]);
2828
2829const valueBucket1: relationalStore.ValuesBucket = {
2830  'NAME': value1,
2831  'AGE': value2,
2832  'SALARY': value3,
2833  'CODES': value4,
2834};
2835const valueBucket2: relationalStore.ValuesBucket = {
2836  'NAME': value5,
2837  'AGE': value6,
2838  'SALARY': value7,
2839  'CODES': value8,
2840};
2841const valueBucket3: relationalStore.ValuesBucket = {
2842  'NAME': value9,
2843  'AGE': value10,
2844  'SALARY': value11,
2845  'CODES': value12,
2846};
2847
2848let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
2849if(store != undefined) {
2850  (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => {
2851    console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
2852  }).catch((err: BusinessError) => {
2853    console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
2854  })
2855}
2856```
2857
2858### batchInsertSync<sup>12+</sup>
2859
2860batchInsertSync(table: string, values: Array&lt;ValuesBucket&gt;):number
2861
2862向目标表中插入一组数据。
2863
2864**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2865
2866**参数:**
2867
2868| 参数名 | 类型                                       | 必填 | 说明                         |
2869| ------ | ------------------------------------------ | ---- | ---------------------------- |
2870| table  | string                                     | 是   | 指定的目标表名。             |
2871| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。 |
2872
2873**返回值**:
2874
2875| 类型   | 说明                                           |
2876| ------ | ---------------------------------------------- |
2877| number | 如果操作成功,返回插入的数据个数,否则返回-1。 |
2878
2879**错误码:**
2880
2881以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2882
2883| **错误码ID** | **错误信息**                                                 |
2884| ------------ | ------------------------------------------------------------ |
2885| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2886| 14800000     | Inner error.                                                 |
2887| 14800011     | Database corrupted.                                          |
2888| 14800014     | Already closed.                                              |
2889| 14800015     | The database does not respond.                                        |
2890| 14800021     | SQLite: Generic error.                                       |
2891| 14800022     | SQLite: Callback routine requested an abort.                 |
2892| 14800023     | SQLite: Access permission denied.                            |
2893| 14800024     | SQLite: The database file is locked.                         |
2894| 14800025     | SQLite: A table in the database is locked.                   |
2895| 14800026     | SQLite: The database is out of memory.                       |
2896| 14800027     | SQLite: Attempt to write a readonly database.                |
2897| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
2898| 14800029     | SQLite: The database is full.                                |
2899| 14800030     | SQLite: Unable to open the database file.                    |
2900| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
2901| 14800032     | SQLite: Abort due to constraint violation.                   |
2902| 14800033     | SQLite: Data type mismatch.                                  |
2903| 14800034     | SQLite: Library used incorrectly.                            |
2904| 14800047     | The WAL file size exceeds the default limit.                 |
2905
2906**示例:**
2907
2908```ts
2909import { BusinessError } from '@kit.BasicServicesKit';
2910
2911let value1 = "Lisa";
2912let value2 = 18;
2913let value3 = 100.5;
2914let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2915let value5 = "Jack";
2916let value6 = 19;
2917let value7 = 101.5;
2918let value8 = new Uint8Array([6, 7, 8, 9, 10]);
2919let value9 = "Tom";
2920let value10 = 20;
2921let value11 = 102.5;
2922let value12 = new Uint8Array([11, 12, 13, 14, 15]);
2923
2924const valueBucket1: relationalStore.ValuesBucket = {
2925  'NAME': value1,
2926  'AGE': value2,
2927  'SALARY': value3,
2928  'CODES': value4,
2929};
2930const valueBucket2: relationalStore.ValuesBucket = {
2931  'NAME': value5,
2932  'AGE': value6,
2933  'SALARY': value7,
2934  'CODES': value8,
2935};
2936const valueBucket3: relationalStore.ValuesBucket = {
2937  'NAME': value9,
2938  'AGE': value10,
2939  'SALARY': value11,
2940  'CODES': value12,
2941};
2942
2943let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
2944if(store != undefined) {
2945  try {
2946    let insertNum: number = (store as relationalStore.RdbStore).batchInsertSync("EMPLOYEE", valueBuckets);
2947    console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
2948  } catch (err) {
2949      console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
2950  }
2951}
2952```
2953
2954### update
2955
2956update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
2957
2958根据RdbPredicates的指定实例对象更新数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2959
2960**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2961
2962**参数:**
2963
2964| 参数名     | 类型                                 | 必填 | 说明                                                         |
2965| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
2966| values     | [ValuesBucket](#valuesbucket)        | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
2967| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的更新条件。                    |
2968| callback   | AsyncCallback&lt;number&gt;          | 是   | 指定的callback回调方法。返回受影响的行数。                   |
2969
2970**错误码:**
2971
2972以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2973
2974| **错误码ID** | **错误信息**                                                 |
2975|-----------| ------------------------------------------------------------ |
2976| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2977| 14800000  | Inner error. |
2978| 14800011  | Database corrupted. |
2979| 14800014  | Already closed. |
2980| 14800015  | The database does not respond. |
2981| 14800021  | SQLite: Generic error. |
2982| 14800022  | SQLite: Callback routine requested an abort. |
2983| 14800023  | SQLite: Access permission denied. |
2984| 14800024  | SQLite: The database file is locked. |
2985| 14800025  | SQLite: A table in the database is locked. |
2986| 14800026  | SQLite: The database is out of memory. |
2987| 14800027  | SQLite: Attempt to write a readonly database. |
2988| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2989| 14800029  | SQLite: The database is full. |
2990| 14800030  | SQLite: Unable to open the database file. |
2991| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2992| 14800032  | SQLite: Abort due to constraint violation. |
2993| 14800033  | SQLite: Data type mismatch. |
2994| 14800034  | SQLite: Library used incorrectly. |
2995| 14800047  | The WAL file size exceeds the default limit. |
2996
2997**示例:**
2998
2999```ts
3000
3001let value1 = "Rose";
3002let value2 = 22;
3003let value3 = 200.5;
3004let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3005
3006// 以下三种方式可用
3007const valueBucket1: relationalStore.ValuesBucket = {
3008  'NAME': value1,
3009  'AGE': value2,
3010  'SALARY': value3,
3011  'CODES': value4,
3012};
3013const valueBucket2: relationalStore.ValuesBucket = {
3014  NAME: value1,
3015  AGE: value2,
3016  SALARY: value3,
3017  CODES: value4,
3018};
3019const valueBucket3: relationalStore.ValuesBucket = {
3020  "NAME": value1,
3021  "AGE": value2,
3022  "SALARY": value3,
3023  "CODES": value4,
3024};
3025
3026let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3027predicates.equalTo("NAME", "Lisa");
3028if(store != undefined) {
3029  (store as relationalStore.RdbStore).update(valueBucket1, predicates,(err, rows) => {
3030    if (err) {
3031      console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3032      return;
3033    }
3034    console.info(`Updated row count: ${rows}`);
3035  })
3036}
3037```
3038
3039### update<sup>10+</sup>
3040
3041update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution, callback: AsyncCallback&lt;number&gt;):void
3042
3043根据RdbPredicates的指定实例对象更新数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3044
3045**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3046
3047**参数:**
3048
3049| 参数名     | 类型                                        | 必填 | 说明                                                         |
3050| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
3051| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3052| predicates | [RdbPredicates](#rdbpredicates)            | 是   | RdbPredicates的实例对象指定的更新条件。                      |
3053| conflict   | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。                                           |
3054| callback   | AsyncCallback&lt;number&gt;                 | 是   | 指定的callback回调方法。返回受影响的行数。                   |
3055
3056**错误码:**
3057
3058以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3059
3060| **错误码ID** | **错误信息**                                                 |
3061|-----------| ------------------------------------------------------------ |
3062| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3063| 14800000  | Inner error. |
3064| 14800011  | Database corrupted. |
3065| 14800014  | Already closed. |
3066| 14800015  | The database does not respond. |
3067| 14800021  | SQLite: Generic error. |
3068| 14800022  | SQLite: Callback routine requested an abort. |
3069| 14800023  | SQLite: Access permission denied. |
3070| 14800024  | SQLite: The database file is locked. |
3071| 14800025  | SQLite: A table in the database is locked. |
3072| 14800026  | SQLite: The database is out of memory. |
3073| 14800027  | SQLite: Attempt to write a readonly database. |
3074| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3075| 14800029  | SQLite: The database is full. |
3076| 14800030  | SQLite: Unable to open the database file. |
3077| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3078| 14800032  | SQLite: Abort due to constraint violation. |
3079| 14800033  | SQLite: Data type mismatch. |
3080| 14800034  | SQLite: Library used incorrectly. |
3081| 14800047  | The WAL file size exceeds the default limit. |
3082
3083**示例:**
3084
3085```ts
3086
3087let value1 = "Rose";
3088let value2 = 22;
3089let value3 = 200.5;
3090let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3091
3092// 以下三种方式可用
3093const valueBucket1: relationalStore.ValuesBucket = {
3094  'NAME': value1,
3095  'AGE': value2,
3096  'SALARY': value3,
3097  'CODES': value4,
3098};
3099const valueBucket2: relationalStore.ValuesBucket = {
3100  NAME: value1,
3101  AGE: value2,
3102  SALARY: value3,
3103  CODES: value4,
3104};
3105const valueBucket3: relationalStore.ValuesBucket = {
3106  "NAME": value1,
3107  "AGE": value2,
3108  "SALARY": value3,
3109  "CODES": value4,
3110};
3111
3112let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3113predicates.equalTo("NAME", "Lisa");
3114if(store != undefined) {
3115  (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, (err, rows) => {
3116    if (err) {
3117      console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3118      return;
3119    }
3120    console.info(`Updated row count: ${rows}`);
3121  })
3122}
3123```
3124
3125### update
3126
3127update(values: ValuesBucket, predicates: RdbPredicates):Promise&lt;number&gt;
3128
3129根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3130
3131**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3132
3133**参数:**
3134
3135| 参数名       | 类型                                 | 必填 | 说明                                                         |
3136| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
3137| values       | [ValuesBucket](#valuesbucket)        | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3138| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的更新条件。                    |
3139
3140**返回值**:
3141
3142| 类型                  | 说明                                      |
3143| --------------------- | ----------------------------------------- |
3144| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |
3145
3146**错误码:**
3147
3148以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3149
3150| **错误码ID** | **错误信息**                                                 |
3151|-----------| ------------------------------------------------------------ |
3152| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3153| 14800000  | Inner error. |
3154| 14800011  | Database corrupted. |
3155| 14800014  | Already closed. |
3156| 14800015  | The database does not respond. |
3157| 14800021  | SQLite: Generic error. |
3158| 14800022  | SQLite: Callback routine requested an abort. |
3159| 14800023  | SQLite: Access permission denied. |
3160| 14800024  | SQLite: The database file is locked. |
3161| 14800025  | SQLite: A table in the database is locked. |
3162| 14800026  | SQLite: The database is out of memory. |
3163| 14800027  | SQLite: Attempt to write a readonly database. |
3164| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3165| 14800029  | SQLite: The database is full. |
3166| 14800030  | SQLite: Unable to open the database file. |
3167| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3168| 14800032  | SQLite: Abort due to constraint violation. |
3169| 14800033  | SQLite: Data type mismatch. |
3170| 14800034  | SQLite: Library used incorrectly. |
3171| 14800047  | The WAL file size exceeds the default limit. |
3172
3173**示例:**
3174
3175```ts
3176import { BusinessError } from '@kit.BasicServicesKit';
3177
3178let value1 = "Rose";
3179let value2 = 22;
3180let value3 = 200.5;
3181let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3182
3183// 以下三种方式可用
3184const valueBucket1: relationalStore.ValuesBucket = {
3185  'NAME': value1,
3186  'AGE': value2,
3187  'SALARY': value3,
3188  'CODES': value4,
3189};
3190const valueBucket2: relationalStore.ValuesBucket = {
3191  NAME: value1,
3192  AGE: value2,
3193  SALARY: value3,
3194  CODES: value4,
3195};
3196const valueBucket3: relationalStore.ValuesBucket = {
3197  "NAME": value1,
3198  "AGE": value2,
3199  "SALARY": value3,
3200  "CODES": value4,
3201};
3202
3203let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3204predicates.equalTo("NAME", "Lisa");
3205if(store != undefined) {
3206  (store as relationalStore.RdbStore).update(valueBucket1, predicates).then(async (rows: Number) => {
3207    console.info(`Updated row count: ${rows}`);
3208  }).catch((err: BusinessError) => {
3209    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3210  })
3211}
3212```
3213
3214### update<sup>10+</sup>
3215
3216update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution):Promise&lt;number&gt;
3217
3218根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3219
3220**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3221
3222**参数:**
3223
3224| 参数名     | 类型                                        | 必填 | 说明                                                         |
3225| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
3226| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3227| predicates | [RdbPredicates](#rdbpredicates)            | 是   | RdbPredicates的实例对象指定的更新条件。                      |
3228| conflict   | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。                                           |
3229
3230**返回值**:
3231
3232| 类型                  | 说明                                      |
3233| --------------------- | ----------------------------------------- |
3234| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |
3235
3236**错误码:**
3237
3238以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3239
3240| **错误码ID** | **错误信息**                                                 |
3241|-----------| ------------------------------------------------------------ |
3242| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3243| 14800000  | Inner error. |
3244| 14800011  | Database corrupted. |
3245| 14800014  | Already closed. |
3246| 14800015  | The database does not respond. |
3247| 14800021  | SQLite: Generic error. |
3248| 14800022  | SQLite: Callback routine requested an abort. |
3249| 14800023  | SQLite: Access permission denied. |
3250| 14800024  | SQLite: The database file is locked. |
3251| 14800025  | SQLite: A table in the database is locked. |
3252| 14800026  | SQLite: The database is out of memory. |
3253| 14800027  | SQLite: Attempt to write a readonly database. |
3254| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3255| 14800029  | SQLite: The database is full. |
3256| 14800030  | SQLite: Unable to open the database file. |
3257| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3258| 14800032  | SQLite: Abort due to constraint violation. |
3259| 14800033  | SQLite: Data type mismatch. |
3260| 14800034  | SQLite: Library used incorrectly. |
3261| 14800047  | The WAL file size exceeds the default limit. |
3262
3263**示例:**
3264
3265```ts
3266import { BusinessError } from '@kit.BasicServicesKit';
3267
3268let value1 = "Rose";
3269let value2 = 22;
3270let value3 = 200.5;
3271let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3272
3273// 以下三种方式可用
3274const valueBucket1: relationalStore.ValuesBucket = {
3275  'NAME': value1,
3276  'AGE': value2,
3277  'SALARY': value3,
3278  'CODES': value4,
3279};
3280const valueBucket2: relationalStore.ValuesBucket = {
3281  NAME: value1,
3282  AGE: value2,
3283  SALARY: value3,
3284  CODES: value4,
3285};
3286const valueBucket3: relationalStore.ValuesBucket = {
3287  "NAME": value1,
3288  "AGE": value2,
3289  "SALARY": value3,
3290  "CODES": value4,
3291};
3292
3293let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3294predicates.equalTo("NAME", "Lisa");
3295if(store != undefined) {
3296  (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => {
3297    console.info(`Updated row count: ${rows}`);
3298  }).catch((err: BusinessError) => {
3299    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3300  })
3301}
3302```
3303
3304### updateSync<sup>12+</sup>
3305
3306updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution):number
3307
3308根据RdbPredicates的指定实例对象更新数据库中的数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3309
3310**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3311
3312**参数:**
3313
3314| 参数名     | 类型                                        | 必填 | 说明                                                         |
3315| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
3316| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3317| predicates | [RdbPredicates](#rdbpredicates)             | 是   | RdbPredicates的实例对象指定的更新条件。                      |
3318| conflict   | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
3319
3320**返回值**:
3321
3322| 类型   | 说明               |
3323| ------ | ------------------ |
3324| number | 返回受影响的行数。 |
3325
3326**错误码:**
3327
3328以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3329
3330| **错误码ID** | **错误信息**                                                 |
3331| ------------ | ------------------------------------------------------------ |
3332| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3333| 14800000     | Inner error.                                                 |
3334| 14800011     | Database corrupted.                                          |
3335| 14800014     | Already closed.                                              |
3336| 14800015     | The database does not respond.                                        |
3337| 14800021     | SQLite: Generic error.                                       |
3338| 14800022     | SQLite: Callback routine requested an abort.                 |
3339| 14800023     | SQLite: Access permission denied.                            |
3340| 14800024     | SQLite: The database file is locked.                         |
3341| 14800025     | SQLite: A table in the database is locked.                   |
3342| 14800026     | SQLite: The database is out of memory.                       |
3343| 14800027     | SQLite: Attempt to write a readonly database.                |
3344| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
3345| 14800029     | SQLite: The database is full.                                |
3346| 14800030     | SQLite: Unable to open the database file.                    |
3347| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
3348| 14800032     | SQLite: Abort due to constraint violation.                   |
3349| 14800033     | SQLite: Data type mismatch.                                  |
3350| 14800034     | SQLite: Library used incorrectly.                            |
3351| 14800047     | The WAL file size exceeds the default limit.                 |
3352
3353**示例:**
3354
3355```ts
3356import { BusinessError } from '@kit.BasicServicesKit';
3357
3358let value1 = "Rose";
3359let value2 = 22;
3360let value3 = 200.5;
3361let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3362
3363// 以下三种方式可用
3364const valueBucket1: relationalStore.ValuesBucket = {
3365  'NAME': value1,
3366  'AGE': value2,
3367  'SALARY': value3,
3368  'CODES': value4,
3369};
3370const valueBucket2: relationalStore.ValuesBucket = {
3371  NAME: value1,
3372  AGE: value2,
3373  SALARY: value3,
3374  CODES: value4,
3375};
3376const valueBucket3: relationalStore.ValuesBucket = {
3377  "NAME": value1,
3378  "AGE": value2,
3379  "SALARY": value3,
3380  "CODES": value4,
3381};
3382
3383let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3384predicates.equalTo("NAME", "Lisa");
3385if(store != undefined) {
3386  try {
3387    let rows: Number = (store as relationalStore.RdbStore).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
3388    console.info(`Updated row count: ${rows}`);
3389  } catch (error) {
3390    console.error(`Updated failed, code is ${error.code},message is ${error.message}`);
3391  }
3392}
3393```
3394
3395### delete
3396
3397delete(predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
3398
3399根据RdbPredicates的指定实例对象从数据库中删除数据,使用callback异步回调。
3400
3401**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3402
3403**参数:**
3404
3405| 参数名     | 类型                                 | 必填 | 说明                                      |
3406| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
3407| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
3408| callback   | AsyncCallback&lt;number&gt;          | 是   | 指定callback回调函数。返回受影响的行数。  |
3409
3410**错误码:**
3411
3412以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3413
3414| **错误码ID** | **错误信息**                                                 |
3415|-----------| ------------------------------------------------------------ |
3416| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3417| 14800000  | Inner error. |
3418| 14800011  | Database corrupted. |
3419| 14800014  | Already closed. |
3420| 14800015  | The database does not respond. |
3421| 14800021  | SQLite: Generic error. |
3422| 14800022  | SQLite: Callback routine requested an abort. |
3423| 14800023  | SQLite: Access permission denied. |
3424| 14800024  | SQLite: The database file is locked. |
3425| 14800025  | SQLite: A table in the database is locked. |
3426| 14800026  | SQLite: The database is out of memory. |
3427| 14800027  | SQLite: Attempt to write a readonly database. |
3428| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3429| 14800029  | SQLite: The database is full. |
3430| 14800030  | SQLite: Unable to open the database file. |
3431| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3432| 14800032  | SQLite: Abort due to constraint violation. |
3433| 14800033  | SQLite: Data type mismatch. |
3434| 14800034  | SQLite: Library used incorrectly. |
3435| 14800047  | The WAL file size exceeds the default limit. |
3436
3437**示例:**
3438
3439```ts
3440let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3441predicates.equalTo("NAME", "Lisa");
3442if(store != undefined) {
3443  (store as relationalStore.RdbStore).delete(predicates, (err, rows) => {
3444    if (err) {
3445      console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
3446      return;
3447    }
3448    console.info(`Delete rows: ${rows}`);
3449  })
3450}
3451```
3452
3453### delete
3454
3455delete(predicates: RdbPredicates):Promise&lt;number&gt;
3456
3457根据RdbPredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。
3458
3459**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3460
3461**参数:**
3462
3463| 参数名     | 类型                                 | 必填 | 说明                                      |
3464| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
3465| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
3466
3467**返回值**:
3468
3469| 类型                  | 说明                            |
3470| --------------------- | ------------------------------- |
3471| Promise&lt;number&gt; | Promise对象。返回受影响的行数。 |
3472
3473**错误码:**
3474
3475以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3476
3477| **错误码ID** | **错误信息**                                                 |
3478|-----------| ------------------------------------------------------------ |
3479| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3480| 14800000  | Inner error. |
3481| 14800011  | Database corrupted. |
3482| 14800014  | Already closed. |
3483| 14800015  | The database does not respond. |
3484| 14800021  | SQLite: Generic error. |
3485| 14800022  | SQLite: Callback routine requested an abort. |
3486| 14800023  | SQLite: Access permission denied. |
3487| 14800024  | SQLite: The database file is locked. |
3488| 14800025  | SQLite: A table in the database is locked. |
3489| 14800026  | SQLite: The database is out of memory. |
3490| 14800027  | SQLite: Attempt to write a readonly database. |
3491| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3492| 14800029  | SQLite: The database is full. |
3493| 14800030  | SQLite: Unable to open the database file. |
3494| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3495| 14800032  | SQLite: Abort due to constraint violation. |
3496| 14800033  | SQLite: Data type mismatch. |
3497| 14800034  | SQLite: Library used incorrectly. |
3498| 14800047  | The WAL file size exceeds the default limit. |
3499
3500**示例:**
3501
3502```ts
3503import { BusinessError } from '@kit.BasicServicesKit';
3504
3505let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3506predicates.equalTo("NAME", "Lisa");
3507if(store != undefined) {
3508  (store as relationalStore.RdbStore).delete(predicates).then((rows: Number) => {
3509    console.info(`Delete rows: ${rows}`);
3510  }).catch((err: BusinessError) => {
3511    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
3512  })
3513}
3514```
3515
3516### deleteSync<sup>12+</sup>
3517
3518deleteSync(predicates: RdbPredicates):number
3519
3520根据RdbPredicates的指定实例对象从数据库中删除数据。
3521
3522**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3523
3524**参数:**
3525
3526| 参数名     | 类型                            | 必填 | 说明                                    |
3527| ---------- | ------------------------------- | ---- | --------------------------------------- |
3528| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
3529
3530**返回值**:
3531
3532| 类型   | 说明               |
3533| ------ | ------------------ |
3534| number | 返回受影响的行数。 |
3535
3536**错误码:**
3537
3538以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3539
3540| **错误码ID** | **错误信息**                                                 |
3541| ------------ | ------------------------------------------------------------ |
3542| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3543| 14800000     | Inner error.                                                 |
3544| 14800011     | Database corrupted.                                          |
3545| 14800014     | Already closed.                                              |
3546| 14800015     | The database does not respond.                                        |
3547| 14800021     | SQLite: Generic error.                                       |
3548| 14800022     | SQLite: Callback routine requested an abort.                 |
3549| 14800023     | SQLite: Access permission denied.                            |
3550| 14800024     | SQLite: The database file is locked.                         |
3551| 14800025     | SQLite: A table in the database is locked.                   |
3552| 14800026     | SQLite: The database is out of memory.                       |
3553| 14800027     | SQLite: Attempt to write a readonly database.                |
3554| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
3555| 14800029     | SQLite: The database is full.                                |
3556| 14800030     | SQLite: Unable to open the database file.                    |
3557| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
3558| 14800032     | SQLite: Abort due to constraint violation.                   |
3559| 14800033     | SQLite: Data type mismatch.                                  |
3560| 14800034     | SQLite: Library used incorrectly.                            |
3561| 14800047     | The WAL file size exceeds the default limit.                 |
3562
3563**示例:**
3564
3565```ts
3566import { BusinessError } from '@kit.BasicServicesKit';
3567
3568let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3569predicates.equalTo("NAME", "Lisa");
3570if(store != undefined) {
3571  try {
3572    let rows: Number = (store as relationalStore.RdbStore).deleteSync(predicates)
3573    console.info(`Delete rows: ${rows}`);
3574  } catch (err) {
3575    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
3576  }
3577}
3578```
3579
3580### query<sup>10+</sup>
3581
3582query(predicates: RdbPredicates, callback: AsyncCallback&lt;ResultSet&gt;):void
3583
3584根据指定条件查询数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3585
3586**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3587
3588**参数:**
3589
3590| 参数名     | 类型                                                         | 必填 | 说明                                                        |
3591| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
3592| predicates | [RdbPredicates](#rdbpredicates)                         | 是   | RdbPredicates的实例对象指定的查询条件。                   |
3593| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
3594
3595**错误码:**
3596
3597以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3598
3599| **错误码ID** | **错误信息**                                                 |
3600|-----------| ------------------------------------------------------------ |
3601| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3602| 14800000  | Inner error. |
3603| 14800014  | Already closed. |
3604| 14800015  | The database does not respond. |
3605
3606**示例:**
3607
3608```ts
3609let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3610predicates.equalTo("NAME", "Rose");
3611if(store != undefined) {
3612  (store as relationalStore.RdbStore).query(predicates, (err, resultSet) => {
3613    if (err) {
3614      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
3615      return;
3616    }
3617    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3618    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3619    while (resultSet.goToNextRow()) {
3620      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3621      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3622      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3623      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3624      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3625    }
3626    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3627    resultSet.close();
3628  })
3629}
3630```
3631
3632### query
3633
3634query(predicates: RdbPredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
3635
3636根据指定条件查询数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3637
3638**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3639
3640**参数:**
3641
3642| 参数名     | 类型                                                         | 必填 | 说明                                                        |
3643| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
3644| predicates | [RdbPredicates](#rdbpredicates)                         | 是   | RdbPredicates的实例对象指定的查询条件。                   |
3645| columns    | Array&lt;string&gt;                                          | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。            |
3646| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
3647
3648**错误码:**
3649
3650以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3651
3652| **错误码ID** | **错误信息**                                                 |
3653|-----------| ------------------------------------------------------------ |
3654| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3655| 14800000  | Inner error. |
3656| 14800014  | Already closed. |
3657| 14800015  | The database does not respond. |
3658
3659**示例:**
3660
3661```ts
3662let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3663predicates.equalTo("NAME", "Rose");
3664if(store != undefined) {
3665  (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], (err, resultSet) => {
3666    if (err) {
3667      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
3668      return;
3669    }
3670    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3671    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3672    while (resultSet.goToNextRow()) {
3673      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3674      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3675      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3676      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3677      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3678    }
3679    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3680    resultSet.close();
3681  })
3682}
3683```
3684
3685### query
3686
3687query(predicates: RdbPredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
3688
3689根据指定条件查询数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3690
3691**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3692
3693**参数:**
3694
3695| 参数名     | 类型                                 | 必填 | 说明                                             |
3696| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
3697| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。        |
3698| columns    | Array&lt;string&gt;                  | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
3699
3700**错误码:**
3701
3702以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3703
3704| **错误码ID** | **错误信息**                                                 |
3705|-----------| ------------------------------------------------------------ |
3706| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3707| 14800000  | Inner error. |
3708| 14800014  | Already closed. |
3709| 14800015  | The database does not respond. |
3710
3711**返回值**:
3712
3713| 类型                                                    | 说明                                               |
3714| ------------------------------------------------------- | -------------------------------------------------- |
3715| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
3716
3717**示例:**
3718
3719```ts
3720import { BusinessError } from '@kit.BasicServicesKit';
3721
3722let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3723predicates.equalTo("NAME", "Rose");
3724if(store != undefined) {
3725  (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => {
3726    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3727    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3728    while (resultSet.goToNextRow()) {
3729      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3730      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3731      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3732      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3733      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3734    }
3735    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3736    resultSet.close();
3737  }).catch((err: BusinessError) => {
3738    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
3739  })
3740}
3741```
3742
3743### querySync<sup>12+</sup>
3744
3745querySync(predicates: RdbPredicates, columns?: Array&lt;string&gt;):ResultSet
3746
3747根据指定条件查询数据库中的数据。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
3748
3749**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3750
3751**参数:**
3752
3753| 参数名     | 类型                            | 必填 | 说明                                                         |
3754| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ |
3755| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。                      |
3756| columns    | Array&lt;string&gt;             | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。默认值为空。 |
3757
3758**错误码:**
3759
3760以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3761
3762| **错误码ID** | **错误信息**                                                 |
3763| ------------ | ------------------------------------------------------------ |
3764| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3765| 14800000     | Inner error.                                                 |
3766| 14800014     | Already closed.                                              |
3767| 14800015     | The database does not respond.                                        |
3768
3769**返回值**:
3770
3771| 类型                    | 说明                                |
3772| ----------------------- | ----------------------------------- |
3773| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
3774
3775**示例:**
3776
3777```ts
3778import { BusinessError } from '@kit.BasicServicesKit';
3779
3780let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3781predicates.equalTo("NAME", "Rose");
3782if(store != undefined) {
3783  try {
3784    let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
3785    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3786    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3787    while (resultSet.goToNextRow()) {
3788      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3789      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3790      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3791      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3792      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3793    }
3794    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3795    resultSet.close();
3796  } catch (err) {
3797    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
3798  }
3799}
3800```
3801
3802### remoteQuery
3803
3804remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt; , callback: AsyncCallback&lt;ResultSet&gt;): void
3805
3806根据指定条件查询远程设备数据库中的数据。使用callback异步回调。
3807
3808> **说明:**
3809>
3810> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
3811
3812**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3813
3814**参数:**
3815
3816| 参数名     | 类型                                         | 必填 | 说明                                                      |
3817| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- |
3818| device     | string                                       | 是   | 指定的远程设备ID。                                        |
3819| table      | string                                       | 是   | 指定的目标表名。                                          |
3820| predicates | [RdbPredicates](#rdbpredicates)              | 是   | RdbPredicates的实例对象,指定查询的条件。                 |
3821| columns    | Array&lt;string&gt;                          | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。          |
3822| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
3823
3824**错误码:**
3825
3826以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3827
3828| **错误码ID** | **错误信息**                                                 |
3829|-----------| ------------------------------------------------------------ |
3830| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3831| 801       | Capability not supported. |
3832| 14800000  | Inner error. |
3833| 14800014  | Already closed. |
3834
3835**示例:**
3836
3837```ts
3838import { distributedDeviceManager } from '@kit.DistributedServiceKit';
3839import { BusinessError } from '@kit.BasicServicesKit';
3840
3841let dmInstance: distributedDeviceManager.DeviceManager;
3842let deviceId: string | undefined = undefined;
3843
3844try {
3845  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
3846  let devices = dmInstance.getAvailableDeviceListSync();
3847  if(deviceId != undefined) {
3848    deviceId = devices[0].networkId;
3849  }
3850} catch (err) {
3851  let code = (err as BusinessError).code;
3852  let message = (err as BusinessError).message;
3853  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
3854}
3855
3856let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
3857predicates.greaterThan("id", 0);
3858if(store != undefined && deviceId != undefined) {
3859  (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => {
3860    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3861    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3862    while (resultSet.goToNextRow()) {
3863      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3864      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3865      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3866      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3867      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3868    }
3869    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3870    resultSet.close();
3871  }).catch((err: BusinessError) => {
3872    console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
3873  })
3874}
3875```
3876
3877### remoteQuery
3878
3879remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt;): Promise&lt;ResultSet&gt;
3880
3881根据指定条件查询远程设备数据库中的数据。使用Promise异步回调。
3882
3883> **说明:**
3884>
3885> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
3886
3887**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3888
3889**参数:**
3890
3891| 参数名     | 类型                                 | 必填 | 说明                                             |
3892| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
3893| device     | string                               | 是   | 指定的远程设备ID。                   |
3894| table      | string                               | 是   | 指定的目标表名。                                 |
3895| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象,指定查询的条件。      |
3896| columns    | Array&lt;string&gt;                  | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
3897
3898**返回值**:
3899
3900| 类型                                                         | 说明                                               |
3901| ------------------------------------------------------------ | -------------------------------------------------- |
3902| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
3903
3904**错误码:**
3905
3906以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3907
3908| **错误码ID** | **错误信息**                                                 |
3909|-----------| ------------------------------------------------------------ |
3910| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3911| 801       | Capability not supported. |
3912| 14800000  | Inner error. |
3913| 14800014  | Already closed. |
3914
3915**示例:**
3916
3917```ts
3918import { distributedDeviceManager } from '@kit.DistributedServiceKit';
3919import { BusinessError } from '@kit.BasicServicesKit';
3920
3921let dmInstance: distributedDeviceManager.DeviceManager;
3922let deviceId: string | undefined = undefined;
3923
3924try {
3925  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
3926  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
3927  if(devices != undefined) {
3928    deviceId = devices[0].networkId;
3929  }
3930} catch (err) {
3931  let code = (err as BusinessError).code;
3932  let message = (err as BusinessError).message;
3933  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
3934}
3935
3936let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
3937predicates.greaterThan("id", 0);
3938if(store != undefined && deviceId != undefined) {
3939  (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => {
3940    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3941    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3942    while (resultSet.goToNextRow()) {
3943      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3944      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3945      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3946      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3947      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
3948    }
3949    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
3950    resultSet.close();
3951  }).catch((err: BusinessError) => {
3952    console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
3953  })
3954}
3955```
3956
3957### querySql<sup>10+</sup>
3958
3959querySql(sql: string, callback: AsyncCallback&lt;ResultSet&gt;):void
3960
3961根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
3962
3963**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3964
3965**参数:**
3966
3967| 参数名   | 类型                                         | 必填 | 说明                                    |
3968| -------- | -------------------------------------------- | ---- |---------------------------------------|
3969| sql      | string                                       | 是   | 指定要执行的SQL语句。                          |
3970| callback | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
3971
3972**错误码:**
3973
3974以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3975
3976| **错误码ID** | **错误信息**                                                 |
3977|-----------| ------------------------------------------------------------ |
3978| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3979| 14800000  | Inner error. |
3980| 14800014  | Already closed. |
3981| 14800015  | The database does not respond. |
3982
3983**示例:**
3984
3985```ts
3986if(store != undefined) {
3987  (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'", (err, resultSet) => {
3988    if (err) {
3989      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
3990      return;
3991    }
3992    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
3993    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
3994    while (resultSet.goToNextRow()) {
3995      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
3996      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
3997      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
3998      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
3999      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4000    }
4001    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4002    resultSet.close();
4003  })
4004}
4005```
4006
4007### querySql
4008
4009querySql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
4010
4011根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
4012
4013**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4014
4015**参数:**
4016
4017| 参数名   | 类型                                         | 必填 | 说明                                                         |
4018| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
4019| sql      | string                                       | 是   | 指定要执行的SQL语句。                                        |
4020| bindArgs | Array&lt;[ValueType](#valuetype)&gt;         | 是   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数需为空数组。 |
4021| callback | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。    |
4022
4023**错误码:**
4024
4025以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4026
4027| **错误码ID** | **错误信息**                                                 |
4028|-----------| ------------------------------------------------------------ |
4029| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4030| 14800000  | Inner error. |
4031| 14800014  | Already closed. |
4032| 14800015  | The database does not respond. |
4033
4034**示例:**
4035
4036```ts
4037if(store != undefined) {
4038  (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], (err, resultSet) => {
4039    if (err) {
4040      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4041      return;
4042    }
4043    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4044    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4045    while (resultSet.goToNextRow()) {
4046      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4047      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4048      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4049      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4050      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4051    }
4052    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4053    resultSet.close();
4054  })
4055}
4056```
4057
4058### querySql
4059
4060querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt;
4061
4062根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
4063
4064**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4065
4066**参数:**
4067
4068| 参数名   | 类型                                 | 必填 | 说明                                                         |
4069| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4070| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4071| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
4072
4073**返回值**:
4074
4075| 类型                                                    | 说明                                               |
4076| ------------------------------------------------------- | -------------------------------------------------- |
4077| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
4078
4079**错误码:**
4080
4081以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4082
4083| **错误码ID** | **错误信息**                                                 |
4084|-----------| ------------------------------------------------------------ |
4085| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4086| 14800000  | Inner error. |
4087| 14800014  | Already closed. |
4088| 14800015  | The database does not respond. |
4089
4090**示例:**
4091
4092```ts
4093import { BusinessError } from '@kit.BasicServicesKit';
4094
4095if(store != undefined) {
4096  (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then((resultSet: relationalStore.ResultSet) => {
4097    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4098    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4099    while (resultSet.goToNextRow()) {
4100      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4101      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4102      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4103      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4104      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4105    }
4106    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4107    resultSet.close();
4108  }).catch((err: BusinessError) => {
4109    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4110  })
4111}
4112```
4113
4114### querySqlSync<sup>12+</sup>
4115
4116querySqlSync(sql: string, bindArgs?: Array&lt;ValueType&gt;):ResultSet
4117
4118根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
4119
4120**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4121
4122**参数:**
4123
4124| 参数名   | 类型                                 | 必填 | 说明                                                         |
4125| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4126| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4127| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。默认值为空。 |
4128
4129**返回值**:
4130
4131| 类型                    | 说明                                |
4132| ----------------------- | ----------------------------------- |
4133| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
4134
4135**错误码:**
4136
4137以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4138
4139| **错误码ID** | **错误信息**                                                 |
4140| ------------ | ------------------------------------------------------------ |
4141| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4142| 14800000     | Inner error.                                                 |
4143| 14800014     | Already closed.                                              |
4144| 14800015     | The database does not respond.                                        |
4145
4146**示例:**
4147
4148```ts
4149import { BusinessError } from '@kit.BasicServicesKit';
4150
4151if(store != undefined) {
4152  try {
4153    let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'");
4154    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4155    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4156    while (resultSet.goToNextRow()) {
4157      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4158      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4159      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4160      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4161      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4162    }
4163    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4164    resultSet.close();
4165  } catch (err) {
4166    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4167  }
4168}
4169```
4170
4171### executeSql<sup>10+</sup>
4172
4173executeSql(sql: string, callback: AsyncCallback&lt;void&gt;):void
4174
4175执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
4176
4177此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4178
4179不支持分号分隔的多条语句。
4180
4181**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4182
4183**参数:**
4184
4185| 参数名   | 类型                                 | 必填 | 说明                                                         |
4186| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4187| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4188| callback | AsyncCallback&lt;void&gt;            | 是   | 指定callback回调函数。                                       |
4189
4190**错误码:**
4191
4192以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4193
4194| **错误码ID** | **错误信息**                                                 |
4195|-----------| ------------------------------------------------------------ |
4196| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4197| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4198| 14800000  | Inner error. |
4199| 14800011  | Database corrupted. |
4200| 14800014  | Already closed. |
4201| 14800015  | The database does not respond. |
4202| 14800021  | SQLite: Generic error. |
4203| 14800022  | SQLite: Callback routine requested an abort. |
4204| 14800023  | SQLite: Access permission denied. |
4205| 14800024  | SQLite: The database file is locked. |
4206| 14800025  | SQLite: A table in the database is locked. |
4207| 14800026  | SQLite: The database is out of memory. |
4208| 14800027  | SQLite: Attempt to write a readonly database. |
4209| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4210| 14800029  | SQLite: The database is full. |
4211| 14800030  | SQLite: Unable to open the database file. |
4212| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4213| 14800032  | SQLite: Abort due to constraint violation. |
4214| 14800033  | SQLite: Data type mismatch. |
4215| 14800034  | SQLite: Library used incorrectly. |
4216| 14800047  | The WAL file size exceeds the default limit. |
4217
4218**示例:**
4219
4220```ts
4221const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"
4222if(store != undefined) {
4223  (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, (err) => {
4224    if (err) {
4225      console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
4226      return;
4227    }
4228    console.info('Delete table done.');
4229  })
4230}
4231```
4232
4233### executeSql
4234
4235executeSql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;void&gt;):void
4236
4237执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
4238
4239此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4240
4241不支持分号分隔的多条语句。
4242
4243**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4244
4245**参数:**
4246
4247| 参数名   | 类型                                 | 必填 | 说明                                                         |
4248| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4249| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4250| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 是   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数需为空数组。 |
4251| callback | AsyncCallback&lt;void&gt;            | 是   | 指定callback回调函数。                                       |
4252
4253**错误码:**
4254
4255以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4256
4257| **错误码ID** | **错误信息**                                                 |
4258|-----------| ------------------------------------------------------------ |
4259| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4260| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4261| 14800000  | Inner error. |
4262| 14800011  | Database corrupted. |
4263| 14800014  | Already closed. |
4264| 14800015  | The database does not respond. |
4265| 14800021  | SQLite: Generic error. |
4266| 14800022  | SQLite: Callback routine requested an abort. |
4267| 14800023  | SQLite: Access permission denied. |
4268| 14800024  | SQLite: The database file is locked. |
4269| 14800025  | SQLite: A table in the database is locked. |
4270| 14800026  | SQLite: The database is out of memory. |
4271| 14800027  | SQLite: Attempt to write a readonly database. |
4272| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4273| 14800029  | SQLite: The database is full. |
4274| 14800030  | SQLite: Unable to open the database file. |
4275| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4276| 14800032  | SQLite: Abort due to constraint violation. |
4277| 14800033  | SQLite: Data type mismatch. |
4278| 14800034  | SQLite: Library used incorrectly. |
4279| 14800047  | The WAL file size exceeds the default limit. |
4280
4281**示例:**
4282
4283```ts
4284const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?"
4285if(store != undefined) {
4286  (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, ['zhangsan'], (err) => {
4287    if (err) {
4288      console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
4289      return;
4290    }
4291    console.info('Delete table done.');
4292  })
4293}
4294```
4295
4296### executeSql
4297
4298executeSql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;void&gt;
4299
4300执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
4301
4302此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4303
4304不支持分号分隔的多条语句。
4305
4306**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4307
4308**参数:**
4309
4310| 参数名   | 类型                                 | 必填 | 说明                                                         |
4311| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4312| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4313| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
4314
4315**返回值**:
4316
4317| 类型                | 说明                      |
4318| ------------------- | ------------------------- |
4319| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4320
4321**错误码:**
4322
4323以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4324
4325| **错误码ID** | **错误信息**                                                 |
4326|-----------| ------------------------------------------------------------ |
4327| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4328| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4329| 14800000  | Inner error. |
4330| 14800011  | Database corrupted. |
4331| 14800014  | Already closed. |
4332| 14800015  | The database does not respond. |
4333| 14800021  | SQLite: Generic error. |
4334| 14800022  | SQLite: Callback routine requested an abort. |
4335| 14800023  | SQLite: Access permission denied. |
4336| 14800024  | SQLite: The database file is locked. |
4337| 14800025  | SQLite: A table in the database is locked. |
4338| 14800026  | SQLite: The database is out of memory. |
4339| 14800027  | SQLite: Attempt to write a readonly database. |
4340| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4341| 14800029  | SQLite: The database is full. |
4342| 14800030  | SQLite: Unable to open the database file. |
4343| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4344| 14800032  | SQLite: Abort due to constraint violation. |
4345| 14800033  | SQLite: Data type mismatch. |
4346| 14800034  | SQLite: Library used incorrectly. |
4347| 14800047  | The WAL file size exceeds the default limit. |
4348
4349**示例:**
4350
4351```ts
4352import { BusinessError } from '@kit.BasicServicesKit';
4353
4354const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"
4355if(store != undefined) {
4356  (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE).then(() => {
4357    console.info('Delete table done.');
4358  }).catch((err: BusinessError) => {
4359    console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
4360  })
4361}
4362```
4363
4364### execute<sup>12+</sup>
4365
4366execute(sql: string, args?: Array&lt;ValueType&gt;):Promise&lt;ValueType&gt;
4367
4368执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType,使用Promise异步回调。
4369
4370该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
4371
4372此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4373
4374不支持分号分隔的多条语句。
4375
4376**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4377
4378**参数:**
4379
4380| 参数名   | 类型                                 | 必填 | 说明                                                         |
4381| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4382| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4383| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
4384
4385**返回值**:
4386
4387| 类型                | 说明                      |
4388| ------------------- | ------------------------- |
4389| Promise&lt;[ValueType](#valuetype)&gt; | Promise对象,返回sql执行后的结果。 |
4390
4391**错误码:**
4392
4393以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4394
4395| **错误码ID** | **错误信息**                                                 |
4396|-----------| ------------------------------------------------------------ |
4397| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4398| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4399| 14800000  | Inner error. |
4400| 14800011  | Database corrupted. |
4401| 14800014  | Already closed. |
4402| 14800015  | The database does not respond. |
4403| 14800021  | SQLite: Generic error. |
4404| 14800022  | SQLite: Callback routine requested an abort. |
4405| 14800023  | SQLite: Access permission denied. |
4406| 14800024  | SQLite: The database file is locked. |
4407| 14800025  | SQLite: A table in the database is locked. |
4408| 14800026  | SQLite: The database is out of memory. |
4409| 14800027  | SQLite: Attempt to write a readonly database. |
4410| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4411| 14800029  | SQLite: The database is full. |
4412| 14800030  | SQLite: Unable to open the database file. |
4413| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4414| 14800032  | SQLite: Abort due to constraint violation. |
4415| 14800033  | SQLite: Data type mismatch. |
4416| 14800034  | SQLite: Library used incorrectly. |
4417| 14800047  | The WAL file size exceeds the default limit. |
4418
4419**示例:**
4420
4421```ts
4422import { BusinessError } from '@kit.BasicServicesKit';
4423
4424// 校验数据库完整性
4425if(store != undefined) {
4426  const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check';
4427  (store as relationalStore.RdbStore).execute(SQL_CHECK_INTEGRITY).then((data) => {
4428    console.info(`check result: ${data}`);
4429  }).catch((err: BusinessError) => {
4430    console.error(`check failed, code is ${err.code}, message is ${err.message}`);
4431  })
4432}
4433
4434// 删除表中所有数据
4435if(store != undefined) {
4436  const SQL_DELETE_TABLE = 'DELETE FROM test';
4437  (store as relationalStore.RdbStore).execute(SQL_DELETE_TABLE).then((data) => {
4438    console.info(`delete result: ${data}`);
4439  }).catch((err: BusinessError) => {
4440    console.error(`delete failed, code is ${err.code}, message is ${err.message}`);
4441  })
4442}
4443
4444// 删表
4445if(store != undefined) {
4446  const SQL_DROP_TABLE = 'DROP TABLE test';
4447  (store as relationalStore.RdbStore).execute(SQL_DROP_TABLE).then((data) => {
4448    console.info(`drop result: ${data}`);
4449  }).catch((err: BusinessError) => {
4450    console.error(`drop failed, code is ${err.code}, message is ${err.message}`);
4451  })
4452}
4453```
4454
4455### execute<sup>12+</sup>
4456
4457execute(sql: string, txId: number, args?: Array&lt;ValueType&gt;): Promise&lt;ValueType&gt;
4458
4459执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
4460
4461<!--RP1-->
4462该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End-->
4463
4464此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4465
4466不支持分号分隔的多条语句。
4467
4468**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4469
4470**参数:**
4471
4472| 参数名   | 类型                                 | 必填 | 说明                                                         |
4473| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4474| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4475| txId      | number                               | 是   | 通过[beginTrans](#begintrans12)获取的事务ID,如果传0,该语句默认在单独事务内。                                      |
4476| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。该参数不填,或者填null或undefined,都认为是sql参数语句完整。 |
4477
4478**返回值**:
4479
4480| 类型                | 说明                      |
4481| ------------------- | ------------------------- |
4482| Promise&lt;[ValueType](#valuetype)&gt; | Promise对象,返回null。 |
4483
4484**错误码:**
4485
4486以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4487
4488| **错误码ID** | **错误信息**                                                 |
4489|-----------| ------------------------------------------------------------ |
4490| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4491| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4492| 14800000  | Inner error. |
4493| 14800011  | Database corrupted. |
4494| 14800014  | Already closed. |
4495| 14800015  | The database does not respond. |
4496| 14800021  | SQLite: Generic error. |
4497| 14800022  | SQLite: Callback routine requested an abort. |
4498| 14800023  | SQLite: Access permission denied. |
4499| 14800024  | SQLite: The database file is locked. |
4500| 14800025  | SQLite: A table in the database is locked. |
4501| 14800026  | SQLite: The database is out of memory. |
4502| 14800027  | SQLite: Attempt to write a readonly database. |
4503| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4504| 14800029  | SQLite: The database is full. |
4505| 14800030  | SQLite: Unable to open the database file. |
4506| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4507| 14800032  | SQLite: Abort due to constraint violation. |
4508| 14800033  | SQLite: Data type mismatch. |
4509| 14800034  | SQLite: Library used incorrectly. |
4510| 14800047  | The WAL file size exceeds the default limit. |
4511
4512**示例:**
4513
4514```ts
4515import { BusinessError } from '@kit.BasicServicesKit';
4516if(store != null) {
4517  let txId : number;
4518  (store as relationalStore.RdbStore).beginTrans().then((txId : number) => {
4519    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
4520      .then(() => {
4521        (store as relationalStore.RdbStore).commit(txId);
4522    })
4523    .catch((err: BusinessError) => {
4524      (store as relationalStore.RdbStore).rollback(txId)
4525      console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
4526    });
4527  });
4528}
4529```
4530
4531### executeSync<sup>12+</sup>
4532
4533executeSync(sql: string, args?: Array&lt;ValueType&gt;): ValueType
4534
4535执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType。
4536
4537该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
4538
4539此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4540
4541不支持分号分隔的多条语句。
4542
4543**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4544
4545**参数:**
4546
4547| 参数名 | 类型                                 | 必填 | 说明                                                         |
4548| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
4549| sql    | string                               | 是   | 指定要执行的SQL语句。                                        |
4550| args   | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。该参数不填,或者填null或undefined,都认为是sql参数语句完整。默认值为空。 |
4551
4552**返回值**:
4553
4554| 类型                    | 说明                |
4555| ----------------------- | ------------------- |
4556| [ValueType](#valuetype) | 返回sql执行后的结果 |
4557
4558**错误码:**
4559
4560以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4561
4562| **错误码ID** | **错误信息**                                                 |
4563| ------------ | ------------------------------------------------------------ |
4564| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4565| 14800000     | Inner error.                                                 |
4566| 14800011     | Database corrupted.                                          |
4567| 14800014     | Already closed.                                              |
4568| 14800015     | The database does not respond.                               |
4569| 14800021     | SQLite: Generic error.                                       |
4570| 14800022     | SQLite: Callback routine requested an abort.                 |
4571| 14800023     | SQLite: Access permission denied.                            |
4572| 14800024     | SQLite: The database file is locked.                         |
4573| 14800025     | SQLite: A table in the database is locked.                   |
4574| 14800026     | SQLite: The database is out of memory.                       |
4575| 14800027     | SQLite: Attempt to write a readonly database.                |
4576| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
4577| 14800029     | SQLite: The database is full.                                |
4578| 14800030     | SQLite: Unable to open the database file.                    |
4579| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
4580| 14800032     | SQLite: Abort due to constraint violation.                   |
4581| 14800033     | SQLite: Data type mismatch.                                  |
4582| 14800034     | SQLite: Library used incorrectly.                            |
4583| 14800047     | The WAL file size exceeds the default limit.                 |
4584
4585**示例:**
4586
4587```ts
4588import { BusinessError } from '@kit.BasicServicesKit';
4589
4590// 校验数据库完整性
4591if(store != undefined) {
4592  const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check';
4593  try {
4594    let data = (store as relationalStore.RdbStore).executeSync(SQL_CHECK_INTEGRITY)
4595    console.info(`check result: ${data}`);
4596  } catch (err) {
4597    console.error(`check failed, code is ${err.code}, message is ${err.message}`);
4598  }
4599}
4600
4601// 删除表中所有数据
4602if(store != undefined) {
4603  const SQL_DELETE_TABLE = 'DELETE FROM test';
4604  try {
4605    let data = (store as relationalStore.RdbStore).executeSync(SQL_DELETE_TABLE)
4606    console.info(`delete result: ${data}`);
4607  } catch (err) {
4608    console.error(`delete failed, code is ${err.code}, message is ${err.message}`);
4609  }
4610}
4611
4612// 删表
4613if(store != undefined) {
4614  const SQL_DROP_TABLE = 'DROP TABLE test';
4615  try {
4616    let data = (store as relationalStore.RdbStore).executeSync(SQL_DROP_TABLE)
4617    console.info(`drop result: ${data}`);
4618  } catch (err) {
4619    console.error(`drop failed, code is ${err.code}, message is ${err.message}`);
4620  }
4621}
4622```
4623
4624### getModifyTime<sup>10+</sup>
4625
4626getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[], callback: AsyncCallback&lt;ModifyTime&gt;): void
4627
4628获取数据库表中数据的最后修改时间,使用callback异步回调。
4629
4630**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4631
4632**参数:**
4633
4634| 参数名      | 类型                                             | 必填 | 说明                                                         |
4635| ----------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
4636| table       | string                                           | 是   | 指定要查询的数据库表的表名。                                 |
4637| columnName  | string                                           | 是   | 指定要查询的数据库表的列名。                                 |
4638| primaryKeys | [PRIKeyType](#prikeytype10)[]                    | 是   | 指定要查询的行的主键。<br>如果数据库表无主键,参数columnName需传入"rowid",此时primaryKeys为要查询的数据库表的行号。<br>如果数据库表无主键,参数columnName传入不为"rowid",返回对应的错误码。 |
4639| callback    | AsyncCallback&lt;[ModifyTime](#modifytime10)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ModifyTime对象,表示数据的最后修改时间。 |
4640
4641**错误码:**
4642
4643以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4644
4645| **错误码ID** | **错误信息**                                                 |
4646|-----------| ------------------------------------------------------------ |
4647| 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. |
4648| 801       | Capability not supported. |
4649| 14800000  | Inner error. |
4650| 14800011  | Database corrupted. |
4651| 14800014  | Already closed. |
4652| 14800015  | The database does not respond. |
4653| 14800021  | SQLite: Generic error. |
4654| 14800022  | SQLite: Callback routine requested an abort. |
4655| 14800023  | SQLite: Access permission denied. |
4656| 14800024  | SQLite: The database file is locked. |
4657| 14800025  | SQLite: A table in the database is locked. |
4658| 14800026  | SQLite: The database is out of memory. |
4659| 14800027  | SQLite: Attempt to write a readonly database. |
4660| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4661| 14800029  | SQLite: The database is full. |
4662| 14800030  | SQLite: Unable to open the database file. |
4663| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4664| 14800032  | SQLite: Abort due to constraint violation. |
4665| 14800033  | SQLite: Data type mismatch. |
4666| 14800034  | SQLite: Library used incorrectly. |
4667
4668**示例:**
4669
4670```ts
4671let PRIKey = [1, 4, 2, 3];
4672if(store != undefined) {
4673  (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey, (err, modifyTime: relationalStore.ModifyTime) => {
4674    if (err) {
4675      console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`);
4676      return;
4677    }
4678    let size = modifyTime.size;
4679  });
4680}
4681```
4682
4683### getModifyTime<sup>10+</sup>
4684
4685getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[]): Promise&lt;ModifyTime&gt;
4686
4687获取数据库表中数据的最后修改时间,使用Promise异步回调。
4688
4689**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4690
4691**参数:**
4692
4693| 参数名      | 类型                          | 必填 | 说明                                                         |
4694| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ |
4695| table       | string                        | 是   | 指定要查询的数据库表的表名。                                 |
4696| columnName  | string                        | 是   | 指定要查询的数据库表的列名。                                 |
4697| primaryKeys | [PRIKeyType](#prikeytype10)[] | 是   | 指定要查询的行的主键。<br>如果数据库表无主键,参数columnName需传入"rowid",此时primaryKeys为要查询的数据库表的行号。<br>如果数据库表无主键,参数columnName传入不为"rowid",返回对应的错误码。 |
4698
4699**返回值**:
4700
4701| 类型                                       | 说明                                                      |
4702| ------------------------------------------ | --------------------------------------------------------- |
4703| Promise&lt;[ModifyTime](#modifytime10)&gt; | 返回ModifyTime类型的Promise对象,表示数据最后的修改时间。 |
4704
4705**错误码:**
4706
4707以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4708
4709| **错误码ID** | **错误信息**                                                 |
4710|-----------| ------------------------------------------------------------ |
4711| 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. |
4712| 801       | Capability not supported. |
4713| 14800000  | Inner error. |
4714| 14800011  | Database corrupted. |
4715| 14800014  | Already closed. |
4716| 14800015  | The database does not respond. |
4717| 14800021  | SQLite: Generic error. |
4718| 14800022  | SQLite: Callback routine requested an abort. |
4719| 14800023  | SQLite: Access permission denied. |
4720| 14800024  | SQLite: The database file is locked. |
4721| 14800025  | SQLite: A table in the database is locked. |
4722| 14800026  | SQLite: The database is out of memory. |
4723| 14800027  | SQLite: Attempt to write a readonly database. |
4724| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4725| 14800029  | SQLite: The database is full. |
4726| 14800030  | SQLite: Unable to open the database file. |
4727| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4728| 14800032  | SQLite: Abort due to constraint violation. |
4729| 14800033  | SQLite: Data type mismatch. |
4730| 14800034  | SQLite: Library used incorrectly. |
4731
4732**示例:**
4733
4734```ts
4735import { BusinessError } from '@kit.BasicServicesKit';
4736
4737let PRIKey = [1, 2, 3];
4738if(store != undefined) {
4739  (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey)
4740    .then((modifyTime: relationalStore.ModifyTime) => {
4741      let size = modifyTime.size;
4742    })
4743    .catch((err: BusinessError) => {
4744      console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`);
4745    });
4746}
4747```
4748
4749### beginTransaction
4750
4751beginTransaction():void
4752
4753在开始执行SQL语句之前,开始事务。
4754此接口不允许嵌套事务,且不支持在多进程或多线程中使用。
4755
4756**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4757
4758**错误码:**
4759
4760以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4761
4762| **错误码ID** | **错误信息**                                                 |
4763|-----------| ------------------------------------------------------------ |
4764| 401       | Parameter error. The store must not be nullptr. |
4765| 14800000  | Inner error. |
4766| 14800011  | Database corrupted. |
4767| 14800014  | Already closed. |
4768| 14800015  | The database does not respond. |
4769| 14800021  | SQLite: Generic error. |
4770| 14800022  | SQLite: Callback routine requested an abort. |
4771| 14800023  | SQLite: Access permission denied. |
4772| 14800024  | SQLite: The database file is locked. |
4773| 14800025  | SQLite: A table in the database is locked. |
4774| 14800026  | SQLite: The database is out of memory. |
4775| 14800027  | SQLite: Attempt to write a readonly database. |
4776| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4777| 14800029  | SQLite: The database is full. |
4778| 14800030  | SQLite: Unable to open the database file. |
4779| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4780| 14800032  | SQLite: Abort due to constraint violation. |
4781| 14800033  | SQLite: Data type mismatch. |
4782| 14800034  | SQLite: Library used incorrectly. |
4783| 14800047  | The WAL file size exceeds the default limit. |
4784
4785**示例:**
4786
4787```ts
4788
4789let value1 = "Lisa";
4790let value2 = 18;
4791let value3 = 100.5;
4792let value4 = new Uint8Array([1, 2, 3]);
4793
4794if(store != undefined) {
4795  (store as relationalStore.RdbStore).beginTransaction();
4796  const valueBucket: relationalStore.ValuesBucket = {
4797    'NAME': value1,
4798    'AGE': value2,
4799    'SALARY': value3,
4800    'CODES': value4,
4801  };
4802  (store as relationalStore.RdbStore).insert("test", valueBucket);
4803  (store as relationalStore.RdbStore).commit();
4804}
4805```
4806
4807### beginTrans<sup>12+</sup>
4808
4809beginTrans(): Promise&lt;number&gt;
4810
4811在开始执行SQL语句之前,开始事务,使用Promise异步回调。
4812
4813与[beginTransaction](#begintransaction)的区别在于:该接口会返回事务ID,[execute](#execute12-1)可以指定不同事务ID达到事务隔离目的。
4814
4815<!--RP1-->
4816该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End-->
4817
4818**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4819
4820**返回值**:
4821
4822| 类型                | 说明                      |
4823| ------------------- | ------------------------- |
4824| Promise&lt;number&gt; | Promise对象,返回事务ID。 |
4825
4826**错误码:**
4827
4828以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4829
4830| **错误码ID** | **错误信息**                                                 |
4831|-----------| ------------------------------------------------------------ |
4832| 401       | Parameter error. The store must not be nullptr. |
4833| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4834| 14800000  | Inner error. |
4835| 14800011  | Database corrupted. |
4836| 14800014  | Already closed. |
4837| 14800015  | The database does not respond. |
4838| 14800021  | SQLite: Generic error. |
4839| 14800022  | SQLite: Callback routine requested an abort. |
4840| 14800023  | SQLite: Access permission denied. |
4841| 14800024  | SQLite: The database file is locked. |
4842| 14800025  | SQLite: A table in the database is locked. |
4843| 14800026  | SQLite: The database is out of memory. |
4844| 14800027  | SQLite: Attempt to write a readonly database. |
4845| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4846| 14800029  | SQLite: The database is full. |
4847| 14800030  | SQLite: Unable to open the database file. |
4848| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4849| 14800032  | SQLite: Abort due to constraint violation. |
4850| 14800033  | SQLite: Data type mismatch. |
4851| 14800034  | SQLite: Library used incorrectly. |
4852| 14800047  | The WAL file size exceeds the default limit. |
4853
4854**示例:**
4855
4856```ts
4857import { BusinessError } from '@kit.BasicServicesKit';
4858if(store != null) {
4859  let txId : number;
4860  (store as relationalStore.RdbStore).beginTrans().then((txId : number) => {
4861    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
4862      .then(() => {
4863        (store as relationalStore.RdbStore).commit(txId);
4864    })
4865    .catch((err: BusinessError) => {
4866      (store as relationalStore.RdbStore).rollback(txId)
4867      console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
4868    });
4869  });
4870}
4871```
4872
4873### createTransaction<sup>14+</sup>
4874
4875createTransaction(options?: TransactionOptions): Promise&lt;Transaction&gt;
4876
4877创建一个事务对象并开始事务,使用Promise异步回调。
4878
4879与[beginTransaction](#begintransaction)的区别在于:createTransaction接口会返回一个事务对象,不同事务对象之间是隔离的。一个store最多支持同时存在四个事务对象,超过后会返回14800015错误码,此时需要检查是否持有事务对象时间过长或并发事务过多。如果已无法优化,可以等其它事务释放后再次尝试创建事务对象。
4880
4881**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4882
4883**参数:**
4884
4885| 参数名      | 类型                          | 必填 | 说明                                                         |
4886| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ |
4887| options       | [TransactionOptions](#transactionoptions14)           | 否   | 表示事务对象的配置信息。                                 |
4888
4889**返回值**:
4890
4891| 类型                | 说明                      |
4892| ------------------- | ------------------------- |
4893| Promise&lt;[Transaction](#transaction14)&gt; | Promise对象,返回事务对象。 |
4894
4895**错误码:**
4896
4897以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4898
4899| **错误码ID** | **错误信息**                                                 |
4900|-----------| ------------------------------------------------------------ |
4901| 14800000  | Inner error. |
4902| 14800011  | Database corrupted. |
4903| 14800014  | Already closed. |
4904| 14800015  | The database is busy.              |
4905| 14800023  | SQLite: Access permission denied. |
4906| 14800024  | SQLite: The database file is locked. |
4907| 14800026  | SQLite: The database is out of memory. |
4908| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4909| 14800029  | SQLite: The database is full. |
4910| 14800030  | SQLite: Unable to open the database file. |
4911
4912**示例:**
4913
4914```ts
4915import { BusinessError } from '@kit.BasicServicesKit';
4916
4917if(store != undefined) {
4918  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
4919    transaction.execute("DELETE FROM test WHERE age = ? OR age = ?", [21, 20]).then(() => {
4920      transaction.commit();
4921    }).catch((e: BusinessError) => {
4922      transaction.rollback();
4923      console.error(`execute sql failed, code is ${e.code},message is ${e.message}`);
4924    });
4925  }).catch((err: BusinessError) => {
4926    console.error(`createTransaction faided, code is ${err.code},message is ${err.message}`);
4927  });
4928}
4929```
4930
4931### commit
4932
4933commit():void
4934
4935提交已执行的SQL语句,跟[beginTransaction](#begintransaction)配合使用。
4936此接口不允许嵌套事务,且不支持在多进程或多线程中使用。
4937
4938**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4939
4940**错误码:**
4941
4942以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4943
4944| **错误码ID** | **错误信息**                                                 |
4945|-----------| ------------------------------------------------------------ |
4946| 401       | Parameter error. The store must not be nullptr. |
4947| 14800000  | Inner error. |
4948| 14800011  | Database corrupted. |
4949| 14800014  | Already closed. |
4950| 14800015  | The database does not respond. |
4951| 14800021  | SQLite: Generic error. |
4952| 14800022  | SQLite: Callback routine requested an abort. |
4953| 14800023  | SQLite: Access permission denied. |
4954| 14800024  | SQLite: The database file is locked. |
4955| 14800025  | SQLite: A table in the database is locked. |
4956| 14800026  | SQLite: The database is out of memory. |
4957| 14800027  | SQLite: Attempt to write a readonly database. |
4958| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4959| 14800029  | SQLite: The database is full. |
4960| 14800030  | SQLite: Unable to open the database file. |
4961| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4962| 14800032  | SQLite: Abort due to constraint violation. |
4963| 14800033  | SQLite: Data type mismatch. |
4964| 14800034  | SQLite: Library used incorrectly. |
4965
4966**示例:**
4967
4968```ts
4969
4970let value1 = "Lisa";
4971let value2 = 18;
4972let value3 = 100.5;
4973let value4 = new Uint8Array([1, 2, 3]);
4974
4975if(store != undefined) {
4976  (store as relationalStore.RdbStore).beginTransaction();
4977  const valueBucket: relationalStore.ValuesBucket = {
4978    'NAME': value1,
4979    'AGE': value2,
4980    'SALARY': value3,
4981    'CODES': value4,
4982  };
4983  (store as relationalStore.RdbStore).insert("test", valueBucket);
4984  (store as relationalStore.RdbStore).commit();
4985}
4986```
4987
4988### commit<sup>12+</sup>
4989
4990commit(txId : number):Promise&lt;void&gt;
4991
4992提交已执行的SQL语句,跟[beginTrans](#begintrans12)配合使用。
4993
4994<!--RP1-->
4995该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End-->
4996
4997**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4998
4999**参数:**
5000
5001| 参数名   | 类型                                 | 必填 | 说明                                                         |
5002| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
5003| txId      | number                               | 是   | 通过[beginTrans](#begintrans12)获取的事务ID。                                        |
5004
5005**返回值**:
5006
5007| 类型                | 说明                      |
5008| ------------------- | ------------------------- |
5009| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5010
5011**错误码:**
5012
5013以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5014
5015| **错误码ID** | **错误信息**                                                 |
5016|-----------| ------------------------------------------------------------ |
5017| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5018| 14800000  | Inner error. |
5019| 14800011  | Database corrupted. |
5020| 14800014  | Already closed. |
5021| 14800015  | The database does not respond. |
5022| 14800021  | SQLite: Generic error. |
5023| 14800022  | SQLite: Callback routine requested an abort. |
5024| 14800023  | SQLite: Access permission denied. |
5025| 14800024  | SQLite: The database file is locked. |
5026| 14800025  | SQLite: A table in the database is locked. |
5027| 14800026  | SQLite: The database is out of memory. |
5028| 14800027  | SQLite: Attempt to write a readonly database. |
5029| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5030| 14800029  | SQLite: The database is full. |
5031| 14800030  | SQLite: Unable to open the database file. |
5032| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5033| 14800032  | SQLite: Abort due to constraint violation. |
5034| 14800033  | SQLite: Data type mismatch. |
5035| 14800034  | SQLite: Library used incorrectly. |
5036
5037**示例:**
5038
5039```ts
5040import { BusinessError } from '@kit.BasicServicesKit';
5041if(store != null) {
5042  let txId : number;
5043  (store as relationalStore.RdbStore).beginTrans().then((txId : number) => {
5044    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
5045      .then(() => {
5046        (store as relationalStore.RdbStore).commit(txId);
5047    })
5048    .catch((err: BusinessError) => {
5049      (store as relationalStore.RdbStore).rollback(txId)
5050      console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
5051    });
5052  });
5053}
5054```
5055
5056### rollBack
5057
5058rollBack():void
5059
5060回滚已经执行的SQL语句。
5061此接口不允许嵌套事务,且不支持在多进程或多线程中使用。
5062
5063**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5064
5065**错误码:**
5066
5067以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5068
5069| **错误码ID** | **错误信息**                                                 |
5070|-----------| ------------------------------------------------------------ |
5071| 401       | Parameter error. The store must not be nullptr. |
5072| 14800000  | Inner error. |
5073| 14800011  | Database corrupted. |
5074| 14800014  | Already closed. |
5075| 14800015  | The database does not respond. |
5076| 14800021  | SQLite: Generic error. |
5077| 14800022  | SQLite: Callback routine requested an abort. |
5078| 14800023  | SQLite: Access permission denied. |
5079| 14800024  | SQLite: The database file is locked. |
5080| 14800025  | SQLite: A table in the database is locked. |
5081| 14800026  | SQLite: The database is out of memory. |
5082| 14800027  | SQLite: Attempt to write a readonly database. |
5083| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5084| 14800029  | SQLite: The database is full. |
5085| 14800030  | SQLite: Unable to open the database file. |
5086| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5087| 14800032  | SQLite: Abort due to constraint violation. |
5088| 14800033  | SQLite: Data type mismatch. |
5089| 14800034  | SQLite: Library used incorrectly. |
5090
5091**示例:**
5092
5093```ts
5094import { BusinessError } from '@kit.BasicServicesKit';
5095
5096let value1 = "Lisa";
5097let value2 = 18;
5098let value3 = 100.5;
5099let value4 = new Uint8Array([1, 2, 3]);
5100
5101if(store != undefined) {
5102  try {
5103    (store as relationalStore.RdbStore).beginTransaction()
5104    const valueBucket: relationalStore.ValuesBucket = {
5105      'NAME': value1,
5106      'AGE': value2,
5107      'SALARY': value3,
5108      'CODES': value4,
5109    };
5110    (store as relationalStore.RdbStore).insert("test", valueBucket);
5111    (store as relationalStore.RdbStore).commit();
5112  } catch (err) {
5113    let code = (err as BusinessError).code;
5114    let message = (err as BusinessError).message
5115    console.error(`Transaction failed, code is ${code},message is ${message}`);
5116    (store as relationalStore.RdbStore).rollBack();
5117  }
5118}
5119```
5120
5121### rollback<sup>12+</sup>
5122
5123rollback(txId : number):Promise&lt;void&gt;
5124
5125回滚已经执行的SQL语句,跟[beginTrans](#begintrans12)配合使用。
5126
5127<!--RP1-->
5128该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End-->
5129
5130**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5131
5132**参数:**
5133
5134| 参数名   | 类型                                 | 必填 | 说明                                                         |
5135| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
5136| txId      | number                               | 是   | 通过[beginTrans](#begintrans12)获取的事务ID。                                        |
5137
5138**返回值**:
5139
5140| 类型                | 说明                      |
5141| ------------------- | ------------------------- |
5142| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5143
5144**错误码:**
5145
5146以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5147
5148| **错误码ID** | **错误信息**                                                 |
5149|-----------| ------------------------------------------------------------ |
5150| 401       | Parameter error. The store must not be nullptr. |
5151| 14800000  | Inner error. |
5152| 14800011  | Database corrupted. |
5153| 14800014  | Already closed. |
5154| 14800015  | The database does not respond. |
5155| 14800021  | SQLite: Generic error. |
5156| 14800022  | SQLite: Callback routine requested an abort. |
5157| 14800023  | SQLite: Access permission denied. |
5158| 14800024  | SQLite: The database file is locked. |
5159| 14800025  | SQLite: A table in the database is locked. |
5160| 14800026  | SQLite: The database is out of memory. |
5161| 14800027  | SQLite: Attempt to write a readonly database. |
5162| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5163| 14800029  | SQLite: The database is full. |
5164| 14800030  | SQLite: Unable to open the database file. |
5165| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5166| 14800032  | SQLite: Abort due to constraint violation. |
5167| 14800033  | SQLite: Data type mismatch. |
5168| 14800034  | SQLite: Library used incorrectly. |
5169
5170**示例:**
5171
5172```ts
5173import { BusinessError } from '@kit.BasicServicesKit';
5174if(store != null) {
5175  let txId : number;
5176  (store as relationalStore.RdbStore).beginTrans().then((txId : number) => {
5177    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
5178      .then(() => {
5179        (store as relationalStore.RdbStore).commit(txId);
5180    })
5181    .catch((err: BusinessError) => {
5182      (store as relationalStore.RdbStore).rollback(txId)
5183      console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
5184    });
5185  });
5186}
5187```
5188
5189### backup
5190
5191backup(destName:string, callback: AsyncCallback&lt;void&gt;):void
5192
5193以指定名称备份数据库,使用callback异步回调。
5194
5195**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5196
5197**参数:**
5198
5199| 参数名   | 类型                      | 必填 | 说明                     |
5200| -------- | ------------------------- | ---- | ------------------------ |
5201| destName | string                    | 是   | 指定数据库的备份文件名。 |
5202| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。   |
5203
5204**错误码:**
5205
5206以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5207
5208| **错误码ID** | **错误信息**                                                 |
5209|-----------| ------------------------------------------------------------ |
5210| 401       | Parameter error. The store must not be nullptr. |
5211| 14800000  | Inner error. |
5212| 14800010  | Invalid database path. |
5213| 14800011  | Database corrupted. |
5214| 14800014  | Already closed. |
5215| 14800015  | The database does not respond. |
5216| 14800021  | SQLite: Generic error. |
5217| 14800022  | SQLite: Callback routine requested an abort. |
5218| 14800023  | SQLite: Access permission denied. |
5219| 14800024  | SQLite: The database file is locked. |
5220| 14800025  | SQLite: A table in the database is locked. |
5221| 14800026  | SQLite: The database is out of memory. |
5222| 14800027  | SQLite: Attempt to write a readonly database. |
5223| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5224| 14800029  | SQLite: The database is full. |
5225| 14800030  | SQLite: Unable to open the database file. |
5226| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5227| 14800032  | SQLite: Abort due to constraint violation. |
5228| 14800033  | SQLite: Data type mismatch. |
5229| 14800034  | SQLite: Library used incorrectly. |
5230
5231**示例:**
5232
5233```ts
5234if(store != undefined) {
5235  (store as relationalStore.RdbStore).backup("dbBackup.db", (err) => {
5236    if (err) {
5237      console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
5238      return;
5239    }
5240    console.info('Backup success.');
5241  })
5242}
5243```
5244
5245### backup
5246
5247backup(destName:string): Promise&lt;void&gt;
5248
5249以指定名称备份数据库,使用Promise异步回调。
5250
5251**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5252
5253**参数:**
5254
5255| 参数名   | 类型   | 必填 | 说明                     |
5256| -------- | ------ | ---- | ------------------------ |
5257| destName | string | 是   | 指定数据库的备份文件名。 |
5258
5259**返回值**:
5260
5261| 类型                | 说明                      |
5262| ------------------- | ------------------------- |
5263| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5264
5265**错误码:**
5266
5267以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5268
5269| **错误码ID** | **错误信息**                                                 |
5270|-----------| ------------------------------------------------------------ |
5271| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5272| 14800000  | Inner error. |
5273| 14800011  | Database corrupted. |
5274| 14800014  | Already closed. |
5275| 14800015  | The database does not respond. |
5276| 14800021  | SQLite: Generic error. |
5277| 14800022  | SQLite: Callback routine requested an abort. |
5278| 14800023  | SQLite: Access permission denied. |
5279| 14800024  | SQLite: The database file is locked. |
5280| 14800025  | SQLite: A table in the database is locked. |
5281| 14800026  | SQLite: The database is out of memory. |
5282| 14800027  | SQLite: Attempt to write a readonly database. |
5283| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5284| 14800029  | SQLite: The database is full. |
5285| 14800030  | SQLite: Unable to open the database file. |
5286| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5287| 14800032  | SQLite: Abort due to constraint violation. |
5288| 14800033  | SQLite: Data type mismatch. |
5289| 14800034  | SQLite: Library used incorrectly. |
5290
5291**示例:**
5292
5293```ts
5294import { BusinessError } from '@kit.BasicServicesKit';
5295
5296if(store != undefined) {
5297  let promiseBackup = (store as relationalStore.RdbStore).backup("dbBackup.db");
5298  promiseBackup.then(() => {
5299    console.info('Backup success.');
5300  }).catch((err: BusinessError) => {
5301    console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
5302  })
5303}
5304```
5305
5306### restore
5307
5308restore(srcName:string, callback: AsyncCallback&lt;void&gt;):void
5309
5310从指定的数据库备份文件恢复数据库,使用callback异步回调。
5311
5312**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5313
5314**参数:**
5315
5316| 参数名   | 类型                      | 必填 | 说明                     |
5317| -------- | ------------------------- | ---- | ------------------------ |
5318| srcName  | string                    | 是   | 指定数据库的备份文件名。 |
5319| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。   |
5320
5321**错误码:**
5322
5323以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5324
5325| **错误码ID** | **错误信息**                                                 |
5326|-----------| ------------------------------------------------------------ |
5327| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5328| 14800000  | Inner error. |
5329| 14800011  | Database corrupted. |
5330| 14800014  | Already closed. |
5331| 14800015  | The database does not respond. |
5332| 14800021  | SQLite: Generic error. |
5333| 14800022  | SQLite: Callback routine requested an abort. |
5334| 14800023  | SQLite: Access permission denied. |
5335| 14800024  | SQLite: The database file is locked. |
5336| 14800025  | SQLite: A table in the database is locked. |
5337| 14800026  | SQLite: The database is out of memory. |
5338| 14800027  | SQLite: Attempt to write a readonly database. |
5339| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5340| 14800029  | SQLite: The database is full. |
5341| 14800030  | SQLite: Unable to open the database file. |
5342| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5343| 14800032  | SQLite: Abort due to constraint violation. |
5344| 14800033  | SQLite: Data type mismatch. |
5345| 14800034  | SQLite: Library used incorrectly. |
5346
5347**示例:**
5348
5349```ts
5350if(store != undefined) {
5351  (store as relationalStore.RdbStore).restore("dbBackup.db", (err) => {
5352    if (err) {
5353      console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
5354      return;
5355    }
5356    console.info('Restore success.');
5357  })
5358}
5359```
5360
5361### restore
5362
5363restore(srcName:string): Promise&lt;void&gt;
5364
5365从指定的数据库备份文件恢复数据库,使用Promise异步回调。
5366
5367**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5368
5369**参数:**
5370
5371| 参数名  | 类型   | 必填 | 说明                     |
5372| ------- | ------ | ---- | ------------------------ |
5373| srcName | string | 是   | 指定数据库的备份文件名。 |
5374
5375**返回值**:
5376
5377| 类型                | 说明                      |
5378| ------------------- | ------------------------- |
5379| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5380
5381**错误码:**
5382
5383以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5384
5385| **错误码ID** | **错误信息**                                                 |
5386|-----------| ------------------------------------------------------------ |
5387| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5388| 14800000  | Inner error. |
5389| 14800011  | Database corrupted. |
5390| 14800014  | Already closed. |
5391| 14800015  | The database does not respond. |
5392| 14800021  | SQLite: Generic error. |
5393| 14800022  | SQLite: Callback routine requested an abort. |
5394| 14800023  | SQLite: Access permission denied. |
5395| 14800024  | SQLite: The database file is locked. |
5396| 14800025  | SQLite: A table in the database is locked. |
5397| 14800026  | SQLite: The database is out of memory. |
5398| 14800027  | SQLite: Attempt to write a readonly database. |
5399| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5400| 14800029  | SQLite: The database is full. |
5401| 14800030  | SQLite: Unable to open the database file. |
5402| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5403| 14800032  | SQLite: Abort due to constraint violation. |
5404| 14800033  | SQLite: Data type mismatch. |
5405| 14800034  | SQLite: Library used incorrectly. |
5406
5407**示例:**
5408
5409```ts
5410import { BusinessError } from '@kit.BasicServicesKit';
5411
5412if(store != undefined) {
5413  let promiseRestore = (store as relationalStore.RdbStore).restore("dbBackup.db");
5414  promiseRestore.then(() => {
5415    console.info('Restore success.');
5416  }).catch((err: BusinessError) => {
5417    console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
5418  })
5419}
5420```
5421
5422### setDistributedTables
5423
5424setDistributedTables(tables: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
5425
5426设置分布式数据库表,使用callback异步回调。
5427
5428**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5429
5430**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5431
5432**参数:**
5433
5434| 参数名   | 类型                      | 必填 | 说明                   |
5435| -------- | ------------------------- | ---- | ---------------------- |
5436| tables   | Array&lt;string&gt;       | 是   | 要设置的分布式数据库表表名。 |
5437| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。 |
5438
5439**错误码:**
5440
5441以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5442
5443| **错误码ID** | **错误信息**                                                 |
5444|-----------| ------------------------------------------------------------ |
5445| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5446| 801       | Capability not supported. |
5447| 14800000  | Inner error. |
5448| 14800014  | Already closed. |
5449
5450**示例:**
5451
5452```ts
5453if(store != undefined) {
5454  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], (err) => {
5455    if (err) {
5456      console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5457      return;
5458    }
5459    console.info('SetDistributedTables successfully.');
5460  })
5461}
5462```
5463
5464### setDistributedTables
5465
5466 setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt;
5467
5468设置分布式数据库表,使用Promise异步回调。
5469
5470**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5471
5472**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5473
5474**参数:**
5475
5476| 参数名 | 类型                     | 必填 | 说明                     |
5477| ------ | ------------------------ | ---- | ------------------------ |
5478| tables | ArrayArray&lt;string&gt; | 是   | 要设置的分布式数据库表表名。 |
5479
5480**返回值**:
5481
5482| 类型                | 说明                      |
5483| ------------------- | ------------------------- |
5484| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5485
5486**错误码:**
5487
5488以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5489
5490| **错误码ID** | **错误信息**                                                 |
5491|-----------| ------------------------------------------------------------ |
5492| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5493| 801       | Capability not supported. |
5494| 14800000  | Inner error. |
5495| 14800014  | Already closed. |
5496
5497**示例:**
5498
5499```ts
5500import { BusinessError } from '@kit.BasicServicesKit';
5501
5502if(store != undefined) {
5503  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"]).then(() => {
5504    console.info('SetDistributedTables successfully.');
5505  }).catch((err: BusinessError) => {
5506    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5507  })
5508}
5509```
5510
5511### setDistributedTables<sup>10+</sup>
5512
5513setDistributedTables(tables: Array&lt;string&gt;, type: DistributedType, callback: AsyncCallback&lt;void&gt;): void
5514
5515设置分布式数据库表,使用callback异步回调。
5516
5517**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5518
5519**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5520
5521**参数:**
5522
5523| 参数名   | 类型                                  | 必填 | 说明                         |
5524| -------- | ------------------------------------- | ---- | ---------------------------- |
5525| tables   | Array&lt;string&gt;                   | 是   | 要设置的分布式数据库表表名。 |
5526| type     | [DistributedType](#distributedtype10) | 是   | 表的分布式类型。             |
5527| callback | AsyncCallback&lt;void&gt;             | 是   | 指定callback回调函数。       |
5528
5529**错误码:**
5530
5531以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5532
5533| **错误码ID** | **错误信息**                                                 |
5534|-----------| ------------------------------------------------------------ |
5535| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5536| 801       | Capability not supported. |
5537| 14800000  | Inner error. |
5538| 14800014  | Already closed. |
5539| 14800051  | The type of the distributed table does not match. |
5540
5541**示例:**
5542
5543```ts
5544if(store != undefined) {
5545  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, (err) => {
5546    if (err) {
5547      console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5548      return;
5549    }
5550    console.info('SetDistributedTables successfully.');
5551  })
5552}
5553```
5554
5555### setDistributedTables<sup>10+</sup>
5556
5557setDistributedTables(tables: Array&lt;string&gt;, type: DistributedType, config: DistributedConfig, callback: AsyncCallback&lt;void&gt;): void
5558
5559设置分布式数据库表,使用callback异步回调。
5560
5561**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5562
5563**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5564
5565**参数:**
5566
5567| 参数名      | 类型                                  | 必填  | 说明              |
5568| -------- | ----------------------------------- | --- | --------------- |
5569| tables   | Array&lt;string&gt;                 | 是   | 要设置的分布式数据库表表名。     |
5570| type     | [DistributedType](#distributedtype10) | 是   | 表的分布式类型。 |
5571| config | [DistributedConfig](#distributedconfig10) | 是 | 表的分布式配置信息。 |
5572| callback | AsyncCallback&lt;void&gt;           | 是   | 指定callback回调函数。 |
5573
5574**错误码:**
5575
5576以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5577
5578| **错误码ID** | **错误信息**                                                 |
5579|-----------| ------------------------------------------------------------ |
5580| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5581| 801       | Capability not supported. |
5582| 14800000  | Inner error. |
5583| 14800014  | Already closed. |
5584| 14800051  | The type of the distributed table does not match. |
5585
5586**示例:**
5587
5588```ts
5589if(store != undefined) {
5590  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, {
5591    autoSync: true
5592  }, (err) => {
5593    if (err) {
5594      console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5595      return;
5596    }
5597    console.info('SetDistributedTables successfully.');
5598  })
5599}
5600```
5601
5602### setDistributedTables<sup>10+</sup>
5603
5604 setDistributedTables(tables: Array&lt;string>, type?: DistributedType, config?: DistributedConfig): Promise&lt;void>
5605
5606设置分布式数据库表,使用Promise异步回调。
5607
5608**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5609
5610**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5611
5612**参数:**
5613
5614| 参数名 | 类型                                      | 必填 | 说明                                                         |
5615| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ |
5616| tables | Array&lt;string&gt;                       | 是   | 要设置的分布式数据库表表名。                                 |
5617| type   | [DistributedType](#distributedtype10)     | 否   | 表的分布式类型。默认值是relationalStore.DistributedType.DISTRIBUTED_DEVICE。 |
5618| config | [DistributedConfig](#distributedconfig10) | 否   | 表的分布式配置信息。不传入时默认autoSync为false,即只支持手动同步。 |
5619
5620**返回值**:
5621
5622| 类型                | 说明                      |
5623| ------------------- | ------------------------- |
5624| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5625
5626**错误码:**
5627
5628以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5629
5630| **错误码ID** | **错误信息**                                                 |
5631|-----------| ------------------------------------------------------------ |
5632| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5633| 801       | Capability not supported. |
5634| 14800000  | Inner error. |
5635| 14800014  | Already closed. |
5636| 14800051  | The type of the distributed table does not match. |
5637
5638**示例:**
5639
5640```ts
5641import { BusinessError } from '@kit.BasicServicesKit';
5642
5643if(store != undefined) {
5644  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, {
5645    autoSync: true
5646  }).then(() => {
5647    console.info('SetDistributedTables successfully.');
5648  }).catch((err: BusinessError) => {
5649    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5650  })
5651}
5652```
5653
5654### obtainDistributedTableName
5655
5656obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void
5657
5658根据远程设备的本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名, 使用callback异步回调。
5659
5660> **说明:**
5661>
5662> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
5663
5664**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5665
5666**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5667
5668**参数:**
5669
5670| 参数名   | 类型                        | 必填 | 说明                                                         |
5671| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
5672| device   | string                      | 是   | 远程设备ID 。                                                |
5673| table    | string                      | 是   | 远程设备的本地表名。                                         |
5674| callback | AsyncCallback&lt;string&gt; | 是   | 指定的callback回调函数。如果操作成功,返回远程设备的分布式表名。 |
5675
5676**错误码:**
5677
5678以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5679
5680| **错误码ID** | **错误信息**                                                 |
5681|-----------| ------------------------------------------------------------ |
5682| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5683| 801       | Capability not supported. |
5684| 14800000  | Inner error. |
5685| 14800014  | Already closed. |
5686
5687**示例:**
5688
5689```ts
5690import { distributedDeviceManager } from '@kit.DistributedServiceKit';
5691import { BusinessError } from '@kit.BasicServicesKit';
5692
5693let dmInstance: distributedDeviceManager.DeviceManager;
5694let deviceId: string | undefined = undefined;
5695
5696try {
5697  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
5698  let devices = dmInstance.getAvailableDeviceListSync();
5699  deviceId = devices[0].networkId;
5700} catch (err) {
5701  let code = (err as BusinessError).code;
5702  let message = (err as BusinessError).message
5703  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
5704}
5705
5706if(store != undefined && deviceId != undefined) {
5707  (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE", (err, tableName) => {
5708    if (err) {
5709      console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
5710      return;
5711    }
5712    console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
5713  })
5714}
5715```
5716
5717### obtainDistributedTableName
5718
5719 obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt;
5720
5721根据远程设备的本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名,使用Promise异步回调。
5722
5723> **说明:**
5724>
5725> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
5726
5727**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5728
5729**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5730
5731**参数:**
5732
5733| 参数名 | 类型   | 必填 | 说明                 |
5734| ------ | ------ | ---- | -------------------- |
5735| device | string | 是   | 远程设备ID。         |
5736| table  | string | 是   | 远程设备的本地表名。 |
5737
5738**返回值**:
5739
5740| 类型                  | 说明                                                  |
5741| --------------------- | ----------------------------------------------------- |
5742| Promise&lt;string&gt; | Promise对象。如果操作成功,返回远程设备的分布式表名。 |
5743
5744**错误码:**
5745
5746以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5747
5748| **错误码ID** | **错误信息**                                                 |
5749|-----------| ------------------------------------------------------------ |
5750| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5751| 801       | Capability not supported. |
5752| 14800000  | Inner error. |
5753| 14800014  | Already closed. |
5754
5755**示例:**
5756
5757```ts
5758import { distributedDeviceManager } from '@kit.DistributedServiceKit';
5759import { BusinessError } from '@kit.BasicServicesKit';
5760
5761let dmInstance: distributedDeviceManager.DeviceManager;
5762let deviceId: string | undefined = undefined;
5763
5764try {
5765  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
5766  let devices = dmInstance.getAvailableDeviceListSync();
5767  deviceId = devices[0].networkId;
5768} catch (err) {
5769  let code = (err as BusinessError).code;
5770  let message = (err as BusinessError).message
5771  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
5772}
5773
5774if(store != undefined && deviceId != undefined) {
5775  (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE").then((tableName: string) => {
5776    console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
5777  }).catch((err: BusinessError) => {
5778    console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
5779  })
5780}
5781```
5782
5783### sync
5784
5785sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback&lt;Array&lt;[string, number]&gt;&gt;): void
5786
5787在设备之间同步数据, 使用callback异步回调。
5788
5789**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5790
5791**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5792
5793**参数:**
5794
5795| 参数名     | 类型                                               | 必填 | 说明                                                         |
5796| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
5797| mode       | [SyncMode](#syncmode)                             | 是   | 指同步模式。该值可以是relationalStore.SyncMode.SYNC_MODE_PUSHrelationalStore.SyncMode.SYNC_MODE_PULL。                               |
5798| predicates | [RdbPredicates](#rdbpredicates)               | 是   | 约束同步数据和设备。                                         |
5799| callback   | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | 是   | 指定的callback回调函数,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 |
5800
5801**错误码:**
5802
5803以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5804
5805| **错误码ID** | **错误信息**                                                 |
5806|-----------| ------------------------------------------------------------ |
5807| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5808| 801       | Capability not supported. |
5809| 14800000  | Inner error. |
5810| 14800014  | Already closed. |
5811
5812**示例:**
5813
5814```ts
5815import { distributedDeviceManager } from '@kit.DistributedServiceKit';
5816import { BusinessError } from '@kit.BasicServicesKit';
5817
5818let dmInstance: distributedDeviceManager.DeviceManager;
5819let deviceIds: Array<string> = [];
5820
5821try {
5822  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
5823  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
5824  for (let i = 0; i < devices.length; i++) {
5825    deviceIds[i] = devices[i].networkId!;
5826  }
5827} catch (err) {
5828  let code = (err as BusinessError).code;
5829  let message = (err as BusinessError).message
5830  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
5831}
5832
5833let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
5834predicates.inDevices(deviceIds);
5835if(store != undefined) {
5836  (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, (err, result) => {
5837    if (err) {
5838      console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
5839      return;
5840    }
5841    console.info('Sync done.');
5842    for (let i = 0; i < result.length; i++) {
5843      console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
5844    }
5845  })
5846}
5847```
5848
5849### sync
5850
5851 sync(mode: SyncMode, predicates: RdbPredicates): Promise&lt;Array&lt;[string, number]&gt;&gt;
5852
5853在设备之间同步数据,使用Promise异步回调。
5854
5855**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5856
5857**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5858
5859**参数:**
5860
5861| 参数名     | 类型                                 | 必填 | 说明                           |
5862| ---------- | ------------------------------------ | ---- | ------------------------------ |
5863| mode       | [SyncMode](#syncmode)               | 是   | 指同步模式。该值可以是relationalStore.SyncMode.SYNC_MODE_PUSHrelationalStore.SyncMode.SYNC_MODE_PULL。 |
5864| predicates | [RdbPredicates](#rdbpredicates) | 是   | 约束同步数据和设备。           |
5865
5866**返回值**:
5867
5868| 类型                                         | 说明                                                         |
5869| -------------------------------------------- | ------------------------------------------------------------ |
5870| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise对象,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 |
5871
5872**错误码:**
5873
5874以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5875
5876| **错误码ID** | **错误信息**                                                 |
5877|-----------| ------------------------------------------------------------ |
5878| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5879| 801       | Capability not supported. |
5880| 14800000  | Inner error. |
5881| 14800014  | Already closed. |
5882
5883**示例:**
5884
5885```ts
5886import { distributedDeviceManager } from '@kit.DistributedServiceKit';
5887import { BusinessError } from '@kit.BasicServicesKit';
5888
5889let dmInstance: distributedDeviceManager.DeviceManager;
5890let deviceIds: Array<string> = [];
5891
5892try {
5893  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
5894  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
5895  for (let i = 0; i < devices.length; i++) {
5896    deviceIds[i] = devices[i].networkId!;
5897  }
5898} catch (err) {
5899  let code = (err as BusinessError).code;
5900  let message = (err as BusinessError).message
5901  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
5902}
5903
5904let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
5905predicates.inDevices(deviceIds);
5906if(store != undefined) {
5907  (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates).then((result: Object[][]) => {
5908    console.info('Sync done.');
5909    for (let i = 0; i < result.length; i++) {
5910      console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
5911    }
5912  }).catch((err: BusinessError) => {
5913    console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
5914  })
5915}
5916```
5917
5918### cloudSync<sup>10+</sup>
5919
5920cloudSync(mode: SyncMode, progress: Callback&lt;ProgressDetails&gt;, callback: AsyncCallback&lt;void&gt;): void
5921
5922手动执行对所有分布式表的端云同步,使用callback异步回调。使用该接口需要实现云服务功能。
5923
5924**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
5925
5926**参数:**
5927
5928| 参数名   | 类型                                                  | 必填 | 说明                                               |
5929| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
5930| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                             |
5931| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。             |
5932| callback | AsyncCallback&lt;void&gt;                             | 是   | 指定的callback回调函数,用于向调用者发送同步结果。 |
5933
5934**错误码:**
5935
5936以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5937
5938| **错误码ID** | **错误信息**        |
5939|-----------|-------|
5940| 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. |
5941| 801       | Capability not supported.       |
5942| 14800014  | Already closed.        |
5943
5944**示例:**
5945
5946```ts
5947if(store != undefined) {
5948  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetails) => {
5949    console.info(`Progess: ${progressDetails}`);
5950  }, (err) => {
5951    if (err) {
5952      console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`);
5953      return;
5954    }
5955    console.info('Cloud sync succeeded');
5956  });
5957}
5958```
5959
5960### cloudSync<sup>10+</sup>
5961
5962cloudSync(mode: SyncMode, progress: Callback&lt;ProgressDetails&gt;): Promise&lt;void&gt;
5963
5964手动执行对所有分布式表的端云同步,使用Promise异步回调。使用该接口需要实现云服务功能。
5965
5966**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
5967
5968**参数:**
5969
5970| 参数名   | 类型                                                  | 必填 | 说明                                   |
5971| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
5972| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                 |
5973| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。 |
5974
5975**返回值**:
5976
5977| 类型                | 说明                                    |
5978| ------------------- | --------------------------------------- |
5979| Promise&lt;void&gt; | Promise对象,用于向调用者发送同步结果。 |
5980
5981**错误码:**
5982
5983以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5984
5985| **错误码ID** | **错误信息**    |
5986|-----------|------------------|
5987| 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. |
5988| 801       | Capability not supported.   |
5989| 14800014  | Already closed.           |
5990
5991**示例:**
5992
5993```ts
5994import { BusinessError } from '@kit.BasicServicesKit';
5995
5996if(store != undefined) {
5997  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetail: relationalStore.ProgressDetails) => {
5998    console.info(`progress: ${progressDetail}`);
5999  }).then(() => {
6000    console.info('Cloud sync succeeded');
6001  }).catch((err: BusinessError) => {
6002    console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`);
6003  });
6004}
6005```
6006
6007### cloudSync<sup>10+</sup>
6008
6009cloudSync(mode: SyncMode, tables: string[], progress: Callback&lt;ProgressDetails&gt;, callback: AsyncCallback&lt;void&gt;): void
6010
6011手动执行对指定表的端云同步,使用callback异步回调。使用该接口需要实现云服务功能。
6012
6013**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6014
6015**参数:**
6016
6017| 参数名   | 类型                                                  | 必填 | 说明                                               |
6018| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
6019| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                             |
6020| tables   | string[]                                              | 是   | 指定同步的表名。                                   |
6021| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。             |
6022| callback | AsyncCallback&lt;void&gt;                             | 是   | 指定的callback回调函数,用于向调用者发送同步结果。 |
6023
6024**错误码:**
6025
6026以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6027
6028| **错误码ID** | **错误信息**                                                                                                                                                                                                                  |
6029|-----------|-------|
6030| 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.|
6031| 801       | Capability not supported.   |
6032| 14800014  | Already closed.   |
6033
6034**示例:**
6035
6036```ts
6037const tables = ["table1", "table2"];
6038
6039if(store != undefined) {
6040  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => {
6041    console.info(`Progess: ${progressDetail}`);
6042  }, (err) => {
6043    if (err) {
6044      console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`);
6045      return;
6046    }
6047    console.info('Cloud sync succeeded');
6048  });
6049};
6050```
6051
6052### cloudSync<sup>10+</sup>
6053
6054cloudSync(mode: SyncMode, tables: string[], progress: Callback&lt;ProgressDetails&gt;): Promise&lt;void&gt;
6055
6056手动执行对指定表的端云同步,使用Promise异步回调。使用该接口需要实现云服务功能。
6057
6058**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6059
6060**参数:**
6061
6062| 参数名   | 类型                                                  | 必填 | 说明                                   |
6063| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
6064| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                 |
6065| tables   | string[]                                              | 是   | 指定同步的表名。                       |
6066| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。 |
6067
6068**返回值**:
6069
6070| 类型                | 说明                                    |
6071| ------------------- | --------------------------------------- |
6072| Promise&lt;void&gt; | Promise对象,用于向调用者发送同步结果。 |
6073
6074**错误码:**
6075
6076以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6077
6078| **错误码ID** | **错误信息**     |
6079|-----------|---------------|
6080| 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 |
6081| 801       | Capability not supported.    |
6082| 14800014  | Already closed.  |
6083
6084**示例:**
6085
6086```ts
6087import { BusinessError } from '@kit.BasicServicesKit';
6088
6089const tables = ["table1", "table2"];
6090
6091if(store != undefined) {
6092  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => {
6093    console.info(`progress: ${progressDetail}`);
6094  }).then(() => {
6095    console.info('Cloud sync succeeded');
6096  }).catch((err: BusinessError) => {
6097    console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`);
6098  });
6099};
6100```
6101
6102### on('dataChange')
6103
6104on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
6105
6106注册数据库的数据变更的事件监听。当分布式数据库中的数据发生更改时,将调用回调。
6107
6108**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6109
6110**参数:**
6111
6112| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6113| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6114| event    | string                                                       | 是   | 取值为'dataChange',表示数据更改。                           |
6115| type     | [SubscribeType](#subscribetype)                              | 是   | 订阅类型。                                                   |
6116| observer | Callback&lt;Array&lt;string&gt;&gt;                          | 是   | 指分布式数据库中数据更改事件的观察者。Array&lt;string&gt;为数据库中的数据发生改变的对端设备ID。 |
6117
6118**错误码:**
6119
6120以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6121
6122| **错误码ID** | **错误信息**        |
6123|-----------|-------------|
6124| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6125| 801       | Capability not supported. |
6126| 14800014  | Already closed.    |
6127
6128**示例:**
6129
6130```ts
6131import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6132import { BusinessError } from '@kit.BasicServicesKit';
6133
6134let storeObserver = (devices: Array<string>) => {
6135  if (devices != undefined) {
6136    for (let i = 0; i < devices.length; i++) {
6137      console.info(`device= ${devices[i]} data changed`);
6138    }
6139  }
6140}
6141
6142try {
6143  if (store != undefined) {
6144    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
6145  }
6146} catch (err) {
6147    let code = (err as BusinessError).code;
6148    let message = (err as BusinessError).message
6149    console.error(`Register observer failed, code is ${code},message is ${message}`);
6150}
6151```
6152
6153### on('dataChange')<sup>10+</sup>
6154
6155on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;ChangeInfo&gt;&gt;): void
6156
6157注册数据库的数据变更的事件监听。当分布式数据库或本地数据库中的数据发生更改时,将调用回调。
6158
6159**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6160
6161**参数:**
6162
6163| 参数名   | 类型                                | 必填 | 说明                                        |
6164| -------- | ----------------------------------- | ---- | ------------------------------------------- |
6165| event    | string                              | 是   | 取值为'dataChange',表示数据更改。          |
6166| type     | [SubscribeType](#subscribetype)    | 是   | 订阅类型。 |
6167| 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;为本地数据库中的数据更改的详情。 |
6168
6169**错误码:**
6170
6171以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6172
6173| **错误码ID** | **错误信息**        |
6174|-----------|-------------|
6175| 202       | Permission verification failed, application which is not a system application uses system API. |
6176| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6177| 801       | Capability not supported. |
6178| 14800014  | Already closed.    |
6179
6180**示例1:type为SUBSCRIBE_TYPE_REMOTE**
6181
6182```ts
6183import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6184import { BusinessError } from '@kit.BasicServicesKit';
6185
6186let storeObserver = (devices: Array<string>) => {
6187  if (devices != undefined) {
6188    for (let i = 0; i < devices.length; i++) {
6189      console.info(`device= ${devices[i]} data changed`);
6190    }
6191  }
6192}
6193
6194try {
6195  if(store != undefined) {
6196    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6197  }
6198} catch (err) {
6199  let code = (err as BusinessError).code;
6200  let message = (err as BusinessError).message;
6201  console.error(`Register observer failed, code is ${code},message is ${message}`);
6202}
6203```
6204
6205**示例2:type为SUBSCRIBE_TYPE_LOCAL_DETAILS**
6206
6207```ts
6208import { BusinessError } from '@kit.BasicServicesKit';
6209
6210let changeInfos = (changeInfos: Array<relationalStore.ChangeInfo>) => {
6211  for (let i = 0; i < changeInfos.length; i++) {
6212    console.info(`changeInfos = ${changeInfos[i]}`);
6213  }
6214}
6215
6216try {
6217  if(store != undefined) {
6218    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_LOCAL_DETAILS, changeInfos);
6219  }
6220} catch (err) {
6221  let code = (err as BusinessError).code;
6222  let message = (err as BusinessError).message;
6223  console.error(`on dataChange fail, code is ${code},message is ${message}`);
6224}
6225
6226let value1 = "Lisa";
6227let value2 = 18;
6228let value3 = 100.5;
6229let value4 = new Uint8Array([1, 2, 3]);
6230
6231try {
6232  const valueBucket: relationalStore.ValuesBucket = {
6233    'name': value1,
6234    'age': value2,
6235    'salary': value3,
6236    'blobType': value4,
6237  };
6238
6239  if(store != undefined) {
6240    (store as relationalStore.RdbStore).insert('test', valueBucket);
6241  }
6242} catch (err) {
6243  let code = (err as BusinessError).code;
6244  let message = (err as BusinessError).message;
6245  console.error(`insert fail, code is ${code},message is ${message}`);
6246}
6247```
6248
6249### on<sup>10+</sup>
6250
6251on(event: string, interProcess: boolean, observer: Callback\<void>): void
6252
6253注册数据库的进程内或者进程间事件监听。当调用[emit](#emit10)接口时,将调用回调。
6254
6255**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6256
6257**参数:**
6258
6259| 参数名       | 类型            | 必填 | 说明                                                         |
6260| ------------ | --------------- | ---- | ------------------------------------------------------------ |
6261| event        | string          | 是   | 订阅事件名称。                                               |
6262| interProcess | boolean         | 是   | 指定是进程间还是本进程订阅。<br/> true:进程间。<br/> false:本进程。 |
6263| observer     | Callback\<void> | 是   | 回调函数。                                                   |
6264
6265**错误码:**
6266
6267以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6268
6269| **错误码ID** | **错误信息**        |
6270|-----------|-------------|
6271| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6272| 801       | Capability not supported. |
6273| 14800000  | Inner error.    |
6274| 14800014  | Already closed.    |
6275| 14800050  | Failed to obtain the subscription service.    |
6276
6277**示例:**
6278
6279```ts
6280import { BusinessError } from '@kit.BasicServicesKit';
6281
6282let storeObserver = () => {
6283  console.info(`storeObserver`);
6284}
6285
6286try {
6287  if(store != undefined) {
6288    (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver);
6289  }
6290} catch (err) {
6291  let code = (err as BusinessError).code;
6292  let message = (err as BusinessError).message
6293  console.error(`Register observer failed, code is ${code},message is ${message}`);
6294}
6295```
6296
6297### on('autoSyncProgress')<sup>11+</sup>
6298
6299on(event: 'autoSyncProgress', progress: Callback&lt;ProgressDetails&gt;): void
6300
6301在已打开端云同步,并且网络状态正常的条件下,注册自动同步进度通知,自动同步进行时调用回调。
6302
6303**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6304
6305**参数:**
6306
6307| 参数名       | 类型                              | 必填 | 说明                                |
6308| ------------ |---------------------------------| ---- |-----------------------------------|
6309| event        | string                          | 是   | 取值为'autoSyncProgress',表示自动同步进度通知。 |
6310| progress     | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 回调函数。                             |
6311
6312**错误码:**
6313
6314以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6315
6316| **错误码ID** | **错误信息**    |
6317|-----------|--------|
6318| 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. |
6319| 801       | Capability not supported.  |
6320| 14800014  | Already closed.     |
6321
6322**示例:**
6323
6324```ts
6325import { BusinessError } from '@kit.BasicServicesKit';
6326
6327let progressDetail = (progressDetail: relationalStore.ProgressDetails) => {
6328  console.info(`progress: ${progressDetail}`);
6329}
6330
6331try {
6332  if(store != undefined) {
6333    (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail)
6334  }
6335} catch (err) {
6336  let code = (err as BusinessError).code;
6337  let message = (err as BusinessError).message
6338  console.error(`Register observer failed, code is ${code},message is ${message}`);
6339}
6340```
6341
6342### on('statistics')<sup>12+</sup>
6343
6344on(event: 'statistics', observer: Callback&lt;SqlExecutionInfo&gt;): void
6345
6346订阅SQL统计信息。
6347
6348**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6349
6350**参数:**
6351
6352| 参数名       | 类型                              | 必填 | 说明                                |
6353| ------------ |---------------------------------| ---- |-----------------------------------|
6354| event        | string                          | 是   | 订阅事件名称,取值为'statistics',表示sql执行时间的统计。 |
6355| observer     | Callback&lt;[SqlExecutionInfo](#sqlexecutioninfo12)&gt; | 是   | 回调函数。用于返回数据库中SQL执行时间的统计信息。  |
6356
6357**错误码:**
6358
6359以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6360
6361| **错误码ID** | **错误信息**    |
6362|-----------|--------|
6363| 401       | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
6364| 801       | Capability not supported.  |
6365| 14800000  | Inner error.  |
6366| 14800014  | Already closed.     |
6367
6368**示例:**
6369
6370```ts
6371import { BusinessError } from '@kit.BasicServicesKit';
6372
6373let sqlExecutionInfo = (sqlExecutionInfo: relationalStore.SqlExecutionInfo) => {
6374  console.info(`sql: ${sqlExecutionInfo.sql[0]}`);
6375  console.info(`totalTime: ${sqlExecutionInfo.totalTime}`);
6376  console.info(`waitTime: ${sqlExecutionInfo.waitTime}`);
6377  console.info(`prepareTime: ${sqlExecutionInfo.prepareTime}`);
6378  console.info(`executeTime: ${sqlExecutionInfo.executeTime}`);
6379}
6380
6381try {
6382  if(store != undefined) {
6383    (store as relationalStore.RdbStore).on('statistics', sqlExecutionInfo);
6384  }
6385} catch (err) {
6386  let code = (err as BusinessError).code;
6387  let message = (err as BusinessError).message;
6388  console.error(`Register observer failed, code is ${code},message is ${message}`);
6389}
6390
6391try {
6392  let value1 = "Lisa";
6393  let value2 = 18;
6394  let value3 = 100.5;
6395  let value4 = new Uint8Array([1, 2, 3, 4, 5]);
6396
6397  const valueBucket: relationalStore.ValuesBucket = {
6398    'NAME': value1,
6399    'AGE': value2,
6400    'SALARY': value3,
6401    'CODES': value4,
6402  };
6403  if(store != undefined) {
6404    (store as relationalStore.RdbStore).insert('test', valueBucket);
6405  }
6406} catch (err) {
6407  console.error(`insert fail, code:${err.code}, message: ${err.message}`);
6408}
6409```
6410
6411### off('dataChange')
6412
6413off(event:'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
6414
6415取消数据变更的事件监听。
6416
6417**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6418
6419**参数:**
6420
6421| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6422| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6423| event    | string                                                       | 是   | 取值为'dataChange',表示数据更改。                           |
6424| type     | [SubscribeType](#subscribetype) | 是   | 订阅类型。                                                   |
6425| observer | Callback&lt;Array&lt;string&gt;&gt;                          | 是   | 指已注册的数据更改观察者。Array&lt;string&gt;为数据库中的数据发生改变的对端设备ID。 |
6426
6427**错误码:**
6428
6429以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6430
6431| **错误码ID** | **错误信息**        |
6432|-----------|-------------|
6433| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6434| 801       | Capability not supported. |
6435| 14800014  | Already closed.    |
6436
6437**示例:**
6438
6439```ts
6440import { BusinessError } from '@kit.BasicServicesKit';
6441
6442let storeObserver = (devices: Array<string>) => {
6443  if (devices != undefined) {
6444    for (let i = 0; i < devices.length; i++) {
6445      console.info(`device= ${devices[i]} data changed`);
6446    }
6447  }
6448}
6449
6450try {
6451  if (store != undefined) {
6452    // 此处不能使用Lambda表达式
6453    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
6454  }
6455} catch (err) {
6456    let code = (err as BusinessError).code;
6457    let message = (err as BusinessError).message
6458    console.error(`Register observer failed, code is ${code},message is ${message}`);
6459}
6460
6461try {
6462  if(store != undefined) {
6463    (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6464  }
6465} catch (err) {
6466  let code = (err as BusinessError).code;
6467  let message = (err as BusinessError).message
6468  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
6469}
6470```
6471
6472### off('dataChange')<sup>10+</sup>
6473
6474off(event:'dataChange', type: SubscribeType, observer?: Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;ChangeInfo&gt;&gt;): void
6475
6476取消数据变更的事件监听。
6477
6478**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6479
6480**参数:**
6481
6482| 参数名   | 类型                                | 必填 | 说明                                        |
6483| -------- | ---------------------------------- | ---- | ------------------------------------------ |
6484| event    | string                              | 是   | 取值为'dataChange',表示数据更改。          |
6485| type     | [SubscribeType](#subscribetype)     | 是   | 订阅类型。                                 |
6486| 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类型下所有数据变更的事件监听。 |
6487
6488**错误码:**
6489
6490以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6491
6492| **错误码ID** | **错误信息**        |
6493|-----------|-------------|
6494| 202       | Permission verification failed, application which is not a system application uses system API. |
6495| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6496| 801       | Capability not supported. |
6497| 14800014  | Already closed.    |
6498
6499**示例:**
6500
6501```ts
6502import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6503import { BusinessError } from '@kit.BasicServicesKit';
6504
6505let storeObserver = (devices: Array<string>) => {
6506  if (devices != undefined) {
6507    for (let i = 0; i < devices.length; i++) {
6508      console.info(`device= ${devices[i]} data changed`);
6509    }
6510  }
6511}
6512
6513try {
6514  if(store != undefined) {
6515    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6516  }
6517} catch (err) {
6518  let code = (err as BusinessError).code;
6519  let message = (err as BusinessError).message;
6520  console.error(`Register observer failed, code is ${code},message is ${message}`);
6521}
6522
6523try {
6524  if(store != undefined) {
6525    (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6526  }
6527} catch (err) {
6528  let code = (err as BusinessError).code;
6529  let message = (err as BusinessError).message
6530  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
6531}
6532```
6533
6534### off<sup>10+</sup>
6535
6536off(event: string, interProcess: boolean, observer?: Callback\<void>): void
6537
6538取消数据变更的事件监听。
6539
6540**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6541
6542**参数:**
6543
6544| 参数名       | 类型            | 必填 | 说明                                                         |
6545| ------------ | --------------- | ---- | ------------------------------------------------------------ |
6546| event        | string          | 是   | 取消订阅事件名称。                                           |
6547| interProcess | boolean         | 是   | 指定是进程间还是本进程取消订阅。<br/> true:进程间。<br/> false:本进程。 |
6548| observer     | Callback\<void> | 否   | 该参数存在,则取消指定Callback监听回调,否则取消该event事件的所有监听回调。 |
6549
6550**错误码:**
6551
6552以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6553
6554| **错误码ID** | **错误信息**                           |
6555| ------------ | -------------------------------------- |
6556| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6557| 801       | Capability not supported. |
6558| 14800000     | Inner error.                           |
6559| 14800014  | Already closed.    |
6560| 14800050     | Failed to obtain the subscription service. |
6561
6562**示例:**
6563
6564```ts
6565import { BusinessError } from '@kit.BasicServicesKit';
6566
6567let storeObserver = () => {
6568  console.info(`storeObserver`);
6569}
6570
6571try {
6572  if(store != undefined) {
6573    (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver);
6574  }
6575} catch (err) {
6576  let code = (err as BusinessError).code;
6577  let message = (err as BusinessError).message
6578  console.error(`Register observer failed, code is ${code},message is ${message}`);
6579}
6580
6581try {
6582  if(store != undefined) {
6583    (store as relationalStore.RdbStore).off('storeObserver', false, storeObserver);
6584  }
6585} catch (err) {
6586  let code = (err as BusinessError).code;
6587  let message = (err as BusinessError).message
6588  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
6589}
6590```
6591
6592### off('autoSyncProgress')<sup>11+</sup>
6593
6594off(event: 'autoSyncProgress', progress?: Callback&lt;ProgressDetails&gt;): void
6595
6596取消订阅自动同步进度的通知。
6597
6598**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6599
6600**参数:**
6601
6602| 参数名       | 类型                              | 必填 | 说明                                                               |
6603| ------------ |---------------------------------| ---- |------------------------------------------------------------------|
6604| event        | string                          | 是   | 取值为'autoSyncProgress',表示自动同步进度通知。                                |
6605| progress     | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 否   | 指已注册的自动同步进度观察者。该参数存在,则取消订阅指定回调,该参数为null或undefined或不存在,则取消订阅所有回调。 |
6606
6607**错误码:**
6608
6609以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6610
6611| **错误码ID** | **错误信息**         |
6612| ------------ |--------------------|
6613| 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. |
6614| 801       | Capability not supported.  |
6615| 14800014  | Already closed.       |
6616
6617**示例:**
6618
6619```ts
6620import { BusinessError } from '@kit.BasicServicesKit';
6621
6622let progressDetail = (progressDetail: relationalStore.ProgressDetails) => {
6623  console.info(`progress: ${progressDetail}`);
6624}
6625
6626try {
6627  if(store != undefined) {
6628    (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail)
6629  }
6630} catch (err) {
6631  let code = (err as BusinessError).code;
6632  let message = (err as BusinessError).message
6633  console.error(`Register observer failed, code is ${code},message is ${message}`);
6634}
6635
6636try {
6637  if(store != undefined) {
6638    (store as relationalStore.RdbStore).off('autoSyncProgress', progressDetail);
6639  }
6640} catch (err) {
6641  let code = (err as BusinessError).code;
6642  let message = (err as BusinessError).message;
6643  console.error(`Unregister failed, code is ${code},message is ${message}`);
6644}
6645```
6646
6647### off('statistics')<sup>12+</sup>
6648
6649off(event: 'statistics', observer?: Callback&lt;SqlExecutionInfo&gt;): void
6650
6651取消订阅SQL统计信息。
6652
6653**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6654
6655**参数:**
6656
6657| 参数名       | 类型                              | 必填 | 说明                                |
6658| ------------ |---------------------------------| ---- |-----------------------------------|
6659| event        | string                          | 是   | 取消订阅事件名称。取值为'statistics',表示sql执行时间的统计。 |
6660| observer     | Callback&lt;[SqlExecutionInfo](#sqlexecutioninfo12)&gt; | 否   | 回调函数。该参数存在,则取消指定Callback监听回调,否则取消该event事件的所有监听回调。  |
6661
6662
6663**错误码:**
6664
6665以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6666
6667| **错误码ID** | **错误信息**    |
6668|-----------|--------|
6669| 401       | Parameter error.  |
6670| 801       | Capability not supported.  |
6671| 14800000  | Inner error.  |
6672| 14800014  | Already closed.     |
6673
6674```ts
6675import { BusinessError } from '@kit.BasicServicesKit';
6676
6677try {
6678  if(store != undefined) {
6679    (store as relationalStore.RdbStore).off('statistics');
6680  }
6681} catch (err) {
6682  let code = (err as BusinessError).code;
6683  let message = (err as BusinessError).message;
6684  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
6685}
6686```
6687
6688### emit<sup>10+</sup>
6689
6690emit(event: string): void
6691
6692通知通过[on](#on10)注册的进程间或者进程内监听事件。
6693
6694**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6695
6696**参数:**
6697
6698| 参数名 | 类型   | 必填 | 说明                 |
6699| ------ | ------ | ---- | -------------------- |
6700| event  | string | 是   | 通知订阅事件的名称。 |
6701
6702**错误码:**
6703
6704以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6705
6706| **错误码ID** | **错误信息**                                                                                                      |
6707| --------- |---------------------------------------------------------------------------------------------------------------|
6708| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6709| 801       | Capability not supported.     |
6710| 14800000  | Inner error.   |
6711| 14800014  | Already closed.     |
6712| 14800050  | Failed to obtain the subscription service.    |
6713
6714
6715**示例:**
6716
6717```ts
6718if(store != undefined) {
6719  (store as relationalStore.RdbStore).emit('storeObserver');
6720}
6721```
6722
6723### cleanDirtyData<sup>11+</sup>
6724
6725cleanDirtyData(table: string, cursor: number, callback: AsyncCallback&lt;void&gt;): void
6726
6727清理云端删除的数据同步到本地后,未自动清理的,且数据的游标(cursor)小于指定游标的数据。
6728
6729**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6730
6731**参数:**
6732
6733| 参数名   | 类型                                                  | 必填 | 说明                                               |
6734| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
6735| table     | string                        | 是   | 表示当前数据库的表的名称。                             |
6736| cursor    | number                        | 是   | 整数类型,表示数据游标,小于此游标的脏数据将被清理。     |
6737| callback  | AsyncCallback&lt;void&gt;     | 是   | 指定的callback回调函数。 |
6738
6739**错误码:**
6740
6741以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
6742
6743| **错误码ID** | **错误信息**     |
6744|-----------|---------------|
6745| 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. |
6746| 801       | Capability not supported. |
6747| 14800000  | Inner error. |
6748| 14800011  | Database corrupted. |
6749| 14800014  | Already closed. |
6750| 14800015  | The database does not respond. |
6751| 14800021  | SQLite: Generic error. |
6752| 14800022  | SQLite: Callback routine requested an abort. |
6753| 14800023  | SQLite: Access permission denied. |
6754| 14800024  | SQLite: The database file is locked. |
6755| 14800025  | SQLite: A table in the database is locked. |
6756| 14800026  | SQLite: The database is out of memory. |
6757| 14800027  | SQLite: Attempt to write a readonly database. |
6758| 14800028  | SQLite: Some kind of disk I/O error occurred. |
6759| 14800029  | SQLite: The database is full. |
6760| 14800030  | SQLite: Unable to open the database file. |
6761| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
6762| 14800032  | SQLite: Abort due to constraint violation. |
6763| 14800033  | SQLite: Data type mismatch. |
6764| 14800034  | SQLite: Library used incorrectly. |
6765
6766**示例:**
6767
6768```ts
6769if(store != undefined) {
6770 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100, (err) => {
6771    if (err) {
6772      console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`);
6773      return;
6774    }
6775    console.info('clean dirty data succeeded');
6776  })
6777}
6778```
6779
6780### cleanDirtyData<sup>11+</sup>
6781
6782cleanDirtyData(table: string, callback: AsyncCallback&lt;void&gt;): void
6783
6784清理云端删除的数据同步到本地后,未自动清理的所有数据。
6785
6786**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6787
6788**参数:**
6789
6790| 参数名   | 类型                                                  | 必填 | 说明                                               |
6791| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
6792| table     | string                        | 是   | 表示当前数据库的表的名称。 |
6793| callback  | AsyncCallback&lt;void&gt;     | 是   | 指定的callback回调函数。 |
6794
6795**错误码:**
6796
6797以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
6798
6799| **错误码ID** | **错误信息**       |
6800|-----------|---------|
6801| 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. |
6802| 801       | Capability not supported.    |
6803| 14800000  | Inner error.        |
6804| 14800011  | Database corrupted.   |
6805| 14800014  | Already closed.       |
6806| 14800015  | The database does not respond.      |
6807| 14800021  | SQLite: Generic error.     |
6808| 14800022  | SQLite: Callback routine requested an abort. |
6809| 14800023  | SQLite: Access permission denied.           |
6810| 14800024  | SQLite: The database file is locked.        |
6811| 14800025  | SQLite: A table in the database is locked.  |
6812| 14800026  | SQLite: The database is out of memory.      |
6813| 14800027  | SQLite: Attempt to write a readonly database.   |
6814| 14800028  | SQLite: Some kind of disk I/O error occurred.  |
6815| 14800029  | SQLite: The database is full.                |
6816| 14800030  | SQLite: Unable to open the database file.            |
6817| 14800031  | SQLite: TEXT or BLOB exceeds size limit.             |
6818| 14800032  | SQLite: Abort due to constraint violation.   |
6819| 14800033  | SQLite: Data type mismatch.                  |
6820| 14800034  | SQLite: Library used incorrectly.          |
6821
6822**示例:**
6823
6824```ts
6825if(store != undefined) {
6826  (store as relationalStore.RdbStore).cleanDirtyData('test_table', (err) => {
6827    if (err) {
6828      console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`);
6829      return;
6830    }
6831    console.info('clean dirty data succeeded');
6832  })
6833}
6834```
6835
6836### cleanDirtyData<sup>11+</sup>
6837
6838cleanDirtyData(table: string, cursor?: number): Promise&lt;void&gt;
6839
6840清理云端删除的数据同步到本地后,未自动清理的,且数据的游标(cursor)小于指定游标的数据。若无cursor参数,将全部清理。
6841
6842**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6843
6844**参数:**
6845
6846| 参数名   | 类型                                                  | 必填 | 说明                                               |
6847| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
6848| table     | string           | 是   | 表示当前数据库的表的名称。           |
6849| cursor    | number           | 否   | 整数类型,表示数据游标,小于此游标的脏数据将被清理。当此参数不填时,清理当前表的所有脏数据。 |
6850
6851**返回值:**
6852| 参数名    | 说明                                               |
6853| -------- | ------------------------------------------------- |
6854| Promise\<void> | 无返回结果的Promise对象。        |
6855
6856**错误码:**
6857
6858以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
6859
6860| **错误码ID** | **错误信息**                                                                                                                                                                      |
6861|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
6862| 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. |
6863| 801       | Capability not supported. |
6864| 14800000  | Inner error.            |
6865| 14800011  | Database corrupted.   |
6866| 14800014  | Already closed. |
6867| 14800015  | The database does not respond.   |
6868| 14800021  | SQLite: Generic error.   |
6869| 14800022  | SQLite: Callback routine requested an abort. |
6870| 14800023  | SQLite: Access permission denied.          |
6871| 14800024  | SQLite: The database file is locked.      |
6872| 14800025  | SQLite: A table in the database is locked. |
6873| 14800026  | SQLite: The database is out of memory.   |
6874| 14800027  | SQLite: Attempt to write a readonly database. |
6875| 14800028  | SQLite: Some kind of disk I/O error occurred. |
6876| 14800029  | SQLite: The database is full.   |
6877| 14800030  | SQLite: Unable to open the database file. |
6878| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
6879| 14800032  | SQLite: Abort due to constraint violation. |
6880| 14800033  | SQLite: Data type mismatch. |
6881| 14800034  | SQLite: Library used incorrectly. |
6882
6883**示例:**
6884
6885```ts
6886import { BusinessError } from '@kit.BasicServicesKit';
6887
6888if(store != undefined) {
6889    (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100).then(() => {
6890        console.info('clean dirty data  succeeded');
6891    }).catch ((err: BusinessError) => {
6892        console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`);
6893    })
6894}
6895```
6896
6897### attach<sup>12+</sup>
6898
6899attach(fullPath: string, attachName: string, waitTime?: number) : Promise&lt;number&gt;
6900
6901将一个数据库文件附加到当前数据库中,以便在SQL语句中可以直接访问附加数据库中的数据。
6902
6903数据库文件来自文件,且此API不支持附加加密数据库。调用attach接口后,数据库切换为非WAL模式,性能会存在一定的劣化。
6904
6905attach的时候,数据库会切换为非WAL模式,切换模式需要确保所有的ResultSet都已经Close,所有的写操作已经结束,否则会报错14800015。
6906
6907attach不能并发调用,可能出现未响应情况,报错14800015,需要重试。
6908
6909**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6910
6911**参数:**
6912
6913| 参数名        | 类型     | 必填  | 说明           |
6914| ----------- | ------ | --- | ------------ |
6915| fullPath | string | 是   | 表示要附加的数据库的路径。 |
6916| attachName | string | 是   | 表示附加后的数据库的别名。 |
6917| waitTime | number | 否   | 表示附加数据库文件的等待时长。默认值2s,最小值1s,最大值300s。 |
6918
6919**返回值:**
6920
6921| 类型              | 说明                           |
6922| ---------------- | ---------------------------- |
6923|  Promise&lt;number&gt; | Promise对象。返回附加数据库的数量。 |
6924
6925**错误码:**
6926
6927以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
6928
6929| **错误码ID** | **错误信息**                                                 |
6930|-----------| ------------------------------------------------------------ |
6931| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6932| 801       | Capability not supported. |
6933| 14800000  | Inner error. |
6934| 14800010  | Invalid database path.               |
6935| 14800011  | Database corrupted. |
6936| 14800014  | Already closed. |
6937| 14800015  | The database does not respond.                 |
6938| 14800016  | The database alias already exists.                |
6939| 14800021  | SQLite: Generic error. |
6940| 14800022  | SQLite: Callback routine requested an abort. |
6941| 14800023  | SQLite: Access permission denied. |
6942| 14800024  | SQLite: The database file is locked. |
6943| 14800025  | SQLite: A table in the database is locked. |
6944| 14800026  | SQLite: The database is out of memory. |
6945| 14800027  | SQLite: Attempt to write a readonly database. |
6946| 14800028  | SQLite: Some kind of disk I/O error occurred. |
6947| 14800029  | SQLite: The database is full. |
6948| 14800030  | SQLite: Unable to open the database file. |
6949| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
6950| 14800032  | SQLite: Abort due to constraint violation. |
6951| 14800033  | SQLite: Data type mismatch. |
6952| 14800034  | SQLite: Library used incorrectly. |
6953
6954**示例:**
6955
6956```ts
6957// 非加密数据库附加非加密数据库。
6958import { BusinessError } from '@kit.BasicServicesKit';
6959
6960if(store != undefined) {
6961    (store as relationalStore.RdbStore).attach("/path/rdbstore1.db", "attachDB").then((number: number) => {
6962        console.info('attach succeeded');
6963    }).catch ((err: BusinessError) => {
6964        console.error(`attach failed, code is ${err.code},message is ${err.message}`);
6965    })
6966}
6967```
6968
6969### attach<sup>12+</sup>
6970
6971attach(context: Context, config: StoreConfig, attachName: string, waitTime?: number) : Promise&lt;number&gt;
6972
6973将一个当前应用的数据库附加到当前数据库中,以便在SQL语句中可以直接访问附加数据库中的数据。
6974
6975此API不支持加密数据库附加非加密数据库的场景。调用attach接口后,数据库切换为非WAL模式,性能会存在一定的劣化。
6976
6977attach的时候,数据库会切换为非WAL模式,切换模式需要确保所有的ResultSet都已经Close,所有的写操作已经结束,否则会报错14800015。
6978
6979attach不能并发调用,可能出现未响应情况,报错14800015,需要重试。除此之外,attach附加加密数据库时,可能受到并发的影响,出现解密失败的情况,报错14800011,需要显式指定加密参数并重试。
6980
6981**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6982
6983**参数:**
6984
6985| 参数名        | 类型     | 必填  | 说明           |
6986| ----------- | ------ | --- | ------------ |
6987| 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)。 |
6988| config  | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |
6989| attachName | string | 是   | 表示附加后的数据库的别名。 |
6990| waitTime | number | 否   | 表示附加数据库文件的等待时长。默认值2s,最小值1s,最大值300s。 |
6991
6992**返回值:**
6993
6994| 类型              | 说明                           |
6995| ---------------- | ---------------------------- |
6996|  Promise&lt;number&gt; | Promise对象。返回附加数据库的数量。 |
6997
6998**错误码:**
6999
7000以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7001
7002| **错误码ID** | **错误信息**                                                 |
7003|-----------| ------------------------------------------------------------ |
7004| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7005| 801       | Capability not supported. |
7006| 14800000  | Inner error. |
7007| 14800010  | Invalid database path.               |
7008| 14800011  | Database corrupted. |
7009| 14800014  | Already closed. |
7010| 14800015  | The database does not respond.                 |
7011| 14800016  | The database alias already exists.                |
7012| 14801001  | The operation is supported in the stage model only.                 |
7013| 14801002  | Invalid data ground ID.                |
7014| 14800021  | SQLite: Generic error. |
7015| 14800022  | SQLite: Callback routine requested an abort. |
7016| 14800023  | SQLite: Access permission denied. |
7017| 14800024  | SQLite: The database file is locked. |
7018| 14800025  | SQLite: A table in the database is locked. |
7019| 14800026  | SQLite: The database is out of memory. |
7020| 14800027  | SQLite: Attempt to write a readonly database. |
7021| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7022| 14800029  | SQLite: The database is full. |
7023| 14800030  | SQLite: Unable to open the database file. |
7024| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7025| 14800032  | SQLite: Abort due to constraint violation. |
7026| 14800033  | SQLite: Data type mismatch. |
7027| 14800034  | SQLite: Library used incorrectly. |
7028
7029**示例1:非加密数据库附加非加密数据库**
7030
7031```ts
7032import { BusinessError } from '@kit.BasicServicesKit';
7033
7034let attachStore: relationalStore.RdbStore | undefined = undefined;
7035
7036const STORE_CONFIG1: relationalStore.StoreConfig = {
7037    name: "rdbstore1.db",
7038    securityLevel: relationalStore.SecurityLevel.S3,
7039}
7040
7041relationalStore.getRdbStore(this.context, STORE_CONFIG1).then(async (rdbStore: relationalStore.RdbStore) => {
7042    attachStore = rdbStore;
7043    console.info('Get RdbStore successfully.')
7044}).catch((err: BusinessError) => {
7045    console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
7046})
7047
7048if(store != undefined) {
7049    (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG1, "attachDB").then((number: number) => {
7050        console.info(`attach succeeded, number is ${number}`);
7051    }).catch ((err: BusinessError) => {
7052        console.error(`attach failed, code is ${err.code},message is ${err.message}`);
7053    })
7054}
7055```
7056
7057**示例2:非加密数据库附加加密数据库**
7058
7059```ts
7060import { BusinessError } from '@kit.BasicServicesKit';
7061
7062let attachStore: relationalStore.RdbStore | undefined = undefined;
7063
7064
7065const STORE_CONFIG2: relationalStore.StoreConfig = {
7066    name: "rdbstore2.db",
7067    encrypt: true,
7068    securityLevel: relationalStore.SecurityLevel.S3,
7069}
7070
7071relationalStore.getRdbStore(this.context, STORE_CONFIG2).then(async (rdbStore: relationalStore.RdbStore) => {
7072    attachStore = rdbStore;
7073    console.info('Get RdbStore successfully.')
7074}).catch((err: BusinessError) => {
7075    console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
7076})
7077
7078if(store != undefined) {
7079    (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG2, "attachDB2", 10).then((number: number) => {
7080        console.info(`attach succeeded, number is ${number}`);
7081    }).catch ((err: BusinessError) => {
7082        console.error(`attach failed, code is ${err.code},message is ${err.message}`);
7083    })
7084}
7085```
7086
7087### detach<sup>12+</sup>
7088
7089detach(attachName: string, waitTime?: number) : Promise&lt;number&gt;
7090
7091将附加的数据库从当前数据库中分离。
7092
7093当所有的附加的数据库被分离后,数据库会重新切换为WAL模式。
7094
7095在detach之前,所有的数据库操作要确保已经结束,所有的ResultSet已经Close。并且不能并发调用,可能出现未响应情况,需要重试。
7096
7097**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7098
7099**参数:**
7100
7101| 参数名        | 类型     | 必填  | 说明           |
7102| ----------- | ------ | --- | ------------ |
7103| attachName | string | 是   | 表示附加后的数据库的别名。 |
7104| waitTime | number | 否   | 表示分离数据库的等待时长。默认值2s,最小值1s,最大值300s。 |
7105
7106**返回值:**
7107
7108| 类型              | 说明                           |
7109| ---------------- | ---------------------------- |
7110|  Promise&lt;number&gt; | Promise对象。返回分离后剩余附加的数据库的数量。 |
7111
7112**错误码:**
7113
7114以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7115
7116| **错误码ID** | **错误信息**       |
7117|-----------|------------------------|
7118| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7119| 14800000  | Inner error.            |
7120| 14800011  | Database corrupted.         |
7121| 14800014  | Already closed.        |
7122| 14800015  | The database does not respond.         |
7123| 14800021  | SQLite: Generic error.            |
7124| 14800022  | SQLite: Callback routine requested an abort.       |
7125| 14800023  | SQLite: Access permission denied.           |
7126| 14800024  | SQLite: The database file is locked.        |
7127| 14800025  | SQLite: A table in the database is locked.       |
7128| 14800026  | SQLite: The database is out of memory.     |
7129| 14800027  | SQLite: Attempt to write a readonly database.        |
7130| 14800028  | SQLite: Some kind of disk I/O error occurred.    |
7131| 14800029  | SQLite: The database is full.      |
7132| 14800030  | SQLite: Unable to open the database file.       |
7133| 14800031  | SQLite: TEXT or BLOB exceeds size limit.      |
7134| 14800032  | SQLite: Abort due to constraint violation.    |
7135| 14800033  | SQLite: Data type mismatch.       |
7136| 14800034  | SQLite: Library used incorrectly.       |
7137
7138**示例:**
7139
7140```ts
7141import { BusinessError } from '@kit.BasicServicesKit';
7142
7143if(store != undefined) {
7144    (store as relationalStore.RdbStore).detach("attachDB").then((number: number) => {
7145        console.info(`detach succeeded, number is ${number}`);
7146    }).catch ((err: BusinessError) => {
7147        console.error(`detach failed, code is ${err.code},message is ${err.message}`);
7148    })
7149}
7150```
7151
7152### lockRow<sup>12+</sup>
7153
7154lockRow(predicates: RdbPredicates):Promise&lt;void&gt;
7155
7156根据RdbPredicates的指定实例对象从数据库中锁定数据,锁定数据不执行端云同步,使用Promise异步回调。
7157
7158该接口只支持主键为基本类型的表、不支持共享表、无主键表和复合类型主键表。
7159该接口不支持依赖关系表之间的锁传递,如果表存在依赖关系,需要根据依赖关系手动调用该接口。
7160该接口不支持对已删除数据的操作。
7161
7162**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7163
7164**参数:**
7165
7166| 参数名     | 类型                                 | 必填 | 说明                                      |
7167| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
7168| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的锁定条件。 |
7169
7170**返回值**:
7171
7172| 类型                  | 说明                            |
7173| --------------------- | ------------------------------- |
7174| Promise&lt;void&gt;   | 无返回结果的Promise对象。        |
7175
7176**错误码:**
7177
7178以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7179
7180| **错误码ID** | **错误信息**                                                                                     |
7181|-----------|----------------------------------------------------------------------------------------------|
7182| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7183| 14800000  | Inner error.                                                                                 |
7184| 14800011  | Database corrupted.                                                                          |
7185| 14800014  | Already closed.                                                                              |
7186| 14800015  | The database does not respond.                                                                        |
7187| 14800018  | No data meets the condition.                                                                 |
7188| 14800021  | SQLite: Generic error.                                                                       |
7189| 14800022  | SQLite: Callback routine requested an abort.                                                 |
7190| 14800023  | SQLite: Access permission denied.                                                            |
7191| 14800024  | SQLite: The database file is locked.                                                         |
7192| 14800025  | SQLite: A table in the database is locked.                                                   |
7193| 14800026  | SQLite: The database is out of memory.                                                       |
7194| 14800027  | SQLite: Attempt to write a readonly database.                                                |
7195| 14800028  | SQLite: Some kind of disk I/O error occurred.                                                |
7196| 14800029  | SQLite: The database is full.                                                                |
7197| 14800030  | SQLite: Unable to open the database file.                                                    |
7198| 14800031  | SQLite: TEXT or BLOB exceeds size limit.                                                     |
7199| 14800032  | SQLite: Abort due to constraint violation.                                                   |
7200| 14800033  | SQLite: Data type mismatch.                                                                  |
7201| 14800034  | SQLite: Library used incorrectly.                                                            |
7202
7203**示例:**
7204
7205```ts
7206import { BusinessError } from '@kit.BasicServicesKit';
7207
7208let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
7209predicates.equalTo("NAME", "Lisa");
7210if(store != undefined) {
7211  (store as relationalStore.RdbStore).lockRow(predicates).then(() => {
7212    console.info(`Lock success`);
7213  }).catch((err: BusinessError) => {
7214    console.error(`Lock failed, code is ${err.code},message is ${err.message}`);
7215  })
7216}
7217```
7218
7219### unlockRow<sup>12+</sup>
7220
7221unlockRow(predicates: RdbPredicates):Promise&lt;void&gt;
7222
7223根据RdbPredicates的指定实例对象从数据库中解锁数据,使用Promise异步回调。
7224
7225该接口只支持主键为基本类型的表、不支持共享表、无主键表和复合类型主键表。
7226该接口不支持依赖关系表之间的锁传递,如果表存在依赖关系,需要根据依赖关系手动调用该接口。
7227该接口不支持对已删除数据的操作。
7228
7229**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7230
7231**参数:**
7232
7233| 参数名     | 类型                                 | 必填 | 说明                                      |
7234| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
7235| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的锁定条件。 |
7236
7237**返回值**:
7238
7239| 类型                  | 说明                            |
7240| --------------------- | ------------------------------- |
7241| Promise&lt;void&gt;   | 无返回结果的Promise对象。        |
7242
7243**错误码:**
7244
7245以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7246
7247| **错误码ID** | **错误信息**                                                 |
7248|-----------| ------------------------------------------------------------ |
7249| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7250| 14800000  | Inner error. |
7251| 14800011  | Database corrupted. |
7252| 14800014  | Already closed. |
7253| 14800015  | The database does not respond.                 |
7254| 14800018  | No data meets the condition.                |
7255| 14800021  | SQLite: Generic error. |
7256| 14800022  | SQLite: Callback routine requested an abort. |
7257| 14800023  | SQLite: Access permission denied. |
7258| 14800024  | SQLite: The database file is locked. |
7259| 14800025  | SQLite: A table in the database is locked. |
7260| 14800026  | SQLite: The database is out of memory. |
7261| 14800027  | SQLite: Attempt to write a readonly database. |
7262| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7263| 14800029  | SQLite: The database is full. |
7264| 14800030  | SQLite: Unable to open the database file. |
7265| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7266| 14800032  | SQLite: Abort due to constraint violation. |
7267| 14800033  | SQLite: Data type mismatch. |
7268| 14800034  | SQLite: Library used incorrectly. |
7269
7270**示例:**
7271
7272```ts
7273import { BusinessError } from '@kit.BasicServicesKit';
7274
7275let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
7276predicates.equalTo("NAME", "Lisa");
7277if(store != undefined) {
7278  (store as relationalStore.RdbStore).unlockRow(predicates).then(() => {
7279    console.info(`Unlock success`);
7280  }).catch((err: BusinessError) => {
7281    console.error(`Unlock failed, code is ${err.code},message is ${err.message}`);
7282  })
7283}
7284```
7285
7286### queryLockedRow<sup>12+</sup>
7287
7288queryLockedRow(predicates: RdbPredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
7289
7290根据指定条件查询数据库中锁定的数据,使用Promise异步回调。
7291由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
7292
7293**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7294
7295**参数:**
7296
7297| 参数名     | 类型                                 | 必填 | 说明                                             |
7298| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
7299| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。        |
7300| columns    | Array&lt;string&gt;                  | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
7301
7302**错误码:**
7303
7304以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7305
7306| **错误码ID** | **错误信息**                                                 |
7307|-----------| ------------------------------------------------------------ |
7308| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7309| 14800000  | Inner error. |
7310| 14800011  | Database corrupted. |
7311| 14800014  | Already closed. |
7312| 14800015  | The database does not respond.                 |
7313| 14800021  | SQLite: Generic error. |
7314| 14800022  | SQLite: Callback routine requested an abort. |
7315| 14800023  | SQLite: Access permission denied. |
7316| 14800024  | SQLite: The database file is locked. |
7317| 14800025  | SQLite: A table in the database is locked. |
7318| 14800026  | SQLite: The database is out of memory. |
7319| 14800027  | SQLite: Attempt to write a readonly database. |
7320| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7321| 14800029  | SQLite: The database is full. |
7322| 14800030  | SQLite: Unable to open the database file. |
7323| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7324| 14800032  | SQLite: Abort due to constraint violation. |
7325| 14800033  | SQLite: Data type mismatch. |
7326| 14800034  | SQLite: Library used incorrectly. |
7327
7328**返回值**:
7329
7330| 类型                                                    | 说明                                               |
7331| ------------------------------------------------------- | -------------------------------------------------- |
7332| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
7333
7334**示例:**
7335
7336```ts
7337import { BusinessError } from '@kit.BasicServicesKit';
7338
7339let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
7340predicates.equalTo("NAME", "Rose");
7341if(store != undefined) {
7342  (store as relationalStore.RdbStore).queryLockedRow(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => {
7343    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
7344    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
7345    while (resultSet.goToNextRow()) {
7346      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
7347      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
7348      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
7349      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
7350      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
7351    }
7352    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
7353    resultSet.close();
7354  }).catch((err: BusinessError) => {
7355    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
7356  })
7357}
7358```
7359### close<sup>12+</sup>
7360
7361close(): Promise&lt;void&gt;
7362
7363关闭数据库,使用Promise异步回调。
7364
7365**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7366
7367**返回值:**
7368
7369| 类型                | 说明          |
7370| ------------------- | ------------- |
7371| Promise&lt;void&gt; | Promise对象。 |
7372
7373**错误码:**
7374
7375以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
7376
7377| **错误码ID** | **错误信息**                                    |
7378| ------------ | ----------------------------------------------- |
7379| 401          | Parameter error. The store must not be nullptr. |
7380| 14800000     | Inner error.                                    |
7381
7382**示例:**
7383
7384```ts
7385import { BusinessError } from '@kit.BasicServicesKit';
7386
7387if(store != undefined) {
7388    (store as relationalStore.RdbStore).close().then(() => {
7389        console.info(`close succeeded`);
7390    }).catch ((err: BusinessError) => {
7391        console.error(`close failed, code is ${err.code},message is ${err.message}`);
7392    })
7393}
7394```
7395
7396## ResultSet
7397
7398提供通过查询数据库生成的数据库结果集的访问方法。结果集是指用户调用关系型数据库查询接口之后返回的结果集合,提供了多种灵活的数据访问方式,以便用户获取各项数据。
7399
7400### 使用说明
7401
7402首先需要获取resultSet对象。
7403
7404**示例:**
7405
7406<!--code_no_check-->
7407```ts
7408let resultSet: relationalStore.ResultSet | undefined = undefined;
7409let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
7410predicates.equalTo("AGE", 18);
7411if(store != undefined) {
7412  (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((result: relationalStore.ResultSet) => {
7413    resultSet = result;
7414    console.info(`resultSet columnNames: ${resultSet.columnNames}`);
7415    console.info(`resultSet columnCount: ${resultSet.columnCount}`);
7416  });
7417}
7418```
7419
7420### 属性
7421
7422**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7423
7424| 名称         | 类型            | 必填 | 说明                             |
7425| ------------ | ------------------- | ---- | -------------------------------- |
7426| columnNames  | Array&lt;string&gt; | 是   | 获取结果集中所有列的名称。       |
7427| columnCount  | number              | 是   | 获取结果集中的列数。             |
7428| rowCount     | number              | 是   | 获取结果集中的行数。             |
7429| rowIndex     | number              | 是   | 获取结果集当前行的索引。         |
7430| isAtFirstRow | boolean             | 是   | 检查结果集是否位于第一行。       |
7431| isAtLastRow  | boolean             | 是   | 检查结果集是否位于最后一行。     |
7432| isEnded      | boolean             | 是   | 检查结果集是否位于最后一行之后。 |
7433| isStarted    | boolean             | 是   | 检查指针是否移动过。             |
7434| isClosed     | boolean             | 是   | 检查当前结果集是否关闭。         |
7435
7436### getColumnIndex
7437
7438getColumnIndex(columnName: string): number
7439
7440根据指定的列名获取列索引。
7441
7442**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7443
7444**参数:**
7445
7446| 参数名     | 类型   | 必填 | 说明                       |
7447| ---------- | ------ | ---- | -------------------------- |
7448| columnName | string | 是   | 表示结果集中指定列的名称。 |
7449
7450**返回值:**
7451
7452| 类型   | 说明               |
7453| ------ | ------------------ |
7454| number | 返回指定列的索引。 |
7455
7456**错误码:**
7457
7458以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7459
7460| **错误码ID** | **错误信息**                                                 |
7461|-----------| ------------------------------------------------------------ |
7462| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7463| 14800000  | Inner error. |
7464| 14800011  | Database corrupted. |
7465| 14800013  | Column out of bounds. |
7466| 14800014  | Already closed. |
7467| 14800019  | The SQL must be a query statement. |
7468| 14800021  | SQLite: Generic error. |
7469| 14800022  | SQLite: Callback routine requested an abort. |
7470| 14800023  | SQLite: Access permission denied. |
7471| 14800024  | SQLite: The database file is locked. |
7472| 14800025  | SQLite: A table in the database is locked. |
7473| 14800026  | SQLite: The database is out of memory. |
7474| 14800027  | SQLite: Attempt to write a readonly database. |
7475| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7476| 14800029  | SQLite: The database is full. |
7477| 14800030  | SQLite: Unable to open the database file. |
7478| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7479| 14800032  | SQLite: Abort due to constraint violation. |
7480| 14800033  | SQLite: Data type mismatch. |
7481| 14800034  | SQLite: Library used incorrectly. |
7482
7483**示例:**
7484
7485```ts
7486if(resultSet != undefined) {
7487  const id = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("ID"));
7488  const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME"));
7489  const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE"));
7490  const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY"));
7491}
7492```
7493
7494### getColumnName
7495
7496getColumnName(columnIndex: number): string
7497
7498根据指定的列索引获取列名。
7499
7500**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7501
7502**参数:**
7503
7504| 参数名      | 类型   | 必填 | 说明                       |
7505| ----------- | ------ | ---- | -------------------------- |
7506| columnIndex | number | 是   | 表示结果集中指定列的索引。 |
7507
7508**返回值:**
7509
7510| 类型   | 说明               |
7511| ------ | ------------------ |
7512| string | 返回指定列的名称。 |
7513
7514**错误码:**
7515
7516以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7517
7518| **错误码ID** | **错误信息**                                                 |
7519|-----------| ------------------------------------------------------------ |
7520| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7521| 14800000  | Inner error. |
7522| 14800011  | Database corrupted. |
7523| 14800013  | Column out of bounds. |
7524| 14800014  | Already closed. |
7525| 14800019  | The SQL must be a query statement. |
7526| 14800021  | SQLite: Generic error. |
7527| 14800022  | SQLite: Callback routine requested an abort. |
7528| 14800023  | SQLite: Access permission denied. |
7529| 14800024  | SQLite: The database file is locked. |
7530| 14800025  | SQLite: A table in the database is locked. |
7531| 14800026  | SQLite: The database is out of memory. |
7532| 14800027  | SQLite: Attempt to write a readonly database. |
7533| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7534| 14800029  | SQLite: The database is full. |
7535| 14800030  | SQLite: Unable to open the database file. |
7536| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7537| 14800032  | SQLite: Abort due to constraint violation. |
7538| 14800033  | SQLite: Data type mismatch. |
7539| 14800034  | SQLite: Library used incorrectly. |
7540
7541**示例:**
7542
7543```ts
7544if(resultSet != undefined) {
7545  const id = (resultSet as relationalStore.ResultSet).getColumnName(0);
7546  const name = (resultSet as relationalStore.ResultSet).getColumnName(1);
7547  const age = (resultSet as relationalStore.ResultSet).getColumnName(2);
7548}
7549```
7550
7551### goTo
7552
7553goTo(offset:number): boolean
7554
7555向前或向后转至结果集的指定行,相对于其当前位置偏移。
7556
7557**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7558
7559**参数:**
7560
7561| 参数名 | 类型   | 必填 | 说明                         |
7562| ------ | ------ | ---- | ---------------------------- |
7563| offset | number | 是   | 表示相对于当前位置的偏移量。 |
7564
7565**返回值:**
7566
7567| 类型    | 说明                                          |
7568| ------- | --------------------------------------------- |
7569| boolean | 如果成功移动结果集,则为true;否则返回false。 |
7570
7571**错误码:**
7572
7573以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7574
7575| **错误码ID** | **错误信息**                                                 |
7576|-----------| ------------------------------------------------------------ |
7577| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7578| 14800000  | Inner error. |
7579| 14800011  | Database corrupted. |
7580| 14800012  | Row out of bounds. |
7581| 14800014  | Already closed. |
7582| 14800019  | The SQL must be a query statement. |
7583| 14800021  | SQLite: Generic error. |
7584| 14800022  | SQLite: Callback routine requested an abort. |
7585| 14800023  | SQLite: Access permission denied. |
7586| 14800024  | SQLite: The database file is locked. |
7587| 14800025  | SQLite: A table in the database is locked. |
7588| 14800026  | SQLite: The database is out of memory. |
7589| 14800027  | SQLite: Attempt to write a readonly database. |
7590| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7591| 14800029  | SQLite: The database is full. |
7592| 14800030  | SQLite: Unable to open the database file. |
7593| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7594| 14800032  | SQLite: Abort due to constraint violation. |
7595| 14800033  | SQLite: Data type mismatch. |
7596| 14800034  | SQLite: Library used incorrectly. |
7597
7598**示例:**
7599
7600```ts
7601if(resultSet != undefined) {
7602  (resultSet as relationalStore.ResultSet).goTo(1);
7603}
7604```
7605
7606### goToRow
7607
7608goToRow(position: number): boolean
7609
7610转到结果集的指定行。
7611
7612**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7613
7614**参数:**
7615
7616| 参数名   | 类型   | 必填 | 说明                     |
7617| -------- | ------ | ---- | ------------------------ |
7618| position | number | 是   | 表示要移动到的指定位置。 |
7619
7620**返回值:**
7621
7622| 类型    | 说明                                          |
7623| ------- | --------------------------------------------- |
7624| boolean | 如果成功移动结果集,则为true;否则返回false。 |
7625
7626**错误码:**
7627
7628以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7629
7630| **错误码ID** | **错误信息**                                                 |
7631|-----------| ------------------------------------------------------------ |
7632| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7633| 14800000  | Inner error. |
7634| 14800011  | Database corrupted. |
7635| 14800012  | Row out of bounds. |
7636| 14800014  | Already closed. |
7637| 14800019  | The SQL must be a query statement. |
7638| 14800021  | SQLite: Generic error. |
7639| 14800022  | SQLite: Callback routine requested an abort. |
7640| 14800023  | SQLite: Access permission denied. |
7641| 14800024  | SQLite: The database file is locked. |
7642| 14800025  | SQLite: A table in the database is locked. |
7643| 14800026  | SQLite: The database is out of memory. |
7644| 14800027  | SQLite: Attempt to write a readonly database. |
7645| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7646| 14800029  | SQLite: The database is full. |
7647| 14800030  | SQLite: Unable to open the database file. |
7648| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7649| 14800032  | SQLite: Abort due to constraint violation. |
7650| 14800033  | SQLite: Data type mismatch. |
7651| 14800034  | SQLite: Library used incorrectly. |
7652
7653**示例:**
7654
7655```ts
7656if(resultSet != undefined) {
7657  (resultSet as relationalStore.ResultSet).goToRow(5);
7658}
7659```
7660
7661### goToFirstRow
7662
7663goToFirstRow(): boolean
7664
7665
7666转到结果集的第一行。
7667
7668**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7669
7670**返回值:**
7671
7672| 类型    | 说明                                          |
7673| ------- | --------------------------------------------- |
7674| boolean | 如果成功移动结果集,则为true;否则返回false。 |
7675
7676**错误码:**
7677
7678以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7679
7680| **错误码ID** | **错误信息**                                                 |
7681|-----------| ------------------------------------------------------------ |
7682| 14800000  | Inner error. |
7683| 14800011  | Database corrupted. |
7684| 14800012  | Row out of bounds. |
7685| 14800014  | Already closed. |
7686| 14800019  | The SQL must be a query statement. |
7687| 14800021  | SQLite: Generic error. |
7688| 14800022  | SQLite: Callback routine requested an abort. |
7689| 14800023  | SQLite: Access permission denied. |
7690| 14800024  | SQLite: The database file is locked. |
7691| 14800025  | SQLite: A table in the database is locked. |
7692| 14800026  | SQLite: The database is out of memory. |
7693| 14800027  | SQLite: Attempt to write a readonly database. |
7694| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7695| 14800029  | SQLite: The database is full. |
7696| 14800030  | SQLite: Unable to open the database file. |
7697| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7698| 14800032  | SQLite: Abort due to constraint violation. |
7699| 14800033  | SQLite: Data type mismatch. |
7700| 14800034  | SQLite: Library used incorrectly. |
7701
7702**示例:**
7703
7704```ts
7705if(resultSet != undefined) {
7706  (resultSet as relationalStore.ResultSet).goToFirstRow();
7707}
7708```
7709
7710### goToLastRow
7711
7712goToLastRow(): boolean
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).goToLastRow();
7755}
7756```
7757
7758### goToNextRow
7759
7760goToNextRow(): 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).goToNextRow();
7803}
7804```
7805
7806### goToPreviousRow
7807
7808goToPreviousRow(): 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).goToPreviousRow();
7851}
7852```
7853
7854### getValue<sup>12+</sup>
7855
7856getValue(columnIndex: number): ValueType
7857
7858获取当前行中指定列的值,值类型如果是ValueType指定的任意类型,则会以对应类型返回指定类的值,否则返回14800000。
7859
7860**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7861
7862**参数:**
7863
7864| 参数名      | 类型   | 必填 | 说明                    |
7865| ----------- | ------ | ---- | ----------------------- |
7866| columnIndex | number | 是   | 指定的列索引,从0开始。 |
7867
7868**返回值:**
7869
7870| 类型       | 说明                             |
7871| ---------- | -------------------------------- |
7872| [ValueType](#valuetype) | 表示允许的数据字段类型。 |
7873
7874**错误码:**
7875
7876以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7877
7878| **错误码ID** | **错误信息**     |
7879|-----------|---------|
7880| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7881| 14800000  | Inner error.      |
7882| 14800011  | Database corrupted.        |
7883| 14800012  | Row out of bounds.       |
7884| 14800013  | Column out of bounds.   |
7885| 14800014  | Already closed.       |
7886| 14800021  | SQLite: Generic error.    |
7887| 14800022  | SQLite: Callback routine requested an abort.     |
7888| 14800023  | SQLite: Access permission denied.    |
7889| 14800024  | SQLite: The database file is locked.    |
7890| 14800025  | SQLite: A table in the database is locked.  |
7891| 14800026  | SQLite: The database is out of memory.    |
7892| 14800027  | SQLite: Attempt to write a readonly database.    |
7893| 14800028  | SQLite: Some kind of disk I/O error occurred.    |
7894| 14800029  | SQLite: The database is full.   |
7895| 14800030  | SQLite: Unable to open the database file.    |
7896| 14800031  | SQLite: TEXT or BLOB exceeds size limit.    |
7897| 14800032  | SQLite: Abort due to constraint violation.   |
7898| 14800033  | SQLite: Data type mismatch.      |
7899| 14800034  | SQLite: Library used incorrectly.    |
7900
7901**示例:**
7902
7903```ts
7904if(resultSet != undefined) {
7905  const codes = (resultSet as relationalStore.ResultSet).getValue((resultSet as relationalStore.ResultSet).getColumnIndex("BIGINT_COLUMN"));
7906}
7907```
7908
7909### getBlob
7910
7911getBlob(columnIndex: number): Uint8Array
7912
7913
7914以字节数组的形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成字节数组类型返回指定值,如果该列内容为空时,会返回空字节数组,其他类型则返回14800000。
7915
7916**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7917
7918**参数:**
7919
7920| 参数名      | 类型   | 必填 | 说明                    |
7921| ----------- | ------ | ---- | ----------------------- |
7922| columnIndex | number | 是   | 指定的列索引,从0开始。 |
7923
7924**返回值:**
7925
7926| 类型       | 说明                             |
7927| ---------- | -------------------------------- |
7928| Uint8Array | 以字节数组的形式返回指定列的值。 |
7929
7930**错误码:**
7931
7932以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7933
7934| **错误码ID** | **错误信息**                                                 |
7935|-----------| ------------------------------------------------------------ |
7936| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7937| 14800000  | Inner error. |
7938| 14800011  | Database corrupted. |
7939| 14800012  | Row out of bounds. |
7940| 14800013  | Column out of bounds. |
7941| 14800014  | Already closed. |
7942| 14800021  | SQLite: Generic error. |
7943| 14800022  | SQLite: Callback routine requested an abort. |
7944| 14800023  | SQLite: Access permission denied. |
7945| 14800024  | SQLite: The database file is locked. |
7946| 14800025  | SQLite: A table in the database is locked. |
7947| 14800026  | SQLite: The database is out of memory. |
7948| 14800027  | SQLite: Attempt to write a readonly database. |
7949| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7950| 14800029  | SQLite: The database is full. |
7951| 14800030  | SQLite: Unable to open the database file. |
7952| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7953| 14800032  | SQLite: Abort due to constraint violation. |
7954| 14800033  | SQLite: Data type mismatch. |
7955| 14800034  | SQLite: Library used incorrectly. |
7956
7957**示例:**
7958
7959```ts
7960if(resultSet != undefined) {
7961  const codes = (resultSet as relationalStore.ResultSet).getBlob((resultSet as relationalStore.ResultSet).getColumnIndex("CODES"));
7962}
7963```
7964
7965### getString
7966
7967getString(columnIndex: number): string
7968
7969以字符串形式获取当前行中指定列的值,如果当前列中的值为INTEGER、DOUBLE、TEXT、BLOB类型,会以字符串形式返回指定值,如果是当前列中的值为INTEGER,并且为空,则会返回空字符串"",其他类型则返回14800000。如果当前列中的值为DOUBLE类型,可能存在精度的丢失,建议使用[getDouble](#getdouble)接口获取。
7970
7971**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7972
7973**参数:**
7974
7975| 参数名      | 类型   | 必填 | 说明                    |
7976| ----------- | ------ | ---- | ----------------------- |
7977| columnIndex | number | 是   | 指定的列索引,从0开始。 |
7978
7979**返回值:**
7980
7981| 类型   | 说明                         |
7982| ------ | ---------------------------- |
7983| string | 以字符串形式返回指定列的值。 |
7984
7985**错误码:**
7986
7987以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7988
7989| **错误码ID** | **错误信息**                                                 |
7990|-----------| ------------------------------------------------------------ |
7991| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7992| 14800000  | Inner error. |
7993| 14800011  | Database corrupted. |
7994| 14800012  | Row out of bounds. |
7995| 14800013  | Column out of bounds. |
7996| 14800014  | Already closed. |
7997| 14800021  | SQLite: Generic error. |
7998| 14800022  | SQLite: Callback routine requested an abort. |
7999| 14800023  | SQLite: Access permission denied. |
8000| 14800024  | SQLite: The database file is locked. |
8001| 14800025  | SQLite: A table in the database is locked. |
8002| 14800026  | SQLite: The database is out of memory. |
8003| 14800027  | SQLite: Attempt to write a readonly database. |
8004| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8005| 14800029  | SQLite: The database is full. |
8006| 14800030  | SQLite: Unable to open the database file. |
8007| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8008| 14800032  | SQLite: Abort due to constraint violation. |
8009| 14800033  | SQLite: Data type mismatch. |
8010| 14800034  | SQLite: Library used incorrectly. |
8011
8012**示例:**
8013
8014```ts
8015if(resultSet != undefined) {
8016  const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME"));
8017}
8018```
8019
8020### getLong
8021
8022getLong(columnIndex: number): number
8023
8024以Long形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成Long类型返回指定值,如果该列内容为空时,会返回0,其他类型则返回14800000。
8025
8026**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8027
8028**参数:**
8029
8030| 参数名      | 类型   | 必填 | 说明                    |
8031| ----------- | ------ | ---- | ----------------------- |
8032| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8033
8034**返回值:**
8035
8036| 类型   | 说明                                                         |
8037| ------ | ------------------------------------------------------------ |
8038| number | 以Long形式返回指定列的值。<br>该接口支持的数据范围是:Number.MIN_SAFE_INTEGER ~ Number.MAX_SAFE_INTEGER,若超出该范围,建议使用[getDouble](#getdouble)。 |
8039
8040**错误码:**
8041
8042以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8043
8044| **错误码ID** | **错误信息**                                                 |
8045|-----------| ------------------------------------------------------------ |
8046| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8047| 14800000  | Inner error. |
8048| 14800011  | Database corrupted. |
8049| 14800012  | Row out of bounds. |
8050| 14800013  | Column out of bounds. |
8051| 14800014  | Already closed. |
8052| 14800021  | SQLite: Generic error. |
8053| 14800022  | SQLite: Callback routine requested an abort. |
8054| 14800023  | SQLite: Access permission denied. |
8055| 14800024  | SQLite: The database file is locked. |
8056| 14800025  | SQLite: A table in the database is locked. |
8057| 14800026  | SQLite: The database is out of memory. |
8058| 14800027  | SQLite: Attempt to write a readonly database. |
8059| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8060| 14800029  | SQLite: The database is full. |
8061| 14800030  | SQLite: Unable to open the database file. |
8062| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8063| 14800032  | SQLite: Abort due to constraint violation. |
8064| 14800033  | SQLite: Data type mismatch. |
8065| 14800034  | SQLite: Library used incorrectly. |
8066
8067**示例:**
8068
8069```ts
8070if(resultSet != undefined) {
8071  const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE"));
8072 }
8073```
8074
8075### getDouble
8076
8077getDouble(columnIndex: number): number
8078
8079以double形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成double类型返回指定值,如果该列内容为空时,会返回0.0,其他类型则返回14800000。
8080
8081**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8082
8083**参数:**
8084
8085| 参数名      | 类型   | 必填 | 说明                    |
8086| ----------- | ------ | ---- | ----------------------- |
8087| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8088
8089**返回值:**
8090
8091| 类型   | 说明                         |
8092| ------ | ---------------------------- |
8093| number | 以double形式返回指定列的值。 |
8094
8095**错误码:**
8096
8097以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8098
8099| **错误码ID** | **错误信息**                                                 |
8100|-----------| ------------------------------------------------------------ |
8101| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8102| 14800000  | Inner error. |
8103| 14800011  | Database corrupted. |
8104| 14800012  | Row out of bounds. |
8105| 14800013  | Column out of bounds. |
8106| 14800014  | Already closed. |
8107| 14800021  | SQLite: Generic error. |
8108| 14800022  | SQLite: Callback routine requested an abort. |
8109| 14800023  | SQLite: Access permission denied. |
8110| 14800024  | SQLite: The database file is locked. |
8111| 14800025  | SQLite: A table in the database is locked. |
8112| 14800026  | SQLite: The database is out of memory. |
8113| 14800027  | SQLite: Attempt to write a readonly database. |
8114| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8115| 14800029  | SQLite: The database is full. |
8116| 14800030  | SQLite: Unable to open the database file. |
8117| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8118| 14800032  | SQLite: Abort due to constraint violation. |
8119| 14800033  | SQLite: Data type mismatch. |
8120| 14800034  | SQLite: Library used incorrectly. |
8121
8122**示例:**
8123
8124```ts
8125if(resultSet != undefined) {
8126  const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY"));
8127}
8128```
8129
8130### getAsset<sup>10+</sup>
8131
8132getAsset(columnIndex: number): Asset
8133
8134以[Asset](#asset10)形式获取当前行中指定列的值,如果当前列的数据类型为Asset类型,会以Asset类型返回指定值,如果当前列中的值为null时,会返回null,其他类型则返回14800000。
8135
8136**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8137
8138**参数:**
8139
8140| 参数名         | 类型     | 必填  | 说明           |
8141| ----------- | ------ | --- | ------------ |
8142| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8143
8144**返回值:**
8145
8146| 类型              | 说明                         |
8147| --------------- | -------------------------- |
8148| [Asset](#asset10) | 以Asset形式返回指定列的值。 |
8149
8150**错误码:**
8151
8152以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8153
8154| **错误码ID** | **错误信息**                                                 |
8155|-----------| ------------------------------------------------------------ |
8156| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8157| 14800000  | Inner error. |
8158| 14800011  | Database corrupted. |
8159| 14800012  | Row out of bounds. |
8160| 14800013  | Column out of bounds. |
8161| 14800014  | Already closed. |
8162| 14800021  | SQLite: Generic error. |
8163| 14800022  | SQLite: Callback routine requested an abort. |
8164| 14800023  | SQLite: Access permission denied. |
8165| 14800024  | SQLite: The database file is locked. |
8166| 14800025  | SQLite: A table in the database is locked. |
8167| 14800026  | SQLite: The database is out of memory. |
8168| 14800027  | SQLite: Attempt to write a readonly database. |
8169| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8170| 14800029  | SQLite: The database is full. |
8171| 14800030  | SQLite: Unable to open the database file. |
8172| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8173| 14800032  | SQLite: Abort due to constraint violation. |
8174| 14800033  | SQLite: Data type mismatch. |
8175| 14800034  | SQLite: Library used incorrectly. |
8176
8177**示例:**
8178
8179```ts
8180if(resultSet != undefined) {
8181  const doc = (resultSet as relationalStore.ResultSet).getAsset((resultSet as relationalStore.ResultSet).getColumnIndex("DOC"));
8182}
8183```
8184
8185### getAssets<sup>10+</sup>
8186
8187getAssets(columnIndex: number): Assets
8188
8189以[Assets](#assets10)形式获取当前行中指定列的值,如果当前列的数据类型为Assets类型,会以Assets类型返回指定值,如果当前列中的值为null时,会返回null,其他类型则返回14800000。
8190
8191**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8192
8193**参数:**
8194
8195| 参数名         | 类型     | 必填  | 说明           |
8196| ----------- | ------ | --- | ------------ |
8197| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8198
8199**返回值:**
8200
8201| 类型              | 说明                           |
8202| ---------------- | ---------------------------- |
8203| [Assets](#assets10)| 以Assets形式返回指定列的值。 |
8204
8205**错误码:**
8206
8207以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8208
8209| **错误码ID** | **错误信息**                                                 |
8210|-----------| ------------------------------------------------------------ |
8211| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8212| 14800000  | Inner error. |
8213| 14800011  | Database corrupted. |
8214| 14800012  | Row out of bounds. |
8215| 14800013  | Column out of bounds. |
8216| 14800014  | Already closed. |
8217| 14800021  | SQLite: Generic error. |
8218| 14800022  | SQLite: Callback routine requested an abort. |
8219| 14800023  | SQLite: Access permission denied. |
8220| 14800024  | SQLite: The database file is locked. |
8221| 14800025  | SQLite: A table in the database is locked. |
8222| 14800026  | SQLite: The database is out of memory. |
8223| 14800027  | SQLite: Attempt to write a readonly database. |
8224| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8225| 14800029  | SQLite: The database is full. |
8226| 14800030  | SQLite: Unable to open the database file. |
8227| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8228| 14800032  | SQLite: Abort due to constraint violation. |
8229| 14800033  | SQLite: Data type mismatch. |
8230| 14800034  | SQLite: Library used incorrectly. |
8231
8232**示例:**
8233
8234```ts
8235if(resultSet != undefined) {
8236  const docs = (resultSet as relationalStore.ResultSet).getAssets((resultSet as relationalStore.ResultSet).getColumnIndex("DOCS"));
8237}
8238```
8239
8240### getRow<sup>11+</sup>
8241
8242getRow(): ValuesBucket
8243
8244获取当前行。
8245
8246**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8247
8248**返回值:**
8249
8250| 类型              | 说明                           |
8251| ---------------- | ---------------------------- |
8252| [ValuesBucket](#valuesbucket) | 返回指定行的值。 |
8253
8254**错误码:**
8255
8256以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8257
8258| **错误码ID** | **错误信息**                                                 |
8259|-----------| ------------------------------------------------------------ |
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 row = (resultSet as relationalStore.ResultSet).getRow();
8285}
8286```
8287
8288### getSendableRow<sup>12+</sup>
8289
8290getSendableRow(): sendableRelationalStore.ValuesBucket
8291
8292获取当前行数据的sendable形式,用于跨线程传递使用。
8293
8294**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8295
8296**返回值:**
8297
8298| 类型                                                                                           | 说明                                           |
8299| ---------------------------------------------------------------------------------------------- | ---------------------------------------------- |
8300| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | 当前行数据的sendable形式,用于跨线程传递使用。 |
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
8331import { taskpool } from '@kit.ArkTS';
8332import type ctx from '@ohos.app.ability.common';
8333import { sendableRelationalStore } from '@kit.ArkData';
8334
8335@Concurrent
8336async function getDataByName(name: string, context: ctx.UIAbilityContext) {
8337  const STORE_CONFIG: relationalStore.StoreConfig = {
8338    name: "RdbTest.db",
8339    securityLevel: relationalStore.SecurityLevel.S3
8340  };
8341  const store = await relationalStore.getRdbStore(context, STORE_CONFIG);
8342  const predicates = new relationalStore.RdbPredicates("EMPLOYEE");
8343  predicates.equalTo("NAME", name);
8344  const resultSet = store.querySync(predicates);
8345
8346  if (resultSet.rowCount > 0) {
8347    resultSet.goToFirstRow();
8348    const sendableValuesBucket = resultSet.getSendableRow();
8349    return sendableValuesBucket;
8350  } else {
8351    return null;
8352  }
8353}
8354
8355async function run() {
8356  const task = new taskpool.Task(getDataByName, 'Lisa', getContext());
8357  const sendableValuesBucket  = await taskpool.execute(task) as sendableRelationalStore.ValuesBucket;
8358
8359  if (sendableValuesBucket) {
8360    const columnCount = sendableValuesBucket.size;
8361    const age = sendableValuesBucket.get('age');
8362    const name = sendableValuesBucket.get('name');
8363    console.info(`Query data in taskpool succeeded, name is "${name}", age is "${age}"`)
8364  }
8365}
8366
8367run()
8368```
8369
8370### isColumnNull
8371
8372isColumnNull(columnIndex: number): boolean
8373
8374检查当前行中指定列的值是否为null。
8375
8376**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8377
8378**参数:**
8379
8380| 参数名      | 类型   | 必填 | 说明                    |
8381| ----------- | ------ | ---- | ----------------------- |
8382| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8383
8384**返回值:**
8385
8386| 类型    | 说明                                                      |
8387| ------- | --------------------------------------------------------- |
8388| boolean | 如果当前行中指定列的值为null,则返回true,否则返回false。 |
8389
8390**错误码:**
8391
8392以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8393
8394| **错误码ID** | **错误信息**                                                 |
8395|-----------| ------------------------------------------------------- |
8396| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8397| 14800000  | Inner error. |
8398| 14800011  | Database corrupted. |
8399| 14800012  | Row out of bounds. |
8400| 14800013  | Column out of bounds. |
8401| 14800014  | Already closed. |
8402| 14800021  | SQLite: Generic error. |
8403| 14800022  | SQLite: Callback routine requested an abort. |
8404| 14800023  | SQLite: Access permission denied. |
8405| 14800024  | SQLite: The database file is locked. |
8406| 14800025  | SQLite: A table in the database is locked. |
8407| 14800026  | SQLite: The database is out of memory. |
8408| 14800027  | SQLite: Attempt to write a readonly database. |
8409| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8410| 14800029  | SQLite: The database is full. |
8411| 14800030  | SQLite: Unable to open the database file. |
8412| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8413| 14800032  | SQLite: Abort due to constraint violation. |
8414| 14800033  | SQLite: Data type mismatch. |
8415| 14800034  | SQLite: Library used incorrectly. |
8416
8417**示例:**
8418
8419```ts
8420if(resultSet != undefined) {
8421  const isColumnNull = (resultSet as relationalStore.ResultSet).isColumnNull((resultSet as relationalStore.ResultSet).getColumnIndex("CODES"));
8422}
8423```
8424
8425### close
8426
8427close(): void
8428
8429关闭结果集,若不关闭可能会引起fd泄露和内存泄露。
8430
8431**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8432
8433**示例:**
8434
8435```ts
8436if(resultSet != undefined) {
8437  (resultSet as relationalStore.ResultSet).close();
8438}
8439```
8440
8441**错误码:**
8442
8443以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。
8444
8445| **错误码ID** | **错误信息**                                                 |
8446|-----------| ------------------------------------------------------------ |
8447| 14800000  | Inner error. |
8448| 14800012  | Row out of bounds. |
8449
8450## Transaction<sup>14+</sup>
8451
8452提供以事务方式管理数据库的方法。事务对象是通过[createTransaction](#createtransaction14)接口创建的,不同事务对象之间的操作是隔离的,不同类型事务的区别见[TransactionType](#transactiontype14) 。
8453
8454当前关系型数据库同一时刻只支持一个写事务,所以如果当前[RdbStore](#rdbstore)存在写事务未释放,创建IMMEDIATE或EXCLUSIVE事务会返回14800024错误码。如果是创建的DEFERRED事务,则可能在首次使用DEFERRED事务调用写操作时返回14800024错误码。通过IMMEDIATE或EXCLUSIVE创建写事务或者DEFERRED事务升级到写事务之后,[RdbStore](#rdbstore)的写操作也会返回14800024错误码。
8455
8456当事务并发量较高且写事务持续时间较长时,返回14800024错误码的次数可能会变多,开发者可以通过减少事务占用时长减少14800024出现的次数,也可以通过重试的方式处理14800024错误码。
8457
8458**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8459
8460**示例:**
8461
8462```ts
8463import { BusinessError } from '@kit.BasicServicesKit';
8464
8465let store: relationalStore.RdbStore | undefined = undefined;
8466
8467if(store != undefined) {
8468  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8469    console.info(`createTransaction success`);
8470  }).catch((err: BusinessError) => {
8471    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8472  });
8473}
8474```
8475
8476### commit<sup>14+</sup>
8477
8478commit(): Promise&lt;void&gt;
8479
8480提交已执行的SQL语句。如果是使用异步接口执行sql语句,请确保异步接口执行完成之后再调用commit接口,否则可能会丢失SQL操作。调用commit接口之后,该Transaction对象及创建的ResultSet对象都会被关闭。
8481
8482**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8483
8484**返回值**:
8485
8486| 类型                | 说明                      |
8487| ------------------- | ------------------------- |
8488| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8489
8490**错误码:**
8491
8492以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8493
8494| **错误码ID** | **错误信息**                                                 |
8495|-----------| ------------------------------------------------------------ |
8496| 14800000  | Inner error. |
8497| 14800011  | Database corrupted. |
8498| 14800014  | Already closed. |
8499| 14800023  | SQLite: Access permission denied. |
8500| 14800024  | SQLite: The database file is locked. |
8501| 14800026  | SQLite: The database is out of memory. |
8502| 14800027  | SQLite: Attempt to write a readonly database. |
8503| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8504| 14800029  | SQLite: The database is full. |
8505
8506**示例:**
8507
8508```ts
8509let value1 = "Lisa";
8510let value2 = 18;
8511let value3 = 100.5;
8512let value4 = new Uint8Array([1, 2, 3]);
8513
8514if(store != undefined) {
8515  const valueBucket: relationalStore.ValuesBucket = {
8516    'NAME': value1,
8517    'AGE': value2,
8518    'SALARY': value3,
8519    'CODES': value4,
8520  };
8521  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8522    transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => {
8523      transaction.commit();
8524    }).catch((e: BusinessError) => {
8525      transaction.rollback();
8526      console.error(`execute sql failed, code is ${e.code},message is ${e.message}`);
8527    });
8528  }).catch((err: BusinessError) => {
8529    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8530  });
8531}
8532```
8533
8534### rollback<sup>14+</sup>
8535
8536rollback(): Promise&lt;void&gt;
8537
8538回滚已经执行的SQL语句。调用rollback接口之后,该Transaction对象及创建的ResultSet对象都会被关闭。
8539
8540**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8541
8542**返回值**:
8543
8544| 类型                | 说明                      |
8545| ------------------- | ------------------------- |
8546| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
8547
8548**错误码:**
8549
8550以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8551
8552| **错误码ID** | **错误信息**                                                 |
8553|-----------| ------------------------------------------------------------ |
8554| 14800000  | Inner error. |
8555| 14800011  | Database corrupted. |
8556| 14800014  | Already closed. |
8557| 14800023  | SQLite: Access permission denied. |
8558| 14800024  | SQLite: The database file is locked. |
8559| 14800026  | SQLite: The database is out of memory. |
8560| 14800027  | SQLite: Attempt to write a readonly database. |
8561| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8562| 14800029  | SQLite: The database is full. |
8563
8564**示例:**
8565
8566```ts
8567if(store != undefined) {
8568  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8569    transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => {
8570      transaction.commit();
8571    }).catch((e: BusinessError) => {
8572      transaction.rollback();
8573      console.error(`execute sql failed, code is ${e.code},message is ${e.message}`);
8574    });
8575  }).catch((err: BusinessError) => {
8576    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8577  });
8578}
8579
8580```
8581
8582### insert<sup>14+</sup>
8583
8584insert(table: string, values: ValuesBucket, conflict?: ConflictResolution): Promise&lt;number&gt;
8585
8586向目标表中插入一行数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
8587
8588**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8589
8590**参数:**
8591
8592| 参数名   | 类型                                        | 必填 | 说明                       |
8593| -------- | ------------------------------------------- | ---- | -------------------------- |
8594| table    | string                                      | 是   | 指定的目标表名。           |
8595| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。 |
8596| conflict | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。         |
8597
8598**返回值**:
8599
8600| 类型                  | 说明                                              |
8601| --------------------- | ------------------------------------------------- |
8602| Promise&lt;number&gt; | Promise对象。如果操作成功,返回行ID;否则返回-1。 |
8603
8604**错误码:**
8605
8606以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8607
8608| **错误码ID** | **错误信息**                                                 |
8609|-----------| ------------------------------------------------------------ |
8610| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8611| 14800000  | Inner error. |
8612| 14800011  | Database corrupted. |
8613| 14800014  | Already closed. |
8614| 14800021  | SQLite: Generic error. |
8615| 14800023  | SQLite: Access permission denied. |
8616| 14800024  | SQLite: The database file is locked. |
8617| 14800025  | SQLite: A table in the database is locked. |
8618| 14800026  | SQLite: The database is out of memory. |
8619| 14800027  | SQLite: Attempt to write a readonly database. |
8620| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8621| 14800029  | SQLite: The database is full. |
8622| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8623| 14800033  | SQLite: Data type mismatch. |
8624| 14800047  | The WAL file size exceeds the default limit. |
8625
8626**示例:**
8627
8628```ts
8629let value1 = "Lisa";
8630let value2 = 18;
8631let value3 = 100.5;
8632let value4 = new Uint8Array([1, 2, 3, 4, 5]);
8633
8634// 以下三种方式可用
8635const valueBucket1: relationalStore.ValuesBucket = {
8636  'NAME': value1,
8637  'AGE': value2,
8638  'SALARY': value3,
8639  'CODES': value4,
8640};
8641const valueBucket2: relationalStore.ValuesBucket = {
8642  NAME: value1,
8643  AGE: value2,
8644  SALARY: value3,
8645  CODES: value4,
8646};
8647const valueBucket3: relationalStore.ValuesBucket = {
8648  "NAME": value1,
8649  "AGE": value2,
8650  "SALARY": value3,
8651  "CODES": value4,
8652};
8653
8654if(store != undefined) {
8655  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8656    transaction.insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => {
8657      transaction.commit();
8658      console.info(`Insert is successful, rowId = ${rowId}`);
8659    }).catch((e: BusinessError) => {
8660      transaction.rollback();
8661      console.error(`Insert is failed, code is ${e.code},message is ${e.message}`);
8662    });
8663  }).catch((err: BusinessError) => {
8664    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8665  });
8666}
8667```
8668
8669### insertSync<sup>14+</sup>
8670
8671insertSync(table: string, values: ValuesBucket | sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution): number
8672
8673向目标表中插入一行数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
8674
8675**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8676
8677**参数:**
8678
8679| 参数名   | 类型                                        | 必填 | 说明                                                         |
8680| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
8681| table    | string                                      | 是   | 指定的目标表名。                                             |
8682| values   | [ValuesBucket](#valuesbucket) \| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket)   | 是   | 表示要插入到表中的数据行。                                   |
8683| conflict | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
8684
8685**返回值**:
8686
8687| 类型   | 说明                                 |
8688| ------ | ------------------------------------ |
8689| number | 如果操作成功,返回行ID;否则返回-1。 |
8690
8691**错误码:**
8692
8693以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8694
8695| **错误码ID** | **错误信息**                                                 |
8696| ------------ | ------------------------------------------------------------ |
8697| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8698| 14800000     | Inner error.                                                 |
8699| 14800011     | Database corrupted.                                          |
8700| 14800014     | Already closed.                                              |
8701| 14800021     | SQLite: Generic error.                                       |
8702| 14800023     | SQLite: Access permission denied.                            |
8703| 14800024     | SQLite: The database file is locked.                         |
8704| 14800025     | SQLite: A table in the database is locked.                   |
8705| 14800026     | SQLite: The database is out of memory.                       |
8706| 14800027     | SQLite: Attempt to write a readonly database.                |
8707| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
8708| 14800029     | SQLite: The database is full.                                |
8709| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
8710| 14800033     | SQLite: Data type mismatch.                                  |
8711| 14800047     | The WAL file size exceeds the default limit.                 |
8712
8713**示例:**
8714
8715```ts
8716let value1 = "Lisa";
8717let value2 = 18;
8718let value3 = 100.5;
8719let value4 = new Uint8Array([1, 2, 3, 4, 5]);
8720
8721// 以下三种方式可用
8722const valueBucket1: relationalStore.ValuesBucket = {
8723  'NAME': value1,
8724  'AGE': value2,
8725  'SALARY': value3,
8726  'CODES': value4,
8727};
8728const valueBucket2: relationalStore.ValuesBucket = {
8729  NAME: value1,
8730  AGE: value2,
8731  SALARY: value3,
8732  CODES: value4,
8733};
8734const valueBucket3: relationalStore.ValuesBucket = {
8735  "NAME": value1,
8736  "AGE": value2,
8737  "SALARY": value3,
8738  "CODES": value4,
8739};
8740
8741if(store != undefined) {
8742  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8743    try {
8744      let rowId: number = (transaction as relationalStore.Transaction).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
8745      transaction.commit();
8746      console.info(`Insert is successful, rowId = ${rowId}`);
8747    } catch (e: BusinessError) {
8748      transaction.rollback();
8749      console.error(`Insert is failed, code is ${e.code},message is ${e.message}`);
8750    };
8751  }).catch((err: BusinessError) => {
8752    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8753  });
8754}
8755```
8756
8757### batchInsert<sup>14+</sup>
8758
8759batchInsert(table: string, values: Array&lt;ValuesBucket&gt;): Promise&lt;number&gt;
8760
8761向目标表中插入一组数据,使用Promise异步回调。
8762
8763**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8764
8765**参数:**
8766
8767| 参数名 | 类型                                       | 必填 | 说明                         |
8768| ------ | ------------------------------------------ | ---- | ---------------------------- |
8769| table  | string                                     | 是   | 指定的目标表名。             |
8770| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。|
8771
8772**返回值**:
8773
8774| 类型                  | 说明                                                        |
8775| --------------------- | ----------------------------------------------------------- |
8776| Promise&lt;number&gt; | Promise对象。如果操作成功,返回插入的数据个数,否则返回-1。 |
8777
8778**错误码:**
8779
8780以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8781
8782| **错误码ID** | **错误信息**                                                 |
8783|-----------| ------------------------------------------------------------ |
8784| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8785| 14800000  | Inner error. |
8786| 14800011  | Database corrupted. |
8787| 14800014  | Already closed. |
8788| 14800021  | SQLite: Generic error. |
8789| 14800023  | SQLite: Access permission denied. |
8790| 14800024  | SQLite: The database file is locked. |
8791| 14800025  | SQLite: A table in the database is locked. |
8792| 14800026  | SQLite: The database is out of memory. |
8793| 14800027  | SQLite: Attempt to write a readonly database. |
8794| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8795| 14800029  | SQLite: The database is full. |
8796| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8797| 14800033  | SQLite: Data type mismatch. |
8798| 14800047  | The WAL file size exceeds the default limit. |
8799
8800**示例:**
8801
8802```ts
8803let value1 = "Lisa";
8804let value2 = 18;
8805let value3 = 100.5;
8806let value4 = new Uint8Array([1, 2, 3, 4, 5]);
8807let value5 = "Jack";
8808let value6 = 19;
8809let value7 = 101.5;
8810let value8 = new Uint8Array([6, 7, 8, 9, 10]);
8811let value9 = "Tom";
8812let value10 = 20;
8813let value11 = 102.5;
8814let value12 = new Uint8Array([11, 12, 13, 14, 15]);
8815
8816const valueBucket1: relationalStore.ValuesBucket = {
8817  'NAME': value1,
8818  'AGE': value2,
8819  'SALARY': value3,
8820  'CODES': value4,
8821};
8822const valueBucket2: relationalStore.ValuesBucket = {
8823  'NAME': value5,
8824  'AGE': value6,
8825  'SALARY': value7,
8826  'CODES': value8,
8827};
8828const valueBucket3: relationalStore.ValuesBucket = {
8829  'NAME': value9,
8830  'AGE': value10,
8831  'SALARY': value11,
8832  'CODES': value12,
8833};
8834
8835let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
8836if(store != undefined) {
8837  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8838    transaction.batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => {
8839      transaction.commit();
8840      console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
8841    }).catch((e: BusinessError) => {
8842      transaction.rollback();
8843      console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`);
8844    });
8845  }).catch((err: BusinessError) => {
8846    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8847  });
8848}
8849```
8850
8851### batchInsertSync<sup>14+</sup>
8852
8853batchInsertSync(table: string, values: Array&lt;ValuesBucket&gt;): number
8854
8855向目标表中插入一组数据。
8856
8857**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8858
8859**参数:**
8860
8861| 参数名 | 类型                                       | 必填 | 说明                         |
8862| ------ | ------------------------------------------ | ---- | ---------------------------- |
8863| table  | string                                     | 是   | 指定的目标表名。             |
8864| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。 |
8865
8866**返回值**:
8867
8868| 类型   | 说明                                           |
8869| ------ | ---------------------------------------------- |
8870| number | 如果操作成功,返回插入的数据个数,否则返回-1。 |
8871
8872**错误码:**
8873
8874以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8875
8876| **错误码ID** | **错误信息**                                                 |
8877| ------------ | ------------------------------------------------------------ |
8878| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8879| 14800000     | Inner error.                                                 |
8880| 14800011     | Database corrupted.                                          |
8881| 14800014     | Already closed.                                              |
8882| 14800021     | SQLite: Generic error.                                       |
8883| 14800023     | SQLite: Access permission denied.                            |
8884| 14800024     | SQLite: The database file is locked.                         |
8885| 14800025     | SQLite: A table in the database is locked.                   |
8886| 14800026     | SQLite: The database is out of memory.                       |
8887| 14800027     | SQLite: Attempt to write a readonly database.                |
8888| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
8889| 14800029     | SQLite: The database is full.                                |
8890| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
8891| 14800033     | SQLite: Data type mismatch.                                  |
8892| 14800047     | The WAL file size exceeds the default limit.                 |
8893
8894**示例:**
8895
8896```ts
8897let value1 = "Lisa";
8898let value2 = 18;
8899let value3 = 100.5;
8900let value4 = new Uint8Array([1, 2, 3, 4, 5]);
8901let value5 = "Jack";
8902let value6 = 19;
8903let value7 = 101.5;
8904let value8 = new Uint8Array([6, 7, 8, 9, 10]);
8905let value9 = "Tom";
8906let value10 = 20;
8907let value11 = 102.5;
8908let value12 = new Uint8Array([11, 12, 13, 14, 15]);
8909
8910const valueBucket1: relationalStore.ValuesBucket = {
8911  'NAME': value1,
8912  'AGE': value2,
8913  'SALARY': value3,
8914  'CODES': value4,
8915};
8916const valueBucket2: relationalStore.ValuesBucket = {
8917  'NAME': value5,
8918  'AGE': value6,
8919  'SALARY': value7,
8920  'CODES': value8,
8921};
8922const valueBucket3: relationalStore.ValuesBucket = {
8923  'NAME': value9,
8924  'AGE': value10,
8925  'SALARY': value11,
8926  'CODES': value12,
8927};
8928
8929let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
8930if(store != undefined) {
8931  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
8932    try {
8933      let insertNum: number = (transaction as relationalStore.Transaction).batchInsertSync("EMPLOYEE", valueBuckets);
8934      transaction.commit();
8935      console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
8936    } catch (e) {
8937      transaction.rollback();
8938      console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`);
8939    };
8940  }).catch((err: BusinessError) => {
8941    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
8942  });
8943}
8944```
8945
8946### update<sup>14+</sup>
8947
8948update(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): Promise&lt;number&gt;
8949
8950根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
8951
8952**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8953
8954**参数:**
8955
8956| 参数名     | 类型                                        | 必填 | 说明                                                         |
8957| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
8958| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
8959| predicates | [RdbPredicates](#rdbpredicates)            | 是   | RdbPredicates的实例对象指定的更新条件。                      |
8960| conflict   | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。 默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。                                          |
8961
8962**返回值**:
8963
8964| 类型                  | 说明                                      |
8965| --------------------- | ----------------------------------------- |
8966| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |
8967
8968**错误码:**
8969
8970以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8971
8972| **错误码ID** | **错误信息**                                                 |
8973|-----------| ------------------------------------------------------------ |
8974| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8975| 14800000  | Inner error. |
8976| 14800011  | Database corrupted. |
8977| 14800014  | Already closed. |
8978| 14800021  | SQLite: Generic error. |
8979| 14800023  | SQLite: Access permission denied. |
8980| 14800024  | SQLite: The database file is locked. |
8981| 14800025  | SQLite: A table in the database is locked. |
8982| 14800026  | SQLite: The database is out of memory. |
8983| 14800027  | SQLite: Attempt to write a readonly database. |
8984| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8985| 14800029  | SQLite: The database is full. |
8986| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8987| 14800033  | SQLite: Data type mismatch. |
8988| 14800047  | The WAL file size exceeds the default limit. |
8989
8990**示例:**
8991
8992```ts
8993let value1 = "Rose";
8994let value2 = 22;
8995let value3 = 200.5;
8996let value4 = new Uint8Array([1, 2, 3, 4, 5]);
8997
8998// 以下三种方式可用
8999const valueBucket1: relationalStore.ValuesBucket = {
9000  'NAME': value1,
9001  'AGE': value2,
9002  'SALARY': value3,
9003  'CODES': value4,
9004};
9005const valueBucket2: relationalStore.ValuesBucket = {
9006  NAME: value1,
9007  AGE: value2,
9008  SALARY: value3,
9009  CODES: value4,
9010};
9011const valueBucket3: relationalStore.ValuesBucket = {
9012  "NAME": value1,
9013  "AGE": value2,
9014  "SALARY": value3,
9015  "CODES": value4,
9016};
9017
9018let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
9019predicates.equalTo("NAME", "Lisa");
9020
9021if(store != undefined) {
9022  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9023    transaction.update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => {
9024      transaction.commit();
9025      console.info(`Updated row count: ${rows}`);
9026    }).catch((e: BusinessError) => {
9027      transaction.rollback();
9028      console.error(`Updated failed, code is ${e.code},message is ${e.message}`);
9029    });
9030  }).catch((err: BusinessError) => {
9031    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9032  });
9033}
9034```
9035
9036### updateSync<sup>14+</sup>
9037
9038updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): number
9039
9040根据RdbPredicates的指定实例对象更新数据库中的数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
9041
9042**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9043
9044**参数:**
9045
9046| 参数名     | 类型                                        | 必填 | 说明                                                         |
9047| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
9048| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
9049| predicates | [RdbPredicates](#rdbpredicates)             | 是   | RdbPredicates的实例对象指定的更新条件。                      |
9050| conflict   | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
9051
9052**返回值**:
9053
9054| 类型   | 说明               |
9055| ------ | ------------------ |
9056| number | 返回受影响的行数。 |
9057
9058**错误码:**
9059
9060以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9061
9062| **错误码ID** | **错误信息**                                                 |
9063| ------------ | ------------------------------------------------------------ |
9064| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9065| 14800000     | Inner error.                                                 |
9066| 14800011     | Database corrupted.                                          |
9067| 14800014     | Already closed.                                              |
9068| 14800021     | SQLite: Generic error.                                       |
9069| 14800023     | SQLite: Access permission denied.                            |
9070| 14800024     | SQLite: The database file is locked.                         |
9071| 14800025     | SQLite: A table in the database is locked.                   |
9072| 14800026     | SQLite: The database is out of memory.                       |
9073| 14800027     | SQLite: Attempt to write a readonly database.                |
9074| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
9075| 14800029     | SQLite: The database is full.                                |
9076| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
9077| 14800033     | SQLite: Data type mismatch.                                  |
9078| 14800047     | The WAL file size exceeds the default limit.                 |
9079
9080**示例:**
9081
9082```ts
9083let value1 = "Rose";
9084let value2 = 22;
9085let value3 = 200.5;
9086let value4 = new Uint8Array([1, 2, 3, 4, 5]);
9087
9088// 以下三种方式可用
9089const valueBucket1: relationalStore.ValuesBucket = {
9090  'NAME': value1,
9091  'AGE': value2,
9092  'SALARY': value3,
9093  'CODES': value4,
9094};
9095const valueBucket2: relationalStore.ValuesBucket = {
9096  NAME: value1,
9097  AGE: value2,
9098  SALARY: value3,
9099  CODES: value4,
9100};
9101const valueBucket3: relationalStore.ValuesBucket = {
9102  "NAME": value1,
9103  "AGE": value2,
9104  "SALARY": value3,
9105  "CODES": value4,
9106};
9107
9108let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
9109predicates.equalTo("NAME", "Lisa");
9110
9111if(store != undefined) {
9112  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9113    try {
9114      let rows: Number = (transaction as relationalStore.Transaction).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
9115      transaction.commit();
9116      console.info(`Updated row count: ${rows}`);
9117    } catch (e) {
9118      transaction.rollback();
9119      console.error(`Updated failed, code is ${e.code},message is ${e.message}`);
9120    };
9121  }).catch((err: BusinessError) => {
9122    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9123  });
9124}
9125```
9126
9127### delete<sup>14+</sup>
9128
9129delete(predicates: RdbPredicates):Promise&lt;number&gt;
9130
9131根据RdbPredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。
9132
9133**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9134
9135**参数:**
9136
9137| 参数名     | 类型                                 | 必填 | 说明                                      |
9138| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
9139| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
9140
9141**返回值**:
9142
9143| 类型                  | 说明                            |
9144| --------------------- | ------------------------------- |
9145| Promise&lt;number&gt; | Promise对象。返回受影响的行数。 |
9146
9147**错误码:**
9148
9149以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9150
9151| **错误码ID** | **错误信息**                                                 |
9152|-----------| ------------------------------------------------------------ |
9153| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9154| 14800000  | Inner error. |
9155| 14800011  | Database corrupted. |
9156| 14800014  | Already closed. |
9157| 14800021  | SQLite: Generic error. |
9158| 14800023  | SQLite: Access permission denied. |
9159| 14800024  | SQLite: The database file is locked. |
9160| 14800025  | SQLite: A table in the database is locked. |
9161| 14800026  | SQLite: The database is out of memory. |
9162| 14800027  | SQLite: Attempt to write a readonly database. |
9163| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9164| 14800029  | SQLite: The database is full. |
9165| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9166| 14800033  | SQLite: Data type mismatch. |
9167| 14800047  | The WAL file size exceeds the default limit. |
9168
9169**示例:**
9170
9171```ts
9172let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
9173predicates.equalTo("NAME", "Lisa");
9174
9175if(store != undefined) {
9176  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9177    transaction.delete(predicates).then((rows: Number) => {
9178      transaction.commit();
9179      console.info(`Delete rows: ${rows}`);
9180    }).catch((e: BusinessError) => {
9181      transaction.rollback();
9182      console.error(`Delete failed, code is ${e.code},message is ${e.message}`);
9183    });
9184  }).catch((err: BusinessError) => {
9185    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9186  });
9187}
9188```
9189
9190### deleteSync<sup>14+</sup>
9191
9192deleteSync(predicates: RdbPredicates): number
9193
9194根据RdbPredicates的指定实例对象从数据库中删除数据。
9195
9196**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9197
9198**参数:**
9199
9200| 参数名     | 类型                            | 必填 | 说明                                    |
9201| ---------- | ------------------------------- | ---- | --------------------------------------- |
9202| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
9203
9204**返回值**:
9205
9206| 类型   | 说明               |
9207| ------ | ------------------ |
9208| number | 返回受影响的行数。 |
9209
9210**错误码:**
9211
9212以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9213
9214| **错误码ID** | **错误信息**                                                 |
9215| ------------ | ------------------------------------------------------------ |
9216| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9217| 14800000  | Inner error. |
9218| 14800011  | Database corrupted. |
9219| 14800014  | Already closed. |
9220| 14800021  | SQLite: Generic error. |
9221| 14800023  | SQLite: Access permission denied. |
9222| 14800024  | SQLite: The database file is locked. |
9223| 14800025  | SQLite: A table in the database is locked. |
9224| 14800026  | SQLite: The database is out of memory. |
9225| 14800027  | SQLite: Attempt to write a readonly database. |
9226| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9227| 14800029  | SQLite: The database is full. |
9228| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9229| 14800033  | SQLite: Data type mismatch. |
9230| 14800047  | The WAL file size exceeds the default limit. |
9231
9232**示例:**
9233
9234```ts
9235let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
9236predicates.equalTo("NAME", "Lisa");
9237
9238if(store != undefined) {
9239  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9240    try {
9241      let rows: Number = (transaction as relationalStore.Transaction).deleteSync(predicates);
9242      transaction.commit();
9243      console.info(`Delete rows: ${rows}`);
9244    } catch (e) {
9245      transaction.rollback();
9246      console.error(`Delete failed, code is ${e.code},message is ${e.message}`);
9247    };
9248  }).catch((err: BusinessError) => {
9249    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9250  });
9251}
9252```
9253
9254### query<sup>14+</sup>
9255
9256query(predicates: RdbPredicates, columns?: Array&lt;string&gt;): Promise&lt;ResultSet&gt;
9257
9258根据指定条件查询数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
9259
9260**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9261
9262**参数:**
9263
9264| 参数名     | 类型                                 | 必填 | 说明                                             |
9265| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
9266| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。        |
9267| columns    | Array&lt;string&gt;                  | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
9268
9269**错误码:**
9270
9271以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
9272
9273| **错误码ID** | **错误信息**                                                 |
9274|-----------| ------------------------------------------------------------ |
9275| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9276| 14800000  | Inner error. |
9277| 14800011  | Database corrupted. |
9278| 14800014  | Already closed. |
9279| 14800021  | SQLite: Generic error. |
9280| 14800023  | SQLite: Access permission denied. |
9281| 14800024  | SQLite: The database file is locked. |
9282| 14800026  | SQLite: The database is out of memory. |
9283| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9284| 14800047  | The WAL file size exceeds the default limit. |
9285
9286**返回值**:
9287
9288| 类型                                                    | 说明                                               |
9289| ------------------------------------------------------- | -------------------------------------------------- |
9290| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
9291
9292**示例:**
9293
9294```ts
9295let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
9296predicates.equalTo("NAME", "Rose");
9297
9298if(store != undefined) {
9299  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9300    transaction.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => {
9301      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
9302      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
9303      while (resultSet.goToNextRow()) {
9304        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
9305        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
9306        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
9307        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
9308        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
9309      }
9310      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
9311      resultSet.close();
9312      transaction.commit();
9313    }).catch((e: BusinessError) => {
9314      transaction.rollback();
9315      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
9316    });
9317  }).catch((err: BusinessError) => {
9318    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9319  });
9320}
9321```
9322
9323### querySync<sup>14+</sup>
9324
9325querySync(predicates: RdbPredicates, columns?: Array&lt;string&gt;): ResultSet
9326
9327根据指定条件查询数据库中的数据。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
9328
9329**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9330
9331**参数:**
9332
9333| 参数名     | 类型                            | 必填 | 说明                                                         |
9334| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ |
9335| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。                      |
9336| columns    | Array&lt;string&gt;             | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。默认值为空。 |
9337
9338**错误码:**
9339
9340以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
9341
9342| **错误码ID** | **错误信息**                                                 |
9343| ------------ | ------------------------------------------------------------ |
9344| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9345| 14800000  | Inner error. |
9346| 14800011  | Database corrupted. |
9347| 14800014  | Already closed. |
9348| 14800021  | SQLite: Generic error. |
9349| 14800023  | SQLite: Access permission denied. |
9350| 14800024  | SQLite: The database file is locked. |
9351| 14800025  | SQLite: A table in the database is locked. |
9352| 14800026  | SQLite: The database is out of memory. |
9353| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9354| 14800047  | The WAL file size exceeds the default limit. |
9355
9356**返回值**:
9357
9358| 类型                    | 说明                                |
9359| ----------------------- | ----------------------------------- |
9360| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
9361
9362**示例:**
9363
9364```ts
9365let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
9366predicates.equalTo("NAME", "Rose");
9367
9368if(store != undefined) {
9369  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9370    try {
9371      let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
9372      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
9373      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
9374      while (resultSet.goToNextRow()) {
9375        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
9376        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
9377        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
9378        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
9379        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
9380      }
9381      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
9382      resultSet.close();
9383      transaction.commit();
9384    } catch (e) {
9385      transaction.rollback();
9386      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
9387    };
9388  }).catch((err: BusinessError) => {
9389    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9390  });
9391}
9392```
9393
9394### querySql<sup>14+</sup>
9395
9396querySql(sql: string, args?: Array&lt;ValueType&gt;): Promise&lt;ResultSet&gt;
9397
9398根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
9399
9400**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9401
9402**参数:**
9403
9404| 参数名   | 类型                                 | 必填 | 说明                                                         |
9405| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
9406| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
9407| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
9408
9409**返回值**:
9410
9411| 类型                                                    | 说明                                               |
9412| ------------------------------------------------------- | -------------------------------------------------- |
9413| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
9414
9415**错误码:**
9416
9417以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
9418
9419| **错误码ID** | **错误信息**                                                 |
9420|-----------| ------------------------------------------------------------ |
9421| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9422| 14800000  | Inner error. |
9423| 14800011  | Database corrupted. |
9424| 14800014  | Already closed. |
9425| 14800021  | SQLite: Generic error. |
9426| 14800023  | SQLite: Access permission denied. |
9427| 14800024  | SQLite: The database file is locked. |
9428| 14800025  | SQLite: A table in the database is locked. |
9429| 14800026  | SQLite: The database is out of memory. |
9430| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9431| 14800047  | The WAL file size exceeds the default limit. |
9432
9433**示例:**
9434
9435```ts
9436if(store != undefined) {
9437  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9438    transaction.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then((resultSet: relationalStore.ResultSet) => {
9439      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
9440      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
9441      while (resultSet.goToNextRow()) {
9442        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
9443        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
9444        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
9445        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
9446        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
9447      }
9448      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
9449      resultSet.close();
9450      transaction.commit();
9451    }).catch((e: BusinessError) => {
9452      transaction.rollback();
9453      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
9454    });
9455  }).catch((err: BusinessError) => {
9456    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9457  });
9458}
9459```
9460
9461### querySqlSync<sup>14+</sup>
9462
9463querySqlSync(sql: string, args?: Array&lt;ValueType&gt;): ResultSet
9464
9465根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
9466
9467**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9468
9469**参数:**
9470
9471| 参数名   | 类型                                 | 必填 | 说明                                                         |
9472| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
9473| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
9474| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。默认值为空。 |
9475
9476**返回值**:
9477
9478| 类型                    | 说明                                |
9479| ----------------------- | ----------------------------------- |
9480| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
9481
9482**错误码:**
9483
9484以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
9485
9486| **错误码ID** | **错误信息**                                                 |
9487| ------------ | ------------------------------------------------------------ |
9488| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9489| 14800000  | Inner error. |
9490| 14800011  | Database corrupted. |
9491| 14800014  | Already closed. |
9492| 14800021  | SQLite: Generic error. |
9493| 14800023  | SQLite: Access permission denied. |
9494| 14800024  | SQLite: The database file is locked. |
9495| 14800025  | SQLite: A table in the database is locked. |
9496| 14800026  | SQLite: The database is out of memory. |
9497| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9498| 14800047  | The WAL file size exceeds the default limit. |
9499
9500**示例:**
9501
9502```ts
9503if(store != undefined) {
9504  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9505    try {
9506      let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'");
9507      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
9508      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
9509      while (resultSet.goToNextRow()) {
9510        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
9511        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
9512        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
9513        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
9514        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
9515      }
9516      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
9517      resultSet.close();
9518      transaction.commit();
9519    } catch (e) {
9520      transaction.rollback();
9521      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
9522    };
9523  }).catch((err: BusinessError) => {
9524    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9525  });
9526}
9527```
9528
9529### execute<sup>14+</sup>
9530
9531execute(sql: string, args?: Array&lt;ValueType&gt;): Promise&lt;ValueType&gt;
9532
9533执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType,使用Promise异步回调。
9534
9535该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
9536
9537此接口不支持执行查询、附加数据库和事务操作,查询可以使用[querySql](#querysql14)、[query](#query14)接口代替、附加数据库可以使用[attach](#attach12)接口代替。
9538
9539不支持分号分隔的多条语句。
9540
9541**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9542
9543**参数:**
9544
9545| 参数名   | 类型                                 | 必填 | 说明                                                         |
9546| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
9547| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
9548| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
9549
9550**返回值**:
9551
9552| 类型                | 说明                      |
9553| ------------------- | ------------------------- |
9554| Promise&lt;[ValueType](#valuetype)&gt; | Promise对象,返回sql执行后的结果。 |
9555
9556**错误码:**
9557
9558以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9559
9560| **错误码ID** | **错误信息**                                                 |
9561|-----------| ------------------------------------------------------------ |
9562| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9563| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
9564| 14800000  | Inner error. |
9565| 14800011  | Database corrupted. |
9566| 14800014  | Already closed. |
9567| 14800021  | SQLite: Generic error. |
9568| 14800023  | SQLite: Access permission denied. |
9569| 14800024  | SQLite: The database file is locked. |
9570| 14800025  | SQLite: A table in the database is locked. |
9571| 14800026  | SQLite: The database is out of memory. |
9572| 14800027  | SQLite: Attempt to write a readonly database. |
9573| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9574| 14800029  | SQLite: The database is full. |
9575| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9576| 14800033  | SQLite: Data type mismatch. |
9577| 14800047  | The WAL file size exceeds the default limit. |
9578
9579**示例:**
9580
9581```ts
9582// 删除表中所有数据
9583if(store != undefined) {
9584  const SQL_DELETE_TABLE = 'DELETE FROM test';
9585  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9586    transaction.execute(SQL_DELETE_TABLE).then((data) => {
9587      transaction.commit();
9588      console.info(`delete result: ${data}`);
9589    }).catch((e: BusinessError) => {
9590      transaction.rollback();
9591      console.error(`delete failed, code is ${e.code}, message is ${e.message}`);
9592    });
9593  }).catch((err: BusinessError) => {
9594    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9595  });
9596}
9597```
9598
9599### executeSync<sup>14+</sup>
9600
9601executeSync(sql: string, args?: Array&lt;ValueType&gt;): ValueType
9602
9603执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType。
9604
9605该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
9606
9607此接口不支持执行查询、附加数据库和事务操作,查询可以使用[querySql](#querysql14)、[query](#query14)接口代替、附加数据库可以使用[attach](#attach12)接口代替。
9608
9609不支持分号分隔的多条语句。
9610
9611**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9612
9613**参数:**
9614
9615| 参数名 | 类型                                 | 必填 | 说明                                                         |
9616| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
9617| sql    | string                               | 是   | 指定要执行的SQL语句。                                        |
9618| args   | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。该参数不填,或者填null或undefined,都认为是sql参数语句完整。默认值为空。 |
9619
9620**返回值**:
9621
9622| 类型                    | 说明                |
9623| ----------------------- | ------------------- |
9624| [ValueType](#valuetype) | 返回sql执行后的结果。 |
9625
9626**错误码:**
9627
9628以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9629
9630| **错误码ID** | **错误信息**                                                 |
9631| ------------ | ------------------------------------------------------------ |
9632| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9633| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
9634| 14800000     | Inner error.                                                 |
9635| 14800011     | Database corrupted.                                          |
9636| 14800014     | Already closed.                                              |
9637| 14800021     | SQLite: Generic error.                                       |
9638| 14800023     | SQLite: Access permission denied.                            |
9639| 14800024     | SQLite: The database file is locked.                         |
9640| 14800025     | SQLite: A table in the database is locked.                   |
9641| 14800026     | SQLite: The database is out of memory.                       |
9642| 14800027     | SQLite: Attempt to write a readonly database.                |
9643| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
9644| 14800029     | SQLite: The database is full.                                |
9645| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
9646| 14800033     | SQLite: Data type mismatch.                                  |
9647| 14800047     | The WAL file size exceeds the default limit.                 |
9648
9649**示例:**
9650
9651```ts
9652// 删除表中所有数据
9653if(store != undefined) {
9654  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9655    const SQL_DELETE_TABLE = 'DELETE FROM test';
9656    try {
9657      let data = (transaction as relationalStore.Transaction).executeSync(SQL_DELETE_TABLE);
9658      transaction.commit();
9659      console.info(`delete result: ${data}`);
9660    } catch (e) {
9661      transaction.rollback();
9662      console.error(`delete failed, code is ${e.code}, message is ${e.message}`);
9663    };
9664  }).catch((err: BusinessError) => {
9665    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9666  });
9667}
9668```