• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.data.relationalStore (关系型数据库)
2
3关系型数据库(Relational Database,RDB)是一种基于关系模型来管理数据的数据库。关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制,对外提供了一系列的增、删、改、查等接口,也可以直接运行用户输入的SQL语句来满足复杂的场景需要。支持通过[ResultSet.getSendableRow](#getsendablerow12)方法获取Sendable数据,进行跨线程传递。
4
5为保证插入并读取数据成功,建议一条数据不要超过2M。超出该大小,插入成功,读取失败。
6
7大数据量场景下查询数据可能会导致耗时长甚至应用卡死,如有相关操作可参考文档[批量数据写数据库场景](../../arkts-utils/batch-database-operations-guide.md),且有建议如下:
8- 单次查询数据量不超过5000条。
9- 在[TaskPool](../apis-arkts/js-apis-taskpool.md)中查询。
10- 拼接SQL语句尽量简洁。
11- 合理地分批次查询。
12
13该模块提供以下关系型数据库相关的常用功能:
14
15- [RdbPredicates](#rdbpredicates):数据库中用来代表数据实体的性质、特征或者数据实体之间关系的词项,主要用来定义数据库的操作条件。
16- [RdbStore](#rdbstore):提供管理关系数据库(RDB)方法的接口。
17- [ResultSet](#resultset):提供用户调用关系型数据库查询接口之后返回的结果集合。
18- [Transaction](#transaction14):提供管理事务对象的接口。
19
20> **说明:**
21>
22> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
23
24## 导入模块
25
26```ts
27import { relationalStore } from '@kit.ArkData';
28```
29
30## relationalStore.getRdbStore
31
32getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback<RdbStore>): void
33
34创建或打开已有的关系型数据库,开发者可以根据自己的需求配置config参数,然后通过RdbStore调用相关接口执行数据操作。使用callback异步回调。
35
36对应沙箱路径下无数据库文件时,将创建数据库文件,文件创建位置详见[StoreConfig](#storeconfig)。对应路径下已有数据库文件时,将打开已有数据库文件。
37
38开发者在创建数据库时,应谨慎配置是否进行数据库加密的参数[encrypt](#storeconfig),数据库创建后,禁止对该参数进行修改。
39
40| 当前开库的加密类型  | 本设备上创建该数据库时的加密类型           | 结果 |
41| ------- | -------------------------------- | ---- |
42| 非加密 | 加密                          | 将数据库以加密方式打开。   |
43| 加密 | 非加密                          | 将数据库以非加密方式打开。   |
44
45getRdbStore目前不支持多线程并发操作。
46
47**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
48
49**参数:**
50
51| 参数名   | 类型                                           | 必填 | 说明                                                         |
52| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
53| 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)。 |
54| config   | [StoreConfig](#storeconfig)               | 是   | 与此RDB存储相关的数据库配置。                                |
55| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | 是   | 指定callback回调函数,返回RdbStore对象。                   |
56
57**错误码:**
58
59以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
60
61| **错误码ID** | **错误信息**   |
62|-----------|---------|
63| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
64| 14800000  | Inner error.     |
65| 14800010  | Invalid database path.   |
66| 14800011  | Database corrupted.    |
67| 14801001  | The operation is supported in the stage model only.    |
68| 14801002  | Invalid data group ID.   |
69| 14800017  | Config changed.   |
70| 14800020  | The secret key is corrupted or lost.   |
71| 14800021  | SQLite: Generic error.    |
72| 14800022  | SQLite: Callback routine requested an abort.   |
73| 14800023  | SQLite: Access permission denied.    |
74| 14800027  | SQLite: Attempt to write a readonly database.   |
75| 14800028  | SQLite: Some kind of disk I/O error occurred.     |
76| 14800029  | SQLite: The database is full.  |
77| 14800030  | SQLite: Unable to open the database file.   |
78
79**示例:**
80
81FA模型示例:
82
83<!--code_no_check_fa-->
84```js
85import { featureAbility } from '@kit.AbilityKit';
86import { BusinessError } from '@kit.BasicServicesKit';
87
88let store: relationalStore.RdbStore | undefined = undefined;
89let context = featureAbility.getContext();
90
91const STORE_CONFIG: relationalStore.StoreConfig = {
92  name: "RdbTest.db",
93  securityLevel: relationalStore.SecurityLevel.S3
94};
95
96relationalStore.getRdbStore(context, STORE_CONFIG, async (err: BusinessError, rdbStore: relationalStore.RdbStore) => {
97  if (err) {
98    console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
99    return;
100  }
101  console.info('Get RdbStore successfully.');
102  store = rdbStore;
103  // 成功获取到 rdbStore 后执行后续操作
104});
105```
106
107Stage模型示例:
108
109```ts
110import { UIAbility } from '@kit.AbilityKit';
111import { window } from '@kit.ArkUI';
112import { BusinessError } from '@kit.BasicServicesKit';
113
114let store: relationalStore.RdbStore | undefined = undefined;
115
116class EntryAbility extends UIAbility {
117  onWindowStageCreate(windowStage: window.WindowStage) {
118    const STORE_CONFIG: relationalStore.StoreConfig = {
119      name: "RdbTest.db",
120      securityLevel: relationalStore.SecurityLevel.S3
121    };
122
123    relationalStore.getRdbStore(this.context, STORE_CONFIG, async (err: BusinessError, rdbStore: relationalStore.RdbStore) => {
124      if (err) {
125        console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
126        return;
127      }
128      console.info('Get RdbStore successfully.');
129      store = rdbStore;
130      // 成功获取到 rdbStore 后执行后续操作
131    });
132  }
133}
134```
135
136## relationalStore.getRdbStore
137
138getRdbStore(context: Context, config: StoreConfig): Promise&lt;RdbStore&gt;
139
140创建或打开已有的关系型数据库,开发者可以根据自己的需求配置config参数,然后通过RdbStore调用相关接口执行数据操作。使用Promise异步回调。
141
142对应沙箱路径下无数据库文件时,将创建数据库文件,文件创建位置详见[StoreConfig](#storeconfig)。对应路径下已有数据库文件时,将打开已有数据库文件。
143
144开发者在创建数据库时,应谨慎配置是否进行数据库加密的参数[encrypt](#storeconfig),数据库创建后,禁止对该参数进行修改。
145
146| 当前开库的加密类型  | 本设备上创建该数据库时的加密类型           | 结果 |
147| ------- | -------------------------------- | ---- |
148| 非加密 | 加密                          | 将数据库以加密方式打开。   |
149| 加密 | 非加密                          | 将数据库以非加密方式打开。   |
150
151getRdbStore目前不支持多线程并发操作。
152
153**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
154
155**参数:**
156
157| 参数名  | 类型                             | 必填 | 说明                                                         |
158| ------- | -------------------------------- | ---- | ------------------------------------------------------------ |
159| 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)。 |
160| config  | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |
161
162**返回值**:
163
164| 类型                                      | 说明                              |
165| ----------------------------------------- | --------------------------------- |
166| Promise&lt;[RdbStore](#rdbstore)&gt; | Promise对象。返回RdbStore对象。 |
167
168**错误码:**
169
170以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
171
172| **错误码ID** | **错误信息**                                                 |
173|-----------| ------------------------------------------------------------ |
174| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
175| 14800000  | Inner error. |
176| 14800010  | Invalid database path. |
177| 14800011  | Database corrupted.  |
178| 14801001  | The operation is supported in the stage model only.                               |
179| 14801002  | Invalid data group ID.                             |
180| 14800017  | Config changed. |
181| 14800020  | The secret key is corrupted or lost.   |
182| 14800021  | SQLite: Generic error. |
183| 14800022  | SQLite: Callback routine requested an abort.   |
184| 14800023  | SQLite: Access permission denied.    |
185| 14800027  | SQLite: Attempt to write a readonly database. |
186| 14800028  | SQLite: Some kind of disk I/O error occurred. |
187| 14800029  | SQLite: The database is full. |
188| 14800030  | SQLite: Unable to open the database file. |
189
190**示例:**
191
192FA模型示例:
193
194<!--code_no_check_fa-->
195```js
196import { featureAbility } from '@kit.AbilityKit';
197import { BusinessError } from '@kit.BasicServicesKit';
198
199let store: relationalStore.RdbStore | undefined = undefined;
200let context = featureAbility.getContext();
201
202const STORE_CONFIG: relationalStore.StoreConfig = {
203  name: "RdbTest.db",
204  securityLevel: relationalStore.SecurityLevel.S3
205};
206
207relationalStore.getRdbStore(context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => {
208  store = rdbStore;
209  console.info('Get RdbStore successfully.');
210}).catch((err: BusinessError) => {
211  console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
212});
213```
214
215Stage模型示例:
216
217```ts
218import { UIAbility } from '@kit.AbilityKit';
219import { window } from '@kit.ArkUI';
220import { BusinessError } from '@kit.BasicServicesKit';
221
222let store: relationalStore.RdbStore | undefined = undefined;
223
224class EntryAbility extends UIAbility {
225  onWindowStageCreate(windowStage: window.WindowStage) {
226    const STORE_CONFIG: relationalStore.StoreConfig = {
227      name: "RdbTest.db",
228      securityLevel: relationalStore.SecurityLevel.S3
229    };
230
231    relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => {
232      store = rdbStore;
233      console.info('Get RdbStore successfully.');
234    }).catch((err: BusinessError) => {
235      console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
236    });
237  }
238}
239```
240
241## relationalStore.deleteRdbStore
242
243deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
244
245删除数据库文件,使用callback异步回调。
246
247删除成功后,建议将数据库对象置为null。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则调用此接口进行删库无效,必须使用 [deleteRdbStore](#relationalstoredeleterdbstore10) 接口进行删库。
248
249**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
250
251**参数:**
252
253| 参数名   | 类型                      | 必填 | 说明                                                         |
254| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
255| 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)。 |
256| name     | string                    | 是   | 数据库名称。                                                 |
257| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。                                       |
258
259**错误码:**
260
261以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
262
263| **错误码ID** | **错误信息**                        |
264|-----------|---------------------------------------|
265| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
266| 14800000  | Inner error.     |
267| 14800010  | Failed to open or delete database by invalid database path. |
268
269**示例:**
270
271FA模型示例:
272
273<!--code_no_check_fa-->
274```js
275import { featureAbility } from '@kit.AbilityKit';
276import { BusinessError } from '@kit.BasicServicesKit';
277
278let store: relationalStore.RdbStore | undefined = undefined;
279let context = featureAbility.getContext();
280
281relationalStore.deleteRdbStore(context, "RdbTest.db", (err: BusinessError) => {
282  if (err) {
283    console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
284    return;
285  }
286  store = undefined;
287  console.info('Delete RdbStore successfully.');
288});
289```
290
291Stage模型示例:
292
293```ts
294import { UIAbility } from '@kit.AbilityKit';
295import { window } from '@kit.ArkUI';
296import { BusinessError } from '@kit.BasicServicesKit';
297
298let store: relationalStore.RdbStore | undefined = undefined;
299
300class EntryAbility extends UIAbility {
301  onWindowStageCreate(windowStage: window.WindowStage) {
302    relationalStore.deleteRdbStore(this.context, "RdbTest.db", (err: BusinessError) => {
303      if (err) {
304        console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
305        return;
306      }
307      store = undefined;
308      console.info('Delete RdbStore successfully.');
309    });
310  }
311}
312```
313
314## relationalStore.deleteRdbStore
315
316deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;
317
318使用指定的数据库文件配置删除数据库,使用Promise异步回调。
319
320删除成功后,建议将数据库对象置为null。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则调用此接口进行删库无效,必须使用 [deleteRdbStore](#relationalstoredeleterdbstore10-1) 接口进行删库。
321
322**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
323
324**参数**
325
326| 参数名  | 类型    | 必填 | 说明                                                         |
327| ------- | ------- | ---- | ------------------------------------------------------------ |
328| 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)。 |
329| name    | string  | 是   | 数据库名称。                                                 |
330
331**返回值**:
332
333| 类型                | 说明                      |
334| ------------------- | ------------------------- |
335| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
336
337**错误码:**
338
339以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
340
341| **错误码ID** | **错误信息**                                                                         |
342|-----------|----------------------------------------------------------------------------------|
343| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
344| 14800000  | Inner error.                                                                     |
345| 14800010  | Invalid database path.                      |
346
347**示例:**
348
349FA模型示例:
350
351<!--code_no_check_fa-->
352```js
353import { featureAbility } from '@kit.AbilityKit';
354import { BusinessError } from '@kit.BasicServicesKit';
355
356let store: relationalStore.RdbStore | undefined = undefined;
357let context = featureAbility.getContext();
358
359relationalStore.deleteRdbStore(context, "RdbTest.db").then(() => {
360  store = undefined;
361  console.info('Delete RdbStore successfully.');
362}).catch((err: BusinessError) => {
363  console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
364});
365```
366
367Stage模型示例:
368
369```ts
370import { UIAbility } from '@kit.AbilityKit';
371import { window } from '@kit.ArkUI';
372import { BusinessError } from '@kit.BasicServicesKit';
373
374let store: relationalStore.RdbStore | undefined = undefined;
375
376class EntryAbility extends UIAbility {
377  onWindowStageCreate(windowStage: window.WindowStage) {
378    relationalStore.deleteRdbStore(this.context, "RdbTest.db").then(() => {
379      store = undefined;
380      console.info('Delete RdbStore successfully.');
381    }).catch((err: BusinessError) => {
382      console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
383    });
384  }
385}
386```
387
388## relationalStore.deleteRdbStore<sup>10+</sup>
389
390deleteRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback\<void>): void
391
392使用指定的数据库文件配置删除数据库,使用callback异步回调。
393
394删除成功后,建议将数据库对象置为null。若数据库文件处于公共沙箱目录下,则删除数据库时必须使用该接口,当存在多个进程操作同一个数据库的情况,建议向其他进程发送数据库删除通知使其感知并处理。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则必须调用此接口进行删库。
395
396**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
397
398**参数:**
399
400| 参数名   | 类型                        | 必填 | 说明                                                         |
401| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
402| 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)。 |
403| config   | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |
404| callback | AsyncCallback&lt;void&gt;   | 是   | 指定callback回调函数。                                       |
405
406**错误码:**
407
408以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
409
410| **错误码ID** | **错误信息**          |
411|-----------|----------|
412| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
413| 14800000  | Inner error.        |
414| 14800010  | Failed to open or delete database by invalid database path.        |
415| 14801001  | The operation is supported in the stage model only.         |
416| 14801002  | Invalid data group ID.        |
417
418**示例:**
419
420FA模型示例:
421
422<!--code_no_check_fa-->
423```js
424import { featureAbility } from '@kit.AbilityKit';
425import { BusinessError } from '@kit.BasicServicesKit';
426
427let store: relationalStore.RdbStore | undefined = undefined;
428let context = featureAbility.getContext();
429
430const STORE_CONFIG: relationalStore.StoreConfig = {
431  name: "RdbTest.db",
432  securityLevel: relationalStore.SecurityLevel.S3
433};
434
435relationalStore.deleteRdbStore(context, STORE_CONFIG, (err: BusinessError) => {
436  if (err) {
437    console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
438    return;
439  }
440  store = undefined;
441  console.info('Delete RdbStore successfully.');
442});
443```
444
445Stage模型示例:
446
447```ts
448import { UIAbility } from '@kit.AbilityKit';
449import { window } from '@kit.ArkUI';
450import { BusinessError } from '@kit.BasicServicesKit';
451
452let store: relationalStore.RdbStore | undefined = undefined;
453
454class EntryAbility extends UIAbility {
455  onWindowStageCreate(windowStage: window.WindowStage) {
456    const STORE_CONFIG: relationalStore.StoreConfig = {
457      name: "RdbTest.db",
458      securityLevel: relationalStore.SecurityLevel.S3
459    };
460    relationalStore.deleteRdbStore(this.context, STORE_CONFIG, (err: BusinessError) => {
461      if (err) {
462        console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
463        return;
464      }
465      store = undefined;
466      console.info('Delete RdbStore successfully.');
467    });
468  }
469}
470```
471
472## relationalStore.deleteRdbStore<sup>10+</sup>
473
474deleteRdbStore(context: Context, config: StoreConfig): Promise\<void>
475
476使用指定的数据库文件配置删除数据库,使用Promise异步回调。
477
478删除成功后,建议将数据库对象置为null。若数据库文件处于公共沙箱目录下,则删除数据库时必须使用该接口,当存在多个进程操作同一个数据库的情况,建议向其他进程发送数据库删除通知使其感知并处理。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则必须调用此接口进行删库。
479
480**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
481
482**参数**
483
484| 参数名  | 类型                        | 必填 | 说明                                                         |
485| ------- | --------------------------- | ---- | ------------------------------------------------------------ |
486| 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)。 |
487| config  | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |
488
489**返回值**:
490
491| 类型                | 说明                      |
492| ------------------- | ------------------------- |
493| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
494
495**错误码:**
496
497以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。
498
499| **错误码ID** | **错误信息**             |
500|-----------|---------------------|
501| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
502| 801       | Capability not supported.      |
503| 14800000  | Inner error.      |
504| 14800010  | Invalid database path.   |
505| 14801001  | The operation is supported in the stage model only.   |
506| 14801002  | Invalid data group ID.   |
507
508**示例:**
509
510FA模型示例:
511
512<!--code_no_check_fa-->
513```js
514import { featureAbility } from "@kit.AbilityKit";
515import { BusinessError } from '@kit.BasicServicesKit';
516
517let store: relationalStore.RdbStore | undefined = undefined;
518let context = featureAbility.getContext();
519
520const STORE_CONFIG: relationalStore.StoreConfig = {
521  name: "RdbTest.db",
522  securityLevel: relationalStore.SecurityLevel.S3
523};
524
525relationalStore.deleteRdbStore(context, STORE_CONFIG).then(() => {
526  store = undefined;
527  console.info('Delete RdbStore successfully.');
528}).catch((err: BusinessError) => {
529  console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
530});
531```
532
533Stage模型示例:
534
535```ts
536import { UIAbility } from '@kit.AbilityKit';
537import { window } from '@kit.ArkUI';
538import { BusinessError } from '@kit.BasicServicesKit';
539
540let store: relationalStore.RdbStore | undefined = undefined;
541
542class EntryAbility extends UIAbility {
543  onWindowStageCreate(windowStage: window.WindowStage) {
544    const STORE_CONFIG: relationalStore.StoreConfig = {
545      name: "RdbTest.db",
546      securityLevel: relationalStore.SecurityLevel.S3
547    };
548    relationalStore.deleteRdbStore(this.context, STORE_CONFIG).then(() => {
549      store = undefined;
550      console.info('Delete RdbStore successfully.');
551    }).catch((err: BusinessError) => {
552      console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
553    });
554  }
555}
556```
557## relationalStore.isVectorSupported<sup>18+</sup>
558
559isVectorSupported(): boolean
560
561判断系统是否提供向量数据库能力。
562
563**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
564
565**返回值**:
566
567| 类型    | 说明                                              |
568| ------- | ------------------------------------------------- |
569| boolean | 系统具备向量数据库能力时返回true,否则返回false。 |
570
571**示例:**
572
573```
574let result = relationalStore.isVectorSupported();
575```
576
577## relationalStore.isTokenizerSupported<sup>18+</sup>
578
579isTokenizerSupported(tokenizer: Tokenizer): boolean
580
581判断当前平台是否支持传入的分词器,此为同步接口。
582
583如果当前平台支持传入的分词器时,此接口返回值为true;反之,返回值为false。
584
585**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
586
587**参数:**
588
589| 参数名  | 类型                  | 必填 | 说明                                                         |
590| ------- | --------------------- | ---- | ------------------------------------------------------------ |
591| tokenizer | [Tokenizer](#tokenizer17)               | 是   | 需要被判断是否支持的分词器。 |
592
593**返回值:**
594
595| 类型                | 说明                      |
596| ------------------- | ------------------------- |
597| boolean | true表示当前平台支持当前传入的分词器,false表示当前平台不支持当前传入的分词器。 |
598
599**错误码:**
600
601以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
602
603| **错误码ID** | **错误信息**             |
604|-----------|---------------------|
605| 401       | Parameter error. Possible causes: Incorrect parameter types. |
606
607
608**示例:**
609
610```ts
611import { relationalStore } from '@kit.ArkData'; // 导入模块
612
613let customType = relationalStore.Tokenizer.CUSTOM_TOKENIZER;
614let customTypeSupported = relationalStore.isTokenizerSupported(customType);
615console.info("custom tokenizer supported on current platform: " + customTypeSupported);
616```
617
618## StoreConfig
619
620管理关系数据库配置。
621
622| 名称        | 类型          | 必填 | 说明                                                      |
623| ------------- | ------------- | ---- | --------------------------------------------------------- |
624| name          | string        | 是   | 数据库文件名,也是数据库唯一标识符。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core   |
625| securityLevel | [SecurityLevel](#securitylevel) | 是   | 设置数据库安全级别。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core|
626| encrypt       | boolean       | 否   | 指定数据库是否加密,默认不加密。<br/> true:加密。<br/> false:非加密。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
627| dataGroupId<sup>10+</sup> | string | 否 | 应用组ID,<!--RP1-->暂不支持指定dataGroupId在对应的沙箱路径下创建RdbStore实例。<!--RP1End--><br/>**模型约束:** 此属性仅在Stage模型下可用。<br/>从API version 10开始,支持此可选参数。dataGroupId共沙箱的方式不支持多进程访问加密数据库,当此参数不填时,默认在本应用沙箱目录下创建RdbStore实例。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
628| customDir<sup>11+</sup> | string | 否 | 数据库自定义路径。<br/>**使用约束:** 数据库路径大小限制为128字节,如果超过该大小会开库失败,返回错误。<br/>从API version 11开始,支持此可选参数。数据库将在如下的目录结构中被创建:context.databaseDir + "/rdb/" + customDir,其中context.databaseDir是应用沙箱对应的路径,"/rdb/"表示创建的是关系型数据库,customDir表示自定义的路径。当此参数不填时,默认在本应用沙箱目录下创建RdbStore实例。从API version 18开始,如果同时配置了rootDir参数,将打开或删除如下路径数据库:rootDir + "/" + customDir + "/" + name。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
629| rootDir<sup>18+</sup> | string | 否 | 指定数据库根路径。<br/>从API version 18开始,支持此可选参数。将从如下目录打开或删除数据库:rootDir + "/" + customDir。通过设置此参数打开的数据库为只读模式,不允许对数据库进行写操作,否则返回错误码801。配置此参数打开或删除数据库时,应确保对应路径下数据库文件存在,并且有读取权限,否则返回错误码14800010。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
630| autoCleanDirtyData<sup>11+</sup> | boolean | 否 | 指定是否自动清理云端删除后同步到本地的数据,true表示自动清理,false表示手动清理,默认自动清理。<br/>对于端云协同的数据库,当云端删除的数据同步到设备端时,可通过该参数设置设备端是否自动清理。手动清理可以通过[cleanDirtyData<sup>11+</sup>](#cleandirtydata11)接口清理。<br/>从API version 11开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
631| allowRebuild<sup>12+</sup> | boolean | 否 | 指定数据库是否支持异常时自动删除,并重建一个空库空表,默认不删除。<br/>true:自动删除。<br/>false:不自动删除。<br/>从API version 12开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
632| isReadOnly<sup>12+</sup> | boolean | 否 | 指定数据库是否只读,默认为数据库可读写。<br/>true:只允许从数据库读取数据,不允许对数据库进行写操作,否则会返回错误码801。<br/>false:允许对数据库进行读写操作。<br/>从API version 12开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
633| 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 |
634| cryptoParam<sup>14+</sup> | [CryptoParam](#cryptoparam14) | 否 | 指定用户自定义的加密参数。<br/>当此参数不填时,使用默认的加密参数,见[CryptoParam](#cryptoparam14)各参数默认值。<br/>此配置只有在encrypt选项设置为真时才有效。<br/>从API version 14开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
635| vector<sup>18+</sup> | boolean | 否 | 指定数据库是否是向量数据库,true表示向量数据库,false表示关系型数据库,默认为false。<br/>向量数据库适用于存储和处理高维向量数据,关系型数据库适用于存储和处理结构化数据。<br/>向量数据库目前支持[execute](#execute12-1),[querySql](#querysql-1),[beginTrans](#begintrans12),[commit](#commit12),[rollback](#rollback12),[backup](#backup),[restore](#restore)以及[ResultSet](#resultset)类型操作接口。当使用向量数据库时,在调用deleteRdbStore接口前,应当确保向量数据库已经被正确关闭。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
636| tokenizer<sup>17+</sup> | [Tokenizer](#tokenizer17) | 否 | 指定用户在fts场景下使用哪种分词器。<br/>当此参数不填时,则在fts下不支持中文以及多国语言分词,但仍可支持英文分词。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
637| persist<sup>18+</sup> | boolean | 否 | 指定数据库是否需要持久化。true表示持久化,false表示不持久化,即内存数据库。默认为true。<br/>内存数据库不支持加密、backup、restore、跨进程访问及分布式能力,securityLevel属性会被忽略。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
638
639## SecurityLevel
640
641数据库的安全级别枚举。请使用枚举名称而非枚举值。数据库的安全等级仅支持由低向高设置,不支持由高向低设置。
642
643> **说明:**
644>
645> 若需要进行同步操作,数据库安全等级应不高于对端设备安全等级,具体可见[跨设备同步访问控制机制](../../database/sync-app-data-across-devices-overview.md#跨设备同步访问控制机制)。
646
647**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
648
649| 名称 | 值   | 说明                                                         |
650| ---- | ---- | ------------------------------------------------------------ |
651| S1   | 1    | 表示数据库的安全级别为低级别,当数据泄露时会产生较低影响。例如,包含壁纸等系统数据的数据库。 |
652| S2   | 2    | 表示数据库的安全级别为中级别,当数据泄露时会产生较大影响。例如,包含录音、视频等用户生成数据或通话记录等信息的数据库。 |
653| S3   | 3    | 表示数据库的安全级别为高级别,当数据泄露时会产生重大影响。例如,包含用户运动、健康、位置等信息的数据库。 |
654| S4   | 4    | 表示数据库的安全级别为关键级别,当数据泄露时会产生严重影响。例如,包含认证凭据、财务数据等信息的数据库。 |
655
656## CryptoParam<sup>14+</sup>
657
658数据库加密参数配置。此配置只有在StoreConfig的encrypt选项设置为真时才有效。
659
660**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
661
662| 名称          | 类型   | 必填 | 说明                                                         |
663| ------------- | ------ | ---- | ------------------------------------------------------------ |
664| encryptionKey | Uint8Array | 是   | 指定数据库加/解密使用的密钥。<br/>如传入密钥为空,则由数据库负责生成并保存密钥,并使用生成的密钥打开数据库文件。<br/>使用完后用户需要将密钥内容全部置为零。 |
665| iterationCount | number | 否 | 整数类型,指定数据库PBKDF2算法的迭代次数,默认值为10000。<br/>迭代次数应当为大于零的整数,若非整数则向下取整。<br/>不指定此参数或指定为零时,使用默认值10000,并使用默认加密算法AES_256_GCM。 |
666| encryptionAlgo | [EncryptionAlgo](#encryptionalgo14) | 否 | 指定数据库加解密使用的加密算法。如不指定,默认值为 AES_256_GCM。 |
667| hmacAlgo | [HmacAlgo](#hmacalgo14) | 否 | 指定数据库加解密使用的HMAC算法。如不指定,默认值为SHA256。 |
668| kdfAlgo | [KdfAlgo](#kdfalgo14) | 否 | 指定数据库加解密使用的PBKDF2算法。如不指定,默认使用和HMAC算法相等的算法。 |
669| cryptoPageSize | number | 否 | 整数类型,指定数据库加解密使用的页大小。如不指定,默认值为1024字节。<br/>用户指定的页大小应为1024到65536范围内的整数,并且为2<sup>n</sup>。若指定值非整数,则向下取整。 |
670
671## EncryptionAlgo<sup>14+</sup>
672
673数据库的加密算法枚举。请使用枚举名称而非枚举值。
674
675**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
676
677| 名称 | 值   | 说明 |
678| ---- | ---- | ---- |
679| AES_256_GCM |  0    | AES_256_GCM加密算法。     |
680| AES_256_CBC |  1    | AES_256_CBC加密算法。     |
681
682## HmacAlgo<sup>14+</sup>
683
684数据库的HMAC算法枚举。请使用枚举名称而非枚举值。
685
686**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
687
688| 名称 | 值   | 说明 |
689| ---- | ---- | ---- |
690| SHA1 |  0    | HMAC_SHA1算法。     |
691| SHA256 |  1    | HMAC_SHA256算法。     |
692| SHA512 |  2    | HMAC_SHA512算法。    |
693
694## KdfAlgo<sup>14+</sup>
695
696数据库的PBKDF2算法枚举。请使用枚举名称而非枚举值。
697
698**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
699
700| 名称 | 值   | 说明 |
701| ---- | ---- | ---- |
702| KDF_SHA1 |  0    | PBKDF2_HMAC_SHA1算法。     |
703| KDF_SHA256 |  1    | PBKDF2_HMAC_SHA256算法。     |
704| KDF_SHA512 |  2    | PBKDF2_HMAC_SHA512算法。     |
705
706## Tokenizer<sup>17+</sup>
707
708描述fts(全文搜索)场景下使用的分词器枚举。请使用枚举名称而非枚举值。
709
710**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
711
712| 名称                              | 值   | 说明             |
713| ------------------------------- | --- | -------------- |
714| NONE_TOKENIZER     | 0  | 不使用分词器。      |
715| ICU_TOKENIZER | 1 | 表示使用icu分词器,支持中文以及多国语言。指定icu分词器时,可指定使用哪种语言,例如zh_CN表示中文,tr_TR表示土耳其语等。详细支持的语言种类,请查阅[ICU分词器](https://gitee.com/openharmony/third_party_icu/blob/master/icu4c/source/data/lang/zh.txt)。详细的语言缩写,请查阅该目录([ICU支持的语言缩写](https://gitee.com/openharmony/third_party_icu/tree/master/icu4c/source/data/locales))下的文件名。|
716| CUSTOM_TOKENIZER<sup>18+</sup> | 2 | 表示使用自研分词器,可支持中文(简体、繁体)、英文、阿拉伯数字。CUSTOM_TOKENIZER相比ICU_TOKENIZER在分词准确率、常驻内存占用上更有优势。 |
717
718在使用不同的分词器时,使用的创表语句会有所区别。
719
720**示例:**
721
722使用ICU_TOKENIZER分词器时,创建表的示例:
723
724```ts
725import { relationalStore } from '@kit.ArkData'; // 导入模块
726import { UIAbility } from '@kit.AbilityKit';
727import { BusinessError } from '@kit.BasicServicesKit';
728import { window } from '@kit.ArkUI';
729
730// 此处示例在Stage模式、Ability中实现,使用者也可以在其他合理场景中使用
731class EntryAbility extends UIAbility {
732  async onWindowStageCreate(windowStage: window.WindowStage) {
733    let store: relationalStore.RdbStore | undefined = undefined;
734    const STORE_CONFIG: relationalStore.StoreConfig = {
735      name: "MyStore.db",
736      securityLevel: relationalStore.SecurityLevel.S3,
737      tokenizer: relationalStore.Tokenizer.ICU_TOKENIZER
738    };
739    store = await relationalStore.getRdbStore(this.context, STORE_CONFIG);
740
741    const SQL_CREATE_TABLE = "CREATE VIRTUAL TABLE example USING fts4(name, content, tokenize=icu zh_CN)";
742    if (store != undefined) {
743      (store as relationalStore.RdbStore).executeSql(SQL_CREATE_TABLE, (err) => {
744        if (err) {
745          console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
746          return;
747        }
748        console.info('create virtual table done.');
749      });
750    }
751  }
752}
753```
754
755使用CUSTOM_TOKENIZER分词器时,创建表的示例:
756
757```ts
758import { relationalStore } from '@kit.ArkData'; // 导入模块
759import { UIAbility } from '@kit.AbilityKit';
760import { BusinessError } from '@kit.BasicServicesKit';
761import { window } from '@kit.ArkUI';
762
763// 此处示例在Stage模式、Ability中实现,使用者也可以在其他合理场景中使用
764class EntryAbility extends UIAbility {
765  async onWindowStageCreate(windowStage: window.WindowStage) {
766    let store: relationalStore.RdbStore | undefined = undefined;
767    const STORE_CONFIG: relationalStore.StoreConfig = {
768      name: "MyStore.db",
769      securityLevel: relationalStore.SecurityLevel.S3,
770      tokenizer: relationalStore.Tokenizer.CUSTOM_TOKENIZER
771    };
772    store = await relationalStore.getRdbStore(this.context, STORE_CONFIG);
773
774    const SQL_CREATE_TABLE = "CREATE VIRTUAL TABLE example USING fts5(name, content, tokenize='customtokenizer')";
775    if (store != undefined) {
776      (store as relationalStore.RdbStore).executeSql(SQL_CREATE_TABLE, (err) => {
777        if (err) {
778          console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
779          return;
780        }
781        console.info('create virtual table done.');
782      });
783    }
784  }
785}
786```
787
788## AssetStatus<sup>10+</sup>
789
790描述资产附件的状态枚举。请使用枚举名称而非枚举值。
791
792**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
793
794| 名称                              | 值   | 说明             |
795| ------------------------------- | --- | -------------- |
796| ASSET_NORMAL     | 1  | 表示资产状态正常。      |
797| ASSET_INSERT | 2 | 表示资产需要插入到云端。 |
798| ASSET_UPDATE | 3 | 表示资产需要更新到云端。 |
799| ASSET_DELETE | 4 | 表示资产需要在云端删除。 |
800| ASSET_ABNORMAL    | 5   | 表示资产状态异常。      |
801| ASSET_DOWNLOADING | 6   | 表示资产正在下载到本地设备。 |
802
803## Asset<sup>10+</sup>
804
805记录资产附件(文件、图片、视频等类型文件)的相关信息。
806
807**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
808
809| 名称          | 类型                          | 必填  | 说明           |
810| ----------- | --------------------------- | --- | ------------ |
811| name        | string                      | 是   | 资产的名称。       |
812| uri         | string                      | 是   | 资产的uri,在系统里的绝对路径。       |
813| path        | string                      | 是   | 资产在应用沙箱里的路径。       |
814| createTime  | string                      | 是   | 资产被创建出来的时间。   |
815| modifyTime  | string                      | 是   | 资产最后一次被修改的时间。 |
816| size        | string                      | 是   | 资产占用空间的大小。    |
817| status      | [AssetStatus](#assetstatus10) | 否   | 资产的状态,默认值为ASSET_NORMAL。        |
818
819## Assets<sup>10+</sup>
820
821type Assets = Asset[]
822
823表示[Asset](#asset10)类型的数组。
824
825**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
826
827| 类型    | 说明                 |
828| ------- | -------------------- |
829| [Asset](#asset10)[] | 表示Asset类型的数组。   |
830
831## ValueType
832
833type ValueType = null | number | string | boolean | Uint8Array | Asset | Assets | Float32Array | bigint
834
835用于表示允许的数据字段类型,接口参数具体类型根据其功能而定。
836
837**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
838
839| 类型    | 说明                 |
840| ------- | -------------------- |
841| null<sup>10+</sup>    | 表示值类型为空。   |
842| number  | 表示值类型为数字。   |
843| string  | 表示值类型为字符串。  |
844| boolean | 表示值类型为布尔值。 |
845| Uint8Array<sup>10+</sup>           | 表示值类型为Uint8类型的数组。            |
846| Asset<sup>10+</sup>  | 表示值类型为附件[Asset](#asset10)。<br/>当字段类型是Asset时,在创建表的sql语句中,类型应当为:ASSET。 |
847| Assets<sup>10+</sup> | 表示值类型为附件数组[Assets](#assets10)。<br/>当字段类型是Assets时,在创建表的sql语句中,类型应当为:ASSETS。 |
848| Float32Array<sup>12+</sup> | 表示值类型为浮点数组。<br/>当字段类型是Float32Array时,在创建表的sql语句中,类型应当为:floatvector(128)。 |
849| 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。 |
850
851## ValuesBucket
852
853type ValuesBucket = Record<string, ValueType>
854
855用于存储键值对的类型。不支持Sendable跨线程传递。
856
857**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
858
859| 类型              | 说明                           |
860| ---------------- | ---------------------------- |
861| Record<string, [ValueType](#valuetype)> | 表示键值对类型。键的类型为string,值的类型为[ValueType](#valuetype)。 |
862
863## PRIKeyType<sup>10+</sup>
864
865type PRIKeyType = number | string
866
867用于表示数据库表某一行主键的数据类型。
868
869**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
870
871| 类型             | 说明                               |
872| ---------------- | ---------------------------------- |
873| number | 主键的类型可以是number。 |
874| string | 主键的类型可以是string。 |
875
876## UTCTime<sup>10+</sup>
877
878type UTCTime = Date
879
880用于表示UTC类型时间的数据类型。
881
882**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
883
884| 类型 | 说明            |
885| ---- | --------------- |
886| Date | UTC类型的时间。 |
887
888## ModifyTime<sup>10+</sup>
889
890type ModifyTime = Map<PRIKeyType, UTCTime>
891
892用于存储数据库表的主键和修改时间的数据类型。
893
894**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
895
896| 类型                                                    | 说明                                                         |
897| ------------------------------------------------------- | ------------------------------------------------------------ |
898| Map<[PRIKeyType](#prikeytype10), [UTCTime](#utctime10)> | 键表示是数据库表某一行的主键,值表示该行的最后修改时间,用UTC格式表示。 |
899
900## SyncMode
901
902指数据库同步模式。请使用枚举名称而非枚举值。
903
904| 名称           | 值   | 说明                               |
905| -------------- | ---- | ---------------------------------- |
906| SYNC_MODE_PUSH                       | 0   | 表示数据从本地设备推送到远程设备。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
907| SYNC_MODE_PULL                       | 1   | 表示数据从远程设备拉至本地设备。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
908| SYNC_MODE_TIME_FIRST<sup>10+</sup>   | 4   | 表示数据从修改时间较近的一端同步到修改时间较远的一端。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
909| SYNC_MODE_NATIVE_FIRST<sup>10+</sup> | 5   | 表示数据从本地设备同步到云端。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
910| SYNC_MODE_CLOUD_FIRST<sup>10+</sup>  | 6   | 表示数据从云端同步到本地设备。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
911
912## Origin<sup>11+</sup>
913
914表示数据来源。请使用枚举名称而非枚举值。
915
916**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
917
918| 名称           | 值   | 说明                               |
919| -------------- | ---- | ---------------------------------- |
920| LOCAL       | 0   | 表示本地数据。      |
921| CLOUD       | 1   | 表示云端同步的数据。     |
922| REMOTE      | 2   | 表示端端同步的数据。 |
923
924## Field<sup>11+</sup>
925
926用于谓词查询条件的特殊字段。请使用枚举名称而非枚举值。
927
928**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
929
930| 名称           | 值   | 说明                               |
931| -------------- | ---- | ---------------------------------- |
932| CURSOR_FIELD        | '#_cursor'     | 用于cursor查找的字段名。|
933| ORIGIN_FIELD        | '#_origin'     | 用于cursor查找时指定数据来源的字段名。    |
934| DELETED_FLAG_FIELD  | '#_deleted_flag' | 用于cursor查找的结果集返回时填充的字段,表示云端删除的数据同步到本地后数据是否清理。<br>返回的结果集中,该字段对应的value为false表示数据未清理,true表示数据已清理。|
935| DATA_STATUS_FIELD<sup>12+</sup>   | '#_data_status' | 用于cursor查找的结果集返回时填充的字段,返回的结果集中,该字段对应的0表示正常数据,1表示退出账号保留数据,2表示云侧同步删除,3表示退出账户删除数据。|
936| OWNER_FIELD  | '#_cloud_owner' | 用于共享表中查找owner时,返回的结果集中填充的字段,表示当前共享记录的共享发起者。|
937| PRIVILEGE_FIELD  | '#_cloud_privilege' | 用于共享表中查找共享数据权限时,返回的结果集中填充的字段,表示当前共享记录的允许的操作权限。|
938| SHARING_RESOURCE_FIELD   | '#_sharing_resource_field' | 用于数据共享查找共享数据的共享资源时,返回的结果集中填充的字段,表示共享数据的共享资源标识。|
939
940## SubscribeType
941
942描述订阅类型。请使用枚举名称而非枚举值。
943
944| 名称                  | 值   | 说明               |
945| --------------------- | ---- | ------------------ |
946| SUBSCRIBE_TYPE_REMOTE | 0    | 订阅远程数据更改。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
947| SUBSCRIBE_TYPE_CLOUD<sup>10+</sup> | 1  | 订阅云端数据更改。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
948| SUBSCRIBE_TYPE_CLOUD_DETAILS<sup>10+</sup> | 2  | 订阅云端数据更改详情。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
949| SUBSCRIBE_TYPE_LOCAL_DETAILS<sup>12+</sup> | 3  | 订阅本地数据更改详情。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core |
950
951## RebuildType<sup>12+</sup>
952
953描述数据库重建类型的枚举。请使用枚举名称而非枚举值。
954
955**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
956
957| 名称    | 值   | 说明                                                                                                             |
958| ------- | ---- |----------------------------------------------------------------------------------------------------------------|
959| NONE    | 0    | 表示数据库未进行重建。                                                                                                    |
960| REBUILT | 1    | 表示数据库进行了重建并且生成了空数据库,需要应用重新建表和恢复数据。                                                                             |
961| REPAIRED | 2    | 表示数据库进行了修复,恢复了未损坏的数据,当前只有[向量数据库](#storeconfig)具备该能力。 |
962
963## ChangeType<sup>10+</sup>
964
965描述数据变更类型的枚举。请使用枚举名称而非枚举值。
966
967**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
968
969| 名称                         | 值   | 说明                         |
970| -------------------------- | --- | -------------------------- |
971| DATA_CHANGE  | 0   | 表示是数据发生变更。   |
972| ASSET_CHANGE | 1   | 表示是资产附件发生了变更。 |
973
974## ChangeInfo<sup>10+</sup>
975
976记录端云同步过程详情。
977
978**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
979
980| 名称     | 类型                               | 必填 | 说明                                                         |
981| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
982| table    | string                             | 是   | 表示发生变化的表的名称。                                     |
983| type     | [ChangeType](#changetype10)        | 是   | 表示发生变化的数据的类型,数据或者资产附件发生变化。         |
984| inserted | Array\<string\> \| Array\<number\> | 是   | 记录插入数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示插入数据的行号。 |
985| updated  | Array\<string\> \| Array\<number\> | 是   | 记录更新数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示更新数据的行号。 |
986| deleted  | Array\<string\> \| Array\<number\> | 是   | 记录删除数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示删除数据的行号。 |
987
988## DistributedType<sup>10+</sup>
989
990描述表的分布式类型的枚举。请使用枚举名称而非枚举值。
991
992| 名称                | 值   | 说明                                                                                                 |
993| ------------------ | --- | -------------------------------------------------------------------------------------------------- |
994| DISTRIBUTED_DEVICE | 0  | 表示在不同设备之间分布式的数据库表。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core               |
995| DISTRIBUTED_CLOUD  | 1   | 表示在设备和云端之间分布式的数据库表。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client |
996
997## DistributedConfig<sup>10+</sup>
998
999记录表的分布式配置信息。
1000
1001**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1002
1003| 名称     | 类型    | 必填 | 说明                                                         |
1004| -------- | ------- | ---- | ------------------------------------------------------------ |
1005| autoSync   | boolean | 是   | 该值为true时,表示该表支持自动同步和手动同步;该值为false时,表示该表只支持手动同步,不支持自动同步。 |
1006| asyncDownloadAsset<sup>18+</sup> | boolean | 否 | 表示当前数据库在端云同步时,同步或异步下载资产。true表示优先下载完所有数据后,使用异步任务下载资产;false表示同步下载资产;默认值为false。 |
1007| enableCloud<sup>18+</sup> | boolean | 否 | 表示当前数据库是否允许端云同步。true表示允许端云同步;false表示不允许端云同步。默认值为true。 |
1008
1009## ConflictResolution<sup>10+</sup>
1010
1011插入和修改接口的冲突解决模式。请使用枚举名称而非枚举值。
1012
1013**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1014
1015| 名称                 | 值   | 说明                                                         |
1016| -------------------- | ---- | ------------------------------------------------------------ |
1017| ON_CONFLICT_NONE | 0 | 表示当冲突发生时,不做任何处理。 |
1018| ON_CONFLICT_ROLLBACK | 1    | 表示当冲突发生时,中止SQL语句并回滚当前事务。                |
1019| ON_CONFLICT_ABORT    | 2    | 表示当冲突发生时,中止当前SQL语句,并撤销当前 SQL 语句所做的任何更改,但是由同一事务中先前的 SQL 语句引起的更改被保留并且事务保持活动状态。 |
1020| ON_CONFLICT_FAIL     | 3    | 表示当冲突发生时,中止当前 SQL 语句。但它不会撤销失败的 SQL 语句的先前更改,也不会结束事务。 |
1021| ON_CONFLICT_IGNORE   | 4    | 表示当冲突发生时,跳过包含违反约束的行并继续处理 SQL 语句的后续行。 |
1022| ON_CONFLICT_REPLACE  | 5    | 表示当冲突发生时,在插入或更新当前行之前删除导致约束违例的预先存在的行,并且命令会继续正常执行。 |
1023
1024## Progress<sup>10+</sup>
1025
1026描述端云同步过程的枚举。请使用枚举名称而非枚举值。
1027
1028**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1029
1030| 名称             | 值   | 说明                     |
1031| ---------------- | ---- | ------------------------ |
1032| SYNC_BEGIN       | 0    | 表示端云同步过程开始。   |
1033| SYNC_IN_PROGRESS | 1    | 表示正在端云同步过程中。 |
1034| SYNC_FINISH      | 2    | 表示端云同步过程已完成。 |
1035
1036## Statistic<sup>10+</sup>
1037
1038描述数据库表的端云同步过程的统计信息。
1039
1040**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1041
1042| 名称       | 类型   | 必填 | 说明                                     |
1043| ---------- | ------ | ---- | ---------------------------------------- |
1044| total      | number | 是   | 表示数据库表中需要端云同步的总行数。     |
1045| successful | number | 是   | 表示数据库表中端云同步成功的行数。       |
1046| failed     | number | 是   | 表示数据库表中端云同步失败的行数。       |
1047| remained   | number | 是   | 表示数据库表中端云同步剩余未执行的行数。 |
1048
1049## TableDetails<sup>10+</sup>
1050
1051描述数据库表执行端云同步任务上传和下载的统计信息。
1052
1053**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1054
1055| 名称     | 类型                      | 必填 | 说明                                       |
1056| -------- | ------------------------- | ---- | ------------------------------------------ |
1057| upload   | [Statistic](#statistic10) | 是   | 表示数据库表中端云同步上传过程的统计信息。 |
1058| download | [Statistic](#statistic10) | 是   | 表示数据库表中端云同步下载过程的统计信息。 |
1059
1060## ProgressCode<sup>10+</sup>
1061
1062表示端云同步过程的状态。请使用枚举名称而非枚举值。
1063
1064**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1065
1066| 名称                  | 值   | 说明                                                         |
1067| --------------------- | ---- | ------------------------------------------------------------ |
1068| SUCCESS               | 0    | 表示端云同步过程成功。                                       |
1069| UNKNOWN_ERROR         | 1    | 表示端云同步过程遇到未知错误。                               |
1070| NETWORK_ERROR         | 2    | 表示端云同步过程遇到网络错误。                               |
1071| CLOUD_DISABLED        | 3    | 表示云端不可用。                                             |
1072| LOCKED_BY_OTHERS      | 4    | 表示有其他设备正在端云同步,本设备无法进行端云同步。<br>请确保无其他设备占用云端资源后,再使用本设备进行端云同步任务。 |
1073| RECORD_LIMIT_EXCEEDED | 5    | 表示本次端云同步需要同步的条目或大小超出最大值。由云端配置最大值。 |
1074| NO_SPACE_FOR_ASSET    | 6    | 表示云空间剩余空间小于待同步的资产大小。                     |
1075| BLOCKED_BY_NETWORK_STRATEGY<sup>12+</sup>    | 7    | 表示端云同步被网络策略限制。                     |
1076
1077## ProgressDetails<sup>10+</sup>
1078
1079描述数据库整体执行端云同步任务上传和下载的统计信息。
1080
1081**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1082
1083| 名称     | 类型                                              | 必填 | 说明                                                         |
1084| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
1085| schedule | [Progress](#progress10)                           | 是   | 表示端云同步过程。                                           |
1086| code     | [ProgressCode](#progresscode10)                   | 是   | 表示端云同步过程的状态。                                     |
1087| details  | Record<string, [TableDetails](#tabledetails10)> | 是   | 表示端云同步各表的统计信息。<br>键表示表名,值表示该表的端云同步过程统计信息。 |
1088
1089## SqlExecutionInfo<sup>12+</sup>
1090
1091描述数据库执行的SQL语句的统计信息。
1092
1093**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1094
1095| 名称     | 类型                                               | 只读 | 可选  |说明                                                         |
1096| -------- | ------------------------------------------------- | ---- | ---- | -------------------------------------------------------- |
1097| sql<sup>12+</sup>           | Array&lt;string&gt;            | 是   |   否   | 表示执行的SQL语句的数组。当[batchInsert](#batchinsert)的参数太大时,可能有多个SQL。      |
1098| totalTime<sup>12+</sup>      | number                        | 是   |   否   | 表示执行SQL语句的总时间,单位为μs。                                    |
1099| waitTime<sup>12+</sup>       | number                        | 是   |   否   | 表示获取句柄的时间,单位为μs。                                         |
1100| prepareTime<sup>12+</sup>    | number                        | 是   |   否   | 表示准备SQL和绑定参数的时间,单位为μs。                                 |
1101| executeTime<sup>12+</sup>    | number                        | 是   |   否   | 表示执行SQL语句的时间,单位为μs。 |
1102
1103## TransactionType<sup>14+</sup>
1104
1105描述创建事务对象的枚举。请使用枚举名称而非枚举值。
1106
1107**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1108
1109| 名称             | 值   | 说明                     |
1110| ---------------- | ---- | ------------------------ |
1111| DEFERRED       | 0    | 表示创建一个DEFERRED类型的事务对象,该类型的事务对象在创建时只会关闭自动提交而不会真正开始事务,只有在首次读或写操作时会真正开始一个读或写事务。   |
1112| IMMEDIATE | 1    | 表示创建一个IMMEDIATE类型的事务对象,该类型的事务对象在创建时会真正开始一个写事务;如果有别的写事务未提交,则会创建失败,返回错误码14800024。 |
1113| EXCLUSIVE      | 2    | 表示创建一个EXCLUSIVE类型的事务对象,该类型的事务在WAL模式下和IMMEDIATE相同,但在其它日志模式下能够防止事务期间有其它连接读取数据库。 |
1114
1115## TransactionOptions<sup>14+</sup>
1116
1117事务对象的配置信息。
1118
1119**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1120
1121| 名称        | 类型          | 必填 | 说明                                                      |
1122| ------------- | ------------- | ---- | --------------------------------------------------------- |
1123| transactionType          | [TransactionType](#transactiontype14)        | 否   | 事务类型。默认为DEFERRED。  |
1124
1125## ColumnType<sup>18+</sup>
1126
1127描述数据库列存储类型的枚举。请使用枚举名称而非枚举值。
1128
1129**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1130
1131| 名称          | 值   | 说明                                                         |
1132| ------------- | ---- | ------------------------------------------------------------ |
1133| NULL          | 0    | 表示列数据类型为NULL。                                       |
1134| INTEGER       | 1    | 表示列数据类型为64位整数。可用于保存8位(包括布尔值)、16位、32位、64位整数。如果64位整数大于2^53或于-2^53,需使用[getString](#getstring)将64位整数转换为字符串。 |
1135| REAL          | 2    | 表示列类型为浮点数。                                         |
1136| TEXT          | 3    | 表示列类型为字符串。                                         |
1137| BLOB          | 4    | 表示列类型为Uint8Array。                                     |
1138| ASSET         | 5    | 表示列类型为[Asset](#asset10)。                              |
1139| ASSETS        | 6    | 表示列类型为[Assets](#assets10)。                            |
1140| FLOAT_VECTOR  | 7    | 表示列类型为Float32Array。                                   |
1141| UNLIMITED_INT | 8    | 表示列类型为bigint。                                         |
1142
1143## RdbPredicates
1144
1145表示关系型数据库(RDB)的谓词。该类确定RDB中条件表达式的值是true还是false。谓词间支持多语句拼接,拼接时默认使用and()连接。不支持Sendable跨线程传递。
1146
1147### constructor
1148
1149constructor(name: string)
1150
1151构造函数。
1152
1153**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1154
1155**参数:**
1156
1157| 参数名 | 类型   | 必填 | 说明         |
1158| ------ | ------ | ---- | ------------ |
1159| name   | string | 是   | 数据库表名。 |
1160
1161**错误码:**
1162
1163以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1164
1165| **错误码ID** | **错误信息**                                                                                                       |
1166| --------- |----------------------------------------------------------------------------------------------------------------|
1167| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1168
1169**示例:**
1170
1171```ts
1172let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1173```
1174
1175### inDevices
1176
1177inDevices(devices: Array&lt;string&gt;): RdbPredicates
1178
1179同步分布式数据库时连接到组网内指定的远程设备。
1180
1181> **说明:**
1182>
1183> 其中devices通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
1184数据库同步时调用Sync接口,需要在入参谓词中调用inDevices接口选择设备。如果不调用inDevices接口即默认连接组网内所有的设备。
1185
1186**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1187
1188**参数:**
1189
1190| 参数名  | 类型                | 必填 | 说明                       |
1191| ------- | ------------------- | ---- | -------------------------- |
1192| devices | Array&lt;string&gt; | 是   | 指定的组网内的远程设备ID。 |
1193
1194**返回值**:
1195
1196| 类型                                 | 说明                       |
1197| ------------------------------------ | -------------------------- |
1198| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1199
1200**错误码:**
1201
1202以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1203
1204| **错误码ID** | **错误信息**                                                                                                       |
1205| --------- |----------------------------------------------------------------------------------------------------------------|
1206| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1207
1208**示例:**
1209
1210```ts
1211import { distributedDeviceManager } from '@kit.DistributedServiceKit';
1212import { BusinessError } from '@kit.BasicServicesKit';
1213
1214let dmInstance: distributedDeviceManager.DeviceManager;
1215let deviceIds: Array<string> = [];
1216
1217try {
1218  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
1219  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
1220  for (let i = 0; i < devices.length; i++) {
1221    deviceIds[i] = devices[i].networkId!;
1222  }
1223} catch (err) {
1224  let code = (err as BusinessError).code;
1225  let message = (err as BusinessError).message;
1226  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
1227}
1228
1229let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1230predicates.inDevices(deviceIds);
1231```
1232
1233### inAllDevices
1234
1235inAllDevices(): RdbPredicates
1236
1237同步分布式数据库时连接到组网内所有的远程设备。
1238
1239
1240**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1241
1242**返回值**:
1243
1244| 类型                                 | 说明                       |
1245| ------------------------------------ | -------------------------- |
1246| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1247
1248**示例:**
1249
1250```ts
1251let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1252predicates.inAllDevices();
1253```
1254
1255### equalTo
1256
1257equalTo(field: string, value: ValueType): RdbPredicates
1258
1259配置谓词以匹配数据表的field列中值为value的字段。
1260
1261**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1262
1263**参数:**
1264
1265| 参数名 | 类型                    | 必填 | 说明                   |
1266| ------ | ----------------------- | ---- | ---------------------- |
1267| field  | string                  | 是   | 数据库表中的列名。     |
1268| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1269
1270**返回值**:
1271
1272| 类型                                 | 说明                       |
1273| ------------------------------------ | -------------------------- |
1274| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1275
1276**错误码:**
1277
1278以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1279
1280| **错误码ID** | **错误信息**                                                                                                       |
1281| --------- |----------------------------------------------------------------------------------------------------------------|
1282| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1283
1284**示例:**
1285
1286```ts
1287// 匹配数据表的"NAME"列中值为"Lisa"的字段
1288let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1289predicates.equalTo("NAME", "Lisa");
1290```
1291
1292
1293### notEqualTo
1294
1295notEqualTo(field: string, value: ValueType): RdbPredicates
1296
1297配置谓词以匹配数据表的field列中值不为value的字段。
1298
1299**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1300
1301**参数:**
1302
1303| 参数名 | 类型                    | 必填 | 说明                   |
1304| ------ | ----------------------- | ---- | ---------------------- |
1305| field  | string                  | 是   | 数据库表中的列名。     |
1306| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1307
1308**返回值**:
1309
1310| 类型                                 | 说明                       |
1311| ------------------------------------ | -------------------------- |
1312| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1313
1314**错误码:**
1315
1316以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1317
1318| **错误码ID** | **错误信息**                                                                                                       |
1319| --------- |----------------------------------------------------------------------------------------------------------------|
1320| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1321
1322**示例:**
1323
1324```ts
1325// 匹配数据表的"NAME"列中值不为"Lisa"的字段
1326let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1327predicates.notEqualTo("NAME", "Lisa");
1328```
1329
1330
1331### beginWrap
1332
1333beginWrap(): RdbPredicates
1334
1335向谓词添加左括号。
1336
1337**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1338
1339**返回值**:
1340
1341| 类型                                 | 说明                      |
1342| ------------------------------------ | ------------------------- |
1343| [RdbPredicates](#rdbpredicates) | 返回带有左括号的Rdb谓词。 |
1344
1345**示例:**
1346
1347```ts
1348let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1349predicates.equalTo("NAME", "Lisa")
1350  .beginWrap()
1351  .equalTo("AGE", 18)
1352  .or()
1353  .equalTo("SALARY", 200.5)
1354  .endWrap();
1355```
1356
1357### endWrap
1358
1359endWrap(): RdbPredicates
1360
1361向谓词添加右括号。
1362
1363**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1364
1365**返回值**:
1366
1367| 类型                                 | 说明                      |
1368| ------------------------------------ | ------------------------- |
1369| [RdbPredicates](#rdbpredicates) | 返回带有右括号的Rdb谓词。 |
1370
1371**示例:**
1372
1373```ts
1374let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1375predicates.equalTo("NAME", "Lisa")
1376  .beginWrap()
1377  .equalTo("AGE", 18)
1378  .or()
1379  .equalTo("SALARY", 200.5)
1380  .endWrap();
1381```
1382
1383### or
1384
1385or(): RdbPredicates
1386
1387将或条件添加到谓词中。
1388
1389**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1390
1391**返回值**:
1392
1393| 类型                                 | 说明                      |
1394| ------------------------------------ | ------------------------- |
1395| [RdbPredicates](#rdbpredicates) | 返回带有或条件的Rdb谓词。 |
1396
1397**示例:**
1398
1399```ts
1400// 匹配数据表的"NAME"列中值为"Lisa"或"Rose"的字段
1401let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1402predicates.equalTo("NAME", "Lisa")
1403  .or()
1404  .equalTo("NAME", "Rose");
1405```
1406
1407### and
1408
1409and(): RdbPredicates
1410
1411向谓词添加和条件。
1412
1413**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1414
1415**返回值**:
1416
1417| 类型                                 | 说明                      |
1418| ------------------------------------ | ------------------------- |
1419| [RdbPredicates](#rdbpredicates) | 返回带有和条件的Rdb谓词。 |
1420
1421**示例:**
1422
1423```ts
1424// 匹配数据表的"NAME"列中值为"Lisa"且"SALARY"列中值为"200.5"的字段
1425let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1426predicates.equalTo("NAME", "Lisa")
1427  .and()
1428  .equalTo("SALARY", 200.5);
1429```
1430
1431### contains
1432
1433contains(field: string, value: string): RdbPredicates
1434
1435配置谓词以匹配数据表的field列中包含value的字段。
1436
1437**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1438
1439**参数:**
1440
1441| 参数名 | 类型   | 必填 | 说明                   |
1442| ------ | ------ | ---- | ---------------------- |
1443| field  | string | 是   | 数据库表中的列名。     |
1444| value  | string | 是   | 指示要与谓词匹配的值。 |
1445
1446**返回值**:
1447
1448| 类型                                 | 说明                       |
1449| ------------------------------------ | -------------------------- |
1450| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1451
1452**错误码:**
1453
1454以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1455
1456| **错误码ID** | **错误信息**                                                                                                       |
1457| --------- |----------------------------------------------------------------------------------------------------------------|
1458| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1459
1460**示例:**
1461
1462```ts
1463// 匹配数据表的"NAME"列中包含"os"的字段,如"Rose"
1464let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1465predicates.contains("NAME", "os");
1466```
1467
1468### beginsWith
1469
1470beginsWith(field: string, value: string): RdbPredicates
1471
1472配置谓词以匹配数据表的field列中以value开头的字段。
1473
1474**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1475
1476**参数:**
1477
1478| 参数名 | 类型   | 必填 | 说明                   |
1479| ------ | ------ | ---- | ---------------------- |
1480| field  | string | 是   | 数据库表中的列名。     |
1481| value  | string | 是   | 指示要与谓词匹配的值。 |
1482
1483**返回值**:
1484
1485| 类型                                 | 说明                       |
1486| ------------------------------------ | -------------------------- |
1487| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1488
1489**错误码:**
1490
1491以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1492
1493| **错误码ID** | **错误信息**                                                                                                       |
1494| --------- |----------------------------------------------------------------------------------------------------------------|
1495| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1496
1497**示例:**
1498
1499```ts
1500// 匹配数据表的"NAME"列中以"Li"开头的字段,如"Lisa"
1501let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1502predicates.beginsWith("NAME", "Li");
1503```
1504
1505### endsWith
1506
1507endsWith(field: string, value: string): RdbPredicates
1508
1509配置谓词以匹配数据表的field列中以value结尾的字段。
1510
1511**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1512
1513**参数:**
1514
1515| 参数名 | 类型   | 必填 | 说明                   |
1516| ------ | ------ | ---- | ---------------------- |
1517| field  | string | 是   | 数据库表中的列名。     |
1518| value  | string | 是   | 指示要与谓词匹配的值。 |
1519
1520**返回值**:
1521
1522| 类型                                 | 说明                       |
1523| ------------------------------------ | -------------------------- |
1524| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1525
1526**错误码:**
1527
1528以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1529
1530| **错误码ID** | **错误信息**                                                                                                       |
1531| --------- |----------------------------------------------------------------------------------------------------------------|
1532| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1533
1534**示例:**
1535
1536```ts
1537// 匹配数据表的"NAME"列中以"se"结尾的字段,如"Rose"
1538let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1539predicates.endsWith("NAME", "se");
1540```
1541
1542### isNull
1543
1544isNull(field: string): RdbPredicates
1545
1546配置谓词以匹配数据表的field列中值为null的字段。
1547
1548**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1549
1550**参数:**
1551
1552| 参数名 | 类型   | 必填 | 说明               |
1553| ------ | ------ | ---- | ------------------ |
1554| field  | string | 是   | 数据库表中的列名。 |
1555
1556**返回值**:
1557
1558| 类型                                 | 说明                       |
1559| ------------------------------------ | -------------------------- |
1560| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1561
1562**错误码:**
1563
1564以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1565
1566| **错误码ID** | **错误信息**                                                                                                       |
1567| --------- |----------------------------------------------------------------------------------------------------------------|
1568| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1569
1570**示例**:
1571
1572```ts
1573let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1574predicates.isNull("NAME");
1575```
1576
1577### isNotNull
1578
1579isNotNull(field: string): RdbPredicates
1580
1581配置谓词以匹配数据表的field列中值不为null的字段。
1582
1583**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1584
1585**参数:**
1586
1587| 参数名 | 类型   | 必填 | 说明               |
1588| ------ | ------ | ---- | ------------------ |
1589| field  | string | 是   | 数据库表中的列名。 |
1590
1591**返回值**:
1592
1593| 类型                                 | 说明                       |
1594| ------------------------------------ | -------------------------- |
1595| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1596
1597**错误码:**
1598
1599以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1600
1601| **错误码ID** | **错误信息**                                                                                                       |
1602| --------- |----------------------------------------------------------------------------------------------------------------|
1603| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1604
1605**示例:**
1606
1607```ts
1608let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1609predicates.isNotNull("NAME");
1610```
1611
1612### like
1613
1614like(field: string, value: string): RdbPredicates
1615
1616配置谓词以匹配数据表的field列中值类似于value的字段。
1617
1618**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1619
1620**参数:**
1621
1622| 参数名 | 类型   | 必填 | 说明                   |
1623| ------ | ------ | ---- | ---------------------- |
1624| field  | string | 是   | 数据库表中的列名。     |
1625| value  | string | 是   | 指示要与谓词匹配的值。 |
1626
1627**返回值**:
1628
1629| 类型                                 | 说明                       |
1630| ------------------------------------ | -------------------------- |
1631| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1632
1633**错误码:**
1634
1635以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1636
1637| **错误码ID** | **错误信息**                                                                                                       |
1638| --------- |----------------------------------------------------------------------------------------------------------------|
1639| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1640
1641**示例:**
1642
1643```ts
1644// 匹配数据表的"NAME"列中值类似于"os"的字段,如"Rose"
1645let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1646predicates.like("NAME", "%os%");
1647```
1648
1649### glob
1650
1651glob(field: string, value: string): RdbPredicates
1652
1653配置谓词匹配数据字段为string的指定字段。
1654
1655**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1656
1657**参数:**
1658
1659| 参数名 | 类型   | 必填 | 说明                                                         |
1660| ------ | ------ | ---- | ------------------------------------------------------------ |
1661| field  | string | 是   | 数据库表中的列名。                                           |
1662| value  | string | 是   | 指示要与谓词匹配的值。<br>支持通配符,*表示0个、1个或多个数字或字符,?表示1个数字或字符。 |
1663
1664**返回值**:
1665
1666| 类型                                 | 说明                       |
1667| ------------------------------------ | -------------------------- |
1668| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1669
1670**错误码:**
1671
1672以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1673
1674| **错误码ID** | **错误信息**                                                                                                       |
1675| --------- |----------------------------------------------------------------------------------------------------------------|
1676| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1677
1678**示例:**
1679
1680```ts
1681// 匹配数据表的"NAME"列中类型为string且值为"?h*g"的字段
1682let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1683predicates.glob("NAME", "?h*g");
1684```
1685
1686### between
1687
1688between(field: string, low: ValueType, high: ValueType): RdbPredicates
1689
1690配置谓词以匹配数据表的field列中值在给定范围内的字段(包含范围边界)。
1691
1692**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1693
1694**参数:**
1695
1696| 参数名 | 类型                    | 必填 | 说明                       |
1697| ------ | ----------------------- | ---- | -------------------------- |
1698| field  | string                  | 是   | 数据库表中的列名。         |
1699| low    | [ValueType](#valuetype) | 是   | 指示与谓词匹配的最小值。   |
1700| high   | [ValueType](#valuetype) | 是   | 指示与谓词匹配的最大值。 |
1701
1702**返回值**:
1703
1704| 类型                                 | 说明                       |
1705| ------------------------------------ | -------------------------- |
1706| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1707
1708**错误码:**
1709
1710以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1711
1712| **错误码ID** | **错误信息**                                                                                                       |
1713| --------- |----------------------------------------------------------------------------------------------------------------|
1714| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1715
1716**示例:**
1717
1718```ts
1719// 匹配数据表的"AGE"列中大于等于10且小于等于50的值
1720let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1721predicates.between("AGE", 10, 50);
1722```
1723
1724### notBetween
1725
1726notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates
1727
1728配置谓词以匹配数据表的field列中值超出给定范围的字段(不包含范围边界)。
1729
1730**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1731
1732**参数:**
1733
1734| 参数名 | 类型                    | 必填 | 说明                       |
1735| ------ | ----------------------- | ---- | -------------------------- |
1736| field  | string                  | 是   | 数据库表中的列名。         |
1737| low    | [ValueType](#valuetype) | 是   | 指示与谓词匹配的最小值。   |
1738| high   | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的最大值。 |
1739
1740**返回值**:
1741
1742| 类型                                 | 说明                       |
1743| ------------------------------------ | -------------------------- |
1744| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1745
1746**错误码:**
1747
1748以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1749
1750| **错误码ID** | **错误信息**                                                                                                       |
1751| --------- |----------------------------------------------------------------------------------------------------------------|
1752| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1753
1754**示例:**
1755
1756```ts
1757// 匹配数据表的"AGE"列中小于10或大于50的值
1758let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1759predicates.notBetween("AGE", 10, 50);
1760```
1761
1762### greaterThan
1763
1764greaterThan(field: string, value: ValueType): RdbPredicates
1765
1766配置谓词以匹配数据表的field列中值大于value的字段。
1767
1768**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1769
1770**参数:**
1771
1772| 参数名 | 类型                    | 必填 | 说明                   |
1773| ------ | ----------------------- | ---- | ---------------------- |
1774| field  | string                  | 是   | 数据库表中的列名。     |
1775| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1776
1777**返回值**:
1778
1779| 类型                                 | 说明                       |
1780| ------------------------------------ | -------------------------- |
1781| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1782
1783**错误码:**
1784
1785以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1786
1787| **错误码ID** | **错误信息**                                                                                                       |
1788| --------- |----------------------------------------------------------------------------------------------------------------|
1789| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1790
1791**示例:**
1792
1793```ts
1794// 匹配数据表的"AGE"列中大于18的值
1795let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1796predicates.greaterThan("AGE", 18);
1797```
1798
1799### lessThan
1800
1801lessThan(field: string, value: ValueType): RdbPredicates
1802
1803配置谓词以匹配数据表的field列中值小于value的字段。
1804
1805**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1806
1807**参数:**
1808
1809| 参数名 | 类型                    | 必填 | 说明                   |
1810| ------ | ----------------------- | ---- | ---------------------- |
1811| field  | string                  | 是   | 数据库表中的列名。     |
1812| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1813
1814**返回值**:
1815
1816| 类型                                 | 说明                       |
1817| ------------------------------------ | -------------------------- |
1818| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1819
1820**错误码:**
1821
1822以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1823
1824| **错误码ID** | **错误信息**                                                                                                       |
1825| --------- |----------------------------------------------------------------------------------------------------------------|
1826| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1827
1828**示例:**
1829
1830```ts
1831// 匹配数据表的"AGE"列中小于20的值
1832let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1833predicates.lessThan("AGE", 20);
1834```
1835
1836### greaterThanOrEqualTo
1837
1838greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates
1839
1840配置谓词以匹配数据表的field列中值大于或者等于value的字段。
1841
1842**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1843
1844**参数:**
1845
1846| 参数名 | 类型                    | 必填 | 说明                   |
1847| ------ | ----------------------- | ---- | ---------------------- |
1848| field  | string                  | 是   | 数据库表中的列名。     |
1849| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1850
1851**返回值**:
1852
1853| 类型                                 | 说明                       |
1854| ------------------------------------ | -------------------------- |
1855| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1856
1857**错误码:**
1858
1859以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1860
1861| **错误码ID** | **错误信息**                                                                                                       |
1862| --------- |----------------------------------------------------------------------------------------------------------------|
1863| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1864
1865**示例:**
1866
1867```ts
1868// 匹配数据表的"AGE"列中大于等于18的值
1869let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1870predicates.greaterThanOrEqualTo("AGE", 18);
1871```
1872
1873### lessThanOrEqualTo
1874
1875lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates
1876
1877配置谓词以匹配数据表的field列中值小于或者等于value的字段。
1878
1879**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1880
1881**参数:**
1882
1883| 参数名 | 类型                    | 必填 | 说明                   |
1884| ------ | ----------------------- | ---- | ---------------------- |
1885| field  | string                  | 是   | 数据库表中的列名。     |
1886| value  | [ValueType](#valuetype) | 是   | 指示要与谓词匹配的值。 |
1887
1888**返回值**:
1889
1890| 类型                                 | 说明                       |
1891| ------------------------------------ | -------------------------- |
1892| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1893
1894**错误码:**
1895
1896以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1897
1898| **错误码ID** | **错误信息**                                                                                                       |
1899| --------- |----------------------------------------------------------------------------------------------------------------|
1900| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1901
1902**示例:**
1903
1904```ts
1905// 匹配数据表的"AGE"列中小于等于20的值
1906let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1907predicates.lessThanOrEqualTo("AGE", 20);
1908```
1909
1910### orderByAsc
1911
1912orderByAsc(field: string): RdbPredicates
1913
1914配置谓词以匹配数据表的field列中值按升序排序的列。
1915
1916**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1917
1918**参数:**
1919
1920| 参数名 | 类型   | 必填 | 说明               |
1921| ------ | ------ | ---- | ------------------ |
1922| field  | string | 是   | 数据库表中的列名。 |
1923
1924**返回值**:
1925
1926| 类型                                 | 说明                       |
1927| ------------------------------------ | -------------------------- |
1928| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1929
1930**错误码:**
1931
1932以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1933
1934| **错误码ID** | **错误信息**                                                                                                       |
1935| --------- |----------------------------------------------------------------------------------------------------------------|
1936| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1937
1938**示例:**
1939
1940```ts
1941let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1942predicates.orderByAsc("NAME");
1943```
1944
1945### orderByDesc
1946
1947orderByDesc(field: string): RdbPredicates
1948
1949配置谓词以匹配数据表的field列中值按降序排序的列。
1950
1951**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1952
1953**参数:**
1954
1955| 参数名 | 类型   | 必填 | 说明               |
1956| ------ | ------ | ---- | ------------------ |
1957| field  | string | 是   | 数据库表中的列名。 |
1958
1959**返回值**:
1960
1961| 类型                                 | 说明                       |
1962| ------------------------------------ | -------------------------- |
1963| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
1964
1965**错误码:**
1966
1967以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1968
1969| **错误码ID** | **错误信息**                                                                                                       |
1970| --------- |----------------------------------------------------------------------------------------------------------------|
1971| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
1972
1973**示例:**
1974
1975```ts
1976let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1977predicates.orderByDesc("AGE");
1978```
1979
1980### distinct
1981
1982distinct(): RdbPredicates
1983
1984配置谓词以过滤重复记录并仅保留其中一个。
1985
1986**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
1987
1988**返回值**:
1989
1990| 类型                                 | 说明                           |
1991| ------------------------------------ | ------------------------------ |
1992| [RdbPredicates](#rdbpredicates) | 返回可用于过滤重复记录的谓词。 |
1993
1994**示例:**
1995
1996```ts
1997let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
1998predicates.equalTo("NAME", "Rose").distinct();
1999```
2000
2001### limitAs
2002
2003limitAs(value: number): RdbPredicates
2004
2005设置谓词的最大数据记录数量。
2006
2007**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2008
2009**参数:**
2010
2011| 参数名 | 类型   | 必填 | 说明             |
2012| ------ | ------ | ---- | ---------------- |
2013| value  | number | 是   | 最大数据记录数,取值应为正整数,传入值小于等于0时,不会限制记录数量。 |
2014
2015**返回值**:
2016
2017| 类型                                 | 说明                                 |
2018| ------------------------------------ | ------------------------------------ |
2019| [RdbPredicates](#rdbpredicates) | 返回可用于设置最大数据记录数的谓词。 |
2020
2021**错误码:**
2022
2023以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2024
2025| **错误码ID** | **错误信息**               |
2026| --------- |--------------------------|
2027| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
2028
2029**示例:**
2030
2031```ts
2032let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2033predicates.equalTo("NAME", "Rose").limitAs(3);
2034```
2035
2036### offsetAs
2037
2038offsetAs(rowOffset: number): RdbPredicates
2039
2040设置谓词查询结果返回的起始位置。需要同步调用limitAs接口指定查询数量,否则将无查询结果。如需查询指定偏移位置后的所有行,limitAs接口入参需小于等于0。
2041
2042**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2043
2044**参数:**
2045
2046| 参数名    | 类型   | 必填 | 说明                               |
2047| --------- | ------ | ---- | ---------------------------------- |
2048| rowOffset | number | 是   | 指定查询结果的起始位置,默认初始位置为结果集的最前端。当rowOffset为负数时,起始位置为结果集的最前端。当rowOffset超出结果集最后位置时,查询结果为空。 |
2049
2050**返回值**:
2051
2052| 类型                                 | 说明                                 |
2053| ------------------------------------ | ------------------------------------ |
2054| [RdbPredicates](#rdbpredicates) | 返回具有指定返回结果起始位置的谓词。 |
2055
2056**错误码:**
2057
2058以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2059
2060| **错误码ID** | **错误信息**                                                                                                       |
2061| --------- |----------------------------------------------------------------------------------------------------------------|
2062| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
2063
2064**示例:**
2065
2066```ts
2067let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2068predicates.equalTo("NAME", "Rose").limitAs(-1).offsetAs(3);
2069```
2070
2071### groupBy
2072
2073groupBy(fields: Array&lt;string&gt;): RdbPredicates
2074
2075配置谓词按指定列分组查询结果。
2076
2077**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2078
2079**参数:**
2080
2081| 参数名 | 类型                | 必填 | 说明                 |
2082| ------ | ------------------- | ---- | -------------------- |
2083| fields | Array&lt;string&gt; | 是   | 指定分组依赖的列名。 |
2084
2085**返回值**:
2086
2087| 类型                                 | 说明                   |
2088| ------------------------------------ | ---------------------- |
2089| [RdbPredicates](#rdbpredicates) | 返回分组查询列的谓词。 |
2090
2091**错误码:**
2092
2093以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2094
2095| **错误码ID** | **错误信息**                                                                                                       |
2096| --------- |----------------------------------------------------------------------------------------------------------------|
2097| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
2098
2099**示例:**
2100
2101```ts
2102let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2103predicates.groupBy(["AGE", "NAME"]);
2104```
2105
2106### indexedBy
2107
2108indexedBy(field: string): RdbPredicates
2109
2110配置谓词以指定索引列。
2111
2112**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2113
2114**参数:**
2115
2116| 参数名 | 类型   | 必填 | 说明           |
2117| ------ | ------ | ---- | -------------- |
2118| field  | string | 是   | 索引列的名称。 |
2119
2120**返回值**:
2121
2122
2123| 类型                                 | 说明                                  |
2124| ------------------------------------ | ------------------------------------- |
2125| [RdbPredicates](#rdbpredicates) | 返回具有指定索引列的RdbPredicates。 |
2126
2127**错误码:**
2128
2129以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2130
2131| **错误码ID** | **错误信息**                                                                                                       |
2132| --------- |----------------------------------------------------------------------------------------------------------------|
2133| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
2134
2135**示例:**
2136
2137```ts
2138let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2139predicates.indexedBy("SALARY");
2140```
2141
2142### in
2143
2144in(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
2145
2146配置谓词以匹配数据表的field列中值在给定范围内的字段。
2147
2148**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2149
2150**参数:**
2151
2152| 参数名 | 类型                                 | 必填 | 说明                                    |
2153| ------ | ------------------------------------ | ---- | --------------------------------------- |
2154| field  | string                               | 是   | 数据库表中的列名。                      |
2155| value  | Array&lt;[ValueType](#valuetype)&gt; | 是   | 以ValueType型数组形式指定的要匹配的值。 |
2156
2157**返回值**:
2158
2159| 类型                                 | 说明                       |
2160| ------------------------------------ | -------------------------- |
2161| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
2162
2163**错误码:**
2164
2165以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2166
2167| **错误码ID** | **错误信息**                                                                                                       |
2168| --------- |----------------------------------------------------------------------------------------------------------------|
2169| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
2170
2171**示例:**
2172
2173```ts
2174// 匹配数据表的"AGE"列中在[18,20]中的值
2175let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2176predicates.in("AGE", [18, 20]);
2177```
2178
2179### notIn
2180
2181notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicates
2182
2183将谓词配置为匹配数据字段为ValueType且值超出给定范围的指定字段。
2184
2185**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2186
2187**参数:**
2188
2189| 参数名 | 类型                                 | 必填 | 说明                                  |
2190| ------ | ------------------------------------ | ---- | ------------------------------------- |
2191| field  | string                               | 是   | 数据库表中的列名。                    |
2192| value  | Array&lt;[ValueType](#valuetype)&gt; | 是   | 以ValueType数组形式指定的要匹配的值。 |
2193
2194**返回值**:
2195
2196| 类型                                 | 说明                       |
2197| ------------------------------------ | -------------------------- |
2198| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
2199
2200**错误码:**
2201
2202以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2203
2204| **错误码ID** | **错误信息**                                                                                                       |
2205| --------- |----------------------------------------------------------------------------------------------------------------|
2206| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
2207
2208**示例:**
2209
2210```ts
2211// 匹配数据表的"NAME"列中不在["Lisa", "Rose"]中的值
2212let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2213predicates.notIn("NAME", ["Lisa", "Rose"]);
2214```
2215
2216### notContains<sup>12+</sup>
2217
2218notContains(field: string, value: string): RdbPredicates
2219
2220配置谓词以匹配数据表的field列中不包含value的字段。
2221
2222**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2223
2224**参数:**
2225
2226| 参数名 | 类型   | 必填 | 说明                   |
2227| ------ | ------ | ---- | ---------------------- |
2228| field  | string | 是   | 数据库表中的列名。     |
2229| value  | string | 是   | 指示要与谓词匹配的值。 |
2230
2231**返回值**:
2232
2233| 类型                            | 说明                       |
2234| ------------------------------- | -------------------------- |
2235| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
2236
2237**错误码:**
2238
2239以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2240
2241| **错误码ID** | **错误信息**                                                                                                       |
2242| --------- |----------------------------------------------------------------------------------------------------------------|
2243| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
2244
2245**示例:**
2246
2247```ts
2248// 匹配数据表的"NAME"列中不包含"os"的字段,如列表中的"Lisa"
2249let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2250predicates.notContains("NAME", "os");
2251```
2252
2253### notLike<sup>12+</sup>
2254
2255notLike(field: string, value: string): RdbPredicates
2256
2257配置谓词以匹配数据表的field列中值不存在类似于value的字段。
2258
2259**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2260
2261**参数:**
2262
2263| 参数名 | 类型   | 必填 | 说明                   |
2264| ------ | ------ | ---- | ---------------------- |
2265| field  | string | 是   | 数据库表中的列名。     |
2266| value  | string | 是   | 指示要与谓词匹配的值。 |
2267
2268**返回值**:
2269
2270| 类型                            | 说明                       |
2271| ------------------------------- | -------------------------- |
2272| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 |
2273
2274**错误码:**
2275
2276以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2277
2278| **错误码ID** | **错误信息**                                                                                                       |
2279| --------- |----------------------------------------------------------------------------------------------------------------|
2280| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;  2. Incorrect parameter types. |
2281
2282**示例:**
2283
2284```ts
2285// 匹配数据表的"NAME"列中不等于"os"的字段,如列表中的"Rose"
2286let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
2287predicates.notLike("NAME", "os");
2288```
2289
2290
2291
2292## RdbStore
2293
2294提供管理关系数据库(RDB)方法的接口。
2295
2296在使用以下相关接口前,请使用[executeSql](#executesql)接口初始化数据库表结构和相关数据。
2297
2298### 属性
2299
2300**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2301
2302| 名称         | 类型            | 只读       | 可选 | 说明                             |
2303| ------------ | ----------- | ---- | -------------------------------- | -------------------------------- |
2304| version<sup>10+</sup>  | number | 否 | 否   | 设置和获取数据库版本,值为大于0的正整数。       |
2305| rebuilt<sup>12+</sup> | [RebuildType](#rebuildtype12) | 是 | 否 | 用于获取数据库是否进行过重建或修复。 |
2306
2307**错误码:**
2308
2309以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
2310
2311| **错误码ID** | **错误信息**                                                 |
2312|-----------| ------------------------------------------------------------ |
2313| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2314| 801       | Capability not supported. |
2315| 14800000  | Inner error. |
2316| 14800014  | Already closed. |
2317| 14800015  | The database does not respond. |
2318| 14800021  | SQLite: Generic error. |
2319| 14800023  | SQLite: Access permission denied. |
2320| 14800024  | SQLite: The database file is locked. |
2321| 14800025  | SQLite: A table in the database is locked. |
2322| 14800026  | SQLite: The database is out of memory. |
2323| 14800027  | SQLite: Attempt to write a readonly database. |
2324| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2325| 14800029  | SQLite: The database is full. |
2326| 14800030  | SQLite: Unable to open the database file. |
2327
2328**示例:**
2329
2330```ts
2331// 设置数据库版本
2332import { UIAbility } from '@kit.AbilityKit';
2333import { BusinessError } from '@kit.BasicServicesKit';
2334import { window } from '@kit.ArkUI';
2335
2336let store: relationalStore.RdbStore | undefined = undefined;
2337
2338class EntryAbility extends UIAbility {
2339  onWindowStageCreate(windowStage: window.WindowStage) {
2340    const STORE_CONFIG: relationalStore.StoreConfig = {
2341      name: "RdbTest.db",
2342      securityLevel: relationalStore.SecurityLevel.S3
2343    };
2344
2345    const SQL_CREATE_TABLE = 'CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB, IDENTITY UNLIMITED INT, ASSETDATA ASSET, ASSETSDATA ASSETS, FLOATARRAY floatvector(128))';
2346    relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => {
2347      store = rdbStore;
2348      await (store as relationalStore.RdbStore).executeSql(SQL_CREATE_TABLE);
2349      console.info('Get RdbStore successfully.');
2350    }).catch((err: BusinessError) => {
2351      console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
2352    });
2353
2354    // 设置数据库版本
2355    if (store != undefined) {
2356      (store as relationalStore.RdbStore).version = 3;
2357      // 获取数据库版本
2358      console.info(`RdbStore version is ${store.version}`);
2359      // 获取数据库是否重建
2360      console.info(`RdbStore rebuilt is ${store.rebuilt}`);
2361    }
2362  }
2363}
2364```
2365
2366### insert
2367
2368insert(table: string, values: ValuesBucket, callback: AsyncCallback&lt;number&gt;):void
2369
2370向目标表中插入一行数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2371
2372**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2373
2374**参数:**
2375
2376| 参数名   | 类型                          | 必填 | 说明                                                       |
2377| -------- | ----------------------------- | ---- | ---------------------------------------------------------- |
2378| table    | string                        | 是   | 指定的目标表名。                                           |
2379| values   | [ValuesBucket](#valuesbucket) | 是   | 表示要插入到表中的数据行。                                 |
2380| callback | AsyncCallback&lt;number&gt;   | 是   | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 |
2381
2382**错误码:**
2383
2384以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2385
2386| **错误码ID** | **错误信息**                                                 |
2387|-----------| ------------------------------------------------------------ |
2388| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2389| 14800000  | Inner error. |
2390| 14800011  | Database corrupted. |
2391| 14800014  | Already closed. |
2392| 14800015  | The database does not respond. |
2393| 14800021  | SQLite: Generic error. |
2394| 14800022  | SQLite: Callback routine requested an abort. |
2395| 14800023  | SQLite: Access permission denied. |
2396| 14800024  | SQLite: The database file is locked. |
2397| 14800025  | SQLite: A table in the database is locked. |
2398| 14800026  | SQLite: The database is out of memory. |
2399| 14800027  | SQLite: Attempt to write a readonly database. |
2400| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2401| 14800029  | SQLite: The database is full. |
2402| 14800030  | SQLite: Unable to open the database file. |
2403| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2404| 14800032  | SQLite: Abort due to constraint violation. |
2405| 14800033  | SQLite: Data type mismatch. |
2406| 14800034  | SQLite: Library used incorrectly. |
2407| 14800047  | The WAL file size exceeds the default limit. |
2408
2409**示例:**
2410
2411```ts
2412let value1 = "Lisa";
2413let value2 = 18;
2414let value3 = 100.5;
2415let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2416
2417// 以下三种方式可用
2418const valueBucket1: relationalStore.ValuesBucket = {
2419  'NAME': value1,
2420  'AGE': value2,
2421  'SALARY': value3,
2422  'CODES': value4
2423};
2424const valueBucket2: relationalStore.ValuesBucket = {
2425  NAME: value1,
2426  AGE: value2,
2427  SALARY: value3,
2428  CODES: value4
2429};
2430const valueBucket3: relationalStore.ValuesBucket = {
2431  "NAME": value1,
2432  "AGE": value2,
2433  "SALARY": value3,
2434  "CODES": value4
2435};
2436
2437if (store != undefined) {
2438  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, (err: BusinessError, rowId: number) => {
2439    if (err) {
2440      console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2441      return;
2442    }
2443    console.info(`Insert is successful, rowId = ${rowId}`);
2444  });
2445}
2446```
2447
2448### insert<sup>10+</sup>
2449
2450insert(table: string, values: ValuesBucket,  conflict: ConflictResolution, callback: AsyncCallback&lt;number&gt;):void
2451
2452向目标表中插入一行数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2453
2454**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2455
2456**参数:**
2457
2458| 参数名   | 类型                                        | 必填 | 说明                                                       |
2459| -------- | ------------------------------------------- | ---- | ---------------------------------------------------------- |
2460| table    | string                                      | 是   | 指定的目标表名。                                           |
2461| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。                                 |
2462| conflict | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。                                         |
2463| callback | AsyncCallback&lt;number&gt;                 | 是   | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 |
2464
2465**错误码:**
2466
2467以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2468
2469| **错误码ID** | **错误信息**                                                 |
2470|-----------| ---------------------------------------------------- |
2471| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2472| 14800000  | Inner error. |
2473| 14800011  | Database corrupted. |
2474| 14800014  | Already closed. |
2475| 14800015  | The database does not respond. |
2476| 14800021  | SQLite: Generic error. |
2477| 14800022  | SQLite: Callback routine requested an abort. |
2478| 14800023  | SQLite: Access permission denied. |
2479| 14800024  | SQLite: The database file is locked. |
2480| 14800025  | SQLite: A table in the database is locked. |
2481| 14800026  | SQLite: The database is out of memory. |
2482| 14800027  | SQLite: Attempt to write a readonly database. |
2483| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2484| 14800029  | SQLite: The database is full. |
2485| 14800030  | SQLite: Unable to open the database file. |
2486| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2487| 14800032  | SQLite: Abort due to constraint violation. |
2488| 14800033  | SQLite: Data type mismatch. |
2489| 14800034  | SQLite: Library used incorrectly. |
2490| 14800047  | The WAL file size exceeds the default limit. |
2491
2492**示例:**
2493
2494```ts
2495let value1 = "Lisa";
2496let value2 = 18;
2497let value3 = 100.5;
2498let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2499
2500// 以下三种方式可用
2501const valueBucket1: relationalStore.ValuesBucket = {
2502  'NAME': value1,
2503  'AGE': value2,
2504  'SALARY': value3,
2505  'CODES': value4
2506};
2507const valueBucket2: relationalStore.ValuesBucket = {
2508  NAME: value1,
2509  AGE: value2,
2510  SALARY: value3,
2511  CODES: value4
2512};
2513const valueBucket3: relationalStore.ValuesBucket = {
2514  "NAME": value1,
2515  "AGE": value2,
2516  "SALARY": value3,
2517  "CODES": value4
2518};
2519
2520if (store != undefined) {
2521  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE,
2522    (err: BusinessError, rowId: number) => {
2523      if (err) {
2524        console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2525        return;
2526      }
2527      console.info(`Insert is successful, rowId = ${rowId}`);
2528    });
2529}
2530```
2531
2532### insert
2533
2534insert(table: string, values: ValuesBucket):Promise&lt;number&gt;
2535
2536向目标表中插入一行数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2537
2538**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2539
2540**参数:**
2541
2542| 参数名 | 类型                          | 必填 | 说明                       |
2543| ------ | ----------------------------- | ---- | -------------------------- |
2544| table  | string                        | 是   | 指定的目标表名。           |
2545| values | [ValuesBucket](#valuesbucket) | 是   | 表示要插入到表中的数据行。 |
2546
2547**返回值**:
2548
2549| 类型                  | 说明                                              |
2550| --------------------- | ------------------------------------------------- |
2551| Promise&lt;number&gt; | Promise对象。如果操作成功,返回行ID;否则返回-1。 |
2552
2553**错误码:**
2554
2555以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2556
2557| **错误码ID** | **错误信息**                                                 |
2558|-----------| ------------------------------------------------------------ |
2559| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2560| 14800000  | Inner error. |
2561| 14800011  | Database corrupted. |
2562| 14800014  | Already closed. |
2563| 14800015  | The database does not respond. |
2564| 14800021  | SQLite: Generic error. |
2565| 14800022  | SQLite: Callback routine requested an abort. |
2566| 14800023  | SQLite: Access permission denied. |
2567| 14800024  | SQLite: The database file is locked. |
2568| 14800025  | SQLite: A table in the database is locked. |
2569| 14800026  | SQLite: The database is out of memory. |
2570| 14800027  | SQLite: Attempt to write a readonly database. |
2571| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2572| 14800029  | SQLite: The database is full. |
2573| 14800030  | SQLite: Unable to open the database file. |
2574| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2575| 14800032  | SQLite: Abort due to constraint violation. |
2576| 14800033  | SQLite: Data type mismatch. |
2577| 14800034  | SQLite: Library used incorrectly. |
2578| 14800047  | The WAL file size exceeds the default limit. |
2579
2580**示例:**
2581
2582```ts
2583import { BusinessError } from '@kit.BasicServicesKit';
2584
2585let value1 = "Lisa";
2586let value2 = 18;
2587let value3 = 100.5;
2588let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2589
2590// 以下三种方式可用
2591const valueBucket1: relationalStore.ValuesBucket = {
2592  'NAME': value1,
2593  'AGE': value2,
2594  'SALARY': value3,
2595  'CODES': value4
2596};
2597const valueBucket2: relationalStore.ValuesBucket = {
2598  NAME: value1,
2599  AGE: value2,
2600  SALARY: value3,
2601  CODES: value4
2602};
2603const valueBucket3: relationalStore.ValuesBucket = {
2604  "NAME": value1,
2605  "AGE": value2,
2606  "SALARY": value3,
2607  "CODES": value4
2608};
2609
2610if (store != undefined) {
2611  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1).then((rowId: number) => {
2612    console.info(`Insert is successful, rowId = ${rowId}`);
2613  }).catch((err: BusinessError) => {
2614    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2615  });
2616}
2617```
2618
2619### insert<sup>10+</sup>
2620
2621insert(table: string, values: ValuesBucket,  conflict: ConflictResolution):Promise&lt;number&gt;
2622
2623向目标表中插入一行数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2624
2625**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2626
2627**参数:**
2628
2629| 参数名   | 类型                                        | 必填 | 说明                       |
2630| -------- | ------------------------------------------- | ---- | -------------------------- |
2631| table    | string                                      | 是   | 指定的目标表名。           |
2632| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。 |
2633| conflict | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。         |
2634
2635**返回值**:
2636
2637| 类型                  | 说明                                              |
2638| --------------------- | ------------------------------------------------- |
2639| Promise&lt;number&gt; | Promise对象。如果操作成功,返回行ID;否则返回-1。 |
2640
2641**错误码:**
2642
2643以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2644
2645| **错误码ID** | **错误信息**                                                 |
2646|-----------| ------------------------------------------------------------ |
2647| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2648| 14800000  | Inner error. |
2649| 14800011  | Database corrupted. |
2650| 14800014  | Already closed. |
2651| 14800015  | The database does not respond. |
2652| 14800021  | SQLite: Generic error. |
2653| 14800022  | SQLite: Callback routine requested an abort. |
2654| 14800023  | SQLite: Access permission denied. |
2655| 14800024  | SQLite: The database file is locked. |
2656| 14800025  | SQLite: A table in the database is locked. |
2657| 14800026  | SQLite: The database is out of memory. |
2658| 14800027  | SQLite: Attempt to write a readonly database. |
2659| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2660| 14800029  | SQLite: The database is full. |
2661| 14800030  | SQLite: Unable to open the database file. |
2662| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2663| 14800032  | SQLite: Abort due to constraint violation. |
2664| 14800033  | SQLite: Data type mismatch. |
2665| 14800034  | SQLite: Library used incorrectly. |
2666| 14800047  | The WAL file size exceeds the default limit. |
2667
2668**示例:**
2669
2670```ts
2671import { BusinessError } from '@kit.BasicServicesKit';
2672
2673let value1 = "Lisa";
2674let value2 = 18;
2675let value3 = 100.5;
2676let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2677
2678// 以下三种方式可用
2679const valueBucket1: relationalStore.ValuesBucket = {
2680  'NAME': value1,
2681  'AGE': value2,
2682  'SALARY': value3,
2683  'CODES': value4
2684};
2685const valueBucket2: relationalStore.ValuesBucket = {
2686  NAME: value1,
2687  AGE: value2,
2688  SALARY: value3,
2689  CODES: value4
2690};
2691const valueBucket3: relationalStore.ValuesBucket = {
2692  "NAME": value1,
2693  "AGE": value2,
2694  "SALARY": value3,
2695  "CODES": value4
2696};
2697
2698if (store != undefined) {
2699  (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => {
2700    console.info(`Insert is successful, rowId = ${rowId}`);
2701  }).catch((err: BusinessError) => {
2702    console.error(`Insert is failed, code is ${err.code},message is ${err.message}`);
2703  });
2704}
2705```
2706
2707### insertSync<sup>12+</sup>
2708
2709insertSync(table: string, values: ValuesBucket,  conflict?: ConflictResolution):number
2710
2711向目标表中插入一行数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2712
2713**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2714
2715**参数:**
2716
2717| 参数名   | 类型                                        | 必填 | 说明                                                         |
2718| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
2719| table    | string                                      | 是   | 指定的目标表名。                                             |
2720| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。                                   |
2721| conflict | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
2722
2723**返回值**:
2724
2725| 类型   | 说明                                 |
2726| ------ | ------------------------------------ |
2727| number | 如果操作成功,返回行ID;否则返回-1。 |
2728
2729**错误码:**
2730
2731以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2732
2733| **错误码ID** | **错误信息**                                                 |
2734| ------------ | ------------------------------------------------------------ |
2735| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2736| 14800000     | Inner error.                                                 |
2737| 14800011     | Database corrupted.                                          |
2738| 14800014     | Already closed.                                              |
2739| 14800015     | The database does not respond.                                        |
2740| 14800021     | SQLite: Generic error.                                       |
2741| 14800022     | SQLite: Callback routine requested an abort.                 |
2742| 14800023     | SQLite: Access permission denied.                            |
2743| 14800024     | SQLite: The database file is locked.                         |
2744| 14800025     | SQLite: A table in the database is locked.                   |
2745| 14800026     | SQLite: The database is out of memory.                       |
2746| 14800027     | SQLite: Attempt to write a readonly database.                |
2747| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
2748| 14800029     | SQLite: The database is full.                                |
2749| 14800030     | SQLite: Unable to open the database file.                    |
2750| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
2751| 14800032     | SQLite: Abort due to constraint violation.                   |
2752| 14800033     | SQLite: Data type mismatch.                                  |
2753| 14800034     | SQLite: Library used incorrectly.                            |
2754| 14800047     | The WAL file size exceeds the default limit.                 |
2755
2756**示例:**
2757
2758```ts
2759import { BusinessError } from '@kit.BasicServicesKit';
2760
2761let value1 = "Lisa";
2762let value2 = 18;
2763let value3 = 100.5;
2764let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2765
2766// 以下三种方式可用
2767const valueBucket1: relationalStore.ValuesBucket = {
2768  'NAME': value1,
2769  'AGE': value2,
2770  'SALARY': value3,
2771  'CODES': value4
2772};
2773const valueBucket2: relationalStore.ValuesBucket = {
2774  NAME: value1,
2775  AGE: value2,
2776  SALARY: value3,
2777  CODES: value4
2778};
2779const valueBucket3: relationalStore.ValuesBucket = {
2780  "NAME": value1,
2781  "AGE": value2,
2782  "SALARY": value3,
2783  "CODES": value4
2784};
2785
2786if (store != undefined) {
2787  try {
2788    let rowId: number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
2789    console.info(`Insert is successful, rowId = ${rowId}`);
2790  } catch (error) {
2791    console.error(`Insert is failed, code is ${error.code},message is ${error.message}`);
2792  }
2793}
2794```
2795
2796### insertSync<sup>12+</sup>
2797
2798insertSync(table: string, values: sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution):number
2799
2800传入Sendable数据,向目标表中插入一行数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
2801
2802**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2803
2804**参数:**
2805
2806| 参数名   | 类型                                                                                           | 必填 | 说明                                                                            |
2807| -------- | ---------------------------------------------------------------------------------------------- | ---- | ------------------------------------------------------------------------------- |
2808| table    | string                                                                                         | 是   | 指定的目标表名。                                                                |
2809| values   | [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | 是   | 表示要插入到表中的可跨线程传递数据。                                            |
2810| conflict | [ConflictResolution](#conflictresolution10)                                                    | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
2811
2812**返回值**:
2813
2814| 类型   | 说明                                 |
2815| ------ | ------------------------------------ |
2816| number | 如果操作成功,返回行ID;否则返回-1。 |
2817
2818**错误码:**
2819
2820以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2821
2822| **错误码ID** | **错误信息**                                                 |
2823| ------------ | ------------------------------------------------------------ |
2824| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2825| 14800000     | Inner error.                                                 |
2826| 14800011     | Database corrupted.                                          |
2827| 14800014     | Already closed.                                              |
2828| 14800015     | The database does not respond.                                        |
2829| 14800021     | SQLite: Generic error.                                       |
2830| 14800022     | SQLite: Callback routine requested an abort.                 |
2831| 14800023     | SQLite: Access permission denied.                            |
2832| 14800024     | SQLite: The database file is locked.                         |
2833| 14800025     | SQLite: A table in the database is locked.                   |
2834| 14800026     | SQLite: The database is out of memory.                       |
2835| 14800027     | SQLite: Attempt to write a readonly database.                |
2836| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
2837| 14800029     | SQLite: The database is full.                                |
2838| 14800030     | SQLite: Unable to open the database file.                    |
2839| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
2840| 14800032     | SQLite: Abort due to constraint violation.                   |
2841| 14800033     | SQLite: Data type mismatch.                                  |
2842| 14800034     | SQLite: Library used incorrectly.                            |
2843| 14800047     | The WAL file size exceeds the default limit.                 |
2844
2845**示例:**
2846
2847```ts
2848import { sendableRelationalStore } from '@kit.ArkData';
2849
2850const valuesBucket: relationalStore.ValuesBucket = {
2851  "NAME": 'hangman',
2852  "AGE": 18,
2853  "SALARY": 100.5,
2854  "CODES": new Uint8Array([1, 2, 3])
2855};
2856const sendableValuesBucket = sendableRelationalStore.toSendableValuesBucket(valuesBucket);
2857
2858if (store != undefined) {
2859  try {
2860    let rowId: number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", sendableValuesBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
2861    console.info(`Insert is successful, rowId = ${rowId}`);
2862  } catch (error) {
2863    console.error(`Insert is failed, code is ${error.code},message is ${error.message}`);
2864  }
2865}
2866```
2867
2868### batchInsert
2869
2870batchInsert(table: string, values: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;):void
2871
2872向目标表中插入一组数据,使用callback异步回调。
2873
2874**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2875
2876**参数:**
2877
2878| 参数名   | 类型                                       | 必填 | 说明                                                         |
2879| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
2880| table    | string                                     | 是   | 指定的目标表名。                                             |
2881| values   | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。             |
2882| callback | AsyncCallback&lt;number&gt;                | 是   | 指定callback回调函数。如果操作成功,返回插入的数据个数,否则返回-1。 |
2883
2884**错误码:**
2885
2886以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2887
2888| **错误码ID** | **错误信息**                                                 |
2889|-----------| ------------------------------------------------------------ |
2890| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2891| 14800000  | Inner error. |
2892| 14800011  | Database corrupted. |
2893| 14800014  | Already closed. |
2894| 14800015  | The database does not respond. |
2895| 14800021  | SQLite: Generic error. |
2896| 14800022  | SQLite: Callback routine requested an abort. |
2897| 14800023  | SQLite: Access permission denied. |
2898| 14800024  | SQLite: The database file is locked. |
2899| 14800025  | SQLite: A table in the database is locked. |
2900| 14800026  | SQLite: The database is out of memory. |
2901| 14800027  | SQLite: Attempt to write a readonly database. |
2902| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2903| 14800029  | SQLite: The database is full. |
2904| 14800030  | SQLite: Unable to open the database file. |
2905| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
2906| 14800032  | SQLite: Abort due to constraint violation. |
2907| 14800033  | SQLite: Data type mismatch. |
2908| 14800034  | SQLite: Library used incorrectly. |
2909| 14800047  | The WAL file size exceeds the default limit. |
2910
2911**示例:**
2912
2913```ts
2914let value1 = "Lisa";
2915let value2 = 18;
2916let value3 = 100.5;
2917let value4 = new Uint8Array([1, 2, 3, 4, 5]);
2918let value5 = "Jack";
2919let value6 = 19;
2920let value7 = 101.5;
2921let value8 = new Uint8Array([6, 7, 8, 9, 10]);
2922let value9 = "Tom";
2923let value10 = 20;
2924let value11 = 102.5;
2925let value12 = new Uint8Array([11, 12, 13, 14, 15]);
2926
2927const valueBucket1: relationalStore.ValuesBucket = {
2928  'NAME': value1,
2929  'AGE': value2,
2930  'SALARY': value3,
2931  'CODES': value4
2932};
2933const valueBucket2: relationalStore.ValuesBucket = {
2934  'NAME': value5,
2935  'AGE': value6,
2936  'SALARY': value7,
2937  'CODES': value8
2938};
2939const valueBucket3: relationalStore.ValuesBucket = {
2940  'NAME': value9,
2941  'AGE': value10,
2942  'SALARY': value11,
2943  'CODES': value12
2944};
2945
2946let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
2947if (store != undefined) {
2948  (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets, (err, insertNum) => {
2949    if (err) {
2950      console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
2951      return;
2952    }
2953    console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
2954  })
2955}
2956```
2957
2958### batchInsert
2959
2960batchInsert(table: string, values: Array&lt;ValuesBucket&gt;):Promise&lt;number&gt;
2961
2962向目标表中插入一组数据,使用Promise异步回调。
2963
2964**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
2965
2966**参数:**
2967
2968| 参数名 | 类型                                       | 必填 | 说明                         |
2969| ------ | ------------------------------------------ | ---- | ---------------------------- |
2970| table  | string                                     | 是   | 指定的目标表名。             |
2971| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。|
2972
2973**返回值**:
2974
2975| 类型                  | 说明                                                        |
2976| --------------------- | ----------------------------------------------------------- |
2977| Promise&lt;number&gt; | Promise对象。如果操作成功,返回插入的数据个数,否则返回-1。 |
2978
2979**错误码:**
2980
2981以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
2982
2983| **错误码ID** | **错误信息**                                                 |
2984|-----------| ------------------------------------------------------------ |
2985| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2986| 14800000  | Inner error. |
2987| 14800011  | Database corrupted. |
2988| 14800014  | Already closed. |
2989| 14800015  | The database does not respond. |
2990| 14800021  | SQLite: Generic error. |
2991| 14800022  | SQLite: Callback routine requested an abort. |
2992| 14800023  | SQLite: Access permission denied. |
2993| 14800024  | SQLite: The database file is locked. |
2994| 14800025  | SQLite: A table in the database is locked. |
2995| 14800026  | SQLite: The database is out of memory. |
2996| 14800027  | SQLite: Attempt to write a readonly database. |
2997| 14800028  | SQLite: Some kind of disk I/O error occurred. |
2998| 14800029  | SQLite: The database is full. |
2999| 14800030  | SQLite: Unable to open the database file. |
3000| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3001| 14800032  | SQLite: Abort due to constraint violation. |
3002| 14800033  | SQLite: Data type mismatch. |
3003| 14800034  | SQLite: Library used incorrectly. |
3004| 14800047  | The WAL file size exceeds the default limit. |
3005
3006**示例:**
3007
3008```ts
3009import { BusinessError } from '@kit.BasicServicesKit';
3010
3011let value1 = "Lisa";
3012let value2 = 18;
3013let value3 = 100.5;
3014let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3015let value5 = "Jack";
3016let value6 = 19;
3017let value7 = 101.5;
3018let value8 = new Uint8Array([6, 7, 8, 9, 10]);
3019let value9 = "Tom";
3020let value10 = 20;
3021let value11 = 102.5;
3022let value12 = new Uint8Array([11, 12, 13, 14, 15]);
3023
3024const valueBucket1: relationalStore.ValuesBucket = {
3025  'NAME': value1,
3026  'AGE': value2,
3027  'SALARY': value3,
3028  'CODES': value4
3029};
3030const valueBucket2: relationalStore.ValuesBucket = {
3031  'NAME': value5,
3032  'AGE': value6,
3033  'SALARY': value7,
3034  'CODES': value8
3035};
3036const valueBucket3: relationalStore.ValuesBucket = {
3037  'NAME': value9,
3038  'AGE': value10,
3039  'SALARY': value11,
3040  'CODES': value12
3041};
3042
3043let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
3044if (store != undefined) {
3045  (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => {
3046    console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
3047  }).catch((err: BusinessError) => {
3048    console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
3049  })
3050}
3051```
3052
3053### batchInsertSync<sup>12+</sup>
3054
3055batchInsertSync(table: string, values: Array&lt;ValuesBucket&gt;):number
3056
3057向目标表中插入一组数据。
3058
3059**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3060
3061**参数:**
3062
3063| 参数名 | 类型                                       | 必填 | 说明                         |
3064| ------ | ------------------------------------------ | ---- | ---------------------------- |
3065| table  | string                                     | 是   | 指定的目标表名。             |
3066| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。 |
3067
3068**返回值**:
3069
3070| 类型   | 说明                                           |
3071| ------ | ---------------------------------------------- |
3072| number | 如果操作成功,返回插入的数据个数,否则返回-1。 |
3073
3074**错误码:**
3075
3076以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3077
3078| **错误码ID** | **错误信息**                                                 |
3079| ------------ | ------------------------------------------------------------ |
3080| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3081| 14800000     | Inner error.                                                 |
3082| 14800011     | Database corrupted.                                          |
3083| 14800014     | Already closed.                                              |
3084| 14800015     | The database does not respond.                                        |
3085| 14800021     | SQLite: Generic error.                                       |
3086| 14800022     | SQLite: Callback routine requested an abort.                 |
3087| 14800023     | SQLite: Access permission denied.                            |
3088| 14800024     | SQLite: The database file is locked.                         |
3089| 14800025     | SQLite: A table in the database is locked.                   |
3090| 14800026     | SQLite: The database is out of memory.                       |
3091| 14800027     | SQLite: Attempt to write a readonly database.                |
3092| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
3093| 14800029     | SQLite: The database is full.                                |
3094| 14800030     | SQLite: Unable to open the database file.                    |
3095| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
3096| 14800032     | SQLite: Abort due to constraint violation.                   |
3097| 14800033     | SQLite: Data type mismatch.                                  |
3098| 14800034     | SQLite: Library used incorrectly.                            |
3099| 14800047     | The WAL file size exceeds the default limit.                 |
3100
3101**示例:**
3102
3103```ts
3104import { BusinessError } from '@kit.BasicServicesKit';
3105
3106let value1 = "Lisa";
3107let value2 = 18;
3108let value3 = 100.5;
3109let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3110let value5 = "Jack";
3111let value6 = 19;
3112let value7 = 101.5;
3113let value8 = new Uint8Array([6, 7, 8, 9, 10]);
3114let value9 = "Tom";
3115let value10 = 20;
3116let value11 = 102.5;
3117let value12 = new Uint8Array([11, 12, 13, 14, 15]);
3118
3119const valueBucket1: relationalStore.ValuesBucket = {
3120  'NAME': value1,
3121  'AGE': value2,
3122  'SALARY': value3,
3123  'CODES': value4
3124};
3125const valueBucket2: relationalStore.ValuesBucket = {
3126  'NAME': value5,
3127  'AGE': value6,
3128  'SALARY': value7,
3129  'CODES': value8
3130};
3131const valueBucket3: relationalStore.ValuesBucket = {
3132  'NAME': value9,
3133  'AGE': value10,
3134  'SALARY': value11,
3135  'CODES': value12
3136};
3137
3138let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
3139if (store != undefined) {
3140  try {
3141    let insertNum: number = (store as relationalStore.RdbStore).batchInsertSync("EMPLOYEE", valueBuckets);
3142    console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
3143  } catch (err) {
3144    console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
3145  }
3146}
3147```
3148
3149### batchInsertWithConflictResolution<sup>18+</sup>
3150
3151batchInsertWithConflictResolution(table: string, values: Array&lt;ValuesBucket&gt;, conflict: ConflictResolution): Promise&lt;number&gt;
3152
3153向目标表中插入一组数据,可以通过conflict参数指定冲突解决模式。使用Promise异步回调。
3154
3155**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3156
3157**参数:**
3158
3159| 参数名 | 类型                                       | 必填 | 说明                         |
3160| ------ | ------------------------------------------ | ---- | ---------------------------- |
3161| table  | string                                     | 是   | 指定的目标表名。             |
3162| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。 |
3163| conflict   | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。       |
3164
3165**返回值**:
3166
3167| 类型   | 说明                                           |
3168| ------ | ---------------------------------------------- |
3169| Promise&lt;number&gt; | Promise对象。如果操作成功,返回插入的数据个数,否则返回-1。 |
3170
3171**错误码:**
3172
3173以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3174
3175| **错误码ID** | **错误信息**                                                 |
3176| ------------ | ------------------------------------------------------------ |
3177| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3178| 14800000     | Inner error.                                                 |
3179| 14800011     | Database corrupted.                                          |
3180| 14800014     | Already closed.                                              |
3181| 14800015     | The database does not respond.                                        |
3182| 14800021     | SQLite: Generic error.                                       |
3183| 14800022     | SQLite: Callback routine requested an abort.                 |
3184| 14800023     | SQLite: Access permission denied.                            |
3185| 14800024     | SQLite: The database file is locked.                         |
3186| 14800025     | SQLite: A table in the database is locked.                   |
3187| 14800026     | SQLite: The database is out of memory.                       |
3188| 14800027     | SQLite: Attempt to write a readonly database.                |
3189| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
3190| 14800029     | SQLite: The database is full.                                |
3191| 14800030     | SQLite: Unable to open the database file.                    |
3192| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
3193| 14800032     | SQLite: Abort due to constraint violation.                   |
3194| 14800033     | SQLite: Data type mismatch.                                  |
3195| 14800034     | SQLite: Library used incorrectly.                            |
3196| 14800047     | The WAL file size exceeds the default limit.                 |
3197
3198**示例:**
3199
3200```ts
3201import { BusinessError } from '@kit.BasicServicesKit';
3202
3203let value1 = "Lisa";
3204let value2 = 18;
3205let value3 = 100.5;
3206let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3207let value5 = "Jack";
3208let value6 = 19;
3209let value7 = 101.5;
3210let value8 = new Uint8Array([6, 7, 8, 9, 10]);
3211let value9 = "Tom";
3212let value10 = 20;
3213let value11 = 102.5;
3214let value12 = new Uint8Array([11, 12, 13, 14, 15]);
3215
3216const valueBucket1: relationalStore.ValuesBucket = {
3217  'NAME': value1,
3218  'AGE': value2,
3219  'SALARY': value3,
3220  'CODES': value4
3221};
3222const valueBucket2: relationalStore.ValuesBucket = {
3223  'NAME': value5,
3224  'AGE': value6,
3225  'SALARY': value7,
3226  'CODES': value8
3227};
3228const valueBucket3: relationalStore.ValuesBucket = {
3229  'NAME': value9,
3230  'AGE': value10,
3231  'SALARY': value11,
3232  'CODES': value12
3233};
3234
3235let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
3236if (store != undefined) {
3237  (store as relationalStore.RdbStore).batchInsertWithConflictResolution("EMPLOYEE", valueBuckets, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((insertNum: number) => {
3238    console.info(`batchInsert is successful, insertNum = ${insertNum}`);
3239  }).catch((err: BusinessError) => {
3240    console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
3241  });
3242}
3243```
3244
3245### batchInsertWithConflictResolutionSync<sup>18+</sup>
3246
3247batchInsertWithConflictResolutionSync(table: string, values: Array&lt;ValuesBucket&gt;, conflict: ConflictResolution): number
3248
3249向目标表中插入一组数据。
3250
3251**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3252
3253**参数:**
3254
3255| 参数名 | 类型                                       | 必填 | 说明                         |
3256| ------ | ------------------------------------------ | ---- | ---------------------------- |
3257| table  | string                                     | 是   | 指定的目标表名。             |
3258| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。 |
3259| conflict   | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。       |
3260
3261**返回值**:
3262
3263| 类型   | 说明                                           |
3264| ------ | ---------------------------------------------- |
3265| number | 如果操作成功,返回插入的数据个数,否则返回-1。 |
3266
3267**错误码:**
3268
3269以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3270
3271| **错误码ID** | **错误信息**                                                 |
3272| ------------ | ------------------------------------------------------------ |
3273| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3274| 14800000     | Inner error.                                                 |
3275| 14800011     | Database corrupted.                                          |
3276| 14800014     | Already closed.                                              |
3277| 14800015     | The database does not respond.                                        |
3278| 14800021     | SQLite: Generic error.                                       |
3279| 14800022     | SQLite: Callback routine requested an abort.                 |
3280| 14800023     | SQLite: Access permission denied.                            |
3281| 14800024     | SQLite: The database file is locked.                         |
3282| 14800025     | SQLite: A table in the database is locked.                   |
3283| 14800026     | SQLite: The database is out of memory.                       |
3284| 14800027     | SQLite: Attempt to write a readonly database.                |
3285| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
3286| 14800029     | SQLite: The database is full.                                |
3287| 14800030     | SQLite: Unable to open the database file.                    |
3288| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
3289| 14800032     | SQLite: Abort due to constraint violation.                   |
3290| 14800033     | SQLite: Data type mismatch.                                  |
3291| 14800034     | SQLite: Library used incorrectly.                            |
3292| 14800047     | The WAL file size exceeds the default limit.                 |
3293
3294**示例:**
3295
3296```ts
3297import { BusinessError } from '@kit.BasicServicesKit';
3298
3299let value1 = "Lisa";
3300let value2 = 18;
3301let value3 = 100.5;
3302let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3303let value5 = "Jack";
3304let value6 = 19;
3305let value7 = 101.5;
3306let value8 = new Uint8Array([6, 7, 8, 9, 10]);
3307let value9 = "Tom";
3308let value10 = 20;
3309let value11 = 102.5;
3310let value12 = new Uint8Array([11, 12, 13, 14, 15]);
3311
3312const valueBucket1: relationalStore.ValuesBucket = {
3313  'NAME': value1,
3314  'AGE': value2,
3315  'SALARY': value3,
3316  'CODES': value4
3317};
3318const valueBucket2: relationalStore.ValuesBucket = {
3319  'NAME': value5,
3320  'AGE': value6,
3321  'SALARY': value7,
3322  'CODES': value8
3323};
3324const valueBucket3: relationalStore.ValuesBucket = {
3325  'NAME': value9,
3326  'AGE': value10,
3327  'SALARY': value11,
3328  'CODES': value12
3329};
3330
3331let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
3332if (store != undefined) {
3333  try {
3334    let insertNum: number = (store as relationalStore.RdbStore).batchInsertWithConflictResolutionSync("EMPLOYEE", valueBuckets, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
3335    console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
3336  } catch (err) {
3337    console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`);
3338  }
3339}
3340```
3341
3342### update
3343
3344update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
3345
3346根据RdbPredicates的指定实例对象更新数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3347
3348**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3349
3350**参数:**
3351
3352| 参数名     | 类型                                 | 必填 | 说明                                                         |
3353| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
3354| values     | [ValuesBucket](#valuesbucket)        | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3355| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的更新条件。                    |
3356| callback   | AsyncCallback&lt;number&gt;          | 是   | 指定的callback回调方法。返回受影响的行数。                   |
3357
3358**错误码:**
3359
3360以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3361
3362| **错误码ID** | **错误信息**                                                 |
3363|-----------| ------------------------------------------------------------ |
3364| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3365| 14800000  | Inner error. |
3366| 14800011  | Database corrupted. |
3367| 14800014  | Already closed. |
3368| 14800015  | The database does not respond. |
3369| 14800021  | SQLite: Generic error. |
3370| 14800022  | SQLite: Callback routine requested an abort. |
3371| 14800023  | SQLite: Access permission denied. |
3372| 14800024  | SQLite: The database file is locked. |
3373| 14800025  | SQLite: A table in the database is locked. |
3374| 14800026  | SQLite: The database is out of memory. |
3375| 14800027  | SQLite: Attempt to write a readonly database. |
3376| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3377| 14800029  | SQLite: The database is full. |
3378| 14800030  | SQLite: Unable to open the database file. |
3379| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3380| 14800032  | SQLite: Abort due to constraint violation. |
3381| 14800033  | SQLite: Data type mismatch. |
3382| 14800034  | SQLite: Library used incorrectly. |
3383| 14800047  | The WAL file size exceeds the default limit. |
3384
3385**示例:**
3386
3387```ts
3388let value1 = "Rose";
3389let value2 = 22;
3390let value3 = 200.5;
3391let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3392
3393// 以下三种方式可用
3394const valueBucket1: relationalStore.ValuesBucket = {
3395  'NAME': value1,
3396  'AGE': value2,
3397  'SALARY': value3,
3398  'CODES': value4
3399};
3400const valueBucket2: relationalStore.ValuesBucket = {
3401  NAME: value1,
3402  AGE: value2,
3403  SALARY: value3,
3404  CODES: value4
3405};
3406const valueBucket3: relationalStore.ValuesBucket = {
3407  "NAME": value1,
3408  "AGE": value2,
3409  "SALARY": value3,
3410  "CODES": value4
3411};
3412
3413let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3414predicates.equalTo("NAME", "Lisa");
3415if (store != undefined) {
3416  (store as relationalStore.RdbStore).update(valueBucket1, predicates, (err, rows) => {
3417    if (err) {
3418      console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3419      return;
3420    }
3421    console.info(`Updated row count: ${rows}`);
3422  });
3423}
3424```
3425
3426### update<sup>10+</sup>
3427
3428update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution, callback: AsyncCallback&lt;number&gt;):void
3429
3430根据RdbPredicates的指定实例对象更新数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3431
3432**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3433
3434**参数:**
3435
3436| 参数名     | 类型                                        | 必填 | 说明                                                         |
3437| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
3438| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3439| predicates | [RdbPredicates](#rdbpredicates)            | 是   | RdbPredicates的实例对象指定的更新条件。                      |
3440| conflict   | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。                                           |
3441| callback   | AsyncCallback&lt;number&gt;                 | 是   | 指定的callback回调方法。返回受影响的行数。                   |
3442
3443**错误码:**
3444
3445以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3446
3447| **错误码ID** | **错误信息**                                                 |
3448|-----------| ------------------------------------------------------------ |
3449| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3450| 14800000  | Inner error. |
3451| 14800011  | Database corrupted. |
3452| 14800014  | Already closed. |
3453| 14800015  | The database does not respond. |
3454| 14800021  | SQLite: Generic error. |
3455| 14800022  | SQLite: Callback routine requested an abort. |
3456| 14800023  | SQLite: Access permission denied. |
3457| 14800024  | SQLite: The database file is locked. |
3458| 14800025  | SQLite: A table in the database is locked. |
3459| 14800026  | SQLite: The database is out of memory. |
3460| 14800027  | SQLite: Attempt to write a readonly database. |
3461| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3462| 14800029  | SQLite: The database is full. |
3463| 14800030  | SQLite: Unable to open the database file. |
3464| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3465| 14800032  | SQLite: Abort due to constraint violation. |
3466| 14800033  | SQLite: Data type mismatch. |
3467| 14800034  | SQLite: Library used incorrectly. |
3468| 14800047  | The WAL file size exceeds the default limit. |
3469
3470**示例:**
3471
3472```ts
3473let value1 = "Rose";
3474let value2 = 22;
3475let value3 = 200.5;
3476let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3477
3478// 以下三种方式可用
3479const valueBucket1: relationalStore.ValuesBucket = {
3480  'NAME': value1,
3481  'AGE': value2,
3482  'SALARY': value3,
3483  'CODES': value4
3484};
3485const valueBucket2: relationalStore.ValuesBucket = {
3486  NAME: value1,
3487  AGE: value2,
3488  SALARY: value3,
3489  CODES: value4
3490};
3491const valueBucket3: relationalStore.ValuesBucket = {
3492  "NAME": value1,
3493  "AGE": value2,
3494  "SALARY": value3,
3495  "CODES": value4
3496};
3497
3498let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3499predicates.equalTo("NAME", "Lisa");
3500if (store != undefined) {
3501  (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, (err, rows) => {
3502    if (err) {
3503      console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3504      return;
3505    }
3506    console.info(`Updated row count: ${rows}`);
3507  });
3508}
3509```
3510
3511### update
3512
3513update(values: ValuesBucket, predicates: RdbPredicates):Promise&lt;number&gt;
3514
3515根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3516
3517**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3518
3519**参数:**
3520
3521| 参数名       | 类型                                 | 必填 | 说明                                                         |
3522| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
3523| values       | [ValuesBucket](#valuesbucket)        | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3524| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的更新条件。                    |
3525
3526**返回值**:
3527
3528| 类型                  | 说明                                      |
3529| --------------------- | ----------------------------------------- |
3530| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |
3531
3532**错误码:**
3533
3534以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3535
3536| **错误码ID** | **错误信息**                                                 |
3537|-----------| ------------------------------------------------------------ |
3538| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3539| 14800000  | Inner error. |
3540| 14800011  | Database corrupted. |
3541| 14800014  | Already closed. |
3542| 14800015  | The database does not respond. |
3543| 14800021  | SQLite: Generic error. |
3544| 14800022  | SQLite: Callback routine requested an abort. |
3545| 14800023  | SQLite: Access permission denied. |
3546| 14800024  | SQLite: The database file is locked. |
3547| 14800025  | SQLite: A table in the database is locked. |
3548| 14800026  | SQLite: The database is out of memory. |
3549| 14800027  | SQLite: Attempt to write a readonly database. |
3550| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3551| 14800029  | SQLite: The database is full. |
3552| 14800030  | SQLite: Unable to open the database file. |
3553| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3554| 14800032  | SQLite: Abort due to constraint violation. |
3555| 14800033  | SQLite: Data type mismatch. |
3556| 14800034  | SQLite: Library used incorrectly. |
3557| 14800047  | The WAL file size exceeds the default limit. |
3558
3559**示例:**
3560
3561```ts
3562import { BusinessError } from '@kit.BasicServicesKit';
3563
3564let value1 = "Rose";
3565let value2 = 22;
3566let value3 = 200.5;
3567let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3568
3569// 以下三种方式可用
3570const valueBucket1: relationalStore.ValuesBucket = {
3571  'NAME': value1,
3572  'AGE': value2,
3573  'SALARY': value3,
3574  'CODES': value4
3575};
3576const valueBucket2: relationalStore.ValuesBucket = {
3577  NAME: value1,
3578  AGE: value2,
3579  SALARY: value3,
3580  CODES: value4
3581};
3582const valueBucket3: relationalStore.ValuesBucket = {
3583  "NAME": value1,
3584  "AGE": value2,
3585  "SALARY": value3,
3586  "CODES": value4
3587};
3588
3589let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3590predicates.equalTo("NAME", "Lisa");
3591if (store != undefined) {
3592  (store as relationalStore.RdbStore).update(valueBucket1, predicates).then(async (rows: Number) => {
3593    console.info(`Updated row count: ${rows}`);
3594  }).catch((err: BusinessError) => {
3595    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3596  });
3597}
3598```
3599
3600### update<sup>10+</sup>
3601
3602update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution):Promise&lt;number&gt;
3603
3604根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3605
3606**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3607
3608**参数:**
3609
3610| 参数名     | 类型                                        | 必填 | 说明                                                         |
3611| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
3612| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3613| predicates | [RdbPredicates](#rdbpredicates)            | 是   | RdbPredicates的实例对象指定的更新条件。                      |
3614| conflict   | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。                                           |
3615
3616**返回值**:
3617
3618| 类型                  | 说明                                      |
3619| --------------------- | ----------------------------------------- |
3620| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |
3621
3622**错误码:**
3623
3624以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3625
3626| **错误码ID** | **错误信息**                                                 |
3627|-----------| ------------------------------------------------------------ |
3628| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3629| 14800000  | Inner error. |
3630| 14800011  | Database corrupted. |
3631| 14800014  | Already closed. |
3632| 14800015  | The database does not respond. |
3633| 14800021  | SQLite: Generic error. |
3634| 14800022  | SQLite: Callback routine requested an abort. |
3635| 14800023  | SQLite: Access permission denied. |
3636| 14800024  | SQLite: The database file is locked. |
3637| 14800025  | SQLite: A table in the database is locked. |
3638| 14800026  | SQLite: The database is out of memory. |
3639| 14800027  | SQLite: Attempt to write a readonly database. |
3640| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3641| 14800029  | SQLite: The database is full. |
3642| 14800030  | SQLite: Unable to open the database file. |
3643| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3644| 14800032  | SQLite: Abort due to constraint violation. |
3645| 14800033  | SQLite: Data type mismatch. |
3646| 14800034  | SQLite: Library used incorrectly. |
3647| 14800047  | The WAL file size exceeds the default limit. |
3648
3649**示例:**
3650
3651```ts
3652import { BusinessError } from '@kit.BasicServicesKit';
3653
3654let value1 = "Rose";
3655let value2 = 22;
3656let value3 = 200.5;
3657let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3658
3659// 以下三种方式可用
3660const valueBucket1: relationalStore.ValuesBucket = {
3661  'NAME': value1,
3662  'AGE': value2,
3663  'SALARY': value3,
3664  'CODES': value4
3665};
3666const valueBucket2: relationalStore.ValuesBucket = {
3667  NAME: value1,
3668  AGE: value2,
3669  SALARY: value3,
3670  CODES: value4
3671};
3672const valueBucket3: relationalStore.ValuesBucket = {
3673  "NAME": value1,
3674  "AGE": value2,
3675  "SALARY": value3,
3676  "CODES": value4
3677};
3678
3679let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3680predicates.equalTo("NAME", "Lisa");
3681if (store != undefined) {
3682  (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => {
3683    console.info(`Updated row count: ${rows}`);
3684  }).catch((err: BusinessError) => {
3685    console.error(`Updated failed, code is ${err.code},message is ${err.message}`);
3686  });
3687}
3688```
3689
3690### updateSync<sup>12+</sup>
3691
3692updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution):number
3693
3694根据RdbPredicates的指定实例对象更新数据库中的数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3695
3696**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3697
3698**参数:**
3699
3700| 参数名     | 类型                                        | 必填 | 说明                                                         |
3701| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
3702| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
3703| predicates | [RdbPredicates](#rdbpredicates)             | 是   | RdbPredicates的实例对象指定的更新条件。                      |
3704| conflict   | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
3705
3706**返回值**:
3707
3708| 类型   | 说明               |
3709| ------ | ------------------ |
3710| number | 返回受影响的行数。 |
3711
3712**错误码:**
3713
3714以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3715
3716| **错误码ID** | **错误信息**                                                 |
3717| ------------ | ------------------------------------------------------------ |
3718| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3719| 14800000     | Inner error.                                                 |
3720| 14800011     | Database corrupted.                                          |
3721| 14800014     | Already closed.                                              |
3722| 14800015     | The database does not respond.                                        |
3723| 14800021     | SQLite: Generic error.                                       |
3724| 14800022     | SQLite: Callback routine requested an abort.                 |
3725| 14800023     | SQLite: Access permission denied.                            |
3726| 14800024     | SQLite: The database file is locked.                         |
3727| 14800025     | SQLite: A table in the database is locked.                   |
3728| 14800026     | SQLite: The database is out of memory.                       |
3729| 14800027     | SQLite: Attempt to write a readonly database.                |
3730| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
3731| 14800029     | SQLite: The database is full.                                |
3732| 14800030     | SQLite: Unable to open the database file.                    |
3733| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
3734| 14800032     | SQLite: Abort due to constraint violation.                   |
3735| 14800033     | SQLite: Data type mismatch.                                  |
3736| 14800034     | SQLite: Library used incorrectly.                            |
3737| 14800047     | The WAL file size exceeds the default limit.                 |
3738
3739**示例:**
3740
3741```ts
3742import { BusinessError } from '@kit.BasicServicesKit';
3743
3744let value1 = "Rose";
3745let value2 = 22;
3746let value3 = 200.5;
3747let value4 = new Uint8Array([1, 2, 3, 4, 5]);
3748
3749// 以下三种方式可用
3750const valueBucket1: relationalStore.ValuesBucket = {
3751  'NAME': value1,
3752  'AGE': value2,
3753  'SALARY': value3,
3754  'CODES': value4
3755};
3756const valueBucket2: relationalStore.ValuesBucket = {
3757  NAME: value1,
3758  AGE: value2,
3759  SALARY: value3,
3760  CODES: value4
3761};
3762const valueBucket3: relationalStore.ValuesBucket = {
3763  "NAME": value1,
3764  "AGE": value2,
3765  "SALARY": value3,
3766  "CODES": value4
3767};
3768
3769let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3770predicates.equalTo("NAME", "Lisa");
3771if (store != undefined) {
3772  try {
3773    let rows: Number = (store as relationalStore.RdbStore).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
3774    console.info(`Updated row count: ${rows}`);
3775  } catch (error) {
3776    console.error(`Updated failed, code is ${error.code},message is ${error.message}`);
3777  }
3778}
3779```
3780
3781### delete
3782
3783delete(predicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void
3784
3785根据RdbPredicates的指定实例对象从数据库中删除数据,使用callback异步回调。
3786
3787**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3788
3789**参数:**
3790
3791| 参数名     | 类型                                 | 必填 | 说明                                      |
3792| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
3793| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
3794| callback   | AsyncCallback&lt;number&gt;          | 是   | 指定callback回调函数。返回受影响的行数量。 |
3795
3796**错误码:**
3797
3798以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3799
3800| **错误码ID** | **错误信息**                                                 |
3801|-----------| ------------------------------------------------------------ |
3802| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3803| 14800000  | Inner error. |
3804| 14800011  | Database corrupted. |
3805| 14800014  | Already closed. |
3806| 14800015  | The database does not respond. |
3807| 14800021  | SQLite: Generic error. |
3808| 14800022  | SQLite: Callback routine requested an abort. |
3809| 14800023  | SQLite: Access permission denied. |
3810| 14800024  | SQLite: The database file is locked. |
3811| 14800025  | SQLite: A table in the database is locked. |
3812| 14800026  | SQLite: The database is out of memory. |
3813| 14800027  | SQLite: Attempt to write a readonly database. |
3814| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3815| 14800029  | SQLite: The database is full. |
3816| 14800030  | SQLite: Unable to open the database file. |
3817| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3818| 14800032  | SQLite: Abort due to constraint violation. |
3819| 14800033  | SQLite: Data type mismatch. |
3820| 14800034  | SQLite: Library used incorrectly. |
3821| 14800047  | The WAL file size exceeds the default limit. |
3822
3823**示例:**
3824
3825```ts
3826let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3827predicates.equalTo("NAME", "Lisa");
3828if (store != undefined) {
3829  (store as relationalStore.RdbStore).delete(predicates, (err, rows) => {
3830    if (err) {
3831      console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
3832      return;
3833    }
3834    console.info(`Delete rows: ${rows}`);
3835  });
3836}
3837```
3838
3839### delete
3840
3841delete(predicates: RdbPredicates):Promise&lt;number&gt;
3842
3843根据RdbPredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。
3844
3845**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3846
3847**参数:**
3848
3849| 参数名     | 类型                                 | 必填 | 说明                                      |
3850| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
3851| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
3852
3853**返回值**:
3854
3855| 类型                  | 说明                            |
3856| --------------------- | ------------------------------- |
3857| Promise&lt;number&gt; | Promise对象。返回受影响的行数量。|
3858
3859**错误码:**
3860
3861以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3862
3863| **错误码ID** | **错误信息**                                                 |
3864|-----------| ------------------------------------------------------------ |
3865| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3866| 14800000  | Inner error. |
3867| 14800011  | Database corrupted. |
3868| 14800014  | Already closed. |
3869| 14800015  | The database does not respond. |
3870| 14800021  | SQLite: Generic error. |
3871| 14800022  | SQLite: Callback routine requested an abort. |
3872| 14800023  | SQLite: Access permission denied. |
3873| 14800024  | SQLite: The database file is locked. |
3874| 14800025  | SQLite: A table in the database is locked. |
3875| 14800026  | SQLite: The database is out of memory. |
3876| 14800027  | SQLite: Attempt to write a readonly database. |
3877| 14800028  | SQLite: Some kind of disk I/O error occurred. |
3878| 14800029  | SQLite: The database is full. |
3879| 14800030  | SQLite: Unable to open the database file. |
3880| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
3881| 14800032  | SQLite: Abort due to constraint violation. |
3882| 14800033  | SQLite: Data type mismatch. |
3883| 14800034  | SQLite: Library used incorrectly. |
3884| 14800047  | The WAL file size exceeds the default limit. |
3885
3886**示例:**
3887
3888```ts
3889import { BusinessError } from '@kit.BasicServicesKit';
3890
3891let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3892predicates.equalTo("NAME", "Lisa");
3893if (store != undefined) {
3894  (store as relationalStore.RdbStore).delete(predicates).then((rows: Number) => {
3895    console.info(`Delete rows: ${rows}`);
3896  }).catch((err: BusinessError) => {
3897    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
3898  });
3899}
3900```
3901
3902### deleteSync<sup>12+</sup>
3903
3904deleteSync(predicates: RdbPredicates):number
3905
3906根据RdbPredicates的指定实例对象从数据库中删除数据。
3907
3908**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3909
3910**参数:**
3911
3912| 参数名     | 类型                            | 必填 | 说明                                    |
3913| ---------- | ------------------------------- | ---- | --------------------------------------- |
3914| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
3915
3916**返回值**:
3917
3918| 类型   | 说明               |
3919| ------ | ------------------ |
3920| number | 返回受影响的行数量。|
3921
3922**错误码:**
3923
3924以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
3925
3926| **错误码ID** | **错误信息**                                                 |
3927| ------------ | ------------------------------------------------------------ |
3928| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3929| 14800000     | Inner error.                                                 |
3930| 14800011     | Database corrupted.                                          |
3931| 14800014     | Already closed.                                              |
3932| 14800015     | The database does not respond.                                        |
3933| 14800021     | SQLite: Generic error.                                       |
3934| 14800022     | SQLite: Callback routine requested an abort.                 |
3935| 14800023     | SQLite: Access permission denied.                            |
3936| 14800024     | SQLite: The database file is locked.                         |
3937| 14800025     | SQLite: A table in the database is locked.                   |
3938| 14800026     | SQLite: The database is out of memory.                       |
3939| 14800027     | SQLite: Attempt to write a readonly database.                |
3940| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
3941| 14800029     | SQLite: The database is full.                                |
3942| 14800030     | SQLite: Unable to open the database file.                    |
3943| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
3944| 14800032     | SQLite: Abort due to constraint violation.                   |
3945| 14800033     | SQLite: Data type mismatch.                                  |
3946| 14800034     | SQLite: Library used incorrectly.                            |
3947| 14800047     | The WAL file size exceeds the default limit.                 |
3948
3949**示例:**
3950
3951```ts
3952import { BusinessError } from '@kit.BasicServicesKit';
3953
3954let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3955predicates.equalTo("NAME", "Lisa");
3956if (store != undefined) {
3957  try {
3958    let rows: Number = (store as relationalStore.RdbStore).deleteSync(predicates);
3959    console.info(`Delete rows: ${rows}`);
3960  } catch (err) {
3961    console.error(`Delete failed, code is ${err.code},message is ${err.message}`);
3962  }
3963}
3964```
3965
3966### query<sup>10+</sup>
3967
3968query(predicates: RdbPredicates, callback: AsyncCallback&lt;ResultSet&gt;):void
3969
3970根据指定条件查询数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
3971
3972**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
3973
3974**参数:**
3975
3976| 参数名     | 类型                                                         | 必填 | 说明                                                        |
3977| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
3978| predicates | [RdbPredicates](#rdbpredicates)                         | 是   | RdbPredicates的实例对象指定的查询条件。                   |
3979| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
3980
3981**错误码:**
3982
3983以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
3984
3985| **错误码ID** | **错误信息**                                                 |
3986|-----------| ------------------------------------------------------------ |
3987| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3988| 14800000  | Inner error. |
3989| 14800014  | Already closed. |
3990| 14800015  | The database does not respond. |
3991
3992**示例:**
3993
3994```ts
3995let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
3996predicates.equalTo("NAME", "Rose");
3997if (store != undefined) {
3998  (store as relationalStore.RdbStore).query(predicates, async (err, resultSet) => {
3999    if (err) {
4000      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4001      return;
4002    }
4003    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4004    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4005    while (resultSet.goToNextRow()) {
4006      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4007      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4008      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4009      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4010      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4011    }
4012    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4013    resultSet.close();
4014  });
4015}
4016```
4017
4018### query
4019
4020query(predicates: RdbPredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
4021
4022根据指定条件查询数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
4023
4024**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4025
4026**参数:**
4027
4028| 参数名     | 类型                                                         | 必填 | 说明                                                        |
4029| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
4030| predicates | [RdbPredicates](#rdbpredicates)                         | 是   | RdbPredicates的实例对象指定的查询条件。                   |
4031| columns    | Array&lt;string&gt;                                          | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。            |
4032| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
4033
4034**错误码:**
4035
4036以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4037
4038| **错误码ID** | **错误信息**                                                 |
4039|-----------| ------------------------------------------------------------ |
4040| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4041| 14800000  | Inner error. |
4042| 14800014  | Already closed. |
4043| 14800015  | The database does not respond. |
4044
4045**示例:**
4046
4047```ts
4048let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
4049predicates.equalTo("NAME", "Rose");
4050if (store != undefined) {
4051  (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], async (err, resultSet) => {
4052    if (err) {
4053      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4054      return;
4055    }
4056    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4057    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4058    while (resultSet.goToNextRow()) {
4059      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4060      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4061      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4062      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4063      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4064    }
4065    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4066    resultSet.close();
4067  });
4068}
4069```
4070
4071### query
4072
4073query(predicates: RdbPredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
4074
4075根据指定条件查询数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
4076
4077**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4078
4079**参数:**
4080
4081| 参数名     | 类型                                 | 必填 | 说明                                             |
4082| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
4083| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。        |
4084| columns    | Array&lt;string&gt;                  | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
4085
4086**错误码:**
4087
4088以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4089
4090| **错误码ID** | **错误信息**                                                 |
4091|-----------| ------------------------------------------------------------ |
4092| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4093| 14800000  | Inner error. |
4094| 14800014  | Already closed. |
4095| 14800015  | The database does not respond. |
4096
4097**返回值**:
4098
4099| 类型                                                    | 说明                                               |
4100| ------------------------------------------------------- | -------------------------------------------------- |
4101| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
4102
4103**示例:**
4104
4105```ts
4106import { BusinessError } from '@kit.BasicServicesKit';
4107
4108let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
4109predicates.equalTo("NAME", "Rose");
4110if (store != undefined) {
4111  (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then(async (resultSet: relationalStore.ResultSet) => {
4112    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4113    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4114    while (resultSet.goToNextRow()) {
4115      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4116      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4117      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4118      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4119      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4120    }
4121    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4122    resultSet.close();
4123  }).catch((err: BusinessError) => {
4124    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4125  });
4126}
4127```
4128
4129### querySync<sup>12+</sup>
4130
4131querySync(predicates: RdbPredicates, columns?: Array&lt;string&gt;):ResultSet
4132
4133根据指定条件查询数据库中的数据。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
4134
4135**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4136
4137**参数:**
4138
4139| 参数名     | 类型                            | 必填 | 说明                                                         |
4140| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ |
4141| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。                      |
4142| columns    | Array&lt;string&gt;             | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。默认值为空。 |
4143
4144**错误码:**
4145
4146以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4147
4148| **错误码ID** | **错误信息**                                                 |
4149| ------------ | ------------------------------------------------------------ |
4150| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4151| 14800000     | Inner error.                                                 |
4152| 14800014     | Already closed.                                              |
4153| 14800015     | The database does not respond.                                        |
4154
4155**返回值**:
4156
4157| 类型                    | 说明                                |
4158| ----------------------- | ----------------------------------- |
4159| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
4160
4161**示例:**
4162
4163```ts
4164import { BusinessError } from '@kit.BasicServicesKit';
4165
4166let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
4167predicates.equalTo("NAME", "Rose");
4168if (store != undefined) {
4169  try {
4170    let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
4171    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4172    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4173    while (resultSet.goToNextRow()) {
4174      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4175      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4176      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4177      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4178      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4179    }
4180    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4181    resultSet.close();
4182  } catch (err) {
4183    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4184  }
4185}
4186```
4187
4188### remoteQuery
4189
4190remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt; , callback: AsyncCallback&lt;ResultSet&gt;): void
4191
4192根据指定条件查询远程设备数据库中的数据。使用callback异步回调。
4193
4194> **说明:**
4195>
4196> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
4197
4198**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4199
4200**参数:**
4201
4202| 参数名     | 类型                                         | 必填 | 说明                                                      |
4203| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- |
4204| device     | string                                       | 是   | 指定的远程设备ID。                                        |
4205| table      | string                                       | 是   | 指定的目标表名。                                          |
4206| predicates | [RdbPredicates](#rdbpredicates)              | 是   | RdbPredicates的实例对象,指定查询的条件。                 |
4207| columns    | Array&lt;string&gt;                          | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。          |
4208| callback   | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
4209
4210**错误码:**
4211
4212以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4213
4214| **错误码ID** | **错误信息**                                                 |
4215|-----------| ------------------------------------------------------------ |
4216| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4217| 801       | Capability not supported. |
4218| 14800000  | Inner error. |
4219| 14800014  | Already closed. |
4220
4221**示例:**
4222
4223```ts
4224import { distributedDeviceManager } from '@kit.DistributedServiceKit';
4225import { BusinessError } from '@kit.BasicServicesKit';
4226
4227let dmInstance: distributedDeviceManager.DeviceManager;
4228let deviceId: string | undefined = undefined;
4229
4230try {
4231  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
4232  let devices = dmInstance.getAvailableDeviceListSync();
4233  if (deviceId != undefined) {
4234    deviceId = devices[0].networkId;
4235  }
4236} catch (err) {
4237  let code = (err as BusinessError).code;
4238  let message = (err as BusinessError).message;
4239  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
4240}
4241
4242let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
4243predicates.greaterThan("id", 0);
4244if (store != undefined && deviceId != undefined) {
4245  (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then(async (resultSet: relationalStore.ResultSet) => {
4246    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4247    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4248    while (resultSet.goToNextRow()) {
4249      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4250      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4251      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4252      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4253      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4254    }
4255    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4256    resultSet.close();
4257  }).catch((err: BusinessError) => {
4258    console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
4259  });
4260}
4261```
4262
4263### remoteQuery
4264
4265remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array&lt;string&gt;): Promise&lt;ResultSet&gt;
4266
4267根据指定条件查询远程设备数据库中的数据。使用Promise异步回调。
4268
4269> **说明:**
4270>
4271> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
4272
4273**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4274
4275**参数:**
4276
4277| 参数名     | 类型                                 | 必填 | 说明                                             |
4278| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
4279| device     | string                               | 是   | 指定的远程设备ID。                   |
4280| table      | string                               | 是   | 指定的目标表名。                                 |
4281| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象,指定查询的条件。      |
4282| columns    | Array&lt;string&gt;                  | 是   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
4283
4284**返回值**:
4285
4286| 类型                                                         | 说明                                               |
4287| ------------------------------------------------------------ | -------------------------------------------------- |
4288| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
4289
4290**错误码:**
4291
4292以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4293
4294| **错误码ID** | **错误信息**                                                 |
4295|-----------| ------------------------------------------------------------ |
4296| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4297| 801       | Capability not supported. |
4298| 14800000  | Inner error. |
4299| 14800014  | Already closed. |
4300
4301**示例:**
4302
4303```ts
4304import { distributedDeviceManager } from '@kit.DistributedServiceKit';
4305import { BusinessError } from '@kit.BasicServicesKit';
4306
4307let dmInstance: distributedDeviceManager.DeviceManager;
4308let deviceId: string | undefined = undefined;
4309
4310try {
4311  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
4312  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
4313  if (devices != undefined) {
4314    deviceId = devices[0].networkId;
4315  }
4316} catch (err) {
4317  let code = (err as BusinessError).code;
4318  let message = (err as BusinessError).message;
4319  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
4320}
4321
4322let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
4323predicates.greaterThan("id", 0);
4324if (store != undefined && deviceId != undefined) {
4325  (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then(async (resultSet: relationalStore.ResultSet) => {
4326    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4327    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4328    while (resultSet.goToNextRow()) {
4329      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4330      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4331      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4332      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4333      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4334    }
4335    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4336    resultSet.close();
4337  }).catch((err: BusinessError) => {
4338    console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`);
4339  });
4340}
4341```
4342
4343### querySql<sup>10+</sup>
4344
4345querySql(sql: string, callback: AsyncCallback&lt;ResultSet&gt;):void
4346
4347根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
4348
4349[向量数据库](#storeconfig)当前支持的标准语法有where、limit、offset、order by、group by以及having;扩展语法有<->(计算相似度)和<=>(计算余弦距离),支持在聚合函数(max、min)中使用,不支持在聚合函数(sum、avg、count)和基础函数(random、abs、upper、lower、length)中使用。
4350
4351聚合函数不支持嵌套使用。
4352
4353**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4354
4355**参数:**
4356
4357| 参数名   | 类型                                         | 必填 | 说明                                    |
4358| -------- | -------------------------------------------- | ---- |---------------------------------------|
4359| sql      | string                                       | 是   | 指定要执行的SQL语句。                          |
4360| callback | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 |
4361
4362**错误码:**
4363
4364以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4365
4366| **错误码ID** | **错误信息**                                                 |
4367|-----------| ------------------------------------------------------------ |
4368| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4369| 14800000  | Inner error. |
4370| 14800014  | Already closed. |
4371| 14800015  | The database does not respond. |
4372
4373**示例:**
4374
4375关系型数据库:
4376
4377```ts
4378if (store != undefined) {
4379  (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'", async (err, resultSet) => {
4380    if (err) {
4381      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4382      return;
4383    }
4384    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4385    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4386    while (resultSet.goToNextRow()) {
4387      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4388      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4389      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4390      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4391      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4392    }
4393    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4394    resultSet.close();
4395  });
4396}
4397```
4398
4399向量数据库:
4400
4401```ts
4402// 相似度的计算符号是<->,余弦距离的计算符号是<=>
4403const querySql = "select id, repr <-> '[1.5,5.6]' as distance from test ORDER BY repr <-> '[1.5,5.6]' limit 10 offset 1;";
4404let resultSet = await store.querySql(querySql);
4405
4406// 聚合查询,其中group by支持多列
4407const querySql1 = "select id, repr from test group by id, repr having max(repr<=>'[1.5,5.6]');";
4408let resultSet1 = await store.querySql(querySql1);
4409
4410// 子查询,最大支持嵌套32层
4411const querySql2 = "select * from test where id in (select id from test1)";
4412let resultSet2 = await store.querySql(querySql2);
4413```
4414
4415### querySql
4416
4417querySql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void
4418
4419根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
4420
4421[向量数据库](#storeconfig)当前支持的标准语法有where、limit、offset、order by、group by以及having;扩展语法有<->(计算相似度)和<=>(计算余弦距离),支持在聚合函数(max、min)中使用,不支持在聚合函数(sum、avg、count)和基础函数(random、abs、upper、lower、length)中使用。
4422
4423聚合函数不支持嵌套使用。
4424
4425**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4426
4427**参数:**
4428
4429| 参数名   | 类型                                         | 必填 | 说明                                                         |
4430| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
4431| sql      | string                                       | 是   | 指定要执行的SQL语句。                                        |
4432| bindArgs | Array&lt;[ValueType](#valuetype)&gt;         | 是   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数需为空数组。 |
4433| callback | AsyncCallback&lt;[ResultSet](#resultset)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ResultSet对象。    |
4434
4435**错误码:**
4436
4437以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4438
4439| **错误码ID** | **错误信息**                                                 |
4440|-----------| ------------------------------------------------------------ |
4441| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4442| 14800000  | Inner error. |
4443| 14800014  | Already closed. |
4444| 14800015  | The database does not respond. |
4445
4446**示例:**
4447
4448```ts
4449if (store != undefined) {
4450  (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], async (err, resultSet) => {
4451    if (err) {
4452      console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4453      return;
4454    }
4455    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4456    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4457    while (resultSet.goToNextRow()) {
4458      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4459      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4460      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4461      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4462      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4463    }
4464    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4465    resultSet.close();
4466  });
4467}
4468```
4469
4470### querySql
4471
4472querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt;
4473
4474根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
4475
4476[向量数据库](#storeconfig)当前支持的标准语法有where、limit、offset、order by、group by以及having;扩展语法有<->(计算相似度)和<=>(计算余弦距离),支持在聚合函数(max、min)中使用,不支持在聚合函数(sum、avg、count)和基础函数(random、abs、upper、lower、length)中使用。
4477
4478聚合函数不支持嵌套使用。
4479
4480**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4481
4482**参数:**
4483
4484| 参数名   | 类型                                 | 必填 | 说明                                                         |
4485| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4486| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4487| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
4488
4489**返回值**:
4490
4491| 类型                                                    | 说明                                               |
4492| ------------------------------------------------------- | -------------------------------------------------- |
4493| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
4494
4495**错误码:**
4496
4497以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4498
4499| **错误码ID** | **错误信息**                                                 |
4500|-----------| ------------------------------------------------------------ |
4501| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4502| 14800000  | Inner error. |
4503| 14800014  | Already closed. |
4504| 14800015  | The database does not respond. |
4505
4506**示例:**
4507
4508关系型数据库:
4509
4510```ts
4511import { BusinessError } from '@kit.BasicServicesKit';
4512
4513if (store != undefined) {
4514  (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then(async (resultSet: relationalStore.ResultSet) => {
4515    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4516    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4517    while (resultSet.goToNextRow()) {
4518      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4519      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4520      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4521      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4522      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4523    }
4524    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4525    resultSet.close();
4526  }).catch((err: BusinessError) => {
4527    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4528  });
4529}
4530```
4531
4532向量数据库:
4533
4534```ts
4535// 查询id为1,与[1.5, 2.5]相似度小于0.5,且以相似度进行升序排序的前10条数据
4536const querySql = "select id, repr <-> ? as distance from test where id = ? and repr <-> ? < 0.5 ORDER BY repr <-> ? limit 10;";
4537const vectorValue: Float32Array = new Float32Array([1.5, 2.5]);
4538let resultSet = await store.querySql(querySql, [vectorValue, 1, vectorValue, vectorValue]);
4539```
4540
4541### querySqlSync<sup>12+</sup>
4542
4543querySqlSync(sql: string, bindArgs?: Array&lt;ValueType&gt;):ResultSet
4544
4545根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
4546
4547**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4548
4549**参数:**
4550
4551| 参数名   | 类型                                 | 必填 | 说明                                                         |
4552| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4553| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4554| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。默认值为空。 |
4555
4556**返回值**:
4557
4558| 类型                    | 说明                                |
4559| ----------------------- | ----------------------------------- |
4560| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
4561
4562**错误码:**
4563
4564以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
4565
4566| **错误码ID** | **错误信息**                                                 |
4567| ------------ | ------------------------------------------------------------ |
4568| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4569| 14800000     | Inner error.                                                 |
4570| 14800014     | Already closed.                                              |
4571| 14800015     | The database does not respond.                                        |
4572
4573**示例:**
4574
4575```ts
4576import { BusinessError } from '@kit.BasicServicesKit';
4577
4578if (store != undefined) {
4579  try {
4580    let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'");
4581    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
4582    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
4583    while (resultSet.goToNextRow()) {
4584      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
4585      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
4586      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
4587      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
4588      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
4589    }
4590    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
4591    resultSet.close();
4592  } catch (err) {
4593    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
4594  }
4595}
4596```
4597
4598### executeSql<sup>10+</sup>
4599
4600executeSql(sql: string, callback: AsyncCallback&lt;void&gt;):void
4601
4602执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
4603
4604此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4605
4606不支持分号分隔的多条语句。
4607
4608**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4609
4610**参数:**
4611
4612| 参数名   | 类型                                 | 必填 | 说明                                                         |
4613| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4614| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4615| callback | AsyncCallback&lt;void&gt;            | 是   | 指定callback回调函数。                                       |
4616
4617**错误码:**
4618
4619以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4620
4621| **错误码ID** | **错误信息**                                                 |
4622|-----------| ------------------------------------------------------------ |
4623| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4624| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4625| 14800000  | Inner error. |
4626| 14800011  | Database corrupted. |
4627| 14800014  | Already closed. |
4628| 14800015  | The database does not respond. |
4629| 14800021  | SQLite: Generic error. |
4630| 14800022  | SQLite: Callback routine requested an abort. |
4631| 14800023  | SQLite: Access permission denied. |
4632| 14800024  | SQLite: The database file is locked. |
4633| 14800025  | SQLite: A table in the database is locked. |
4634| 14800026  | SQLite: The database is out of memory. |
4635| 14800027  | SQLite: Attempt to write a readonly database. |
4636| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4637| 14800029  | SQLite: The database is full. |
4638| 14800030  | SQLite: Unable to open the database file. |
4639| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4640| 14800032  | SQLite: Abort due to constraint violation. |
4641| 14800033  | SQLite: Data type mismatch. |
4642| 14800034  | SQLite: Library used incorrectly. |
4643| 14800047  | The WAL file size exceeds the default limit. |
4644
4645**示例:**
4646
4647```ts
4648const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'";
4649if (store != undefined) {
4650  (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, (err) => {
4651    if (err) {
4652      console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
4653      return;
4654    }
4655    console.info('Delete table done.');
4656  });
4657}
4658```
4659
4660### executeSql
4661
4662executeSql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;void&gt;):void
4663
4664执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。
4665
4666此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4667
4668不支持分号分隔的多条语句。
4669
4670**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4671
4672**参数:**
4673
4674| 参数名   | 类型                                 | 必填 | 说明                                                         |
4675| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4676| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4677| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 是   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数需为空数组。 |
4678| callback | AsyncCallback&lt;void&gt;            | 是   | 指定callback回调函数。                                       |
4679
4680**错误码:**
4681
4682以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4683
4684| **错误码ID** | **错误信息**                                                 |
4685|-----------| ------------------------------------------------------------ |
4686| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4687| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4688| 14800000  | Inner error. |
4689| 14800011  | Database corrupted. |
4690| 14800014  | Already closed. |
4691| 14800015  | The database does not respond. |
4692| 14800021  | SQLite: Generic error. |
4693| 14800022  | SQLite: Callback routine requested an abort. |
4694| 14800023  | SQLite: Access permission denied. |
4695| 14800024  | SQLite: The database file is locked. |
4696| 14800025  | SQLite: A table in the database is locked. |
4697| 14800026  | SQLite: The database is out of memory. |
4698| 14800027  | SQLite: Attempt to write a readonly database. |
4699| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4700| 14800029  | SQLite: The database is full. |
4701| 14800030  | SQLite: Unable to open the database file. |
4702| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4703| 14800032  | SQLite: Abort due to constraint violation. |
4704| 14800033  | SQLite: Data type mismatch. |
4705| 14800034  | SQLite: Library used incorrectly. |
4706| 14800047  | The WAL file size exceeds the default limit. |
4707
4708**示例:**
4709
4710```ts
4711const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?";
4712if (store != undefined) {
4713  (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, ['zhangsan'], (err) => {
4714    if (err) {
4715      console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
4716      return;
4717    }
4718    console.info('Delete table done.');
4719  });
4720}
4721```
4722
4723### executeSql
4724
4725executeSql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;void&gt;
4726
4727执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
4728
4729此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4730
4731不支持分号分隔的多条语句。
4732
4733**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4734
4735**参数:**
4736
4737| 参数名   | 类型                                 | 必填 | 说明                                                         |
4738| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4739| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4740| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
4741
4742**返回值**:
4743
4744| 类型                | 说明                      |
4745| ------------------- | ------------------------- |
4746| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
4747
4748**错误码:**
4749
4750以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4751
4752| **错误码ID** | **错误信息**                                                 |
4753|-----------| ------------------------------------------------------------ |
4754| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4755| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4756| 14800000  | Inner error. |
4757| 14800011  | Database corrupted. |
4758| 14800014  | Already closed. |
4759| 14800015  | The database does not respond. |
4760| 14800021  | SQLite: Generic error. |
4761| 14800022  | SQLite: Callback routine requested an abort. |
4762| 14800023  | SQLite: Access permission denied. |
4763| 14800024  | SQLite: The database file is locked. |
4764| 14800025  | SQLite: A table in the database is locked. |
4765| 14800026  | SQLite: The database is out of memory. |
4766| 14800027  | SQLite: Attempt to write a readonly database. |
4767| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4768| 14800029  | SQLite: The database is full. |
4769| 14800030  | SQLite: Unable to open the database file. |
4770| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4771| 14800032  | SQLite: Abort due to constraint violation. |
4772| 14800033  | SQLite: Data type mismatch. |
4773| 14800034  | SQLite: Library used incorrectly. |
4774| 14800047  | The WAL file size exceeds the default limit. |
4775
4776**示例:**
4777
4778```ts
4779import { BusinessError } from '@kit.BasicServicesKit';
4780
4781const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'";
4782if (store != undefined) {
4783  (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE).then(() => {
4784    console.info('Delete table done.');
4785  }).catch((err: BusinessError) => {
4786    console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
4787  });
4788}
4789```
4790
4791### execute<sup>12+</sup>
4792
4793execute(sql: string, args?: Array&lt;ValueType&gt;):Promise&lt;ValueType&gt;
4794
4795执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType,使用Promise异步回调。
4796
4797该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
4798
4799此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4800
4801向量数据库使用该接口执行插入操作,数据来源于子查询时,支持全字段插入,暂不支持部分字段插入。
4802
4803不支持分号分隔的多条语句。
4804
4805**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4806
4807**参数:**
4808
4809| 参数名   | 类型                                 | 必填 | 说明                                                         |
4810| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4811| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4812| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
4813
4814**返回值**:
4815
4816| 类型                | 说明                      |
4817| ------------------- | ------------------------- |
4818| Promise&lt;[ValueType](#valuetype)&gt; | Promise对象,返回sql执行后的结果。 |
4819
4820**错误码:**
4821
4822以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4823
4824| **错误码ID** | **错误信息**                                                 |
4825|-----------| ------------------------------------------------------------ |
4826| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4827| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4828| 14800000  | Inner error. |
4829| 14800011  | Database corrupted. |
4830| 14800014  | Already closed. |
4831| 14800015  | The database does not respond. |
4832| 14800021  | SQLite: Generic error. |
4833| 14800022  | SQLite: Callback routine requested an abort. |
4834| 14800023  | SQLite: Access permission denied. |
4835| 14800024  | SQLite: The database file is locked. |
4836| 14800025  | SQLite: A table in the database is locked. |
4837| 14800026  | SQLite: The database is out of memory. |
4838| 14800027  | SQLite: Attempt to write a readonly database. |
4839| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4840| 14800029  | SQLite: The database is full. |
4841| 14800030  | SQLite: Unable to open the database file. |
4842| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4843| 14800032  | SQLite: Abort due to constraint violation. |
4844| 14800033  | SQLite: Data type mismatch. |
4845| 14800034  | SQLite: Library used incorrectly. |
4846| 14800047  | The WAL file size exceeds the default limit. |
4847
4848**示例:**
4849
4850关系型数据库:
4851
4852```ts
4853import { BusinessError } from '@kit.BasicServicesKit';
4854
4855// 校验数据库完整性
4856if (store != undefined) {
4857  const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check';
4858  (store as relationalStore.RdbStore).execute(SQL_CHECK_INTEGRITY).then((data) => {
4859    console.info(`check result: ${data}`);
4860  }).catch((err: BusinessError) => {
4861    console.error(`check failed, code is ${err.code}, message is ${err.message}`);
4862  });
4863}
4864
4865// 删除表中所有数据
4866if (store != undefined) {
4867  const SQL_DELETE_TABLE = 'DELETE FROM test';
4868  (store as relationalStore.RdbStore).execute(SQL_DELETE_TABLE).then((data) => {
4869    console.info(`delete result: ${data}`);
4870  }).catch((err: BusinessError) => {
4871    console.error(`delete failed, code is ${err.code}, message is ${err.message}`);
4872  });
4873}
4874
4875// 删表
4876if (store != undefined) {
4877  const SQL_DROP_TABLE = 'DROP TABLE test';
4878  (store as relationalStore.RdbStore).execute(SQL_DROP_TABLE).then((data) => {
4879    console.info(`drop result: ${data}`);
4880  }).catch((err: BusinessError) => {
4881    console.error(`drop failed, code is ${err.code}, message is ${err.message}`);
4882  });
4883}
4884```
4885
4886向量数据库:
4887
4888```ts
4889// FLOATVECTOR(2)是维度为2的向量属性,后续操作repr需依照该维度进行。
4890let createSql = "CREATE TABLE test (ID INTEGER PRIMARY KEY,REPR FLOATVECTOR(2));";
4891// 建表
4892await store!.execute(createSql);
4893// 使用参数绑定插入数据
4894let insertSql = "insert into test VALUES(?, ?);";
4895const vectorValue: Float32Array = Float32Array.from([1.5, 6.6]);
4896await store!.execute(insertSql, [0, vectorValue]);
4897// 不使用绑定参数直接执行
4898await store!.execute("insert into test values(1, '[3.5, 1.8]');");
4899```
4900
4901### execute<sup>12+</sup>
4902
4903execute(sql: string, txId: number, args?: Array&lt;ValueType&gt;): Promise&lt;ValueType&gt;
4904
4905执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
4906
4907该接口仅支持[向量数据库](#storeconfig)使用。使用该接口执行插入操作,数据来源于子查询时,支持全字段插入,暂不支持部分字段插入。
4908
4909此接口不支持执行查询,可以使用[querySql](#querysql10)接口代替。
4910
4911不支持分号分隔的多条语句。
4912
4913**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4914
4915**参数:**
4916
4917| 参数名   | 类型                                 | 必填 | 说明                                                         |
4918| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
4919| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
4920| txId      | number                               | 是   | 通过[beginTrans](#begintrans12)获取的事务ID,如果传0,该语句默认在单独事务内。                                      |
4921| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。该参数不填,填null或者填undefined,都认为是sql参数语句完整。 |
4922
4923**返回值**:
4924
4925| 类型                | 说明                      |
4926| ------------------- | ------------------------- |
4927| Promise&lt;[ValueType](#valuetype)&gt; | Promise对象,返回null。 |
4928
4929**错误码:**
4930
4931以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
4932
4933| **错误码ID** | **错误信息**                                                 |
4934|-----------| ------------------------------------------------------------ |
4935| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4936| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
4937| 14800000  | Inner error. |
4938| 14800011  | Database corrupted. |
4939| 14800014  | Already closed. |
4940| 14800015  | The database does not respond. |
4941| 14800021  | SQLite: Generic error. |
4942| 14800022  | SQLite: Callback routine requested an abort. |
4943| 14800023  | SQLite: Access permission denied. |
4944| 14800024  | SQLite: The database file is locked. |
4945| 14800025  | SQLite: A table in the database is locked. |
4946| 14800026  | SQLite: The database is out of memory. |
4947| 14800027  | SQLite: Attempt to write a readonly database. |
4948| 14800028  | SQLite: Some kind of disk I/O error occurred. |
4949| 14800029  | SQLite: The database is full. |
4950| 14800030  | SQLite: Unable to open the database file. |
4951| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
4952| 14800032  | SQLite: Abort due to constraint violation. |
4953| 14800033  | SQLite: Data type mismatch. |
4954| 14800034  | SQLite: Library used incorrectly. |
4955| 14800047  | The WAL file size exceeds the default limit. |
4956
4957**示例:**
4958
4959```ts
4960import { BusinessError } from '@kit.BasicServicesKit';
4961if (store != null) {
4962  let txId: number;
4963  (store as relationalStore.RdbStore).beginTrans().then((txId: number) => {
4964    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
4965      .then(() => {
4966        (store as relationalStore.RdbStore).commit(txId);
4967      })
4968      .catch((err: BusinessError) => {
4969        (store as relationalStore.RdbStore).rollback(txId);
4970        console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
4971      });
4972  });
4973}
4974```
4975
4976### executeSync<sup>12+</sup>
4977
4978executeSync(sql: string, args?: Array&lt;ValueType&gt;): ValueType
4979
4980执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType。
4981
4982该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
4983
4984此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。
4985
4986不支持分号分隔的多条语句。
4987
4988**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
4989
4990**参数:**
4991
4992| 参数名 | 类型                                 | 必填 | 说明                                                         |
4993| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
4994| sql    | string                               | 是   | 指定要执行的SQL语句。                                        |
4995| args   | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。该参数不填,或者填null或undefined,都认为是sql参数语句完整。默认值为空。 |
4996
4997**返回值**:
4998
4999| 类型                    | 说明                |
5000| ----------------------- | ------------------- |
5001| [ValueType](#valuetype) | 返回sql执行后的结果 |
5002
5003**错误码:**
5004
5005以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5006
5007| **错误码ID** | **错误信息**                                                 |
5008| ------------ | ------------------------------------------------------------ |
5009| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5010| 14800000     | Inner error.                                                 |
5011| 14800011     | Database corrupted.                                          |
5012| 14800014     | Already closed.                                              |
5013| 14800015     | The database does not respond.                               |
5014| 14800021     | SQLite: Generic error.                                       |
5015| 14800022     | SQLite: Callback routine requested an abort.                 |
5016| 14800023     | SQLite: Access permission denied.                            |
5017| 14800024     | SQLite: The database file is locked.                         |
5018| 14800025     | SQLite: A table in the database is locked.                   |
5019| 14800026     | SQLite: The database is out of memory.                       |
5020| 14800027     | SQLite: Attempt to write a readonly database.                |
5021| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
5022| 14800029     | SQLite: The database is full.                                |
5023| 14800030     | SQLite: Unable to open the database file.                    |
5024| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
5025| 14800032     | SQLite: Abort due to constraint violation.                   |
5026| 14800033     | SQLite: Data type mismatch.                                  |
5027| 14800034     | SQLite: Library used incorrectly.                            |
5028| 14800047     | The WAL file size exceeds the default limit.                 |
5029
5030**示例:**
5031
5032```ts
5033import { BusinessError } from '@kit.BasicServicesKit';
5034
5035// 校验数据库完整性
5036if (store != undefined) {
5037  const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check';
5038  try {
5039    let data = (store as relationalStore.RdbStore).executeSync(SQL_CHECK_INTEGRITY);
5040    console.info(`check result: ${data}`);
5041  } catch (err) {
5042    console.error(`check failed, code is ${err.code}, message is ${err.message}`);
5043  }
5044}
5045
5046// 删除表中所有数据
5047if (store != undefined) {
5048  const SQL_DELETE_TABLE = 'DELETE FROM test';
5049  try {
5050    let data = (store as relationalStore.RdbStore).executeSync(SQL_DELETE_TABLE);
5051    console.info(`delete result: ${data}`);
5052  } catch (err) {
5053    console.error(`delete failed, code is ${err.code}, message is ${err.message}`);
5054  }
5055}
5056
5057// 删表
5058if (store != undefined) {
5059  const SQL_DROP_TABLE = 'DROP TABLE test';
5060  try {
5061    let data = (store as relationalStore.RdbStore).executeSync(SQL_DROP_TABLE);
5062    console.info(`drop result: ${data}`);
5063  } catch (err) {
5064    console.error(`drop failed, code is ${err.code}, message is ${err.message}`);
5065  }
5066}
5067```
5068
5069### getModifyTime<sup>10+</sup>
5070
5071getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[], callback: AsyncCallback&lt;ModifyTime&gt;): void
5072
5073获取数据库表中数据的最后修改时间,使用callback异步回调。
5074
5075**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5076
5077**参数:**
5078
5079| 参数名      | 类型                                             | 必填 | 说明                                                         |
5080| ----------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
5081| table       | string                                           | 是   | 指定要查询的数据库表的表名。                                 |
5082| columnName  | string                                           | 是   | 指定要查询的数据库表的列名。                                 |
5083| primaryKeys | [PRIKeyType](#prikeytype10)[]                    | 是   | 指定要查询的行的主键。<br>如果数据库表无主键,参数columnName需传入"rowid",此时primaryKeys为要查询的数据库表的行号。<br>如果数据库表无主键,参数columnName传入不为"rowid",返回对应的错误码。 |
5084| callback    | AsyncCallback&lt;[ModifyTime](#modifytime10)&gt; | 是   | 指定callback回调函数。如果操作成功,则返回ModifyTime对象,表示数据的最后修改时间。 |
5085
5086**错误码:**
5087
5088以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5089
5090| **错误码ID** | **错误信息**                                                 |
5091|-----------| ------------------------------------------------------------ |
5092| 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. |
5093| 801       | Capability not supported. |
5094| 14800000  | Inner error. |
5095| 14800011  | Database corrupted. |
5096| 14800014  | Already closed. |
5097| 14800015  | The database does not respond. |
5098| 14800021  | SQLite: Generic error. |
5099| 14800022  | SQLite: Callback routine requested an abort. |
5100| 14800023  | SQLite: Access permission denied. |
5101| 14800024  | SQLite: The database file is locked. |
5102| 14800025  | SQLite: A table in the database is locked. |
5103| 14800026  | SQLite: The database is out of memory. |
5104| 14800027  | SQLite: Attempt to write a readonly database. |
5105| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5106| 14800029  | SQLite: The database is full. |
5107| 14800030  | SQLite: Unable to open the database file. |
5108| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5109| 14800032  | SQLite: Abort due to constraint violation. |
5110| 14800033  | SQLite: Data type mismatch. |
5111| 14800034  | SQLite: Library used incorrectly. |
5112
5113**示例:**
5114
5115```ts
5116let PRIKey = [1, 4, 2, 3];
5117if (store != undefined) {
5118  (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey, (err, modifyTime: relationalStore.ModifyTime) => {
5119    if (err) {
5120      console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`);
5121      return;
5122    }
5123    let size = modifyTime.size;
5124  });
5125}
5126```
5127
5128### getModifyTime<sup>10+</sup>
5129
5130getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[]): Promise&lt;ModifyTime&gt;
5131
5132获取数据库表中数据的最后修改时间,使用Promise异步回调。
5133
5134**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5135
5136**参数:**
5137
5138| 参数名      | 类型                          | 必填 | 说明                                                         |
5139| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ |
5140| table       | string                        | 是   | 指定要查询的数据库表的表名。                                 |
5141| columnName  | string                        | 是   | 指定要查询的数据库表的列名。                                 |
5142| primaryKeys | [PRIKeyType](#prikeytype10)[] | 是   | 指定要查询的行的主键。<br>如果数据库表无主键,参数columnName需传入"rowid",此时primaryKeys为要查询的数据库表的行号。<br>如果数据库表无主键,参数columnName传入不为"rowid",返回对应的错误码。 |
5143
5144**返回值**:
5145
5146| 类型                                       | 说明                                                      |
5147| ------------------------------------------ | --------------------------------------------------------- |
5148| Promise&lt;[ModifyTime](#modifytime10)&gt; | 返回ModifyTime类型的Promise对象,表示数据最后的修改时间。 |
5149
5150**错误码:**
5151
5152以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5153
5154| **错误码ID** | **错误信息**                                                 |
5155|-----------| ------------------------------------------------------------ |
5156| 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. |
5157| 801       | Capability not supported. |
5158| 14800000  | Inner error. |
5159| 14800011  | Database corrupted. |
5160| 14800014  | Already closed. |
5161| 14800015  | The database does not respond. |
5162| 14800021  | SQLite: Generic error. |
5163| 14800022  | SQLite: Callback routine requested an abort. |
5164| 14800023  | SQLite: Access permission denied. |
5165| 14800024  | SQLite: The database file is locked. |
5166| 14800025  | SQLite: A table in the database is locked. |
5167| 14800026  | SQLite: The database is out of memory. |
5168| 14800027  | SQLite: Attempt to write a readonly database. |
5169| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5170| 14800029  | SQLite: The database is full. |
5171| 14800030  | SQLite: Unable to open the database file. |
5172| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5173| 14800032  | SQLite: Abort due to constraint violation. |
5174| 14800033  | SQLite: Data type mismatch. |
5175| 14800034  | SQLite: Library used incorrectly. |
5176
5177**示例:**
5178
5179```ts
5180import { BusinessError } from '@kit.BasicServicesKit';
5181
5182let PRIKey = [1, 2, 3];
5183if (store != undefined) {
5184  (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey)
5185    .then((modifyTime: relationalStore.ModifyTime) => {
5186      let size = modifyTime.size;
5187    })
5188    .catch((err: BusinessError) => {
5189      console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`);
5190    });
5191}
5192```
5193
5194### beginTransaction
5195
5196beginTransaction():void
5197
5198在开始执行SQL语句之前,开始事务。
5199此接口不允许嵌套事务,且不支持在多进程或多线程中使用。
5200
5201**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5202
5203**错误码:**
5204
5205以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5206
5207| **错误码ID** | **错误信息**                                                 |
5208|-----------| ------------------------------------------------------------ |
5209| 401       | Parameter error. The store must not be nullptr. |
5210| 14800000  | Inner error. |
5211| 14800011  | Database corrupted. |
5212| 14800014  | Already closed. |
5213| 14800015  | The database does not respond. |
5214| 14800021  | SQLite: Generic error. |
5215| 14800022  | SQLite: Callback routine requested an abort. |
5216| 14800023  | SQLite: Access permission denied. |
5217| 14800024  | SQLite: The database file is locked. |
5218| 14800025  | SQLite: A table in the database is locked. |
5219| 14800026  | SQLite: The database is out of memory. |
5220| 14800027  | SQLite: Attempt to write a readonly database. |
5221| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5222| 14800029  | SQLite: The database is full. |
5223| 14800030  | SQLite: Unable to open the database file. |
5224| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5225| 14800032  | SQLite: Abort due to constraint violation. |
5226| 14800033  | SQLite: Data type mismatch. |
5227| 14800034  | SQLite: Library used incorrectly. |
5228| 14800047  | The WAL file size exceeds the default limit. |
5229
5230**示例:**
5231
5232```ts
5233let value1 = "Lisa";
5234let value2 = 18;
5235let value3 = 100.5;
5236let value4 = new Uint8Array([1, 2, 3]);
5237
5238if (store != undefined) {
5239  (store as relationalStore.RdbStore).beginTransaction();
5240  const valueBucket: relationalStore.ValuesBucket = {
5241    'NAME': value1,
5242    'AGE': value2,
5243    'SALARY': value3,
5244    'CODES': value4
5245  };
5246  (store as relationalStore.RdbStore).insert("test", valueBucket);
5247  (store as relationalStore.RdbStore).commit();
5248}
5249```
5250
5251### beginTrans<sup>12+</sup>
5252
5253beginTrans(): Promise&lt;number&gt;
5254
5255在开始执行SQL语句之前,开始事务,使用Promise异步回调。
5256
5257与[beginTransaction](#begintransaction)的区别在于:该接口会返回事务ID,[execute](#execute12-1)可以指定不同事务ID达到事务隔离目的。
5258
5259该接口仅支持[向量数据库](#storeconfig)使用。
5260
5261**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5262
5263**返回值**:
5264
5265| 类型                | 说明                      |
5266| ------------------- | ------------------------- |
5267| Promise&lt;number&gt; | Promise对象,返回事务ID。 |
5268
5269**错误码:**
5270
5271以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5272
5273| **错误码ID** | **错误信息**                                                 |
5274|-----------| ------------------------------------------------------------ |
5275| 401       | Parameter error. The store must not be nullptr. |
5276| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
5277| 14800000  | Inner error. |
5278| 14800011  | Database corrupted. |
5279| 14800014  | Already closed. |
5280| 14800015  | The database does not respond. |
5281| 14800021  | SQLite: Generic error. |
5282| 14800022  | SQLite: Callback routine requested an abort. |
5283| 14800023  | SQLite: Access permission denied. |
5284| 14800024  | SQLite: The database file is locked. |
5285| 14800025  | SQLite: A table in the database is locked. |
5286| 14800026  | SQLite: The database is out of memory. |
5287| 14800027  | SQLite: Attempt to write a readonly database. |
5288| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5289| 14800029  | SQLite: The database is full. |
5290| 14800030  | SQLite: Unable to open the database file. |
5291| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5292| 14800032  | SQLite: Abort due to constraint violation. |
5293| 14800033  | SQLite: Data type mismatch. |
5294| 14800034  | SQLite: Library used incorrectly. |
5295| 14800047  | The WAL file size exceeds the default limit. |
5296
5297**示例:**
5298
5299```ts
5300import { BusinessError } from '@kit.BasicServicesKit';
5301if (store != null) {
5302  let txId: number;
5303  (store as relationalStore.RdbStore).beginTrans().then((txId: number) => {
5304    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
5305      .then(() => {
5306        (store as relationalStore.RdbStore).commit(txId);
5307      })
5308      .catch((err: BusinessError) => {
5309        (store as relationalStore.RdbStore).rollback(txId);
5310        console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
5311      });
5312  });
5313}
5314```
5315
5316### createTransaction<sup>14+</sup>
5317
5318createTransaction(options?: TransactionOptions): Promise&lt;Transaction&gt;
5319
5320创建一个事务对象并开始事务,使用Promise异步回调。
5321
5322与[beginTransaction](#begintransaction)的区别在于:createTransaction接口会返回一个事务对象,不同事务对象之间是隔离的。使用事务对象进行插入、删除或更新数据等操作,无法被注册数据变更通知[on('dataChange')](#ondatachange)监听到。
5323
5324一个store最多支持同时存在四个事务对象,超过后会返回14800015错误码,此时需要检查是否持有事务对象时间过长或并发事务过多,若确认无法通过上述优化解决问题,建议等待现有事务释放后,再尝试新建事务对象。
5325
5326优先使用createTransaction,不再推荐使用beginTransaction。
5327
5328**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5329
5330**参数:**
5331
5332| 参数名      | 类型                          | 必填 | 说明                                                         |
5333| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ |
5334| options       | [TransactionOptions](#transactionoptions14)           | 否   | 表示事务对象的配置信息。                                 |
5335
5336**返回值**:
5337
5338| 类型                | 说明                      |
5339| ------------------- | ------------------------- |
5340| Promise&lt;[Transaction](#transaction14)&gt; | Promise对象,返回事务对象。 |
5341
5342**错误码:**
5343
5344以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5345
5346| **错误码ID** | **错误信息**                                                 |
5347|-----------| ------------------------------------------------------------ |
5348| 14800000  | Inner error. |
5349| 14800011  | Database corrupted. |
5350| 14800014  | Already closed. |
5351| 14800015  | The database is busy.              |
5352| 14800023  | SQLite: Access permission denied. |
5353| 14800024  | SQLite: The database file is locked. |
5354| 14800026  | SQLite: The database is out of memory. |
5355| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5356| 14800029  | SQLite: The database is full. |
5357| 14800030  | SQLite: Unable to open the database file. |
5358
5359**示例:**
5360
5361```ts
5362import { BusinessError } from '@kit.BasicServicesKit';
5363
5364if (store != undefined) {
5365  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
5366    transaction.execute("DELETE FROM test WHERE age = ? OR age = ?", [21, 20]).then(() => {
5367      transaction.commit();
5368    }).catch((e: BusinessError) => {
5369      transaction.rollback();
5370      console.error(`execute sql failed, code is ${e.code},message is ${e.message}`);
5371    });
5372  }).catch((err: BusinessError) => {
5373    console.error(`createTransaction faided, code is ${err.code},message is ${err.message}`);
5374  });
5375}
5376```
5377
5378### commit
5379
5380commit():void
5381
5382提交已执行的SQL语句,跟[beginTransaction](#begintransaction)配合使用。
5383此接口不允许嵌套事务,且不支持在多进程或多线程中使用。
5384
5385**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5386
5387**错误码:**
5388
5389以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5390
5391| **错误码ID** | **错误信息**                                                 |
5392|-----------| ------------------------------------------------------------ |
5393| 401       | Parameter error. The store must not be nullptr. |
5394| 14800000  | Inner error. |
5395| 14800011  | Database corrupted. |
5396| 14800014  | Already closed. |
5397| 14800015  | The database does not respond. |
5398| 14800021  | SQLite: Generic error. |
5399| 14800022  | SQLite: Callback routine requested an abort. |
5400| 14800023  | SQLite: Access permission denied. |
5401| 14800024  | SQLite: The database file is locked. |
5402| 14800025  | SQLite: A table in the database is locked. |
5403| 14800026  | SQLite: The database is out of memory. |
5404| 14800027  | SQLite: Attempt to write a readonly database. |
5405| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5406| 14800029  | SQLite: The database is full. |
5407| 14800030  | SQLite: Unable to open the database file. |
5408| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5409| 14800032  | SQLite: Abort due to constraint violation. |
5410| 14800033  | SQLite: Data type mismatch. |
5411| 14800034  | SQLite: Library used incorrectly. |
5412
5413**示例:**
5414
5415```ts
5416let value1 = "Lisa";
5417let value2 = 18;
5418let value3 = 100.5;
5419let value4 = new Uint8Array([1, 2, 3]);
5420
5421if (store != undefined) {
5422  (store as relationalStore.RdbStore).beginTransaction();
5423  const valueBucket: relationalStore.ValuesBucket = {
5424    'NAME': value1,
5425    'AGE': value2,
5426    'SALARY': value3,
5427    'CODES': value4
5428  };
5429  (store as relationalStore.RdbStore).insert("test", valueBucket);
5430  (store as relationalStore.RdbStore).commit();
5431}
5432```
5433
5434### commit<sup>12+</sup>
5435
5436commit(txId : number):Promise&lt;void&gt;
5437
5438提交已执行的SQL语句,跟[beginTrans](#begintrans12)配合使用。
5439
5440该接口仅支持[向量数据库](#storeconfig)使用。
5441
5442**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5443
5444**参数:**
5445
5446| 参数名   | 类型                                 | 必填 | 说明                                                         |
5447| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
5448| txId      | number                               | 是   | 通过[beginTrans](#begintrans12)获取的事务ID。                                        |
5449
5450**返回值**:
5451
5452| 类型                | 说明                      |
5453| ------------------- | ------------------------- |
5454| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5455
5456**错误码:**
5457
5458以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5459
5460| **错误码ID** | **错误信息**                                                 |
5461|-----------| ------------------------------------------------------------ |
5462| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5463| 14800000  | Inner error. |
5464| 14800011  | Database corrupted. |
5465| 14800014  | Already closed. |
5466| 14800015  | The database does not respond. |
5467| 14800021  | SQLite: Generic error. |
5468| 14800022  | SQLite: Callback routine requested an abort. |
5469| 14800023  | SQLite: Access permission denied. |
5470| 14800024  | SQLite: The database file is locked. |
5471| 14800025  | SQLite: A table in the database is locked. |
5472| 14800026  | SQLite: The database is out of memory. |
5473| 14800027  | SQLite: Attempt to write a readonly database. |
5474| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5475| 14800029  | SQLite: The database is full. |
5476| 14800030  | SQLite: Unable to open the database file. |
5477| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5478| 14800032  | SQLite: Abort due to constraint violation. |
5479| 14800033  | SQLite: Data type mismatch. |
5480| 14800034  | SQLite: Library used incorrectly. |
5481
5482**示例:**
5483
5484```ts
5485import { BusinessError } from '@kit.BasicServicesKit';
5486if (store != null) {
5487  let txId: number;
5488  (store as relationalStore.RdbStore).beginTrans().then((txId: number) => {
5489    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
5490      .then(() => {
5491        (store as relationalStore.RdbStore).commit(txId);
5492      })
5493      .catch((err: BusinessError) => {
5494        (store as relationalStore.RdbStore).rollback(txId);
5495        console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
5496      });
5497  });
5498}
5499```
5500
5501### rollBack
5502
5503rollBack():void
5504
5505回滚已经执行的SQL语句。
5506此接口不允许嵌套事务,且不支持在多进程或多线程中使用。
5507
5508**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5509
5510**错误码:**
5511
5512以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5513
5514| **错误码ID** | **错误信息**                                                 |
5515|-----------| ------------------------------------------------------------ |
5516| 401       | Parameter error. The store must not be nullptr. |
5517| 14800000  | Inner error. |
5518| 14800011  | Database corrupted. |
5519| 14800014  | Already closed. |
5520| 14800015  | The database does not respond. |
5521| 14800021  | SQLite: Generic error. |
5522| 14800022  | SQLite: Callback routine requested an abort. |
5523| 14800023  | SQLite: Access permission denied. |
5524| 14800024  | SQLite: The database file is locked. |
5525| 14800025  | SQLite: A table in the database is locked. |
5526| 14800026  | SQLite: The database is out of memory. |
5527| 14800027  | SQLite: Attempt to write a readonly database. |
5528| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5529| 14800029  | SQLite: The database is full. |
5530| 14800030  | SQLite: Unable to open the database file. |
5531| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5532| 14800032  | SQLite: Abort due to constraint violation. |
5533| 14800033  | SQLite: Data type mismatch. |
5534| 14800034  | SQLite: Library used incorrectly. |
5535
5536**示例:**
5537
5538```ts
5539import { BusinessError } from '@kit.BasicServicesKit';
5540
5541let value1 = "Lisa";
5542let value2 = 18;
5543let value3 = 100.5;
5544let value4 = new Uint8Array([1, 2, 3]);
5545
5546if (store != undefined) {
5547  try {
5548    (store as relationalStore.RdbStore).beginTransaction();
5549    const valueBucket: relationalStore.ValuesBucket = {
5550      'NAME': value1,
5551      'AGE': value2,
5552      'SALARY': value3,
5553      'CODES': value4
5554    };
5555    (store as relationalStore.RdbStore).insert("test", valueBucket);
5556    (store as relationalStore.RdbStore).commit();
5557  } catch (err) {
5558    let code = (err as BusinessError).code;
5559    let message = (err as BusinessError).message;
5560    console.error(`Transaction failed, code is ${code},message is ${message}`);
5561    (store as relationalStore.RdbStore).rollBack();
5562  }
5563}
5564```
5565
5566### rollback<sup>12+</sup>
5567
5568rollback(txId : number):Promise&lt;void&gt;
5569
5570回滚已经执行的SQL语句,跟[beginTrans](#begintrans12)配合使用。
5571
5572该接口仅支持[向量数据库](#storeconfig)使用。
5573
5574**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5575
5576**参数:**
5577
5578| 参数名   | 类型                                 | 必填 | 说明                                                         |
5579| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
5580| txId      | number                               | 是   | 通过[beginTrans](#begintrans12)获取的事务ID。                                        |
5581
5582**返回值**:
5583
5584| 类型                | 说明                      |
5585| ------------------- | ------------------------- |
5586| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5587
5588**错误码:**
5589
5590以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5591
5592| **错误码ID** | **错误信息**                                                 |
5593|-----------| ------------------------------------------------------------ |
5594| 401       | Parameter error. The store must not be nullptr. |
5595| 14800000  | Inner error. |
5596| 14800011  | Database corrupted. |
5597| 14800014  | Already closed. |
5598| 14800015  | The database does not respond. |
5599| 14800021  | SQLite: Generic error. |
5600| 14800022  | SQLite: Callback routine requested an abort. |
5601| 14800023  | SQLite: Access permission denied. |
5602| 14800024  | SQLite: The database file is locked. |
5603| 14800025  | SQLite: A table in the database is locked. |
5604| 14800026  | SQLite: The database is out of memory. |
5605| 14800027  | SQLite: Attempt to write a readonly database. |
5606| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5607| 14800029  | SQLite: The database is full. |
5608| 14800030  | SQLite: Unable to open the database file. |
5609| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5610| 14800032  | SQLite: Abort due to constraint violation. |
5611| 14800033  | SQLite: Data type mismatch. |
5612| 14800034  | SQLite: Library used incorrectly. |
5613
5614**示例:**
5615
5616```ts
5617import { BusinessError } from '@kit.BasicServicesKit';
5618if (store != null) {
5619  let txId: number;
5620  (store as relationalStore.RdbStore).beginTrans().then((txId: number) => {
5621    (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"])
5622      .then(() => {
5623        (store as relationalStore.RdbStore).commit(txId);
5624      })
5625      .catch((err: BusinessError) => {
5626        (store as relationalStore.RdbStore).rollback(txId);
5627        console.error(`execute sql failed, code is ${err.code},message is ${err.message}`);
5628      });
5629  });
5630}
5631```
5632
5633### backup
5634
5635backup(destName:string, callback: AsyncCallback&lt;void&gt;):void
5636
5637以指定名称备份数据库,使用callback异步回调。
5638
5639**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5640
5641**参数:**
5642
5643| 参数名   | 类型                      | 必填 | 说明                     |
5644| -------- | ------------------------- | ---- | ------------------------ |
5645| destName | string                    | 是   | 指定数据库的备份文件名。 |
5646| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。   |
5647
5648**错误码:**
5649
5650以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5651
5652| **错误码ID** | **错误信息**                                                 |
5653|-----------| ------------------------------------------------------------ |
5654| 401       | Parameter error. The store must not be nullptr. |
5655| 14800000  | Inner error. |
5656| 14800010  | Invalid database path. |
5657| 14800011  | Database corrupted. |
5658| 14800014  | Already closed. |
5659| 14800015  | The database does not respond. |
5660| 14800021  | SQLite: Generic error. |
5661| 14800022  | SQLite: Callback routine requested an abort. |
5662| 14800023  | SQLite: Access permission denied. |
5663| 14800024  | SQLite: The database file is locked. |
5664| 14800025  | SQLite: A table in the database is locked. |
5665| 14800026  | SQLite: The database is out of memory. |
5666| 14800027  | SQLite: Attempt to write a readonly database. |
5667| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5668| 14800029  | SQLite: The database is full. |
5669| 14800030  | SQLite: Unable to open the database file. |
5670| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5671| 14800032  | SQLite: Abort due to constraint violation. |
5672| 14800033  | SQLite: Data type mismatch. |
5673| 14800034  | SQLite: Library used incorrectly. |
5674
5675**示例:**
5676
5677```ts
5678if (store != undefined) {
5679  (store as relationalStore.RdbStore).backup("dbBackup.db", (err) => {
5680    if (err) {
5681      console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
5682      return;
5683    }
5684    console.info('Backup success.');
5685  });
5686}
5687```
5688
5689### backup
5690
5691backup(destName:string): Promise&lt;void&gt;
5692
5693以指定名称备份数据库,使用Promise异步回调。
5694
5695**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5696
5697**参数:**
5698
5699| 参数名   | 类型   | 必填 | 说明                     |
5700| -------- | ------ | ---- | ------------------------ |
5701| destName | string | 是   | 指定数据库的备份文件名。 |
5702
5703**返回值**:
5704
5705| 类型                | 说明                      |
5706| ------------------- | ------------------------- |
5707| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5708
5709**错误码:**
5710
5711以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5712
5713| **错误码ID** | **错误信息**                                                 |
5714|-----------| ------------------------------------------------------------ |
5715| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5716| 14800000  | Inner error. |
5717| 14800011  | Database corrupted. |
5718| 14800014  | Already closed. |
5719| 14800015  | The database does not respond. |
5720| 14800021  | SQLite: Generic error. |
5721| 14800022  | SQLite: Callback routine requested an abort. |
5722| 14800023  | SQLite: Access permission denied. |
5723| 14800024  | SQLite: The database file is locked. |
5724| 14800025  | SQLite: A table in the database is locked. |
5725| 14800026  | SQLite: The database is out of memory. |
5726| 14800027  | SQLite: Attempt to write a readonly database. |
5727| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5728| 14800029  | SQLite: The database is full. |
5729| 14800030  | SQLite: Unable to open the database file. |
5730| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5731| 14800032  | SQLite: Abort due to constraint violation. |
5732| 14800033  | SQLite: Data type mismatch. |
5733| 14800034  | SQLite: Library used incorrectly. |
5734
5735**示例:**
5736
5737```ts
5738import { BusinessError } from '@kit.BasicServicesKit';
5739
5740if (store != undefined) {
5741  let promiseBackup = (store as relationalStore.RdbStore).backup("dbBackup.db");
5742  promiseBackup.then(() => {
5743    console.info('Backup success.');
5744  }).catch((err: BusinessError) => {
5745    console.error(`Backup failed, code is ${err.code},message is ${err.message}`);
5746  });
5747}
5748```
5749
5750### restore
5751
5752restore(srcName:string, callback: AsyncCallback&lt;void&gt;):void
5753
5754从指定的数据库备份文件恢复数据库,使用callback异步回调。
5755
5756**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5757
5758**参数:**
5759
5760| 参数名   | 类型                      | 必填 | 说明                     |
5761| -------- | ------------------------- | ---- | ------------------------ |
5762| srcName  | string                    | 是   | 指定数据库的备份文件名。 |
5763| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。   |
5764
5765**错误码:**
5766
5767以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5768
5769| **错误码ID** | **错误信息**                                                 |
5770|-----------| ------------------------------------------------------------ |
5771| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5772| 14800000  | Inner error. |
5773| 14800011  | Database corrupted. |
5774| 14800014  | Already closed. |
5775| 14800015  | The database does not respond. |
5776| 14800021  | SQLite: Generic error. |
5777| 14800022  | SQLite: Callback routine requested an abort. |
5778| 14800023  | SQLite: Access permission denied. |
5779| 14800024  | SQLite: The database file is locked. |
5780| 14800025  | SQLite: A table in the database is locked. |
5781| 14800026  | SQLite: The database is out of memory. |
5782| 14800027  | SQLite: Attempt to write a readonly database. |
5783| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5784| 14800029  | SQLite: The database is full. |
5785| 14800030  | SQLite: Unable to open the database file. |
5786| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5787| 14800032  | SQLite: Abort due to constraint violation. |
5788| 14800033  | SQLite: Data type mismatch. |
5789| 14800034  | SQLite: Library used incorrectly. |
5790
5791**示例:**
5792
5793```ts
5794if (store != undefined) {
5795  (store as relationalStore.RdbStore).restore("dbBackup.db", (err) => {
5796    if (err) {
5797      console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
5798      return;
5799    }
5800    console.info('Restore success.');
5801  });
5802}
5803```
5804
5805### restore
5806
5807restore(srcName:string): Promise&lt;void&gt;
5808
5809从指定的数据库备份文件恢复数据库,使用Promise异步回调。
5810
5811**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5812
5813**参数:**
5814
5815| 参数名  | 类型   | 必填 | 说明                     |
5816| ------- | ------ | ---- | ------------------------ |
5817| srcName | string | 是   | 指定数据库的备份文件名。 |
5818
5819**返回值**:
5820
5821| 类型                | 说明                      |
5822| ------------------- | ------------------------- |
5823| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5824
5825**错误码:**
5826
5827以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
5828
5829| **错误码ID** | **错误信息**                                                 |
5830|-----------| ------------------------------------------------------------ |
5831| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5832| 14800000  | Inner error. |
5833| 14800011  | Database corrupted. |
5834| 14800014  | Already closed. |
5835| 14800015  | The database does not respond. |
5836| 14800021  | SQLite: Generic error. |
5837| 14800022  | SQLite: Callback routine requested an abort. |
5838| 14800023  | SQLite: Access permission denied. |
5839| 14800024  | SQLite: The database file is locked. |
5840| 14800025  | SQLite: A table in the database is locked. |
5841| 14800026  | SQLite: The database is out of memory. |
5842| 14800027  | SQLite: Attempt to write a readonly database. |
5843| 14800028  | SQLite: Some kind of disk I/O error occurred. |
5844| 14800029  | SQLite: The database is full. |
5845| 14800030  | SQLite: Unable to open the database file. |
5846| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
5847| 14800032  | SQLite: Abort due to constraint violation. |
5848| 14800033  | SQLite: Data type mismatch. |
5849| 14800034  | SQLite: Library used incorrectly. |
5850
5851**示例:**
5852
5853```ts
5854import { BusinessError } from '@kit.BasicServicesKit';
5855
5856if (store != undefined) {
5857  let promiseRestore = (store as relationalStore.RdbStore).restore("dbBackup.db");
5858  promiseRestore.then(() => {
5859    console.info('Restore success.');
5860  }).catch((err: BusinessError) => {
5861    console.error(`Restore failed, code is ${err.code},message is ${err.message}`);
5862  });
5863}
5864```
5865
5866### setDistributedTables
5867
5868setDistributedTables(tables: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
5869
5870设置分布式数据库表,使用callback异步回调。
5871
5872**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5873
5874**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5875
5876**参数:**
5877
5878| 参数名   | 类型                      | 必填 | 说明                   |
5879| -------- | ------------------------- | ---- | ---------------------- |
5880| tables   | Array&lt;string&gt;       | 是   | 要设置的分布式数据库表表名。 |
5881| callback | AsyncCallback&lt;void&gt; | 是   | 指定callback回调函数。 |
5882
5883**错误码:**
5884
5885以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5886
5887| **错误码ID** | **错误信息**                                                 |
5888|-----------| ------------------------------------------------------------ |
5889| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5890| 801       | Capability not supported. |
5891| 14800000  | Inner error. |
5892| 14800014  | Already closed. |
5893
5894**示例:**
5895
5896```ts
5897if (store != undefined) {
5898  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], (err) => {
5899    if (err) {
5900      console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5901      return;
5902    }
5903    console.info('SetDistributedTables successfully.');
5904  });
5905}
5906```
5907
5908### setDistributedTables
5909
5910 setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt;
5911
5912设置分布式数据库表,使用Promise异步回调。
5913
5914**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5915
5916**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5917
5918**参数:**
5919
5920| 参数名 | 类型                     | 必填 | 说明                     |
5921| ------ | ------------------------ | ---- | ------------------------ |
5922| tables | Array&lt;string&gt; | 是   | 要设置的分布式数据库表表名。 |
5923
5924**返回值**:
5925
5926| 类型                | 说明                      |
5927| ------------------- | ------------------------- |
5928| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
5929
5930**错误码:**
5931
5932以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5933
5934| **错误码ID** | **错误信息**                                                 |
5935|-----------| ------------------------------------------------------------ |
5936| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5937| 801       | Capability not supported. |
5938| 14800000  | Inner error. |
5939| 14800014  | Already closed. |
5940
5941**示例:**
5942
5943```ts
5944import { BusinessError } from '@kit.BasicServicesKit';
5945
5946if (store != undefined) {
5947  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"]).then(() => {
5948    console.info('SetDistributedTables successfully.');
5949  }).catch((err: BusinessError) => {
5950    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5951  });
5952}
5953```
5954
5955### setDistributedTables<sup>10+</sup>
5956
5957setDistributedTables(tables: Array&lt;string&gt;, type: DistributedType, callback: AsyncCallback&lt;void&gt;): void
5958
5959设置分布式数据库表,使用callback异步回调。
5960
5961**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
5962
5963**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
5964
5965**参数:**
5966
5967| 参数名   | 类型                                  | 必填 | 说明                         |
5968| -------- | ------------------------------------- | ---- | ---------------------------- |
5969| tables   | Array&lt;string&gt;                   | 是   | 要设置的分布式数据库表表名。 |
5970| type     | [DistributedType](#distributedtype10) | 是   | 表的分布式类型。             |
5971| callback | AsyncCallback&lt;void&gt;             | 是   | 指定callback回调函数。       |
5972
5973**错误码:**
5974
5975以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
5976
5977| **错误码ID** | **错误信息**                                                 |
5978|-----------| ------------------------------------------------------------ |
5979| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
5980| 801       | Capability not supported. |
5981| 14800000  | Inner error. |
5982| 14800014  | Already closed. |
5983| 14800051  | The type of the distributed table does not match. |
5984
5985**示例:**
5986
5987```ts
5988if (store != undefined) {
5989  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, (err) => {
5990    if (err) {
5991      console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
5992      return;
5993    }
5994    console.info('SetDistributedTables successfully.');
5995  });
5996}
5997```
5998
5999### setDistributedTables<sup>10+</sup>
6000
6001setDistributedTables(tables: Array&lt;string&gt;, type: DistributedType, config: DistributedConfig, callback: AsyncCallback&lt;void&gt;): void
6002
6003设置分布式数据库表,使用callback异步回调。
6004
6005**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
6006
6007**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6008
6009**参数:**
6010
6011| 参数名      | 类型                                  | 必填  | 说明              |
6012| -------- | ----------------------------------- | --- | --------------- |
6013| tables   | Array&lt;string&gt;                 | 是   | 要设置的分布式数据库表表名。     |
6014| type     | [DistributedType](#distributedtype10) | 是   | 表的分布式类型。 |
6015| config | [DistributedConfig](#distributedconfig10) | 是 | 表的分布式配置信息。 |
6016| callback | AsyncCallback&lt;void&gt;           | 是   | 指定callback回调函数。 |
6017
6018**错误码:**
6019
6020以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6021
6022| **错误码ID** | **错误信息**                                                 |
6023|-----------| ------------------------------------------------------------ |
6024| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6025| 801       | Capability not supported. |
6026| 14800000  | Inner error. |
6027| 14800014  | Already closed. |
6028| 14800051  | The type of the distributed table does not match. |
6029
6030**示例:**
6031
6032```ts
6033if (store != undefined) {
6034  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, {
6035    autoSync: true
6036  }, (err) => {
6037    if (err) {
6038      console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
6039      return;
6040    }
6041    console.info('SetDistributedTables successfully.');
6042  });
6043}
6044```
6045
6046### setDistributedTables<sup>10+</sup>
6047
6048 setDistributedTables(tables: Array&lt;string>, type?: DistributedType, config?: DistributedConfig): Promise&lt;void>
6049
6050设置分布式数据库表,使用Promise异步回调。
6051
6052**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
6053
6054**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6055
6056**参数:**
6057
6058| 参数名 | 类型                                      | 必填 | 说明                                                         |
6059| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ |
6060| tables | Array&lt;string&gt;                       | 是   | 要设置的分布式数据库表表名。                                 |
6061| type   | [DistributedType](#distributedtype10)     | 否   | 表的分布式类型。默认值是relationalStore.DistributedType.DISTRIBUTED_DEVICE。 |
6062| config | [DistributedConfig](#distributedconfig10) | 否   | 表的分布式配置信息。不传入时默认autoSync为false,即只支持手动同步。 |
6063
6064**返回值**:
6065
6066| 类型                | 说明                      |
6067| ------------------- | ------------------------- |
6068| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
6069
6070**错误码:**
6071
6072以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6073
6074| **错误码ID** | **错误信息**                                                 |
6075|-----------| ------------------------------------------------------------ |
6076| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6077| 801       | Capability not supported. |
6078| 14800000  | Inner error. |
6079| 14800014  | Already closed. |
6080| 14800051  | The type of the distributed table does not match. |
6081
6082**示例:**
6083
6084```ts
6085import { BusinessError } from '@kit.BasicServicesKit';
6086
6087if (store != undefined) {
6088  (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, {
6089    autoSync: true
6090  }).then(() => {
6091    console.info('SetDistributedTables successfully.');
6092  }).catch((err: BusinessError) => {
6093    console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`);
6094  });
6095}
6096```
6097
6098### obtainDistributedTableName
6099
6100obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void
6101
6102根据远程设备的本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名,使用callback异步回调。
6103
6104> **说明:**
6105>
6106> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
6107
6108**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
6109
6110**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6111
6112**参数:**
6113
6114| 参数名   | 类型                        | 必填 | 说明                                                         |
6115| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
6116| device   | string                      | 是   | 远程设备ID 。                                                |
6117| table    | string                      | 是   | 远程设备的本地表名。                                         |
6118| callback | AsyncCallback&lt;string&gt; | 是   | 指定的callback回调函数。如果操作成功,返回远程设备的分布式表名。 |
6119
6120**错误码:**
6121
6122以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6123
6124| **错误码ID** | **错误信息**                                                 |
6125|-----------| ------------------------------------------------------------ |
6126| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6127| 801       | Capability not supported. |
6128| 14800000  | Inner error. |
6129| 14800014  | Already closed. |
6130
6131**示例:**
6132
6133```ts
6134import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6135import { BusinessError } from '@kit.BasicServicesKit';
6136
6137let dmInstance: distributedDeviceManager.DeviceManager;
6138let deviceId: string | undefined = undefined;
6139
6140try {
6141  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
6142  let devices = dmInstance.getAvailableDeviceListSync();
6143  deviceId = devices[0].networkId;
6144} catch (err) {
6145  let code = (err as BusinessError).code;
6146  let message = (err as BusinessError).message;
6147  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
6148}
6149
6150if (store != undefined && deviceId != undefined) {
6151  (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE", (err, tableName) => {
6152    if (err) {
6153      console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
6154      return;
6155    }
6156    console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
6157  });
6158}
6159```
6160
6161### obtainDistributedTableName
6162
6163 obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt;
6164
6165根据远程设备的本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名,使用Promise异步回调。
6166
6167> **说明:**
6168>
6169> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。
6170
6171**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
6172
6173**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6174
6175**参数:**
6176
6177| 参数名 | 类型   | 必填 | 说明                 |
6178| ------ | ------ | ---- | -------------------- |
6179| device | string | 是   | 远程设备ID。         |
6180| table  | string | 是   | 远程设备的本地表名。 |
6181
6182**返回值**:
6183
6184| 类型                  | 说明                                                  |
6185| --------------------- | ----------------------------------------------------- |
6186| Promise&lt;string&gt; | Promise对象。如果操作成功,返回远程设备的分布式表名。 |
6187
6188**错误码:**
6189
6190以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6191
6192| **错误码ID** | **错误信息**                                                 |
6193|-----------| ------------------------------------------------------------ |
6194| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6195| 801       | Capability not supported. |
6196| 14800000  | Inner error. |
6197| 14800014  | Already closed. |
6198
6199**示例:**
6200
6201```ts
6202import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6203import { BusinessError } from '@kit.BasicServicesKit';
6204
6205let dmInstance: distributedDeviceManager.DeviceManager;
6206let deviceId: string | undefined = undefined;
6207
6208try {
6209  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
6210  let devices = dmInstance.getAvailableDeviceListSync();
6211  deviceId = devices[0].networkId;
6212} catch (err) {
6213  let code = (err as BusinessError).code;
6214  let message = (err as BusinessError).message;
6215  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
6216}
6217
6218if (store != undefined && deviceId != undefined) {
6219  (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE").then((tableName: string) => {
6220    console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
6221  }).catch((err: BusinessError) => {
6222    console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`);
6223  });
6224}
6225```
6226
6227### sync
6228
6229sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback&lt;Array&lt;[string, number]&gt;&gt;): void
6230
6231在设备之间同步数据,使用callback异步回调。
6232
6233**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
6234
6235**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6236
6237**参数:**
6238
6239| 参数名     | 类型                                               | 必填 | 说明                                                         |
6240| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
6241| mode       | [SyncMode](#syncmode)                             | 是   | 指同步模式。该值可以是relationalStore.SyncMode.SYNC_MODE_PUSHrelationalStore.SyncMode.SYNC_MODE_PULL。                               |
6242| predicates | [RdbPredicates](#rdbpredicates)               | 是   | 约束同步数据和设备。                                         |
6243| callback   | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | 是   | 指定的callback回调函数,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 |
6244
6245**错误码:**
6246
6247以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6248
6249| **错误码ID** | **错误信息**                                                 |
6250|-----------| ------------------------------------------------------------ |
6251| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6252| 801       | Capability not supported. |
6253| 14800000  | Inner error. |
6254| 14800014  | Already closed. |
6255
6256**示例:**
6257
6258```ts
6259import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6260import { BusinessError } from '@kit.BasicServicesKit';
6261
6262let dmInstance: distributedDeviceManager.DeviceManager;
6263let deviceIds: Array<string> = [];
6264
6265try {
6266  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
6267  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
6268  for (let i = 0; i < devices.length; i++) {
6269    deviceIds[i] = devices[i].networkId!;
6270  }
6271} catch (err) {
6272  let code = (err as BusinessError).code;
6273  let message = (err as BusinessError).message;
6274  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
6275}
6276
6277let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
6278predicates.inDevices(deviceIds);
6279if (store != undefined) {
6280  (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, (err, result) => {
6281    if (err) {
6282      console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
6283      return;
6284    }
6285    console.info('Sync done.');
6286    for (let i = 0; i < result.length; i++) {
6287      console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
6288    }
6289  });
6290}
6291```
6292
6293### sync
6294
6295 sync(mode: SyncMode, predicates: RdbPredicates): Promise&lt;Array&lt;[string, number]&gt;&gt;
6296
6297在设备之间同步数据,使用Promise异步回调。
6298
6299**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC
6300
6301**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6302
6303**参数:**
6304
6305| 参数名     | 类型                                 | 必填 | 说明                           |
6306| ---------- | ------------------------------------ | ---- | ------------------------------ |
6307| mode       | [SyncMode](#syncmode)               | 是   | 指同步模式。该值可以是relationalStore.SyncMode.SYNC_MODE_PUSHrelationalStore.SyncMode.SYNC_MODE_PULL。 |
6308| predicates | [RdbPredicates](#rdbpredicates) | 是   | 约束同步数据和设备。           |
6309
6310**返回值**:
6311
6312| 类型                                         | 说明                                                         |
6313| -------------------------------------------- | ------------------------------------------------------------ |
6314| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise对象,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 |
6315
6316**错误码:**
6317
6318以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6319
6320| **错误码ID** | **错误信息**                                                 |
6321|-----------| ------------------------------------------------------------ |
6322| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6323| 801       | Capability not supported. |
6324| 14800000  | Inner error. |
6325| 14800014  | Already closed. |
6326
6327**示例:**
6328
6329```ts
6330import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6331import { BusinessError } from '@kit.BasicServicesKit';
6332
6333let dmInstance: distributedDeviceManager.DeviceManager;
6334let deviceIds: Array<string> = [];
6335
6336try {
6337  dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify");
6338  let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync();
6339  for (let i = 0; i < devices.length; i++) {
6340    deviceIds[i] = devices[i].networkId!;
6341  }
6342} catch (err) {
6343  let code = (err as BusinessError).code;
6344  let message = (err as BusinessError).message;
6345  console.error("createDeviceManager errCode:" + code + ",errMessage:" + message);
6346}
6347
6348let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
6349predicates.inDevices(deviceIds);
6350if (store != undefined) {
6351  (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates).then((result: Object[][]) => {
6352    console.info('Sync done.');
6353    for (let i = 0; i < result.length; i++) {
6354      console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
6355    }
6356  }).catch((err: BusinessError) => {
6357    console.error(`Sync failed, code is ${err.code},message is ${err.message}`);
6358  });
6359}
6360```
6361
6362### cloudSync<sup>10+</sup>
6363
6364cloudSync(mode: SyncMode, progress: Callback&lt;ProgressDetails&gt;, callback: AsyncCallback&lt;void&gt;): void
6365
6366手动执行对所有分布式表的端云同步,使用callback异步回调。使用该接口需要实现云服务功能。
6367
6368**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6369
6370**参数:**
6371
6372| 参数名   | 类型                                                  | 必填 | 说明                                               |
6373| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
6374| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                             |
6375| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。             |
6376| callback | AsyncCallback&lt;void&gt;                             | 是   | 指定的callback回调函数,用于向调用者发送同步结果。 |
6377
6378**错误码:**
6379
6380以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6381
6382| **错误码ID** | **错误信息**        |
6383|-----------|-------|
6384| 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. |
6385| 801       | Capability not supported.       |
6386| 14800014  | Already closed.        |
6387
6388**示例:**
6389
6390```ts
6391if (store != undefined) {
6392  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetails) => {
6393    console.info(`Progess: ${progressDetails}`);
6394  }, (err) => {
6395    if (err) {
6396      console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`);
6397      return;
6398    }
6399    console.info('Cloud sync succeeded');
6400  });
6401}
6402```
6403
6404### cloudSync<sup>10+</sup>
6405
6406cloudSync(mode: SyncMode, progress: Callback&lt;ProgressDetails&gt;): Promise&lt;void&gt;
6407
6408手动执行对所有分布式表的端云同步,使用Promise异步回调。使用该接口需要实现云服务功能。
6409
6410**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6411
6412**参数:**
6413
6414| 参数名   | 类型                                                  | 必填 | 说明                                   |
6415| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
6416| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                 |
6417| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。 |
6418
6419**返回值**:
6420
6421| 类型                | 说明                                    |
6422| ------------------- | --------------------------------------- |
6423| Promise&lt;void&gt; | Promise对象,用于向调用者发送同步结果。 |
6424
6425**错误码:**
6426
6427以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6428
6429| **错误码ID** | **错误信息**    |
6430|-----------|------------------|
6431| 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. |
6432| 801       | Capability not supported.   |
6433| 14800014  | Already closed.           |
6434
6435**示例:**
6436
6437```ts
6438import { BusinessError } from '@kit.BasicServicesKit';
6439
6440if (store != undefined) {
6441  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetail: relationalStore.ProgressDetails) => {
6442    console.info(`progress: ${progressDetail}`);
6443  }).then(() => {
6444    console.info('Cloud sync succeeded');
6445  }).catch((err: BusinessError) => {
6446    console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`);
6447  });
6448}
6449```
6450
6451### cloudSync<sup>10+</sup>
6452
6453cloudSync(mode: SyncMode, tables: string[], progress: Callback&lt;ProgressDetails&gt;, callback: AsyncCallback&lt;void&gt;): void
6454
6455手动执行对指定表的端云同步,使用callback异步回调。使用该接口需要实现云服务功能。
6456
6457**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6458
6459**参数:**
6460
6461| 参数名   | 类型                                                  | 必填 | 说明                                               |
6462| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
6463| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                             |
6464| tables   | string[]                                              | 是   | 指定同步的表名。                                   |
6465| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。             |
6466| callback | AsyncCallback&lt;void&gt;                             | 是   | 指定的callback回调函数,用于向调用者发送同步结果。 |
6467
6468**错误码:**
6469
6470以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6471
6472| **错误码ID** | **错误信息**                                                                                                                                                                                                                  |
6473|-----------|-------|
6474| 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.|
6475| 801       | Capability not supported.   |
6476| 14800014  | Already closed.   |
6477
6478**示例:**
6479
6480```ts
6481const tables = ["table1", "table2"];
6482
6483if (store != undefined) {
6484  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => {
6485    console.info(`Progess: ${progressDetail}`);
6486  }, (err) => {
6487    if (err) {
6488      console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`);
6489      return;
6490    }
6491    console.info('Cloud sync succeeded');
6492  });
6493};
6494```
6495
6496### cloudSync<sup>10+</sup>
6497
6498cloudSync(mode: SyncMode, tables: string[], progress: Callback&lt;ProgressDetails&gt;): Promise&lt;void&gt;
6499
6500手动执行对指定表的端云同步,使用Promise异步回调。使用该接口需要实现云服务功能。
6501
6502**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
6503
6504**参数:**
6505
6506| 参数名   | 类型                                                  | 必填 | 说明                                   |
6507| -------- | ----------------------------------------------------- | ---- | -------------------------------------- |
6508| mode     | [SyncMode](#syncmode)                                 | 是   | 表示数据库的同步模式。                 |
6509| tables   | string[]                                              | 是   | 指定同步的表名。                       |
6510| progress | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 用来处理数据库同步详细信息的回调函数。 |
6511
6512**返回值**:
6513
6514| 类型                | 说明                                    |
6515| ------------------- | --------------------------------------- |
6516| Promise&lt;void&gt; | Promise对象,用于向调用者发送同步结果。 |
6517
6518**错误码:**
6519
6520以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6521
6522| **错误码ID** | **错误信息**     |
6523|-----------|---------------|
6524| 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 |
6525| 801       | Capability not supported.    |
6526| 14800014  | Already closed.  |
6527
6528**示例:**
6529
6530```ts
6531import { BusinessError } from '@kit.BasicServicesKit';
6532
6533const tables = ["table1", "table2"];
6534
6535if (store != undefined) {
6536  (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => {
6537    console.info(`progress: ${progressDetail}`);
6538  }).then(() => {
6539    console.info('Cloud sync succeeded');
6540  }).catch((err: BusinessError) => {
6541    console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`);
6542  });
6543};
6544```
6545
6546### on('dataChange')
6547
6548on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
6549
6550注册数据库的数据变更的事件监听。当分布式数据库中的数据发生更改时,将调用回调。
6551
6552**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6553
6554**参数:**
6555
6556| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6557| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6558| event    | string                                                       | 是   | 取值为'dataChange',表示数据更改。                           |
6559| type     | [SubscribeType](#subscribetype)                              | 是   | 订阅类型。                                                   |
6560| observer | Callback&lt;Array&lt;string&gt;&gt;                          | 是   | 指分布式数据库中数据更改事件的观察者。Array&lt;string&gt;为数据库中的数据发生改变的对端设备ID。 |
6561
6562**错误码:**
6563
6564以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6565
6566| **错误码ID** | **错误信息**        |
6567|-----------|-------------|
6568| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6569| 801       | Capability not supported. |
6570| 14800014  | Already closed.    |
6571
6572**示例:**
6573
6574```ts
6575import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6576import { BusinessError } from '@kit.BasicServicesKit';
6577
6578let storeObserver = (devices: Array<string>) => {
6579  if (devices != undefined) {
6580    for (let i = 0; i < devices.length; i++) {
6581      console.info(`device= ${devices[i]} data changed`);
6582    }
6583  }
6584};
6585
6586try {
6587  if (store != undefined) {
6588    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6589  }
6590} catch (err) {
6591  let code = (err as BusinessError).code;
6592  let message = (err as BusinessError).message;
6593  console.error(`Register observer failed, code is ${code},message is ${message}`);
6594}
6595```
6596
6597### on('dataChange')<sup>10+</sup>
6598
6599on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;ChangeInfo&gt;&gt;): void
6600
6601注册数据库的数据变更的事件监听。当分布式数据库或本地数据库中的数据发生更改时,将调用回调。
6602
6603**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6604
6605**参数:**
6606
6607| 参数名   | 类型                                | 必填 | 说明                                        |
6608| -------- | ----------------------------------- | ---- | ------------------------------------------- |
6609| event    | string                              | 是   | 取值为'dataChange',表示数据更改。          |
6610| type     | [SubscribeType](#subscribetype)    | 是   | 订阅类型。 |
6611| 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;为本地数据库中的数据更改的详情。 |
6612
6613**错误码:**
6614
6615以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6616
6617| **错误码ID** | **错误信息**        |
6618|-----------|-------------|
6619| 202       | Permission verification failed, application which is not a system application uses system API. |
6620| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6621| 801       | Capability not supported. |
6622| 14800014  | Already closed.    |
6623
6624**示例1:type为SUBSCRIBE_TYPE_REMOTE**
6625
6626```ts
6627import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6628import { BusinessError } from '@kit.BasicServicesKit';
6629
6630let storeObserver = (devices: Array<string>) => {
6631  if (devices != undefined) {
6632    for (let i = 0; i < devices.length; i++) {
6633      console.info(`device= ${devices[i]} data changed`);
6634    }
6635  }
6636};
6637
6638try {
6639  if (store != undefined) {
6640    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6641  }
6642} catch (err) {
6643  let code = (err as BusinessError).code;
6644  let message = (err as BusinessError).message;
6645  console.error(`Register observer failed, code is ${code},message is ${message}`);
6646}
6647```
6648
6649**示例2:type为SUBSCRIBE_TYPE_LOCAL_DETAILS**
6650
6651```ts
6652import { BusinessError } from '@kit.BasicServicesKit';
6653
6654let changeInfos = (changeInfos: Array<relationalStore.ChangeInfo>) => {
6655  for (let i = 0; i < changeInfos.length; i++) {
6656    console.info(`changeInfos = ${changeInfos[i]}`);
6657  }
6658};
6659
6660try {
6661  if (store != undefined) {
6662    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_LOCAL_DETAILS, changeInfos);
6663  }
6664} catch (err) {
6665  let code = (err as BusinessError).code;
6666  let message = (err as BusinessError).message;
6667  console.error(`on dataChange fail, code is ${code},message is ${message}`);
6668}
6669
6670let value1 = "Lisa";
6671let value2 = 18;
6672let value3 = 100.5;
6673let value4 = new Uint8Array([1, 2, 3]);
6674
6675try {
6676  const valueBucket: relationalStore.ValuesBucket = {
6677    'name': value1,
6678    'age': value2,
6679    'salary': value3,
6680    'blobType': value4
6681  };
6682
6683  if (store != undefined) {
6684    (store as relationalStore.RdbStore).insert('test', valueBucket);
6685  }
6686} catch (err) {
6687  let code = (err as BusinessError).code;
6688  let message = (err as BusinessError).message;
6689  console.error(`insert fail, code is ${code},message is ${message}`);
6690}
6691```
6692
6693### on<sup>10+</sup>
6694
6695on(event: string, interProcess: boolean, observer: Callback\<void>): void
6696
6697注册数据库的进程内或者进程间事件监听。当调用[emit](#emit10)接口时,将调用回调。
6698
6699**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6700
6701**参数:**
6702
6703| 参数名       | 类型            | 必填 | 说明                                                         |
6704| ------------ | --------------- | ---- | ------------------------------------------------------------ |
6705| event        | string          | 是   | 订阅事件名称,与emit接口触发事件时的名称一致。               |
6706| interProcess | boolean         | 是   | 指定是进程间还是本进程订阅。<br/> true:进程间。<br/> false:本进程。 |
6707| observer     | Callback\<void> | 是   | 回调函数。                                                   |
6708
6709**错误码:**
6710
6711以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6712
6713| **错误码ID** | **错误信息**        |
6714|-----------|-------------|
6715| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6716| 801       | Capability not supported. |
6717| 14800000  | Inner error.    |
6718| 14800014  | Already closed.    |
6719| 14800050  | Failed to obtain the subscription service.    |
6720
6721**示例:**
6722
6723```ts
6724import { BusinessError } from '@kit.BasicServicesKit';
6725
6726let storeObserver = () => {
6727  console.info(`storeObserver`);
6728};
6729
6730try {
6731  if (store != undefined) {
6732    (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver);
6733  }
6734} catch (err) {
6735  let code = (err as BusinessError).code;
6736  let message = (err as BusinessError).message;
6737  console.error(`Register observer failed, code is ${code},message is ${message}`);
6738}
6739```
6740
6741### on('autoSyncProgress')<sup>11+</sup>
6742
6743on(event: 'autoSyncProgress', progress: Callback&lt;ProgressDetails&gt;): void
6744
6745在已打开端云同步,并且网络状态正常的条件下,注册自动同步进度通知,自动同步进行时调用回调。
6746
6747**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6748
6749**参数:**
6750
6751| 参数名       | 类型                              | 必填 | 说明                                |
6752| ------------ |---------------------------------| ---- |-----------------------------------|
6753| event        | string                          | 是   | 取值为'autoSyncProgress',表示自动同步进度通知。 |
6754| progress     | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 是   | 回调函数。                             |
6755
6756**错误码:**
6757
6758以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6759
6760| **错误码ID** | **错误信息**    |
6761|-----------|--------|
6762| 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. |
6763| 801       | Capability not supported.  |
6764| 14800014  | Already closed.     |
6765
6766**示例:**
6767
6768```ts
6769import { BusinessError } from '@kit.BasicServicesKit';
6770
6771let progressDetail = (progressDetail: relationalStore.ProgressDetails) => {
6772  console.info(`progress: ${progressDetail}`);
6773};
6774
6775try {
6776  if (store != undefined) {
6777    (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail);
6778  }
6779} catch (err) {
6780  let code = (err as BusinessError).code;
6781  let message = (err as BusinessError).message;
6782  console.error(`Register observer failed, code is ${code},message is ${message}`);
6783}
6784```
6785
6786### on('statistics')<sup>12+</sup>
6787
6788on(event: 'statistics', observer: Callback&lt;SqlExecutionInfo&gt;): void
6789
6790订阅SQL统计信息。
6791
6792**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6793
6794**参数:**
6795
6796| 参数名       | 类型                              | 必填 | 说明                                |
6797| ------------ |---------------------------------| ---- |-----------------------------------|
6798| event        | string                          | 是   | 订阅事件名称,取值为'statistics',表示sql执行时间的统计。 |
6799| observer     | Callback&lt;[SqlExecutionInfo](#sqlexecutioninfo12)&gt; | 是   | 回调函数。用于返回数据库中SQL执行时间的统计信息。  |
6800
6801**错误码:**
6802
6803以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6804
6805| **错误码ID** | **错误信息**    |
6806|-----------|--------|
6807| 401       | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
6808| 801       | Capability not supported.  |
6809| 14800000  | Inner error.  |
6810| 14800014  | Already closed.     |
6811
6812**示例:**
6813
6814```ts
6815import { BusinessError } from '@kit.BasicServicesKit';
6816
6817let sqlExecutionInfo = (sqlExecutionInfo: relationalStore.SqlExecutionInfo) => {
6818  console.info(`sql: ${sqlExecutionInfo.sql[0]}`);
6819  console.info(`totalTime: ${sqlExecutionInfo.totalTime}`);
6820  console.info(`waitTime: ${sqlExecutionInfo.waitTime}`);
6821  console.info(`prepareTime: ${sqlExecutionInfo.prepareTime}`);
6822  console.info(`executeTime: ${sqlExecutionInfo.executeTime}`);
6823};
6824
6825try {
6826  if (store != undefined) {
6827    (store as relationalStore.RdbStore).on('statistics', sqlExecutionInfo);
6828  }
6829} catch (err) {
6830  let code = (err as BusinessError).code;
6831  let message = (err as BusinessError).message;
6832  console.error(`Register observer failed, code is ${code},message is ${message}`);
6833}
6834
6835try {
6836  let value1 = "Lisa";
6837  let value2 = 18;
6838  let value3 = 100.5;
6839  let value4 = new Uint8Array([1, 2, 3, 4, 5]);
6840
6841  const valueBucket: relationalStore.ValuesBucket = {
6842    'NAME': value1,
6843    'AGE': value2,
6844    'SALARY': value3,
6845    'CODES': value4
6846  };
6847  if (store != undefined) {
6848    (store as relationalStore.RdbStore).insert('test', valueBucket);
6849  }
6850} catch (err) {
6851  console.error(`insert fail, code:${err.code}, message: ${err.message}`);
6852}
6853```
6854
6855### off('dataChange')
6856
6857off(event:'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
6858
6859取消数据变更的事件监听。
6860
6861**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6862
6863**参数:**
6864
6865| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6866| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6867| event    | string                                                       | 是   | 取值为'dataChange',表示数据更改。                           |
6868| type     | [SubscribeType](#subscribetype) | 是   | 订阅类型。                                                   |
6869| observer | Callback&lt;Array&lt;string&gt;&gt;                          | 是   | 指已注册的数据更改观察者。Array&lt;string&gt;为数据库中的数据发生改变的对端设备ID。 |
6870
6871**错误码:**
6872
6873以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6874
6875| **错误码ID** | **错误信息**        |
6876|-----------|-------------|
6877| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6878| 801       | Capability not supported. |
6879| 14800014  | Already closed.    |
6880
6881**示例:**
6882
6883```ts
6884import { BusinessError } from '@kit.BasicServicesKit';
6885
6886let storeObserver = (devices: Array<string>) => {
6887  if (devices != undefined) {
6888    for (let i = 0; i < devices.length; i++) {
6889      console.info(`device= ${devices[i]} data changed`);
6890    }
6891  }
6892};
6893
6894try {
6895  if (store != undefined) {
6896    // 此处不能使用Lambda表达式
6897    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6898  }
6899} catch (err) {
6900  let code = (err as BusinessError).code;
6901  let message = (err as BusinessError).message;
6902  console.error(`Register observer failed, code is ${code},message is ${message}`);
6903}
6904
6905try {
6906  if (store != undefined) {
6907    (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6908  }
6909} catch (err) {
6910  let code = (err as BusinessError).code;
6911  let message = (err as BusinessError).message;
6912  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
6913}
6914```
6915
6916### off('dataChange')<sup>10+</sup>
6917
6918off(event:'dataChange', type: SubscribeType, observer?: Callback&lt;Array&lt;string&gt;&gt;\| Callback&lt;Array&lt;ChangeInfo&gt;&gt;): void
6919
6920取消数据变更的事件监听。
6921
6922**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6923
6924**参数:**
6925
6926| 参数名   | 类型                                | 必填 | 说明                                        |
6927| -------- | ---------------------------------- | ---- | ------------------------------------------ |
6928| event    | string                              | 是   | 取值为'dataChange',表示数据更改。          |
6929| type     | [SubscribeType](#subscribetype)     | 是   | 订阅类型。                                 |
6930| 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类型下所有数据变更的事件监听。 |
6931
6932**错误码:**
6933
6934以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6935
6936| **错误码ID** | **错误信息**        |
6937|-----------|-------------|
6938| 202       | Permission verification failed, application which is not a system application uses system API. |
6939| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
6940| 801       | Capability not supported. |
6941| 14800014  | Already closed.    |
6942
6943**示例:**
6944
6945```ts
6946import { distributedDeviceManager } from '@kit.DistributedServiceKit';
6947import { BusinessError } from '@kit.BasicServicesKit';
6948
6949let storeObserver = (devices: Array<string>) => {
6950  if (devices != undefined) {
6951    for (let i = 0; i < devices.length; i++) {
6952      console.info(`device= ${devices[i]} data changed`);
6953    }
6954  }
6955};
6956
6957try {
6958  if (store != undefined) {
6959    (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6960  }
6961} catch (err) {
6962  let code = (err as BusinessError).code;
6963  let message = (err as BusinessError).message;
6964  console.error(`Register observer failed, code is ${code},message is ${message}`);
6965}
6966
6967try {
6968  if (store != undefined) {
6969    (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
6970  }
6971} catch (err) {
6972  let code = (err as BusinessError).code;
6973  let message = (err as BusinessError).message;
6974  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
6975}
6976```
6977
6978### off<sup>10+</sup>
6979
6980off(event: string, interProcess: boolean, observer?: Callback\<void>): void
6981
6982取消数据变更的事件监听。
6983
6984**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
6985
6986**参数:**
6987
6988| 参数名       | 类型            | 必填 | 说明                                                         |
6989| ------------ | --------------- | ---- | ------------------------------------------------------------ |
6990| event        | string          | 是   | 取消订阅事件名称。事件名称与on接口调用时订阅事件的名称一致。 |
6991| interProcess | boolean         | 是   | 指定是进程间还是本进程取消订阅。<br/> true:进程间。<br/> false:本进程。 |
6992| observer     | Callback\<void> | 否   | 该参数存在,则取消指定Callback监听回调,否则取消该event事件的所有监听回调。 |
6993
6994**错误码:**
6995
6996以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
6997
6998| **错误码ID** | **错误信息**                           |
6999| ------------ | -------------------------------------- |
7000| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7001| 801       | Capability not supported. |
7002| 14800000     | Inner error.                           |
7003| 14800014  | Already closed.    |
7004| 14800050     | Failed to obtain the subscription service. |
7005
7006**示例:**
7007
7008```ts
7009import { BusinessError } from '@kit.BasicServicesKit';
7010
7011let storeObserver = () => {
7012  console.info(`storeObserver`);
7013};
7014
7015try {
7016  if (store != undefined) {
7017    (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver);
7018  }
7019} catch (err) {
7020  let code = (err as BusinessError).code;
7021  let message = (err as BusinessError).message;
7022  console.error(`Register observer failed, code is ${code},message is ${message}`);
7023}
7024
7025try {
7026  if (store != undefined) {
7027    (store as relationalStore.RdbStore).off('storeObserver', false, storeObserver);
7028  }
7029} catch (err) {
7030  let code = (err as BusinessError).code;
7031  let message = (err as BusinessError).message;
7032  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
7033}
7034```
7035
7036### off('autoSyncProgress')<sup>11+</sup>
7037
7038off(event: 'autoSyncProgress', progress?: Callback&lt;ProgressDetails&gt;): void
7039
7040取消订阅自动同步进度的通知。
7041
7042**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7043
7044**参数:**
7045
7046| 参数名       | 类型                              | 必填 | 说明                                                               |
7047| ------------ |---------------------------------| ---- |------------------------------------------------------------------|
7048| event        | string                          | 是   | 取值为'autoSyncProgress',表示自动同步进度通知。                                |
7049| progress     | Callback&lt;[ProgressDetails](#progressdetails10)&gt; | 否   | 指已注册的自动同步进度观察者。该参数存在,则取消订阅指定回调,该参数为null或undefined或不存在,则取消订阅所有回调。 |
7050
7051**错误码:**
7052
7053以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
7054
7055| **错误码ID** | **错误信息**         |
7056| ------------ |--------------------|
7057| 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. |
7058| 801       | Capability not supported.  |
7059| 14800014  | Already closed.       |
7060
7061**示例:**
7062
7063```ts
7064import { BusinessError } from '@kit.BasicServicesKit';
7065
7066let progressDetail = (progressDetail: relationalStore.ProgressDetails) => {
7067  console.info(`progress: ${progressDetail}`);
7068};
7069
7070try {
7071  if (store != undefined) {
7072    (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail);
7073  }
7074} catch (err) {
7075  let code = (err as BusinessError).code;
7076  let message = (err as BusinessError).message;
7077  console.error(`Register observer failed, code is ${code},message is ${message}`);
7078}
7079
7080try {
7081  if (store != undefined) {
7082    (store as relationalStore.RdbStore).off('autoSyncProgress', progressDetail);
7083  }
7084} catch (err) {
7085  let code = (err as BusinessError).code;
7086  let message = (err as BusinessError).message;
7087  console.error(`Unregister failed, code is ${code},message is ${message}`);
7088}
7089```
7090
7091### off('statistics')<sup>12+</sup>
7092
7093off(event: 'statistics', observer?: Callback&lt;SqlExecutionInfo&gt;): void
7094
7095取消订阅SQL统计信息。
7096
7097**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7098
7099**参数:**
7100
7101| 参数名       | 类型                              | 必填 | 说明                                |
7102| ------------ |---------------------------------| ---- |-----------------------------------|
7103| event        | string                          | 是   | 取消订阅事件名称。取值为'statistics',表示sql执行时间的统计。 |
7104| observer     | Callback&lt;[SqlExecutionInfo](#sqlexecutioninfo12)&gt; | 否   | 回调函数。该参数存在,则取消指定Callback监听回调,否则取消该event事件的所有监听回调。  |
7105
7106
7107**错误码:**
7108
7109以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
7110
7111| **错误码ID** | **错误信息**    |
7112|-----------|--------|
7113| 401       | Parameter error.  |
7114| 801       | Capability not supported.  |
7115| 14800000  | Inner error.  |
7116| 14800014  | Already closed.     |
7117
7118```ts
7119import { BusinessError } from '@kit.BasicServicesKit';
7120
7121try {
7122  if (store != undefined) {
7123    (store as relationalStore.RdbStore).off('statistics');
7124  }
7125} catch (err) {
7126  let code = (err as BusinessError).code;
7127  let message = (err as BusinessError).message;
7128  console.error(`Unregister observer failed, code is ${code},message is ${message}`);
7129}
7130```
7131
7132### emit<sup>10+</sup>
7133
7134emit(event: string): void
7135
7136通知通过[on](#on10)注册的进程间或者进程内监听事件。
7137
7138**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7139
7140**参数:**
7141
7142| 参数名 | 类型   | 必填 | 说明                 |
7143| ------ | ------ | ---- | -------------------- |
7144| event  | string | 是   | 通知订阅事件的名称,可自定义事件名称,不能与系统已有事件[dataChange](#ondatachange),[autoSyncProgress](#onautosyncprogress11),[statistics](#onstatistics12)名称重复。 |
7145
7146**错误码:**
7147
7148以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
7149
7150| **错误码ID** | **错误信息**                                                                                                      |
7151| --------- |---------------------------------------------------------------------------------------------------------------|
7152| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7153| 801       | Capability not supported.     |
7154| 14800000  | Inner error.   |
7155| 14800014  | Already closed.     |
7156| 14800050  | Failed to obtain the subscription service.    |
7157
7158
7159**示例:**
7160
7161```ts
7162if (store != undefined) {
7163  (store as relationalStore.RdbStore).emit('storeObserver');
7164}
7165```
7166
7167### cleanDirtyData<sup>11+</sup>
7168
7169cleanDirtyData(table: string, cursor: number, callback: AsyncCallback&lt;void&gt;): void
7170
7171清理云端删除的数据同步到本地后,未自动清理的,且数据的游标(cursor)小于指定游标的数据。
7172
7173**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
7174
7175**参数:**
7176
7177| 参数名   | 类型                                                  | 必填 | 说明                                               |
7178| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
7179| table     | string                        | 是   | 表示当前数据库的表的名称。                             |
7180| cursor    | number                        | 是   | 整数类型,表示数据游标,小于此游标的脏数据将被清理。     |
7181| callback  | AsyncCallback&lt;void&gt;     | 是   | 指定的callback回调函数。 |
7182
7183**错误码:**
7184
7185以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7186
7187| **错误码ID** | **错误信息**     |
7188|-----------|---------------|
7189| 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. |
7190| 801       | Capability not supported. |
7191| 14800000  | Inner error. |
7192| 14800011  | Database corrupted. |
7193| 14800014  | Already closed. |
7194| 14800015  | The database does not respond. |
7195| 14800021  | SQLite: Generic error. |
7196| 14800022  | SQLite: Callback routine requested an abort. |
7197| 14800023  | SQLite: Access permission denied. |
7198| 14800024  | SQLite: The database file is locked. |
7199| 14800025  | SQLite: A table in the database is locked. |
7200| 14800026  | SQLite: The database is out of memory. |
7201| 14800027  | SQLite: Attempt to write a readonly database. |
7202| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7203| 14800029  | SQLite: The database is full. |
7204| 14800030  | SQLite: Unable to open the database file. |
7205| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7206| 14800032  | SQLite: Abort due to constraint violation. |
7207| 14800033  | SQLite: Data type mismatch. |
7208| 14800034  | SQLite: Library used incorrectly. |
7209
7210**示例:**
7211
7212```ts
7213if (store != undefined) {
7214  (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100, (err) => {
7215    if (err) {
7216      console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`);
7217      return;
7218    }
7219    console.info('clean dirty data succeeded');
7220  });
7221}
7222```
7223
7224### cleanDirtyData<sup>11+</sup>
7225
7226cleanDirtyData(table: string, callback: AsyncCallback&lt;void&gt;): void
7227
7228清理云端删除的数据同步到本地后,未自动清理的所有数据。
7229
7230**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
7231
7232**参数:**
7233
7234| 参数名   | 类型                                                  | 必填 | 说明                                               |
7235| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
7236| table     | string                        | 是   | 表示当前数据库的表的名称。 |
7237| callback  | AsyncCallback&lt;void&gt;     | 是   | 指定的callback回调函数。 |
7238
7239**错误码:**
7240
7241以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7242
7243| **错误码ID** | **错误信息**       |
7244|-----------|---------|
7245| 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. |
7246| 801       | Capability not supported.    |
7247| 14800000  | Inner error.        |
7248| 14800011  | Database corrupted.   |
7249| 14800014  | Already closed.       |
7250| 14800015  | The database does not respond.      |
7251| 14800021  | SQLite: Generic error.     |
7252| 14800022  | SQLite: Callback routine requested an abort. |
7253| 14800023  | SQLite: Access permission denied.           |
7254| 14800024  | SQLite: The database file is locked.        |
7255| 14800025  | SQLite: A table in the database is locked.  |
7256| 14800026  | SQLite: The database is out of memory.      |
7257| 14800027  | SQLite: Attempt to write a readonly database.   |
7258| 14800028  | SQLite: Some kind of disk I/O error occurred.  |
7259| 14800029  | SQLite: The database is full.                |
7260| 14800030  | SQLite: Unable to open the database file.            |
7261| 14800031  | SQLite: TEXT or BLOB exceeds size limit.             |
7262| 14800032  | SQLite: Abort due to constraint violation.   |
7263| 14800033  | SQLite: Data type mismatch.                  |
7264| 14800034  | SQLite: Library used incorrectly.          |
7265
7266**示例:**
7267
7268```ts
7269if (store != undefined) {
7270  (store as relationalStore.RdbStore).cleanDirtyData('test_table', (err) => {
7271    if (err) {
7272      console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`);
7273      return;
7274    }
7275    console.info('clean dirty data succeeded');
7276  });
7277}
7278```
7279
7280### cleanDirtyData<sup>11+</sup>
7281
7282cleanDirtyData(table: string, cursor?: number): Promise&lt;void&gt;
7283
7284清理云端删除的数据同步到本地后,未自动清理的,且数据的游标(cursor)小于指定游标的数据。若无cursor参数,将全部清理。
7285
7286**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client
7287
7288**参数:**
7289
7290| 参数名   | 类型                                                  | 必填 | 说明                                               |
7291| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- |
7292| table     | string           | 是   | 表示当前数据库的表的名称。           |
7293| cursor    | number           | 否   | 整数类型,表示数据游标,小于此游标的脏数据将被清理。当此参数不填时,清理当前表的所有脏数据。 |
7294
7295**返回值:**
7296| 参数名    | 说明                                               |
7297| -------- | ------------------------------------------------- |
7298| Promise\<void> | 无返回结果的Promise对象。        |
7299
7300**错误码:**
7301
7302以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7303
7304| **错误码ID** | **错误信息**                                                                                                                                                                      |
7305|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7306| 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. |
7307| 801       | Capability not supported. |
7308| 14800000  | Inner error.            |
7309| 14800011  | Database corrupted.   |
7310| 14800014  | Already closed. |
7311| 14800015  | The database does not respond.   |
7312| 14800021  | SQLite: Generic error.   |
7313| 14800022  | SQLite: Callback routine requested an abort. |
7314| 14800023  | SQLite: Access permission denied.          |
7315| 14800024  | SQLite: The database file is locked.      |
7316| 14800025  | SQLite: A table in the database is locked. |
7317| 14800026  | SQLite: The database is out of memory.   |
7318| 14800027  | SQLite: Attempt to write a readonly database. |
7319| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7320| 14800029  | SQLite: The database is full.   |
7321| 14800030  | SQLite: Unable to open the database file. |
7322| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7323| 14800032  | SQLite: Abort due to constraint violation. |
7324| 14800033  | SQLite: Data type mismatch. |
7325| 14800034  | SQLite: Library used incorrectly. |
7326
7327**示例:**
7328
7329```ts
7330import { BusinessError } from '@kit.BasicServicesKit';
7331
7332if (store != undefined) {
7333  (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100).then(() => {
7334    console.info('clean dirty data  succeeded');
7335  }).catch((err: BusinessError) => {
7336    console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`);
7337  });
7338}
7339```
7340
7341### attach<sup>12+</sup>
7342
7343attach(fullPath: string, attachName: string, waitTime?: number) : Promise&lt;number&gt;
7344
7345将一个数据库文件附加到当前数据库中,以便在SQL语句中可以直接访问附加数据库中的数据。
7346
7347数据库文件来自文件,且此API不支持附加加密数据库。调用attach接口后,数据库切换为非WAL模式,性能会存在一定的劣化。
7348
7349attach的时候,数据库会切换为非WAL模式,切换模式需要确保所有的ResultSet都已经Close,所有的写操作已经结束,否则会报错14800015。
7350
7351attach不能并发调用,可能出现未响应情况,报错14800015,需要重试。
7352
7353**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7354
7355**参数:**
7356
7357| 参数名        | 类型     | 必填  | 说明           |
7358| ----------- | ------ | --- | ------------ |
7359| fullPath | string | 是   | 表示要附加的数据库的路径。 |
7360| attachName | string | 是   | 表示附加后的数据库的别名。 |
7361| waitTime | number | 否   | 表示附加数据库文件的等待时长。默认值2s,最小值1s,最大值300s。 |
7362
7363**返回值:**
7364
7365| 类型              | 说明                           |
7366| ---------------- | ---------------------------- |
7367|  Promise&lt;number&gt; | Promise对象。返回附加数据库的数量。 |
7368
7369**错误码:**
7370
7371以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7372
7373| **错误码ID** | **错误信息**                                                 |
7374|-----------| ------------------------------------------------------------ |
7375| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7376| 801       | Capability not supported. |
7377| 14800000  | Inner error. |
7378| 14800010  | Invalid database path.               |
7379| 14800011  | Database corrupted. |
7380| 14800014  | Already closed. |
7381| 14800015  | The database does not respond.                 |
7382| 14800016  | The database alias already exists.                |
7383| 14800021  | SQLite: Generic error. |
7384| 14800022  | SQLite: Callback routine requested an abort. |
7385| 14800023  | SQLite: Access permission denied. |
7386| 14800024  | SQLite: The database file is locked. |
7387| 14800025  | SQLite: A table in the database is locked. |
7388| 14800026  | SQLite: The database is out of memory. |
7389| 14800027  | SQLite: Attempt to write a readonly database. |
7390| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7391| 14800029  | SQLite: The database is full. |
7392| 14800030  | SQLite: Unable to open the database file. |
7393| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7394| 14800032  | SQLite: Abort due to constraint violation. |
7395| 14800033  | SQLite: Data type mismatch. |
7396| 14800034  | SQLite: Library used incorrectly. |
7397
7398**示例:**
7399
7400```ts
7401// 非加密数据库附加非加密数据库。
7402import { BusinessError } from '@kit.BasicServicesKit';
7403
7404if (store != undefined) {
7405  (store as relationalStore.RdbStore).attach("/path/rdbstore1.db", "attachDB").then((number: number) => {
7406    console.info('attach succeeded');
7407  }).catch((err: BusinessError) => {
7408    console.error(`attach failed, code is ${err.code},message is ${err.message}`);
7409  });
7410}
7411```
7412
7413### attach<sup>12+</sup>
7414
7415attach(context: Context, config: StoreConfig, attachName: string, waitTime?: number) : Promise&lt;number&gt;
7416
7417将一个当前应用的数据库附加到当前数据库中,以便在SQL语句中可以直接访问附加数据库中的数据。
7418
7419此API不支持加密数据库附加非加密数据库的场景。调用attach接口后,数据库切换为非WAL模式,性能会存在一定的劣化。
7420
7421attach的时候,数据库会切换为非WAL模式,切换模式需要确保所有的ResultSet都已经Close,所有的写操作已经结束,否则会报错14800015。
7422
7423attach不能并发调用,可能出现未响应情况,报错14800015,需要重试。除此之外,attach附加加密数据库时,可能受到并发的影响,出现解密失败的情况,报错14800011,需要显式指定加密参数并重试。
7424
7425**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7426
7427**参数:**
7428
7429| 参数名        | 类型     | 必填  | 说明           |
7430| ----------- | ------ | --- | ------------ |
7431| 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)。 |
7432| config  | [StoreConfig](#storeconfig) | 是   | 与此RDB存储相关的数据库配置。                                |
7433| attachName | string | 是   | 表示附加后的数据库的别名。 |
7434| waitTime | number | 否   | 表示附加数据库文件的等待时长。默认值2s,最小值1s,最大值300s。 |
7435
7436**返回值:**
7437
7438| 类型              | 说明                           |
7439| ---------------- | ---------------------------- |
7440|  Promise&lt;number&gt; | Promise对象。返回附加数据库的数量。 |
7441
7442**错误码:**
7443
7444以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7445
7446| **错误码ID** | **错误信息**                                                 |
7447|-----------| ------------------------------------------------------------ |
7448| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7449| 801       | Capability not supported. |
7450| 14800000  | Inner error. |
7451| 14800010  | Invalid database path.               |
7452| 14800011  | Database corrupted. |
7453| 14800014  | Already closed. |
7454| 14800015  | The database does not respond.                 |
7455| 14800016  | The database alias already exists.                |
7456| 14801001  | The operation is supported in the stage model only.                 |
7457| 14801002  | Invalid data group ID.                |
7458| 14800021  | SQLite: Generic error. |
7459| 14800022  | SQLite: Callback routine requested an abort. |
7460| 14800023  | SQLite: Access permission denied. |
7461| 14800024  | SQLite: The database file is locked. |
7462| 14800025  | SQLite: A table in the database is locked. |
7463| 14800026  | SQLite: The database is out of memory. |
7464| 14800027  | SQLite: Attempt to write a readonly database. |
7465| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7466| 14800029  | SQLite: The database is full. |
7467| 14800030  | SQLite: Unable to open the database file. |
7468| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7469| 14800032  | SQLite: Abort due to constraint violation. |
7470| 14800033  | SQLite: Data type mismatch. |
7471| 14800034  | SQLite: Library used incorrectly. |
7472
7473**示例1:非加密数据库附加非加密数据库**
7474
7475```ts
7476import { BusinessError } from '@kit.BasicServicesKit';
7477
7478let attachStore: relationalStore.RdbStore | undefined = undefined;
7479
7480const STORE_CONFIG1: relationalStore.StoreConfig = {
7481  name: "rdbstore1.db",
7482  securityLevel: relationalStore.SecurityLevel.S3
7483};
7484
7485relationalStore.getRdbStore(this.context, STORE_CONFIG1).then(async (rdbStore: relationalStore.RdbStore) => {
7486  attachStore = rdbStore;
7487  console.info('Get RdbStore successfully.');
7488}).catch((err: BusinessError) => {
7489  console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
7490});
7491
7492if (store != undefined) {
7493  (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG1, "attachDB").then((number: number) => {
7494    console.info(`attach succeeded, number is ${number}`);
7495  }).catch((err: BusinessError) => {
7496    console.error(`attach failed, code is ${err.code},message is ${err.message}`);
7497  });
7498}
7499```
7500
7501**示例2:非加密数据库附加加密数据库**
7502
7503```ts
7504import { BusinessError } from '@kit.BasicServicesKit';
7505
7506let attachStore: relationalStore.RdbStore | undefined = undefined;
7507
7508const STORE_CONFIG2: relationalStore.StoreConfig = {
7509  name: "rdbstore2.db",
7510  encrypt: true,
7511  securityLevel: relationalStore.SecurityLevel.S3
7512};
7513
7514relationalStore.getRdbStore(this.context, STORE_CONFIG2).then(async (rdbStore: relationalStore.RdbStore) => {
7515  attachStore = rdbStore;
7516  console.info('Get RdbStore successfully.');
7517}).catch((err: BusinessError) => {
7518  console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
7519});
7520
7521if (store != undefined) {
7522  (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG2, "attachDB2", 10).then((number: number) => {
7523    console.info(`attach succeeded, number is ${number}`);
7524  }).catch((err: BusinessError) => {
7525    console.error(`attach failed, code is ${err.code},message is ${err.message}`);
7526  });
7527}
7528```
7529
7530### detach<sup>12+</sup>
7531
7532detach(attachName: string, waitTime?: number) : Promise&lt;number&gt;
7533
7534将附加的数据库从当前数据库中分离。
7535
7536当所有的附加的数据库被分离后,数据库会重新切换为WAL模式。
7537
7538在detach之前,所有的数据库操作要确保已经结束,所有的ResultSet已经Close。并且不能并发调用,可能出现未响应情况,需要重试。
7539
7540**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7541
7542**参数:**
7543
7544| 参数名        | 类型     | 必填  | 说明           |
7545| ----------- | ------ | --- | ------------ |
7546| attachName | string | 是   | 表示附加后的数据库的别名。 |
7547| waitTime | number | 否   | 表示分离数据库的等待时长。默认值2s,最小值1s,最大值300s。 |
7548
7549**返回值:**
7550
7551| 类型              | 说明                           |
7552| ---------------- | ---------------------------- |
7553|  Promise&lt;number&gt; | Promise对象。返回分离后剩余附加的数据库的数量。 |
7554
7555**错误码:**
7556
7557以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7558
7559| **错误码ID** | **错误信息**       |
7560|-----------|------------------------|
7561| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7562| 14800000  | Inner error.            |
7563| 14800011  | Database corrupted.         |
7564| 14800014  | Already closed.        |
7565| 14800015  | The database does not respond.         |
7566| 14800021  | SQLite: Generic error.            |
7567| 14800022  | SQLite: Callback routine requested an abort.       |
7568| 14800023  | SQLite: Access permission denied.           |
7569| 14800024  | SQLite: The database file is locked.        |
7570| 14800025  | SQLite: A table in the database is locked.       |
7571| 14800026  | SQLite: The database is out of memory.     |
7572| 14800027  | SQLite: Attempt to write a readonly database.        |
7573| 14800028  | SQLite: Some kind of disk I/O error occurred.    |
7574| 14800029  | SQLite: The database is full.      |
7575| 14800030  | SQLite: Unable to open the database file.       |
7576| 14800031  | SQLite: TEXT or BLOB exceeds size limit.      |
7577| 14800032  | SQLite: Abort due to constraint violation.    |
7578| 14800033  | SQLite: Data type mismatch.       |
7579| 14800034  | SQLite: Library used incorrectly.       |
7580
7581**示例:**
7582
7583```ts
7584import { BusinessError } from '@kit.BasicServicesKit';
7585
7586if (store != undefined) {
7587  (store as relationalStore.RdbStore).detach("attachDB").then((number: number) => {
7588    console.info(`detach succeeded, number is ${number}`);
7589  }).catch((err: BusinessError) => {
7590    console.error(`detach failed, code is ${err.code},message is ${err.message}`);
7591  });
7592}
7593```
7594
7595### lockRow<sup>12+</sup>
7596
7597lockRow(predicates: RdbPredicates):Promise&lt;void&gt;
7598
7599根据RdbPredicates的指定实例对象从数据库中锁定数据,锁定数据不执行端云同步,使用Promise异步回调。
7600
7601该接口只支持主键为基本类型的表、不支持共享表、无主键表和复合类型主键表。
7602该接口不支持依赖关系表之间的锁传递,如果表存在依赖关系,需要根据依赖关系手动调用该接口。
7603该接口不支持对已删除数据的操作。
7604
7605**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7606
7607**参数:**
7608
7609| 参数名     | 类型                                 | 必填 | 说明                                      |
7610| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
7611| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的锁定条件。 |
7612
7613**返回值**:
7614
7615| 类型                  | 说明                            |
7616| --------------------- | ------------------------------- |
7617| Promise&lt;void&gt;   | 无返回结果的Promise对象。        |
7618
7619**错误码:**
7620
7621以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7622
7623| **错误码ID** | **错误信息**                                                                                     |
7624|-----------|----------------------------------------------------------------------------------------------|
7625| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7626| 14800000  | Inner error.                                                                                 |
7627| 14800011  | Database corrupted.                                                                          |
7628| 14800014  | Already closed.                                                                              |
7629| 14800015  | The database does not respond.                                                                        |
7630| 14800018  | No data meets the condition.                                                                 |
7631| 14800021  | SQLite: Generic error.                                                                       |
7632| 14800022  | SQLite: Callback routine requested an abort.                                                 |
7633| 14800023  | SQLite: Access permission denied.                                                            |
7634| 14800024  | SQLite: The database file is locked.                                                         |
7635| 14800025  | SQLite: A table in the database is locked.                                                   |
7636| 14800026  | SQLite: The database is out of memory.                                                       |
7637| 14800027  | SQLite: Attempt to write a readonly database.                                                |
7638| 14800028  | SQLite: Some kind of disk I/O error occurred.                                                |
7639| 14800029  | SQLite: The database is full.                                                                |
7640| 14800030  | SQLite: Unable to open the database file.                                                    |
7641| 14800031  | SQLite: TEXT or BLOB exceeds size limit.                                                     |
7642| 14800032  | SQLite: Abort due to constraint violation.                                                   |
7643| 14800033  | SQLite: Data type mismatch.                                                                  |
7644| 14800034  | SQLite: Library used incorrectly.                                                            |
7645
7646**示例:**
7647
7648```ts
7649import { BusinessError } from '@kit.BasicServicesKit';
7650
7651let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
7652predicates.equalTo("NAME", "Lisa");
7653if (store != undefined) {
7654  (store as relationalStore.RdbStore).lockRow(predicates).then(() => {
7655    console.info(`Lock success`);
7656  }).catch((err: BusinessError) => {
7657    console.error(`Lock failed, code is ${err.code},message is ${err.message}`);
7658  });
7659}
7660```
7661
7662### unlockRow<sup>12+</sup>
7663
7664unlockRow(predicates: RdbPredicates):Promise&lt;void&gt;
7665
7666根据RdbPredicates的指定实例对象从数据库中解锁数据,使用Promise异步回调。
7667
7668该接口只支持主键为基本类型的表、不支持共享表、无主键表和复合类型主键表。
7669该接口不支持依赖关系表之间的锁传递,如果表存在依赖关系,需要根据依赖关系手动调用该接口。
7670该接口不支持对已删除数据的操作。
7671
7672**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7673
7674**参数:**
7675
7676| 参数名     | 类型                                 | 必填 | 说明                                      |
7677| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
7678| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的锁定条件。 |
7679
7680**返回值**:
7681
7682| 类型                  | 说明                            |
7683| --------------------- | ------------------------------- |
7684| Promise&lt;void&gt;   | 无返回结果的Promise对象。        |
7685
7686**错误码:**
7687
7688以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7689
7690| **错误码ID** | **错误信息**                                                 |
7691|-----------| ------------------------------------------------------------ |
7692| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7693| 14800000  | Inner error. |
7694| 14800011  | Database corrupted. |
7695| 14800014  | Already closed. |
7696| 14800015  | The database does not respond.                 |
7697| 14800018  | No data meets the condition.                |
7698| 14800021  | SQLite: Generic error. |
7699| 14800022  | SQLite: Callback routine requested an abort. |
7700| 14800023  | SQLite: Access permission denied. |
7701| 14800024  | SQLite: The database file is locked. |
7702| 14800025  | SQLite: A table in the database is locked. |
7703| 14800026  | SQLite: The database is out of memory. |
7704| 14800027  | SQLite: Attempt to write a readonly database. |
7705| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7706| 14800029  | SQLite: The database is full. |
7707| 14800030  | SQLite: Unable to open the database file. |
7708| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7709| 14800032  | SQLite: Abort due to constraint violation. |
7710| 14800033  | SQLite: Data type mismatch. |
7711| 14800034  | SQLite: Library used incorrectly. |
7712
7713**示例:**
7714
7715```ts
7716import { BusinessError } from '@kit.BasicServicesKit';
7717
7718let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
7719predicates.equalTo("NAME", "Lisa");
7720if (store != undefined) {
7721  (store as relationalStore.RdbStore).unlockRow(predicates).then(() => {
7722    console.info(`Unlock success`);
7723  }).catch((err: BusinessError) => {
7724    console.error(`Unlock failed, code is ${err.code},message is ${err.message}`);
7725  });
7726}
7727```
7728
7729### queryLockedRow<sup>12+</sup>
7730
7731queryLockedRow(predicates: RdbPredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSet&gt;
7732
7733根据指定条件查询数据库中锁定的数据,使用Promise异步回调。
7734由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
7735
7736**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7737
7738**参数:**
7739
7740| 参数名     | 类型                                 | 必填 | 说明                                             |
7741| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
7742| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。        |
7743| columns    | Array&lt;string&gt;                  | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
7744
7745**错误码:**
7746
7747以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7748
7749| **错误码ID** | **错误信息**                                                 |
7750|-----------| ------------------------------------------------------------ |
7751| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7752| 14800000  | Inner error. |
7753| 14800011  | Database corrupted. |
7754| 14800014  | Already closed. |
7755| 14800015  | The database does not respond.                 |
7756| 14800021  | SQLite: Generic error. |
7757| 14800022  | SQLite: Callback routine requested an abort. |
7758| 14800023  | SQLite: Access permission denied. |
7759| 14800024  | SQLite: The database file is locked. |
7760| 14800025  | SQLite: A table in the database is locked. |
7761| 14800026  | SQLite: The database is out of memory. |
7762| 14800027  | SQLite: Attempt to write a readonly database. |
7763| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7764| 14800029  | SQLite: The database is full. |
7765| 14800030  | SQLite: Unable to open the database file. |
7766| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7767| 14800032  | SQLite: Abort due to constraint violation. |
7768| 14800033  | SQLite: Data type mismatch. |
7769| 14800034  | SQLite: Library used incorrectly. |
7770
7771**返回值**:
7772
7773| 类型                                                    | 说明                                               |
7774| ------------------------------------------------------- | -------------------------------------------------- |
7775| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
7776
7777**示例:**
7778
7779```ts
7780import { BusinessError } from '@kit.BasicServicesKit';
7781
7782let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
7783predicates.equalTo("NAME", "Rose");
7784if (store != undefined) {
7785  (store as relationalStore.RdbStore).queryLockedRow(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then(async (resultSet: relationalStore.ResultSet) => {
7786    console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
7787    // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
7788    while (resultSet.goToNextRow()) {
7789      const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
7790      const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
7791      const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
7792      const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
7793      console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
7794    }
7795    // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
7796    resultSet.close();
7797  }).catch((err: BusinessError) => {
7798    console.error(`Query failed, code is ${err.code},message is ${err.message}`);
7799  });
7800}
7801```
7802### close<sup>12+</sup>
7803
7804close(): Promise&lt;void&gt;
7805
7806关闭数据库,使用Promise异步回调。
7807
7808**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7809
7810**返回值:**
7811
7812| 类型                | 说明          |
7813| ------------------- | ------------- |
7814| Promise&lt;void&gt; | Promise对象。 |
7815
7816**错误码:**
7817
7818以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
7819
7820| **错误码ID** | **错误信息**                                    |
7821| ------------ | ----------------------------------------------- |
7822| 401          | Parameter error. The store must not be nullptr. |
7823| 14800000     | Inner error.                                    |
7824
7825**示例:**
7826
7827```ts
7828import { BusinessError } from '@kit.BasicServicesKit';
7829
7830if (store != undefined) {
7831  (store as relationalStore.RdbStore).close().then(() => {
7832    console.info(`close succeeded`);
7833  }).catch((err: BusinessError) => {
7834    console.error(`close failed, code is ${err.code},message is ${err.message}`);
7835  });
7836}
7837```
7838
7839## ResultSet
7840
7841提供通过查询数据库生成的数据库结果集的访问方法。结果集是指用户调用关系型数据库查询接口之后返回的结果集合,提供了多种灵活的数据访问方式,以便用户获取各项数据。
7842
7843下列API示例中,都需先使用[query](#query14)、[querySql](#querysql14)、[remoteQuery](#remotequery-1)、[queryLockedRow](#querylockedrow12)中任一方法获取到ResultSet实例,再通过此实例调用对应方法。
7844
7845### 属性
7846
7847**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7848
7849| 名称         | 类型            | 必填 | 说明                             |
7850| ------------ | ------------------- | ---- | -------------------------------- |
7851| columnNames  | Array&lt;string&gt; | 是   | 获取结果集中所有列的名称。       |
7852| columnCount  | number              | 是   | 获取结果集中列的数量。             |
7853| rowCount     | number              | 是   | 获取结果集中行的数量。             |
7854| rowIndex     | number              | 是   | 获取结果集当前行的索引位置,默认值为-1。索引位置下标从0开始。 |
7855| isAtFirstRow | boolean             | 是   | 检查结果集指针是否位于第一行(行索引为0),true表示位于第一行,false表示不位于第一行。 |
7856| isAtLastRow  | boolean             | 是   | 检查结果集指针是否位于最后一行,true表示位于最后一行,false表示不位于最后一行。 |
7857| isEnded      | boolean             | 是   | 检查结果集指针是否位于最后一行之后,true表示位于最后一行之后,false表示不位于最后一行之后。 |
7858| isStarted    | boolean             | 是   | 检查指针是否移动过,true表示指针已移动过,false表示指针未移动过。             |
7859| isClosed     | boolean             | 是   | 检查当前结果集是否关闭,true表示结果集已关闭,false表示结果集未关闭。         |
7860
7861### getColumnIndex
7862
7863getColumnIndex(columnName: string): number
7864
7865根据指定的列名获取列索引。
7866
7867**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7868
7869**参数:**
7870
7871| 参数名     | 类型   | 必填 | 说明                       |
7872| ---------- | ------ | ---- | -------------------------- |
7873| columnName | string | 是   | 表示结果集中指定列的名称。 |
7874
7875**返回值:**
7876
7877| 类型   | 说明               |
7878| ------ | ------------------ |
7879| number | 返回指定列的索引。 |
7880
7881**错误码:**
7882
7883以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7884
7885| **错误码ID** | **错误信息**                                                 |
7886|-----------| ------------------------------------------------------------ |
7887| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7888| 14800000  | Inner error. |
7889| 14800011  | Database corrupted. |
7890| 14800013  | Column out of bounds. |
7891| 14800014  | Already closed. |
7892| 14800019  | The SQL must be a query statement. |
7893| 14800021  | SQLite: Generic error. |
7894| 14800022  | SQLite: Callback routine requested an abort. |
7895| 14800023  | SQLite: Access permission denied. |
7896| 14800024  | SQLite: The database file is locked. |
7897| 14800025  | SQLite: A table in the database is locked. |
7898| 14800026  | SQLite: The database is out of memory. |
7899| 14800027  | SQLite: Attempt to write a readonly database. |
7900| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7901| 14800029  | SQLite: The database is full. |
7902| 14800030  | SQLite: Unable to open the database file. |
7903| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7904| 14800032  | SQLite: Abort due to constraint violation. |
7905| 14800033  | SQLite: Data type mismatch. |
7906| 14800034  | SQLite: Library used incorrectly. |
7907
7908**示例:**
7909
7910```ts
7911if (resultSet != undefined) {
7912  const id = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("ID"));
7913  const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME"));
7914  const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE"));
7915  const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY"));
7916}
7917```
7918
7919### getColumnName
7920
7921getColumnName(columnIndex: number): string
7922
7923根据指定的列索引获取列名。
7924
7925**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7926
7927**参数:**
7928
7929| 参数名      | 类型   | 必填 | 说明                       |
7930| ----------- | ------ | ---- | -------------------------- |
7931| columnIndex | number | 是   | 表示结果集中指定列的索引。 |
7932
7933**返回值:**
7934
7935| 类型   | 说明               |
7936| ------ | ------------------ |
7937| string | 返回指定列的名称。 |
7938
7939**错误码:**
7940
7941以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7942
7943| **错误码ID** | **错误信息**                                                 |
7944|-----------| ------------------------------------------------------------ |
7945| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
7946| 14800000  | Inner error. |
7947| 14800011  | Database corrupted. |
7948| 14800013  | Column out of bounds. |
7949| 14800014  | Already closed. |
7950| 14800019  | The SQL must be a query statement. |
7951| 14800021  | SQLite: Generic error. |
7952| 14800022  | SQLite: Callback routine requested an abort. |
7953| 14800023  | SQLite: Access permission denied. |
7954| 14800024  | SQLite: The database file is locked. |
7955| 14800025  | SQLite: A table in the database is locked. |
7956| 14800026  | SQLite: The database is out of memory. |
7957| 14800027  | SQLite: Attempt to write a readonly database. |
7958| 14800028  | SQLite: Some kind of disk I/O error occurred. |
7959| 14800029  | SQLite: The database is full. |
7960| 14800030  | SQLite: Unable to open the database file. |
7961| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
7962| 14800032  | SQLite: Abort due to constraint violation. |
7963| 14800033  | SQLite: Data type mismatch. |
7964| 14800034  | SQLite: Library used incorrectly. |
7965
7966**示例:**
7967
7968```ts
7969if (resultSet != undefined) {
7970  const id = (resultSet as relationalStore.ResultSet).getColumnName(0);
7971  const name = (resultSet as relationalStore.ResultSet).getColumnName(1);
7972  const age = (resultSet as relationalStore.ResultSet).getColumnName(2);
7973}
7974```
7975
7976### getColumnType<sup>18+</sup>
7977
7978getColumnType(columnIdentifier: number | string): Promise\<ColumnType>
7979
7980根据指定的列索引或列名称获取列数据类型,使用Promise异步回调。
7981
7982**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
7983
7984**参数:**
7985
7986| 参数名           | 类型             | 必填 | 说明                                                         |
7987| ---------------- | ---------------- | ---- | ------------------------------------------------------------ |
7988| columnIdentifier | number \| string | 是   | 表示结果集中指定列的索引或名称。索引必须是非负整数,最大不能超过属性columnNames的长度。列名必须是属性columnNames内的名称。 |
7989
7990**返回值:**
7991
7992| 类型                                 | 说明                                |
7993| ------------------------------------ | ----------------------------------- |
7994| Promise<[ColumnType](#columntype18)> | Promise对象。返回指定列的数据类型。 |
7995
7996**错误码:**
7997
7998以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
7999
8000| **错误码ID** | **错误信息**                                                 |
8001| ------------ | ------------------------------------------------------------ |
8002| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8003| 14800000     | Inner error.                                                 |
8004| 14800011     | Database corrupted.                                          |
8005| 14800012     | Row out of bounds.                                           |
8006| 14800013     | Column out of bounds.                                        |
8007| 14800014     | Already closed.                                              |
8008| 14800019     | The SQL must be a query statement.                           |
8009| 14800021     | SQLite: Generic error.                                       |
8010| 14800022     | SQLite: Callback routine requested an abort.                 |
8011| 14800023     | SQLite: Access permission denied.                            |
8012| 14800024     | SQLite: The database file is locked.                         |
8013| 14800025     | SQLite: A table in the database is locked.                   |
8014| 14800026     | SQLite: The database is out of memory.                       |
8015| 14800027     | SQLite: Attempt to write a readonly database.                |
8016| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
8017| 14800029     | SQLite: The database is full.                                |
8018| 14800030     | SQLite: Unable to open the database file.                    |
8019| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
8020| 14800032     | SQLite: Abort due to constraint violation.                   |
8021| 14800033     | SQLite: Data type mismatch.                                  |
8022| 14800034     | SQLite: Library used incorrectly.                            |
8023
8024**示例:**
8025
8026```ts
8027if(resultSet != undefined) {
8028  let idType = await (resultSet as relationalStore.ResultSet).getColumnType("ID") as relationalStore.ColumnType;
8029  let nameType = await (resultSet as relationalStore.ResultSet).getColumnType("NAME") as relationalStore.ColumnType;
8030  let ageType = await (resultSet as relationalStore.ResultSet).getColumnType("AGE") as relationalStore.ColumnType;
8031  let salaryType = await (resultSet as relationalStore.ResultSet).getColumnType("SALARY") as relationalStore.ColumnType;
8032  let codesType = await (resultSet as relationalStore.ResultSet).getColumnType("CODES") as relationalStore.ColumnType;
8033  let identityType = await (resultSet as relationalStore.ResultSet).getColumnType(5) as relationalStore.ColumnType;
8034  let assetDataType = await (resultSet as relationalStore.ResultSet).getColumnType(6) as relationalStore.ColumnType;
8035  let assetsDataType = await (resultSet as relationalStore.ResultSet).getColumnType(7) as relationalStore.ColumnType;
8036  let floatArrayType = await (resultSet as relationalStore.ResultSet).getColumnType(8) as relationalStore.ColumnType;
8037}
8038```
8039
8040### getColumnTypeSync<sup>18+</sup>
8041
8042getColumnTypeSync(columnIdentifier: number | string): ColumnType
8043
8044根据指定的列索引或列名称获取列数据类型。
8045
8046**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8047
8048**参数:**
8049
8050| 参数名           | 类型             | 必填 | 说明                                                         |
8051| ---------------- | ---------------- | ---- | ------------------------------------------------------------ |
8052| columnIdentifier | number \| string | 是   | 表示结果集中指定列的索引或名称。索引必须是非负整数,最大不能超过属性columnNames的长度。列名必须是属性columnNames内的名称。 |
8053
8054**返回值:**
8055
8056| 类型                        | 说明                   |
8057| --------------------------- | ---------------------- |
8058| [ColumnType](#columntype18) | 返回指定列的数据类型。 |
8059
8060**错误码:**
8061
8062以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8063
8064| **错误码ID** | **错误信息**                                                 |
8065| ------------ | ------------------------------------------------------------ |
8066| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8067| 14800000     | Inner error.                                                 |
8068| 14800011     | Database corrupted.                                          |
8069| 14800012     | Row out of bounds.                                           |
8070| 14800013     | Column out of bounds.                                        |
8071| 14800014     | Already closed.                                              |
8072| 14800019     | The SQL must be a query statement.                           |
8073| 14800021     | SQLite: Generic error.                                       |
8074| 14800022     | SQLite: Callback routine requested an abort.                 |
8075| 14800023     | SQLite: Access permission denied.                            |
8076| 14800024     | SQLite: The database file is locked.                         |
8077| 14800025     | SQLite: A table in the database is locked.                   |
8078| 14800026     | SQLite: The database is out of memory.                       |
8079| 14800027     | SQLite: Attempt to write a readonly database.                |
8080| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
8081| 14800029     | SQLite: The database is full.                                |
8082| 14800030     | SQLite: Unable to open the database file.                    |
8083| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
8084| 14800032     | SQLite: Abort due to constraint violation.                   |
8085| 14800033     | SQLite: Data type mismatch.                                  |
8086| 14800034     | SQLite: Library used incorrectly.                            |
8087
8088**示例:**
8089
8090```ts
8091if(resultSet != undefined) {
8092  let idType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("ID") as relationalStore.ColumnType;
8093  let nameType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("NAME") as relationalStore.ColumnType;
8094  let ageType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("AGE") as relationalStore.ColumnType;
8095  let salaryType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("SALARY") as relationalStore.ColumnType;
8096  let codesType = (resultSet as relationalStore.ResultSet).getColumnTypeSync("CODES") as relationalStore.ColumnType;
8097  let identityType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(5) as relationalStore.ColumnType;
8098  let assetDataType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(6) as relationalStore.ColumnType;
8099  let assetsDataType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(7) as relationalStore.ColumnType;
8100  let floatArrayType = (resultSet as relationalStore.ResultSet).getColumnTypeSync(8) as relationalStore.ColumnType;
8101}
8102```
8103
8104### goTo
8105
8106goTo(offset:number): boolean
8107
8108指定相对当前结果集指针位置的偏移量,以移动结果集的指针位置。
8109
8110**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8111
8112**参数:**
8113
8114| 参数名 | 类型   | 必填 | 说明                         |
8115| ------ | ------ | ---- | ---------------------------- |
8116| offset | number | 是   | 表示相对当前结果集指针位置的偏移量,正值表示向后移动,负值表示向前移动。 |
8117
8118**返回值:**
8119
8120| 类型    | 说明                                          |
8121| ------- | --------------------------------------------- |
8122| boolean | 如果成功移动结果集,则为true;否则返回false。 |
8123
8124**错误码:**
8125
8126以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8127
8128| **错误码ID** | **错误信息**                                                 |
8129|-----------| ------------------------------------------------------------ |
8130| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8131| 14800000  | Inner error. |
8132| 14800011  | Database corrupted. |
8133| 14800012  | Row out of bounds. |
8134| 14800014  | Already closed. |
8135| 14800019  | The SQL must be a query statement. |
8136| 14800021  | SQLite: Generic error. |
8137| 14800022  | SQLite: Callback routine requested an abort. |
8138| 14800023  | SQLite: Access permission denied. |
8139| 14800024  | SQLite: The database file is locked. |
8140| 14800025  | SQLite: A table in the database is locked. |
8141| 14800026  | SQLite: The database is out of memory. |
8142| 14800027  | SQLite: Attempt to write a readonly database. |
8143| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8144| 14800029  | SQLite: The database is full. |
8145| 14800030  | SQLite: Unable to open the database file. |
8146| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8147| 14800032  | SQLite: Abort due to constraint violation. |
8148| 14800033  | SQLite: Data type mismatch. |
8149| 14800034  | SQLite: Library used incorrectly. |
8150
8151**示例:**
8152
8153```ts
8154if (resultSet != undefined) {
8155  (resultSet as relationalStore.ResultSet).goTo(1);
8156}
8157```
8158
8159### goToRow
8160
8161goToRow(position: number): boolean
8162
8163转到结果集的指定行。
8164
8165**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8166
8167**参数:**
8168
8169| 参数名   | 类型   | 必填 | 说明                     |
8170| -------- | ------ | ---- | ------------------------ |
8171| position | number | 是   | 表示要移动到的指定位置。 |
8172
8173**返回值:**
8174
8175| 类型    | 说明                                          |
8176| ------- | --------------------------------------------- |
8177| boolean | 如果成功移动结果集,则为true;否则返回false。 |
8178
8179**错误码:**
8180
8181以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8182
8183| **错误码ID** | **错误信息**                                                 |
8184|-----------| ------------------------------------------------------------ |
8185| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8186| 14800000  | Inner error. |
8187| 14800011  | Database corrupted. |
8188| 14800012  | Row out of bounds. |
8189| 14800014  | Already closed. |
8190| 14800019  | The SQL must be a query statement. |
8191| 14800021  | SQLite: Generic error. |
8192| 14800022  | SQLite: Callback routine requested an abort. |
8193| 14800023  | SQLite: Access permission denied. |
8194| 14800024  | SQLite: The database file is locked. |
8195| 14800025  | SQLite: A table in the database is locked. |
8196| 14800026  | SQLite: The database is out of memory. |
8197| 14800027  | SQLite: Attempt to write a readonly database. |
8198| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8199| 14800029  | SQLite: The database is full. |
8200| 14800030  | SQLite: Unable to open the database file. |
8201| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8202| 14800032  | SQLite: Abort due to constraint violation. |
8203| 14800033  | SQLite: Data type mismatch. |
8204| 14800034  | SQLite: Library used incorrectly. |
8205
8206**示例:**
8207
8208```ts
8209if (resultSet != undefined) {
8210  (resultSet as relationalStore.ResultSet).goToRow(5);
8211}
8212```
8213
8214### goToFirstRow
8215
8216goToFirstRow(): boolean
8217
8218
8219转到结果集的第一行。
8220
8221**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8222
8223**返回值:**
8224
8225| 类型    | 说明                                          |
8226| ------- | --------------------------------------------- |
8227| boolean | 如果成功移动结果集,则为true;否则返回false。 |
8228
8229**错误码:**
8230
8231以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8232
8233| **错误码ID** | **错误信息**                                                 |
8234|-----------| ------------------------------------------------------------ |
8235| 14800000  | Inner error. |
8236| 14800011  | Database corrupted. |
8237| 14800012  | Row out of bounds. |
8238| 14800014  | Already closed. |
8239| 14800019  | The SQL must be a query statement. |
8240| 14800021  | SQLite: Generic error. |
8241| 14800022  | SQLite: Callback routine requested an abort. |
8242| 14800023  | SQLite: Access permission denied. |
8243| 14800024  | SQLite: The database file is locked. |
8244| 14800025  | SQLite: A table in the database is locked. |
8245| 14800026  | SQLite: The database is out of memory. |
8246| 14800027  | SQLite: Attempt to write a readonly database. |
8247| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8248| 14800029  | SQLite: The database is full. |
8249| 14800030  | SQLite: Unable to open the database file. |
8250| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8251| 14800032  | SQLite: Abort due to constraint violation. |
8252| 14800033  | SQLite: Data type mismatch. |
8253| 14800034  | SQLite: Library used incorrectly. |
8254
8255**示例:**
8256
8257```ts
8258if (resultSet != undefined) {
8259  (resultSet as relationalStore.ResultSet).goToFirstRow();
8260}
8261```
8262
8263### goToLastRow
8264
8265goToLastRow(): boolean
8266
8267转到结果集的最后一行。
8268
8269**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8270
8271**返回值:**
8272
8273| 类型    | 说明                                          |
8274| ------- | --------------------------------------------- |
8275| boolean | 如果成功移动结果集,则为true;否则返回false。 |
8276
8277**错误码:**
8278
8279以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8280
8281| **错误码ID** | **错误信息**                                                 |
8282|-----------| ------------------------------------------------------------ |
8283| 14800000  | Inner error. |
8284| 14800011  | Database corrupted. |
8285| 14800012  | Row out of bounds. |
8286| 14800014  | Already closed. |
8287| 14800019  | The SQL must be a query statement. |
8288| 14800021  | SQLite: Generic error. |
8289| 14800022  | SQLite: Callback routine requested an abort. |
8290| 14800023  | SQLite: Access permission denied. |
8291| 14800024  | SQLite: The database file is locked. |
8292| 14800025  | SQLite: A table in the database is locked. |
8293| 14800026  | SQLite: The database is out of memory. |
8294| 14800027  | SQLite: Attempt to write a readonly database. |
8295| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8296| 14800029  | SQLite: The database is full. |
8297| 14800030  | SQLite: Unable to open the database file. |
8298| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8299| 14800032  | SQLite: Abort due to constraint violation. |
8300| 14800033  | SQLite: Data type mismatch. |
8301| 14800034  | SQLite: Library used incorrectly. |
8302
8303**示例:**
8304
8305```ts
8306if (resultSet != undefined) {
8307  (resultSet as relationalStore.ResultSet).goToLastRow();
8308}
8309```
8310
8311### goToNextRow
8312
8313goToNextRow(): boolean
8314
8315转到结果集的下一行。
8316
8317**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8318
8319**返回值:**
8320
8321| 类型    | 说明                                          |
8322| ------- | --------------------------------------------- |
8323| boolean | 如果成功移动结果集,则为true;否则返回false。 |
8324
8325**错误码:**
8326
8327以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8328
8329| **错误码ID** | **错误信息**                                                 |
8330|-----------| ------------------------------------------------------------ |
8331| 14800000  | Inner error. |
8332| 14800011  | Database corrupted. |
8333| 14800012  | Row out of bounds. |
8334| 14800014  | Already closed. |
8335| 14800019  | The SQL must be a query statement. |
8336| 14800021  | SQLite: Generic error. |
8337| 14800022  | SQLite: Callback routine requested an abort. |
8338| 14800023  | SQLite: Access permission denied. |
8339| 14800024  | SQLite: The database file is locked. |
8340| 14800025  | SQLite: A table in the database is locked. |
8341| 14800026  | SQLite: The database is out of memory. |
8342| 14800027  | SQLite: Attempt to write a readonly database. |
8343| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8344| 14800029  | SQLite: The database is full. |
8345| 14800030  | SQLite: Unable to open the database file. |
8346| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8347| 14800032  | SQLite: Abort due to constraint violation. |
8348| 14800033  | SQLite: Data type mismatch. |
8349| 14800034  | SQLite: Library used incorrectly. |
8350
8351**示例:**
8352
8353```ts
8354if (resultSet != undefined) {
8355  (resultSet as relationalStore.ResultSet).goToNextRow();
8356}
8357```
8358
8359### goToPreviousRow
8360
8361goToPreviousRow(): boolean
8362
8363转到结果集的上一行。
8364
8365**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8366
8367**返回值:**
8368
8369| 类型    | 说明                                          |
8370| ------- | --------------------------------------------- |
8371| boolean | 如果成功移动结果集,则为true;否则返回false。 |
8372
8373**错误码:**
8374
8375以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8376
8377| **错误码ID** | **错误信息**                                                 |
8378|-----------| ------------------------------------------------------------ |
8379| 14800000  | Inner error. |
8380| 14800011  | Database corrupted. |
8381| 14800012  | Row out of bounds. |
8382| 14800014  | Already closed. |
8383| 14800019  | The SQL must be a query statement. |
8384| 14800021  | SQLite: Generic error. |
8385| 14800022  | SQLite: Callback routine requested an abort. |
8386| 14800023  | SQLite: Access permission denied. |
8387| 14800024  | SQLite: The database file is locked. |
8388| 14800025  | SQLite: A table in the database is locked. |
8389| 14800026  | SQLite: The database is out of memory. |
8390| 14800027  | SQLite: Attempt to write a readonly database. |
8391| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8392| 14800029  | SQLite: The database is full. |
8393| 14800030  | SQLite: Unable to open the database file. |
8394| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8395| 14800032  | SQLite: Abort due to constraint violation. |
8396| 14800033  | SQLite: Data type mismatch. |
8397| 14800034  | SQLite: Library used incorrectly. |
8398
8399**示例:**
8400
8401```ts
8402if (resultSet != undefined) {
8403  (resultSet as relationalStore.ResultSet).goToPreviousRow();
8404}
8405```
8406
8407### getValue<sup>12+</sup>
8408
8409getValue(columnIndex: number): ValueType
8410
8411获取当前行中指定列的值,值类型如果是ValueType指定的任意类型,则会以对应类型返回指定类的值,否则返回14800000。
8412
8413**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8414
8415**参数:**
8416
8417| 参数名      | 类型   | 必填 | 说明                    |
8418| ----------- | ------ | ---- | ----------------------- |
8419| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8420
8421**返回值:**
8422
8423| 类型       | 说明                             |
8424| ---------- | -------------------------------- |
8425| [ValueType](#valuetype) | 表示允许的数据字段类型。 |
8426
8427**错误码:**
8428
8429以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8430
8431| **错误码ID** | **错误信息**     |
8432|-----------|---------|
8433| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8434| 14800000  | Inner error.      |
8435| 14800011  | Database corrupted.        |
8436| 14800012  | Row out of bounds.       |
8437| 14800013  | Column out of bounds.   |
8438| 14800014  | Already closed.       |
8439| 14800021  | SQLite: Generic error.    |
8440| 14800022  | SQLite: Callback routine requested an abort.     |
8441| 14800023  | SQLite: Access permission denied.    |
8442| 14800024  | SQLite: The database file is locked.    |
8443| 14800025  | SQLite: A table in the database is locked.  |
8444| 14800026  | SQLite: The database is out of memory.    |
8445| 14800027  | SQLite: Attempt to write a readonly database.    |
8446| 14800028  | SQLite: Some kind of disk I/O error occurred.    |
8447| 14800029  | SQLite: The database is full.   |
8448| 14800030  | SQLite: Unable to open the database file.    |
8449| 14800031  | SQLite: TEXT or BLOB exceeds size limit.    |
8450| 14800032  | SQLite: Abort due to constraint violation.   |
8451| 14800033  | SQLite: Data type mismatch.      |
8452| 14800034  | SQLite: Library used incorrectly.    |
8453
8454**示例:**
8455
8456```ts
8457if (resultSet != undefined) {
8458  const codes = (resultSet as relationalStore.ResultSet).getValue((resultSet as relationalStore.ResultSet).getColumnIndex("BIGINT_COLUMN"));
8459}
8460```
8461
8462### getBlob
8463
8464getBlob(columnIndex: number): Uint8Array
8465
8466
8467以字节数组的形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成字节数组类型返回指定值,如果该列内容为空时,会返回空字节数组,其他类型则返回14800000。
8468
8469**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8470
8471**参数:**
8472
8473| 参数名      | 类型   | 必填 | 说明                    |
8474| ----------- | ------ | ---- | ----------------------- |
8475| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8476
8477**返回值:**
8478
8479| 类型       | 说明                             |
8480| ---------- | -------------------------------- |
8481| Uint8Array | 以字节数组的形式返回指定列的值。 |
8482
8483**错误码:**
8484
8485以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8486
8487| **错误码ID** | **错误信息**                                                 |
8488|-----------| ------------------------------------------------------------ |
8489| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8490| 14800000  | Inner error. |
8491| 14800011  | Database corrupted. |
8492| 14800012  | Row out of bounds. |
8493| 14800013  | Column out of bounds. |
8494| 14800014  | Already closed. |
8495| 14800021  | SQLite: Generic error. |
8496| 14800022  | SQLite: Callback routine requested an abort. |
8497| 14800023  | SQLite: Access permission denied. |
8498| 14800024  | SQLite: The database file is locked. |
8499| 14800025  | SQLite: A table in the database is locked. |
8500| 14800026  | SQLite: The database is out of memory. |
8501| 14800027  | SQLite: Attempt to write a readonly database. |
8502| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8503| 14800029  | SQLite: The database is full. |
8504| 14800030  | SQLite: Unable to open the database file. |
8505| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8506| 14800032  | SQLite: Abort due to constraint violation. |
8507| 14800033  | SQLite: Data type mismatch. |
8508| 14800034  | SQLite: Library used incorrectly. |
8509
8510**示例:**
8511
8512```ts
8513if (resultSet != undefined) {
8514  const codes = (resultSet as relationalStore.ResultSet).getBlob((resultSet as relationalStore.ResultSet).getColumnIndex("CODES"));
8515}
8516```
8517
8518### getString
8519
8520getString(columnIndex: number): string
8521
8522以字符串形式获取当前行中指定列的值,如果当前列中的值为INTEGER、DOUBLE、TEXT、BLOB类型,会以字符串形式返回指定值,如果是当前列中的值为INTEGER,并且为空,则会返回空字符串"",其他类型则返回14800000。如果当前列中的值为DOUBLE类型,可能存在精度的丢失,建议使用[getDouble](#getdouble)接口获取。
8523
8524**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8525
8526**参数:**
8527
8528| 参数名      | 类型   | 必填 | 说明                    |
8529| ----------- | ------ | ---- | ----------------------- |
8530| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8531
8532**返回值:**
8533
8534| 类型   | 说明                         |
8535| ------ | ---------------------------- |
8536| string | 以字符串形式返回指定列的值。 |
8537
8538**错误码:**
8539
8540以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8541
8542| **错误码ID** | **错误信息**                                                 |
8543|-----------| ------------------------------------------------------------ |
8544| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8545| 14800000  | Inner error. |
8546| 14800011  | Database corrupted. |
8547| 14800012  | Row out of bounds. |
8548| 14800013  | Column out of bounds. |
8549| 14800014  | Already closed. |
8550| 14800021  | SQLite: Generic error. |
8551| 14800022  | SQLite: Callback routine requested an abort. |
8552| 14800023  | SQLite: Access permission denied. |
8553| 14800024  | SQLite: The database file is locked. |
8554| 14800025  | SQLite: A table in the database is locked. |
8555| 14800026  | SQLite: The database is out of memory. |
8556| 14800027  | SQLite: Attempt to write a readonly database. |
8557| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8558| 14800029  | SQLite: The database is full. |
8559| 14800030  | SQLite: Unable to open the database file. |
8560| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8561| 14800032  | SQLite: Abort due to constraint violation. |
8562| 14800033  | SQLite: Data type mismatch. |
8563| 14800034  | SQLite: Library used incorrectly. |
8564
8565**示例:**
8566
8567```ts
8568if (resultSet != undefined) {
8569  const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME"));
8570}
8571```
8572
8573### getLong
8574
8575getLong(columnIndex: number): number
8576
8577以Long形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成Long类型返回指定值,如果该列内容为空时,会返回0,其他类型则返回14800000。
8578
8579**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8580
8581**参数:**
8582
8583| 参数名      | 类型   | 必填 | 说明                    |
8584| ----------- | ------ | ---- | ----------------------- |
8585| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8586
8587**返回值:**
8588
8589| 类型   | 说明                                                         |
8590| ------ | ------------------------------------------------------------ |
8591| number | 以Long形式返回指定列的值。<br>该接口支持的数据范围是:Number.MIN_SAFE_INTEGER ~ Number.MAX_SAFE_INTEGER,若超出该范围,建议使用[getDouble](#getdouble)。 |
8592
8593**错误码:**
8594
8595以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8596
8597| **错误码ID** | **错误信息**                                                 |
8598|-----------| ------------------------------------------------------------ |
8599| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8600| 14800000  | Inner error. |
8601| 14800011  | Database corrupted. |
8602| 14800012  | Row out of bounds. |
8603| 14800013  | Column out of bounds. |
8604| 14800014  | Already closed. |
8605| 14800021  | SQLite: Generic error. |
8606| 14800022  | SQLite: Callback routine requested an abort. |
8607| 14800023  | SQLite: Access permission denied. |
8608| 14800024  | SQLite: The database file is locked. |
8609| 14800025  | SQLite: A table in the database is locked. |
8610| 14800026  | SQLite: The database is out of memory. |
8611| 14800027  | SQLite: Attempt to write a readonly database. |
8612| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8613| 14800029  | SQLite: The database is full. |
8614| 14800030  | SQLite: Unable to open the database file. |
8615| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8616| 14800032  | SQLite: Abort due to constraint violation. |
8617| 14800033  | SQLite: Data type mismatch. |
8618| 14800034  | SQLite: Library used incorrectly. |
8619
8620**示例:**
8621
8622```ts
8623if (resultSet != undefined) {
8624  const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE"));
8625}
8626```
8627
8628### getDouble
8629
8630getDouble(columnIndex: number): number
8631
8632以double形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成double类型返回指定值,如果该列内容为空时,会返回0.0,其他类型则返回14800000。
8633
8634**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8635
8636**参数:**
8637
8638| 参数名      | 类型   | 必填 | 说明                    |
8639| ----------- | ------ | ---- | ----------------------- |
8640| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8641
8642**返回值:**
8643
8644| 类型   | 说明                         |
8645| ------ | ---------------------------- |
8646| number | 以double形式返回指定列的值。 |
8647
8648**错误码:**
8649
8650以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8651
8652| **错误码ID** | **错误信息**                                                 |
8653|-----------| ------------------------------------------------------------ |
8654| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8655| 14800000  | Inner error. |
8656| 14800011  | Database corrupted. |
8657| 14800012  | Row out of bounds. |
8658| 14800013  | Column out of bounds. |
8659| 14800014  | Already closed. |
8660| 14800021  | SQLite: Generic error. |
8661| 14800022  | SQLite: Callback routine requested an abort. |
8662| 14800023  | SQLite: Access permission denied. |
8663| 14800024  | SQLite: The database file is locked. |
8664| 14800025  | SQLite: A table in the database is locked. |
8665| 14800026  | SQLite: The database is out of memory. |
8666| 14800027  | SQLite: Attempt to write a readonly database. |
8667| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8668| 14800029  | SQLite: The database is full. |
8669| 14800030  | SQLite: Unable to open the database file. |
8670| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8671| 14800032  | SQLite: Abort due to constraint violation. |
8672| 14800033  | SQLite: Data type mismatch. |
8673| 14800034  | SQLite: Library used incorrectly. |
8674
8675**示例:**
8676
8677```ts
8678if (resultSet != undefined) {
8679  const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY"));
8680}
8681```
8682
8683### getAsset<sup>10+</sup>
8684
8685getAsset(columnIndex: number): Asset
8686
8687以[Asset](#asset10)形式获取当前行中指定列的值,如果当前列的数据类型为Asset类型,会以Asset类型返回指定值,如果当前列中的值为null时,会返回null,其他类型则返回14800000。
8688
8689**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8690
8691**参数:**
8692
8693| 参数名         | 类型     | 必填  | 说明           |
8694| ----------- | ------ | --- | ------------ |
8695| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8696
8697**返回值:**
8698
8699| 类型              | 说明                         |
8700| --------------- | -------------------------- |
8701| [Asset](#asset10) | 以Asset形式返回指定列的值。 |
8702
8703**错误码:**
8704
8705以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8706
8707| **错误码ID** | **错误信息**                                                 |
8708|-----------| ------------------------------------------------------------ |
8709| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8710| 14800000  | Inner error. |
8711| 14800011  | Database corrupted. |
8712| 14800012  | Row out of bounds. |
8713| 14800013  | Column out of bounds. |
8714| 14800014  | Already closed. |
8715| 14800021  | SQLite: Generic error. |
8716| 14800022  | SQLite: Callback routine requested an abort. |
8717| 14800023  | SQLite: Access permission denied. |
8718| 14800024  | SQLite: The database file is locked. |
8719| 14800025  | SQLite: A table in the database is locked. |
8720| 14800026  | SQLite: The database is out of memory. |
8721| 14800027  | SQLite: Attempt to write a readonly database. |
8722| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8723| 14800029  | SQLite: The database is full. |
8724| 14800030  | SQLite: Unable to open the database file. |
8725| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8726| 14800032  | SQLite: Abort due to constraint violation. |
8727| 14800033  | SQLite: Data type mismatch. |
8728| 14800034  | SQLite: Library used incorrectly. |
8729
8730**示例:**
8731
8732```ts
8733if (resultSet != undefined) {
8734  const doc = (resultSet as relationalStore.ResultSet).getAsset((resultSet as relationalStore.ResultSet).getColumnIndex("DOC"));
8735}
8736```
8737
8738### getAssets<sup>10+</sup>
8739
8740getAssets(columnIndex: number): Assets
8741
8742以[Assets](#assets10)形式获取当前行中指定列的值,如果当前列的数据类型为Assets类型,会以Assets类型返回指定值,如果当前列中的值为null时,会返回null,其他类型则返回14800000。
8743
8744**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8745
8746**参数:**
8747
8748| 参数名         | 类型     | 必填  | 说明           |
8749| ----------- | ------ | --- | ------------ |
8750| columnIndex | number | 是   | 指定的列索引,从0开始。 |
8751
8752**返回值:**
8753
8754| 类型              | 说明                           |
8755| ---------------- | ---------------------------- |
8756| [Assets](#assets10)| 以Assets形式返回指定列的值。 |
8757
8758**错误码:**
8759
8760以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8761
8762| **错误码ID** | **错误信息**                                                 |
8763|-----------| ------------------------------------------------------------ |
8764| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8765| 14800000  | Inner error. |
8766| 14800011  | Database corrupted. |
8767| 14800012  | Row out of bounds. |
8768| 14800013  | Column out of bounds. |
8769| 14800014  | Already closed. |
8770| 14800021  | SQLite: Generic error. |
8771| 14800022  | SQLite: Callback routine requested an abort. |
8772| 14800023  | SQLite: Access permission denied. |
8773| 14800024  | SQLite: The database file is locked. |
8774| 14800025  | SQLite: A table in the database is locked. |
8775| 14800026  | SQLite: The database is out of memory. |
8776| 14800027  | SQLite: Attempt to write a readonly database. |
8777| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8778| 14800029  | SQLite: The database is full. |
8779| 14800030  | SQLite: Unable to open the database file. |
8780| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8781| 14800032  | SQLite: Abort due to constraint violation. |
8782| 14800033  | SQLite: Data type mismatch. |
8783| 14800034  | SQLite: Library used incorrectly. |
8784
8785**示例:**
8786
8787```ts
8788if (resultSet != undefined) {
8789  const docs = (resultSet as relationalStore.ResultSet).getAssets((resultSet as relationalStore.ResultSet).getColumnIndex("DOCS"));
8790}
8791```
8792
8793### getRow<sup>11+</sup>
8794
8795getRow(): ValuesBucket
8796
8797获取当前行。
8798
8799**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8800
8801**返回值:**
8802
8803| 类型              | 说明                           |
8804| ---------------- | ---------------------------- |
8805| [ValuesBucket](#valuesbucket) | 返回指定行的值。 |
8806
8807**错误码:**
8808
8809以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8810
8811| **错误码ID** | **错误信息**                                                 |
8812|-----------| ------------------------------------------------------------ |
8813| 14800000  | Inner error. |
8814| 14800011  | Database corrupted. |
8815| 14800012  | Row out of bounds. |
8816| 14800013  | Column out of bounds. |
8817| 14800014  | Already closed. |
8818| 14800021  | SQLite: Generic error. |
8819| 14800022  | SQLite: Callback routine requested an abort. |
8820| 14800023  | SQLite: Access permission denied. |
8821| 14800024  | SQLite: The database file is locked. |
8822| 14800025  | SQLite: A table in the database is locked. |
8823| 14800026  | SQLite: The database is out of memory. |
8824| 14800027  | SQLite: Attempt to write a readonly database. |
8825| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8826| 14800029  | SQLite: The database is full. |
8827| 14800030  | SQLite: Unable to open the database file. |
8828| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8829| 14800032  | SQLite: Abort due to constraint violation. |
8830| 14800033  | SQLite: Data type mismatch. |
8831| 14800034  | SQLite: Library used incorrectly. |
8832
8833**示例:**
8834
8835```ts
8836if (resultSet != undefined) {
8837  const row = (resultSet as relationalStore.ResultSet).getRow();
8838}
8839```
8840
8841### getRows<sup>18+</sup>
8842
8843getRows(maxCount: number, position?: number): Promise<Array\<ValuesBucket>>
8844
8845从结果集中获取指定数量的数据,使用Promise异步回调。禁止与[ResultSet](#resultset)的其它接口并发调用,否则获取的数据可能非预期。
8846
8847**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8848
8849**参数:**
8850
8851| 参数名      | 类型   | 必填 | 说明                    |
8852| ----------- | ------ | ---- | ----------------------- |
8853| maxCount | number | 是   | 正整数,指定要从结果集中获取数据的条数。不为正整数则参数非法,抛出错误码401。 |
8854| position | number | 否   | 非负整数,指定从结果集中获取数据的起始位置,不填则从结果集的当前行(默认首次获取数据时为当前结果集的第一行)开始获取数据。不为非负整数则参数非法,抛出错误码401。 |
8855
8856
8857**返回值:**
8858
8859| 类型              | 说明                           |
8860| ---------------- | ---------------------------- |
8861| Promise<Array<[ValuesBucket](#valuesbucket)>> | 返回maxCount条数据,剩余数据不足maxCount条则返回剩余数据,返回空数组时代表已经遍历到结果集的末尾。 |
8862
8863**错误码:**
8864
8865以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8866
8867| **错误码ID** | **错误信息**                                                 |
8868|-----------| ------------------------------------------------------------ |
8869| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
8870| 14800000  | Inner error. |
8871| 14800011  | Database corrupted. |
8872| 14800012  | Row out of bounds. |
8873| 14800013  | Column out of bounds. |
8874| 14800014  | Already closed. |
8875| 14800021  | SQLite: Generic error. |
8876| 14800022  | SQLite: Callback routine requested an abort. |
8877| 14800023  | SQLite: Access permission denied. |
8878| 14800024  | SQLite: The database file is locked. |
8879| 14800025  | SQLite: A table in the database is locked. |
8880| 14800026  | SQLite: The database is out of memory. |
8881| 14800028  | SQLite: Some kind of disk I/O error occurred. |
8882| 14800029  | SQLite: The database is full. |
8883| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
8884| 14800032  | SQLite: Abort due to constraint violation. |
8885| 14800033  | SQLite: Data type mismatch. |
8886
8887**示例:**
8888
8889```ts
8890// 以查到100条数据为例
8891async function proccessRows(resultSet: relationalStore.ResultSet) {
8892  // 示例1:仅指定maxCount
8893  if (resultSet != undefined) {
8894    let rows: Array<relationalStore.ValuesBucket>;
8895    let maxCount: number = 50;
8896    // 从结果集的当前行(默认首次获取数据时为当前结果集的第一行,后续为上次获取数据结束位置的下一行)开始获取数据
8897    // getRows会自动移动结果集当前行到上次getRows获取结束位置的下一行,无需使用goToFirstRow、goToNextRow等接口移动
8898    while ((rows = await (resultSet as relationalStore.ResultSet).getRows(maxCount)).length != 0) {
8899      console.info(JSON.stringify(rows[0]));
8900    }
8901  }
8902
8903  // 示例2:指定maxCount和起始的position
8904  if (resultSet != undefined) {
8905    let rows: Array<relationalStore.ValuesBucket>;
8906    let maxCount: number = 50;
8907    let position: number = 50;
8908    while ((rows = await (resultSet as relationalStore.ResultSet).getRows(maxCount, position)).length != 0) {
8909      console.info(JSON.stringify(rows[0]));
8910      position += rows.length;
8911    }
8912  }
8913}
8914```
8915
8916### getSendableRow<sup>12+</sup>
8917
8918getSendableRow(): sendableRelationalStore.ValuesBucket
8919
8920获取当前行数据的sendable形式,用于跨线程传递使用。
8921
8922**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
8923
8924**返回值:**
8925
8926| 类型                                                                                           | 说明                                           |
8927| ---------------------------------------------------------------------------------------------- | ---------------------------------------------- |
8928| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | 当前行数据的sendable形式,用于跨线程传递使用。 |
8929
8930**错误码:**
8931
8932以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
8933
8934| **错误码ID** | **错误信息**                                  |
8935| ------------ | --------------------------------------------- |
8936| 14800000     | Inner error.                                  |
8937| 14800011     | Database corrupted.                           |
8938| 14800012     | Row out of bounds.                            |
8939| 14800013     | Column out of bounds.                         |
8940| 14800014     | Already closed.                               |
8941| 14800021     | SQLite: Generic error.                        |
8942| 14800022     | SQLite: Callback routine requested an abort.  |
8943| 14800023     | SQLite: Access permission denied.             |
8944| 14800024     | SQLite: The database file is locked.          |
8945| 14800025     | SQLite: A table in the database is locked.    |
8946| 14800026     | SQLite: The database is out of memory.        |
8947| 14800027     | SQLite: Attempt to write a readonly database. |
8948| 14800028     | SQLite: Some kind of disk I/O error occurred. |
8949| 14800029     | SQLite: The database is full.                 |
8950| 14800030     | SQLite: Unable to open the database file.     |
8951| 14800031     | SQLite: TEXT or BLOB exceeds size limit.      |
8952| 14800032     | SQLite: Abort due to constraint violation.    |
8953| 14800033     | SQLite: Data type mismatch.                   |
8954| 14800034     | SQLite: Library used incorrectly.             |
8955
8956**示例:**
8957
8958<!--code_no_check-->
8959```ts
8960import { window } from '@kit.ArkUI';
8961import { UIAbility } from '@kit.AbilityKit';
8962import { relationalStore } from '@kit.ArkData';
8963import { taskpool } from '@kit.ArkTS';
8964import type ctx from '@ohos.app.ability.common';
8965import { sendableRelationalStore } from '@kit.ArkData';
8966
8967@Concurrent
8968async function getDataByName(name: string, context: ctx.UIAbilityContext) {
8969  const STORE_CONFIG: relationalStore.StoreConfig = {
8970    name: "RdbTest.db",
8971    securityLevel: relationalStore.SecurityLevel.S3
8972  };
8973  const store = await relationalStore.getRdbStore(context, STORE_CONFIG);
8974  const predicates = new relationalStore.RdbPredicates("EMPLOYEE");
8975  predicates.equalTo("NAME", name);
8976  const resultSet = store.querySync(predicates);
8977
8978  if (resultSet.rowCount > 0) {
8979    resultSet.goToFirstRow();
8980    const sendableValuesBucket = resultSet.getSendableRow();
8981    return sendableValuesBucket;
8982  } else {
8983    return null;
8984  }
8985}
8986
8987export default class EntryAbility extends UIAbility {
8988  async onWindowStageCreate(windowStage: window.WindowStage) {
8989    const task = new taskpool.Task(getDataByName, 'Lisa', this.context);
8990    const sendableValuesBucket = await taskpool.execute(task) as sendableRelationalStore.ValuesBucket;
8991
8992    if (sendableValuesBucket) {
8993      const columnCount = sendableValuesBucket.size;
8994      const age = sendableValuesBucket.get('age');
8995      const name = sendableValuesBucket.get('name');
8996      console.info(`Query data in taskpool succeeded, name is "${name}", age is "${age}"`);
8997    }
8998  }
8999}
9000```
9001
9002### isColumnNull
9003
9004isColumnNull(columnIndex: number): boolean
9005
9006检查当前行中指定列的值是否为null。
9007
9008**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9009
9010**参数:**
9011
9012| 参数名      | 类型   | 必填 | 说明                    |
9013| ----------- | ------ | ---- | ----------------------- |
9014| columnIndex | number | 是   | 指定的列索引,从0开始。 |
9015
9016**返回值:**
9017
9018| 类型    | 说明                                                      |
9019| ------- | --------------------------------------------------------- |
9020| boolean | 如果当前行中指定列的值为null,则返回true,否则返回false。 |
9021
9022**错误码:**
9023
9024以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9025
9026| **错误码ID** | **错误信息**                                                 |
9027|-----------| ------------------------------------------------------- |
9028| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9029| 14800000  | Inner error. |
9030| 14800011  | Database corrupted. |
9031| 14800012  | Row out of bounds. |
9032| 14800013  | Column out of bounds. |
9033| 14800014  | Already closed. |
9034| 14800021  | SQLite: Generic error. |
9035| 14800022  | SQLite: Callback routine requested an abort. |
9036| 14800023  | SQLite: Access permission denied. |
9037| 14800024  | SQLite: The database file is locked. |
9038| 14800025  | SQLite: A table in the database is locked. |
9039| 14800026  | SQLite: The database is out of memory. |
9040| 14800027  | SQLite: Attempt to write a readonly database. |
9041| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9042| 14800029  | SQLite: The database is full. |
9043| 14800030  | SQLite: Unable to open the database file. |
9044| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9045| 14800032  | SQLite: Abort due to constraint violation. |
9046| 14800033  | SQLite: Data type mismatch. |
9047| 14800034  | SQLite: Library used incorrectly. |
9048
9049**示例:**
9050
9051```ts
9052if (resultSet != undefined) {
9053  const isColumnNull = (resultSet as relationalStore.ResultSet).isColumnNull((resultSet as relationalStore.ResultSet).getColumnIndex("CODES"));
9054}
9055```
9056
9057### close
9058
9059close(): void
9060
9061关闭结果集,若不关闭可能会引起fd泄露和内存泄露。
9062
9063**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9064
9065**示例:**
9066
9067```ts
9068if (resultSet != undefined) {
9069  (resultSet as relationalStore.ResultSet).close();
9070}
9071```
9072
9073**错误码:**
9074
9075以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。
9076
9077| **错误码ID** | **错误信息**                                                 |
9078|-----------| ------------------------------------------------------------ |
9079| 14800000  | Inner error. |
9080| 14800012  | Row out of bounds. |
9081
9082## Transaction<sup>14+</sup>
9083
9084提供以事务方式管理数据库的方法。事务对象是通过[createTransaction](#createtransaction14)接口创建的,不同事务对象之间的操作是隔离的,不同类型事务的区别见[TransactionType](#transactiontype14) 。
9085
9086当前关系型数据库同一时刻只支持一个写事务,所以如果当前[RdbStore](#rdbstore)存在写事务未释放,创建IMMEDIATE或EXCLUSIVE事务会返回14800024错误码。如果是创建的DEFERRED事务,则可能在首次使用DEFERRED事务调用写操作时返回14800024错误码。通过IMMEDIATE或EXCLUSIVE创建写事务或者DEFERRED事务升级到写事务之后,[RdbStore](#rdbstore)的写操作也会返回14800024错误码。
9087
9088当事务并发量较高且写事务持续时间较长时,返回14800024错误码的次数可能会变多,开发者可以通过减少事务占用时长减少14800024出现的次数,也可以通过重试的方式处理14800024错误码。
9089
9090**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9091
9092**示例:**
9093
9094```ts
9095import { UIAbility } from '@kit.AbilityKit';
9096import { BusinessError } from '@kit.BasicServicesKit';
9097import { window } from '@kit.ArkUI';
9098
9099let store: relationalStore.RdbStore | undefined = undefined;
9100
9101class EntryAbility extends UIAbility {
9102  async onWindowStageCreate(windowStage: window.WindowStage) {
9103    const STORE_CONFIG: relationalStore.StoreConfig = {
9104      name: "RdbTest.db",
9105      securityLevel: relationalStore.SecurityLevel.S3
9106    };
9107
9108    await relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => {
9109      store = rdbStore;
9110      console.info('Get RdbStore successfully.');
9111    }).catch((err: BusinessError) => {
9112      console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
9113    });
9114
9115    if (store != undefined) {
9116      (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9117        console.info(`createTransaction success`);
9118        // 成功获取到事务对象后执行后续操作
9119      }).catch((err: BusinessError) => {
9120        console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9121      });
9122    }
9123  }
9124}
9125```
9126
9127### commit<sup>14+</sup>
9128
9129commit(): Promise&lt;void&gt;
9130
9131提交已执行的SQL语句。如果是使用异步接口执行sql语句,请确保异步接口执行完成之后再调用commit接口,否则可能会丢失SQL操作。调用commit接口之后,该Transaction对象及创建的ResultSet对象都会被关闭。
9132
9133**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9134
9135**返回值**:
9136
9137| 类型                | 说明                      |
9138| ------------------- | ------------------------- |
9139| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9140
9141**错误码:**
9142
9143以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9144
9145| **错误码ID** | **错误信息**                                                 |
9146|-----------| ------------------------------------------------------------ |
9147| 14800000  | Inner error. |
9148| 14800011  | Database corrupted. |
9149| 14800014  | Already closed. |
9150| 14800023  | SQLite: Access permission denied. |
9151| 14800024  | SQLite: The database file is locked. |
9152| 14800026  | SQLite: The database is out of memory. |
9153| 14800027  | SQLite: Attempt to write a readonly database. |
9154| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9155| 14800029  | SQLite: The database is full. |
9156
9157**示例:**
9158
9159```ts
9160let value1 = "Lisa";
9161let value2 = 18;
9162let value3 = 100.5;
9163let value4 = new Uint8Array([1, 2, 3]);
9164
9165if (store != undefined) {
9166  const valueBucket: relationalStore.ValuesBucket = {
9167    'NAME': value1,
9168    'AGE': value2,
9169    'SALARY': value3,
9170    'CODES': value4
9171  };
9172  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9173    transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => {
9174      transaction.commit();
9175    }).catch((e: BusinessError) => {
9176      transaction.rollback();
9177      console.error(`execute sql failed, code is ${e.code},message is ${e.message}`);
9178    });
9179  }).catch((err: BusinessError) => {
9180    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9181  });
9182}
9183```
9184
9185### rollback<sup>14+</sup>
9186
9187rollback(): Promise&lt;void&gt;
9188
9189回滚已经执行的SQL语句。调用rollback接口之后,该Transaction对象及创建的ResultSet对象都会被关闭。
9190
9191**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9192
9193**返回值**:
9194
9195| 类型                | 说明                      |
9196| ------------------- | ------------------------- |
9197| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
9198
9199**错误码:**
9200
9201以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9202
9203| **错误码ID** | **错误信息**                                                 |
9204|-----------| ------------------------------------------------------------ |
9205| 14800000  | Inner error. |
9206| 14800011  | Database corrupted. |
9207| 14800014  | Already closed. |
9208| 14800023  | SQLite: Access permission denied. |
9209| 14800024  | SQLite: The database file is locked. |
9210| 14800026  | SQLite: The database is out of memory. |
9211| 14800027  | SQLite: Attempt to write a readonly database. |
9212| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9213| 14800029  | SQLite: The database is full. |
9214
9215**示例:**
9216
9217```ts
9218if (store != undefined) {
9219  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9220    transaction.execute("DELETE FROM TEST WHERE age = ? OR age = ?", ["18", "20"]).then(() => {
9221      transaction.commit();
9222    }).catch((e: BusinessError) => {
9223      transaction.rollback();
9224      console.error(`execute sql failed, code is ${e.code},message is ${e.message}`);
9225    });
9226  }).catch((err: BusinessError) => {
9227    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9228  });
9229}
9230```
9231
9232### insert<sup>14+</sup>
9233
9234insert(table: string, values: ValuesBucket, conflict?: ConflictResolution): Promise&lt;number&gt;
9235
9236向目标表中插入一行数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
9237
9238**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9239
9240**参数:**
9241
9242| 参数名   | 类型                                        | 必填 | 说明                       |
9243| -------- | ------------------------------------------- | ---- | -------------------------- |
9244| table    | string                                      | 是   | 指定的目标表名。           |
9245| values   | [ValuesBucket](#valuesbucket)               | 是   | 表示要插入到表中的数据行。 |
9246| conflict | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。         |
9247
9248**返回值**:
9249
9250| 类型                  | 说明                                              |
9251| --------------------- | ------------------------------------------------- |
9252| Promise&lt;number&gt; | Promise对象。如果操作成功,返回行ID;否则返回-1。 |
9253
9254**错误码:**
9255
9256以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9257
9258| **错误码ID** | **错误信息**                                                 |
9259|-----------| ------------------------------------------------------------ |
9260| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9261| 14800000  | Inner error. |
9262| 14800011  | Database corrupted. |
9263| 14800014  | Already closed. |
9264| 14800021  | SQLite: Generic error. |
9265| 14800023  | SQLite: Access permission denied. |
9266| 14800024  | SQLite: The database file is locked. |
9267| 14800025  | SQLite: A table in the database is locked. |
9268| 14800026  | SQLite: The database is out of memory. |
9269| 14800027  | SQLite: Attempt to write a readonly database. |
9270| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9271| 14800029  | SQLite: The database is full. |
9272| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9273| 14800033  | SQLite: Data type mismatch. |
9274| 14800047  | The WAL file size exceeds the default limit. |
9275
9276**示例:**
9277
9278```ts
9279let value1 = "Lisa";
9280let value2 = 18;
9281let value3 = 100.5;
9282let value4 = new Uint8Array([1, 2, 3, 4, 5]);
9283
9284// 以下三种方式可用
9285const valueBucket1: relationalStore.ValuesBucket = {
9286  'NAME': value1,
9287  'AGE': value2,
9288  'SALARY': value3,
9289  'CODES': value4
9290};
9291const valueBucket2: relationalStore.ValuesBucket = {
9292  NAME: value1,
9293  AGE: value2,
9294  SALARY: value3,
9295  CODES: value4
9296};
9297const valueBucket3: relationalStore.ValuesBucket = {
9298  "NAME": value1,
9299  "AGE": value2,
9300  "SALARY": value3,
9301  "CODES": value4
9302};
9303
9304if (store != undefined) {
9305  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9306    transaction.insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => {
9307      transaction.commit();
9308      console.info(`Insert is successful, rowId = ${rowId}`);
9309    }).catch((e: BusinessError) => {
9310      transaction.rollback();
9311      console.error(`Insert is failed, code is ${e.code},message is ${e.message}`);
9312    });
9313  }).catch((err: BusinessError) => {
9314    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9315  });
9316}
9317```
9318
9319### insertSync<sup>14+</sup>
9320
9321insertSync(table: string, values: ValuesBucket | sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution): number
9322
9323向目标表中插入一行数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
9324
9325**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9326
9327**参数:**
9328
9329| 参数名   | 类型                                        | 必填 | 说明                                                         |
9330| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
9331| table    | string                                      | 是   | 指定的目标表名。                                             |
9332| values   | [ValuesBucket](#valuesbucket) \| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket)   | 是   | 表示要插入到表中的数据行。                                   |
9333| conflict | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
9334
9335**返回值**:
9336
9337| 类型   | 说明                                 |
9338| ------ | ------------------------------------ |
9339| number | 如果操作成功,返回行ID;否则返回-1。 |
9340
9341**错误码:**
9342
9343以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9344
9345| **错误码ID** | **错误信息**                                                 |
9346| ------------ | ------------------------------------------------------------ |
9347| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9348| 14800000     | Inner error.                                                 |
9349| 14800011     | Database corrupted.                                          |
9350| 14800014     | Already closed.                                              |
9351| 14800021     | SQLite: Generic error.                                       |
9352| 14800023     | SQLite: Access permission denied.                            |
9353| 14800024     | SQLite: The database file is locked.                         |
9354| 14800025     | SQLite: A table in the database is locked.                   |
9355| 14800026     | SQLite: The database is out of memory.                       |
9356| 14800027     | SQLite: Attempt to write a readonly database.                |
9357| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
9358| 14800029     | SQLite: The database is full.                                |
9359| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
9360| 14800033     | SQLite: Data type mismatch.                                  |
9361| 14800047     | The WAL file size exceeds the default limit.                 |
9362
9363**示例:**
9364
9365```ts
9366let value1 = "Lisa";
9367let value2 = 18;
9368let value3 = 100.5;
9369let value4 = new Uint8Array([1, 2, 3, 4, 5]);
9370
9371// 以下三种方式可用
9372const valueBucket1: relationalStore.ValuesBucket = {
9373  'NAME': value1,
9374  'AGE': value2,
9375  'SALARY': value3,
9376  'CODES': value4
9377};
9378const valueBucket2: relationalStore.ValuesBucket = {
9379  NAME: value1,
9380  AGE: value2,
9381  SALARY: value3,
9382  CODES: value4
9383};
9384const valueBucket3: relationalStore.ValuesBucket = {
9385  "NAME": value1,
9386  "AGE": value2,
9387  "SALARY": value3,
9388  "CODES": value4
9389};
9390
9391if (store != undefined) {
9392  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9393    try {
9394      let rowId: number = (transaction as relationalStore.Transaction).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
9395      transaction.commit();
9396      console.info(`Insert is successful, rowId = ${rowId}`);
9397    } catch (e) {
9398      transaction.rollback();
9399      console.error(`Insert is failed, code is ${e.code},message is ${e.message}`);
9400    };
9401  }).catch((err: BusinessError) => {
9402    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9403  });
9404}
9405```
9406
9407### batchInsert<sup>14+</sup>
9408
9409batchInsert(table: string, values: Array&lt;ValuesBucket&gt;): Promise&lt;number&gt;
9410
9411向目标表中插入一组数据,使用Promise异步回调。
9412
9413**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9414
9415**参数:**
9416
9417| 参数名 | 类型                                       | 必填 | 说明                         |
9418| ------ | ------------------------------------------ | ---- | ---------------------------- |
9419| table  | string                                     | 是   | 指定的目标表名。             |
9420| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。|
9421
9422**返回值**:
9423
9424| 类型                  | 说明                                                        |
9425| --------------------- | ----------------------------------------------------------- |
9426| Promise&lt;number&gt; | Promise对象。如果操作成功,返回插入的数据个数,否则返回-1。 |
9427
9428**错误码:**
9429
9430以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9431
9432| **错误码ID** | **错误信息**                                                 |
9433|-----------| ------------------------------------------------------------ |
9434| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9435| 14800000  | Inner error. |
9436| 14800011  | Database corrupted. |
9437| 14800014  | Already closed. |
9438| 14800021  | SQLite: Generic error. |
9439| 14800023  | SQLite: Access permission denied. |
9440| 14800024  | SQLite: The database file is locked. |
9441| 14800025  | SQLite: A table in the database is locked. |
9442| 14800026  | SQLite: The database is out of memory. |
9443| 14800027  | SQLite: Attempt to write a readonly database. |
9444| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9445| 14800029  | SQLite: The database is full. |
9446| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9447| 14800033  | SQLite: Data type mismatch. |
9448| 14800047  | The WAL file size exceeds the default limit. |
9449
9450**示例:**
9451
9452```ts
9453let value1 = "Lisa";
9454let value2 = 18;
9455let value3 = 100.5;
9456let value4 = new Uint8Array([1, 2, 3, 4, 5]);
9457let value5 = "Jack";
9458let value6 = 19;
9459let value7 = 101.5;
9460let value8 = new Uint8Array([6, 7, 8, 9, 10]);
9461let value9 = "Tom";
9462let value10 = 20;
9463let value11 = 102.5;
9464let value12 = new Uint8Array([11, 12, 13, 14, 15]);
9465
9466const valueBucket1: relationalStore.ValuesBucket = {
9467  'NAME': value1,
9468  'AGE': value2,
9469  'SALARY': value3,
9470  'CODES': value4
9471};
9472const valueBucket2: relationalStore.ValuesBucket = {
9473  'NAME': value5,
9474  'AGE': value6,
9475  'SALARY': value7,
9476  'CODES': value8
9477};
9478const valueBucket3: relationalStore.ValuesBucket = {
9479  'NAME': value9,
9480  'AGE': value10,
9481  'SALARY': value11,
9482  'CODES': value12
9483};
9484
9485let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
9486if (store != undefined) {
9487  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9488    transaction.batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => {
9489      transaction.commit();
9490      console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
9491    }).catch((e: BusinessError) => {
9492      transaction.rollback();
9493      console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`);
9494    });
9495  }).catch((err: BusinessError) => {
9496    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9497  });
9498}
9499```
9500
9501### batchInsertSync<sup>14+</sup>
9502
9503batchInsertSync(table: string, values: Array&lt;ValuesBucket&gt;): number
9504
9505向目标表中插入一组数据。
9506
9507**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9508
9509**参数:**
9510
9511| 参数名 | 类型                                       | 必填 | 说明                         |
9512| ------ | ------------------------------------------ | ---- | ---------------------------- |
9513| table  | string                                     | 是   | 指定的目标表名。             |
9514| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。 |
9515
9516**返回值**:
9517
9518| 类型   | 说明                                           |
9519| ------ | ---------------------------------------------- |
9520| number | 如果操作成功,返回插入的数据个数,否则返回-1。 |
9521
9522**错误码:**
9523
9524以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9525
9526| **错误码ID** | **错误信息**                                                 |
9527| ------------ | ------------------------------------------------------------ |
9528| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9529| 14800000     | Inner error.                                                 |
9530| 14800011     | Database corrupted.                                          |
9531| 14800014     | Already closed.                                              |
9532| 14800021     | SQLite: Generic error.                                       |
9533| 14800023     | SQLite: Access permission denied.                            |
9534| 14800024     | SQLite: The database file is locked.                         |
9535| 14800025     | SQLite: A table in the database is locked.                   |
9536| 14800026     | SQLite: The database is out of memory.                       |
9537| 14800027     | SQLite: Attempt to write a readonly database.                |
9538| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
9539| 14800029     | SQLite: The database is full.                                |
9540| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
9541| 14800033     | SQLite: Data type mismatch.                                  |
9542| 14800047     | The WAL file size exceeds the default limit.                 |
9543
9544**示例:**
9545
9546```ts
9547let value1 = "Lisa";
9548let value2 = 18;
9549let value3 = 100.5;
9550let value4 = new Uint8Array([1, 2, 3, 4, 5]);
9551let value5 = "Jack";
9552let value6 = 19;
9553let value7 = 101.5;
9554let value8 = new Uint8Array([6, 7, 8, 9, 10]);
9555let value9 = "Tom";
9556let value10 = 20;
9557let value11 = 102.5;
9558let value12 = new Uint8Array([11, 12, 13, 14, 15]);
9559
9560const valueBucket1: relationalStore.ValuesBucket = {
9561  'NAME': value1,
9562  'AGE': value2,
9563  'SALARY': value3,
9564  'CODES': value4
9565};
9566const valueBucket2: relationalStore.ValuesBucket = {
9567  'NAME': value5,
9568  'AGE': value6,
9569  'SALARY': value7,
9570  'CODES': value8
9571};
9572const valueBucket3: relationalStore.ValuesBucket = {
9573  'NAME': value9,
9574  'AGE': value10,
9575  'SALARY': value11,
9576  'CODES': value12
9577};
9578
9579let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
9580if (store != undefined) {
9581  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9582    try {
9583      let insertNum: number = (transaction as relationalStore.Transaction).batchInsertSync("EMPLOYEE", valueBuckets);
9584      transaction.commit();
9585      console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
9586    } catch (e) {
9587      transaction.rollback();
9588      console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`);
9589    };
9590  }).catch((err: BusinessError) => {
9591    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9592  });
9593}
9594```
9595
9596### batchInsertWithConflictResolution<sup>18+</sup>
9597
9598batchInsertWithConflictResolution(table: string, values: Array&lt;ValuesBucket&gt;, conflict: ConflictResolution): Promise&lt;number&gt;
9599
9600向目标表中插入一组数据,使用Promise异步回调。
9601
9602**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9603
9604**参数:**
9605
9606| 参数名 | 类型                                       | 必填 | 说明                         |
9607| ------ | ------------------------------------------ | ---- | ---------------------------- |
9608| table  | string                                     | 是   | 指定的目标表名。             |
9609| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。|
9610| conflict | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。如果是ON_CONFLICT_ROLLBACK模式,当发生冲突时会回滚整个事务。 |
9611
9612**返回值**:
9613
9614| 类型                  | 说明                                                        |
9615| --------------------- | ----------------------------------------------------------- |
9616| Promise&lt;number&gt; | Promise对象。如果操作成功,返回插入的数据个数,否则返回-1。 |
9617
9618**错误码:**
9619
9620以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9621
9622| **错误码ID** | **错误信息**                                                 |
9623|-----------| ------------------------------------------------------------ |
9624| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9625| 14800000  | Inner error. |
9626| 14800011  | Database corrupted. |
9627| 14800014  | Already closed. |
9628| 14800021  | SQLite: Generic error. |
9629| 14800022  | SQLite: Callback routine requested an abort. |
9630| 14800023  | SQLite: Access permission denied. |
9631| 14800024  | SQLite: The database file is locked. |
9632| 14800025  | SQLite: A table in the database is locked. |
9633| 14800026  | SQLite: The database is out of memory. |
9634| 14800027  | SQLite: Attempt to write a readonly database. |
9635| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9636| 14800029  | SQLite: The database is full. |
9637| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9638| 14800032  | SQLite: Abort due to constraint violation. |
9639| 14800033  | SQLite: Data type mismatch. |
9640| 14800034  | SQLite: Library used incorrectly. |
9641| 14800047  | The WAL file size exceeds the default limit. |
9642
9643**示例:**
9644
9645```ts
9646let value1 = "Lisa";
9647let value2 = 18;
9648let value3 = 100.5;
9649let value4 = new Uint8Array([1, 2, 3, 4, 5]);
9650let value5 = "Jack";
9651let value6 = 19;
9652let value7 = 101.5;
9653let value8 = new Uint8Array([6, 7, 8, 9, 10]);
9654let value9 = "Tom";
9655let value10 = 20;
9656let value11 = 102.5;
9657let value12 = new Uint8Array([11, 12, 13, 14, 15]);
9658
9659const valueBucket1: relationalStore.ValuesBucket = {
9660  'NAME': value1,
9661  'AGE': value2,
9662  'SALARY': value3,
9663  'CODES': value4
9664};
9665const valueBucket2: relationalStore.ValuesBucket = {
9666  'NAME': value5,
9667  'AGE': value6,
9668  'SALARY': value7,
9669  'CODES': value8
9670};
9671const valueBucket3: relationalStore.ValuesBucket = {
9672  'NAME': value9,
9673  'AGE': value10,
9674  'SALARY': value11,
9675  'CODES': value12
9676};
9677
9678let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
9679if (store != undefined) {
9680  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9681    transaction.batchInsertWithConflictResolution("EMPLOYEE", valueBuckets, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((insertNum: number) => {
9682      transaction.commit();
9683      console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
9684    }).catch((e: BusinessError) => {
9685      transaction.rollback();
9686      console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`);
9687    });
9688  }).catch((err: BusinessError) => {
9689    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9690  });
9691}
9692```
9693
9694### batchInsertWithConflictResolutionSync<sup>18+</sup>
9695
9696batchInsertWithConflictResolutionSync(table: string, values: Array&lt;ValuesBucket&gt;, conflict: ConflictResolution): number
9697
9698向目标表中插入一组数据。
9699
9700**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9701
9702**参数:**
9703
9704| 参数名 | 类型                                       | 必填 | 说明                         |
9705| ------ | ------------------------------------------ | ---- | ---------------------------- |
9706| table  | string                                     | 是   | 指定的目标表名。             |
9707| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | 是   | 表示要插入到表中的一组数据。 |
9708| conflict | [ConflictResolution](#conflictresolution10) | 是   | 指定冲突解决模式。如果是ON_CONFLICT_ROLLBACK模式,当发生冲突时会回滚整个事务。 |
9709
9710**返回值**:
9711
9712| 类型   | 说明                                           |
9713| ------ | ---------------------------------------------- |
9714| number | 如果操作成功,返回插入的数据个数,否则返回-1。 |
9715
9716**错误码:**
9717
9718以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9719
9720| **错误码ID** | **错误信息**                                                 |
9721| ------------ | ------------------------------------------------------------ |
9722| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9723| 14800000  | Inner error. |
9724| 14800011  | Database corrupted. |
9725| 14800014  | Already closed. |
9726| 14800021  | SQLite: Generic error. |
9727| 14800022  | SQLite: Callback routine requested an abort. |
9728| 14800023  | SQLite: Access permission denied. |
9729| 14800024  | SQLite: The database file is locked. |
9730| 14800025  | SQLite: A table in the database is locked. |
9731| 14800026  | SQLite: The database is out of memory. |
9732| 14800027  | SQLite: Attempt to write a readonly database. |
9733| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9734| 14800029  | SQLite: The database is full. |
9735| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9736| 14800032  | SQLite: Abort due to constraint violation. |
9737| 14800033  | SQLite: Data type mismatch. |
9738| 14800034  | SQLite: Library used incorrectly. |
9739| 14800047  | The WAL file size exceeds the default limit. |
9740
9741**示例:**
9742
9743```ts
9744let value1 = "Lisa";
9745let value2 = 18;
9746let value3 = 100.5;
9747let value4 = new Uint8Array([1, 2, 3, 4, 5]);
9748let value5 = "Jack";
9749let value6 = 19;
9750let value7 = 101.5;
9751let value8 = new Uint8Array([6, 7, 8, 9, 10]);
9752let value9 = "Tom";
9753let value10 = 20;
9754let value11 = 102.5;
9755let value12 = new Uint8Array([11, 12, 13, 14, 15]);
9756
9757const valueBucket1: relationalStore.ValuesBucket = {
9758  'NAME': value1,
9759  'AGE': value2,
9760  'SALARY': value3,
9761  'CODES': value4
9762};
9763const valueBucket2: relationalStore.ValuesBucket = {
9764  'NAME': value5,
9765  'AGE': value6,
9766  'SALARY': value7,
9767  'CODES': value8
9768};
9769const valueBucket3: relationalStore.ValuesBucket = {
9770  'NAME': value9,
9771  'AGE': value10,
9772  'SALARY': value11,
9773  'CODES': value12
9774};
9775
9776let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
9777if (store != undefined) {
9778  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9779    try {
9780      let insertNum: number = (transaction as relationalStore.Transaction).batchInsertWithConflictResolutionSync("EMPLOYEE", valueBuckets, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
9781      transaction.commit();
9782      console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
9783    } catch (e) {
9784      transaction.rollback();
9785      console.error(`batchInsert is failed, code is ${e.code},message is ${e.message}`);
9786    };
9787  }).catch((err: BusinessError) => {
9788    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9789  });
9790}
9791```
9792
9793### update<sup>14+</sup>
9794
9795update(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): Promise&lt;number&gt;
9796
9797根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
9798
9799**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9800
9801**参数:**
9802
9803| 参数名     | 类型                                        | 必填 | 说明                                                         |
9804| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
9805| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
9806| predicates | [RdbPredicates](#rdbpredicates)            | 是   | RdbPredicates的实例对象指定的更新条件。                      |
9807| conflict   | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。                                          |
9808
9809**返回值**:
9810
9811| 类型                  | 说明                                      |
9812| --------------------- | ----------------------------------------- |
9813| Promise&lt;number&gt; | 指定的Promise回调方法。返回受影响的行数。 |
9814
9815**错误码:**
9816
9817以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9818
9819| **错误码ID** | **错误信息**                                                 |
9820|-----------| ------------------------------------------------------------ |
9821| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9822| 14800000  | Inner error. |
9823| 14800011  | Database corrupted. |
9824| 14800014  | Already closed. |
9825| 14800021  | SQLite: Generic error. |
9826| 14800023  | SQLite: Access permission denied. |
9827| 14800024  | SQLite: The database file is locked. |
9828| 14800025  | SQLite: A table in the database is locked. |
9829| 14800026  | SQLite: The database is out of memory. |
9830| 14800027  | SQLite: Attempt to write a readonly database. |
9831| 14800028  | SQLite: Some kind of disk I/O error occurred. |
9832| 14800029  | SQLite: The database is full. |
9833| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
9834| 14800033  | SQLite: Data type mismatch. |
9835| 14800047  | The WAL file size exceeds the default limit. |
9836
9837**示例:**
9838
9839```ts
9840let value1 = "Rose";
9841let value2 = 22;
9842let value3 = 200.5;
9843let value4 = new Uint8Array([1, 2, 3, 4, 5]);
9844
9845// 以下三种方式可用
9846const valueBucket1: relationalStore.ValuesBucket = {
9847  'NAME': value1,
9848  'AGE': value2,
9849  'SALARY': value3,
9850  'CODES': value4
9851};
9852const valueBucket2: relationalStore.ValuesBucket = {
9853  NAME: value1,
9854  AGE: value2,
9855  SALARY: value3,
9856  CODES: value4
9857};
9858const valueBucket3: relationalStore.ValuesBucket = {
9859  "NAME": value1,
9860  "AGE": value2,
9861  "SALARY": value3,
9862  "CODES": value4
9863};
9864
9865let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
9866predicates.equalTo("NAME", "Lisa");
9867
9868if (store != undefined) {
9869  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9870    transaction.update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => {
9871      transaction.commit();
9872      console.info(`Updated row count: ${rows}`);
9873    }).catch((e: BusinessError) => {
9874      transaction.rollback();
9875      console.error(`Updated failed, code is ${e.code},message is ${e.message}`);
9876    });
9877  }).catch((err: BusinessError) => {
9878    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9879  });
9880}
9881```
9882
9883### updateSync<sup>14+</sup>
9884
9885updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution): number
9886
9887根据RdbPredicates的指定实例对象更新数据库中的数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
9888
9889**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9890
9891**参数:**
9892
9893| 参数名     | 类型                                        | 必填 | 说明                                                         |
9894| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
9895| values     | [ValuesBucket](#valuesbucket)               | 是   | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 |
9896| predicates | [RdbPredicates](#rdbpredicates)             | 是   | RdbPredicates的实例对象指定的更新条件。                      |
9897| conflict   | [ConflictResolution](#conflictresolution10) | 否   | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 |
9898
9899**返回值**:
9900
9901| 类型   | 说明               |
9902| ------ | ------------------ |
9903| number | 返回受影响的行数。 |
9904
9905**错误码:**
9906
9907以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9908
9909| **错误码ID** | **错误信息**                                                 |
9910| ------------ | ------------------------------------------------------------ |
9911| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
9912| 14800000     | Inner error.                                                 |
9913| 14800011     | Database corrupted.                                          |
9914| 14800014     | Already closed.                                              |
9915| 14800021     | SQLite: Generic error.                                       |
9916| 14800023     | SQLite: Access permission denied.                            |
9917| 14800024     | SQLite: The database file is locked.                         |
9918| 14800025     | SQLite: A table in the database is locked.                   |
9919| 14800026     | SQLite: The database is out of memory.                       |
9920| 14800027     | SQLite: Attempt to write a readonly database.                |
9921| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
9922| 14800029     | SQLite: The database is full.                                |
9923| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
9924| 14800033     | SQLite: Data type mismatch.                                  |
9925| 14800047     | The WAL file size exceeds the default limit.                 |
9926
9927**示例:**
9928
9929```ts
9930let value1 = "Rose";
9931let value2 = 22;
9932let value3 = 200.5;
9933let value4 = new Uint8Array([1, 2, 3, 4, 5]);
9934
9935// 以下三种方式可用
9936const valueBucket1: relationalStore.ValuesBucket = {
9937  'NAME': value1,
9938  'AGE': value2,
9939  'SALARY': value3,
9940  'CODES': value4
9941};
9942const valueBucket2: relationalStore.ValuesBucket = {
9943  NAME: value1,
9944  AGE: value2,
9945  SALARY: value3,
9946  CODES: value4
9947};
9948const valueBucket3: relationalStore.ValuesBucket = {
9949  "NAME": value1,
9950  "AGE": value2,
9951  "SALARY": value3,
9952  "CODES": value4
9953};
9954
9955let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
9956predicates.equalTo("NAME", "Lisa");
9957
9958if (store != undefined) {
9959  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
9960    try {
9961      let rows: Number = (transaction as relationalStore.Transaction).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
9962      transaction.commit();
9963      console.info(`Updated row count: ${rows}`);
9964    } catch (e) {
9965      transaction.rollback();
9966      console.error(`Updated failed, code is ${e.code},message is ${e.message}`);
9967    };
9968  }).catch((err: BusinessError) => {
9969    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
9970  });
9971}
9972```
9973
9974### delete<sup>14+</sup>
9975
9976delete(predicates: RdbPredicates):Promise&lt;number&gt;
9977
9978根据RdbPredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。
9979
9980**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
9981
9982**参数:**
9983
9984| 参数名     | 类型                                 | 必填 | 说明                                      |
9985| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
9986| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
9987
9988**返回值**:
9989
9990| 类型                  | 说明                            |
9991| --------------------- | ------------------------------- |
9992| Promise&lt;number&gt; | Promise对象。返回受影响的行数。 |
9993
9994**错误码:**
9995
9996以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
9997
9998| **错误码ID** | **错误信息**                                                 |
9999|-----------| ------------------------------------------------------------ |
10000| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10001| 14800000  | Inner error. |
10002| 14800011  | Database corrupted. |
10003| 14800014  | Already closed. |
10004| 14800021  | SQLite: Generic error. |
10005| 14800023  | SQLite: Access permission denied. |
10006| 14800024  | SQLite: The database file is locked. |
10007| 14800025  | SQLite: A table in the database is locked. |
10008| 14800026  | SQLite: The database is out of memory. |
10009| 14800027  | SQLite: Attempt to write a readonly database. |
10010| 14800028  | SQLite: Some kind of disk I/O error occurred. |
10011| 14800029  | SQLite: The database is full. |
10012| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
10013| 14800033  | SQLite: Data type mismatch. |
10014| 14800047  | The WAL file size exceeds the default limit. |
10015
10016**示例:**
10017
10018```ts
10019let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
10020predicates.equalTo("NAME", "Lisa");
10021
10022if (store != undefined) {
10023  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
10024    transaction.delete(predicates).then((rows: Number) => {
10025      transaction.commit();
10026      console.info(`Delete rows: ${rows}`);
10027    }).catch((e: BusinessError) => {
10028      transaction.rollback();
10029      console.error(`Delete failed, code is ${e.code},message is ${e.message}`);
10030    });
10031  }).catch((err: BusinessError) => {
10032    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
10033  });
10034}
10035```
10036
10037### deleteSync<sup>14+</sup>
10038
10039deleteSync(predicates: RdbPredicates): number
10040
10041根据RdbPredicates的指定实例对象从数据库中删除数据。
10042
10043**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
10044
10045**参数:**
10046
10047| 参数名     | 类型                            | 必填 | 说明                                    |
10048| ---------- | ------------------------------- | ---- | --------------------------------------- |
10049| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的删除条件。 |
10050
10051**返回值**:
10052
10053| 类型   | 说明               |
10054| ------ | ------------------ |
10055| number | 返回受影响的行数。 |
10056
10057**错误码:**
10058
10059以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
10060
10061| **错误码ID** | **错误信息**                                                 |
10062| ------------ | ------------------------------------------------------------ |
10063| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10064| 14800000  | Inner error. |
10065| 14800011  | Database corrupted. |
10066| 14800014  | Already closed. |
10067| 14800021  | SQLite: Generic error. |
10068| 14800023  | SQLite: Access permission denied. |
10069| 14800024  | SQLite: The database file is locked. |
10070| 14800025  | SQLite: A table in the database is locked. |
10071| 14800026  | SQLite: The database is out of memory. |
10072| 14800027  | SQLite: Attempt to write a readonly database. |
10073| 14800028  | SQLite: Some kind of disk I/O error occurred. |
10074| 14800029  | SQLite: The database is full. |
10075| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
10076| 14800033  | SQLite: Data type mismatch. |
10077| 14800047  | The WAL file size exceeds the default limit. |
10078
10079**示例:**
10080
10081```ts
10082let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
10083predicates.equalTo("NAME", "Lisa");
10084
10085if (store != undefined) {
10086  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
10087    try {
10088      let rows: Number = (transaction as relationalStore.Transaction).deleteSync(predicates);
10089      transaction.commit();
10090      console.info(`Delete rows: ${rows}`);
10091    } catch (e) {
10092      transaction.rollback();
10093      console.error(`Delete failed, code is ${e.code},message is ${e.message}`);
10094    };
10095  }).catch((err: BusinessError) => {
10096    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
10097  });
10098}
10099```
10100
10101### query<sup>14+</sup>
10102
10103query(predicates: RdbPredicates, columns?: Array&lt;string&gt;): Promise&lt;ResultSet&gt;
10104
10105根据指定条件查询数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。
10106
10107**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
10108
10109**参数:**
10110
10111| 参数名     | 类型                                 | 必填 | 说明                                             |
10112| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
10113| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。        |
10114| columns    | Array&lt;string&gt;                  | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。 |
10115
10116**错误码:**
10117
10118以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
10119
10120| **错误码ID** | **错误信息**                                                 |
10121|-----------| ------------------------------------------------------------ |
10122| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10123| 14800000  | Inner error. |
10124| 14800011  | Database corrupted. |
10125| 14800014  | Already closed. |
10126| 14800021  | SQLite: Generic error. |
10127| 14800023  | SQLite: Access permission denied. |
10128| 14800024  | SQLite: The database file is locked. |
10129| 14800026  | SQLite: The database is out of memory. |
10130| 14800028  | SQLite: Some kind of disk I/O error occurred. |
10131| 14800047  | The WAL file size exceeds the default limit. |
10132
10133**返回值**:
10134
10135| 类型                                                    | 说明                                               |
10136| ------------------------------------------------------- | -------------------------------------------------- |
10137| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
10138
10139**示例:**
10140
10141```ts
10142let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
10143predicates.equalTo("NAME", "Rose");
10144
10145if (store != undefined) {
10146  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
10147    transaction.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then(async (resultSet: relationalStore.ResultSet) => {
10148      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
10149      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
10150      while (resultSet.goToNextRow()) {
10151        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
10152        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
10153        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
10154        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
10155        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
10156      }
10157      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
10158      resultSet.close();
10159      transaction.commit();
10160    }).catch((e: BusinessError) => {
10161      transaction.rollback();
10162      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
10163    });
10164  }).catch((err: BusinessError) => {
10165    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
10166  });
10167}
10168```
10169
10170### querySync<sup>14+</sup>
10171
10172querySync(predicates: RdbPredicates, columns?: Array&lt;string&gt;): ResultSet
10173
10174根据指定条件查询数据库中的数据。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
10175
10176**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
10177
10178**参数:**
10179
10180| 参数名     | 类型                            | 必填 | 说明                                                         |
10181| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ |
10182| predicates | [RdbPredicates](#rdbpredicates) | 是   | RdbPredicates的实例对象指定的查询条件。                      |
10183| columns    | Array&lt;string&gt;             | 否   | 表示要查询的列。如果值为空,则查询应用于所有列。默认值为空。 |
10184
10185**错误码:**
10186
10187以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
10188
10189| **错误码ID** | **错误信息**                                                 |
10190| ------------ | ------------------------------------------------------------ |
10191| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10192| 14800000  | Inner error. |
10193| 14800011  | Database corrupted. |
10194| 14800014  | Already closed. |
10195| 14800021  | SQLite: Generic error. |
10196| 14800023  | SQLite: Access permission denied. |
10197| 14800024  | SQLite: The database file is locked. |
10198| 14800025  | SQLite: A table in the database is locked. |
10199| 14800026  | SQLite: The database is out of memory. |
10200| 14800028  | SQLite: Some kind of disk I/O error occurred. |
10201| 14800047  | The WAL file size exceeds the default limit. |
10202
10203**返回值**:
10204
10205| 类型                    | 说明                                |
10206| ----------------------- | ----------------------------------- |
10207| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
10208
10209**示例:**
10210
10211```ts
10212let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
10213predicates.equalTo("NAME", "Rose");
10214
10215if (store != undefined) {
10216  (store as relationalStore.RdbStore).createTransaction().then(async (transaction: relationalStore.Transaction) => {
10217    try {
10218      let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
10219      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
10220      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
10221      while (resultSet.goToNextRow()) {
10222        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
10223        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
10224        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
10225        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
10226        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
10227      }
10228      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
10229      resultSet.close();
10230      transaction.commit();
10231    } catch (e) {
10232      transaction.rollback();
10233      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
10234    };
10235  }).catch((err: BusinessError) => {
10236    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
10237  });
10238}
10239```
10240
10241### querySql<sup>14+</sup>
10242
10243querySql(sql: string, args?: Array&lt;ValueType&gt;): Promise&lt;ResultSet&gt;
10244
10245根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。
10246
10247**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
10248
10249**参数:**
10250
10251| 参数名   | 类型                                 | 必填 | 说明                                                         |
10252| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
10253| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
10254| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
10255
10256**返回值**:
10257
10258| 类型                                                    | 说明                                               |
10259| ------------------------------------------------------- | -------------------------------------------------- |
10260| Promise&lt;[ResultSet](#resultset)&gt; | Promise对象。如果操作成功,则返回ResultSet对象。 |
10261
10262**错误码:**
10263
10264以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
10265
10266| **错误码ID** | **错误信息**                                                 |
10267|-----------| ------------------------------------------------------------ |
10268| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10269| 14800000  | Inner error. |
10270| 14800011  | Database corrupted. |
10271| 14800014  | Already closed. |
10272| 14800021  | SQLite: Generic error. |
10273| 14800023  | SQLite: Access permission denied. |
10274| 14800024  | SQLite: The database file is locked. |
10275| 14800025  | SQLite: A table in the database is locked. |
10276| 14800026  | SQLite: The database is out of memory. |
10277| 14800028  | SQLite: Some kind of disk I/O error occurred. |
10278| 14800047  | The WAL file size exceeds the default limit. |
10279
10280**示例:**
10281
10282```ts
10283if (store != undefined) {
10284  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
10285    transaction.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then(async (resultSet: relationalStore.ResultSet) => {
10286      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
10287      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
10288      while (resultSet.goToNextRow()) {
10289        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
10290        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
10291        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
10292        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
10293        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
10294      }
10295      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
10296      resultSet.close();
10297      transaction.commit();
10298    }).catch((e: BusinessError) => {
10299      transaction.rollback();
10300      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
10301    });
10302  }).catch((err: BusinessError) => {
10303    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
10304  });
10305}
10306```
10307
10308### querySqlSync<sup>14+</sup>
10309
10310querySqlSync(sql: string, args?: Array&lt;ValueType&gt;): ResultSet
10311
10312根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个。对query同步接口获得的resultSet进行操作时,若逻辑复杂且循环次数过多,可能造成freeze问题,建议将此步骤放到[taskpool](../apis-arkts/js-apis-taskpool.md)线程中执行。
10313
10314**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
10315
10316**参数:**
10317
10318| 参数名   | 类型                                 | 必填 | 说明                                                         |
10319| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
10320| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
10321| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。默认值为空。 |
10322
10323**返回值**:
10324
10325| 类型                    | 说明                                |
10326| ----------------------- | ----------------------------------- |
10327| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 |
10328
10329**错误码:**
10330
10331以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。
10332
10333| **错误码ID** | **错误信息**                                                 |
10334| ------------ | ------------------------------------------------------------ |
10335| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10336| 14800000  | Inner error. |
10337| 14800011  | Database corrupted. |
10338| 14800014  | Already closed. |
10339| 14800021  | SQLite: Generic error. |
10340| 14800023  | SQLite: Access permission denied. |
10341| 14800024  | SQLite: The database file is locked. |
10342| 14800025  | SQLite: A table in the database is locked. |
10343| 14800026  | SQLite: The database is out of memory. |
10344| 14800028  | SQLite: Some kind of disk I/O error occurred. |
10345| 14800047  | The WAL file size exceeds the default limit. |
10346
10347**示例:**
10348
10349```ts
10350if (store != undefined) {
10351  (store as relationalStore.RdbStore).createTransaction().then(async (transaction: relationalStore.Transaction) => {
10352    try {
10353      let resultSet: relationalStore.ResultSet = (transaction as relationalStore.Transaction).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'");
10354      console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);
10355      // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
10356      while (resultSet.goToNextRow()) {
10357        const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
10358        const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
10359        const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
10360        const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
10361        console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`);
10362      }
10363      // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露
10364      resultSet.close();
10365      transaction.commit();
10366    } catch (e) {
10367      transaction.rollback();
10368      console.error(`Query failed, code is ${e.code},message is ${e.message}`);
10369    };
10370  }).catch((err: BusinessError) => {
10371    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
10372  });
10373}
10374```
10375
10376### execute<sup>14+</sup>
10377
10378execute(sql: string, args?: Array&lt;ValueType&gt;): Promise&lt;ValueType&gt;
10379
10380执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType,使用Promise异步回调。
10381
10382该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
10383
10384此接口不支持执行查询、附加数据库和事务操作,查询可以使用[querySql](#querysql14)、[query](#query14)接口代替、附加数据库可以使用[attach](#attach12)接口代替。
10385
10386不支持分号分隔的多条语句。
10387
10388**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
10389
10390**参数:**
10391
10392| 参数名   | 类型                                 | 必填 | 说明                                                         |
10393| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
10394| sql      | string                               | 是   | 指定要执行的SQL语句。                                        |
10395| args | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 |
10396
10397**返回值**:
10398
10399| 类型                | 说明                      |
10400| ------------------- | ------------------------- |
10401| Promise&lt;[ValueType](#valuetype)&gt; | Promise对象,返回sql执行后的结果。 |
10402
10403**错误码:**
10404
10405以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
10406
10407| **错误码ID** | **错误信息**                                                 |
10408|-----------| ------------------------------------------------------------ |
10409| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10410| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
10411| 14800000  | Inner error. |
10412| 14800011  | Database corrupted. |
10413| 14800014  | Already closed. |
10414| 14800021  | SQLite: Generic error. |
10415| 14800023  | SQLite: Access permission denied. |
10416| 14800024  | SQLite: The database file is locked. |
10417| 14800025  | SQLite: A table in the database is locked. |
10418| 14800026  | SQLite: The database is out of memory. |
10419| 14800027  | SQLite: Attempt to write a readonly database. |
10420| 14800028  | SQLite: Some kind of disk I/O error occurred. |
10421| 14800029  | SQLite: The database is full. |
10422| 14800031  | SQLite: TEXT or BLOB exceeds size limit. |
10423| 14800033  | SQLite: Data type mismatch. |
10424| 14800047  | The WAL file size exceeds the default limit. |
10425
10426**示例:**
10427
10428```ts
10429// 删除表中所有数据
10430if (store != undefined) {
10431  const SQL_DELETE_TABLE = 'DELETE FROM test';
10432  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
10433    transaction.execute(SQL_DELETE_TABLE).then((data) => {
10434      transaction.commit();
10435      console.info(`delete result: ${data}`);
10436    }).catch((e: BusinessError) => {
10437      transaction.rollback();
10438      console.error(`delete failed, code is ${e.code}, message is ${e.message}`);
10439    });
10440  }).catch((err: BusinessError) => {
10441    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
10442  });
10443}
10444```
10445
10446### executeSync<sup>14+</sup>
10447
10448executeSync(sql: string, args?: Array&lt;ValueType&gt;): ValueType
10449
10450执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType。
10451
10452该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。
10453
10454此接口不支持执行查询、附加数据库和事务操作,查询可以使用[querySql](#querysql14)、[query](#query14)接口代替、附加数据库可以使用[attach](#attach12)接口代替。
10455
10456不支持分号分隔的多条语句。
10457
10458**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core
10459
10460**参数:**
10461
10462| 参数名 | 类型                                 | 必填 | 说明                                                         |
10463| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
10464| sql    | string                               | 是   | 指定要执行的SQL语句。                                        |
10465| args   | Array&lt;[ValueType](#valuetype)&gt; | 否   | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。该参数不填,或者填null或undefined,都认为是sql参数语句完整。默认值为空。 |
10466
10467**返回值**:
10468
10469| 类型                    | 说明                |
10470| ----------------------- | ------------------- |
10471| [ValueType](#valuetype) | 返回sql执行后的结果。 |
10472
10473**错误码:**
10474
10475以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。
10476
10477| **错误码ID** | **错误信息**                                                 |
10478| ------------ | ------------------------------------------------------------ |
10479| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
10480| 801       | Capability not supported the sql(attach,begin,commit,rollback etc.). |
10481| 14800000     | Inner error.                                                 |
10482| 14800011     | Database corrupted.                                          |
10483| 14800014     | Already closed.                                              |
10484| 14800021     | SQLite: Generic error.                                       |
10485| 14800023     | SQLite: Access permission denied.                            |
10486| 14800024     | SQLite: The database file is locked.                         |
10487| 14800025     | SQLite: A table in the database is locked.                   |
10488| 14800026     | SQLite: The database is out of memory.                       |
10489| 14800027     | SQLite: Attempt to write a readonly database.                |
10490| 14800028     | SQLite: Some kind of disk I/O error occurred.                |
10491| 14800029     | SQLite: The database is full.                                |
10492| 14800031     | SQLite: TEXT or BLOB exceeds size limit.                     |
10493| 14800033     | SQLite: Data type mismatch.                                  |
10494| 14800047     | The WAL file size exceeds the default limit.                 |
10495
10496**示例:**
10497
10498```ts
10499// 删除表中所有数据
10500if (store != undefined) {
10501  (store as relationalStore.RdbStore).createTransaction().then((transaction: relationalStore.Transaction) => {
10502    const SQL_DELETE_TABLE = 'DELETE FROM test';
10503    try {
10504      let data = (transaction as relationalStore.Transaction).executeSync(SQL_DELETE_TABLE);
10505      transaction.commit();
10506      console.info(`delete result: ${data}`);
10507    } catch (e) {
10508      transaction.rollback();
10509      console.error(`delete failed, code is ${e.code}, message is ${e.message}`);
10510    };
10511  }).catch((err: BusinessError) => {
10512    console.error(`createTransaction failed, code is ${err.code},message is ${err.message}`);
10513  });
10514}
10515```