1# @ohos.data.relationalStore (关系型数据库) 2 3关系型数据库(Relational Database,RDB)是一种基于关系模型来管理数据的数据库。关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制,对外提供了一系列的增、删、改、查等接口,也可以直接运行用户输入的SQL语句来满足复杂的场景需要。支持通过[ResultSet.getSendableRow](#getsendablerow12)方法获取Sendable数据,进行跨线程传递。 4 5为保证插入并读取数据成功,建议一条数据不要超过2M。超出该大小,插入成功,读取失败。 6 7大数据量场景下查询数据可能会导致耗时长甚至应用卡死,建议如下: 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 19> **说明:** 20> 21> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 22 23## 导入模块 24 25```ts 26import { relationalStore } from '@kit.ArkData'; 27``` 28 29## relationalStore.getRdbStore 30 31getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback<RdbStore>): void 32 33获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用callback异步回调。 34 35当用非加密方式打开一个已有的加密数据库时,会返回错误码14800011,表示数据库损坏。此时用加密方式可以正常打开该数据库。 36 37getRdbStore目前不支持多线程并发操作。 38 39**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 40 41**参数:** 42 43| 参数名 | 类型 | 必填 | 说明 | 44| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | 45| 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)。 | 46| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 | 47| callback | AsyncCallback<[RdbStore](#rdbstore)> | 是 | 指定callback回调函数,返回RdbStore对象。 | 48 49**错误码:** 50 51以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 52 53| **错误码ID** | **错误信息** | 54|-----------|---------| 55| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 56| 14800000 | Inner error. | 57| 14800010 | Invalid database path. | 58| 14800011 | Database corrupted. | 59| 14801001 | Only supported in stage mode. | 60| 14801002 | The data group id is not valid. | 61| 14800017 | Config changed. | 62| 14800021 | SQLite: Generic error. | 63| 14800022 | SQLite: Callback routine requested an abort. | 64| 14800023 | SQLite: Access permission denied. | 65| 14800027 | SQLite: Attempt to write a readonly database. | 66| 14800028 | SQLite: Some kind of disk I/O error occurred. | 67| 14800029 | SQLite: The database is full. | 68| 14800030 | SQLite: Unable to open the database file. | 69 70**示例:** 71 72FA模型示例: 73 74<!--code_no_check_fa--> 75```js 76import { featureAbility } from '@kit.AbilityKit'; 77import { BusinessError } from '@kit.BasicServicesKit'; 78 79let store: relationalStore.RdbStore | undefined = undefined; 80let context = featureAbility.getContext(); 81 82const STORE_CONFIG: relationalStore.StoreConfig = { 83 name: "RdbTest.db", 84 securityLevel: relationalStore.SecurityLevel.S3 85}; 86 87relationalStore.getRdbStore(context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 88 store = rdbStore; 89 if (err) { 90 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 91 return; 92 } 93 console.info('Get RdbStore successfully.'); 94}) 95``` 96 97Stage模型示例: 98 99```ts 100import { UIAbility } from '@kit.AbilityKit'; 101import { window } from '@kit.ArkUI'; 102import { BusinessError } from '@kit.BasicServicesKit'; 103 104let store: relationalStore.RdbStore | undefined = undefined; 105 106class EntryAbility extends UIAbility { 107 onWindowStageCreate(windowStage: window.WindowStage) { 108 const STORE_CONFIG: relationalStore.StoreConfig = { 109 name: "RdbTest.db", 110 securityLevel: relationalStore.SecurityLevel.S3 111 }; 112 113 relationalStore.getRdbStore(this.context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { 114 store = rdbStore; 115 if (err) { 116 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 117 return; 118 } 119 console.info('Get RdbStore successfully.'); 120 }) 121 } 122} 123``` 124 125## relationalStore.getRdbStore 126 127getRdbStore(context: Context, config: StoreConfig): Promise<RdbStore> 128 129获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用Promise异步回调。 130 131当用非加密方式打开一个已有的加密数据库时,会返回错误码14800011,表示数据库损坏。此时用加密方式可以正常打开该数据库。 132 133getRdbStore目前不支持多线程并发操作。 134 135**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 136 137**参数:** 138 139| 参数名 | 类型 | 必填 | 说明 | 140| ------- | -------------------------------- | ---- | ------------------------------------------------------------ | 141| 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)。 | 142| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 | 143 144**返回值**: 145 146| 类型 | 说明 | 147| ----------------------------------------- | --------------------------------- | 148| Promise<[RdbStore](#rdbstore)> | Promise对象。返回RdbStore对象。 | 149 150**错误码:** 151 152以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 153 154| **错误码ID** | **错误信息** | 155|-----------| ------------------------------------------------------------ | 156| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 157| 14800000 | Inner error. | 158| 14800010 | Invalid database path. | 159| 14800011 | Database corrupted. | 160| 14801001 | Only supported in stage mode. | 161| 14801002 | The data group id is not valid. | 162| 14800017 | Config changed. | 163| 14800021 | SQLite: Generic error. | 164| 14800027 | SQLite: Attempt to write a readonly database. | 165| 14800028 | SQLite: Some kind of disk I/O error occurred. | 166| 14800029 | SQLite: The database is full. | 167| 14800030 | SQLite: Unable to open the database file. | 168 169**示例:** 170 171FA模型示例: 172 173<!--code_no_check_fa--> 174```js 175import { featureAbility } from '@kit.AbilityKit'; 176import { BusinessError } from '@kit.BasicServicesKit'; 177 178let store: relationalStore.RdbStore | undefined = undefined; 179let context = featureAbility.getContext(); 180 181const STORE_CONFIG: relationalStore.StoreConfig = { 182 name: "RdbTest.db", 183 securityLevel: relationalStore.SecurityLevel.S3 184}; 185 186relationalStore.getRdbStore(context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 187 store = rdbStore; 188 console.info('Get RdbStore successfully.') 189}).catch((err: BusinessError) => { 190 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 191}) 192``` 193 194Stage模型示例: 195 196```ts 197import { UIAbility } from '@kit.AbilityKit'; 198import { window } from '@kit.ArkUI'; 199import { BusinessError } from '@kit.BasicServicesKit'; 200 201let store: relationalStore.RdbStore | undefined = undefined; 202 203class EntryAbility extends UIAbility { 204 onWindowStageCreate(windowStage: window.WindowStage) { 205 const STORE_CONFIG: relationalStore.StoreConfig = { 206 name: "RdbTest.db", 207 securityLevel: relationalStore.SecurityLevel.S3 208 }; 209 210 relationalStore.getRdbStore(this.context, STORE_CONFIG).then(async (rdbStore: relationalStore.RdbStore) => { 211 store = rdbStore; 212 console.info('Get RdbStore successfully.') 213 }).catch((err: BusinessError) => { 214 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 215 }) 216 } 217} 218``` 219 220## relationalStore.deleteRdbStore 221 222deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void 223 224删除数据库文件,使用callback异步回调。 225 226删除成功后,建议将数据库对象置为null。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则调用此接口进行删库无效,必须使用 [deleteRdbStore<sup>10+</sup>](#relationalstoredeleterdbstore10) 接口进行删库。 227 228**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 229 230**参数:** 231 232| 参数名 | 类型 | 必填 | 说明 | 233| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 234| 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)。 | 235| name | string | 是 | 数据库名称。 | 236| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | 237 238**错误码:** 239 240以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 241 242| **错误码ID** | **错误信息** | 243|-----------|---------------------------------------| 244| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 245| 14800000 | Inner error. | 246| 14800010 | Failed to open or delete database by invalid database path. | 247 248**示例:** 249 250FA模型示例: 251 252<!--code_no_check_fa--> 253```js 254import { featureAbility } from '@kit.AbilityKit'; 255import { BusinessError } from '@kit.BasicServicesKit'; 256 257let store: relationalStore.RdbStore | undefined = undefined; 258let context = featureAbility.getContext(); 259 260relationalStore.deleteRdbStore(context, "RdbTest.db", (err: BusinessError) => { 261 if (err) { 262 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 263 return; 264 } 265 store = undefined; 266 console.info('Delete RdbStore successfully.'); 267}) 268``` 269 270Stage模型示例: 271 272```ts 273import { UIAbility } from '@kit.AbilityKit'; 274import { window } from '@kit.ArkUI'; 275import { BusinessError } from '@kit.BasicServicesKit'; 276 277let store: relationalStore.RdbStore | undefined = undefined; 278 279class EntryAbility extends UIAbility { 280 onWindowStageCreate(windowStage: window.WindowStage){ 281 relationalStore.deleteRdbStore(this.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} 291``` 292 293## relationalStore.deleteRdbStore 294 295deleteRdbStore(context: Context, name: string): Promise<void> 296 297使用指定的数据库文件配置删除数据库,使用Promise异步回调。 298 299删除成功后,建议将数据库对象置为null。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则调用此接口进行删库无效,必须使用 [deleteRdbStore<sup>10+</sup>](#relationalstoredeleterdbstore10-1) 接口进行删库。 300 301**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 302 303**参数** 304 305| 参数名 | 类型 | 必填 | 说明 | 306| ------- | ------- | ---- | ------------------------------------------------------------ | 307| 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)。 | 308| name | string | 是 | 数据库名称。 | 309 310**返回值**: 311 312| 类型 | 说明 | 313| ------------------- | ------------------------- | 314| Promise<void> | 无返回结果的Promise对象。 | 315 316**错误码:** 317 318以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 319 320| **错误码ID** | **错误信息** | 321|-----------|----------------------------------------------------------------------------------| 322| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 323| 14800000 | Inner error. | 324| 14800010 | Invalid database path. | 325 326**示例:** 327 328FA模型示例: 329 330<!--code_no_check_fa--> 331```js 332import { featureAbility } from '@kit.AbilityKit'; 333import { BusinessError } from '@kit.BasicServicesKit'; 334 335let store: relationalStore.RdbStore | undefined = undefined; 336let context = featureAbility.getContext(); 337 338relationalStore.deleteRdbStore(context, "RdbTest.db").then(()=>{ 339 store = undefined; 340 console.info('Delete RdbStore successfully.'); 341}).catch((err: BusinessError) => { 342 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 343}) 344``` 345 346Stage模型示例: 347 348```ts 349import { UIAbility } from '@kit.AbilityKit'; 350import { window } from '@kit.ArkUI'; 351import { BusinessError } from '@kit.BasicServicesKit'; 352 353let store: relationalStore.RdbStore | undefined = undefined; 354 355class EntryAbility extends UIAbility { 356 onWindowStageCreate(windowStage: window.WindowStage){ 357 relationalStore.deleteRdbStore(this.context, "RdbTest.db").then(()=>{ 358 store = undefined; 359 console.info('Delete RdbStore successfully.'); 360 }).catch((err: BusinessError) => { 361 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 362 }) 363 } 364} 365``` 366 367## relationalStore.deleteRdbStore<sup>10+</sup> 368 369deleteRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback\<void>): void 370 371使用指定的数据库文件配置删除数据库,使用callback异步回调。 372 373删除成功后,建议将数据库对象置为null。若数据库文件处于公共沙箱目录下,则删除数据库时必须使用该接口,当存在多个进程操作同一个数据库的情况,建议向其他进程发送数据库删除通知使其感知并处理。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则必须调用此接口进行删库。 374 375**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 376 377**参数:** 378 379| 参数名 | 类型 | 必填 | 说明 | 380| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 381| 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)。 | 382| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 | 383| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | 384 385**错误码:** 386 387以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 388 389| **错误码ID** | **错误信息** | 390|-----------|----------| 391| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 392| 14800000 | Inner error. | 393| 14800010 | Failed to open or delete database by invalid database path. | 394| 14801001 | Only supported in stage mode. | 395| 14801002 | The data group id is not valid. | 396 397**示例:** 398 399FA模型示例: 400 401<!--code_no_check_fa--> 402```js 403import { featureAbility } from '@kit.AbilityKit'; 404import { BusinessError } from '@kit.BasicServicesKit'; 405 406let store: relationalStore.RdbStore | undefined = undefined; 407let context = featureAbility.getContext(); 408 409const STORE_CONFIG: relationalStore.StoreConfig = { 410 name: "RdbTest.db", 411 securityLevel: relationalStore.SecurityLevel.S3 412}; 413 414relationalStore.deleteRdbStore(context, STORE_CONFIG, (err: BusinessError) => { 415 if (err) { 416 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 417 return; 418 } 419 store = undefined; 420 console.info('Delete RdbStore successfully.'); 421}) 422``` 423 424Stage模型示例: 425 426```ts 427import { UIAbility } from '@kit.AbilityKit'; 428import { window } from '@kit.ArkUI'; 429import { BusinessError } from '@kit.BasicServicesKit'; 430 431let store: relationalStore.RdbStore | undefined = undefined; 432 433class EntryAbility extends UIAbility { 434 onWindowStageCreate(windowStage: window.WindowStage){ 435 const STORE_CONFIG: relationalStore.StoreConfig = { 436 name: "RdbTest.db", 437 securityLevel: relationalStore.SecurityLevel.S3 438 }; 439 relationalStore.deleteRdbStore(this.context, STORE_CONFIG, (err: BusinessError) => { 440 if (err) { 441 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 442 return; 443 } 444 store = undefined; 445 console.info('Delete RdbStore successfully.'); 446 }) 447 } 448} 449``` 450 451## relationalStore.deleteRdbStore<sup>10+</sup> 452 453deleteRdbStore(context: Context, config: StoreConfig): Promise\<void> 454 455使用指定的数据库文件配置删除数据库,使用Promise异步回调。 456 457删除成功后,建议将数据库对象置为null。若数据库文件处于公共沙箱目录下,则删除数据库时必须使用该接口,当存在多个进程操作同一个数据库的情况,建议向其他进程发送数据库删除通知使其感知并处理。建立数据库时,若在[StoreConfig](#storeconfig)中配置了自定义路径,则必须调用此接口进行删库。 458 459**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 460 461**参数** 462 463| 参数名 | 类型 | 必填 | 说明 | 464| ------- | --------------------------- | ---- | ------------------------------------------------------------ | 465| 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)。 | 466| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 | 467 468**返回值**: 469 470| 类型 | 说明 | 471| ------------------- | ------------------------- | 472| Promise<void> | 无返回结果的Promise对象。 | 473 474**错误码:** 475 476以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。 477 478| **错误码ID** | **错误信息** | 479|-----------|---------------------| 480| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 481| 801 | Capability not supported. | 482| 14800000 | Inner error. | 483| 14800010 | Invalid database path. | 484| 14801001 | Only supported in stage mode. | 485| 14801002 | The data group id is not valid. | 486 487 488**示例:** 489 490FA模型示例: 491 492<!--code_no_check_fa--> 493```js 494import { featureAbility } from "@kit.AbilityKit"; 495import { BusinessError } from '@kit.BasicServicesKit'; 496 497let store: relationalStore.RdbStore | undefined = undefined; 498let context = featureAbility.getContext(); 499 500const STORE_CONFIG: relationalStore.StoreConfig = { 501 name: "RdbTest.db", 502 securityLevel: relationalStore.SecurityLevel.S3 503}; 504 505relationalStore.deleteRdbStore(context, STORE_CONFIG).then(()=>{ 506 store = undefined; 507 console.info('Delete RdbStore successfully.'); 508}).catch((err: BusinessError) => { 509 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 510}) 511``` 512 513Stage模型示例: 514 515```ts 516import { UIAbility } from '@kit.AbilityKit'; 517import { window } from '@kit.ArkUI'; 518import { BusinessError } from '@kit.BasicServicesKit'; 519 520let store: relationalStore.RdbStore | undefined = undefined; 521 522class EntryAbility extends UIAbility { 523 onWindowStageCreate(windowStage: window.WindowStage){ 524 const STORE_CONFIG: relationalStore.StoreConfig = { 525 name: "RdbTest.db", 526 securityLevel: relationalStore.SecurityLevel.S3 527 }; 528 relationalStore.deleteRdbStore(this.context, STORE_CONFIG).then(()=>{ 529 store = undefined; 530 console.info('Delete RdbStore successfully.'); 531 }).catch((err: BusinessError) => { 532 console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); 533 }) 534 } 535} 536``` 537 538## StoreConfig 539 540管理关系数据库配置。 541 542| 名称 | 类型 | 必填 | 说明 | 543| ------------- | ------------- | ---- | --------------------------------------------------------- | 544| name | string | 是 | 数据库文件名,也是数据库唯一标识符。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 545| securityLevel | [SecurityLevel](#securitylevel) | 是 | 设置数据库安全级别。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core| 546| encrypt | boolean | 否 | 指定数据库是否加密,默认不加密。<br/> true:加密。<br/> false:非加密。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 547| dataGroupId<sup>10+</sup> | string | 否 | 应用组ID,需要向应用市场获取,暂不支持。<br/>**模型约束:** 此属性仅在Stage模型下可用。<br/>从API version 10开始,支持此可选参数。指定在此dataGroupId对应的沙箱路径下创建RdbStore实例,当此参数不填时,默认在本应用沙箱目录下创建RdbStore实例。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 548| customDir<sup>11+</sup> | string | 否 | 数据库自定义路径。<br/>**使用约束:** 数据库路径大小限制为128字节,如果超过该大小会开库失败,返回错误。<br/>从API version 11开始,支持此可选参数。数据库将在如下的目录结构中被创建:context.databaseDir + "/rdb/" + customDir,其中context.databaseDir是应用沙箱对应的路径,"/rdb/"表示创建的是关系型数据库,customDir表示自定义的路径。当此参数不填时,默认在本应用沙箱目录下创建RdbStore实例。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 549| autoCleanDirtyData<sup>11+</sup> | boolean | 否 | 指定是否自动清理云端删除后同步到本地的数据,true表示自动清理,false表示手动清理,默认自动清理。<br/>对于端云协同的数据库,当云端删除的数据同步到设备端时,可通过该参数设置设备端是否自动清理。手动清理可以通过[cleanDirtyData<sup>11+</sup>](#cleandirtydata11)接口清理。<br/>从API version 11开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client | 550| allowRebuild<sup>12+</sup> | boolean | 否 | 指定数据库是否支持损坏时自动重建,默认不重建。<br/>true:自动重建。<br/>false:不自动重建。<br/>从API version 12开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 551| isReadOnly<sup>12+</sup> | boolean | 否 | 指定数据库是否只读,默认为数据库可读写。<br/>true:只允许从数据库读取数据,不允许对数据库进行写操作,否则会返回错误码801。<br/>false:允许对数据库进行读写操作。<br/>从API version 12开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 552| pluginLibs<sup>12+</sup> | Array\<string> | 否 | 表示包含有fts(Full-Text Search,即全文搜索引擎)等能力的动态库名的数组。<br/>**使用约束:** 动态库名的数量限制最多为16个,如果超过该数量会开库失败,返回错误;动态库名需为本应用沙箱路径下或系统路径下的动态库,如果动态库无法加载会开库失败,返回错误。<br/>动态库名需为完整路径,用于被sqlite加载,样例:[context.bundleCodeDir+ "/libs/arm64/" + libtokenizer.so],其中context.bundleCodeDir是应用沙箱对应的路径,"/libs/arm64/"表示子目录,libtokenizer.so表示动态库的文件名。当此参数不填时,默认不加载动态库。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 553| cryptoParam<sup>14+</sup> | [CryptoParam](#cryptoparam14) | 否 | 指定用户自定义的加密参数。<br/>当此参数不填时,使用默认的加密参数,见[CryptoParam](#cryptoparam14)各参数默认值。<br/>此配置只有在encrypt选项设置为真时才有效。<br/>从API version 14开始,支持此可选参数。<br/>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 554 555## SecurityLevel 556 557数据库的安全级别枚举。请使用枚举名称而非枚举值。 558 559> **说明:** 560> 561> 若需要进行同步操作,数据库安全等级应不高于对端设备安全等级,具体可见[跨设备同步访问控制机制](../../database/sync-app-data-across-devices-overview.md#跨设备同步访问控制机制)。 562 563**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 564 565| 名称 | 值 | 说明 | 566| ---- | ---- | ------------------------------------------------------------ | 567| S1 | 1 | 表示数据库的安全级别为低级别,当数据泄露时会产生较低影响。例如,包含壁纸等系统数据的数据库。 | 568| S2 | 2 | 表示数据库的安全级别为中级别,当数据泄露时会产生较大影响。例如,包含录音、视频等用户生成数据或通话记录等信息的数据库。 | 569| S3 | 3 | 表示数据库的安全级别为高级别,当数据泄露时会产生重大影响。例如,包含用户运动、健康、位置等信息的数据库。 | 570| S4 | 4 | 表示数据库的安全级别为关键级别,当数据泄露时会产生严重影响。例如,包含认证凭据、财务数据等信息的数据库。 | 571 572## CryptoParam<sup>14+</sup> 573 574数据库加密参数配置。此配置只有在StoreConfig的encrypt选项设置为真时才有效。 575 576**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 577 578| 名称 | 类型 | 必填 | 说明 | 579| ------------- | ------ | ---- | ------------------------------------------------------------ | 580| encryptionKey | Uint8Array | 是 | 指定数据库加/解密使用的密钥。<br/>如传入密钥为空,则由数据库负责生成并保存密钥,并使用生成的密钥打开数据库文件。<br/>使用完后用户需要将密钥内容全部置为零。 | 581| iterationCount | number | 否 | 整数类型,指定数据库PBKDF2算法的迭代次数,默认值为10000。<br/>迭代次数应当为大于零的整数,若非整数则向下取整。<br/>不指定此参数或指定为零时,使用默认值10000,并使用默认加密算法AES_256_GCM。 | 582| encryptionAlgo | [EncryptionAlgo](#encryptionalgo14) | 否 | 指定数据库加解密使用的加密算法。如不指定,默认值为 AES_256_GCM。 | 583| hmacAlgo | [HmacAlgo](#hmacalgo14) | 否 | 指定数据库加解密使用的HMAC算法。如不指定,默认值为SHA256。 | 584| kdfAlgo | [KdfAlgo](#kdfalgo14) | 否 | 指定数据库加解密使用的PBKDF2算法。如不指定,默认使用和HMAC算法相等的算法。 | 585| cryptoPageSize | number | 否 | 整数类型,指定数据库加解密使用的页大小。如不指定,默认值为1024字节。<br/>用户指定的页大小应为1024到65536范围内的整数,并且为2<sup>n</sup>。若指定值非整数,则向下取整。 | 586 587## EncryptionAlgo<sup>14+</sup> 588 589数据库的加密算法枚举。请使用枚举名称而非枚举值。 590 591**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 592 593| 名称 | 值 | 说明 | 594| ---- | ---- | ---- | 595| AES_256_GCM | 0 | AES_256_GCM加密算法。 | 596| AES_256_CBC | 1 | AES_256_CBC加密算法。 | 597 598## HmacAlgo<sup>14+</sup> 599 600数据库的HMAC算法枚举。请使用枚举名称而非枚举值。 601 602**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 603 604| 名称 | 值 | 说明 | 605| ---- | ---- | ---- | 606| SHA1 | 0 | HMAC_SHA1算法。 | 607| SHA256 | 1 | HMAC_SHA256算法。 | 608| SHA512 | 2 | HMAC_SHA512算法。 | 609 610## KdfAlgo<sup>14+</sup> 611 612数据库的PBKDF2算法枚举。请使用枚举名称而非枚举值。 613 614**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 615 616| 名称 | 值 | 说明 | 617| ---- | ---- | ---- | 618| KDF_SHA1 | 0 | PBKDF2_HMAC_SHA1算法。 | 619| KDF_SHA256 | 1 | PBKDF2_HMAC_SHA256算法。 | 620| KDF_SHA512 | 2 | PBKDF2_HMAC_SHA512算法。 | 621 622## AssetStatus<sup>10+</sup> 623 624描述资产附件的状态枚举。请使用枚举名称而非枚举值。 625 626**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 627 628| 名称 | 值 | 说明 | 629| ------------------------------- | --- | -------------- | 630| ASSET_NORMAL | 1 | 表示资产状态正常。 | 631| ASSET_INSERT | 2 | 表示资产需要插入到云端。 | 632| ASSET_UPDATE | 3 | 表示资产需要更新到云端。 | 633| ASSET_DELETE | 4 | 表示资产需要在云端删除。 | 634| ASSET_ABNORMAL | 5 | 表示资产状态异常。 | 635| ASSET_DOWNLOADING | 6 | 表示资产正在下载到本地设备。 | 636 637## Asset<sup>10+</sup> 638 639记录资产附件(文件、图片、视频等类型文件)的相关信息。 640 641**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 642 643| 名称 | 类型 | 必填 | 说明 | 644| ----------- | --------------------------- | --- | ------------ | 645| name | string | 是 | 资产的名称。 | 646| uri | string | 是 | 资产的uri,在系统里的绝对路径。 | 647| path | string | 是 | 资产在应用沙箱里的路径。 | 648| createTime | string | 是 | 资产被创建出来的时间。 | 649| modifyTime | string | 是 | 资产最后一次被修改的时间。 | 650| size | string | 是 | 资产占用空间的大小。 | 651| status | [AssetStatus](#assetstatus10) | 否 | 资产的状态,默认值为ASSET_NORMAL。 | 652 653## Assets<sup>10+</sup> 654 655type Assets = Asset[] 656 657表示[Asset](#asset10)类型的数组。 658 659**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 660 661| 类型 | 说明 | 662| ------- | -------------------- | 663| [Asset](#asset10)[] | 表示Asset类型的数组。 | 664 665## ValueType 666 667type ValueType = null | number | string | boolean | Uint8Array | Asset | Assets | Float32Array | bigint 668 669用于表示允许的数据字段类型,接口参数具体类型根据其功能而定。 670 671**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 672 673| 类型 | 说明 | 674| ------- | -------------------- | 675| null<sup>10+</sup> | 表示值类型为空。 | 676| number | 表示值类型为数字。 | 677| string | 表示值类型为字符串。 | 678| boolean | 表示值类型为布尔值。 | 679| Uint8Array<sup>10+</sup> | 表示值类型为Uint8类型的数组。 | 680| Asset<sup>10+</sup> | 表示值类型为附件[Asset](#asset10)。<br/>当字段类型是Asset时,在创建表的sql语句中,类型应当为:ASSET。 | 681| Assets<sup>10+</sup> | 表示值类型为附件数组[Assets](#assets10)。<br/>当字段类型是Assets时,在创建表的sql语句中,类型应当为:ASSETS。 | 682| Float32Array<sup>12+</sup> | 表示值类型为浮点数组。<br/>当字段类型是Float32Array时,在创建表的sql语句中,类型应当为:floatvector(128)。 | 683| 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。 | 684 685## ValuesBucket 686 687type ValuesBucket = Record<string, ValueType> 688 689用于存储键值对的类型。不支持Sendable跨线程传递。 690 691**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 692 693| 类型 | 说明 | 694| ---------------- | ---------------------------- | 695| Record<string, [ValueType](#valuetype)> | 表示键值对类型。键的类型为string,值的类型为[ValueType](#valuetype)。 | 696 697## PRIKeyType<sup>10+</sup> 698 699type PRIKeyType = number | string 700 701用于表示数据库表某一行主键的数据类型。 702 703**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 704 705| 类型 | 说明 | 706| ---------------- | ---------------------------------- | 707| number | 主键的类型可以是number。 | 708| string | 主键的类型可以是string。 | 709 710## UTCTime<sup>10+</sup> 711 712type UTCTime = Date 713 714用于表示UTC类型时间的数据类型。 715 716**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 717 718| 类型 | 说明 | 719| ---- | --------------- | 720| Date | UTC类型的时间。 | 721 722## ModifyTime<sup>10+</sup> 723 724type ModifyTime = Map<PRIKeyType, UTCTime> 725 726用于存储数据库表的主键和修改时间的数据类型。 727 728**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 729 730| 类型 | 说明 | 731| ------------------------------------------------------- | ------------------------------------------------------------ | 732| Map<[PRIKeyType](#prikeytype10), [UTCTime](#utctime10)> | 键表示是数据库表某一行的主键,值表示该行的最后修改时间,用UTC格式表示。 | 733 734## SyncMode 735 736指数据库同步模式。请使用枚举名称而非枚举值。 737 738| 名称 | 值 | 说明 | 739| -------------- | ---- | ---------------------------------- | 740| SYNC_MODE_PUSH | 0 | 表示数据从本地设备推送到远程设备。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 741| SYNC_MODE_PULL | 1 | 表示数据从远程设备拉至本地设备。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 742| SYNC_MODE_TIME_FIRST<sup>10+</sup> | 4 | 表示数据从修改时间较近的一端同步到修改时间较远的一端。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client | 743| SYNC_MODE_NATIVE_FIRST<sup>10+</sup> | 5 | 表示数据从本地设备同步到云端。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client | 744| SYNC_MODE_CLOUD_FIRST<sup>10+</sup> | 6 | 表示数据从云端同步到本地设备。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client | 745 746## Origin<sup>11+</sup> 747 748表示数据来源。请使用枚举名称而非枚举值。 749 750**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 751 752| 名称 | 值 | 说明 | 753| -------------- | ---- | ---------------------------------- | 754| LOCAL | 0 | 表示本地数据。 | 755| CLOUD | 1 | 表示云端同步的数据。 | 756| REMOTE | 2 | 表示端端同步的数据。 | 757 758## Field<sup>11+</sup> 759 760用于谓词查询条件的特殊字段。请使用枚举名称而非枚举值。 761 762**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 763 764| 名称 | 值 | 说明 | 765| -------------- | ---- | ---------------------------------- | 766| CURSOR_FIELD | '#_cursor' | 用于cursor查找的字段名。| 767| ORIGIN_FIELD | '#_origin' | 用于cursor查找时指定数据来源的字段名。 | 768| DELETED_FLAG_FIELD | '#_deleted_flag' | 用于cursor查找的结果集返回时填充的字段,表示云端删除的数据同步到本地后数据是否清理。<br>返回的结果集中,该字段对应的value为false表示数据未清理,true表示数据已清理。| 769| DATA_STATUS_FIELD<sup>12+</sup> | '#_data_status' | 用于cursor查找的结果集返回时填充的字段,返回的结果集中,该字段对应的0表示正常数据,1表示退出账号保留数据,2表示云侧同步删除,3表示退出账户删除数据。| 770| OWNER_FIELD | '#_cloud_owner' | 用于共享表中查找owner时,返回的结果集中填充的字段,表示当前共享记录的共享发起者。| 771| PRIVILEGE_FIELD | '#_cloud_privilege' | 用于共享表中查找共享数据权限时,返回的结果集中填充的字段,表示当前共享记录的允许的操作权限。| 772| SHARING_RESOURCE_FIELD | '#_sharing_resource_field' | 用于数据共享查找共享数据的共享资源时,返回的结果集中填充的字段,表示共享数据的共享资源标识。| 773 774## SubscribeType 775 776描述订阅类型。请使用枚举名称而非枚举值。 777 778| 名称 | 值 | 说明 | 779| --------------------- | ---- | ------------------ | 780| SUBSCRIBE_TYPE_REMOTE | 0 | 订阅远程数据更改。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 781| SUBSCRIBE_TYPE_CLOUD<sup>10+</sup> | 1 | 订阅云端数据更改。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client | 782| SUBSCRIBE_TYPE_CLOUD_DETAILS<sup>10+</sup> | 2 | 订阅云端数据更改详情。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client | 783| SUBSCRIBE_TYPE_LOCAL_DETAILS<sup>12+</sup> | 3 | 订阅本地数据更改详情。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 784 785## RebuildType<sup>12+</sup> 786 787描述数据库重建类型的枚举。请使用枚举名称而非枚举值。 788 789**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 790 791| 名称 | 值 | 说明 | 792| ------- | ---- |----------------------------------------------------------------------------------------------------------------| 793| NONE | 0 | 表示数据库未进行重建。 | 794| REBUILT | 1 | 表示数据库进行了重建并且生成了空数据库,需要应用重新建表和恢复数据。 | 795| REPAIRED | 2 | 表示数据库进行了修复,恢复了未损坏的数据,<!--RP2-->当前只有[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)具备该能力。<!--RP2End--> | 796 797## ChangeType<sup>10+</sup> 798 799描述数据变更类型的枚举。请使用枚举名称而非枚举值。 800 801**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 802 803| 名称 | 值 | 说明 | 804| -------------------------- | --- | -------------------------- | 805| DATA_CHANGE | 0 | 表示是数据发生变更。 | 806| ASSET_CHANGE | 1 | 表示是资产附件发生了变更。 | 807 808## ChangeInfo<sup>10+</sup> 809 810记录端云同步过程详情。 811 812**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 813 814| 名称 | 类型 | 必填 | 说明 | 815| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ | 816| table | string | 是 | 表示发生变化的表的名称。 | 817| type | [ChangeType](#changetype10) | 是 | 表示发生变化的数据的类型,数据或者资产附件发生变化。 | 818| inserted | Array\<string\> \| Array\<number\> | 是 | 记录插入数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示插入数据的行号。 | 819| updated | Array\<string\> \| Array\<number\> | 是 | 记录更新数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示更新数据的行号。 | 820| deleted | Array\<string\> \| Array\<number\> | 是 | 记录删除数据的位置,如果该表的主键是string类型,该值是主键的值,否则该值表示删除数据的行号。 | 821 822## DistributedType<sup>10+</sup> 823 824描述表的分布式类型的枚举。请使用枚举名称而非枚举值。 825 826| 名称 | 值 | 说明 | 827| ------------------ | --- | -------------------------------------------------------------------------------------------------- | 828| DISTRIBUTED_DEVICE | 0 | 表示在不同设备之间分布式的数据库表。<br>**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 829| DISTRIBUTED_CLOUD | 1 | 表示在设备和云端之间分布式的数据库表。<br>**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client | 830 831## DistributedConfig<sup>10+</sup> 832 833记录表的分布式配置信息。 834 835**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 836 837| 名称 | 类型 | 必填 | 说明 | 838| -------- | ------- | ---- | ------------------------------------------------------------ | 839| autoSync | boolean | 是 | 该值为true时,表示该表支持自动同步和手动同步;该值为false时,表示该表只支持手动同步,不支持自动同步。 | 840 841## ConflictResolution<sup>10+</sup> 842 843插入和修改接口的冲突解决模式。请使用枚举名称而非枚举值。 844 845**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 846 847| 名称 | 值 | 说明 | 848| -------------------- | ---- | ------------------------------------------------------------ | 849| ON_CONFLICT_NONE | 0 | 表示当冲突发生时,不做任何处理。 | 850| ON_CONFLICT_ROLLBACK | 1 | 表示当冲突发生时,中止SQL语句并回滚当前事务。 | 851| ON_CONFLICT_ABORT | 2 | 表示当冲突发生时,中止当前SQL语句,并撤销当前 SQL 语句所做的任何更改,但是由同一事务中先前的 SQL 语句引起的更改被保留并且事务保持活动状态。 | 852| ON_CONFLICT_FAIL | 3 | 表示当冲突发生时,中止当前 SQL 语句。但它不会撤销失败的 SQL 语句的先前更改,也不会结束事务。 | 853| ON_CONFLICT_IGNORE | 4 | 表示当冲突发生时,跳过包含违反约束的行并继续处理 SQL 语句的后续行。 | 854| ON_CONFLICT_REPLACE | 5 | 表示当冲突发生时,在插入或更新当前行之前删除导致约束违例的预先存在的行,并且命令会继续正常执行。 | 855 856## Progress<sup>10+</sup> 857 858描述端云同步过程的枚举。请使用枚举名称而非枚举值。 859 860**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 861 862| 名称 | 值 | 说明 | 863| ---------------- | ---- | ------------------------ | 864| SYNC_BEGIN | 0 | 表示端云同步过程开始。 | 865| SYNC_IN_PROGRESS | 1 | 表示正在端云同步过程中。 | 866| SYNC_FINISH | 2 | 表示端云同步过程已完成。 | 867 868## Statistic<sup>10+</sup> 869 870描述数据库表的端云同步过程的统计信息。 871 872**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 873 874| 名称 | 类型 | 必填 | 说明 | 875| ---------- | ------ | ---- | ---------------------------------------- | 876| total | number | 是 | 表示数据库表中需要端云同步的总行数。 | 877| successful | number | 是 | 表示数据库表中端云同步成功的行数。 | 878| failed | number | 是 | 表示数据库表中端云同步失败的行数。 | 879| remained | number | 是 | 表示数据库表中端云同步剩余未执行的行数。 | 880 881## TableDetails<sup>10+</sup> 882 883描述数据库表执行端云同步任务上传和下载的统计信息。 884 885**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 886 887| 名称 | 类型 | 必填 | 说明 | 888| -------- | ------------------------- | ---- | ------------------------------------------ | 889| upload | [Statistic](#statistic10) | 是 | 表示数据库表中端云同步上传过程的统计信息。 | 890| download | [Statistic](#statistic10) | 是 | 表示数据库表中端云同步下载过程的统计信息。 | 891 892## ProgressCode<sup>10+</sup> 893 894表示端云同步过程的状态。请使用枚举名称而非枚举值。 895 896**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 897 898| 名称 | 值 | 说明 | 899| --------------------- | ---- | ------------------------------------------------------------ | 900| SUCCESS | 0 | 表示端云同步过程成功。 | 901| UNKNOWN_ERROR | 1 | 表示端云同步过程遇到未知错误。 | 902| NETWORK_ERROR | 2 | 表示端云同步过程遇到网络错误。 | 903| CLOUD_DISABLED | 3 | 表示云端不可用。 | 904| LOCKED_BY_OTHERS | 4 | 表示有其他设备正在端云同步,本设备无法进行端云同步。<br>请确保无其他设备占用云端资源后,再使用本设备进行端云同步任务。 | 905| RECORD_LIMIT_EXCEEDED | 5 | 表示本次端云同步需要同步的条目或大小超出最大值。由云端配置最大值。 | 906| NO_SPACE_FOR_ASSET | 6 | 表示云空间剩余空间小于待同步的资产大小。 | 907| BLOCKED_BY_NETWORK_STRATEGY<sup>12+</sup> | 7 | 表示端云同步被网络策略限制。 | 908 909## ProgressDetails<sup>10+</sup> 910 911描述数据库整体执行端云同步任务上传和下载的统计信息。 912 913**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 914 915| 名称 | 类型 | 必填 | 说明 | 916| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | 917| schedule | [Progress](#progress10) | 是 | 表示端云同步过程。 | 918| code | [ProgressCode](#progresscode10) | 是 | 表示端云同步过程的状态。 | 919| details | Record<string, [TableDetails](#tabledetails10)> | 是 | 表示端云同步各表的统计信息。<br>键表示表名,值表示该表的端云同步过程统计信息。 | 920 921## SqlExecutionInfo<sup>12+</sup> 922 923描述数据库执行的SQL语句的统计信息。 924 925**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 926 927| 名称 | 类型 | 只读 | 可选 |说明 | 928| -------- | ------------------------------------------------- | ---- | ---- | -------------------------------------------------------- | 929| sql<sup>12+</sup> | Array<string> | 是 | 否 | 表示执行的SQL语句的数组。当[batchInsert](#batchinsert)的参数太大时,可能有多个SQL。 | 930| totalTime<sup>12+</sup> | number | 是 | 否 | 表示执行SQL语句的总时间,单位为μs。 | 931| waitTime<sup>12+</sup> | number | 是 | 否 | 表示获取句柄的时间,单位为μs。 | 932| prepareTime<sup>12+</sup> | number | 是 | 否 | 表示准备SQL和绑定参数的时间,单位为μs。 | 933| executeTime<sup>12+</sup> | number | 是 | 否 | 表示执行SQL语句的时间,单位为μs。 | 934 935## RdbPredicates 936 937表示关系型数据库(RDB)的谓词。该类确定RDB中条件表达式的值是true还是false。谓词间支持多语句拼接,拼接时默认使用and()连接。不支持Sendable跨线程传递。 938 939### constructor 940 941constructor(name: string) 942 943构造函数。 944 945**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 946 947**参数:** 948 949| 参数名 | 类型 | 必填 | 说明 | 950| ------ | ------ | ---- | ------------ | 951| name | string | 是 | 数据库表名。 | 952 953**错误码:** 954 955以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 956 957| **错误码ID** | **错误信息** | 958| --------- |----------------------------------------------------------------------------------------------------------------| 959| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 960 961**示例:** 962 963```ts 964let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 965``` 966 967### inDevices 968 969inDevices(devices: Array<string>): RdbPredicates 970 971同步分布式数据库时连接到组网内指定的远程设备。 972 973> **说明:** 974> 975> 其中devices通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。 976数据库同步时调用Sync接口,需要在入参谓词中调用inDevices接口选择设备。如果不调用inDevices接口即默认连接组网内所有的设备。 977 978**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 979 980**参数:** 981 982| 参数名 | 类型 | 必填 | 说明 | 983| ------- | ------------------- | ---- | -------------------------- | 984| devices | Array<string> | 是 | 指定的组网内的远程设备ID。 | 985 986**返回值**: 987 988| 类型 | 说明 | 989| ------------------------------------ | -------------------------- | 990| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 991 992**错误码:** 993 994以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 995 996| **错误码ID** | **错误信息** | 997| --------- |----------------------------------------------------------------------------------------------------------------| 998| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 999 1000**示例:** 1001 1002```ts 1003import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 1004import { BusinessError } from '@kit.BasicServicesKit'; 1005 1006let dmInstance: distributedDeviceManager.DeviceManager; 1007let deviceIds: Array<string> = []; 1008 1009try { 1010 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 1011 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 1012 for (let i = 0; i < devices.length; i++) { 1013 deviceIds[i] = devices[i].networkId!; 1014 } 1015} catch (err) { 1016 let code = (err as BusinessError).code; 1017 let message = (err as BusinessError).message 1018 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 1019} 1020 1021let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1022predicates.inDevices(deviceIds); 1023``` 1024 1025### inAllDevices 1026 1027inAllDevices(): RdbPredicates 1028 1029同步分布式数据库时连接到组网内所有的远程设备。 1030 1031 1032**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1033 1034**返回值**: 1035 1036| 类型 | 说明 | 1037| ------------------------------------ | -------------------------- | 1038| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1039 1040**示例:** 1041 1042```ts 1043let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1044predicates.inAllDevices(); 1045``` 1046 1047### equalTo 1048 1049equalTo(field: string, value: ValueType): RdbPredicates 1050 1051配置谓词以匹配数据表的field列中值为value的字段。 1052 1053**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1054 1055**参数:** 1056 1057| 参数名 | 类型 | 必填 | 说明 | 1058| ------ | ----------------------- | ---- | ---------------------- | 1059| field | string | 是 | 数据库表中的列名。 | 1060| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | 1061 1062**返回值**: 1063 1064| 类型 | 说明 | 1065| ------------------------------------ | -------------------------- | 1066| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1067 1068**错误码:** 1069 1070以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1071 1072| **错误码ID** | **错误信息** | 1073| --------- |----------------------------------------------------------------------------------------------------------------| 1074| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1075 1076**示例:** 1077 1078```ts 1079// 匹配数据表的"NAME"列中值为"Lisa"的字段 1080let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1081predicates.equalTo("NAME", "Lisa"); 1082``` 1083 1084 1085### notEqualTo 1086 1087notEqualTo(field: string, value: ValueType): RdbPredicates 1088 1089配置谓词以匹配数据表的field列中值不为value的字段。 1090 1091**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1092 1093**参数:** 1094 1095| 参数名 | 类型 | 必填 | 说明 | 1096| ------ | ----------------------- | ---- | ---------------------- | 1097| field | string | 是 | 数据库表中的列名。 | 1098| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | 1099 1100**返回值**: 1101 1102| 类型 | 说明 | 1103| ------------------------------------ | -------------------------- | 1104| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1105 1106**错误码:** 1107 1108以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1109 1110| **错误码ID** | **错误信息** | 1111| --------- |----------------------------------------------------------------------------------------------------------------| 1112| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1113 1114**示例:** 1115 1116```ts 1117// 匹配数据表的"NAME"列中值不为"Lisa"的字段 1118let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1119predicates.notEqualTo("NAME", "Lisa"); 1120``` 1121 1122 1123### beginWrap 1124 1125beginWrap(): RdbPredicates 1126 1127向谓词添加左括号。 1128 1129**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1130 1131**返回值**: 1132 1133| 类型 | 说明 | 1134| ------------------------------------ | ------------------------- | 1135| [RdbPredicates](#rdbpredicates) | 返回带有左括号的Rdb谓词。 | 1136 1137**示例:** 1138 1139```ts 1140let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1141predicates.equalTo("NAME", "Lisa") 1142 .beginWrap() 1143 .equalTo("AGE", 18) 1144 .or() 1145 .equalTo("SALARY", 200.5) 1146 .endWrap() 1147``` 1148 1149### endWrap 1150 1151endWrap(): RdbPredicates 1152 1153向谓词添加右括号。 1154 1155**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1156 1157**返回值**: 1158 1159| 类型 | 说明 | 1160| ------------------------------------ | ------------------------- | 1161| [RdbPredicates](#rdbpredicates) | 返回带有右括号的Rdb谓词。 | 1162 1163**示例:** 1164 1165```ts 1166let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1167predicates.equalTo("NAME", "Lisa") 1168 .beginWrap() 1169 .equalTo("AGE", 18) 1170 .or() 1171 .equalTo("SALARY", 200.5) 1172 .endWrap() 1173``` 1174 1175### or 1176 1177or(): RdbPredicates 1178 1179将或条件添加到谓词中。 1180 1181**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1182 1183**返回值**: 1184 1185| 类型 | 说明 | 1186| ------------------------------------ | ------------------------- | 1187| [RdbPredicates](#rdbpredicates) | 返回带有或条件的Rdb谓词。 | 1188 1189**示例:** 1190 1191```ts 1192// 匹配数据表的"NAME"列中值为"Lisa"或"Rose"的字段 1193let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1194predicates.equalTo("NAME", "Lisa") 1195 .or() 1196 .equalTo("NAME", "Rose") 1197``` 1198 1199### and 1200 1201and(): RdbPredicates 1202 1203向谓词添加和条件。 1204 1205**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1206 1207**返回值**: 1208 1209| 类型 | 说明 | 1210| ------------------------------------ | ------------------------- | 1211| [RdbPredicates](#rdbpredicates) | 返回带有和条件的Rdb谓词。 | 1212 1213**示例:** 1214 1215```ts 1216// 匹配数据表的"NAME"列中值为"Lisa"且"SALARY"列中值为"200.5"的字段 1217let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1218predicates.equalTo("NAME", "Lisa") 1219 .and() 1220 .equalTo("SALARY", 200.5) 1221``` 1222 1223### contains 1224 1225contains(field: string, value: string): RdbPredicates 1226 1227配置谓词以匹配数据表的field列中包含value的字段。 1228 1229**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1230 1231**参数:** 1232 1233| 参数名 | 类型 | 必填 | 说明 | 1234| ------ | ------ | ---- | ---------------------- | 1235| field | string | 是 | 数据库表中的列名。 | 1236| value | string | 是 | 指示要与谓词匹配的值。 | 1237 1238**返回值**: 1239 1240| 类型 | 说明 | 1241| ------------------------------------ | -------------------------- | 1242| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1243 1244**错误码:** 1245 1246以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1247 1248| **错误码ID** | **错误信息** | 1249| --------- |----------------------------------------------------------------------------------------------------------------| 1250| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1251 1252**示例:** 1253 1254```ts 1255// 匹配数据表的"NAME"列中包含"os"的字段,如"Rose" 1256let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1257predicates.contains("NAME", "os"); 1258``` 1259 1260### beginsWith 1261 1262beginsWith(field: string, value: string): RdbPredicates 1263 1264配置谓词以匹配数据表的field列中以value开头的字段。 1265 1266**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1267 1268**参数:** 1269 1270| 参数名 | 类型 | 必填 | 说明 | 1271| ------ | ------ | ---- | ---------------------- | 1272| field | string | 是 | 数据库表中的列名。 | 1273| value | string | 是 | 指示要与谓词匹配的值。 | 1274 1275**返回值**: 1276 1277| 类型 | 说明 | 1278| ------------------------------------ | -------------------------- | 1279| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1280 1281**错误码:** 1282 1283以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1284 1285| **错误码ID** | **错误信息** | 1286| --------- |----------------------------------------------------------------------------------------------------------------| 1287| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1288 1289**示例:** 1290 1291```ts 1292// 匹配数据表的"NAME"列中以"Li"开头的字段,如"Lisa" 1293let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1294predicates.beginsWith("NAME", "Li"); 1295``` 1296 1297### endsWith 1298 1299endsWith(field: string, value: string): RdbPredicates 1300 1301配置谓词以匹配数据表的field列中以value结尾的字段。 1302 1303**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1304 1305**参数:** 1306 1307| 参数名 | 类型 | 必填 | 说明 | 1308| ------ | ------ | ---- | ---------------------- | 1309| field | string | 是 | 数据库表中的列名。 | 1310| value | string | 是 | 指示要与谓词匹配的值。 | 1311 1312**返回值**: 1313 1314| 类型 | 说明 | 1315| ------------------------------------ | -------------------------- | 1316| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1317 1318**错误码:** 1319 1320以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1321 1322| **错误码ID** | **错误信息** | 1323| --------- |----------------------------------------------------------------------------------------------------------------| 1324| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1325 1326**示例:** 1327 1328```ts 1329// 匹配数据表的"NAME"列中以"se"结尾的字段,如"Rose" 1330let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1331predicates.endsWith("NAME", "se"); 1332``` 1333 1334### isNull 1335 1336isNull(field: string): RdbPredicates 1337 1338配置谓词以匹配数据表的field列中值为null的字段。 1339 1340**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1341 1342**参数:** 1343 1344| 参数名 | 类型 | 必填 | 说明 | 1345| ------ | ------ | ---- | ------------------ | 1346| field | string | 是 | 数据库表中的列名。 | 1347 1348**返回值**: 1349 1350| 类型 | 说明 | 1351| ------------------------------------ | -------------------------- | 1352| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1353 1354**错误码:** 1355 1356以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1357 1358| **错误码ID** | **错误信息** | 1359| --------- |----------------------------------------------------------------------------------------------------------------| 1360| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1361 1362**示例**: 1363 1364```ts 1365let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1366predicates.isNull("NAME"); 1367``` 1368 1369### isNotNull 1370 1371isNotNull(field: string): RdbPredicates 1372 1373配置谓词以匹配数据表的field列中值不为null的字段。 1374 1375**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1376 1377**参数:** 1378 1379| 参数名 | 类型 | 必填 | 说明 | 1380| ------ | ------ | ---- | ------------------ | 1381| field | string | 是 | 数据库表中的列名。 | 1382 1383**返回值**: 1384 1385| 类型 | 说明 | 1386| ------------------------------------ | -------------------------- | 1387| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1388 1389**错误码:** 1390 1391以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1392 1393| **错误码ID** | **错误信息** | 1394| --------- |----------------------------------------------------------------------------------------------------------------| 1395| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1396 1397**示例:** 1398 1399```ts 1400let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1401predicates.isNotNull("NAME"); 1402``` 1403 1404### like 1405 1406like(field: string, value: string): RdbPredicates 1407 1408配置谓词以匹配数据表的field列中值类似于value的字段。 1409 1410**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1411 1412**参数:** 1413 1414| 参数名 | 类型 | 必填 | 说明 | 1415| ------ | ------ | ---- | ---------------------- | 1416| field | string | 是 | 数据库表中的列名。 | 1417| value | string | 是 | 指示要与谓词匹配的值。 | 1418 1419**返回值**: 1420 1421| 类型 | 说明 | 1422| ------------------------------------ | -------------------------- | 1423| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1424 1425**错误码:** 1426 1427以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1428 1429| **错误码ID** | **错误信息** | 1430| --------- |----------------------------------------------------------------------------------------------------------------| 1431| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1432 1433**示例:** 1434 1435```ts 1436// 匹配数据表的"NAME"列中值类似于"os"的字段,如"Rose" 1437let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1438predicates.like("NAME", "%os%"); 1439``` 1440 1441### glob 1442 1443glob(field: string, value: string): RdbPredicates 1444 1445配置谓词匹配数据字段为string的指定字段。 1446 1447**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1448 1449**参数:** 1450 1451| 参数名 | 类型 | 必填 | 说明 | 1452| ------ | ------ | ---- | ------------------------------------------------------------ | 1453| field | string | 是 | 数据库表中的列名。 | 1454| value | string | 是 | 指示要与谓词匹配的值。<br>支持通配符,*表示0个、1个或多个数字或字符,?表示1个数字或字符。 | 1455 1456**返回值**: 1457 1458| 类型 | 说明 | 1459| ------------------------------------ | -------------------------- | 1460| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1461 1462**错误码:** 1463 1464以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1465 1466| **错误码ID** | **错误信息** | 1467| --------- |----------------------------------------------------------------------------------------------------------------| 1468| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1469 1470**示例:** 1471 1472```ts 1473// 匹配数据表的"NAME"列中类型为string且值为"?h*g"的字段 1474let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1475predicates.glob("NAME", "?h*g"); 1476``` 1477 1478### between 1479 1480between(field: string, low: ValueType, high: ValueType): RdbPredicates 1481 1482配置谓词以匹配数据表的field列中值在给定范围内的字段(包含范围边界)。 1483 1484**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1485 1486**参数:** 1487 1488| 参数名 | 类型 | 必填 | 说明 | 1489| ------ | ----------------------- | ---- | -------------------------- | 1490| field | string | 是 | 数据库表中的列名。 | 1491| low | [ValueType](#valuetype) | 是 | 指示与谓词匹配的最小值。 | 1492| high | [ValueType](#valuetype) | 是 | 指示与谓词匹配的最大值。 | 1493 1494**返回值**: 1495 1496| 类型 | 说明 | 1497| ------------------------------------ | -------------------------- | 1498| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1499 1500**错误码:** 1501 1502以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1503 1504| **错误码ID** | **错误信息** | 1505| --------- |----------------------------------------------------------------------------------------------------------------| 1506| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1507 1508**示例:** 1509 1510```ts 1511// 匹配数据表的"AGE"列中大于等于10且小于等于50的值 1512let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1513predicates.between("AGE", 10, 50); 1514``` 1515 1516### notBetween 1517 1518notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates 1519 1520配置谓词以匹配数据表的field列中值超出给定范围的字段(不包含范围边界)。 1521 1522**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1523 1524**参数:** 1525 1526| 参数名 | 类型 | 必填 | 说明 | 1527| ------ | ----------------------- | ---- | -------------------------- | 1528| field | string | 是 | 数据库表中的列名。 | 1529| low | [ValueType](#valuetype) | 是 | 指示与谓词匹配的最小值。 | 1530| high | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的最大值。 | 1531 1532**返回值**: 1533 1534| 类型 | 说明 | 1535| ------------------------------------ | -------------------------- | 1536| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1537 1538**错误码:** 1539 1540以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1541 1542| **错误码ID** | **错误信息** | 1543| --------- |----------------------------------------------------------------------------------------------------------------| 1544| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1545 1546**示例:** 1547 1548```ts 1549// 匹配数据表的"AGE"列中小于10或大于50的值 1550let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1551predicates.notBetween("AGE", 10, 50); 1552``` 1553 1554### greaterThan 1555 1556greaterThan(field: string, value: ValueType): RdbPredicates 1557 1558配置谓词以匹配数据表的field列中值大于value的字段。 1559 1560**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1561 1562**参数:** 1563 1564| 参数名 | 类型 | 必填 | 说明 | 1565| ------ | ----------------------- | ---- | ---------------------- | 1566| field | string | 是 | 数据库表中的列名。 | 1567| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | 1568 1569**返回值**: 1570 1571| 类型 | 说明 | 1572| ------------------------------------ | -------------------------- | 1573| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1574 1575**错误码:** 1576 1577以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1578 1579| **错误码ID** | **错误信息** | 1580| --------- |----------------------------------------------------------------------------------------------------------------| 1581| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1582 1583**示例:** 1584 1585```ts 1586// 匹配数据表的"AGE"列中大于18的值 1587let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1588predicates.greaterThan("AGE", 18); 1589``` 1590 1591### lessThan 1592 1593lessThan(field: string, value: ValueType): RdbPredicates 1594 1595配置谓词以匹配数据表的field列中值小于value的字段。 1596 1597**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1598 1599**参数:** 1600 1601| 参数名 | 类型 | 必填 | 说明 | 1602| ------ | ----------------------- | ---- | ---------------------- | 1603| field | string | 是 | 数据库表中的列名。 | 1604| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | 1605 1606**返回值**: 1607 1608| 类型 | 说明 | 1609| ------------------------------------ | -------------------------- | 1610| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1611 1612**错误码:** 1613 1614以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1615 1616| **错误码ID** | **错误信息** | 1617| --------- |----------------------------------------------------------------------------------------------------------------| 1618| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1619 1620**示例:** 1621 1622```ts 1623// 匹配数据表的"AGE"列中小于20的值 1624let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1625predicates.lessThan("AGE", 20); 1626``` 1627 1628### greaterThanOrEqualTo 1629 1630greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1631 1632配置谓词以匹配数据表的field列中值大于或者等于value的字段。 1633 1634**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1635 1636**参数:** 1637 1638| 参数名 | 类型 | 必填 | 说明 | 1639| ------ | ----------------------- | ---- | ---------------------- | 1640| field | string | 是 | 数据库表中的列名。 | 1641| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | 1642 1643**返回值**: 1644 1645| 类型 | 说明 | 1646| ------------------------------------ | -------------------------- | 1647| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1648 1649**错误码:** 1650 1651以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1652 1653| **错误码ID** | **错误信息** | 1654| --------- |----------------------------------------------------------------------------------------------------------------| 1655| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1656 1657**示例:** 1658 1659```ts 1660// 匹配数据表的"AGE"列中大于等于18的值 1661let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1662predicates.greaterThanOrEqualTo("AGE", 18); 1663``` 1664 1665### lessThanOrEqualTo 1666 1667lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates 1668 1669配置谓词以匹配数据表的field列中值小于或者等于value的字段。 1670 1671**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1672 1673**参数:** 1674 1675| 参数名 | 类型 | 必填 | 说明 | 1676| ------ | ----------------------- | ---- | ---------------------- | 1677| field | string | 是 | 数据库表中的列名。 | 1678| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | 1679 1680**返回值**: 1681 1682| 类型 | 说明 | 1683| ------------------------------------ | -------------------------- | 1684| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1685 1686**错误码:** 1687 1688以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1689 1690| **错误码ID** | **错误信息** | 1691| --------- |----------------------------------------------------------------------------------------------------------------| 1692| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1693 1694**示例:** 1695 1696```ts 1697// 匹配数据表的"AGE"列中小于等于20的值 1698let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1699predicates.lessThanOrEqualTo("AGE", 20); 1700``` 1701 1702### orderByAsc 1703 1704orderByAsc(field: string): RdbPredicates 1705 1706配置谓词以匹配数据表的field列中值按升序排序的列。 1707 1708**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1709 1710**参数:** 1711 1712| 参数名 | 类型 | 必填 | 说明 | 1713| ------ | ------ | ---- | ------------------ | 1714| field | string | 是 | 数据库表中的列名。 | 1715 1716**返回值**: 1717 1718| 类型 | 说明 | 1719| ------------------------------------ | -------------------------- | 1720| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1721 1722**错误码:** 1723 1724以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1725 1726| **错误码ID** | **错误信息** | 1727| --------- |----------------------------------------------------------------------------------------------------------------| 1728| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1729 1730**示例:** 1731 1732```ts 1733let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1734predicates.orderByAsc("NAME"); 1735``` 1736 1737### orderByDesc 1738 1739orderByDesc(field: string): RdbPredicates 1740 1741配置谓词以匹配数据表的field列中值按降序排序的列。 1742 1743**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1744 1745**参数:** 1746 1747| 参数名 | 类型 | 必填 | 说明 | 1748| ------ | ------ | ---- | ------------------ | 1749| field | string | 是 | 数据库表中的列名。 | 1750 1751**返回值**: 1752 1753| 类型 | 说明 | 1754| ------------------------------------ | -------------------------- | 1755| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1756 1757**错误码:** 1758 1759以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1760 1761| **错误码ID** | **错误信息** | 1762| --------- |----------------------------------------------------------------------------------------------------------------| 1763| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1764 1765**示例:** 1766 1767```ts 1768let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1769predicates.orderByDesc("AGE"); 1770``` 1771 1772### distinct 1773 1774distinct(): RdbPredicates 1775 1776配置谓词以过滤重复记录并仅保留其中一个。 1777 1778**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1779 1780**返回值**: 1781 1782| 类型 | 说明 | 1783| ------------------------------------ | ------------------------------ | 1784| [RdbPredicates](#rdbpredicates) | 返回可用于过滤重复记录的谓词。 | 1785 1786**示例:** 1787 1788```ts 1789let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1790predicates.equalTo("NAME", "Rose").distinct(); 1791``` 1792 1793### limitAs 1794 1795limitAs(value: number): RdbPredicates 1796 1797设置最大数据记录数的谓词。 1798 1799**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1800 1801**参数:** 1802 1803| 参数名 | 类型 | 必填 | 说明 | 1804| ------ | ------ | ---- | ---------------- | 1805| value | number | 是 | 最大数据记录数。 | 1806 1807**返回值**: 1808 1809| 类型 | 说明 | 1810| ------------------------------------ | ------------------------------------ | 1811| [RdbPredicates](#rdbpredicates) | 返回可用于设置最大数据记录数的谓词。 | 1812 1813**错误码:** 1814 1815以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1816 1817| **错误码ID** | **错误信息** | 1818| --------- |--------------------------| 1819| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1820 1821**示例:** 1822 1823```ts 1824let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1825predicates.equalTo("NAME", "Rose").limitAs(3); 1826``` 1827 1828### offsetAs 1829 1830offsetAs(rowOffset: number): RdbPredicates 1831 1832配置谓词以指定返回结果的起始位置。 1833 1834**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1835 1836**参数:** 1837 1838| 参数名 | 类型 | 必填 | 说明 | 1839| --------- | ------ | ---- | ---------------------------------- | 1840| rowOffset | number | 是 | 返回结果的起始位置,取值为正整数。 | 1841 1842**返回值**: 1843 1844| 类型 | 说明 | 1845| ------------------------------------ | ------------------------------------ | 1846| [RdbPredicates](#rdbpredicates) | 返回具有指定返回结果起始位置的谓词。 | 1847 1848**错误码:** 1849 1850以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1851 1852| **错误码ID** | **错误信息** | 1853| --------- |----------------------------------------------------------------------------------------------------------------| 1854| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1855 1856**示例:** 1857 1858```ts 1859let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1860predicates.equalTo("NAME", "Rose").offsetAs(3); 1861``` 1862 1863### groupBy 1864 1865groupBy(fields: Array<string>): RdbPredicates 1866 1867配置谓词按指定列分组查询结果。 1868 1869**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1870 1871**参数:** 1872 1873| 参数名 | 类型 | 必填 | 说明 | 1874| ------ | ------------------- | ---- | -------------------- | 1875| fields | Array<string> | 是 | 指定分组依赖的列名。 | 1876 1877**返回值**: 1878 1879| 类型 | 说明 | 1880| ------------------------------------ | ---------------------- | 1881| [RdbPredicates](#rdbpredicates) | 返回分组查询列的谓词。 | 1882 1883**错误码:** 1884 1885以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1886 1887| **错误码ID** | **错误信息** | 1888| --------- |----------------------------------------------------------------------------------------------------------------| 1889| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1890 1891**示例:** 1892 1893```ts 1894let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1895predicates.groupBy(["AGE", "NAME"]); 1896``` 1897 1898### indexedBy 1899 1900indexedBy(field: string): RdbPredicates 1901 1902配置谓词以指定索引列。 1903 1904**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1905 1906**参数:** 1907 1908| 参数名 | 类型 | 必填 | 说明 | 1909| ------ | ------ | ---- | -------------- | 1910| field | string | 是 | 索引列的名称。 | 1911 1912**返回值**: 1913 1914 1915| 类型 | 说明 | 1916| ------------------------------------ | ------------------------------------- | 1917| [RdbPredicates](#rdbpredicates) | 返回具有指定索引列的RdbPredicates。 | 1918 1919**错误码:** 1920 1921以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1922 1923| **错误码ID** | **错误信息** | 1924| --------- |----------------------------------------------------------------------------------------------------------------| 1925| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1926 1927**示例:** 1928 1929```ts 1930let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1931predicates.indexedBy("SALARY"); 1932``` 1933 1934### in 1935 1936in(field: string, value: Array<ValueType>): RdbPredicates 1937 1938配置谓词以匹配数据表的field列中值在给定范围内的字段。 1939 1940**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1941 1942**参数:** 1943 1944| 参数名 | 类型 | 必填 | 说明 | 1945| ------ | ------------------------------------ | ---- | --------------------------------------- | 1946| field | string | 是 | 数据库表中的列名。 | 1947| value | Array<[ValueType](#valuetype)> | 是 | 以ValueType型数组形式指定的要匹配的值。 | 1948 1949**返回值**: 1950 1951| 类型 | 说明 | 1952| ------------------------------------ | -------------------------- | 1953| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1954 1955**错误码:** 1956 1957以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1958 1959| **错误码ID** | **错误信息** | 1960| --------- |----------------------------------------------------------------------------------------------------------------| 1961| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1962 1963**示例:** 1964 1965```ts 1966// 匹配数据表的"AGE"列中在[18,20]中的值 1967let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 1968predicates.in("AGE", [18, 20]); 1969``` 1970 1971### notIn 1972 1973notIn(field: string, value: Array<ValueType>): RdbPredicates 1974 1975将谓词配置为匹配数据字段为ValueType且值超出给定范围的指定字段。 1976 1977**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1978 1979**参数:** 1980 1981| 参数名 | 类型 | 必填 | 说明 | 1982| ------ | ------------------------------------ | ---- | ------------------------------------- | 1983| field | string | 是 | 数据库表中的列名。 | 1984| value | Array<[ValueType](#valuetype)> | 是 | 以ValueType数组形式指定的要匹配的值。 | 1985 1986**返回值**: 1987 1988| 类型 | 说明 | 1989| ------------------------------------ | -------------------------- | 1990| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 1991 1992**错误码:** 1993 1994以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1995 1996| **错误码ID** | **错误信息** | 1997| --------- |----------------------------------------------------------------------------------------------------------------| 1998| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1999 2000**示例:** 2001 2002```ts 2003// 匹配数据表的"NAME"列中不在["Lisa", "Rose"]中的值 2004let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2005predicates.notIn("NAME", ["Lisa", "Rose"]); 2006``` 2007 2008### notContains<sup>12+</sup> 2009 2010notContains(field: string, value: string): RdbPredicates 2011 2012配置谓词以匹配数据表的field列中不包含value的字段。 2013 2014**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2015 2016**参数:** 2017 2018| 参数名 | 类型 | 必填 | 说明 | 2019| ------ | ------ | ---- | ---------------------- | 2020| field | string | 是 | 数据库表中的列名。 | 2021| value | string | 是 | 指示要与谓词匹配的值。 | 2022 2023**返回值**: 2024 2025| 类型 | 说明 | 2026| ------------------------------- | -------------------------- | 2027| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 2028 2029**错误码:** 2030 2031以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 2032 2033| **错误码ID** | **错误信息** | 2034| --------- |----------------------------------------------------------------------------------------------------------------| 2035| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2036 2037**示例:** 2038 2039```ts 2040// 匹配数据表的"NAME"列中不包含"os"的字段,如列表中的"Lisa" 2041let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2042predicates.notContains("NAME", "os"); 2043``` 2044 2045### notLike<sup>12+</sup> 2046 2047notLike(field: string, value: string): RdbPredicates 2048 2049配置谓词以匹配数据表的field列中值不存在类似于value的字段。 2050 2051**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2052 2053**参数:** 2054 2055| 参数名 | 类型 | 必填 | 说明 | 2056| ------ | ------ | ---- | ---------------------- | 2057| field | string | 是 | 数据库表中的列名。 | 2058| value | string | 是 | 指示要与谓词匹配的值。 | 2059 2060**返回值**: 2061 2062| 类型 | 说明 | 2063| ------------------------------- | -------------------------- | 2064| [RdbPredicates](#rdbpredicates) | 返回与指定字段匹配的谓词。 | 2065 2066**错误码:** 2067 2068以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 2069 2070| **错误码ID** | **错误信息** | 2071| --------- |----------------------------------------------------------------------------------------------------------------| 2072| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2073 2074**示例:** 2075 2076```ts 2077// 匹配数据表的"NAME"列中不等于"os"的字段,如列表中的"Rose" 2078let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2079predicates.notLike("NAME", "os"); 2080``` 2081 2082 2083 2084## RdbStore 2085 2086提供管理关系数据库(RDB)方法的接口。 2087 2088在使用以下相关接口前,请使用[executeSql](#executesql)接口初始化数据库表结构和相关数据。 2089 2090### 属性 2091 2092**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2093 2094| 名称 | 类型 | 只读 | 可选 | 说明 | 2095| ------------ | ----------- | ---- | -------------------------------- | -------------------------------- | 2096| version<sup>10+</sup> | number | 否 | 否 | 设置和获取数据库版本,值为大于0的正整数。 | 2097| rebuilt<sup>12+</sup> | [RebuildType](#rebuildtype12) | 是 | 否 | 用于获取数据库是否进行过重建或修复。 | 2098 2099**错误码:** 2100 2101以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 2102 2103| **错误码ID** | **错误信息** | 2104|-----------| ------------------------------------------------------------ | 2105| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2106| 801 | Capability not supported. | 2107| 14800000 | Inner error. | 2108| 14800014 | Already closed. | 2109| 14800015 | The database does not respond. | 2110| 14800021 | SQLite: Generic error. | 2111| 14800023 | SQLite: Access permission denied. | 2112| 14800024 | SQLite: The database file is locked. | 2113| 14800025 | SQLite: A table in the database is locked. | 2114| 14800026 | SQLite: The database is out of memory. | 2115| 14800027 | SQLite: Attempt to write a readonly database. | 2116| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2117| 14800029 | SQLite: The database is full. | 2118| 14800030 | SQLite: Unable to open the database file. | 2119 2120**示例:** 2121 2122```ts 2123// 设置数据库版本 2124if(store != undefined) { 2125 (store as relationalStore.RdbStore).version = 3; 2126 // 获取数据库版本 2127 console.info(`RdbStore version is ${store.version}`); 2128 // 获取数据库是否重建 2129 console.info(`RdbStore rebuilt is ${store.rebuilt}`); 2130} 2131``` 2132 2133### insert 2134 2135insert(table: string, values: ValuesBucket, callback: AsyncCallback<number>):void 2136 2137向目标表中插入一行数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 2138 2139**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2140 2141**参数:** 2142 2143| 参数名 | 类型 | 必填 | 说明 | 2144| -------- | ----------------------------- | ---- | ---------------------------------------------------------- | 2145| table | string | 是 | 指定的目标表名。 | 2146| values | [ValuesBucket](#valuesbucket) | 是 | 表示要插入到表中的数据行。 | 2147| callback | AsyncCallback<number> | 是 | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 | 2148 2149**错误码:** 2150 2151以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 2152 2153| **错误码ID** | **错误信息** | 2154|-----------| ------------------------------------------------------------ | 2155| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2156| 14800000 | Inner error. | 2157| 14800011 | Database corrupted. | 2158| 14800014 | Already closed. | 2159| 14800015 | The database does not respond. | 2160| 14800021 | SQLite: Generic error. | 2161| 14800022 | SQLite: Callback routine requested an abort. | 2162| 14800023 | SQLite: Access permission denied. | 2163| 14800024 | SQLite: The database file is locked. | 2164| 14800025 | SQLite: A table in the database is locked. | 2165| 14800026 | SQLite: The database is out of memory. | 2166| 14800027 | SQLite: Attempt to write a readonly database. | 2167| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2168| 14800029 | SQLite: The database is full. | 2169| 14800030 | SQLite: Unable to open the database file. | 2170| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2171| 14800032 | SQLite: Abort due to constraint violation. | 2172| 14800033 | SQLite: Data type mismatch. | 2173| 14800034 | SQLite: Library used incorrectly. | 2174| 14800047 | The WAL file size exceeds the default limit. | 2175 2176**示例:** 2177 2178```ts 2179let value1 = "Lisa"; 2180let value2 = 18; 2181let value3 = 100.5; 2182let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2183 2184// 以下三种方式可用 2185const valueBucket1: relationalStore.ValuesBucket = { 2186 'NAME': value1, 2187 'AGE': value2, 2188 'SALARY': value3, 2189 'CODES': value4, 2190}; 2191const valueBucket2: relationalStore.ValuesBucket = { 2192 NAME: value1, 2193 AGE: value2, 2194 SALARY: value3, 2195 CODES: value4, 2196}; 2197const valueBucket3: relationalStore.ValuesBucket = { 2198 "NAME": value1, 2199 "AGE": value2, 2200 "SALARY": value3, 2201 "CODES": value4, 2202}; 2203 2204if(store != undefined) { 2205 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, (err: BusinessError, rowId: number) => { 2206 if (err) { 2207 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2208 return; 2209 } 2210 console.info(`Insert is successful, rowId = ${rowId}`); 2211 }) 2212} 2213``` 2214 2215### insert<sup>10+</sup> 2216 2217insert(table: string, values: ValuesBucket, conflict: ConflictResolution, callback: AsyncCallback<number>):void 2218 2219向目标表中插入一行数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 2220 2221**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2222 2223**参数:** 2224 2225| 参数名 | 类型 | 必填 | 说明 | 2226| -------- | ------------------------------------------- | ---- | ---------------------------------------------------------- | 2227| table | string | 是 | 指定的目标表名。 | 2228| values | [ValuesBucket](#valuesbucket) | 是 | 表示要插入到表中的数据行。 | 2229| conflict | [ConflictResolution](#conflictresolution10) | 是 | 指定冲突解决模式。 | 2230| callback | AsyncCallback<number> | 是 | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 | 2231 2232**错误码:** 2233 2234以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 2235 2236| **错误码ID** | **错误信息** | 2237|-----------| ---------------------------------------------------- | 2238| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2239| 14800000 | Inner error. | 2240| 14800011 | Database corrupted. | 2241| 14800014 | Already closed. | 2242| 14800015 | The database does not respond. | 2243| 14800021 | SQLite: Generic error. | 2244| 14800022 | SQLite: Callback routine requested an abort. | 2245| 14800023 | SQLite: Access permission denied. | 2246| 14800024 | SQLite: The database file is locked. | 2247| 14800025 | SQLite: A table in the database is locked. | 2248| 14800026 | SQLite: The database is out of memory. | 2249| 14800027 | SQLite: Attempt to write a readonly database. | 2250| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2251| 14800029 | SQLite: The database is full. | 2252| 14800030 | SQLite: Unable to open the database file. | 2253| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2254| 14800032 | SQLite: Abort due to constraint violation. | 2255| 14800033 | SQLite: Data type mismatch. | 2256| 14800034 | SQLite: Library used incorrectly. | 2257| 14800047 | The WAL file size exceeds the default limit. | 2258 2259**示例:** 2260 2261```ts 2262let value1 = "Lisa"; 2263let value2 = 18; 2264let value3 = 100.5; 2265let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2266 2267// 以下三种方式可用 2268const valueBucket1: relationalStore.ValuesBucket = { 2269 'NAME': value1, 2270 'AGE': value2, 2271 'SALARY': value3, 2272 'CODES': value4, 2273}; 2274const valueBucket2: relationalStore.ValuesBucket = { 2275 NAME: value1, 2276 AGE: value2, 2277 SALARY: value3, 2278 CODES: value4, 2279}; 2280const valueBucket3: relationalStore.ValuesBucket = { 2281 "NAME": value1, 2282 "AGE": value2, 2283 "SALARY": value3, 2284 "CODES": value4, 2285}; 2286 2287if(store != undefined) { 2288 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, 2289 (err: BusinessError, rowId: number) => { 2290 if (err) { 2291 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2292 return; 2293 } 2294 console.info(`Insert is successful, rowId = ${rowId}`); 2295 }) 2296} 2297``` 2298 2299### insert 2300 2301insert(table: string, values: ValuesBucket):Promise<number> 2302 2303向目标表中插入一行数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 2304 2305**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2306 2307**参数:** 2308 2309| 参数名 | 类型 | 必填 | 说明 | 2310| ------ | ----------------------------- | ---- | -------------------------- | 2311| table | string | 是 | 指定的目标表名。 | 2312| values | [ValuesBucket](#valuesbucket) | 是 | 表示要插入到表中的数据行。 | 2313 2314**返回值**: 2315 2316| 类型 | 说明 | 2317| --------------------- | ------------------------------------------------- | 2318| Promise<number> | Promise对象。如果操作成功,返回行ID;否则返回-1。 | 2319 2320**错误码:** 2321 2322以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 2323 2324| **错误码ID** | **错误信息** | 2325|-----------| ------------------------------------------------------------ | 2326| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2327| 14800000 | Inner error. | 2328| 14800011 | Database corrupted. | 2329| 14800014 | Already closed. | 2330| 14800015 | The database does not respond. | 2331| 14800021 | SQLite: Generic error. | 2332| 14800022 | SQLite: Callback routine requested an abort. | 2333| 14800023 | SQLite: Access permission denied. | 2334| 14800024 | SQLite: The database file is locked. | 2335| 14800025 | SQLite: A table in the database is locked. | 2336| 14800026 | SQLite: The database is out of memory. | 2337| 14800027 | SQLite: Attempt to write a readonly database. | 2338| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2339| 14800029 | SQLite: The database is full. | 2340| 14800030 | SQLite: Unable to open the database file. | 2341| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2342| 14800032 | SQLite: Abort due to constraint violation. | 2343| 14800033 | SQLite: Data type mismatch. | 2344| 14800034 | SQLite: Library used incorrectly. | 2345| 14800047 | The WAL file size exceeds the default limit. | 2346 2347**示例:** 2348 2349```ts 2350import { BusinessError } from '@kit.BasicServicesKit'; 2351 2352let value1 = "Lisa"; 2353let value2 = 18; 2354let value3 = 100.5; 2355let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2356 2357// 以下三种方式可用 2358const valueBucket1: relationalStore.ValuesBucket = { 2359 'NAME': value1, 2360 'AGE': value2, 2361 'SALARY': value3, 2362 'CODES': value4, 2363}; 2364const valueBucket2: relationalStore.ValuesBucket = { 2365 NAME: value1, 2366 AGE: value2, 2367 SALARY: value3, 2368 CODES: value4, 2369}; 2370const valueBucket3: relationalStore.ValuesBucket = { 2371 "NAME": value1, 2372 "AGE": value2, 2373 "SALARY": value3, 2374 "CODES": value4, 2375}; 2376 2377if(store != undefined) { 2378 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1).then((rowId: number) => { 2379 console.info(`Insert is successful, rowId = ${rowId}`); 2380 }).catch((err: BusinessError) => { 2381 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2382 }) 2383} 2384``` 2385 2386### insert<sup>10+</sup> 2387 2388insert(table: string, values: ValuesBucket, conflict: ConflictResolution):Promise<number> 2389 2390向目标表中插入一行数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 2391 2392**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2393 2394**参数:** 2395 2396| 参数名 | 类型 | 必填 | 说明 | 2397| -------- | ------------------------------------------- | ---- | -------------------------- | 2398| table | string | 是 | 指定的目标表名。 | 2399| values | [ValuesBucket](#valuesbucket) | 是 | 表示要插入到表中的数据行。 | 2400| conflict | [ConflictResolution](#conflictresolution10) | 是 | 指定冲突解决模式。 | 2401 2402**返回值**: 2403 2404| 类型 | 说明 | 2405| --------------------- | ------------------------------------------------- | 2406| Promise<number> | Promise对象。如果操作成功,返回行ID;否则返回-1。 | 2407 2408**错误码:** 2409 2410以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 2411 2412| **错误码ID** | **错误信息** | 2413|-----------| ------------------------------------------------------------ | 2414| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2415| 14800000 | Inner error. | 2416| 14800011 | Database corrupted. | 2417| 14800014 | Already closed. | 2418| 14800015 | The database does not respond. | 2419| 14800021 | SQLite: Generic error. | 2420| 14800022 | SQLite: Callback routine requested an abort. | 2421| 14800023 | SQLite: Access permission denied. | 2422| 14800024 | SQLite: The database file is locked. | 2423| 14800025 | SQLite: A table in the database is locked. | 2424| 14800026 | SQLite: The database is out of memory. | 2425| 14800027 | SQLite: Attempt to write a readonly database. | 2426| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2427| 14800029 | SQLite: The database is full. | 2428| 14800030 | SQLite: Unable to open the database file. | 2429| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2430| 14800032 | SQLite: Abort due to constraint violation. | 2431| 14800033 | SQLite: Data type mismatch. | 2432| 14800034 | SQLite: Library used incorrectly. | 2433| 14800047 | The WAL file size exceeds the default limit. | 2434 2435**示例:** 2436 2437```ts 2438import { BusinessError } from '@kit.BasicServicesKit'; 2439 2440let value1 = "Lisa"; 2441let value2 = 18; 2442let value3 = 100.5; 2443let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2444 2445// 以下三种方式可用 2446const valueBucket1: relationalStore.ValuesBucket = { 2447 'NAME': value1, 2448 'AGE': value2, 2449 'SALARY': value3, 2450 'CODES': value4, 2451}; 2452const valueBucket2: relationalStore.ValuesBucket = { 2453 NAME: value1, 2454 AGE: value2, 2455 SALARY: value3, 2456 CODES: value4, 2457}; 2458const valueBucket3: relationalStore.ValuesBucket = { 2459 "NAME": value1, 2460 "AGE": value2, 2461 "SALARY": value3, 2462 "CODES": value4, 2463}; 2464 2465if(store != undefined) { 2466 (store as relationalStore.RdbStore).insert("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then((rowId: number) => { 2467 console.info(`Insert is successful, rowId = ${rowId}`); 2468 }).catch((err: BusinessError) => { 2469 console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); 2470 }) 2471} 2472``` 2473 2474### insertSync<sup>12+</sup> 2475 2476insertSync(table: string, values: ValuesBucket, conflict?: ConflictResolution):number 2477 2478向目标表中插入一行数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 2479 2480**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2481 2482**参数:** 2483 2484| 参数名 | 类型 | 必填 | 说明 | 2485| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 2486| table | string | 是 | 指定的目标表名。 | 2487| values | [ValuesBucket](#valuesbucket) | 是 | 表示要插入到表中的数据行。 | 2488| conflict | [ConflictResolution](#conflictresolution10) | 否 | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 | 2489 2490**返回值**: 2491 2492| 类型 | 说明 | 2493| ------ | ------------------------------------ | 2494| number | 如果操作成功,返回行ID;否则返回-1。 | 2495 2496**错误码:** 2497 2498以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 2499 2500| **错误码ID** | **错误信息** | 2501| ------------ | ------------------------------------------------------------ | 2502| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2503| 14800000 | Inner error. | 2504| 14800011 | Database corrupted. | 2505| 14800014 | Already closed. | 2506| 14800015 | The database does not respond. | 2507| 14800021 | SQLite: Generic error. | 2508| 14800022 | SQLite: Callback routine requested an abort. | 2509| 14800023 | SQLite: Access permission denied. | 2510| 14800024 | SQLite: The database file is locked. | 2511| 14800025 | SQLite: A table in the database is locked. | 2512| 14800026 | SQLite: The database is out of memory. | 2513| 14800027 | SQLite: Attempt to write a readonly database. | 2514| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2515| 14800029 | SQLite: The database is full. | 2516| 14800030 | SQLite: Unable to open the database file. | 2517| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2518| 14800032 | SQLite: Abort due to constraint violation. | 2519| 14800033 | SQLite: Data type mismatch. | 2520| 14800034 | SQLite: Library used incorrectly. | 2521| 14800047 | The WAL file size exceeds the default limit. | 2522 2523**示例:** 2524 2525```ts 2526import { BusinessError } from '@kit.BasicServicesKit'; 2527 2528let value1 = "Lisa"; 2529let value2 = 18; 2530let value3 = 100.5; 2531let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2532 2533// 以下三种方式可用 2534const valueBucket1: relationalStore.ValuesBucket = { 2535 'NAME': value1, 2536 'AGE': value2, 2537 'SALARY': value3, 2538 'CODES': value4, 2539}; 2540const valueBucket2: relationalStore.ValuesBucket = { 2541 NAME: value1, 2542 AGE: value2, 2543 SALARY: value3, 2544 CODES: value4, 2545}; 2546const valueBucket3: relationalStore.ValuesBucket = { 2547 "NAME": value1, 2548 "AGE": value2, 2549 "SALARY": value3, 2550 "CODES": value4, 2551}; 2552 2553if(store != undefined) { 2554 try { 2555 let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", valueBucket1, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 2556 console.info(`Insert is successful, rowId = ${rowId}`); 2557 } catch (error) { 2558 console.error(`Insert is failed, code is ${error.code},message is ${error.message}`); 2559 } 2560} 2561``` 2562 2563### insertSync<sup>12+</sup> 2564 2565insertSync(table: string, values: sendableRelationalStore.ValuesBucket, conflict?: ConflictResolution):number 2566 2567传入Sendable数据,向目标表中插入一行数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 2568 2569**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2570 2571**参数:** 2572 2573| 参数名 | 类型 | 必填 | 说明 | 2574| -------- | ---------------------------------------------------------------------------------------------- | ---- | ------------------------------------------------------------------------------- | 2575| table | string | 是 | 指定的目标表名。 | 2576| values | [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | 是 | 表示要插入到表中的可跨线程传递数据。 | 2577| conflict | [ConflictResolution](#conflictresolution10) | 否 | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 | 2578 2579**返回值**: 2580 2581| 类型 | 说明 | 2582| ------ | ------------------------------------ | 2583| number | 如果操作成功,返回行ID;否则返回-1。 | 2584 2585**错误码:** 2586 2587以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 2588 2589| **错误码ID** | **错误信息** | 2590| ------------ | ------------------------------------------------------------ | 2591| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2592| 14800000 | Inner error. | 2593| 14800011 | Database corrupted. | 2594| 14800014 | Already closed. | 2595| 14800015 | The database does not respond. | 2596| 14800021 | SQLite: Generic error. | 2597| 14800022 | SQLite: Callback routine requested an abort. | 2598| 14800023 | SQLite: Access permission denied. | 2599| 14800024 | SQLite: The database file is locked. | 2600| 14800025 | SQLite: A table in the database is locked. | 2601| 14800026 | SQLite: The database is out of memory. | 2602| 14800027 | SQLite: Attempt to write a readonly database. | 2603| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2604| 14800029 | SQLite: The database is full. | 2605| 14800030 | SQLite: Unable to open the database file. | 2606| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2607| 14800032 | SQLite: Abort due to constraint violation. | 2608| 14800033 | SQLite: Data type mismatch. | 2609| 14800034 | SQLite: Library used incorrectly. | 2610| 14800047 | The WAL file size exceeds the default limit. | 2611 2612**示例:** 2613 2614```ts 2615import { sendableRelationalStore } from '@kit.ArkData'; 2616 2617const valuesBucket: relationalStore.ValuesBucket = { 2618 "NAME": 'hangman', 2619 "AGE": 18, 2620 "SALARY": 100.5, 2621 "CODES": new Uint8Array([1,2,3]), 2622}; 2623const sendableValuesBucket = sendableRelationalStore.toSendableValuesBucket(valuesBucket); 2624 2625if(store != undefined) { 2626 try { 2627 let rowId : number = (store as relationalStore.RdbStore).insertSync("EMPLOYEE", sendableValuesBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 2628 console.info(`Insert is successful, rowId = ${rowId}`); 2629 } catch (error) { 2630 console.error(`Insert is failed, code is ${error.code},message is ${error.message}`); 2631 } 2632} 2633``` 2634 2635### batchInsert 2636 2637batchInsert(table: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>):void 2638 2639向目标表中插入一组数据,使用callback异步回调。 2640 2641**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2642 2643**参数:** 2644 2645| 参数名 | 类型 | 必填 | 说明 | 2646| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ | 2647| table | string | 是 | 指定的目标表名。 | 2648| values | Array<[ValuesBucket](#valuesbucket)> | 是 | 表示要插入到表中的一组数据。 | 2649| callback | AsyncCallback<number> | 是 | 指定callback回调函数。如果操作成功,返回插入的数据个数,否则返回-1。 | 2650 2651**错误码:** 2652 2653以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 2654 2655| **错误码ID** | **错误信息** | 2656|-----------| ------------------------------------------------------------ | 2657| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2658| 14800000 | Inner error. | 2659| 14800011 | Database corrupted. | 2660| 14800014 | Already closed. | 2661| 14800015 | The database does not respond. | 2662| 14800021 | SQLite: Generic error. | 2663| 14800022 | SQLite: Callback routine requested an abort. | 2664| 14800023 | SQLite: Access permission denied. | 2665| 14800024 | SQLite: The database file is locked. | 2666| 14800025 | SQLite: A table in the database is locked. | 2667| 14800026 | SQLite: The database is out of memory. | 2668| 14800027 | SQLite: Attempt to write a readonly database. | 2669| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2670| 14800029 | SQLite: The database is full. | 2671| 14800030 | SQLite: Unable to open the database file. | 2672| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2673| 14800032 | SQLite: Abort due to constraint violation. | 2674| 14800033 | SQLite: Data type mismatch. | 2675| 14800034 | SQLite: Library used incorrectly. | 2676| 14800047 | The WAL file size exceeds the default limit. | 2677 2678**示例:** 2679 2680```ts 2681 2682let value1 = "Lisa"; 2683let value2 = 18; 2684let value3 = 100.5; 2685let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2686let value5 = "Jack"; 2687let value6 = 19; 2688let value7 = 101.5; 2689let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2690let value9 = "Tom"; 2691let value10 = 20; 2692let value11 = 102.5; 2693let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2694 2695const valueBucket1: relationalStore.ValuesBucket = { 2696 'NAME': value1, 2697 'AGE': value2, 2698 'SALARY': value3, 2699 'CODES': value4, 2700}; 2701const valueBucket2: relationalStore.ValuesBucket = { 2702 'NAME': value5, 2703 'AGE': value6, 2704 'SALARY': value7, 2705 'CODES': value8, 2706}; 2707const valueBucket3: relationalStore.ValuesBucket = { 2708 'NAME': value9, 2709 'AGE': value10, 2710 'SALARY': value11, 2711 'CODES': value12, 2712}; 2713 2714let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2715if(store != undefined) { 2716 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets, (err, insertNum) => { 2717 if (err) { 2718 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2719 return; 2720 } 2721 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2722 }) 2723} 2724``` 2725 2726### batchInsert 2727 2728batchInsert(table: string, values: Array<ValuesBucket>):Promise<number> 2729 2730向目标表中插入一组数据,使用Promise异步回调。 2731 2732**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2733 2734**参数:** 2735 2736| 参数名 | 类型 | 必填 | 说明 | 2737| ------ | ------------------------------------------ | ---- | ---------------------------- | 2738| table | string | 是 | 指定的目标表名。 | 2739| values | Array<[ValuesBucket](#valuesbucket)> | 是 | 表示要插入到表中的一组数据。 | 2740 2741**返回值**: 2742 2743| 类型 | 说明 | 2744| --------------------- | ----------------------------------------------------------- | 2745| Promise<number> | Promise对象。如果操作成功,返回插入的数据个数,否则返回-1。 | 2746 2747**错误码:** 2748 2749以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 2750 2751| **错误码ID** | **错误信息** | 2752|-----------| ------------------------------------------------------------ | 2753| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2754| 14800000 | Inner error. | 2755| 14800011 | Database corrupted. | 2756| 14800014 | Already closed. | 2757| 14800015 | The database does not respond. | 2758| 14800021 | SQLite: Generic error. | 2759| 14800022 | SQLite: Callback routine requested an abort. | 2760| 14800023 | SQLite: Access permission denied. | 2761| 14800024 | SQLite: The database file is locked. | 2762| 14800025 | SQLite: A table in the database is locked. | 2763| 14800026 | SQLite: The database is out of memory. | 2764| 14800027 | SQLite: Attempt to write a readonly database. | 2765| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2766| 14800029 | SQLite: The database is full. | 2767| 14800030 | SQLite: Unable to open the database file. | 2768| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2769| 14800032 | SQLite: Abort due to constraint violation. | 2770| 14800033 | SQLite: Data type mismatch. | 2771| 14800034 | SQLite: Library used incorrectly. | 2772| 14800047 | The WAL file size exceeds the default limit. | 2773 2774**示例:** 2775 2776```ts 2777import { BusinessError } from '@kit.BasicServicesKit'; 2778 2779let value1 = "Lisa"; 2780let value2 = 18; 2781let value3 = 100.5; 2782let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2783let value5 = "Jack"; 2784let value6 = 19; 2785let value7 = 101.5; 2786let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2787let value9 = "Tom"; 2788let value10 = 20; 2789let value11 = 102.5; 2790let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2791 2792const valueBucket1: relationalStore.ValuesBucket = { 2793 'NAME': value1, 2794 'AGE': value2, 2795 'SALARY': value3, 2796 'CODES': value4, 2797}; 2798const valueBucket2: relationalStore.ValuesBucket = { 2799 'NAME': value5, 2800 'AGE': value6, 2801 'SALARY': value7, 2802 'CODES': value8, 2803}; 2804const valueBucket3: relationalStore.ValuesBucket = { 2805 'NAME': value9, 2806 'AGE': value10, 2807 'SALARY': value11, 2808 'CODES': value12, 2809}; 2810 2811let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2812if(store != undefined) { 2813 (store as relationalStore.RdbStore).batchInsert("EMPLOYEE", valueBuckets).then((insertNum: number) => { 2814 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2815 }).catch((err: BusinessError) => { 2816 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2817 }) 2818} 2819``` 2820 2821### batchInsertSync<sup>12+</sup> 2822 2823batchInsertSync(table: string, values: Array<ValuesBucket>):number 2824 2825向目标表中插入一组数据。 2826 2827**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2828 2829**参数:** 2830 2831| 参数名 | 类型 | 必填 | 说明 | 2832| ------ | ------------------------------------------ | ---- | ---------------------------- | 2833| table | string | 是 | 指定的目标表名。 | 2834| values | Array<[ValuesBucket](#valuesbucket)> | 是 | 表示要插入到表中的一组数据。 | 2835 2836**返回值**: 2837 2838| 类型 | 说明 | 2839| ------ | ---------------------------------------------- | 2840| number | 如果操作成功,返回插入的数据个数,否则返回-1。 | 2841 2842**错误码:** 2843 2844以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 2845 2846| **错误码ID** | **错误信息** | 2847| ------------ | ------------------------------------------------------------ | 2848| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2849| 14800000 | Inner error. | 2850| 14800011 | Database corrupted. | 2851| 14800014 | Already closed. | 2852| 14800015 | The database does not respond. | 2853| 14800021 | SQLite: Generic error. | 2854| 14800022 | SQLite: Callback routine requested an abort. | 2855| 14800023 | SQLite: Access permission denied. | 2856| 14800024 | SQLite: The database file is locked. | 2857| 14800025 | SQLite: A table in the database is locked. | 2858| 14800026 | SQLite: The database is out of memory. | 2859| 14800027 | SQLite: Attempt to write a readonly database. | 2860| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2861| 14800029 | SQLite: The database is full. | 2862| 14800030 | SQLite: Unable to open the database file. | 2863| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2864| 14800032 | SQLite: Abort due to constraint violation. | 2865| 14800033 | SQLite: Data type mismatch. | 2866| 14800034 | SQLite: Library used incorrectly. | 2867| 14800047 | The WAL file size exceeds the default limit. | 2868 2869**示例:** 2870 2871```ts 2872import { BusinessError } from '@kit.BasicServicesKit'; 2873 2874let value1 = "Lisa"; 2875let value2 = 18; 2876let value3 = 100.5; 2877let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2878let value5 = "Jack"; 2879let value6 = 19; 2880let value7 = 101.5; 2881let value8 = new Uint8Array([6, 7, 8, 9, 10]); 2882let value9 = "Tom"; 2883let value10 = 20; 2884let value11 = 102.5; 2885let value12 = new Uint8Array([11, 12, 13, 14, 15]); 2886 2887const valueBucket1: relationalStore.ValuesBucket = { 2888 'NAME': value1, 2889 'AGE': value2, 2890 'SALARY': value3, 2891 'CODES': value4, 2892}; 2893const valueBucket2: relationalStore.ValuesBucket = { 2894 'NAME': value5, 2895 'AGE': value6, 2896 'SALARY': value7, 2897 'CODES': value8, 2898}; 2899const valueBucket3: relationalStore.ValuesBucket = { 2900 'NAME': value9, 2901 'AGE': value10, 2902 'SALARY': value11, 2903 'CODES': value12, 2904}; 2905 2906let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); 2907if(store != undefined) { 2908 try { 2909 let insertNum: number = (store as relationalStore.RdbStore).batchInsertSync("EMPLOYEE", valueBuckets); 2910 console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); 2911 } catch (err) { 2912 console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); 2913 } 2914} 2915``` 2916 2917### update 2918 2919update(values: ValuesBucket, predicates: RdbPredicates, callback: AsyncCallback<number>):void 2920 2921根据RdbPredicates的指定实例对象更新数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 2922 2923**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 2924 2925**参数:** 2926 2927| 参数名 | 类型 | 必填 | 说明 | 2928| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 2929| values | [ValuesBucket](#valuesbucket) | 是 | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 | 2930| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的更新条件。 | 2931| callback | AsyncCallback<number> | 是 | 指定的callback回调方法。返回受影响的行数。 | 2932 2933**错误码:** 2934 2935以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 2936 2937| **错误码ID** | **错误信息** | 2938|-----------| ------------------------------------------------------------ | 2939| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2940| 14800000 | Inner error. | 2941| 14800011 | Database corrupted. | 2942| 14800014 | Already closed. | 2943| 14800015 | The database does not respond. | 2944| 14800021 | SQLite: Generic error. | 2945| 14800022 | SQLite: Callback routine requested an abort. | 2946| 14800023 | SQLite: Access permission denied. | 2947| 14800024 | SQLite: The database file is locked. | 2948| 14800025 | SQLite: A table in the database is locked. | 2949| 14800026 | SQLite: The database is out of memory. | 2950| 14800027 | SQLite: Attempt to write a readonly database. | 2951| 14800028 | SQLite: Some kind of disk I/O error occurred. | 2952| 14800029 | SQLite: The database is full. | 2953| 14800030 | SQLite: Unable to open the database file. | 2954| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 2955| 14800032 | SQLite: Abort due to constraint violation. | 2956| 14800033 | SQLite: Data type mismatch. | 2957| 14800034 | SQLite: Library used incorrectly. | 2958| 14800047 | The WAL file size exceeds the default limit. | 2959 2960**示例:** 2961 2962```ts 2963 2964let value1 = "Rose"; 2965let value2 = 22; 2966let value3 = 200.5; 2967let value4 = new Uint8Array([1, 2, 3, 4, 5]); 2968 2969// 以下三种方式可用 2970const valueBucket1: relationalStore.ValuesBucket = { 2971 'NAME': value1, 2972 'AGE': value2, 2973 'SALARY': value3, 2974 'CODES': value4, 2975}; 2976const valueBucket2: relationalStore.ValuesBucket = { 2977 NAME: value1, 2978 AGE: value2, 2979 SALARY: value3, 2980 CODES: value4, 2981}; 2982const valueBucket3: relationalStore.ValuesBucket = { 2983 "NAME": value1, 2984 "AGE": value2, 2985 "SALARY": value3, 2986 "CODES": value4, 2987}; 2988 2989let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 2990predicates.equalTo("NAME", "Lisa"); 2991if(store != undefined) { 2992 (store as relationalStore.RdbStore).update(valueBucket1, predicates,(err, rows) => { 2993 if (err) { 2994 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 2995 return; 2996 } 2997 console.info(`Updated row count: ${rows}`); 2998 }) 2999} 3000``` 3001 3002### update<sup>10+</sup> 3003 3004update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution, callback: AsyncCallback<number>):void 3005 3006根据RdbPredicates的指定实例对象更新数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 3007 3008**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3009 3010**参数:** 3011 3012| 参数名 | 类型 | 必填 | 说明 | 3013| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3014| values | [ValuesBucket](#valuesbucket) | 是 | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 | 3015| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的更新条件。 | 3016| conflict | [ConflictResolution](#conflictresolution10) | 是 | 指定冲突解决模式。 | 3017| callback | AsyncCallback<number> | 是 | 指定的callback回调方法。返回受影响的行数。 | 3018 3019**错误码:** 3020 3021以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 3022 3023| **错误码ID** | **错误信息** | 3024|-----------| ------------------------------------------------------------ | 3025| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3026| 14800000 | Inner error. | 3027| 14800011 | Database corrupted. | 3028| 14800014 | Already closed. | 3029| 14800015 | The database does not respond. | 3030| 14800021 | SQLite: Generic error. | 3031| 14800022 | SQLite: Callback routine requested an abort. | 3032| 14800023 | SQLite: Access permission denied. | 3033| 14800024 | SQLite: The database file is locked. | 3034| 14800025 | SQLite: A table in the database is locked. | 3035| 14800026 | SQLite: The database is out of memory. | 3036| 14800027 | SQLite: Attempt to write a readonly database. | 3037| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3038| 14800029 | SQLite: The database is full. | 3039| 14800030 | SQLite: Unable to open the database file. | 3040| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3041| 14800032 | SQLite: Abort due to constraint violation. | 3042| 14800033 | SQLite: Data type mismatch. | 3043| 14800034 | SQLite: Library used incorrectly. | 3044| 14800047 | The WAL file size exceeds the default limit. | 3045 3046**示例:** 3047 3048```ts 3049 3050let value1 = "Rose"; 3051let value2 = 22; 3052let value3 = 200.5; 3053let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3054 3055// 以下三种方式可用 3056const valueBucket1: relationalStore.ValuesBucket = { 3057 'NAME': value1, 3058 'AGE': value2, 3059 'SALARY': value3, 3060 'CODES': value4, 3061}; 3062const valueBucket2: relationalStore.ValuesBucket = { 3063 NAME: value1, 3064 AGE: value2, 3065 SALARY: value3, 3066 CODES: value4, 3067}; 3068const valueBucket3: relationalStore.ValuesBucket = { 3069 "NAME": value1, 3070 "AGE": value2, 3071 "SALARY": value3, 3072 "CODES": value4, 3073}; 3074 3075let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3076predicates.equalTo("NAME", "Lisa"); 3077if(store != undefined) { 3078 (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, (err, rows) => { 3079 if (err) { 3080 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3081 return; 3082 } 3083 console.info(`Updated row count: ${rows}`); 3084 }) 3085} 3086``` 3087 3088### update 3089 3090update(values: ValuesBucket, predicates: RdbPredicates):Promise<number> 3091 3092根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 3093 3094**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3095 3096**参数:** 3097 3098| 参数名 | 类型 | 必填 | 说明 | 3099| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 3100| values | [ValuesBucket](#valuesbucket) | 是 | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 | 3101| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的更新条件。 | 3102 3103**返回值**: 3104 3105| 类型 | 说明 | 3106| --------------------- | ----------------------------------------- | 3107| Promise<number> | 指定的Promise回调方法。返回受影响的行数。 | 3108 3109**错误码:** 3110 3111以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 3112 3113| **错误码ID** | **错误信息** | 3114|-----------| ------------------------------------------------------------ | 3115| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3116| 14800000 | Inner error. | 3117| 14800011 | Database corrupted. | 3118| 14800014 | Already closed. | 3119| 14800015 | The database does not respond. | 3120| 14800021 | SQLite: Generic error. | 3121| 14800022 | SQLite: Callback routine requested an abort. | 3122| 14800023 | SQLite: Access permission denied. | 3123| 14800024 | SQLite: The database file is locked. | 3124| 14800025 | SQLite: A table in the database is locked. | 3125| 14800026 | SQLite: The database is out of memory. | 3126| 14800027 | SQLite: Attempt to write a readonly database. | 3127| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3128| 14800029 | SQLite: The database is full. | 3129| 14800030 | SQLite: Unable to open the database file. | 3130| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3131| 14800032 | SQLite: Abort due to constraint violation. | 3132| 14800033 | SQLite: Data type mismatch. | 3133| 14800034 | SQLite: Library used incorrectly. | 3134| 14800047 | The WAL file size exceeds the default limit. | 3135 3136**示例:** 3137 3138```ts 3139import { BusinessError } from '@kit.BasicServicesKit'; 3140 3141let value1 = "Rose"; 3142let value2 = 22; 3143let value3 = 200.5; 3144let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3145 3146// 以下三种方式可用 3147const valueBucket1: relationalStore.ValuesBucket = { 3148 'NAME': value1, 3149 'AGE': value2, 3150 'SALARY': value3, 3151 'CODES': value4, 3152}; 3153const valueBucket2: relationalStore.ValuesBucket = { 3154 NAME: value1, 3155 AGE: value2, 3156 SALARY: value3, 3157 CODES: value4, 3158}; 3159const valueBucket3: relationalStore.ValuesBucket = { 3160 "NAME": value1, 3161 "AGE": value2, 3162 "SALARY": value3, 3163 "CODES": value4, 3164}; 3165 3166let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3167predicates.equalTo("NAME", "Lisa"); 3168if(store != undefined) { 3169 (store as relationalStore.RdbStore).update(valueBucket1, predicates).then(async (rows: Number) => { 3170 console.info(`Updated row count: ${rows}`); 3171 }).catch((err: BusinessError) => { 3172 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3173 }) 3174} 3175``` 3176 3177### update<sup>10+</sup> 3178 3179update(values: ValuesBucket, predicates: RdbPredicates, conflict: ConflictResolution):Promise<number> 3180 3181根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 3182 3183**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3184 3185**参数:** 3186 3187| 参数名 | 类型 | 必填 | 说明 | 3188| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3189| values | [ValuesBucket](#valuesbucket) | 是 | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 | 3190| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的更新条件。 | 3191| conflict | [ConflictResolution](#conflictresolution10) | 是 | 指定冲突解决模式。 | 3192 3193**返回值**: 3194 3195| 类型 | 说明 | 3196| --------------------- | ----------------------------------------- | 3197| Promise<number> | 指定的Promise回调方法。返回受影响的行数。 | 3198 3199**错误码:** 3200 3201以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 3202 3203| **错误码ID** | **错误信息** | 3204|-----------| ------------------------------------------------------------ | 3205| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3206| 14800000 | Inner error. | 3207| 14800011 | Database corrupted. | 3208| 14800014 | Already closed. | 3209| 14800015 | The database does not respond. | 3210| 14800021 | SQLite: Generic error. | 3211| 14800022 | SQLite: Callback routine requested an abort. | 3212| 14800023 | SQLite: Access permission denied. | 3213| 14800024 | SQLite: The database file is locked. | 3214| 14800025 | SQLite: A table in the database is locked. | 3215| 14800026 | SQLite: The database is out of memory. | 3216| 14800027 | SQLite: Attempt to write a readonly database. | 3217| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3218| 14800029 | SQLite: The database is full. | 3219| 14800030 | SQLite: Unable to open the database file. | 3220| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3221| 14800032 | SQLite: Abort due to constraint violation. | 3222| 14800033 | SQLite: Data type mismatch. | 3223| 14800034 | SQLite: Library used incorrectly. | 3224| 14800047 | The WAL file size exceeds the default limit. | 3225 3226**示例:** 3227 3228```ts 3229import { BusinessError } from '@kit.BasicServicesKit'; 3230 3231let value1 = "Rose"; 3232let value2 = 22; 3233let value3 = 200.5; 3234let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3235 3236// 以下三种方式可用 3237const valueBucket1: relationalStore.ValuesBucket = { 3238 'NAME': value1, 3239 'AGE': value2, 3240 'SALARY': value3, 3241 'CODES': value4, 3242}; 3243const valueBucket2: relationalStore.ValuesBucket = { 3244 NAME: value1, 3245 AGE: value2, 3246 SALARY: value3, 3247 CODES: value4, 3248}; 3249const valueBucket3: relationalStore.ValuesBucket = { 3250 "NAME": value1, 3251 "AGE": value2, 3252 "SALARY": value3, 3253 "CODES": value4, 3254}; 3255 3256let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3257predicates.equalTo("NAME", "Lisa"); 3258if(store != undefined) { 3259 (store as relationalStore.RdbStore).update(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE).then(async (rows: Number) => { 3260 console.info(`Updated row count: ${rows}`); 3261 }).catch((err: BusinessError) => { 3262 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 3263 }) 3264} 3265``` 3266 3267### updateSync<sup>12+</sup> 3268 3269updateSync(values: ValuesBucket, predicates: RdbPredicates, conflict?: ConflictResolution):number 3270 3271根据RdbPredicates的指定实例对象更新数据库中的数据。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 3272 3273**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3274 3275**参数:** 3276 3277| 参数名 | 类型 | 必填 | 说明 | 3278| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 3279| values | [ValuesBucket](#valuesbucket) | 是 | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 | 3280| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的更新条件。 | 3281| conflict | [ConflictResolution](#conflictresolution10) | 否 | 指定冲突解决模式。默认值是relationalStore.ConflictResolution.ON_CONFLICT_NONE。 | 3282 3283**返回值**: 3284 3285| 类型 | 说明 | 3286| ------ | ------------------ | 3287| number | 返回受影响的行数。 | 3288 3289**错误码:** 3290 3291以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 3292 3293| **错误码ID** | **错误信息** | 3294| ------------ | ------------------------------------------------------------ | 3295| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3296| 14800000 | Inner error. | 3297| 14800011 | Database corrupted. | 3298| 14800014 | Already closed. | 3299| 14800015 | The database does not respond. | 3300| 14800021 | SQLite: Generic error. | 3301| 14800022 | SQLite: Callback routine requested an abort. | 3302| 14800023 | SQLite: Access permission denied. | 3303| 14800024 | SQLite: The database file is locked. | 3304| 14800025 | SQLite: A table in the database is locked. | 3305| 14800026 | SQLite: The database is out of memory. | 3306| 14800027 | SQLite: Attempt to write a readonly database. | 3307| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3308| 14800029 | SQLite: The database is full. | 3309| 14800030 | SQLite: Unable to open the database file. | 3310| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3311| 14800032 | SQLite: Abort due to constraint violation. | 3312| 14800033 | SQLite: Data type mismatch. | 3313| 14800034 | SQLite: Library used incorrectly. | 3314| 14800047 | The WAL file size exceeds the default limit. | 3315 3316**示例:** 3317 3318```ts 3319import { BusinessError } from '@kit.BasicServicesKit'; 3320 3321let value1 = "Rose"; 3322let value2 = 22; 3323let value3 = 200.5; 3324let value4 = new Uint8Array([1, 2, 3, 4, 5]); 3325 3326// 以下三种方式可用 3327const valueBucket1: relationalStore.ValuesBucket = { 3328 'NAME': value1, 3329 'AGE': value2, 3330 'SALARY': value3, 3331 'CODES': value4, 3332}; 3333const valueBucket2: relationalStore.ValuesBucket = { 3334 NAME: value1, 3335 AGE: value2, 3336 SALARY: value3, 3337 CODES: value4, 3338}; 3339const valueBucket3: relationalStore.ValuesBucket = { 3340 "NAME": value1, 3341 "AGE": value2, 3342 "SALARY": value3, 3343 "CODES": value4, 3344}; 3345 3346let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3347predicates.equalTo("NAME", "Lisa"); 3348if(store != undefined) { 3349 try { 3350 let rows: Number = (store as relationalStore.RdbStore).updateSync(valueBucket1, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); 3351 console.info(`Updated row count: ${rows}`); 3352 } catch (error) { 3353 console.error(`Updated failed, code is ${error.code},message is ${error.message}`); 3354 } 3355} 3356``` 3357 3358### delete 3359 3360delete(predicates: RdbPredicates, callback: AsyncCallback<number>):void 3361 3362根据RdbPredicates的指定实例对象从数据库中删除数据,使用callback异步回调。 3363 3364**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3365 3366**参数:** 3367 3368| 参数名 | 类型 | 必填 | 说明 | 3369| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 3370| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的删除条件。 | 3371| callback | AsyncCallback<number> | 是 | 指定callback回调函数。返回受影响的行数。 | 3372 3373**错误码:** 3374 3375以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 3376 3377| **错误码ID** | **错误信息** | 3378|-----------| ------------------------------------------------------------ | 3379| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3380| 14800000 | Inner error. | 3381| 14800011 | Database corrupted. | 3382| 14800014 | Already closed. | 3383| 14800015 | The database does not respond. | 3384| 14800021 | SQLite: Generic error. | 3385| 14800022 | SQLite: Callback routine requested an abort. | 3386| 14800023 | SQLite: Access permission denied. | 3387| 14800024 | SQLite: The database file is locked. | 3388| 14800025 | SQLite: A table in the database is locked. | 3389| 14800026 | SQLite: The database is out of memory. | 3390| 14800027 | SQLite: Attempt to write a readonly database. | 3391| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3392| 14800029 | SQLite: The database is full. | 3393| 14800030 | SQLite: Unable to open the database file. | 3394| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3395| 14800032 | SQLite: Abort due to constraint violation. | 3396| 14800033 | SQLite: Data type mismatch. | 3397| 14800034 | SQLite: Library used incorrectly. | 3398| 14800047 | The WAL file size exceeds the default limit. | 3399 3400**示例:** 3401 3402```ts 3403let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3404predicates.equalTo("NAME", "Lisa"); 3405if(store != undefined) { 3406 (store as relationalStore.RdbStore).delete(predicates, (err, rows) => { 3407 if (err) { 3408 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3409 return; 3410 } 3411 console.info(`Delete rows: ${rows}`); 3412 }) 3413} 3414``` 3415 3416### delete 3417 3418delete(predicates: RdbPredicates):Promise<number> 3419 3420根据RdbPredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。 3421 3422**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3423 3424**参数:** 3425 3426| 参数名 | 类型 | 必填 | 说明 | 3427| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 3428| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的删除条件。 | 3429 3430**返回值**: 3431 3432| 类型 | 说明 | 3433| --------------------- | ------------------------------- | 3434| Promise<number> | Promise对象。返回受影响的行数。 | 3435 3436**错误码:** 3437 3438以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 3439 3440| **错误码ID** | **错误信息** | 3441|-----------| ------------------------------------------------------------ | 3442| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3443| 14800000 | Inner error. | 3444| 14800011 | Database corrupted. | 3445| 14800014 | Already closed. | 3446| 14800015 | The database does not respond. | 3447| 14800021 | SQLite: Generic error. | 3448| 14800022 | SQLite: Callback routine requested an abort. | 3449| 14800023 | SQLite: Access permission denied. | 3450| 14800024 | SQLite: The database file is locked. | 3451| 14800025 | SQLite: A table in the database is locked. | 3452| 14800026 | SQLite: The database is out of memory. | 3453| 14800027 | SQLite: Attempt to write a readonly database. | 3454| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3455| 14800029 | SQLite: The database is full. | 3456| 14800030 | SQLite: Unable to open the database file. | 3457| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3458| 14800032 | SQLite: Abort due to constraint violation. | 3459| 14800033 | SQLite: Data type mismatch. | 3460| 14800034 | SQLite: Library used incorrectly. | 3461| 14800047 | The WAL file size exceeds the default limit. | 3462 3463**示例:** 3464 3465```ts 3466import { BusinessError } from '@kit.BasicServicesKit'; 3467 3468let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3469predicates.equalTo("NAME", "Lisa"); 3470if(store != undefined) { 3471 (store as relationalStore.RdbStore).delete(predicates).then((rows: Number) => { 3472 console.info(`Delete rows: ${rows}`); 3473 }).catch((err: BusinessError) => { 3474 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3475 }) 3476} 3477``` 3478 3479### deleteSync<sup>12+</sup> 3480 3481deleteSync(predicates: RdbPredicates):number 3482 3483根据RdbPredicates的指定实例对象从数据库中删除数据。 3484 3485**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3486 3487**参数:** 3488 3489| 参数名 | 类型 | 必填 | 说明 | 3490| ---------- | ------------------------------- | ---- | --------------------------------------- | 3491| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的删除条件。 | 3492 3493**返回值**: 3494 3495| 类型 | 说明 | 3496| ------ | ------------------ | 3497| number | 返回受影响的行数。 | 3498 3499**错误码:** 3500 3501以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 3502 3503| **错误码ID** | **错误信息** | 3504| ------------ | ------------------------------------------------------------ | 3505| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3506| 14800000 | Inner error. | 3507| 14800011 | Database corrupted. | 3508| 14800014 | Already closed. | 3509| 14800015 | The database does not respond. | 3510| 14800021 | SQLite: Generic error. | 3511| 14800022 | SQLite: Callback routine requested an abort. | 3512| 14800023 | SQLite: Access permission denied. | 3513| 14800024 | SQLite: The database file is locked. | 3514| 14800025 | SQLite: A table in the database is locked. | 3515| 14800026 | SQLite: The database is out of memory. | 3516| 14800027 | SQLite: Attempt to write a readonly database. | 3517| 14800028 | SQLite: Some kind of disk I/O error occurred. | 3518| 14800029 | SQLite: The database is full. | 3519| 14800030 | SQLite: Unable to open the database file. | 3520| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 3521| 14800032 | SQLite: Abort due to constraint violation. | 3522| 14800033 | SQLite: Data type mismatch. | 3523| 14800034 | SQLite: Library used incorrectly. | 3524| 14800047 | The WAL file size exceeds the default limit. | 3525 3526**示例:** 3527 3528```ts 3529import { BusinessError } from '@kit.BasicServicesKit'; 3530 3531let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3532predicates.equalTo("NAME", "Lisa"); 3533if(store != undefined) { 3534 try { 3535 let rows: Number = (store as relationalStore.RdbStore).deleteSync(predicates) 3536 console.info(`Delete rows: ${rows}`); 3537 } catch (err) { 3538 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 3539 } 3540} 3541``` 3542 3543### query<sup>10+</sup> 3544 3545query(predicates: RdbPredicates, callback: AsyncCallback<ResultSet>):void 3546 3547根据指定条件查询数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 3548 3549**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3550 3551**参数:** 3552 3553| 参数名 | 类型 | 必填 | 说明 | 3554| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 3555| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的查询条件。 | 3556| callback | AsyncCallback<[ResultSet](#resultset)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 | 3557 3558**错误码:** 3559 3560以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 3561 3562| **错误码ID** | **错误信息** | 3563|-----------| ------------------------------------------------------------ | 3564| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3565| 14800000 | Inner error. | 3566| 14800014 | Already closed. | 3567| 14800015 | The database does not respond. | 3568 3569**示例:** 3570 3571```ts 3572let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3573predicates.equalTo("NAME", "Rose"); 3574if(store != undefined) { 3575 (store as relationalStore.RdbStore).query(predicates, (err, resultSet) => { 3576 if (err) { 3577 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3578 return; 3579 } 3580 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3581 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 3582 while (resultSet.goToNextRow()) { 3583 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3584 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3585 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3586 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3587 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3588 } 3589 // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露 3590 resultSet.close(); 3591 }) 3592} 3593``` 3594 3595### query 3596 3597query(predicates: RdbPredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>):void 3598 3599根据指定条件查询数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 3600 3601**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3602 3603**参数:** 3604 3605| 参数名 | 类型 | 必填 | 说明 | 3606| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 3607| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的查询条件。 | 3608| columns | Array<string> | 是 | 表示要查询的列。如果值为空,则查询应用于所有列。 | 3609| callback | AsyncCallback<[ResultSet](#resultset)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 | 3610 3611**错误码:** 3612 3613以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 3614 3615| **错误码ID** | **错误信息** | 3616|-----------| ------------------------------------------------------------ | 3617| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3618| 14800000 | Inner error. | 3619| 14800014 | Already closed. | 3620| 14800015 | The database does not respond. | 3621 3622**示例:** 3623 3624```ts 3625let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3626predicates.equalTo("NAME", "Rose"); 3627if(store != undefined) { 3628 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], (err, resultSet) => { 3629 if (err) { 3630 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3631 return; 3632 } 3633 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3634 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 3635 while (resultSet.goToNextRow()) { 3636 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3637 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3638 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3639 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3640 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3641 } 3642 // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露 3643 resultSet.close(); 3644 }) 3645} 3646``` 3647 3648### query 3649 3650query(predicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> 3651 3652根据指定条件查询数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 3653 3654**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3655 3656**参数:** 3657 3658| 参数名 | 类型 | 必填 | 说明 | 3659| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 3660| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的查询条件。 | 3661| columns | Array<string> | 否 | 表示要查询的列。如果值为空,则查询应用于所有列。 | 3662 3663**错误码:** 3664 3665以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 3666 3667| **错误码ID** | **错误信息** | 3668|-----------| ------------------------------------------------------------ | 3669| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3670| 14800000 | Inner error. | 3671| 14800014 | Already closed. | 3672| 14800015 | The database does not respond. | 3673 3674**返回值**: 3675 3676| 类型 | 说明 | 3677| ------------------------------------------------------- | -------------------------------------------------- | 3678| Promise<[ResultSet](#resultset)> | Promise对象。如果操作成功,则返回ResultSet对象。 | 3679 3680**示例:** 3681 3682```ts 3683import { BusinessError } from '@kit.BasicServicesKit'; 3684 3685let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3686predicates.equalTo("NAME", "Rose"); 3687if(store != undefined) { 3688 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 3689 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3690 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 3691 while (resultSet.goToNextRow()) { 3692 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3693 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3694 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3695 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3696 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3697 } 3698 // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露 3699 resultSet.close(); 3700 }).catch((err: BusinessError) => { 3701 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3702 }) 3703} 3704``` 3705 3706### querySync<sup>12+</sup> 3707 3708querySync(predicates: RdbPredicates, columns?: Array<string>):ResultSet 3709 3710根据指定条件查询数据库中的数据。 3711 3712**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3713 3714**参数:** 3715 3716| 参数名 | 类型 | 必填 | 说明 | 3717| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ | 3718| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的查询条件。 | 3719| columns | Array<string> | 否 | 表示要查询的列。如果值为空,则查询应用于所有列。默认值为空。 | 3720 3721**错误码:** 3722 3723以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 3724 3725| **错误码ID** | **错误信息** | 3726| ------------ | ------------------------------------------------------------ | 3727| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3728| 14800000 | Inner error. | 3729| 14800014 | Already closed. | 3730| 14800015 | The database does not respond. | 3731 3732**返回值**: 3733 3734| 类型 | 说明 | 3735| ----------------------- | ----------------------------------- | 3736| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 | 3737 3738**示例:** 3739 3740```ts 3741import { BusinessError } from '@kit.BasicServicesKit'; 3742 3743let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 3744predicates.equalTo("NAME", "Rose"); 3745if(store != undefined) { 3746 try { 3747 let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySync(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); 3748 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3749 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 3750 while (resultSet.goToNextRow()) { 3751 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3752 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3753 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3754 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3755 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3756 } 3757 // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露 3758 resultSet.close(); 3759 } catch (err) { 3760 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3761 } 3762} 3763``` 3764 3765### remoteQuery 3766 3767remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string> , callback: AsyncCallback<ResultSet>): void 3768 3769根据指定条件查询远程设备数据库中的数据。使用callback异步回调。 3770 3771> **说明:** 3772> 3773> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。 3774 3775**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3776 3777**参数:** 3778 3779| 参数名 | 类型 | 必填 | 说明 | 3780| ---------- | -------------------------------------------- | ---- | --------------------------------------------------------- | 3781| device | string | 是 | 指定的远程设备ID。 | 3782| table | string | 是 | 指定的目标表名。 | 3783| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象,指定查询的条件。 | 3784| columns | Array<string> | 是 | 表示要查询的列。如果值为空,则查询应用于所有列。 | 3785| callback | AsyncCallback<[ResultSet](#resultset)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 | 3786 3787**错误码:** 3788 3789以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 3790 3791| **错误码ID** | **错误信息** | 3792|-----------| ------------------------------------------------------------ | 3793| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3794| 801 | Capability not supported. | 3795| 14800000 | Inner error. | 3796| 14800014 | Already closed. | 3797 3798**示例:** 3799 3800```ts 3801import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 3802import { BusinessError } from '@kit.BasicServicesKit'; 3803 3804let dmInstance: distributedDeviceManager.DeviceManager; 3805let deviceId: string | undefined = undefined; 3806 3807try { 3808 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 3809 let devices = dmInstance.getAvailableDeviceListSync(); 3810 if(deviceId != undefined) { 3811 deviceId = devices[0].networkId; 3812 } 3813} catch (err) { 3814 let code = (err as BusinessError).code; 3815 let message = (err as BusinessError).message; 3816 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 3817} 3818 3819let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 3820predicates.greaterThan("id", 0); 3821if(store != undefined && deviceId != undefined) { 3822 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 3823 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3824 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 3825 while (resultSet.goToNextRow()) { 3826 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3827 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3828 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3829 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3830 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3831 } 3832 // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露 3833 resultSet.close(); 3834 }).catch((err: BusinessError) => { 3835 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 3836 }) 3837} 3838``` 3839 3840### remoteQuery 3841 3842remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: Array<string>): Promise<ResultSet> 3843 3844根据指定条件查询远程设备数据库中的数据。使用Promise异步回调。 3845 3846> **说明:** 3847> 3848> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。 3849 3850**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3851 3852**参数:** 3853 3854| 参数名 | 类型 | 必填 | 说明 | 3855| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 3856| device | string | 是 | 指定的远程设备ID。 | 3857| table | string | 是 | 指定的目标表名。 | 3858| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象,指定查询的条件。 | 3859| columns | Array<string> | 是 | 表示要查询的列。如果值为空,则查询应用于所有列。 | 3860 3861**返回值**: 3862 3863| 类型 | 说明 | 3864| ------------------------------------------------------------ | -------------------------------------------------- | 3865| Promise<[ResultSet](#resultset)> | Promise对象。如果操作成功,则返回ResultSet对象。 | 3866 3867**错误码:** 3868 3869以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 3870 3871| **错误码ID** | **错误信息** | 3872|-----------| ------------------------------------------------------------ | 3873| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3874| 801 | Capability not supported. | 3875| 14800000 | Inner error. | 3876| 14800014 | Already closed. | 3877 3878**示例:** 3879 3880```ts 3881import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 3882import { BusinessError } from '@kit.BasicServicesKit'; 3883 3884let dmInstance: distributedDeviceManager.DeviceManager; 3885let deviceId: string | undefined = undefined; 3886 3887try { 3888 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 3889 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 3890 if(devices != undefined) { 3891 deviceId = devices[0].networkId; 3892 } 3893} catch (err) { 3894 let code = (err as BusinessError).code; 3895 let message = (err as BusinessError).message; 3896 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 3897} 3898 3899let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 3900predicates.greaterThan("id", 0); 3901if(store != undefined && deviceId != undefined) { 3902 (store as relationalStore.RdbStore).remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 3903 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3904 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 3905 while (resultSet.goToNextRow()) { 3906 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3907 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3908 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3909 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3910 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3911 } 3912 // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露 3913 resultSet.close(); 3914 }).catch((err: BusinessError) => { 3915 console.error(`Failed to remoteQuery, code is ${err.code},message is ${err.message}`); 3916 }) 3917} 3918``` 3919 3920### querySql<sup>10+</sup> 3921 3922querySql(sql: string, callback: AsyncCallback<ResultSet>):void 3923 3924根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。 3925 3926**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3927 3928**参数:** 3929 3930| 参数名 | 类型 | 必填 | 说明 | 3931| -------- | -------------------------------------------- | ---- |---------------------------------------| 3932| sql | string | 是 | 指定要执行的SQL语句。 | 3933| callback | AsyncCallback<[ResultSet](#resultset)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 | 3934 3935**错误码:** 3936 3937以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 3938 3939| **错误码ID** | **错误信息** | 3940|-----------| ------------------------------------------------------------ | 3941| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3942| 14800000 | Inner error. | 3943| 14800014 | Already closed. | 3944| 14800015 | The database does not respond. | 3945 3946**示例:** 3947 3948```ts 3949if(store != undefined) { 3950 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'", (err, resultSet) => { 3951 if (err) { 3952 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 3953 return; 3954 } 3955 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 3956 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 3957 while (resultSet.goToNextRow()) { 3958 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 3959 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 3960 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 3961 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 3962 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 3963 } 3964 // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露 3965 resultSet.close(); 3966 }) 3967} 3968``` 3969 3970### querySql 3971 3972querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void 3973 3974根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。 3975 3976**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 3977 3978**参数:** 3979 3980| 参数名 | 类型 | 必填 | 说明 | 3981| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | 3982| sql | string | 是 | 指定要执行的SQL语句。 | 3983| bindArgs | Array<[ValueType](#valuetype)> | 是 | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数需为空数组。 | 3984| callback | AsyncCallback<[ResultSet](#resultset)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 | 3985 3986**错误码:** 3987 3988以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 3989 3990| **错误码ID** | **错误信息** | 3991|-----------| ------------------------------------------------------------ | 3992| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3993| 14800000 | Inner error. | 3994| 14800014 | Already closed. | 3995| 14800015 | The database does not respond. | 3996 3997**示例:** 3998 3999```ts 4000if(store != undefined) { 4001 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], (err, resultSet) => { 4002 if (err) { 4003 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4004 return; 4005 } 4006 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4007 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 4008 while (resultSet.goToNextRow()) { 4009 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4010 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4011 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4012 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4013 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4014 } 4015 // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露 4016 resultSet.close(); 4017 }) 4018} 4019``` 4020 4021### querySql 4022 4023querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> 4024 4025根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。 4026 4027**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4028 4029**参数:** 4030 4031| 参数名 | 类型 | 必填 | 说明 | 4032| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4033| sql | string | 是 | 指定要执行的SQL语句。 | 4034| bindArgs | Array<[ValueType](#valuetype)> | 否 | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 | 4035 4036**返回值**: 4037 4038| 类型 | 说明 | 4039| ------------------------------------------------------- | -------------------------------------------------- | 4040| Promise<[ResultSet](#resultset)> | Promise对象。如果操作成功,则返回ResultSet对象。 | 4041 4042**错误码:** 4043 4044以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 4045 4046| **错误码ID** | **错误信息** | 4047|-----------| ------------------------------------------------------------ | 4048| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4049| 14800000 | Inner error. | 4050| 14800014 | Already closed. | 4051| 14800015 | The database does not respond. | 4052 4053**示例:** 4054 4055```ts 4056import { BusinessError } from '@kit.BasicServicesKit'; 4057 4058if(store != undefined) { 4059 (store as relationalStore.RdbStore).querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'").then((resultSet: relationalStore.ResultSet) => { 4060 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4061 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 4062 while (resultSet.goToNextRow()) { 4063 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4064 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4065 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4066 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4067 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4068 } 4069 // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露 4070 resultSet.close(); 4071 }).catch((err: BusinessError) => { 4072 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4073 }) 4074} 4075``` 4076 4077### querySqlSync<sup>12+</sup> 4078 4079querySqlSync(sql: string, bindArgs?: Array<ValueType>):ResultSet 4080 4081根据指定SQL语句查询数据库中的数据,语句中的各种表达式和操作符之间的关系操作符号不超过1000个。 4082 4083**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4084 4085**参数:** 4086 4087| 参数名 | 类型 | 必填 | 说明 | 4088| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4089| sql | string | 是 | 指定要执行的SQL语句。 | 4090| bindArgs | Array<[ValueType](#valuetype)> | 否 | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。默认值为空。 | 4091 4092**返回值**: 4093 4094| 类型 | 说明 | 4095| ----------------------- | ----------------------------------- | 4096| [ResultSet](#resultset) | 如果操作成功,则返回ResultSet对象。 | 4097 4098**错误码:** 4099 4100以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 4101 4102| **错误码ID** | **错误信息** | 4103| ------------ | ------------------------------------------------------------ | 4104| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4105| 14800000 | Inner error. | 4106| 14800014 | Already closed. | 4107| 14800015 | The database does not respond. | 4108 4109**示例:** 4110 4111```ts 4112import { BusinessError } from '@kit.BasicServicesKit'; 4113 4114if(store != undefined) { 4115 try { 4116 let resultSet: relationalStore.ResultSet = (store as relationalStore.RdbStore).querySqlSync("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'"); 4117 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 4118 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 4119 while (resultSet.goToNextRow()) { 4120 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 4121 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 4122 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 4123 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 4124 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 4125 } 4126 // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露 4127 resultSet.close(); 4128 } catch (err) { 4129 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 4130 } 4131} 4132``` 4133 4134### executeSql<sup>10+</sup> 4135 4136executeSql(sql: string, callback: AsyncCallback<void>):void 4137 4138执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。 4139 4140此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。 4141 4142不支持分号分隔的多条语句。 4143 4144**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4145 4146**参数:** 4147 4148| 参数名 | 类型 | 必填 | 说明 | 4149| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4150| sql | string | 是 | 指定要执行的SQL语句。 | 4151| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | 4152 4153**错误码:** 4154 4155以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4156 4157| **错误码ID** | **错误信息** | 4158|-----------| ------------------------------------------------------------ | 4159| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4160| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4161| 14800000 | Inner error. | 4162| 14800011 | Database corrupted. | 4163| 14800014 | Already closed. | 4164| 14800015 | The database does not respond. | 4165| 14800021 | SQLite: Generic error. | 4166| 14800022 | SQLite: Callback routine requested an abort. | 4167| 14800023 | SQLite: Access permission denied. | 4168| 14800024 | SQLite: The database file is locked. | 4169| 14800025 | SQLite: A table in the database is locked. | 4170| 14800026 | SQLite: The database is out of memory. | 4171| 14800027 | SQLite: Attempt to write a readonly database. | 4172| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4173| 14800029 | SQLite: The database is full. | 4174| 14800030 | SQLite: Unable to open the database file. | 4175| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4176| 14800032 | SQLite: Abort due to constraint violation. | 4177| 14800033 | SQLite: Data type mismatch. | 4178| 14800034 | SQLite: Library used incorrectly. | 4179| 14800047 | The WAL file size exceeds the default limit. | 4180 4181**示例:** 4182 4183```ts 4184const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" 4185if(store != undefined) { 4186 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, (err) => { 4187 if (err) { 4188 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4189 return; 4190 } 4191 console.info('Delete table done.'); 4192 }) 4193} 4194``` 4195 4196### executeSql 4197 4198executeSql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<void>):void 4199 4200执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用callback异步回调。 4201 4202此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。 4203 4204不支持分号分隔的多条语句。 4205 4206**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4207 4208**参数:** 4209 4210| 参数名 | 类型 | 必填 | 说明 | 4211| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4212| sql | string | 是 | 指定要执行的SQL语句。 | 4213| bindArgs | Array<[ValueType](#valuetype)> | 是 | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数需为空数组。 | 4214| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | 4215 4216**错误码:** 4217 4218以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4219 4220| **错误码ID** | **错误信息** | 4221|-----------| ------------------------------------------------------------ | 4222| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4223| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4224| 14800000 | Inner error. | 4225| 14800011 | Database corrupted. | 4226| 14800014 | Already closed. | 4227| 14800015 | The database does not respond. | 4228| 14800021 | SQLite: Generic error. | 4229| 14800022 | SQLite: Callback routine requested an abort. | 4230| 14800023 | SQLite: Access permission denied. | 4231| 14800024 | SQLite: The database file is locked. | 4232| 14800025 | SQLite: A table in the database is locked. | 4233| 14800026 | SQLite: The database is out of memory. | 4234| 14800027 | SQLite: Attempt to write a readonly database. | 4235| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4236| 14800029 | SQLite: The database is full. | 4237| 14800030 | SQLite: Unable to open the database file. | 4238| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4239| 14800032 | SQLite: Abort due to constraint violation. | 4240| 14800033 | SQLite: Data type mismatch. | 4241| 14800034 | SQLite: Library used incorrectly. | 4242| 14800047 | The WAL file size exceeds the default limit. | 4243 4244**示例:** 4245 4246```ts 4247const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?" 4248if(store != undefined) { 4249 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE, ['zhangsan'], (err) => { 4250 if (err) { 4251 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4252 return; 4253 } 4254 console.info('Delete table done.'); 4255 }) 4256} 4257``` 4258 4259### executeSql 4260 4261executeSql(sql: string, bindArgs?: Array<ValueType>):Promise<void> 4262 4263执行包含指定参数但不返回值的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。 4264 4265此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。 4266 4267不支持分号分隔的多条语句。 4268 4269**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4270 4271**参数:** 4272 4273| 参数名 | 类型 | 必填 | 说明 | 4274| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4275| sql | string | 是 | 指定要执行的SQL语句。 | 4276| bindArgs | Array<[ValueType](#valuetype)> | 否 | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 | 4277 4278**返回值**: 4279 4280| 类型 | 说明 | 4281| ------------------- | ------------------------- | 4282| Promise<void> | 无返回结果的Promise对象。 | 4283 4284**错误码:** 4285 4286以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4287 4288| **错误码ID** | **错误信息** | 4289|-----------| ------------------------------------------------------------ | 4290| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4291| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4292| 14800000 | Inner error. | 4293| 14800011 | Database corrupted. | 4294| 14800014 | Already closed. | 4295| 14800015 | The database does not respond. | 4296| 14800021 | SQLite: Generic error. | 4297| 14800022 | SQLite: Callback routine requested an abort. | 4298| 14800023 | SQLite: Access permission denied. | 4299| 14800024 | SQLite: The database file is locked. | 4300| 14800025 | SQLite: A table in the database is locked. | 4301| 14800026 | SQLite: The database is out of memory. | 4302| 14800027 | SQLite: Attempt to write a readonly database. | 4303| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4304| 14800029 | SQLite: The database is full. | 4305| 14800030 | SQLite: Unable to open the database file. | 4306| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4307| 14800032 | SQLite: Abort due to constraint violation. | 4308| 14800033 | SQLite: Data type mismatch. | 4309| 14800034 | SQLite: Library used incorrectly. | 4310| 14800047 | The WAL file size exceeds the default limit. | 4311 4312**示例:** 4313 4314```ts 4315import { BusinessError } from '@kit.BasicServicesKit'; 4316 4317const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" 4318if(store != undefined) { 4319 (store as relationalStore.RdbStore).executeSql(SQL_DELETE_TABLE).then(() => { 4320 console.info('Delete table done.'); 4321 }).catch((err: BusinessError) => { 4322 console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); 4323 }) 4324} 4325``` 4326 4327### execute<sup>12+</sup> 4328 4329execute(sql: string, args?: Array<ValueType>):Promise<ValueType> 4330 4331执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType,使用Promise异步回调。 4332 4333该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。 4334 4335此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。 4336 4337不支持分号分隔的多条语句。 4338 4339**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4340 4341**参数:** 4342 4343| 参数名 | 类型 | 必填 | 说明 | 4344| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4345| sql | string | 是 | 指定要执行的SQL语句。 | 4346| args | Array<[ValueType](#valuetype)> | 否 | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。当sql参数语句完整时,该参数不填。 | 4347 4348**返回值**: 4349 4350| 类型 | 说明 | 4351| ------------------- | ------------------------- | 4352| Promise<[ValueType](#valuetype)> | Promise对象,返回sql执行后的结果。 | 4353 4354**错误码:** 4355 4356以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4357 4358| **错误码ID** | **错误信息** | 4359|-----------| ------------------------------------------------------------ | 4360| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4361| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4362| 14800000 | Inner error. | 4363| 14800011 | Database corrupted. | 4364| 14800014 | Already closed. | 4365| 14800015 | The database does not respond. | 4366| 14800021 | SQLite: Generic error. | 4367| 14800022 | SQLite: Callback routine requested an abort. | 4368| 14800023 | SQLite: Access permission denied. | 4369| 14800024 | SQLite: The database file is locked. | 4370| 14800025 | SQLite: A table in the database is locked. | 4371| 14800026 | SQLite: The database is out of memory. | 4372| 14800027 | SQLite: Attempt to write a readonly database. | 4373| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4374| 14800029 | SQLite: The database is full. | 4375| 14800030 | SQLite: Unable to open the database file. | 4376| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4377| 14800032 | SQLite: Abort due to constraint violation. | 4378| 14800033 | SQLite: Data type mismatch. | 4379| 14800034 | SQLite: Library used incorrectly. | 4380| 14800047 | The WAL file size exceeds the default limit. | 4381 4382**示例:** 4383 4384```ts 4385import { BusinessError } from '@kit.BasicServicesKit'; 4386 4387// 校验数据库完整性 4388if(store != undefined) { 4389 const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check'; 4390 (store as relationalStore.RdbStore).execute(SQL_CHECK_INTEGRITY).then((data) => { 4391 console.info(`check result: ${data}`); 4392 }).catch((err: BusinessError) => { 4393 console.error(`check failed, code is ${err.code}, message is ${err.message}`); 4394 }) 4395} 4396 4397// 删除表中所有数据 4398if(store != undefined) { 4399 const SQL_DELETE_TABLE = 'DELETE FROM test'; 4400 (store as relationalStore.RdbStore).execute(SQL_DELETE_TABLE).then((data) => { 4401 console.info(`delete result: ${data}`); 4402 }).catch((err: BusinessError) => { 4403 console.error(`delete failed, code is ${err.code}, message is ${err.message}`); 4404 }) 4405} 4406 4407// 删表 4408if(store != undefined) { 4409 const SQL_DROP_TABLE = 'DROP TABLE test'; 4410 (store as relationalStore.RdbStore).execute(SQL_DROP_TABLE).then((data) => { 4411 console.info(`drop result: ${data}`); 4412 }).catch((err: BusinessError) => { 4413 console.error(`drop failed, code is ${err.code}, message is ${err.message}`); 4414 }) 4415} 4416``` 4417 4418### execute<sup>12+</sup> 4419 4420execute(sql: string, txId: number, args?: Array<ValueType>): Promise<ValueType> 4421 4422执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,使用Promise异步回调。 4423 4424<!--RP1--> 4425该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End--> 4426 4427此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。 4428 4429不支持分号分隔的多条语句。 4430 4431**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4432 4433**参数:** 4434 4435| 参数名 | 类型 | 必填 | 说明 | 4436| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4437| sql | string | 是 | 指定要执行的SQL语句。 | 4438| txId | number | 是 | 通过[beginTrans](#begintrans12)获取的事务ID,如果传0,该语句默认在单独事务内。 | 4439| args | Array<[ValueType](#valuetype)> | 否 | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。该参数不填,或者填null或undefined,都认为是sql参数语句完整。 | 4440 4441**返回值**: 4442 4443| 类型 | 说明 | 4444| ------------------- | ------------------------- | 4445| Promise<[ValueType](#valuetype)> | Promise对象,返回null。 | 4446 4447**错误码:** 4448 4449以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4450 4451| **错误码ID** | **错误信息** | 4452|-----------| ------------------------------------------------------------ | 4453| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4454| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4455| 14800000 | Inner error. | 4456| 14800011 | Database corrupted. | 4457| 14800014 | Already closed. | 4458| 14800015 | The database does not respond. | 4459| 14800021 | SQLite: Generic error. | 4460| 14800022 | SQLite: Callback routine requested an abort. | 4461| 14800023 | SQLite: Access permission denied. | 4462| 14800024 | SQLite: The database file is locked. | 4463| 14800025 | SQLite: A table in the database is locked. | 4464| 14800026 | SQLite: The database is out of memory. | 4465| 14800027 | SQLite: Attempt to write a readonly database. | 4466| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4467| 14800029 | SQLite: The database is full. | 4468| 14800030 | SQLite: Unable to open the database file. | 4469| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4470| 14800032 | SQLite: Abort due to constraint violation. | 4471| 14800033 | SQLite: Data type mismatch. | 4472| 14800034 | SQLite: Library used incorrectly. | 4473| 14800047 | The WAL file size exceeds the default limit. | 4474 4475**示例:** 4476 4477```ts 4478import { BusinessError } from '@kit.BasicServicesKit'; 4479if(store != null) { 4480 let txId : number; 4481 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 4482 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 4483 .then(() => { 4484 (store as relationalStore.RdbStore).commit(txId); 4485 }) 4486 .catch((err: BusinessError) => { 4487 (store as relationalStore.RdbStore).rollback(txId) 4488 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 4489 }); 4490 }); 4491} 4492``` 4493 4494### executeSync<sup>12+</sup> 4495 4496executeSync(sql: string, args?: Array<ValueType>): ValueType 4497 4498执行包含指定参数的SQL语句,语句中的各种表达式和操作符之间的关系操作符号不超过1000个,返回值类型为ValueType。 4499 4500该接口支持执行增删改操作,支持执行PRAGMA语法的sql,支持对表的操作(建表、删表、修改表),返回结果类型由执行具体sql的结果决定。 4501 4502此接口不支持执行查询、附加数据库和事务操作,可以使用[querySql](#querysql10)、[query](#query10)、[attach](#attach12)、[beginTransaction](#begintransaction)、[commit](#commit)等接口代替。 4503 4504不支持分号分隔的多条语句。 4505 4506**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4507 4508**参数:** 4509 4510| 参数名 | 类型 | 必填 | 说明 | 4511| ------ | ------------------------------------ | ---- | ------------------------------------------------------------ | 4512| sql | string | 是 | 指定要执行的SQL语句。 | 4513| args | Array<[ValueType](#valuetype)> | 否 | SQL语句中参数的值。该值与sql参数语句中的占位符相对应。该参数不填,或者填null或undefined,都认为是sql参数语句完整。默认值为空。 | 4514 4515**返回值**: 4516 4517| 类型 | 说明 | 4518| ----------------------- | ------------------- | 4519| [ValueType](#valuetype) | 返回sql执行后的结果 | 4520 4521**错误码:** 4522 4523以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4524 4525| **错误码ID** | **错误信息** | 4526| ------------ | ------------------------------------------------------------ | 4527| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4528| 14800000 | Inner error. | 4529| 14800011 | Database corrupted. | 4530| 14800014 | Already closed. | 4531| 14800015 | The database does not respond. | 4532| 14800021 | SQLite: Generic error. | 4533| 14800022 | SQLite: Callback routine requested an abort. | 4534| 14800023 | SQLite: Access permission denied. | 4535| 14800024 | SQLite: The database file is locked. | 4536| 14800025 | SQLite: A table in the database is locked. | 4537| 14800026 | SQLite: The database is out of memory. | 4538| 14800027 | SQLite: Attempt to write a readonly database. | 4539| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4540| 14800029 | SQLite: The database is full. | 4541| 14800030 | SQLite: Unable to open the database file. | 4542| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4543| 14800032 | SQLite: Abort due to constraint violation. | 4544| 14800033 | SQLite: Data type mismatch. | 4545| 14800034 | SQLite: Library used incorrectly. | 4546| 14800047 | The WAL file size exceeds the default limit. | 4547 4548**示例:** 4549 4550```ts 4551import { BusinessError } from '@kit.BasicServicesKit'; 4552 4553// 校验数据库完整性 4554if(store != undefined) { 4555 const SQL_CHECK_INTEGRITY = 'PRAGMA integrity_check'; 4556 try { 4557 let data = (store as relationalStore.RdbStore).executeSync(SQL_CHECK_INTEGRITY) 4558 console.info(`check result: ${data}`); 4559 } catch (err) { 4560 console.error(`check failed, code is ${err.code}, message is ${err.message}`); 4561 } 4562} 4563 4564// 删除表中所有数据 4565if(store != undefined) { 4566 const SQL_DELETE_TABLE = 'DELETE FROM test'; 4567 try { 4568 let data = (store as relationalStore.RdbStore).executeSync(SQL_DELETE_TABLE) 4569 console.info(`delete result: ${data}`); 4570 } catch (err) { 4571 console.error(`delete failed, code is ${err.code}, message is ${err.message}`); 4572 } 4573} 4574 4575// 删表 4576if(store != undefined) { 4577 const SQL_DROP_TABLE = 'DROP TABLE test'; 4578 try { 4579 let data = (store as relationalStore.RdbStore).executeSync(SQL_DROP_TABLE) 4580 console.info(`drop result: ${data}`); 4581 } catch (err) { 4582 console.error(`drop failed, code is ${err.code}, message is ${err.message}`); 4583 } 4584} 4585``` 4586 4587### getModifyTime<sup>10+</sup> 4588 4589getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[], callback: AsyncCallback<ModifyTime>): void 4590 4591获取数据库表中数据的最后修改时间,使用callback异步回调。 4592 4593**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4594 4595**参数:** 4596 4597| 参数名 | 类型 | 必填 | 说明 | 4598| ----------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 4599| table | string | 是 | 指定要查询的数据库表的表名。 | 4600| columnName | string | 是 | 指定要查询的数据库表的列名。 | 4601| primaryKeys | [PRIKeyType](#prikeytype10)[] | 是 | 指定要查询的行的主键。<br>如果数据库表无主键,参数columnName需传入"rowid",此时primaryKeys为要查询的数据库表的行号。<br>如果数据库表无主键,参数columnName传入不为"rowid",返回对应的错误码。 | 4602| callback | AsyncCallback<[ModifyTime](#modifytime10)> | 是 | 指定callback回调函数。如果操作成功,则返回ModifyTime对象,表示数据的最后修改时间。 | 4603 4604**错误码:** 4605 4606以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4607 4608| **错误码ID** | **错误信息** | 4609|-----------| ------------------------------------------------------------ | 4610| 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. | 4611| 801 | Capability not supported. | 4612| 14800000 | Inner error. | 4613| 14800011 | Database corrupted. | 4614| 14800014 | Already closed. | 4615| 14800015 | The database does not respond. | 4616| 14800021 | SQLite: Generic error. | 4617| 14800022 | SQLite: Callback routine requested an abort. | 4618| 14800023 | SQLite: Access permission denied. | 4619| 14800024 | SQLite: The database file is locked. | 4620| 14800025 | SQLite: A table in the database is locked. | 4621| 14800026 | SQLite: The database is out of memory. | 4622| 14800027 | SQLite: Attempt to write a readonly database. | 4623| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4624| 14800029 | SQLite: The database is full. | 4625| 14800030 | SQLite: Unable to open the database file. | 4626| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4627| 14800032 | SQLite: Abort due to constraint violation. | 4628| 14800033 | SQLite: Data type mismatch. | 4629| 14800034 | SQLite: Library used incorrectly. | 4630 4631**示例:** 4632 4633```ts 4634let PRIKey = [1, 4, 2, 3]; 4635if(store != undefined) { 4636 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey, (err, modifyTime: relationalStore.ModifyTime) => { 4637 if (err) { 4638 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 4639 return; 4640 } 4641 let size = modifyTime.size; 4642 }); 4643} 4644``` 4645 4646### getModifyTime<sup>10+</sup> 4647 4648getModifyTime(table: string, columnName: string, primaryKeys: PRIKeyType[]): Promise<ModifyTime> 4649 4650获取数据库表中数据的最后修改时间,使用Promise异步回调。 4651 4652**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4653 4654**参数:** 4655 4656| 参数名 | 类型 | 必填 | 说明 | 4657| ----------- | ----------------------------- | ---- | ------------------------------------------------------------ | 4658| table | string | 是 | 指定要查询的数据库表的表名。 | 4659| columnName | string | 是 | 指定要查询的数据库表的列名。 | 4660| primaryKeys | [PRIKeyType](#prikeytype10)[] | 是 | 指定要查询的行的主键。<br>如果数据库表无主键,参数columnName需传入"rowid",此时primaryKeys为要查询的数据库表的行号。<br>如果数据库表无主键,参数columnName传入不为"rowid",返回对应的错误码。 | 4661 4662**返回值**: 4663 4664| 类型 | 说明 | 4665| ------------------------------------------ | --------------------------------------------------------- | 4666| Promise<[ModifyTime](#modifytime10)> | 返回ModifyTime类型的Promise对象,表示数据最后的修改时间。 | 4667 4668**错误码:** 4669 4670以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4671 4672| **错误码ID** | **错误信息** | 4673|-----------| ------------------------------------------------------------ | 4674| 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. | 4675| 801 | Capability not supported. | 4676| 14800000 | Inner error. | 4677| 14800011 | Database corrupted. | 4678| 14800014 | Already closed. | 4679| 14800015 | The database does not respond. | 4680| 14800021 | SQLite: Generic error. | 4681| 14800022 | SQLite: Callback routine requested an abort. | 4682| 14800023 | SQLite: Access permission denied. | 4683| 14800024 | SQLite: The database file is locked. | 4684| 14800025 | SQLite: A table in the database is locked. | 4685| 14800026 | SQLite: The database is out of memory. | 4686| 14800027 | SQLite: Attempt to write a readonly database. | 4687| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4688| 14800029 | SQLite: The database is full. | 4689| 14800030 | SQLite: Unable to open the database file. | 4690| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4691| 14800032 | SQLite: Abort due to constraint violation. | 4692| 14800033 | SQLite: Data type mismatch. | 4693| 14800034 | SQLite: Library used incorrectly. | 4694 4695**示例:** 4696 4697```ts 4698import { BusinessError } from '@kit.BasicServicesKit'; 4699 4700let PRIKey = [1, 2, 3]; 4701if(store != undefined) { 4702 (store as relationalStore.RdbStore).getModifyTime("EMPLOYEE", "NAME", PRIKey) 4703 .then((modifyTime: relationalStore.ModifyTime) => { 4704 let size = modifyTime.size; 4705 }) 4706 .catch((err: BusinessError) => { 4707 console.error(`getModifyTime failed, code is ${err.code},message is ${err.message}`); 4708 }); 4709} 4710``` 4711 4712### beginTransaction 4713 4714beginTransaction():void 4715 4716在开始执行SQL语句之前,开始事务。 4717此接口不允许嵌套事务,且不支持在多进程或多线程中使用。 4718 4719**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4720 4721**错误码:** 4722 4723以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4724 4725| **错误码ID** | **错误信息** | 4726|-----------| ------------------------------------------------------------ | 4727| 401 | Parameter error. The store must not be nullptr. | 4728| 14800000 | Inner error. | 4729| 14800011 | Database corrupted. | 4730| 14800014 | Already closed. | 4731| 14800015 | The database does not respond. | 4732| 14800021 | SQLite: Generic error. | 4733| 14800022 | SQLite: Callback routine requested an abort. | 4734| 14800023 | SQLite: Access permission denied. | 4735| 14800024 | SQLite: The database file is locked. | 4736| 14800025 | SQLite: A table in the database is locked. | 4737| 14800026 | SQLite: The database is out of memory. | 4738| 14800027 | SQLite: Attempt to write a readonly database. | 4739| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4740| 14800029 | SQLite: The database is full. | 4741| 14800030 | SQLite: Unable to open the database file. | 4742| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4743| 14800032 | SQLite: Abort due to constraint violation. | 4744| 14800033 | SQLite: Data type mismatch. | 4745| 14800034 | SQLite: Library used incorrectly. | 4746| 14800047 | The WAL file size exceeds the default limit. | 4747 4748**示例:** 4749 4750```ts 4751 4752let value1 = "Lisa"; 4753let value2 = 18; 4754let value3 = 100.5; 4755let value4 = new Uint8Array([1, 2, 3]); 4756 4757if(store != undefined) { 4758 (store as relationalStore.RdbStore).beginTransaction(); 4759 const valueBucket: relationalStore.ValuesBucket = { 4760 'NAME': value1, 4761 'AGE': value2, 4762 'SALARY': value3, 4763 'CODES': value4, 4764 }; 4765 (store as relationalStore.RdbStore).insert("test", valueBucket); 4766 (store as relationalStore.RdbStore).commit(); 4767} 4768``` 4769 4770### beginTrans<sup>12+</sup> 4771 4772beginTrans(): Promise<number> 4773 4774在开始执行SQL语句之前,开始事务,使用Promise异步回调。 4775 4776与[beginTransaction](#begintransaction)的区别在于:该接口会返回事务ID,[execute](#execute12-1)可以指定不同事务ID达到事务隔离目的。 4777 4778<!--RP1--> 4779该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End--> 4780 4781**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4782 4783**返回值**: 4784 4785| 类型 | 说明 | 4786| ------------------- | ------------------------- | 4787| Promise<number> | Promise对象,返回事务ID。 | 4788 4789**错误码:** 4790 4791以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4792 4793| **错误码ID** | **错误信息** | 4794|-----------| ------------------------------------------------------------ | 4795| 401 | Parameter error. The store must not be nullptr. | 4796| 801 | Capability not supported the sql(attach,begin,commit,rollback etc.). | 4797| 14800000 | Inner error. | 4798| 14800011 | Database corrupted. | 4799| 14800014 | Already closed. | 4800| 14800015 | The database does not respond. | 4801| 14800021 | SQLite: Generic error. | 4802| 14800022 | SQLite: Callback routine requested an abort. | 4803| 14800023 | SQLite: Access permission denied. | 4804| 14800024 | SQLite: The database file is locked. | 4805| 14800025 | SQLite: A table in the database is locked. | 4806| 14800026 | SQLite: The database is out of memory. | 4807| 14800027 | SQLite: Attempt to write a readonly database. | 4808| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4809| 14800029 | SQLite: The database is full. | 4810| 14800030 | SQLite: Unable to open the database file. | 4811| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4812| 14800032 | SQLite: Abort due to constraint violation. | 4813| 14800033 | SQLite: Data type mismatch. | 4814| 14800034 | SQLite: Library used incorrectly. | 4815| 14800047 | The WAL file size exceeds the default limit. | 4816 4817**示例:** 4818 4819```ts 4820import { BusinessError } from '@kit.BasicServicesKit'; 4821if(store != null) { 4822 let txId : number; 4823 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 4824 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 4825 .then(() => { 4826 (store as relationalStore.RdbStore).commit(txId); 4827 }) 4828 .catch((err: BusinessError) => { 4829 (store as relationalStore.RdbStore).rollback(txId) 4830 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 4831 }); 4832 }); 4833} 4834``` 4835 4836### commit 4837 4838commit():void 4839 4840提交已执行的SQL语句。 4841此接口不允许嵌套事务,且不支持在多进程或多线程中使用。 4842 4843**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4844 4845**错误码:** 4846 4847以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4848 4849| **错误码ID** | **错误信息** | 4850|-----------| ------------------------------------------------------------ | 4851| 401 | Parameter error. The store must not be nullptr. | 4852| 14800000 | Inner error. | 4853| 14800011 | Database corrupted. | 4854| 14800014 | Already closed. | 4855| 14800015 | The database does not respond. | 4856| 14800021 | SQLite: Generic error. | 4857| 14800022 | SQLite: Callback routine requested an abort. | 4858| 14800023 | SQLite: Access permission denied. | 4859| 14800024 | SQLite: The database file is locked. | 4860| 14800025 | SQLite: A table in the database is locked. | 4861| 14800026 | SQLite: The database is out of memory. | 4862| 14800027 | SQLite: Attempt to write a readonly database. | 4863| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4864| 14800029 | SQLite: The database is full. | 4865| 14800030 | SQLite: Unable to open the database file. | 4866| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4867| 14800032 | SQLite: Abort due to constraint violation. | 4868| 14800033 | SQLite: Data type mismatch. | 4869| 14800034 | SQLite: Library used incorrectly. | 4870 4871**示例:** 4872 4873```ts 4874 4875let value1 = "Lisa"; 4876let value2 = 18; 4877let value3 = 100.5; 4878let value4 = new Uint8Array([1, 2, 3]); 4879 4880if(store != undefined) { 4881 (store as relationalStore.RdbStore).beginTransaction(); 4882 const valueBucket: relationalStore.ValuesBucket = { 4883 'NAME': value1, 4884 'AGE': value2, 4885 'SALARY': value3, 4886 'CODES': value4, 4887 }; 4888 (store as relationalStore.RdbStore).insert("test", valueBucket); 4889 (store as relationalStore.RdbStore).commit(); 4890} 4891``` 4892 4893### commit<sup>12+</sup> 4894 4895commit(txId : number):Promise<void> 4896 4897提交已执行的SQL语句,跟[beginTrans](#begintrans12)配合使用。 4898 4899<!--RP1--> 4900该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End--> 4901 4902**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4903 4904**参数:** 4905 4906| 参数名 | 类型 | 必填 | 说明 | 4907| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 4908| txId | number | 是 | 通过[beginTrans](#begintrans12)获取的事务ID。 | 4909 4910**返回值**: 4911 4912| 类型 | 说明 | 4913| ------------------- | ------------------------- | 4914| Promise<void> | 无返回结果的Promise对象。 | 4915 4916**错误码:** 4917 4918以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4919 4920| **错误码ID** | **错误信息** | 4921|-----------| ------------------------------------------------------------ | 4922| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4923| 14800000 | Inner error. | 4924| 14800011 | Database corrupted. | 4925| 14800014 | Already closed. | 4926| 14800015 | The database does not respond. | 4927| 14800021 | SQLite: Generic error. | 4928| 14800022 | SQLite: Callback routine requested an abort. | 4929| 14800023 | SQLite: Access permission denied. | 4930| 14800024 | SQLite: The database file is locked. | 4931| 14800025 | SQLite: A table in the database is locked. | 4932| 14800026 | SQLite: The database is out of memory. | 4933| 14800027 | SQLite: Attempt to write a readonly database. | 4934| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4935| 14800029 | SQLite: The database is full. | 4936| 14800030 | SQLite: Unable to open the database file. | 4937| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4938| 14800032 | SQLite: Abort due to constraint violation. | 4939| 14800033 | SQLite: Data type mismatch. | 4940| 14800034 | SQLite: Library used incorrectly. | 4941 4942**示例:** 4943 4944```ts 4945import { BusinessError } from '@kit.BasicServicesKit'; 4946if(store != null) { 4947 let txId : number; 4948 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 4949 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 4950 .then(() => { 4951 (store as relationalStore.RdbStore).commit(txId); 4952 }) 4953 .catch((err: BusinessError) => { 4954 (store as relationalStore.RdbStore).rollback(txId) 4955 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 4956 }); 4957 }); 4958} 4959``` 4960 4961### rollBack 4962 4963rollBack():void 4964 4965回滚已经执行的SQL语句。 4966此接口不允许嵌套事务,且不支持在多进程或多线程中使用。 4967 4968**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 4969 4970**错误码:** 4971 4972以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 4973 4974| **错误码ID** | **错误信息** | 4975|-----------| ------------------------------------------------------------ | 4976| 401 | Parameter error. The store must not be nullptr. | 4977| 14800000 | Inner error. | 4978| 14800011 | Database corrupted. | 4979| 14800014 | Already closed. | 4980| 14800015 | The database does not respond. | 4981| 14800021 | SQLite: Generic error. | 4982| 14800022 | SQLite: Callback routine requested an abort. | 4983| 14800023 | SQLite: Access permission denied. | 4984| 14800024 | SQLite: The database file is locked. | 4985| 14800025 | SQLite: A table in the database is locked. | 4986| 14800026 | SQLite: The database is out of memory. | 4987| 14800027 | SQLite: Attempt to write a readonly database. | 4988| 14800028 | SQLite: Some kind of disk I/O error occurred. | 4989| 14800029 | SQLite: The database is full. | 4990| 14800030 | SQLite: Unable to open the database file. | 4991| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 4992| 14800032 | SQLite: Abort due to constraint violation. | 4993| 14800033 | SQLite: Data type mismatch. | 4994| 14800034 | SQLite: Library used incorrectly. | 4995 4996**示例:** 4997 4998```ts 4999import { BusinessError } from '@kit.BasicServicesKit'; 5000 5001let value1 = "Lisa"; 5002let value2 = 18; 5003let value3 = 100.5; 5004let value4 = new Uint8Array([1, 2, 3]); 5005 5006if(store != undefined) { 5007 try { 5008 (store as relationalStore.RdbStore).beginTransaction() 5009 const valueBucket: relationalStore.ValuesBucket = { 5010 'NAME': value1, 5011 'AGE': value2, 5012 'SALARY': value3, 5013 'CODES': value4, 5014 }; 5015 (store as relationalStore.RdbStore).insert("test", valueBucket); 5016 (store as relationalStore.RdbStore).commit(); 5017 } catch (err) { 5018 let code = (err as BusinessError).code; 5019 let message = (err as BusinessError).message 5020 console.error(`Transaction failed, code is ${code},message is ${message}`); 5021 (store as relationalStore.RdbStore).rollBack(); 5022 } 5023} 5024``` 5025 5026### rollback<sup>12+</sup> 5027 5028rollback(txId : number):Promise<void> 5029 5030回滚已经执行的SQL语句,跟[beginTrans](#begintrans12)配合使用。 5031 5032<!--RP1--> 5033该接口仅支持[向量数据库](js-apis-data-relationalStore-sys.md#storeconfig)使用。<!--RP1End--> 5034 5035**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5036 5037**参数:** 5038 5039| 参数名 | 类型 | 必填 | 说明 | 5040| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 5041| txId | number | 是 | 通过[beginTrans](#begintrans12)获取的事务ID。 | 5042 5043**返回值**: 5044 5045| 类型 | 说明 | 5046| ------------------- | ------------------------- | 5047| Promise<void> | 无返回结果的Promise对象。 | 5048 5049**错误码:** 5050 5051以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 5052 5053| **错误码ID** | **错误信息** | 5054|-----------| ------------------------------------------------------------ | 5055| 401 | Parameter error. The store must not be nullptr. | 5056| 14800000 | Inner error. | 5057| 14800011 | Database corrupted. | 5058| 14800014 | Already closed. | 5059| 14800015 | The database does not respond. | 5060| 14800021 | SQLite: Generic error. | 5061| 14800022 | SQLite: Callback routine requested an abort. | 5062| 14800023 | SQLite: Access permission denied. | 5063| 14800024 | SQLite: The database file is locked. | 5064| 14800025 | SQLite: A table in the database is locked. | 5065| 14800026 | SQLite: The database is out of memory. | 5066| 14800027 | SQLite: Attempt to write a readonly database. | 5067| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5068| 14800029 | SQLite: The database is full. | 5069| 14800030 | SQLite: Unable to open the database file. | 5070| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5071| 14800032 | SQLite: Abort due to constraint violation. | 5072| 14800033 | SQLite: Data type mismatch. | 5073| 14800034 | SQLite: Library used incorrectly. | 5074 5075**示例:** 5076 5077```ts 5078import { BusinessError } from '@kit.BasicServicesKit'; 5079if(store != null) { 5080 let txId : number; 5081 (store as relationalStore.RdbStore).beginTrans().then((txId : number) => { 5082 (store as relationalStore.RdbStore).execute("DELETE FROM TEST WHERE age = ? OR age = ?", txId, ["18", "20"]) 5083 .then(() => { 5084 (store as relationalStore.RdbStore).commit(txId); 5085 }) 5086 .catch((err: BusinessError) => { 5087 (store as relationalStore.RdbStore).rollback(txId) 5088 console.error(`execute sql failed, code is ${err.code},message is ${err.message}`); 5089 }); 5090 }); 5091} 5092``` 5093 5094### backup 5095 5096backup(destName:string, callback: AsyncCallback<void>):void 5097 5098以指定名称备份数据库,使用callback异步回调。 5099 5100**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5101 5102**参数:** 5103 5104| 参数名 | 类型 | 必填 | 说明 | 5105| -------- | ------------------------- | ---- | ------------------------ | 5106| destName | string | 是 | 指定数据库的备份文件名。 | 5107| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | 5108 5109**错误码:** 5110 5111以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 5112 5113| **错误码ID** | **错误信息** | 5114|-----------| ------------------------------------------------------------ | 5115| 401 | Parameter error. The store must not be nullptr. | 5116| 14800000 | Inner error. | 5117| 14800010 | Invalid database path. | 5118| 14800011 | Database corrupted. | 5119| 14800014 | Already closed. | 5120| 14800015 | The database does not respond. | 5121| 14800021 | SQLite: Generic error. | 5122| 14800022 | SQLite: Callback routine requested an abort. | 5123| 14800023 | SQLite: Access permission denied. | 5124| 14800024 | SQLite: The database file is locked. | 5125| 14800025 | SQLite: A table in the database is locked. | 5126| 14800026 | SQLite: The database is out of memory. | 5127| 14800027 | SQLite: Attempt to write a readonly database. | 5128| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5129| 14800029 | SQLite: The database is full. | 5130| 14800030 | SQLite: Unable to open the database file. | 5131| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5132| 14800032 | SQLite: Abort due to constraint violation. | 5133| 14800033 | SQLite: Data type mismatch. | 5134| 14800034 | SQLite: Library used incorrectly. | 5135 5136**示例:** 5137 5138```ts 5139if(store != undefined) { 5140 (store as relationalStore.RdbStore).backup("dbBackup.db", (err) => { 5141 if (err) { 5142 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 5143 return; 5144 } 5145 console.info('Backup success.'); 5146 }) 5147} 5148``` 5149 5150### backup 5151 5152backup(destName:string): Promise<void> 5153 5154以指定名称备份数据库,使用Promise异步回调。 5155 5156**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5157 5158**参数:** 5159 5160| 参数名 | 类型 | 必填 | 说明 | 5161| -------- | ------ | ---- | ------------------------ | 5162| destName | string | 是 | 指定数据库的备份文件名。 | 5163 5164**返回值**: 5165 5166| 类型 | 说明 | 5167| ------------------- | ------------------------- | 5168| Promise<void> | 无返回结果的Promise对象。 | 5169 5170**错误码:** 5171 5172以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 5173 5174| **错误码ID** | **错误信息** | 5175|-----------| ------------------------------------------------------------ | 5176| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5177| 14800000 | Inner error. | 5178| 14800011 | Database corrupted. | 5179| 14800014 | Already closed. | 5180| 14800015 | The database does not respond. | 5181| 14800021 | SQLite: Generic error. | 5182| 14800022 | SQLite: Callback routine requested an abort. | 5183| 14800023 | SQLite: Access permission denied. | 5184| 14800024 | SQLite: The database file is locked. | 5185| 14800025 | SQLite: A table in the database is locked. | 5186| 14800026 | SQLite: The database is out of memory. | 5187| 14800027 | SQLite: Attempt to write a readonly database. | 5188| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5189| 14800029 | SQLite: The database is full. | 5190| 14800030 | SQLite: Unable to open the database file. | 5191| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5192| 14800032 | SQLite: Abort due to constraint violation. | 5193| 14800033 | SQLite: Data type mismatch. | 5194| 14800034 | SQLite: Library used incorrectly. | 5195 5196**示例:** 5197 5198```ts 5199import { BusinessError } from '@kit.BasicServicesKit'; 5200 5201if(store != undefined) { 5202 let promiseBackup = (store as relationalStore.RdbStore).backup("dbBackup.db"); 5203 promiseBackup.then(() => { 5204 console.info('Backup success.'); 5205 }).catch((err: BusinessError) => { 5206 console.error(`Backup failed, code is ${err.code},message is ${err.message}`); 5207 }) 5208} 5209``` 5210 5211### restore 5212 5213restore(srcName:string, callback: AsyncCallback<void>):void 5214 5215从指定的数据库备份文件恢复数据库,使用callback异步回调。 5216 5217**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5218 5219**参数:** 5220 5221| 参数名 | 类型 | 必填 | 说明 | 5222| -------- | ------------------------- | ---- | ------------------------ | 5223| srcName | string | 是 | 指定数据库的备份文件名。 | 5224| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | 5225 5226**错误码:** 5227 5228以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 5229 5230| **错误码ID** | **错误信息** | 5231|-----------| ------------------------------------------------------------ | 5232| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5233| 14800000 | Inner error. | 5234| 14800011 | Database corrupted. | 5235| 14800014 | Already closed. | 5236| 14800015 | The database does not respond. | 5237| 14800021 | SQLite: Generic error. | 5238| 14800022 | SQLite: Callback routine requested an abort. | 5239| 14800023 | SQLite: Access permission denied. | 5240| 14800024 | SQLite: The database file is locked. | 5241| 14800025 | SQLite: A table in the database is locked. | 5242| 14800026 | SQLite: The database is out of memory. | 5243| 14800027 | SQLite: Attempt to write a readonly database. | 5244| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5245| 14800029 | SQLite: The database is full. | 5246| 14800030 | SQLite: Unable to open the database file. | 5247| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5248| 14800032 | SQLite: Abort due to constraint violation. | 5249| 14800033 | SQLite: Data type mismatch. | 5250| 14800034 | SQLite: Library used incorrectly. | 5251 5252**示例:** 5253 5254```ts 5255if(store != undefined) { 5256 (store as relationalStore.RdbStore).restore("dbBackup.db", (err) => { 5257 if (err) { 5258 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 5259 return; 5260 } 5261 console.info('Restore success.'); 5262 }) 5263} 5264``` 5265 5266### restore 5267 5268restore(srcName:string): Promise<void> 5269 5270从指定的数据库备份文件恢复数据库,使用Promise异步回调。 5271 5272**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5273 5274**参数:** 5275 5276| 参数名 | 类型 | 必填 | 说明 | 5277| ------- | ------ | ---- | ------------------------ | 5278| srcName | string | 是 | 指定数据库的备份文件名。 | 5279 5280**返回值**: 5281 5282| 类型 | 说明 | 5283| ------------------- | ------------------------- | 5284| Promise<void> | 无返回结果的Promise对象。 | 5285 5286**错误码:** 5287 5288以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 5289 5290| **错误码ID** | **错误信息** | 5291|-----------| ------------------------------------------------------------ | 5292| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5293| 14800000 | Inner error. | 5294| 14800011 | Database corrupted. | 5295| 14800014 | Already closed. | 5296| 14800015 | The database does not respond. | 5297| 14800021 | SQLite: Generic error. | 5298| 14800022 | SQLite: Callback routine requested an abort. | 5299| 14800023 | SQLite: Access permission denied. | 5300| 14800024 | SQLite: The database file is locked. | 5301| 14800025 | SQLite: A table in the database is locked. | 5302| 14800026 | SQLite: The database is out of memory. | 5303| 14800027 | SQLite: Attempt to write a readonly database. | 5304| 14800028 | SQLite: Some kind of disk I/O error occurred. | 5305| 14800029 | SQLite: The database is full. | 5306| 14800030 | SQLite: Unable to open the database file. | 5307| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 5308| 14800032 | SQLite: Abort due to constraint violation. | 5309| 14800033 | SQLite: Data type mismatch. | 5310| 14800034 | SQLite: Library used incorrectly. | 5311 5312**示例:** 5313 5314```ts 5315import { BusinessError } from '@kit.BasicServicesKit'; 5316 5317if(store != undefined) { 5318 let promiseRestore = (store as relationalStore.RdbStore).restore("dbBackup.db"); 5319 promiseRestore.then(() => { 5320 console.info('Restore success.'); 5321 }).catch((err: BusinessError) => { 5322 console.error(`Restore failed, code is ${err.code},message is ${err.message}`); 5323 }) 5324} 5325``` 5326 5327### setDistributedTables 5328 5329setDistributedTables(tables: Array<string>, callback: AsyncCallback<void>): void 5330 5331设置分布式数据库表,使用callback异步回调。 5332 5333**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 5334 5335**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5336 5337**参数:** 5338 5339| 参数名 | 类型 | 必填 | 说明 | 5340| -------- | ------------------------- | ---- | ---------------------- | 5341| tables | Array<string> | 是 | 要设置的分布式数据库表表名。 | 5342| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | 5343 5344**错误码:** 5345 5346以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5347 5348| **错误码ID** | **错误信息** | 5349|-----------| ------------------------------------------------------------ | 5350| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5351| 801 | Capability not supported. | 5352| 14800000 | Inner error. | 5353| 14800014 | Already closed. | 5354 5355**示例:** 5356 5357```ts 5358if(store != undefined) { 5359 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], (err) => { 5360 if (err) { 5361 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5362 return; 5363 } 5364 console.info('SetDistributedTables successfully.'); 5365 }) 5366} 5367``` 5368 5369### setDistributedTables 5370 5371 setDistributedTables(tables: Array<string>): Promise<void> 5372 5373设置分布式数据库表,使用Promise异步回调。 5374 5375**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 5376 5377**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5378 5379**参数:** 5380 5381| 参数名 | 类型 | 必填 | 说明 | 5382| ------ | ------------------------ | ---- | ------------------------ | 5383| tables | ArrayArray<string> | 是 | 要设置的分布式数据库表表名。 | 5384 5385**返回值**: 5386 5387| 类型 | 说明 | 5388| ------------------- | ------------------------- | 5389| Promise<void> | 无返回结果的Promise对象。 | 5390 5391**错误码:** 5392 5393以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5394 5395| **错误码ID** | **错误信息** | 5396|-----------| ------------------------------------------------------------ | 5397| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5398| 801 | Capability not supported. | 5399| 14800000 | Inner error. | 5400| 14800014 | Already closed. | 5401 5402**示例:** 5403 5404```ts 5405import { BusinessError } from '@kit.BasicServicesKit'; 5406 5407if(store != undefined) { 5408 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"]).then(() => { 5409 console.info('SetDistributedTables successfully.'); 5410 }).catch((err: BusinessError) => { 5411 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5412 }) 5413} 5414``` 5415 5416### setDistributedTables<sup>10+</sup> 5417 5418setDistributedTables(tables: Array<string>, type: DistributedType, callback: AsyncCallback<void>): void 5419 5420设置分布式数据库表,使用callback异步回调。 5421 5422**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 5423 5424**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5425 5426**参数:** 5427 5428| 参数名 | 类型 | 必填 | 说明 | 5429| -------- | ------------------------------------- | ---- | ---------------------------- | 5430| tables | Array<string> | 是 | 要设置的分布式数据库表表名。 | 5431| type | [DistributedType](#distributedtype10) | 是 | 表的分布式类型。 | 5432| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | 5433 5434**错误码:** 5435 5436以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5437 5438| **错误码ID** | **错误信息** | 5439|-----------| ------------------------------------------------------------ | 5440| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5441| 801 | Capability not supported. | 5442| 14800000 | Inner error. | 5443| 14800014 | Already closed. | 5444| 14800051 | The type of the distributed table does not match. | 5445 5446**示例:** 5447 5448```ts 5449if(store != undefined) { 5450 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, (err) => { 5451 if (err) { 5452 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5453 return; 5454 } 5455 console.info('SetDistributedTables successfully.'); 5456 }) 5457} 5458``` 5459 5460### setDistributedTables<sup>10+</sup> 5461 5462setDistributedTables(tables: Array<string>, type: DistributedType, config: DistributedConfig, callback: AsyncCallback<void>): void 5463 5464设置分布式数据库表,使用callback异步回调。 5465 5466**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 5467 5468**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5469 5470**参数:** 5471 5472| 参数名 | 类型 | 必填 | 说明 | 5473| -------- | ----------------------------------- | --- | --------------- | 5474| tables | Array<string> | 是 | 要设置的分布式数据库表表名。 | 5475| type | [DistributedType](#distributedtype10) | 是 | 表的分布式类型。 | 5476| config | [DistributedConfig](#distributedconfig10) | 是 | 表的分布式配置信息。 | 5477| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | 5478 5479**错误码:** 5480 5481以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5482 5483| **错误码ID** | **错误信息** | 5484|-----------| ------------------------------------------------------------ | 5485| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5486| 801 | Capability not supported. | 5487| 14800000 | Inner error. | 5488| 14800014 | Already closed. | 5489| 14800051 | The type of the distributed table does not match. | 5490 5491**示例:** 5492 5493```ts 5494if(store != undefined) { 5495 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 5496 autoSync: true 5497 }, (err) => { 5498 if (err) { 5499 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5500 return; 5501 } 5502 console.info('SetDistributedTables successfully.'); 5503 }) 5504} 5505``` 5506 5507### setDistributedTables<sup>10+</sup> 5508 5509 setDistributedTables(tables: Array<string>, type?: DistributedType, config?: DistributedConfig): Promise<void> 5510 5511设置分布式数据库表,使用Promise异步回调。 5512 5513**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 5514 5515**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5516 5517**参数:** 5518 5519| 参数名 | 类型 | 必填 | 说明 | 5520| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ | 5521| tables | Array<string> | 是 | 要设置的分布式数据库表表名。 | 5522| type | [DistributedType](#distributedtype10) | 否 | 表的分布式类型。默认值是relationalStore.DistributedType.DISTRIBUTED_DEVICE。 | 5523| config | [DistributedConfig](#distributedconfig10) | 否 | 表的分布式配置信息。不传入时默认autoSync为false,即只支持手动同步。 | 5524 5525**返回值**: 5526 5527| 类型 | 说明 | 5528| ------------------- | ------------------------- | 5529| Promise<void> | 无返回结果的Promise对象。 | 5530 5531**错误码:** 5532 5533以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5534 5535| **错误码ID** | **错误信息** | 5536|-----------| ------------------------------------------------------------ | 5537| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5538| 801 | Capability not supported. | 5539| 14800000 | Inner error. | 5540| 14800014 | Already closed. | 5541| 14800051 | The type of the distributed table does not match. | 5542 5543**示例:** 5544 5545```ts 5546import { BusinessError } from '@kit.BasicServicesKit'; 5547 5548if(store != undefined) { 5549 (store as relationalStore.RdbStore).setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIBUTED_CLOUD, { 5550 autoSync: true 5551 }).then(() => { 5552 console.info('SetDistributedTables successfully.'); 5553 }).catch((err: BusinessError) => { 5554 console.error(`SetDistributedTables failed, code is ${err.code},message is ${err.message}`); 5555 }) 5556} 5557``` 5558 5559### obtainDistributedTableName 5560 5561obtainDistributedTableName(device: string, table: string, callback: AsyncCallback<string>): void 5562 5563根据远程设备的本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名, 使用callback异步回调。 5564 5565> **说明:** 5566> 5567> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。 5568 5569**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 5570 5571**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5572 5573**参数:** 5574 5575| 参数名 | 类型 | 必填 | 说明 | 5576| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 5577| device | string | 是 | 远程设备ID 。 | 5578| table | string | 是 | 远程设备的本地表名。 | 5579| callback | AsyncCallback<string> | 是 | 指定的callback回调函数。如果操作成功,返回远程设备的分布式表名。 | 5580 5581**错误码:** 5582 5583以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5584 5585| **错误码ID** | **错误信息** | 5586|-----------| ------------------------------------------------------------ | 5587| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5588| 801 | Capability not supported. | 5589| 14800000 | Inner error. | 5590| 14800014 | Already closed. | 5591 5592**示例:** 5593 5594```ts 5595import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5596import { BusinessError } from '@kit.BasicServicesKit'; 5597 5598let dmInstance: distributedDeviceManager.DeviceManager; 5599let deviceId: string | undefined = undefined; 5600 5601try { 5602 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5603 let devices = dmInstance.getAvailableDeviceListSync(); 5604 deviceId = devices[0].networkId; 5605} catch (err) { 5606 let code = (err as BusinessError).code; 5607 let message = (err as BusinessError).message 5608 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5609} 5610 5611if(store != undefined && deviceId != undefined) { 5612 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE", (err, tableName) => { 5613 if (err) { 5614 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 5615 return; 5616 } 5617 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 5618 }) 5619} 5620``` 5621 5622### obtainDistributedTableName 5623 5624 obtainDistributedTableName(device: string, table: string): Promise<string> 5625 5626根据远程设备的本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名,使用Promise异步回调。 5627 5628> **说明:** 5629> 5630> 其中device通过调用[deviceManager.getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync)方法得到。 5631 5632**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 5633 5634**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5635 5636**参数:** 5637 5638| 参数名 | 类型 | 必填 | 说明 | 5639| ------ | ------ | ---- | -------------------- | 5640| device | string | 是 | 远程设备ID。 | 5641| table | string | 是 | 远程设备的本地表名。 | 5642 5643**返回值**: 5644 5645| 类型 | 说明 | 5646| --------------------- | ----------------------------------------------------- | 5647| Promise<string> | Promise对象。如果操作成功,返回远程设备的分布式表名。 | 5648 5649**错误码:** 5650 5651以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5652 5653| **错误码ID** | **错误信息** | 5654|-----------| ------------------------------------------------------------ | 5655| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5656| 801 | Capability not supported. | 5657| 14800000 | Inner error. | 5658| 14800014 | Already closed. | 5659 5660**示例:** 5661 5662```ts 5663import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5664import { BusinessError } from '@kit.BasicServicesKit'; 5665 5666let dmInstance: distributedDeviceManager.DeviceManager; 5667let deviceId: string | undefined = undefined; 5668 5669try { 5670 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5671 let devices = dmInstance.getAvailableDeviceListSync(); 5672 deviceId = devices[0].networkId; 5673} catch (err) { 5674 let code = (err as BusinessError).code; 5675 let message = (err as BusinessError).message 5676 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5677} 5678 5679if(store != undefined && deviceId != undefined) { 5680 (store as relationalStore.RdbStore).obtainDistributedTableName(deviceId, "EMPLOYEE").then((tableName: string) => { 5681 console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`); 5682 }).catch((err: BusinessError) => { 5683 console.error(`ObtainDistributedTableName failed, code is ${err.code},message is ${err.message}`); 5684 }) 5685} 5686``` 5687 5688### sync 5689 5690sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void 5691 5692在设备之间同步数据, 使用callback异步回调。 5693 5694**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 5695 5696**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5697 5698**参数:** 5699 5700| 参数名 | 类型 | 必填 | 说明 | 5701| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ | 5702| mode | [SyncMode](#syncmode) | 是 | 指同步模式。该值可以是relationalStore.SyncMode.SYNC_MODE_PUSH、relationalStore.SyncMode.SYNC_MODE_PULL。 | 5703| predicates | [RdbPredicates](#rdbpredicates) | 是 | 约束同步数据和设备。 | 5704| callback | AsyncCallback<Array<[string, number]>> | 是 | 指定的callback回调函数,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 | 5705 5706**错误码:** 5707 5708以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5709 5710| **错误码ID** | **错误信息** | 5711|-----------| ------------------------------------------------------------ | 5712| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5713| 801 | Capability not supported. | 5714| 14800000 | Inner error. | 5715| 14800014 | Already closed. | 5716 5717**示例:** 5718 5719```ts 5720import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5721import { BusinessError } from '@kit.BasicServicesKit'; 5722 5723let dmInstance: distributedDeviceManager.DeviceManager; 5724let deviceIds: Array<string> = []; 5725 5726try { 5727 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5728 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 5729 for (let i = 0; i < devices.length; i++) { 5730 deviceIds[i] = devices[i].networkId!; 5731 } 5732} catch (err) { 5733 let code = (err as BusinessError).code; 5734 let message = (err as BusinessError).message 5735 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5736} 5737 5738let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 5739predicates.inDevices(deviceIds); 5740if(store != undefined) { 5741 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, (err, result) => { 5742 if (err) { 5743 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 5744 return; 5745 } 5746 console.info('Sync done.'); 5747 for (let i = 0; i < result.length; i++) { 5748 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 5749 } 5750 }) 5751} 5752``` 5753 5754### sync 5755 5756 sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>> 5757 5758在设备之间同步数据,使用Promise异步回调。 5759 5760**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC 5761 5762**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 5763 5764**参数:** 5765 5766| 参数名 | 类型 | 必填 | 说明 | 5767| ---------- | ------------------------------------ | ---- | ------------------------------ | 5768| mode | [SyncMode](#syncmode) | 是 | 指同步模式。该值可以是relationalStore.SyncMode.SYNC_MODE_PUSH、relationalStore.SyncMode.SYNC_MODE_PULL。 | 5769| predicates | [RdbPredicates](#rdbpredicates) | 是 | 约束同步数据和设备。 | 5770 5771**返回值**: 5772 5773| 类型 | 说明 | 5774| -------------------------------------------- | ------------------------------------------------------------ | 5775| Promise<Array<[string, number]>> | Promise对象,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 | 5776 5777**错误码:** 5778 5779以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5780 5781| **错误码ID** | **错误信息** | 5782|-----------| ------------------------------------------------------------ | 5783| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5784| 801 | Capability not supported. | 5785| 14800000 | Inner error. | 5786| 14800014 | Already closed. | 5787 5788**示例:** 5789 5790```ts 5791import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 5792import { BusinessError } from '@kit.BasicServicesKit'; 5793 5794let dmInstance: distributedDeviceManager.DeviceManager; 5795let deviceIds: Array<string> = []; 5796 5797try { 5798 dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); 5799 let devices: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 5800 for (let i = 0; i < devices.length; i++) { 5801 deviceIds[i] = devices[i].networkId!; 5802 } 5803} catch (err) { 5804 let code = (err as BusinessError).code; 5805 let message = (err as BusinessError).message 5806 console.error("createDeviceManager errCode:" + code + ",errMessage:" + message); 5807} 5808 5809let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); 5810predicates.inDevices(deviceIds); 5811if(store != undefined) { 5812 (store as relationalStore.RdbStore).sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates).then((result: Object[][]) => { 5813 console.info('Sync done.'); 5814 for (let i = 0; i < result.length; i++) { 5815 console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); 5816 } 5817 }).catch((err: BusinessError) => { 5818 console.error(`Sync failed, code is ${err.code},message is ${err.message}`); 5819 }) 5820} 5821``` 5822 5823### cloudSync<sup>10+</sup> 5824 5825cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 5826 5827手动执行对所有分布式表的端云同步,使用callback异步回调。使用该接口需要实现云服务功能。 5828 5829**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 5830 5831**参数:** 5832 5833| 参数名 | 类型 | 必填 | 说明 | 5834| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 5835| mode | [SyncMode](#syncmode) | 是 | 表示数据库的同步模式。 | 5836| progress | Callback<[ProgressDetails](#progressdetails10)> | 是 | 用来处理数据库同步详细信息的回调函数。 | 5837| callback | AsyncCallback<void> | 是 | 指定的callback回调函数,用于向调用者发送同步结果。 | 5838 5839**错误码:** 5840 5841以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5842 5843| **错误码ID** | **错误信息** | 5844|-----------|-------| 5845| 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. | 5846| 801 | Capability not supported. | 5847| 14800014 | Already closed. | 5848 5849**示例:** 5850 5851```ts 5852if(store != undefined) { 5853 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetails) => { 5854 console.info(`Progess: ${progressDetails}`); 5855 }, (err) => { 5856 if (err) { 5857 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 5858 return; 5859 } 5860 console.info('Cloud sync succeeded'); 5861 }); 5862} 5863``` 5864 5865### cloudSync<sup>10+</sup> 5866 5867cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>): Promise<void> 5868 5869手动执行对所有分布式表的端云同步,使用Promise异步回调。使用该接口需要实现云服务功能。 5870 5871**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 5872 5873**参数:** 5874 5875| 参数名 | 类型 | 必填 | 说明 | 5876| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 5877| mode | [SyncMode](#syncmode) | 是 | 表示数据库的同步模式。 | 5878| progress | Callback<[ProgressDetails](#progressdetails10)> | 是 | 用来处理数据库同步详细信息的回调函数。 | 5879 5880**返回值**: 5881 5882| 类型 | 说明 | 5883| ------------------- | --------------------------------------- | 5884| Promise<void> | Promise对象,用于向调用者发送同步结果。 | 5885 5886**错误码:** 5887 5888以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5889 5890| **错误码ID** | **错误信息** | 5891|-----------|------------------| 5892| 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. | 5893| 801 | Capability not supported. | 5894| 14800014 | Already closed. | 5895 5896**示例:** 5897 5898```ts 5899import { BusinessError } from '@kit.BasicServicesKit'; 5900 5901if(store != undefined) { 5902 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, (progressDetail: relationalStore.ProgressDetails) => { 5903 console.info(`progress: ${progressDetail}`); 5904 }).then(() => { 5905 console.info('Cloud sync succeeded'); 5906 }).catch((err: BusinessError) => { 5907 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 5908 }); 5909} 5910``` 5911 5912### cloudSync<sup>10+</sup> 5913 5914cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 5915 5916手动执行对指定表的端云同步,使用callback异步回调。使用该接口需要实现云服务功能。 5917 5918**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 5919 5920**参数:** 5921 5922| 参数名 | 类型 | 必填 | 说明 | 5923| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 5924| mode | [SyncMode](#syncmode) | 是 | 表示数据库的同步模式。 | 5925| tables | string[] | 是 | 指定同步的表名。 | 5926| progress | Callback<[ProgressDetails](#progressdetails10)> | 是 | 用来处理数据库同步详细信息的回调函数。 | 5927| callback | AsyncCallback<void> | 是 | 指定的callback回调函数,用于向调用者发送同步结果。 | 5928 5929**错误码:** 5930 5931以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5932 5933| **错误码ID** | **错误信息** | 5934|-----------|-------| 5935| 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.| 5936| 801 | Capability not supported. | 5937| 14800014 | Already closed. | 5938 5939**示例:** 5940 5941```ts 5942const tables = ["table1", "table2"]; 5943 5944if(store != undefined) { 5945 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => { 5946 console.info(`Progess: ${progressDetail}`); 5947 }, (err) => { 5948 if (err) { 5949 console.error(`Cloud sync failed, code is ${err.code},message is ${err.message}`); 5950 return; 5951 } 5952 console.info('Cloud sync succeeded'); 5953 }); 5954}; 5955``` 5956 5957### cloudSync<sup>10+</sup> 5958 5959cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetails>): Promise<void> 5960 5961手动执行对指定表的端云同步,使用Promise异步回调。使用该接口需要实现云服务功能。 5962 5963**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 5964 5965**参数:** 5966 5967| 参数名 | 类型 | 必填 | 说明 | 5968| -------- | ----------------------------------------------------- | ---- | -------------------------------------- | 5969| mode | [SyncMode](#syncmode) | 是 | 表示数据库的同步模式。 | 5970| tables | string[] | 是 | 指定同步的表名。 | 5971| progress | Callback<[ProgressDetails](#progressdetails10)> | 是 | 用来处理数据库同步详细信息的回调函数。 | 5972 5973**返回值**: 5974 5975| 类型 | 说明 | 5976| ------------------- | --------------------------------------- | 5977| Promise<void> | Promise对象,用于向调用者发送同步结果。 | 5978 5979**错误码:** 5980 5981以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 5982 5983| **错误码ID** | **错误信息** | 5984|-----------|---------------| 5985| 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 | 5986| 801 | Capability not supported. | 5987| 14800014 | Already closed. | 5988 5989**示例:** 5990 5991```ts 5992import { BusinessError } from '@kit.BasicServicesKit'; 5993 5994const tables = ["table1", "table2"]; 5995 5996if(store != undefined) { 5997 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, tables, (progressDetail: relationalStore.ProgressDetails) => { 5998 console.info(`progress: ${progressDetail}`); 5999 }).then(() => { 6000 console.info('Cloud sync succeeded'); 6001 }).catch((err: BusinessError) => { 6002 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}`); 6003 }); 6004}; 6005``` 6006 6007### on('dataChange') 6008 6009on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 6010 6011注册数据库的数据变更的事件监听。当分布式数据库中的数据发生更改时,将调用回调。 6012 6013**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6014 6015**参数:** 6016 6017| 参数名 | 类型 | 必填 | 说明 | 6018| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6019| event | string | 是 | 取值为'dataChange',表示数据更改。 | 6020| type | [SubscribeType](#subscribetype) | 是 | 订阅类型。 | 6021| observer | Callback<Array<string>> | 是 | 指分布式数据库中数据更改事件的观察者。Array<string>为数据库中的数据发生改变的对端设备ID。 | 6022 6023**错误码:** 6024 6025以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 6026 6027| **错误码ID** | **错误信息** | 6028|-----------|-------------| 6029| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6030| 801 | Capability not supported. | 6031| 14800014 | Already closed. | 6032 6033**示例:** 6034 6035```ts 6036import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6037import { BusinessError } from '@kit.BasicServicesKit'; 6038 6039let storeObserver = (devices: Array<string>) => { 6040 if (devices != undefined) { 6041 for (let i = 0; i < devices.length; i++) { 6042 console.info(`device= ${devices[i]} data changed`); 6043 } 6044 } 6045} 6046 6047try { 6048 if (store != undefined) { 6049 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) 6050 } 6051} catch (err) { 6052 let code = (err as BusinessError).code; 6053 let message = (err as BusinessError).message 6054 console.error(`Register observer failed, code is ${code},message is ${message}`); 6055} 6056``` 6057 6058### on('dataChange')<sup>10+</sup> 6059 6060on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 6061 6062注册数据库的数据变更的事件监听。当分布式数据库或本地数据库中的数据发生更改时,将调用回调。 6063 6064**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6065 6066**参数:** 6067 6068| 参数名 | 类型 | 必填 | 说明 | 6069| -------- | ----------------------------------- | ---- | ------------------------------------------- | 6070| event | string | 是 | 取值为'dataChange',表示数据更改。 | 6071| type | [SubscribeType](#subscribetype) | 是 | 订阅类型。 | 6072| observer | Callback<Array<string>> \| Callback<Array<[ChangeInfo](#changeinfo10)>> | 是 | 回调函数。<br>当type为SUBSCRIBE_TYPE_REMOTE,observer类型需为Callback<Array<string>>,其中Array<string>为数据库中的数据发生改变的对端设备ID。<br> 当type为SUBSCRIBE_TYPE_CLOUD,observer类型需为Callback<Array<string>>,其中Array<string>为数据库中的数据发生改变的云端账号。 <br> 当type为SUBSCRIBE_TYPE_CLOUD_DETAILS,observer类型需为Callback<Array<ChangeInfo>>,其中Array<ChangeInfo>为数据库端云同步过程的详情。<br>当type为SUBSCRIBE_TYPE_LOCAL_DETAILS,observer类型需为Callback<Array<ChangeInfo>>,其中Array<ChangeInfo>为本地数据库中的数据更改的详情。 | 6073 6074**错误码:** 6075 6076以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 6077 6078| **错误码ID** | **错误信息** | 6079|-----------|-------------| 6080| 202 | Permission verification failed, application which is not a system application uses system API. | 6081| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6082| 801 | Capability not supported. | 6083| 14800014 | Already closed. | 6084 6085**示例1:type为SUBSCRIBE_TYPE_REMOTE** 6086 6087```ts 6088import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6089import { BusinessError } from '@kit.BasicServicesKit'; 6090 6091let storeObserver = (devices: Array<string>) => { 6092 if (devices != undefined) { 6093 for (let i = 0; i < devices.length; i++) { 6094 console.info(`device= ${devices[i]} data changed`); 6095 } 6096 } 6097} 6098 6099try { 6100 if(store != undefined) { 6101 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6102 } 6103} catch (err) { 6104 let code = (err as BusinessError).code; 6105 let message = (err as BusinessError).message; 6106 console.error(`Register observer failed, code is ${code},message is ${message}`); 6107} 6108``` 6109 6110**示例2:type为SUBSCRIBE_TYPE_LOCAL_DETAILS** 6111 6112```ts 6113import { BusinessError } from '@kit.BasicServicesKit'; 6114 6115let changeInfos = (changeInfos: Array<relationalStore.ChangeInfo>) => { 6116 for (let i = 0; i < changeInfos.length; i++) { 6117 console.info(`changeInfos = ${changeInfos[i]}`); 6118 } 6119} 6120 6121try { 6122 if(store != undefined) { 6123 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_LOCAL_DETAILS, changeInfos); 6124 } 6125} catch (err) { 6126 let code = (err as BusinessError).code; 6127 let message = (err as BusinessError).message; 6128 console.error(`on dataChange fail, code is ${code},message is ${message}`); 6129} 6130 6131let value1 = "Lisa"; 6132let value2 = 18; 6133let value3 = 100.5; 6134let value4 = new Uint8Array([1, 2, 3]); 6135 6136try { 6137 const valueBucket: relationalStore.ValuesBucket = { 6138 'name': value1, 6139 'age': value2, 6140 'salary': value3, 6141 'blobType': value4, 6142 }; 6143 6144 if(store != undefined) { 6145 (store as relationalStore.RdbStore).insert('test', valueBucket); 6146 } 6147} catch (err) { 6148 let code = (err as BusinessError).code; 6149 let message = (err as BusinessError).message; 6150 console.error(`insert fail, code is ${code},message is ${message}`); 6151} 6152``` 6153 6154### on<sup>10+</sup> 6155 6156on(event: string, interProcess: boolean, observer: Callback\<void>): void 6157 6158注册数据库的进程内或者进程间事件监听。当调用[emit](#emit10)接口时,将调用回调。 6159 6160**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6161 6162**参数:** 6163 6164| 参数名 | 类型 | 必填 | 说明 | 6165| ------------ | --------------- | ---- | ------------------------------------------------------------ | 6166| event | string | 是 | 订阅事件名称。 | 6167| interProcess | boolean | 是 | 指定是进程间还是本进程订阅。<br/> true:进程间。<br/> false:本进程。 | 6168| observer | Callback\<void> | 是 | 回调函数。 | 6169 6170**错误码:** 6171 6172以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 6173 6174| **错误码ID** | **错误信息** | 6175|-----------|-------------| 6176| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6177| 801 | Capability not supported. | 6178| 14800000 | Inner error. | 6179| 14800014 | Already closed. | 6180| 14800050 | Failed to obtain subscription service. | 6181 6182**示例:** 6183 6184```ts 6185import { BusinessError } from '@kit.BasicServicesKit'; 6186 6187let storeObserver = () => { 6188 console.info(`storeObserver`); 6189} 6190 6191try { 6192 if(store != undefined) { 6193 (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver); 6194 } 6195} catch (err) { 6196 let code = (err as BusinessError).code; 6197 let message = (err as BusinessError).message 6198 console.error(`Register observer failed, code is ${code},message is ${message}`); 6199} 6200``` 6201 6202### on('autoSyncProgress')<sup>11+</sup> 6203 6204on(event: 'autoSyncProgress', progress: Callback<ProgressDetails>): void 6205 6206在已打开端云同步,并且网络状态正常的条件下,注册自动同步进度通知,自动同步进行时调用回调。 6207 6208**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6209 6210**参数:** 6211 6212| 参数名 | 类型 | 必填 | 说明 | 6213| ------------ |---------------------------------| ---- |-----------------------------------| 6214| event | string | 是 | 取值为'autoSyncProgress',表示自动同步进度通知。 | 6215| progress | Callback<[ProgressDetails](#progressdetails10)> | 是 | 回调函数。 | 6216 6217**错误码:** 6218 6219以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 6220 6221| **错误码ID** | **错误信息** | 6222|-----------|--------| 6223| 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. | 6224| 801 | Capability not supported. | 6225| 14800014 | Already closed. | 6226 6227**示例:** 6228 6229```ts 6230import { BusinessError } from '@kit.BasicServicesKit'; 6231 6232let progressDetail = (progressDetail: relationalStore.ProgressDetails) => { 6233 console.info(`progress: ${progressDetail}`); 6234} 6235 6236try { 6237 if(store != undefined) { 6238 (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail) 6239 } 6240} catch (err) { 6241 let code = (err as BusinessError).code; 6242 let message = (err as BusinessError).message 6243 console.error(`Register observer failed, code is ${code},message is ${message}`); 6244} 6245``` 6246 6247### on('statistics')<sup>12+</sup> 6248 6249on(event: 'statistics', observer: Callback<SqlExecutionInfo>): void 6250 6251订阅SQL统计信息。 6252 6253**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6254 6255**参数:** 6256 6257| 参数名 | 类型 | 必填 | 说明 | 6258| ------------ |---------------------------------| ---- |-----------------------------------| 6259| event | string | 是 | 订阅事件名称,取值为'statistics',表示sql执行时间的统计。 | 6260| observer | Callback<[SqlExecutionInfo](#sqlexecutioninfo12)> | 是 | 回调函数。用于返回数据库中SQL执行时间的统计信息。 | 6261 6262**错误码:** 6263 6264以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 6265 6266| **错误码ID** | **错误信息** | 6267|-----------|--------| 6268| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 6269| 801 | Capability not supported. | 6270| 14800000 | Inner error. | 6271| 14800014 | Already closed. | 6272 6273**示例:** 6274 6275```ts 6276import { BusinessError } from '@kit.BasicServicesKit'; 6277 6278let sqlExecutionInfo = (sqlExecutionInfo: relationalStore.SqlExecutionInfo) => { 6279 console.info(`sql: ${sqlExecutionInfo.sql[0]}`); 6280 console.info(`totalTime: ${sqlExecutionInfo.totalTime}`); 6281 console.info(`waitTime: ${sqlExecutionInfo.waitTime}`); 6282 console.info(`prepareTime: ${sqlExecutionInfo.prepareTime}`); 6283 console.info(`executeTime: ${sqlExecutionInfo.executeTime}`); 6284} 6285 6286try { 6287 if(store != undefined) { 6288 (store as relationalStore.RdbStore).on('statistics', sqlExecutionInfo); 6289 } 6290} catch (err) { 6291 let code = (err as BusinessError).code; 6292 let message = (err as BusinessError).message; 6293 console.error(`Register observer failed, code is ${code},message is ${message}`); 6294} 6295 6296try { 6297 let value1 = "Lisa"; 6298 let value2 = 18; 6299 let value3 = 100.5; 6300 let value4 = new Uint8Array([1, 2, 3, 4, 5]); 6301 6302 const valueBucket: relationalStore.ValuesBucket = { 6303 'NAME': value1, 6304 'AGE': value2, 6305 'SALARY': value3, 6306 'CODES': value4, 6307 }; 6308 if(store != undefined) { 6309 (store as relationalStore.RdbStore).insert('test', valueBucket); 6310 } 6311} catch (err) { 6312 console.error(`insert fail, code:${err.code}, message: ${err.message}`); 6313} 6314``` 6315 6316### off('dataChange') 6317 6318off(event:'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void 6319 6320取消数据变更的事件监听。 6321 6322**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6323 6324**参数:** 6325 6326| 参数名 | 类型 | 必填 | 说明 | 6327| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6328| event | string | 是 | 取值为'dataChange',表示数据更改。 | 6329| type | [SubscribeType](#subscribetype) | 是 | 订阅类型。 | 6330| observer | Callback<Array<string>> | 是 | 指已注册的数据更改观察者。Array<string>为数据库中的数据发生改变的对端设备ID。 | 6331 6332**错误码:** 6333 6334以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 6335 6336| **错误码ID** | **错误信息** | 6337|-----------|-------------| 6338| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6339| 801 | Capability not supported. | 6340| 14800014 | Already closed. | 6341 6342**示例:** 6343 6344```ts 6345import { BusinessError } from '@kit.BasicServicesKit'; 6346 6347let storeObserver = (devices: Array<string>) => { 6348 if (devices != undefined) { 6349 for (let i = 0; i < devices.length; i++) { 6350 console.info(`device= ${devices[i]} data changed`); 6351 } 6352 } 6353} 6354 6355try { 6356 if (store != undefined) { 6357 // 此处不能使用Lambda表达式 6358 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) 6359 } 6360} catch (err) { 6361 let code = (err as BusinessError).code; 6362 let message = (err as BusinessError).message 6363 console.error(`Register observer failed, code is ${code},message is ${message}`); 6364} 6365 6366try { 6367 if(store != undefined) { 6368 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6369 } 6370} catch (err) { 6371 let code = (err as BusinessError).code; 6372 let message = (err as BusinessError).message 6373 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6374} 6375``` 6376 6377### off('dataChange')<sup>10+</sup> 6378 6379off(event:'dataChange', type: SubscribeType, observer?: Callback<Array<string>>\| Callback<Array<ChangeInfo>>): void 6380 6381取消数据变更的事件监听。 6382 6383**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6384 6385**参数:** 6386 6387| 参数名 | 类型 | 必填 | 说明 | 6388| -------- | ---------------------------------- | ---- | ------------------------------------------ | 6389| event | string | 是 | 取值为'dataChange',表示数据更改。 | 6390| type | [SubscribeType](#subscribetype) | 是 | 订阅类型。 | 6391| observer | Callback<Array<string>>\| Callback<Array<[ChangeInfo](#changeinfo10)>> | 否 | 回调函数。<br/>当type为SUBSCRIBE_TYPE_REMOTE,observer类型需为Callback<Array<string>>,其中Array<string>为数据库中的数据发生改变的对端设备ID。<br/> 当type为SUBSCRIBE_TYPE_CLOUD,observer类型需为Callback<Array<string>>,其中Array<string>为数据库中的数据发生改变的云端账号。 <br/> 当type为SUBSCRIBE_TYPE_CLOUD_DETAILS,observer类型需为Callback<Array<ChangeInfo>>,其中Array<ChangeInfo>为数据库端云同步过程的详情。<br>当type为SUBSCRIBE_TYPE_LOCAL_DETAILS,observer类型需为Callback<Array<ChangeInfo>>,其中Array<ChangeInfo>为本地数据库中的数据更改的详情。<br> 当observer没有传入时,表示取消当前type类型下所有数据变更的事件监听。 | 6392 6393**错误码:** 6394 6395以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 6396 6397| **错误码ID** | **错误信息** | 6398|-----------|-------------| 6399| 202 | Permission verification failed, application which is not a system application uses system API. | 6400| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6401| 801 | Capability not supported. | 6402| 14800014 | Already closed. | 6403 6404**示例:** 6405 6406```ts 6407import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 6408import { BusinessError } from '@kit.BasicServicesKit'; 6409 6410let storeObserver = (devices: Array<string>) => { 6411 if (devices != undefined) { 6412 for (let i = 0; i < devices.length; i++) { 6413 console.info(`device= ${devices[i]} data changed`); 6414 } 6415 } 6416} 6417 6418try { 6419 if(store != undefined) { 6420 (store as relationalStore.RdbStore).on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6421 } 6422} catch (err) { 6423 let code = (err as BusinessError).code; 6424 let message = (err as BusinessError).message; 6425 console.error(`Register observer failed, code is ${code},message is ${message}`); 6426} 6427 6428try { 6429 if(store != undefined) { 6430 (store as relationalStore.RdbStore).off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver); 6431 } 6432} catch (err) { 6433 let code = (err as BusinessError).code; 6434 let message = (err as BusinessError).message 6435 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6436} 6437``` 6438 6439### off<sup>10+</sup> 6440 6441off(event: string, interProcess: boolean, observer?: Callback\<void>): void 6442 6443取消数据变更的事件监听。 6444 6445**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6446 6447**参数:** 6448 6449| 参数名 | 类型 | 必填 | 说明 | 6450| ------------ | --------------- | ---- | ------------------------------------------------------------ | 6451| event | string | 是 | 取消订阅事件名称。 | 6452| interProcess | boolean | 是 | 指定是进程间还是本进程取消订阅。<br/> true:进程间。<br/> false:本进程。 | 6453| observer | Callback\<void> | 否 | 该参数存在,则取消指定Callback监听回调,否则取消该event事件的所有监听回调。 | 6454 6455**错误码:** 6456 6457以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 6458 6459| **错误码ID** | **错误信息** | 6460| ------------ | -------------------------------------- | 6461| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6462| 801 | Capability not supported. | 6463| 14800000 | Inner error. | 6464| 14800014 | Already closed. | 6465| 14800050 | Failed to obtain subscription service. | 6466 6467**示例:** 6468 6469```ts 6470import { BusinessError } from '@kit.BasicServicesKit'; 6471 6472let storeObserver = () => { 6473 console.info(`storeObserver`); 6474} 6475 6476try { 6477 if(store != undefined) { 6478 (store as relationalStore.RdbStore).on('storeObserver', false, storeObserver); 6479 } 6480} catch (err) { 6481 let code = (err as BusinessError).code; 6482 let message = (err as BusinessError).message 6483 console.error(`Register observer failed, code is ${code},message is ${message}`); 6484} 6485 6486try { 6487 if(store != undefined) { 6488 (store as relationalStore.RdbStore).off('storeObserver', false, storeObserver); 6489 } 6490} catch (err) { 6491 let code = (err as BusinessError).code; 6492 let message = (err as BusinessError).message 6493 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6494} 6495``` 6496 6497### off('autoSyncProgress')<sup>11+</sup> 6498 6499off(event: 'autoSyncProgress', progress?: Callback<ProgressDetails>): void 6500 6501取消订阅自动同步进度的通知。 6502 6503**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6504 6505**参数:** 6506 6507| 参数名 | 类型 | 必填 | 说明 | 6508| ------------ |---------------------------------| ---- |------------------------------------------------------------------| 6509| event | string | 是 | 取值为'autoSyncProgress',表示自动同步进度通知。 | 6510| progress | Callback<[ProgressDetails](#progressdetails10)> | 否 | 指已注册的自动同步进度观察者。该参数存在,则取消订阅指定回调,该参数为null或undefined或不存在,则取消订阅所有回调。 | 6511 6512**错误码:** 6513 6514以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 6515 6516| **错误码ID** | **错误信息** | 6517| ------------ |--------------------| 6518| 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. | 6519| 801 | Capability not supported. | 6520| 14800014 | Already closed. | 6521 6522**示例:** 6523 6524```ts 6525import { BusinessError } from '@kit.BasicServicesKit'; 6526 6527let progressDetail = (progressDetail: relationalStore.ProgressDetails) => { 6528 console.info(`progress: ${progressDetail}`); 6529} 6530 6531try { 6532 if(store != undefined) { 6533 (store as relationalStore.RdbStore).on('autoSyncProgress', progressDetail) 6534 } 6535} catch (err) { 6536 let code = (err as BusinessError).code; 6537 let message = (err as BusinessError).message 6538 console.error(`Register observer failed, code is ${code},message is ${message}`); 6539} 6540 6541try { 6542 if(store != undefined) { 6543 (store as relationalStore.RdbStore).off('autoSyncProgress', progressDetail); 6544 } 6545} catch (err) { 6546 let code = (err as BusinessError).code; 6547 let message = (err as BusinessError).message; 6548 console.error(`Unregister failed, code is ${code},message is ${message}`); 6549} 6550``` 6551 6552### off('statistics')<sup>12+</sup> 6553 6554off(event: 'statistics', observer?: Callback<SqlExecutionInfo>): void 6555 6556取消订阅SQL统计信息。 6557 6558**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6559 6560**参数:** 6561 6562| 参数名 | 类型 | 必填 | 说明 | 6563| ------------ |---------------------------------| ---- |-----------------------------------| 6564| event | string | 是 | 取消订阅事件名称。取值为'statistics',表示sql执行时间的统计。 | 6565| observer | Callback<[SqlExecutionInfo](#sqlexecutioninfo12)> | 否 | 回调函数。该参数存在,则取消指定Callback监听回调,否则取消该event事件的所有监听回调。 | 6566 6567 6568**错误码:** 6569 6570以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 6571 6572| **错误码ID** | **错误信息** | 6573|-----------|--------| 6574| 401 | Parameter error. | 6575| 801 | Capability not supported. | 6576| 14800000 | Inner error. | 6577| 14800014 | Already closed. | 6578 6579```ts 6580import { BusinessError } from '@kit.BasicServicesKit'; 6581 6582try { 6583 if(store != undefined) { 6584 (store as relationalStore.RdbStore).off('statistics'); 6585 } 6586} catch (err) { 6587 let code = (err as BusinessError).code; 6588 let message = (err as BusinessError).message; 6589 console.error(`Unregister observer failed, code is ${code},message is ${message}`); 6590} 6591``` 6592 6593### emit<sup>10+</sup> 6594 6595emit(event: string): void 6596 6597通知通过[on](#on10)注册的进程间或者进程内监听事件。 6598 6599**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6600 6601**参数:** 6602 6603| 参数名 | 类型 | 必填 | 说明 | 6604| ------ | ------ | ---- | -------------------- | 6605| event | string | 是 | 通知订阅事件的名称。 | 6606 6607**错误码:** 6608 6609以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 6610 6611| **错误码ID** | **错误信息** | 6612| --------- |---------------------------------------------------------------------------------------------------------------| 6613| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6614| 801 | Capability not supported. | 6615| 14800000 | Inner error. | 6616| 14800014 | Already closed. | 6617| 14800050 | Failed to obtain subscription service. | 6618 6619 6620**示例:** 6621 6622```ts 6623if(store != undefined) { 6624 (store as relationalStore.RdbStore).emit('storeObserver'); 6625} 6626``` 6627 6628### cleanDirtyData<sup>11+</sup> 6629 6630cleanDirtyData(table: string, cursor: number, callback: AsyncCallback<void>): void 6631 6632清理云端删除的数据同步到本地后,未自动清理的,且数据的游标(cursor)小于指定游标的数据。 6633 6634**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 6635 6636**参数:** 6637 6638| 参数名 | 类型 | 必填 | 说明 | 6639| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6640| table | string | 是 | 表示当前数据库的表的名称。 | 6641| cursor | number | 是 | 整数类型,表示数据游标,小于此游标的脏数据将被清理。 | 6642| callback | AsyncCallback<void> | 是 | 指定的callback回调函数。 | 6643 6644**错误码:** 6645 6646以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 6647 6648| **错误码ID** | **错误信息** | 6649|-----------|---------------| 6650| 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. | 6651| 801 | Capability not supported. | 6652| 14800000 | Inner error. | 6653| 14800011 | Database corrupted. | 6654| 14800014 | Already closed. | 6655| 14800015 | The database does not respond. | 6656| 14800021 | SQLite: Generic error. | 6657| 14800022 | SQLite: Callback routine requested an abort. | 6658| 14800023 | SQLite: Access permission denied. | 6659| 14800024 | SQLite: The database file is locked. | 6660| 14800025 | SQLite: A table in the database is locked. | 6661| 14800026 | SQLite: The database is out of memory. | 6662| 14800027 | SQLite: Attempt to write a readonly database. | 6663| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6664| 14800029 | SQLite: The database is full. | 6665| 14800030 | SQLite: Unable to open the database file. | 6666| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6667| 14800032 | SQLite: Abort due to constraint violation. | 6668| 14800033 | SQLite: Data type mismatch. | 6669| 14800034 | SQLite: Library used incorrectly. | 6670 6671**示例:** 6672 6673```ts 6674if(store != undefined) { 6675 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100, (err) => { 6676 if (err) { 6677 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 6678 return; 6679 } 6680 console.info('clean dirty data succeeded'); 6681 }) 6682} 6683``` 6684 6685### cleanDirtyData<sup>11+</sup> 6686 6687cleanDirtyData(table: string, callback: AsyncCallback<void>): void 6688 6689清理云端删除的数据同步到本地后,未自动清理的所有数据。 6690 6691**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 6692 6693**参数:** 6694 6695| 参数名 | 类型 | 必填 | 说明 | 6696| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6697| table | string | 是 | 表示当前数据库的表的名称。 | 6698| callback | AsyncCallback<void> | 是 | 指定的callback回调函数。 | 6699 6700**错误码:** 6701 6702以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 6703 6704| **错误码ID** | **错误信息** | 6705|-----------|---------| 6706| 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. | 6707| 801 | Capability not supported. | 6708| 14800000 | Inner error. | 6709| 14800011 | Database corrupted. | 6710| 14800014 | Already closed. | 6711| 14800015 | The database does not respond. | 6712| 14800021 | SQLite: Generic error. | 6713| 14800022 | SQLite: Callback routine requested an abort. | 6714| 14800023 | SQLite: Access permission denied. | 6715| 14800024 | SQLite: The database file is locked. | 6716| 14800025 | SQLite: A table in the database is locked. | 6717| 14800026 | SQLite: The database is out of memory. | 6718| 14800027 | SQLite: Attempt to write a readonly database. | 6719| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6720| 14800029 | SQLite: The database is full. | 6721| 14800030 | SQLite: Unable to open the database file. | 6722| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6723| 14800032 | SQLite: Abort due to constraint violation. | 6724| 14800033 | SQLite: Data type mismatch. | 6725| 14800034 | SQLite: Library used incorrectly. | 6726 6727**示例:** 6728 6729```ts 6730if(store != undefined) { 6731 (store as relationalStore.RdbStore).cleanDirtyData('test_table', (err) => { 6732 if (err) { 6733 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 6734 return; 6735 } 6736 console.info('clean dirty data succeeded'); 6737 }) 6738} 6739``` 6740 6741### cleanDirtyData<sup>11+</sup> 6742 6743cleanDirtyData(table: string, cursor?: number): Promise<void> 6744 6745清理云端删除的数据同步到本地后,未自动清理的,且数据的游标(cursor)小于指定游标的数据。若无cursor参数,将全部清理。 6746 6747**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 6748 6749**参数:** 6750 6751| 参数名 | 类型 | 必填 | 说明 | 6752| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 6753| table | string | 是 | 表示当前数据库的表的名称。 | 6754| cursor | number | 否 | 整数类型,表示数据游标,小于此游标的脏数据将被清理。当此参数不填时,清理当前表的所有脏数据。 | 6755 6756**返回值:** 6757| 参数名 | 说明 | 6758| -------- | ------------------------------------------------- | 6759| Promise\<void> | 无返回结果的Promise对象。 | 6760 6761**错误码:** 6762 6763以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 6764 6765| **错误码ID** | **错误信息** | 6766|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 6767| 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. | 6768| 801 | Capability not supported. | 6769| 14800000 | Inner error. | 6770| 14800011 | Database corrupted. | 6771| 14800014 | Already closed. | 6772| 14800015 | The database does not respond. | 6773| 14800021 | SQLite: Generic error. | 6774| 14800022 | SQLite: Callback routine requested an abort. | 6775| 14800023 | SQLite: Access permission denied. | 6776| 14800024 | SQLite: The database file is locked. | 6777| 14800025 | SQLite: A table in the database is locked. | 6778| 14800026 | SQLite: The database is out of memory. | 6779| 14800027 | SQLite: Attempt to write a readonly database. | 6780| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6781| 14800029 | SQLite: The database is full. | 6782| 14800030 | SQLite: Unable to open the database file. | 6783| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6784| 14800032 | SQLite: Abort due to constraint violation. | 6785| 14800033 | SQLite: Data type mismatch. | 6786| 14800034 | SQLite: Library used incorrectly. | 6787 6788**示例:** 6789 6790```ts 6791import { BusinessError } from '@kit.BasicServicesKit'; 6792 6793if(store != undefined) { 6794 (store as relationalStore.RdbStore).cleanDirtyData('test_table', 100).then(() => { 6795 console.info('clean dirty data succeeded'); 6796 }).catch ((err: BusinessError) => { 6797 console.error(`clean dirty data failed, code is ${err.code},message is ${err.message}`); 6798 }) 6799} 6800``` 6801 6802### attach<sup>12+</sup> 6803 6804attach(fullPath: string, attachName: string, waitTime?: number) : Promise<number> 6805 6806将一个数据库文件附加到当前数据库中,以便在SQL语句中可以直接访问附加数据库中的数据。 6807 6808数据库文件来自文件,且此API不支持附加加密数据库。调用attach接口后,数据库切换为非WAL模式,性能会存在一定的劣化。 6809 6810attach的时候,数据库会切换为非WAL模式,切换模式需要确保所有的ResultSet都已经Close,所有的写操作已经结束,否则会报错14800015。 6811 6812attach不能并发调用,可能出现未响应情况,报错14800015,需要重试。 6813 6814**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6815 6816**参数:** 6817 6818| 参数名 | 类型 | 必填 | 说明 | 6819| ----------- | ------ | --- | ------------ | 6820| fullPath | string | 是 | 表示要附加的数据库的路径。 | 6821| attachName | string | 是 | 表示附加后的数据库的别名。 | 6822| waitTime | number | 否 | 表示附加数据库文件的等待时长。默认值2s,最小值1s,最大值300s。 | 6823 6824**返回值:** 6825 6826| 类型 | 说明 | 6827| ---------------- | ---------------------------- | 6828| Promise<number> | Promise对象。返回附加数据库的数量。 | 6829 6830**错误码:** 6831 6832以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 6833 6834| **错误码ID** | **错误信息** | 6835|-----------| ------------------------------------------------------------ | 6836| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6837| 801 | Capability not supported. | 6838| 14800000 | Inner error. | 6839| 14800010 | Invalid database path. | 6840| 14800011 | Database corrupted. | 6841| 14800014 | Already closed. | 6842| 14800015 | The database does not respond. | 6843| 14800016 | The database is already attached. | 6844| 14800021 | SQLite: Generic error. | 6845| 14800022 | SQLite: Callback routine requested an abort. | 6846| 14800023 | SQLite: Access permission denied. | 6847| 14800024 | SQLite: The database file is locked. | 6848| 14800025 | SQLite: A table in the database is locked. | 6849| 14800026 | SQLite: The database is out of memory. | 6850| 14800027 | SQLite: Attempt to write a readonly database. | 6851| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6852| 14800029 | SQLite: The database is full. | 6853| 14800030 | SQLite: Unable to open the database file. | 6854| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6855| 14800032 | SQLite: Abort due to constraint violation. | 6856| 14800033 | SQLite: Data type mismatch. | 6857| 14800034 | SQLite: Library used incorrectly. | 6858 6859**示例:** 6860 6861```ts 6862// 非加密数据库附加非加密数据库。 6863import { BusinessError } from '@kit.BasicServicesKit'; 6864 6865if(store != undefined) { 6866 (store as relationalStore.RdbStore).attach("/path/rdbstore1.db", "attachDB").then((number: number) => { 6867 console.info('attach succeeded'); 6868 }).catch ((err: BusinessError) => { 6869 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 6870 }) 6871} 6872``` 6873 6874### attach<sup>12+</sup> 6875 6876attach(context: Context, config: StoreConfig, attachName: string, waitTime?: number) : Promise<number> 6877 6878将一个当前应用的数据库附加到当前数据库中,以便在SQL语句中可以直接访问附加数据库中的数据。 6879 6880此API不支持加密数据库附加非加密数据库的场景。调用attach接口后,数据库切换为非WAL模式,性能会存在一定的劣化。 6881 6882attach的时候,数据库会切换为非WAL模式,切换模式需要确保所有的ResultSet都已经Close,所有的写操作已经结束,否则会报错14800015。 6883 6884attach不能并发调用,可能出现未响应情况,报错14800015,需要重试。 6885 6886**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 6887 6888**参数:** 6889 6890| 参数名 | 类型 | 必填 | 说明 | 6891| ----------- | ------ | --- | ------------ | 6892| 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)。 | 6893| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 | 6894| attachName | string | 是 | 表示附加后的数据库的别名。 | 6895| waitTime | number | 否 | 表示附加数据库文件的等待时长。默认值2s,最小值1s,最大值300s。 | 6896 6897**返回值:** 6898 6899| 类型 | 说明 | 6900| ---------------- | ---------------------------- | 6901| Promise<number> | Promise对象。返回附加数据库的数量。 | 6902 6903**错误码:** 6904 6905以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 6906 6907| **错误码ID** | **错误信息** | 6908|-----------| ------------------------------------------------------------ | 6909| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 6910| 801 | Capability not supported. | 6911| 14800000 | Inner error. | 6912| 14800010 | Invalid database path. | 6913| 14800011 | Database corrupted. | 6914| 14800014 | Already closed. | 6915| 14800015 | The database does not respond. | 6916| 14800016 | The database is already attached. | 6917| 14801001 | Only supported in stage mode. | 6918| 14801002 | The data group id is not valid. | 6919| 14800021 | SQLite: Generic error. | 6920| 14800022 | SQLite: Callback routine requested an abort. | 6921| 14800023 | SQLite: Access permission denied. | 6922| 14800024 | SQLite: The database file is locked. | 6923| 14800025 | SQLite: A table in the database is locked. | 6924| 14800026 | SQLite: The database is out of memory. | 6925| 14800027 | SQLite: Attempt to write a readonly database. | 6926| 14800028 | SQLite: Some kind of disk I/O error occurred. | 6927| 14800029 | SQLite: The database is full. | 6928| 14800030 | SQLite: Unable to open the database file. | 6929| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 6930| 14800032 | SQLite: Abort due to constraint violation. | 6931| 14800033 | SQLite: Data type mismatch. | 6932| 14800034 | SQLite: Library used incorrectly. | 6933 6934**示例1:非加密数据库附加非加密数据库** 6935 6936```ts 6937import { BusinessError } from '@kit.BasicServicesKit'; 6938 6939let attachStore: relationalStore.RdbStore | undefined = undefined; 6940 6941const STORE_CONFIG1: relationalStore.StoreConfig = { 6942 name: "rdbstore1.db", 6943 securityLevel: relationalStore.SecurityLevel.S3, 6944} 6945 6946relationalStore.getRdbStore(this.context, STORE_CONFIG1).then(async (rdbStore: relationalStore.RdbStore) => { 6947 attachStore = rdbStore; 6948 console.info('Get RdbStore successfully.') 6949}).catch((err: BusinessError) => { 6950 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 6951}) 6952 6953if(store != undefined) { 6954 (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG1, "attachDB").then((number: number) => { 6955 console.info(`attach succeeded, number is ${number}`); 6956 }).catch ((err: BusinessError) => { 6957 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 6958 }) 6959} 6960``` 6961 6962**示例2:非加密数据库附加加密数据库** 6963 6964```ts 6965import { BusinessError } from '@kit.BasicServicesKit'; 6966 6967let attachStore: relationalStore.RdbStore | undefined = undefined; 6968 6969 6970const STORE_CONFIG2: relationalStore.StoreConfig = { 6971 name: "rdbstore2.db", 6972 encrypt: true, 6973 securityLevel: relationalStore.SecurityLevel.S3, 6974} 6975 6976relationalStore.getRdbStore(this.context, STORE_CONFIG2).then(async (rdbStore: relationalStore.RdbStore) => { 6977 attachStore = rdbStore; 6978 console.info('Get RdbStore successfully.') 6979}).catch((err: BusinessError) => { 6980 console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); 6981}) 6982 6983if(store != undefined) { 6984 (store as relationalStore.RdbStore).attach(this.context, STORE_CONFIG2, "attachDB2", 10).then((number: number) => { 6985 console.info(`attach succeeded, number is ${number}`); 6986 }).catch ((err: BusinessError) => { 6987 console.error(`attach failed, code is ${err.code},message is ${err.message}`); 6988 }) 6989} 6990``` 6991 6992### detach<sup>12+</sup> 6993 6994detach(attachName: string, waitTime?: number) : Promise<number> 6995 6996将附加的数据库从当前数据库中分离。 6997 6998当所有的附加的数据库被分离后,数据库会重新切换为WAL模式。 6999 7000在detach之前,所有的数据库操作要确保已经结束,所有的ResultSet已经Close。并且不能并发调用,可能出现未响应情况,需要重试。 7001 7002**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7003 7004**参数:** 7005 7006| 参数名 | 类型 | 必填 | 说明 | 7007| ----------- | ------ | --- | ------------ | 7008| attachName | string | 是 | 表示附加后的数据库的别名。 | 7009| waitTime | number | 否 | 表示分离数据库的等待时长。默认值2s,最小值1s,最大值300s。 | 7010 7011**返回值:** 7012 7013| 类型 | 说明 | 7014| ---------------- | ---------------------------- | 7015| Promise<number> | Promise对象。返回分离后剩余附加的数据库的数量。 | 7016 7017**错误码:** 7018 7019以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7020 7021| **错误码ID** | **错误信息** | 7022|-----------|------------------------| 7023| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7024| 14800000 | Inner error. | 7025| 14800011 | Database corrupted. | 7026| 14800014 | Already closed. | 7027| 14800015 | The database does not respond. | 7028| 14800021 | SQLite: Generic error. | 7029| 14800022 | SQLite: Callback routine requested an abort. | 7030| 14800023 | SQLite: Access permission denied. | 7031| 14800024 | SQLite: The database file is locked. | 7032| 14800025 | SQLite: A table in the database is locked. | 7033| 14800026 | SQLite: The database is out of memory. | 7034| 14800027 | SQLite: Attempt to write a readonly database. | 7035| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7036| 14800029 | SQLite: The database is full. | 7037| 14800030 | SQLite: Unable to open the database file. | 7038| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7039| 14800032 | SQLite: Abort due to constraint violation. | 7040| 14800033 | SQLite: Data type mismatch. | 7041| 14800034 | SQLite: Library used incorrectly. | 7042 7043**示例:** 7044 7045```ts 7046import { BusinessError } from '@kit.BasicServicesKit'; 7047 7048if(store != undefined) { 7049 (store as relationalStore.RdbStore).detach("attachDB").then((number: number) => { 7050 console.info(`detach succeeded, number is ${number}`); 7051 }).catch ((err: BusinessError) => { 7052 console.error(`detach failed, code is ${err.code},message is ${err.message}`); 7053 }) 7054} 7055``` 7056 7057### lockRow<sup>12+</sup> 7058 7059lockRow(predicates: RdbPredicates):Promise<void> 7060 7061根据RdbPredicates的指定实例对象从数据库中锁定数据,锁定数据不执行端云同步,使用Promise异步回调。 7062 7063该接口只支持主键为基本类型的表、不支持共享表、无主键表和复合类型主键表。 7064该接口不支持依赖关系表之间的锁传递,如果表存在依赖关系,需要根据依赖关系手动调用该接口。 7065该接口不支持对已删除数据的操作。 7066 7067**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7068 7069**参数:** 7070 7071| 参数名 | 类型 | 必填 | 说明 | 7072| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 7073| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的锁定条件。 | 7074 7075**返回值**: 7076 7077| 类型 | 说明 | 7078| --------------------- | ------------------------------- | 7079| Promise<void> | 无返回结果的Promise对象。 | 7080 7081**错误码:** 7082 7083以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7084 7085| **错误码ID** | **错误信息** | 7086|-----------|----------------------------------------------------------------------------------------------| 7087| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7088| 14800000 | Inner error. | 7089| 14800011 | Database corrupted. | 7090| 14800014 | Already closed. | 7091| 14800015 | The database does not respond. | 7092| 14800018 | No data meets the condition. | 7093| 14800021 | SQLite: Generic error. | 7094| 14800022 | SQLite: Callback routine requested an abort. | 7095| 14800023 | SQLite: Access permission denied. | 7096| 14800024 | SQLite: The database file is locked. | 7097| 14800025 | SQLite: A table in the database is locked. | 7098| 14800026 | SQLite: The database is out of memory. | 7099| 14800027 | SQLite: Attempt to write a readonly database. | 7100| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7101| 14800029 | SQLite: The database is full. | 7102| 14800030 | SQLite: Unable to open the database file. | 7103| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7104| 14800032 | SQLite: Abort due to constraint violation. | 7105| 14800033 | SQLite: Data type mismatch. | 7106| 14800034 | SQLite: Library used incorrectly. | 7107 7108**示例:** 7109 7110```ts 7111import { BusinessError } from '@kit.BasicServicesKit'; 7112 7113let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7114predicates.equalTo("NAME", "Lisa"); 7115if(store != undefined) { 7116 (store as relationalStore.RdbStore).lockRow(predicates).then(() => { 7117 console.info(`Lock success`); 7118 }).catch((err: BusinessError) => { 7119 console.error(`Lock failed, code is ${err.code},message is ${err.message}`); 7120 }) 7121} 7122``` 7123 7124### unlockRow<sup>12+</sup> 7125 7126unlockRow(predicates: RdbPredicates):Promise<void> 7127 7128根据RdbPredicates的指定实例对象从数据库中解锁数据,使用Promise异步回调。 7129 7130该接口只支持主键为基本类型的表、不支持共享表、无主键表和复合类型主键表。 7131该接口不支持依赖关系表之间的锁传递,如果表存在依赖关系,需要根据依赖关系手动调用该接口。 7132该接口不支持对已删除数据的操作。 7133 7134**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7135 7136**参数:** 7137 7138| 参数名 | 类型 | 必填 | 说明 | 7139| ---------- | ------------------------------------ | ---- | ----------------------------------------- | 7140| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的锁定条件。 | 7141 7142**返回值**: 7143 7144| 类型 | 说明 | 7145| --------------------- | ------------------------------- | 7146| Promise<void> | 无返回结果的Promise对象。 | 7147 7148**错误码:** 7149 7150以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7151 7152| **错误码ID** | **错误信息** | 7153|-----------| ------------------------------------------------------------ | 7154| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7155| 14800000 | Inner error. | 7156| 14800011 | Database corrupted. | 7157| 14800014 | Already closed. | 7158| 14800015 | The database does not respond. | 7159| 14800018 | No data meets the condition. | 7160| 14800021 | SQLite: Generic error. | 7161| 14800022 | SQLite: Callback routine requested an abort. | 7162| 14800023 | SQLite: Access permission denied. | 7163| 14800024 | SQLite: The database file is locked. | 7164| 14800025 | SQLite: A table in the database is locked. | 7165| 14800026 | SQLite: The database is out of memory. | 7166| 14800027 | SQLite: Attempt to write a readonly database. | 7167| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7168| 14800029 | SQLite: The database is full. | 7169| 14800030 | SQLite: Unable to open the database file. | 7170| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7171| 14800032 | SQLite: Abort due to constraint violation. | 7172| 14800033 | SQLite: Data type mismatch. | 7173| 14800034 | SQLite: Library used incorrectly. | 7174 7175**示例:** 7176 7177```ts 7178import { BusinessError } from '@kit.BasicServicesKit'; 7179 7180let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7181predicates.equalTo("NAME", "Lisa"); 7182if(store != undefined) { 7183 (store as relationalStore.RdbStore).unlockRow(predicates).then(() => { 7184 console.info(`Unlock success`); 7185 }).catch((err: BusinessError) => { 7186 console.error(`Unlock failed, code is ${err.code},message is ${err.message}`); 7187 }) 7188} 7189``` 7190 7191### queryLockedRow<sup>12+</sup> 7192 7193queryLockedRow(predicates: RdbPredicates, columns?: Array<string>):Promise<ResultSet> 7194 7195根据指定条件查询数据库中锁定的数据,使用Promise异步回调。 7196由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 7197 7198**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7199 7200**参数:** 7201 7202| 参数名 | 类型 | 必填 | 说明 | 7203| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | 7204| predicates | [RdbPredicates](#rdbpredicates) | 是 | RdbPredicates的实例对象指定的查询条件。 | 7205| columns | Array<string> | 否 | 表示要查询的列。如果值为空,则查询应用于所有列。 | 7206 7207**错误码:** 7208 7209以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7210 7211| **错误码ID** | **错误信息** | 7212|-----------| ------------------------------------------------------------ | 7213| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7214| 14800000 | Inner error. | 7215| 14800011 | Database corrupted. | 7216| 14800014 | Already closed. | 7217| 14800015 | The database does not respond. | 7218| 14800021 | SQLite: Generic error. | 7219| 14800022 | SQLite: Callback routine requested an abort. | 7220| 14800023 | SQLite: Access permission denied. | 7221| 14800024 | SQLite: The database file is locked. | 7222| 14800025 | SQLite: A table in the database is locked. | 7223| 14800026 | SQLite: The database is out of memory. | 7224| 14800027 | SQLite: Attempt to write a readonly database. | 7225| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7226| 14800029 | SQLite: The database is full. | 7227| 14800030 | SQLite: Unable to open the database file. | 7228| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7229| 14800032 | SQLite: Abort due to constraint violation. | 7230| 14800033 | SQLite: Data type mismatch. | 7231| 14800034 | SQLite: Library used incorrectly. | 7232 7233**返回值**: 7234 7235| 类型 | 说明 | 7236| ------------------------------------------------------- | -------------------------------------------------- | 7237| Promise<[ResultSet](#resultset)> | Promise对象。如果操作成功,则返回ResultSet对象。 | 7238 7239**示例:** 7240 7241```ts 7242import { BusinessError } from '@kit.BasicServicesKit'; 7243 7244let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7245predicates.equalTo("NAME", "Rose"); 7246if(store != undefined) { 7247 (store as relationalStore.RdbStore).queryLockedRow(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 7248 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 7249 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 7250 while (resultSet.goToNextRow()) { 7251 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 7252 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 7253 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 7254 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 7255 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 7256 } 7257 // 释放数据集的内存,若不释放可能会引起fd泄露与内存泄露 7258 resultSet.close(); 7259 }).catch((err: BusinessError) => { 7260 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 7261 }) 7262} 7263``` 7264### close<sup>12+</sup> 7265 7266close(): Promise<void> 7267 7268关闭数据库,使用Promise异步回调。 7269 7270**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7271 7272**返回值:** 7273 7274| 类型 | 说明 | 7275| ------------------- | ------------- | 7276| Promise<void> | Promise对象。 | 7277 7278**错误码:** 7279 7280以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 7281 7282| **错误码ID** | **错误信息** | 7283| ------------ | ----------------------------------------------- | 7284| 401 | Parameter error. The store must not be nullptr. | 7285| 14800000 | Inner error. | 7286 7287**示例:** 7288 7289```ts 7290import { BusinessError } from '@kit.BasicServicesKit'; 7291 7292if(store != undefined) { 7293 (store as relationalStore.RdbStore).close().then(() => { 7294 console.info(`close succeeded`); 7295 }).catch ((err: BusinessError) => { 7296 console.error(`close failed, code is ${err.code},message is ${err.message}`); 7297 }) 7298} 7299``` 7300 7301## ResultSet 7302 7303提供通过查询数据库生成的数据库结果集的访问方法。结果集是指用户调用关系型数据库查询接口之后返回的结果集合,提供了多种灵活的数据访问方式,以便用户获取各项数据。 7304 7305### 使用说明 7306 7307首先需要获取resultSet对象。 7308 7309**示例:** 7310 7311<!--code_no_check--> 7312```ts 7313let resultSet: relationalStore.ResultSet | undefined = undefined; 7314let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 7315predicates.equalTo("AGE", 18); 7316if(store != undefined) { 7317 (store as relationalStore.RdbStore).query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((result: relationalStore.ResultSet) => { 7318 resultSet = result; 7319 console.info(`resultSet columnNames: ${resultSet.columnNames}`); 7320 console.info(`resultSet columnCount: ${resultSet.columnCount}`); 7321 }); 7322} 7323``` 7324 7325### 属性 7326 7327**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7328 7329| 名称 | 类型 | 必填 | 说明 | 7330| ------------ | ------------------- | ---- | -------------------------------- | 7331| columnNames | Array<string> | 是 | 获取结果集中所有列的名称。 | 7332| columnCount | number | 是 | 获取结果集中的列数。 | 7333| rowCount | number | 是 | 获取结果集中的行数。 | 7334| rowIndex | number | 是 | 获取结果集当前行的索引。 | 7335| isAtFirstRow | boolean | 是 | 检查结果集是否位于第一行。 | 7336| isAtLastRow | boolean | 是 | 检查结果集是否位于最后一行。 | 7337| isEnded | boolean | 是 | 检查结果集是否位于最后一行之后。 | 7338| isStarted | boolean | 是 | 检查指针是否移动过。 | 7339| isClosed | boolean | 是 | 检查当前结果集是否关闭。 | 7340 7341### getColumnIndex 7342 7343getColumnIndex(columnName: string): number 7344 7345根据指定的列名获取列索引。 7346 7347**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7348 7349**参数:** 7350 7351| 参数名 | 类型 | 必填 | 说明 | 7352| ---------- | ------ | ---- | -------------------------- | 7353| columnName | string | 是 | 表示结果集中指定列的名称。 | 7354 7355**返回值:** 7356 7357| 类型 | 说明 | 7358| ------ | ------------------ | 7359| number | 返回指定列的索引。 | 7360 7361**错误码:** 7362 7363以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7364 7365| **错误码ID** | **错误信息** | 7366|-----------| ------------------------------------------------------------ | 7367| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7368| 14800000 | Inner error. | 7369| 14800011 | Database corrupted. | 7370| 14800013 | Column out of bounds. | 7371| 14800014 | Already closed. | 7372| 14800019 | The SQL must be a query statement. | 7373| 14800021 | SQLite: Generic error. | 7374| 14800022 | SQLite: Callback routine requested an abort. | 7375| 14800023 | SQLite: Access permission denied. | 7376| 14800024 | SQLite: The database file is locked. | 7377| 14800025 | SQLite: A table in the database is locked. | 7378| 14800026 | SQLite: The database is out of memory. | 7379| 14800027 | SQLite: Attempt to write a readonly database. | 7380| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7381| 14800029 | SQLite: The database is full. | 7382| 14800030 | SQLite: Unable to open the database file. | 7383| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7384| 14800032 | SQLite: Abort due to constraint violation. | 7385| 14800033 | SQLite: Data type mismatch. | 7386| 14800034 | SQLite: Library used incorrectly. | 7387 7388**示例:** 7389 7390```ts 7391if(resultSet != undefined) { 7392 const id = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("ID")); 7393 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 7394 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 7395 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 7396} 7397``` 7398 7399### getColumnName 7400 7401getColumnName(columnIndex: number): string 7402 7403根据指定的列索引获取列名。 7404 7405**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7406 7407**参数:** 7408 7409| 参数名 | 类型 | 必填 | 说明 | 7410| ----------- | ------ | ---- | -------------------------- | 7411| columnIndex | number | 是 | 表示结果集中指定列的索引。 | 7412 7413**返回值:** 7414 7415| 类型 | 说明 | 7416| ------ | ------------------ | 7417| string | 返回指定列的名称。 | 7418 7419**错误码:** 7420 7421以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7422 7423| **错误码ID** | **错误信息** | 7424|-----------| ------------------------------------------------------------ | 7425| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7426| 14800000 | Inner error. | 7427| 14800011 | Database corrupted. | 7428| 14800013 | Column out of bounds. | 7429| 14800014 | Already closed. | 7430| 14800019 | The SQL must be a query statement. | 7431| 14800021 | SQLite: Generic error. | 7432| 14800022 | SQLite: Callback routine requested an abort. | 7433| 14800023 | SQLite: Access permission denied. | 7434| 14800024 | SQLite: The database file is locked. | 7435| 14800025 | SQLite: A table in the database is locked. | 7436| 14800026 | SQLite: The database is out of memory. | 7437| 14800027 | SQLite: Attempt to write a readonly database. | 7438| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7439| 14800029 | SQLite: The database is full. | 7440| 14800030 | SQLite: Unable to open the database file. | 7441| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7442| 14800032 | SQLite: Abort due to constraint violation. | 7443| 14800033 | SQLite: Data type mismatch. | 7444| 14800034 | SQLite: Library used incorrectly. | 7445 7446**示例:** 7447 7448```ts 7449if(resultSet != undefined) { 7450 const id = (resultSet as relationalStore.ResultSet).getColumnName(0); 7451 const name = (resultSet as relationalStore.ResultSet).getColumnName(1); 7452 const age = (resultSet as relationalStore.ResultSet).getColumnName(2); 7453} 7454``` 7455 7456### goTo 7457 7458goTo(offset:number): boolean 7459 7460向前或向后转至结果集的指定行,相对于其当前位置偏移。 7461 7462**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7463 7464**参数:** 7465 7466| 参数名 | 类型 | 必填 | 说明 | 7467| ------ | ------ | ---- | ---------------------------- | 7468| offset | number | 是 | 表示相对于当前位置的偏移量。 | 7469 7470**返回值:** 7471 7472| 类型 | 说明 | 7473| ------- | --------------------------------------------- | 7474| boolean | 如果成功移动结果集,则为true;否则返回false。 | 7475 7476**错误码:** 7477 7478以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7479 7480| **错误码ID** | **错误信息** | 7481|-----------| ------------------------------------------------------------ | 7482| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7483| 14800000 | Inner error. | 7484| 14800011 | Database corrupted. | 7485| 14800012 | Row out of bounds. | 7486| 14800014 | Already closed. | 7487| 14800019 | The SQL must be a query statement. | 7488| 14800021 | SQLite: Generic error. | 7489| 14800022 | SQLite: Callback routine requested an abort. | 7490| 14800023 | SQLite: Access permission denied. | 7491| 14800024 | SQLite: The database file is locked. | 7492| 14800025 | SQLite: A table in the database is locked. | 7493| 14800026 | SQLite: The database is out of memory. | 7494| 14800027 | SQLite: Attempt to write a readonly database. | 7495| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7496| 14800029 | SQLite: The database is full. | 7497| 14800030 | SQLite: Unable to open the database file. | 7498| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7499| 14800032 | SQLite: Abort due to constraint violation. | 7500| 14800033 | SQLite: Data type mismatch. | 7501| 14800034 | SQLite: Library used incorrectly. | 7502 7503**示例:** 7504 7505```ts 7506if(resultSet != undefined) { 7507 (resultSet as relationalStore.ResultSet).goTo(1); 7508} 7509``` 7510 7511### goToRow 7512 7513goToRow(position: number): boolean 7514 7515转到结果集的指定行。 7516 7517**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7518 7519**参数:** 7520 7521| 参数名 | 类型 | 必填 | 说明 | 7522| -------- | ------ | ---- | ------------------------ | 7523| position | number | 是 | 表示要移动到的指定位置。 | 7524 7525**返回值:** 7526 7527| 类型 | 说明 | 7528| ------- | --------------------------------------------- | 7529| boolean | 如果成功移动结果集,则为true;否则返回false。 | 7530 7531**错误码:** 7532 7533以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7534 7535| **错误码ID** | **错误信息** | 7536|-----------| ------------------------------------------------------------ | 7537| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7538| 14800000 | Inner error. | 7539| 14800011 | Database corrupted. | 7540| 14800012 | Row out of bounds. | 7541| 14800014 | Already closed. | 7542| 14800019 | The SQL must be a query statement. | 7543| 14800021 | SQLite: Generic error. | 7544| 14800022 | SQLite: Callback routine requested an abort. | 7545| 14800023 | SQLite: Access permission denied. | 7546| 14800024 | SQLite: The database file is locked. | 7547| 14800025 | SQLite: A table in the database is locked. | 7548| 14800026 | SQLite: The database is out of memory. | 7549| 14800027 | SQLite: Attempt to write a readonly database. | 7550| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7551| 14800029 | SQLite: The database is full. | 7552| 14800030 | SQLite: Unable to open the database file. | 7553| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7554| 14800032 | SQLite: Abort due to constraint violation. | 7555| 14800033 | SQLite: Data type mismatch. | 7556| 14800034 | SQLite: Library used incorrectly. | 7557 7558**示例:** 7559 7560```ts 7561if(resultSet != undefined) { 7562 (resultSet as relationalStore.ResultSet).goToRow(5); 7563} 7564``` 7565 7566### goToFirstRow 7567 7568goToFirstRow(): boolean 7569 7570 7571转到结果集的第一行。 7572 7573**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7574 7575**返回值:** 7576 7577| 类型 | 说明 | 7578| ------- | --------------------------------------------- | 7579| boolean | 如果成功移动结果集,则为true;否则返回false。 | 7580 7581**错误码:** 7582 7583以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7584 7585| **错误码ID** | **错误信息** | 7586|-----------| ------------------------------------------------------------ | 7587| 14800000 | Inner error. | 7588| 14800011 | Database corrupted. | 7589| 14800012 | Row out of bounds. | 7590| 14800014 | Already closed. | 7591| 14800019 | The SQL must be a query statement. | 7592| 14800021 | SQLite: Generic error. | 7593| 14800022 | SQLite: Callback routine requested an abort. | 7594| 14800023 | SQLite: Access permission denied. | 7595| 14800024 | SQLite: The database file is locked. | 7596| 14800025 | SQLite: A table in the database is locked. | 7597| 14800026 | SQLite: The database is out of memory. | 7598| 14800027 | SQLite: Attempt to write a readonly database. | 7599| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7600| 14800029 | SQLite: The database is full. | 7601| 14800030 | SQLite: Unable to open the database file. | 7602| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7603| 14800032 | SQLite: Abort due to constraint violation. | 7604| 14800033 | SQLite: Data type mismatch. | 7605| 14800034 | SQLite: Library used incorrectly. | 7606 7607**示例:** 7608 7609```ts 7610if(resultSet != undefined) { 7611 (resultSet as relationalStore.ResultSet).goToFirstRow(); 7612} 7613``` 7614 7615### goToLastRow 7616 7617goToLastRow(): boolean 7618 7619转到结果集的最后一行。 7620 7621**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7622 7623**返回值:** 7624 7625| 类型 | 说明 | 7626| ------- | --------------------------------------------- | 7627| boolean | 如果成功移动结果集,则为true;否则返回false。 | 7628 7629**错误码:** 7630 7631以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7632 7633| **错误码ID** | **错误信息** | 7634|-----------| ------------------------------------------------------------ | 7635| 14800000 | Inner error. | 7636| 14800011 | Database corrupted. | 7637| 14800012 | Row out of bounds. | 7638| 14800014 | Already closed. | 7639| 14800019 | The SQL must be a query statement. | 7640| 14800021 | SQLite: Generic error. | 7641| 14800022 | SQLite: Callback routine requested an abort. | 7642| 14800023 | SQLite: Access permission denied. | 7643| 14800024 | SQLite: The database file is locked. | 7644| 14800025 | SQLite: A table in the database is locked. | 7645| 14800026 | SQLite: The database is out of memory. | 7646| 14800027 | SQLite: Attempt to write a readonly database. | 7647| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7648| 14800029 | SQLite: The database is full. | 7649| 14800030 | SQLite: Unable to open the database file. | 7650| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7651| 14800032 | SQLite: Abort due to constraint violation. | 7652| 14800033 | SQLite: Data type mismatch. | 7653| 14800034 | SQLite: Library used incorrectly. | 7654 7655**示例:** 7656 7657```ts 7658if(resultSet != undefined) { 7659 (resultSet as relationalStore.ResultSet).goToLastRow(); 7660} 7661``` 7662 7663### goToNextRow 7664 7665goToNextRow(): boolean 7666 7667转到结果集的下一行。 7668 7669**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7670 7671**返回值:** 7672 7673| 类型 | 说明 | 7674| ------- | --------------------------------------------- | 7675| boolean | 如果成功移动结果集,则为true;否则返回false。 | 7676 7677**错误码:** 7678 7679以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7680 7681| **错误码ID** | **错误信息** | 7682|-----------| ------------------------------------------------------------ | 7683| 14800000 | Inner error. | 7684| 14800011 | Database corrupted. | 7685| 14800012 | Row out of bounds. | 7686| 14800014 | Already closed. | 7687| 14800019 | The SQL must be a query statement. | 7688| 14800021 | SQLite: Generic error. | 7689| 14800022 | SQLite: Callback routine requested an abort. | 7690| 14800023 | SQLite: Access permission denied. | 7691| 14800024 | SQLite: The database file is locked. | 7692| 14800025 | SQLite: A table in the database is locked. | 7693| 14800026 | SQLite: The database is out of memory. | 7694| 14800027 | SQLite: Attempt to write a readonly database. | 7695| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7696| 14800029 | SQLite: The database is full. | 7697| 14800030 | SQLite: Unable to open the database file. | 7698| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7699| 14800032 | SQLite: Abort due to constraint violation. | 7700| 14800033 | SQLite: Data type mismatch. | 7701| 14800034 | SQLite: Library used incorrectly. | 7702 7703**示例:** 7704 7705```ts 7706if(resultSet != undefined) { 7707 (resultSet as relationalStore.ResultSet).goToNextRow(); 7708} 7709``` 7710 7711### goToPreviousRow 7712 7713goToPreviousRow(): boolean 7714 7715转到结果集的上一行。 7716 7717**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7718 7719**返回值:** 7720 7721| 类型 | 说明 | 7722| ------- | --------------------------------------------- | 7723| boolean | 如果成功移动结果集,则为true;否则返回false。 | 7724 7725**错误码:** 7726 7727以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7728 7729| **错误码ID** | **错误信息** | 7730|-----------| ------------------------------------------------------------ | 7731| 14800000 | Inner error. | 7732| 14800011 | Database corrupted. | 7733| 14800012 | Row out of bounds. | 7734| 14800014 | Already closed. | 7735| 14800019 | The SQL must be a query statement. | 7736| 14800021 | SQLite: Generic error. | 7737| 14800022 | SQLite: Callback routine requested an abort. | 7738| 14800023 | SQLite: Access permission denied. | 7739| 14800024 | SQLite: The database file is locked. | 7740| 14800025 | SQLite: A table in the database is locked. | 7741| 14800026 | SQLite: The database is out of memory. | 7742| 14800027 | SQLite: Attempt to write a readonly database. | 7743| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7744| 14800029 | SQLite: The database is full. | 7745| 14800030 | SQLite: Unable to open the database file. | 7746| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7747| 14800032 | SQLite: Abort due to constraint violation. | 7748| 14800033 | SQLite: Data type mismatch. | 7749| 14800034 | SQLite: Library used incorrectly. | 7750 7751**示例:** 7752 7753```ts 7754if(resultSet != undefined) { 7755 (resultSet as relationalStore.ResultSet).goToPreviousRow(); 7756} 7757``` 7758 7759### getValue<sup>12+</sup> 7760 7761getValue(columnIndex: number): ValueType 7762 7763获取当前行中指定列的值,值类型如果是ValueType指定的任意类型,则会以对应类型返回指定类的值,否则返回14800000。 7764 7765**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7766 7767**参数:** 7768 7769| 参数名 | 类型 | 必填 | 说明 | 7770| ----------- | ------ | ---- | ----------------------- | 7771| columnIndex | number | 是 | 指定的列索引,从0开始。 | 7772 7773**返回值:** 7774 7775| 类型 | 说明 | 7776| ---------- | -------------------------------- | 7777| [ValueType](#valuetype) | 表示允许的数据字段类型。 | 7778 7779**错误码:** 7780 7781以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7782 7783| **错误码ID** | **错误信息** | 7784|-----------|---------| 7785| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7786| 14800000 | Inner error. | 7787| 14800011 | Database corrupted. | 7788| 14800012 | Row out of bounds. | 7789| 14800013 | Column out of bounds. | 7790| 14800014 | Already closed. | 7791| 14800021 | SQLite: Generic error. | 7792| 14800022 | SQLite: Callback routine requested an abort. | 7793| 14800023 | SQLite: Access permission denied. | 7794| 14800024 | SQLite: The database file is locked. | 7795| 14800025 | SQLite: A table in the database is locked. | 7796| 14800026 | SQLite: The database is out of memory. | 7797| 14800027 | SQLite: Attempt to write a readonly database. | 7798| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7799| 14800029 | SQLite: The database is full. | 7800| 14800030 | SQLite: Unable to open the database file. | 7801| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7802| 14800032 | SQLite: Abort due to constraint violation. | 7803| 14800033 | SQLite: Data type mismatch. | 7804| 14800034 | SQLite: Library used incorrectly. | 7805 7806**示例:** 7807 7808```ts 7809if(resultSet != undefined) { 7810 const codes = (resultSet as relationalStore.ResultSet).getValue((resultSet as relationalStore.ResultSet).getColumnIndex("BIGINT_COLUMN")); 7811} 7812``` 7813 7814### getBlob 7815 7816getBlob(columnIndex: number): Uint8Array 7817 7818 7819以字节数组的形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成字节数组类型返回指定值,如果该列内容为空时,会返回空字节数组,其他类型则返回14800000。 7820 7821**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7822 7823**参数:** 7824 7825| 参数名 | 类型 | 必填 | 说明 | 7826| ----------- | ------ | ---- | ----------------------- | 7827| columnIndex | number | 是 | 指定的列索引,从0开始。 | 7828 7829**返回值:** 7830 7831| 类型 | 说明 | 7832| ---------- | -------------------------------- | 7833| Uint8Array | 以字节数组的形式返回指定列的值。 | 7834 7835**错误码:** 7836 7837以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7838 7839| **错误码ID** | **错误信息** | 7840|-----------| ------------------------------------------------------------ | 7841| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7842| 14800000 | Inner error. | 7843| 14800011 | Database corrupted. | 7844| 14800012 | Row out of bounds. | 7845| 14800013 | Column out of bounds. | 7846| 14800014 | Already closed. | 7847| 14800021 | SQLite: Generic error. | 7848| 14800022 | SQLite: Callback routine requested an abort. | 7849| 14800023 | SQLite: Access permission denied. | 7850| 14800024 | SQLite: The database file is locked. | 7851| 14800025 | SQLite: A table in the database is locked. | 7852| 14800026 | SQLite: The database is out of memory. | 7853| 14800027 | SQLite: Attempt to write a readonly database. | 7854| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7855| 14800029 | SQLite: The database is full. | 7856| 14800030 | SQLite: Unable to open the database file. | 7857| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7858| 14800032 | SQLite: Abort due to constraint violation. | 7859| 14800033 | SQLite: Data type mismatch. | 7860| 14800034 | SQLite: Library used incorrectly. | 7861 7862**示例:** 7863 7864```ts 7865if(resultSet != undefined) { 7866 const codes = (resultSet as relationalStore.ResultSet).getBlob((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 7867} 7868``` 7869 7870### getString 7871 7872getString(columnIndex: number): string 7873 7874以字符串形式获取当前行中指定列的值,如果当前列中的值为INTEGER、DOUBLE、TEXT、BLOB类型,会以字符串形式返回指定值,如果是当前列中的值为INTEGER,并且为空,则会返回空字符串"",其他类型则返回14800000,。 7875 7876**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7877 7878**参数:** 7879 7880| 参数名 | 类型 | 必填 | 说明 | 7881| ----------- | ------ | ---- | ----------------------- | 7882| columnIndex | number | 是 | 指定的列索引,从0开始。 | 7883 7884**返回值:** 7885 7886| 类型 | 说明 | 7887| ------ | ---------------------------- | 7888| string | 以字符串形式返回指定列的值。 | 7889 7890**错误码:** 7891 7892以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7893 7894| **错误码ID** | **错误信息** | 7895|-----------| ------------------------------------------------------------ | 7896| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7897| 14800000 | Inner error. | 7898| 14800011 | Database corrupted. | 7899| 14800012 | Row out of bounds. | 7900| 14800013 | Column out of bounds. | 7901| 14800014 | Already closed. | 7902| 14800021 | SQLite: Generic error. | 7903| 14800022 | SQLite: Callback routine requested an abort. | 7904| 14800023 | SQLite: Access permission denied. | 7905| 14800024 | SQLite: The database file is locked. | 7906| 14800025 | SQLite: A table in the database is locked. | 7907| 14800026 | SQLite: The database is out of memory. | 7908| 14800027 | SQLite: Attempt to write a readonly database. | 7909| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7910| 14800029 | SQLite: The database is full. | 7911| 14800030 | SQLite: Unable to open the database file. | 7912| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7913| 14800032 | SQLite: Abort due to constraint violation. | 7914| 14800033 | SQLite: Data type mismatch. | 7915| 14800034 | SQLite: Library used incorrectly. | 7916 7917**示例:** 7918 7919```ts 7920if(resultSet != undefined) { 7921 const name = (resultSet as relationalStore.ResultSet).getString((resultSet as relationalStore.ResultSet).getColumnIndex("NAME")); 7922} 7923``` 7924 7925### getLong 7926 7927getLong(columnIndex: number): number 7928 7929以Long形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成Long类型返回指定值,如果该列内容为空时,会返回0,其他类型则返回14800000。 7930 7931**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7932 7933**参数:** 7934 7935| 参数名 | 类型 | 必填 | 说明 | 7936| ----------- | ------ | ---- | ----------------------- | 7937| columnIndex | number | 是 | 指定的列索引,从0开始。 | 7938 7939**返回值:** 7940 7941| 类型 | 说明 | 7942| ------ | ------------------------------------------------------------ | 7943| number | 以Long形式返回指定列的值。<br>该接口支持的数据范围是:Number.MIN_SAFE_INTEGER ~ Number.MAX_SAFE_INTEGER,若超出该范围,建议使用[getDouble](#getdouble)。 | 7944 7945**错误码:** 7946 7947以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 7948 7949| **错误码ID** | **错误信息** | 7950|-----------| ------------------------------------------------------------ | 7951| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7952| 14800000 | Inner error. | 7953| 14800011 | Database corrupted. | 7954| 14800012 | Row out of bounds. | 7955| 14800013 | Column out of bounds. | 7956| 14800014 | Already closed. | 7957| 14800021 | SQLite: Generic error. | 7958| 14800022 | SQLite: Callback routine requested an abort. | 7959| 14800023 | SQLite: Access permission denied. | 7960| 14800024 | SQLite: The database file is locked. | 7961| 14800025 | SQLite: A table in the database is locked. | 7962| 14800026 | SQLite: The database is out of memory. | 7963| 14800027 | SQLite: Attempt to write a readonly database. | 7964| 14800028 | SQLite: Some kind of disk I/O error occurred. | 7965| 14800029 | SQLite: The database is full. | 7966| 14800030 | SQLite: Unable to open the database file. | 7967| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 7968| 14800032 | SQLite: Abort due to constraint violation. | 7969| 14800033 | SQLite: Data type mismatch. | 7970| 14800034 | SQLite: Library used incorrectly. | 7971 7972**示例:** 7973 7974```ts 7975if(resultSet != undefined) { 7976 const age = (resultSet as relationalStore.ResultSet).getLong((resultSet as relationalStore.ResultSet).getColumnIndex("AGE")); 7977 } 7978``` 7979 7980### getDouble 7981 7982getDouble(columnIndex: number): number 7983 7984以double形式获取当前行中指定列的值,如果当前列的数据类型为INTEGER、DOUBLE、TEXT、BLOB类型,会转成double类型返回指定值,如果该列内容为空时,会返回0.0,其他类型则返回14800000。 7985 7986**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 7987 7988**参数:** 7989 7990| 参数名 | 类型 | 必填 | 说明 | 7991| ----------- | ------ | ---- | ----------------------- | 7992| columnIndex | number | 是 | 指定的列索引,从0开始。 | 7993 7994**返回值:** 7995 7996| 类型 | 说明 | 7997| ------ | ---------------------------- | 7998| number | 以double形式返回指定列的值。 | 7999 8000**错误码:** 8001 8002以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 8003 8004| **错误码ID** | **错误信息** | 8005|-----------| ------------------------------------------------------------ | 8006| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8007| 14800000 | Inner error. | 8008| 14800011 | Database corrupted. | 8009| 14800012 | Row out of bounds. | 8010| 14800013 | Column out of bounds. | 8011| 14800014 | Already closed. | 8012| 14800021 | SQLite: Generic error. | 8013| 14800022 | SQLite: Callback routine requested an abort. | 8014| 14800023 | SQLite: Access permission denied. | 8015| 14800024 | SQLite: The database file is locked. | 8016| 14800025 | SQLite: A table in the database is locked. | 8017| 14800026 | SQLite: The database is out of memory. | 8018| 14800027 | SQLite: Attempt to write a readonly database. | 8019| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8020| 14800029 | SQLite: The database is full. | 8021| 14800030 | SQLite: Unable to open the database file. | 8022| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8023| 14800032 | SQLite: Abort due to constraint violation. | 8024| 14800033 | SQLite: Data type mismatch. | 8025| 14800034 | SQLite: Library used incorrectly. | 8026 8027**示例:** 8028 8029```ts 8030if(resultSet != undefined) { 8031 const salary = (resultSet as relationalStore.ResultSet).getDouble((resultSet as relationalStore.ResultSet).getColumnIndex("SALARY")); 8032} 8033``` 8034 8035### getAsset<sup>10+</sup> 8036 8037getAsset(columnIndex: number): Asset 8038 8039以[Asset](#asset10)形式获取当前行中指定列的值,如果当前列的数据类型为Asset类型,会以Asset类型返回指定值,如果当前列中的值为null时,会返回null,其他类型则返回14800000。 8040 8041**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 8042 8043**参数:** 8044 8045| 参数名 | 类型 | 必填 | 说明 | 8046| ----------- | ------ | --- | ------------ | 8047| columnIndex | number | 是 | 指定的列索引,从0开始。 | 8048 8049**返回值:** 8050 8051| 类型 | 说明 | 8052| --------------- | -------------------------- | 8053| [Asset](#asset10) | 以Asset形式返回指定列的值。 | 8054 8055**错误码:** 8056 8057以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 8058 8059| **错误码ID** | **错误信息** | 8060|-----------| ------------------------------------------------------------ | 8061| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8062| 14800000 | Inner error. | 8063| 14800011 | Database corrupted. | 8064| 14800012 | Row out of bounds. | 8065| 14800013 | Column out of bounds. | 8066| 14800014 | Already closed. | 8067| 14800021 | SQLite: Generic error. | 8068| 14800022 | SQLite: Callback routine requested an abort. | 8069| 14800023 | SQLite: Access permission denied. | 8070| 14800024 | SQLite: The database file is locked. | 8071| 14800025 | SQLite: A table in the database is locked. | 8072| 14800026 | SQLite: The database is out of memory. | 8073| 14800027 | SQLite: Attempt to write a readonly database. | 8074| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8075| 14800029 | SQLite: The database is full. | 8076| 14800030 | SQLite: Unable to open the database file. | 8077| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8078| 14800032 | SQLite: Abort due to constraint violation. | 8079| 14800033 | SQLite: Data type mismatch. | 8080| 14800034 | SQLite: Library used incorrectly. | 8081 8082**示例:** 8083 8084```ts 8085if(resultSet != undefined) { 8086 const doc = (resultSet as relationalStore.ResultSet).getAsset((resultSet as relationalStore.ResultSet).getColumnIndex("DOC")); 8087} 8088``` 8089 8090### getAssets<sup>10+</sup> 8091 8092getAssets(columnIndex: number): Assets 8093 8094以[Assets](#assets10)形式获取当前行中指定列的值,如果当前列的数据类型为Assets类型,会以Assets类型返回指定值,如果当前列中的值为null时,会返回null,其他类型则返回14800000。 8095 8096**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 8097 8098**参数:** 8099 8100| 参数名 | 类型 | 必填 | 说明 | 8101| ----------- | ------ | --- | ------------ | 8102| columnIndex | number | 是 | 指定的列索引,从0开始。 | 8103 8104**返回值:** 8105 8106| 类型 | 说明 | 8107| ---------------- | ---------------------------- | 8108| [Assets](#assets10)| 以Assets形式返回指定列的值。 | 8109 8110**错误码:** 8111 8112以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 8113 8114| **错误码ID** | **错误信息** | 8115|-----------| ------------------------------------------------------------ | 8116| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8117| 14800000 | Inner error. | 8118| 14800011 | Database corrupted. | 8119| 14800012 | Row out of bounds. | 8120| 14800013 | Column out of bounds. | 8121| 14800014 | Already closed. | 8122| 14800021 | SQLite: Generic error. | 8123| 14800022 | SQLite: Callback routine requested an abort. | 8124| 14800023 | SQLite: Access permission denied. | 8125| 14800024 | SQLite: The database file is locked. | 8126| 14800025 | SQLite: A table in the database is locked. | 8127| 14800026 | SQLite: The database is out of memory. | 8128| 14800027 | SQLite: Attempt to write a readonly database. | 8129| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8130| 14800029 | SQLite: The database is full. | 8131| 14800030 | SQLite: Unable to open the database file. | 8132| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8133| 14800032 | SQLite: Abort due to constraint violation. | 8134| 14800033 | SQLite: Data type mismatch. | 8135| 14800034 | SQLite: Library used incorrectly. | 8136 8137**示例:** 8138 8139```ts 8140if(resultSet != undefined) { 8141 const docs = (resultSet as relationalStore.ResultSet).getAssets((resultSet as relationalStore.ResultSet).getColumnIndex("DOCS")); 8142} 8143``` 8144 8145### getRow<sup>11+</sup> 8146 8147getRow(): ValuesBucket 8148 8149获取当前行。 8150 8151**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 8152 8153**返回值:** 8154 8155| 类型 | 说明 | 8156| ---------------- | ---------------------------- | 8157| [ValuesBucket](#valuesbucket) | 返回指定行的值。 | 8158 8159**错误码:** 8160 8161以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 8162 8163| **错误码ID** | **错误信息** | 8164|-----------| ------------------------------------------------------------ | 8165| 14800000 | Inner error. | 8166| 14800011 | Database corrupted. | 8167| 14800012 | Row out of bounds. | 8168| 14800013 | Column out of bounds. | 8169| 14800014 | Already closed. | 8170| 14800021 | SQLite: Generic error. | 8171| 14800022 | SQLite: Callback routine requested an abort. | 8172| 14800023 | SQLite: Access permission denied. | 8173| 14800024 | SQLite: The database file is locked. | 8174| 14800025 | SQLite: A table in the database is locked. | 8175| 14800026 | SQLite: The database is out of memory. | 8176| 14800027 | SQLite: Attempt to write a readonly database. | 8177| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8178| 14800029 | SQLite: The database is full. | 8179| 14800030 | SQLite: Unable to open the database file. | 8180| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8181| 14800032 | SQLite: Abort due to constraint violation. | 8182| 14800033 | SQLite: Data type mismatch. | 8183| 14800034 | SQLite: Library used incorrectly. | 8184 8185**示例:** 8186 8187```ts 8188if(resultSet != undefined) { 8189 const row = (resultSet as relationalStore.ResultSet).getRow(); 8190} 8191``` 8192 8193### getSendableRow<sup>12+</sup> 8194 8195getSendableRow(): sendableRelationalStore.ValuesBucket 8196 8197获取当前行数据的sendable形式,用于跨线程传递使用。 8198 8199**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 8200 8201**返回值:** 8202 8203| 类型 | 说明 | 8204| ---------------------------------------------------------------------------------------------- | ---------------------------------------------- | 8205| [sendableRelationalStore.ValuesBucket](./js-apis-data-sendableRelationalStore.md#valuesbucket) | 当前行数据的sendable形式,用于跨线程传递使用。 | 8206 8207**错误码:** 8208 8209以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 8210 8211| **错误码ID** | **错误信息** | 8212| ------------ | --------------------------------------------- | 8213| 14800000 | Inner error. | 8214| 14800011 | Database corrupted. | 8215| 14800012 | Row out of bounds. | 8216| 14800013 | Column out of bounds. | 8217| 14800014 | Already closed. | 8218| 14800021 | SQLite: Generic error. | 8219| 14800022 | SQLite: Callback routine requested an abort. | 8220| 14800023 | SQLite: Access permission denied. | 8221| 14800024 | SQLite: The database file is locked. | 8222| 14800025 | SQLite: A table in the database is locked. | 8223| 14800026 | SQLite: The database is out of memory. | 8224| 14800027 | SQLite: Attempt to write a readonly database. | 8225| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8226| 14800029 | SQLite: The database is full. | 8227| 14800030 | SQLite: Unable to open the database file. | 8228| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8229| 14800032 | SQLite: Abort due to constraint violation. | 8230| 14800033 | SQLite: Data type mismatch. | 8231| 14800034 | SQLite: Library used incorrectly. | 8232 8233**示例:** 8234 8235```ts 8236import { taskpool } from '@kit.ArkTS'; 8237import type ctx from '@ohos.app.ability.common'; 8238import { sendableRelationalStore } from '@kit.ArkData'; 8239 8240@Concurrent 8241async function getDataByName(name: string, context: ctx.UIAbilityContext) { 8242 const STORE_CONFIG: relationalStore.StoreConfig = { 8243 name: "RdbTest.db", 8244 securityLevel: relationalStore.SecurityLevel.S3 8245 }; 8246 const store = await relationalStore.getRdbStore(context, STORE_CONFIG); 8247 const predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 8248 predicates.equalTo("NAME", name); 8249 const resultSet = store.querySync(predicates); 8250 8251 if (resultSet.rowCount > 0) { 8252 resultSet.goToFirstRow(); 8253 const sendableValuesBucket = resultSet.getSendableRow(); 8254 return sendableValuesBucket; 8255 } else { 8256 return null; 8257 } 8258} 8259 8260const task = new taskpool.Task(getDataByName, 'Lisa', this.context); 8261const sendableValuesBucket = await taskpool.execute(task) as sendableRelationalStore.ValuesBucket; 8262 8263if (sendableValuesBucket) { 8264 const columnCount = sendableValuesBucket.size; 8265 const age = sendableValuesBucket.get('age'); 8266 const name = sendableValuesBucket.get('name'); 8267 console.info(`Query data in taskpool succeeded, name is "${name}", age is "${age}"`) 8268} 8269``` 8270 8271### isColumnNull 8272 8273isColumnNull(columnIndex: number): boolean 8274 8275检查当前行中指定列的值是否为null。 8276 8277**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 8278 8279**参数:** 8280 8281| 参数名 | 类型 | 必填 | 说明 | 8282| ----------- | ------ | ---- | ----------------------- | 8283| columnIndex | number | 是 | 指定的列索引,从0开始。 | 8284 8285**返回值:** 8286 8287| 类型 | 说明 | 8288| ------- | --------------------------------------------------------- | 8289| boolean | 如果当前行中指定列的值为null,则返回true,否则返回false。 | 8290 8291**错误码:** 8292 8293以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。其中,14800011错误码处理可参考[数据库备份与恢复](../../database/data-backup-and-restore.md)。 8294 8295| **错误码ID** | **错误信息** | 8296|-----------| ------------------------------------------------------- | 8297| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 8298| 14800000 | Inner error. | 8299| 14800011 | Database corrupted. | 8300| 14800012 | Row out of bounds. | 8301| 14800013 | Column out of bounds. | 8302| 14800014 | Already closed. | 8303| 14800021 | SQLite: Generic error. | 8304| 14800022 | SQLite: Callback routine requested an abort. | 8305| 14800023 | SQLite: Access permission denied. | 8306| 14800024 | SQLite: The database file is locked. | 8307| 14800025 | SQLite: A table in the database is locked. | 8308| 14800026 | SQLite: The database is out of memory. | 8309| 14800027 | SQLite: Attempt to write a readonly database. | 8310| 14800028 | SQLite: Some kind of disk I/O error occurred. | 8311| 14800029 | SQLite: The database is full. | 8312| 14800030 | SQLite: Unable to open the database file. | 8313| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 8314| 14800032 | SQLite: Abort due to constraint violation. | 8315| 14800033 | SQLite: Data type mismatch. | 8316| 14800034 | SQLite: Library used incorrectly. | 8317 8318**示例:** 8319 8320```ts 8321if(resultSet != undefined) { 8322 const isColumnNull = (resultSet as relationalStore.ResultSet).isColumnNull((resultSet as relationalStore.ResultSet).getColumnIndex("CODES")); 8323} 8324``` 8325 8326### close 8327 8328close(): void 8329 8330关闭结果集,若不关闭可能会引起fd泄露和内存泄露。 8331 8332**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 8333 8334**示例:** 8335 8336```ts 8337if(resultSet != undefined) { 8338 (resultSet as relationalStore.ResultSet).close(); 8339} 8340``` 8341 8342**错误码:** 8343 8344以下错误码的详细介绍请参见[关系型数据库错误码](errorcode-data-rdb.md)。 8345 8346| **错误码ID** | **错误信息** | 8347|-----------| ------------------------------------------------------------ | 8348| 14800000 | Inner error. | 8349| 14800012 | Row out of bounds. | 8350