1# @ohos.data.relationalStore (关系型数据库)(系统接口) 2 3关系型数据库(Relational Database,RDB)是一种基于关系模型来管理数据的数据库。关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制,对外提供了一系列的增、删、改、查等接口,也可以直接运行用户输入的SQL语句来满足复杂的场景需要。不支持Worker线程。 4ArkTS侧支持的基本数据类型:number、string、二进制类型数据、boolean。为保证插入并读取数据成功,建议一条数据不要超过2M。超出该大小,插入成功,读取失败。 5 6该模块提供以下关系型数据库相关的常用功能: 7 8- [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates): 数据库中用来代表数据实体的性质、特征或者数据实体之间关系的词项,主要用来定义数据库的操作条件。 9- [RdbStore](#rdbstore):提供管理关系数据库(RDB)方法的接口。 10- [ResultSet](js-apis-data-relationalStore.md#resultset):提供用户调用关系型数据库查询接口之后返回的结果集合。 11 12> **说明:** 13> 14> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 15> 16> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.data.relationalStore (关系型数据库)](js-apis-data-relationalStore.md)。 17 18## 导入模块 19 20```ts 21import { relationalStore } from '@kit.ArkData'; 22``` 23 24## StoreConfig 25 26管理数据库配置。 27 28**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 29 30| 名称 | 类型 | 必填 | 说明 | 31| ------------- | ------------- | ---- | --------------------------------------------------------- | 32| isSearchable<sup>11+</sup> | boolean | 否 | 指定数据库是否支持搜索,true表示支持搜索,false表示不支持搜索,默认不支持搜索。<br/>**系统接口:** 此接口为系统接口。<br/>从API version 11开始,支持此可选参数。<br/> | 33| vector<sup>12+</sup> | boolean | 否 | 指定数据库是否是向量数据库,true表示向量数据库,false表示关系型数据库,默认为false。<br/>向量数据库适用于存储和处理高维向量数据,关系型数据库适用于存储和处理结构化数据。<br/>**系统接口:** 此接口为系统接口。<br/>从API version 12开始,支持此可选参数。向量数据库目前支持[execute](js-apis-data-relationalStore.md#execute12-1),[querySql](js-apis-data-relationalStore.md#querysql-1),[beginTrans](js-apis-data-relationalStore.md#begintrans12),[commit](js-apis-data-relationalStore.md#commit12),[rollback](js-apis-data-relationalStore.md#rollback12)以及[ResultSet](js-apis-data-relationalStore.md#resultset)类型操作接口。当使用向量数据库时,在调用deleteRdbStore接口前,应当确保向量数据库已经被正确关闭。| 34| haMode<sup>12+</sup> | [HAMode](#hamode12) | 否 | 指定关系型数据库存储的高可用性模式,SINGLE表示将数据写入单个关系型数据库存储,MAIN_REPLICA表示将数据写入主关系型数据库存储和副本关系型数据库存储,但不支持加密场景和attach场景。MAIN_REPLICA会导致数据库写入性能的劣化,默认为SINGLE。<br/>**系统接口:** 此接口为系统接口。<br/>从API version 12开始,支持此可选参数。<br/> | 35 36## HAMode<sup>12+</sup> 37 38描述关系型数据库存储的高可用性模式的枚举。 39 40**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 41 42| 名称 | 值 | 说明 | 43| ------------------------------- | --- | -------------- | 44| SINGLE | 0 | 表示将数据写入单个关系型数据库存储。 | 45| MAIN_REPLICA | 1 | 表示将数据写入主关系型数据库存储和副本关系型数据库存储,不支持加密场景和attach场景。 | 46 47## Reference<sup>11+</sup> 48 49记录表之间通过表字段指定的关联关系。其中表a关联到表b,称a为b关联的子表,b为a关联的父表。 50 51**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 52 53**系统接口:** 此接口为系统接口。 54 55| 名称 | 类型 | 必填 | 说明 | 56| ---------- | ------ | ---- | ---------------------------------------- | 57| sourceTable | string | 是 | 关联的子表名称。 | 58| targetTable | string | 是 | 关联的父表名称。 | 59| refFields | Record<string, string> | 是 | 表示关联表的关联字段。键值数据中键为子表字段,值为父表字段。 | 60 61## DistributedConfig<sup>10+</sup> 62 63记录表的分布式配置信息。 64 65**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 66 67| 名称 | 类型 | 必填 | 说明 | 68| -------- | ------- | ---- | ------------------------------------------------------------ | 69| references<sup>11+</sup> | Array<[Reference](#reference11)> | 否 | 设置表之间的关联关系,可以设置多个字段的关联,子表和父表关联字段的值必须相同。默认数据库表之间无关联关系。<br/>**系统接口:** 此接口为系统接口。<br/>从API version 11开始,支持此可选参数。| 70 71## RdbStore 72 73提供管理关系型数据库(RDB)的接口。 74在使用以下相关接口前,请使用[executeSql](js-apis-data-relationalStore.md#executesql)接口初始化数据库表结构和相关数据。 75 76### update 77 78update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>):void 79 80根据DataSharePredicates的指定实例对象更新数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 81 82**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 83 84**模型约束:** 此接口仅可在Stage模型下可用。 85 86**系统接口:** 此接口为系统接口。 87 88**参数:** 89 90| 参数名 | 类型 | 必填 | 说明 | 91| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 92| table | string | 是 | 指定的目标表名。 | 93| values | [ValuesBucket](js-apis-data-relationalStore.md#valuesbucket) | 是 | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 | 94| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的更新条件。 | 95| callback | AsyncCallback<number> | 是 | 指定的callback回调方法。返回受影响的行数。 | 96 97**错误码:** 98 99以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 100 101| **错误码ID** | **错误信息** | 102|-----------| ------------------------------------------------------------ | 103| 202 | Permission verification failed, application which is not a system application uses system API. | 104| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 105| 14800000 | Inner error. | 106| 14800011 | Database corrupted. | 107| 14800014 | Already closed. | 108| 14800015 | The database does not respond. | 109| 14800021 | SQLite: Generic error. | 110| 14800022 | SQLite: Callback routine requested an abort. | 111| 14800023 | SQLite: Access permission denied. | 112| 14800024 | SQLite: The database file is locked. | 113| 14800025 | SQLite: A table in the database is locked. | 114| 14800026 | SQLite: The database is out of memory. | 115| 14800027 | SQLite: Attempt to write a readonly database. | 116| 14800028 | SQLite: Some kind of disk I/O error occurred. | 117| 14800029 | SQLite: The database is full. | 118| 14800030 | SQLite: Unable to open the database file. | 119| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 120| 14800032 | SQLite: Abort due to constraint violation. | 121| 14800033 | SQLite: Data type mismatch. | 122| 14800034 | SQLite: Library used incorrectly. | 123| 14800047 | The WAL file size exceeds the default limit. | 124 125**示例:** 126 127```ts 128import { dataSharePredicates } from '@kit.ArkData'; 129import { ValuesBucket } from '@kit.ArkData'; 130 131let value1 = "Rose"; 132let value2 = 22; 133let value3 = 200.5; 134let value4 = new Uint8Array([1, 2, 3, 4, 5]); 135 136// 以下三种方式可用 137const valueBucket1: ValuesBucket = { 138 'NAME': value1, 139 'AGE': value2, 140 'SALARY': value3, 141 'CODES': value4, 142}; 143const valueBucket2: ValuesBucket = { 144 NAME: value1, 145 AGE: value2, 146 SALARY: value3, 147 CODES: value4, 148}; 149const valueBucket3: ValuesBucket = { 150 "NAME": value1, 151 "AGE": value2, 152 "SALARY": value3, 153 "CODES": value4, 154}; 155 156let predicates = new dataSharePredicates.DataSharePredicates(); 157predicates.equalTo("NAME", "Lisa"); 158if(store != undefined) { 159 (store as relationalStore.RdbStore).update("EMPLOYEE", valueBucket1, predicates, (err, rows) => { 160 if (err) { 161 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 162 return; 163 } 164 console.info(`Updated row count: ${rows}`); 165 }) 166} 167``` 168 169### update 170 171update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates):Promise<number> 172 173根据DataSharePredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 174 175**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 176 177**模型约束:** 此接口仅可在Stage模型下可用。 178 179**系统接口:** 此接口为系统接口。 180 181**参数:** 182 183| 参数名 | 类型 | 必填 | 说明 | 184| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 185| table | string | 是 | 指定的目标表名。 | 186| values | [ValuesBucket](js-apis-data-relationalStore.md#valuesbucket) | 是 | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 | 187| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的更新条件。 | 188 189**返回值**: 190 191| 类型 | 说明 | 192| --------------------- | ----------------------------------------- | 193| Promise<number> | 指定的Promise回调方法。返回受影响的行数。 | 194 195**错误码:** 196 197以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 198 199| **错误码ID** | **错误信息** | 200|-----------| ------------------------------------------------------------ | 201| 202 | Permission verification failed, application which is not a system application uses system API. | 202| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 203| 14800000 | Inner error. | 204| 14800011 | Database corrupted. | 205| 14800014 | Already closed. | 206| 14800015 | The database does not respond. | 207| 14800021 | SQLite: Generic error. | 208| 14800022 | SQLite: Callback routine requested an abort. | 209| 14800023 | SQLite: Access permission denied. | 210| 14800024 | SQLite: The database file is locked. | 211| 14800025 | SQLite: A table in the database is locked. | 212| 14800026 | SQLite: The database is out of memory. | 213| 14800027 | SQLite: Attempt to write a readonly database. | 214| 14800028 | SQLite: Some kind of disk I/O error occurred. | 215| 14800029 | SQLite: The database is full. | 216| 14800030 | SQLite: Unable to open the database file. | 217| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 218| 14800032 | SQLite: Abort due to constraint violation. | 219| 14800033 | SQLite: Data type mismatch. | 220| 14800034 | SQLite: Library used incorrectly. | 221| 14800047 | The WAL file size exceeds the default limit. | 222 223**示例:** 224 225```ts 226import { dataSharePredicates } from '@kit.ArkData'; 227import { ValuesBucket } from '@kit.ArkData'; 228import { BusinessError } from '@kit.BasicServicesKit'; 229 230let value1 = "Rose"; 231let value2 = 22; 232let value3 = 200.5; 233let value4 = new Uint8Array([1, 2, 3, 4, 5]); 234 235// 以下三种方式可用 236const valueBucket1: ValuesBucket = { 237 'NAME': value1, 238 'AGE': value2, 239 'SALARY': value3, 240 'CODES': value4, 241}; 242const valueBucket2: ValuesBucket = { 243 NAME: value1, 244 AGE: value2, 245 SALARY: value3, 246 CODES: value4, 247}; 248const valueBucket3: ValuesBucket = { 249 "NAME": value1, 250 "AGE": value2, 251 "SALARY": value3, 252 "CODES": value4, 253}; 254 255let predicates = new dataSharePredicates.DataSharePredicates(); 256predicates.equalTo("NAME", "Lisa"); 257if(store != undefined) { 258 (store as relationalStore.RdbStore).update("EMPLOYEE", valueBucket1, predicates).then(async (rows: Number) => { 259 console.info(`Updated row count: ${rows}`); 260 }).catch((err: BusinessError) => { 261 console.error(`Updated failed, code is ${err.code},message is ${err.message}`); 262 }) 263} 264``` 265 266### delete 267 268delete(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>):void 269 270根据DataSharePredicates的指定实例对象从数据库中删除数据,使用callback异步回调。 271 272**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 273 274**模型约束:** 此接口仅可在Stage模型下可用。 275 276**系统接口:** 此接口为系统接口。 277 278**参数:** 279 280| 参数名 | 类型 | 必填 | 说明 | 281| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- | 282| table | string | 是 | 指定的目标表名。 | 283| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的删除条件。 | 284| callback | AsyncCallback<number> | 是 | 指定callback回调函数。返回受影响的行数。 | 285 286**错误码:** 287 288以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 289 290| **错误码ID** | **错误信息** | 291|-----------| ------------------------------------------------------------ | 292| 202 | Permission verification failed, application which is not a system application uses system API. | 293| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 294| 14800000 | Inner error. | 295| 14800011 | Database corrupted. | 296| 14800014 | Already closed. | 297| 14800015 | The database does not respond. | 298| 14800021 | SQLite: Generic error. | 299| 14800022 | SQLite: Callback routine requested an abort. | 300| 14800023 | SQLite: Access permission denied. | 301| 14800024 | SQLite: The database file is locked. | 302| 14800025 | SQLite: A table in the database is locked. | 303| 14800026 | SQLite: The database is out of memory. | 304| 14800027 | SQLite: Attempt to write a readonly database. | 305| 14800028 | SQLite: Some kind of disk I/O error occurred. | 306| 14800029 | SQLite: The database is full. | 307| 14800030 | SQLite: Unable to open the database file. | 308| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 309| 14800032 | SQLite: Abort due to constraint violation. | 310| 14800033 | SQLite: Data type mismatch. | 311| 14800034 | SQLite: Library used incorrectly. | 312| 14800047 | The WAL file size exceeds the default limit. | 313 314**示例:** 315 316```ts 317import { dataSharePredicates } from '@kit.ArkData'; 318 319let predicates = new dataSharePredicates.DataSharePredicates(); 320predicates.equalTo("NAME", "Lisa"); 321if(store != undefined) { 322 (store as relationalStore.RdbStore).delete("EMPLOYEE", predicates, (err, rows) => { 323 if (err) { 324 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 325 return; 326 } 327 console.info(`Delete rows: ${rows}`); 328 }) 329} 330``` 331 332### delete 333 334delete(table: string, predicates: dataSharePredicates.DataSharePredicates):Promise<number> 335 336根据DataSharePredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。 337 338**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 339 340**模型约束:** 此接口仅可在Stage模型下可用。 341 342**系统接口:** 此接口为系统接口。 343 344**参数:** 345 346| 参数名 | 类型 | 必填 | 说明 | 347| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- | 348| table | string | 是 | 指定的目标表名。 | 349| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的删除条件。 | 350 351**返回值**: 352 353| 类型 | 说明 | 354| --------------------- | ------------------------------- | 355| Promise<number> | Promise对象。返回受影响的行数。 | 356 357**错误码:** 358 359以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 360 361| **错误码ID** | **错误信息** | 362|-----------| --------------------- | 363| 202 | Permission verification failed, application which is not a system application uses system API. | 364| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 365| 14800000 | Inner error. | 366| 14800011 | Database corrupted. | 367| 14800014 | Already closed. | 368| 14800015 | The database does not respond. | 369| 14800021 | SQLite: Generic error. | 370| 14800022 | SQLite: Callback routine requested an abort. | 371| 14800023 | SQLite: Access permission denied. | 372| 14800024 | SQLite: The database file is locked. | 373| 14800025 | SQLite: A table in the database is locked. | 374| 14800026 | SQLite: The database is out of memory. | 375| 14800027 | SQLite: Attempt to write a readonly database. | 376| 14800028 | SQLite: Some kind of disk I/O error occurred. | 377| 14800029 | SQLite: The database is full. | 378| 14800030 | SQLite: Unable to open the database file. | 379| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 380| 14800032 | SQLite: Abort due to constraint violation. | 381| 14800033 | SQLite: Data type mismatch. | 382| 14800034 | SQLite: Library used incorrectly. | 383| 14800047 | The WAL file size exceeds the default limit. | 384 385**示例:** 386 387```ts 388import { dataSharePredicates } from '@kit.ArkData'; 389import { BusinessError } from '@kit.BasicServicesKit'; 390 391let predicates = new dataSharePredicates.DataSharePredicates(); 392predicates.equalTo("NAME", "Lisa"); 393if(store != undefined) { 394 (store as relationalStore.RdbStore).delete("EMPLOYEE", predicates).then((rows: Number) => { 395 console.info(`Delete rows: ${rows}`); 396 }).catch((err: BusinessError) => { 397 console.error(`Delete failed, code is ${err.code},message is ${err.message}`); 398 }) 399} 400``` 401 402### query<sup>10+</sup> 403 404query(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<ResultSet>):void 405 406根据指定条件查询数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 407 408**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 409 410**模型约束:** 此接口仅可在Stage模型下可用。 411 412**系统接口:** 此接口为系统接口。 413 414**参数:** 415 416| 参数名 | 类型 | 必填 | 说明 | 417| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 418| table | string | 是 | 指定的目标表名。 | 419| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的查询条件。 | 420| callback | AsyncCallback<[ResultSet](#resultset)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 | 421 422**错误码:** 423 424以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 425 426| **错误码ID** | **错误信息** | 427|-----------| ------------------ | 428| 202 | Permission verification failed, application which is not a system application uses system API. | 429| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 430| 14800000 | Inner error. | 431| 14800014 | Already closed. | 432| 14800015 | The database does not respond. | 433 434**示例:** 435 436```ts 437import { dataSharePredicates } from '@kit.ArkData'; 438 439let predicates = new dataSharePredicates.DataSharePredicates(); 440predicates.equalTo("NAME", "Rose"); 441if(store != undefined) { 442 (store as relationalStore.RdbStore).query("EMPLOYEE", predicates, (err, resultSet) => { 443 if (err) { 444 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 445 return; 446 } 447 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 448 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 449 while (resultSet.goToNextRow()) { 450 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 451 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 452 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 453 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 454 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 455 } 456 // 释放数据集的内存 457 resultSet.close(); 458 }) 459} 460``` 461 462### query 463 464query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>):void 465 466根据指定条件查询数据库中的数据,使用callback异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 467 468**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 469 470**模型约束:** 此接口仅可在Stage模型下可用。 471 472**系统接口:** 此接口为系统接口。 473 474**参数:** 475 476| 参数名 | 类型 | 必填 | 说明 | 477| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 478| table | string | 是 | 指定的目标表名。 | 479| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的查询条件。 | 480| columns | Array<string> | 是 | 表示要查询的列。如果值为空,则查询应用于所有列。 | 481| callback | AsyncCallback<[ResultSet](#resultset)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSet对象。 | 482 483**错误码:** 484 485以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 486 487| **错误码ID** | **错误信息** | 488|-----------| --------------- | 489| 202 | Permission verification failed, application which is not a system application uses system API. | 490| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 491| 14800000 | Inner error. | 492| 14800014 | Already closed. | 493| 14800015 | The database does not respond. | 494 495**示例:** 496 497```ts 498import { dataSharePredicates } from '@kit.ArkData'; 499 500let predicates = new dataSharePredicates.DataSharePredicates(); 501predicates.equalTo("NAME", "Rose"); 502if(store != undefined) { 503 (store as relationalStore.RdbStore).query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], (err, resultSet) => { 504 if (err) { 505 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 506 return; 507 } 508 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 509 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 510 while (resultSet.goToNextRow()) { 511 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 512 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 513 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 514 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 515 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 516 } 517 // 释放数据集的内存 518 resultSet.close(); 519 }) 520} 521``` 522 523### query 524 525query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns?: Array<string>):Promise<ResultSet> 526 527根据指定条件查询数据库中的数据,使用Promise异步回调。由于共享内存大小限制为2Mb,因此单条数据的大小需小于2Mb,否则会查询失败。 528 529**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 530 531**模型约束:** 此接口仅可在Stage模型下可用。 532 533**系统接口:** 此接口为系统接口。 534 535**参数:** 536 537| 参数名 | 类型 | 必填 | 说明 | 538| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ | 539| table | string | 是 | 指定的目标表名。 | 540| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的查询条件。 | 541| columns | Array<string> | 否 | 表示要查询的列。如果值为空,则查询应用于所有列。 | 542 543**返回值**: 544 545| 类型 | 说明 | 546| ------------------------------------------------------- | -------------------------------------------------- | 547| Promise<[ResultSet](#resultset)> | Promise对象。如果操作成功,则返回ResultSet对象。 | 548 549**错误码:** 550 551以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 552 553| **错误码ID** | **错误信息** | 554|-----------| ----------- | 555| 202 | Permission verification failed, application which is not a system application uses system API. | 556| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 557| 14800000 | Inner error. | 558| 14800014 | Already closed. | 559| 14800015 | The database does not respond. | 560 561**示例:** 562 563```ts 564import { dataSharePredicates } from '@kit.ArkData'; 565import { BusinessError } from '@kit.BasicServicesKit'; 566 567let predicates = new dataSharePredicates.DataSharePredicates(); 568predicates.equalTo("NAME", "Rose"); 569if(store != undefined) { 570 (store as relationalStore.RdbStore).query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet: relationalStore.ResultSet) => { 571 console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); 572 // resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。 573 while (resultSet.goToNextRow()) { 574 const id = resultSet.getLong(resultSet.getColumnIndex("ID")); 575 const name = resultSet.getString(resultSet.getColumnIndex("NAME")); 576 const age = resultSet.getLong(resultSet.getColumnIndex("AGE")); 577 const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); 578 console.info(`id=${id}, name=${name}, age=${age}, salary=${salary}`); 579 } 580 // 释放数据集的内存 581 resultSet.close(); 582 }).catch((err: BusinessError) => { 583 console.error(`Query failed, code is ${err.code},message is ${err.message}`); 584 }) 585} 586``` 587 588### cloudSync<sup>11+</sup> 589 590cloudSync(mode: SyncMode, predicates: RdbPredicates, progress: Callback<ProgressDetails>, callback: AsyncCallback<void>): void 591 592手动执行按条件进行端云同步,使用callback异步回调。使用该接口需要实现云同步功能。 593 594**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 595 596**系统接口:** 此接口为系统接口。 597 598**参数:** 599 600| 参数名 | 类型 | 必填 | 说明 | 601|-------------|--------------------------------| ---- |-------------------------------| 602| mode | [SyncMode](js-apis-data-relationalStore.md#syncmode) | 是 | 表示数据库的同步模式。 | 603| predicates | [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | 是 | 表示同步数据的谓词条件。 | 604| progress | Callback<[ProgressDetails](js-apis-data-relationalStore.md#progressdetails10)> | 是 | 用来处理数据库同步详细信息的回调函数。 | 605| callback | AsyncCallback<void> | 是 | 指定的callback回调函数,用于向调用者发送同步结果。 | 606 607**错误码:** 608 609以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 610 611| **错误码ID** | **错误信息** | 612|-----------|--------------| 613| 202 | if permission verification failed, application which is not a system application uses system API. | 614| 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.| 615| 801 | Capability not supported. | 616| 14800014 | Already closed. | 617 618**示例:** 619 620```ts 621let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 622predicates.in("id", ["id1", "id2"]); 623 624if(store != undefined) { 625 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, predicates, (progressDetail: relationalStore.ProgressDetails) => { 626 console.info(`progress: ${progressDetail}`); 627 }, (err) => { 628 if (err) { 629 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}}`); 630 return; 631 } 632 console.info('Cloud sync succeeded'); 633 }); 634}; 635``` 636 637### cloudSync<sup>11+</sup> 638 639cloudSync(mode: SyncMode, predicates: RdbPredicates, progress: Callback<ProgressDetails>): Promise<void> 640 641手动执行按条件进行端云同步,使用Promise异步处理。使用该接口需要实现云同步功能。 642 643**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 644 645**系统接口:** 此接口为系统接口。 646 647**参数:** 648 649| 参数名 | 类型 | 必填 | 说明 | 650|------------|---------------------------------| ---- |---------------------| 651| mode | [SyncMode](js-apis-data-relationalStore.md#syncmode) | 是 | 表示数据库的同步模式。 | 652| predicates | [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | 是 | 表示同步数据的谓词条件。 | 653| progress | Callback<[ProgressDetails](js-apis-data-relationalStore.md#progressdetails10)> | 是 | 用来处理数据库同步详细信息的回调函数。 | 654 655**返回值**: 656 657| 类型 | 说明 | 658| ------------------- | --------------------------------------- | 659| Promise<void> | Promise对象,用于向调用者发送同步结果。 | 660 661**错误码:** 662 663以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 664 665| **错误码ID** | **错误信息** | 666|-----------|---------------------------| 667| 202 | if permission verification failed, application which is not a system application uses system API. | 668| 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. | 669| 801 | Capability not supported. | 670| 14800014 | Already closed. | 671 672**示例:** 673 674```ts 675import { BusinessError } from '@kit.BasicServicesKit'; 676 677let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); 678predicates.in("id", ["id1", "id2"]); 679 680if(store != undefined) { 681 (store as relationalStore.RdbStore).cloudSync(relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST, predicates, (progressDetail: relationalStore.ProgressDetails) => { 682 console.info(`progress: ${progressDetail}`); 683 }).then(() => { 684 console.info('Cloud sync succeeded'); 685 }).catch((err: BusinessError) => { 686 console.error(`cloudSync failed, code is ${err.code},message is ${err.message}}`); 687 }); 688}; 689``` 690 691### querySharingResource<sup>11+</sup> 692 693querySharingResource(predicates: RdbPredicates, columns?: Array<string>): Promise<ResultSet> 694 695根据谓词条件匹配的数据记录查找对应记录的共享资源标识,返回查找的结果集。 如果指定了列字段,则返回结果集中同时包含对应列的字段值,使用Promise异步回调。 696 697**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 698 699**系统接口:** 此接口为系统接口。 700 701**参数:** 702 703| 参数名 | 类型 | 必填 | 说明 | 704| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 705| predicates | [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | 是 | 表示查询的谓词条件。 | 706| columns | Array<string> | 否 | 表示要查找的列字段名。此参数不填时,返回的结果集中只包含共享资源标识字段。 | 707 708**返回值:** 709 710| 参数名 | 说明 | 711| -------- | ------------------------------------------------- | 712| Promise<[ResultSet](#resultset)> | Promise对象,返回查询的结果集。 | 713 714**错误码:** 715 716以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 717 718| **错误码ID** | **错误信息** | 719|-----------|-------------| 720| 401 | Parameter error. Possible causes: 1. Need 1 - 3 parameter(s)! 2. The RdbStore must be not nullptr. 3. The predicates must be an RdbPredicates. 4. The columns must be a string array. | 721| 801 | Capability not supported. | 722| 14800000 | Inner error. | 723| 14800011 | Database corrupted. | 724| 14800014 | Already closed. | 725| 14800015 | The database does not respond. | 726| 14800021 | SQLite: Generic error. | 727| 14800022 | SQLite: Callback routine requested an abort. | 728| 14800023 | SQLite: Access permission denied. | 729| 14800024 | SQLite: The database file is locked. | 730| 14800025 | SQLite: A table in the database is locked. | 731| 14800026 | SQLite: The database is out of memory. | 732| 14800027 | SQLite: Attempt to write a readonly database. | 733| 14800028 | SQLite: Some kind of disk I/O error occurred. | 734| 14800029 | SQLite: The database is full. | 735| 14800030 | SQLite: Unable to open the database file. | 736| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 737| 14800032 | SQLite: Abort due to constraint violation. | 738| 14800033 | SQLite: Data type mismatch. | 739| 14800034 | SQLite: Library used incorrectly. | 740 741**示例:** 742 743```ts 744import { BusinessError } from '@kit.BasicServicesKit'; 745 746let sharingResource: string; 747let predicates = new relationalStore.RdbPredicates('test_table'); 748predicates.equalTo('data', 'data_test'); 749if(store != undefined) { 750 (store as relationalStore.RdbStore).querySharingResource(predicates, ['uuid', 'data']).then((resultSet) => { 751 if (!resultSet.goToFirstRow()) { 752 console.error(`resultSet error`); 753 return; 754 } 755 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 756 console.info(`sharing resource: ${res}`); 757 sharingResource = res; 758 }).catch((err: BusinessError) => { 759 console.error(`query sharing resource failed, code is ${err.code},message is ${err.message}`); 760 }) 761} 762 763``` 764 765### querySharingResource<sup>11+</sup> 766 767querySharingResource(predicates: RdbPredicates, callback: AsyncCallback<ResultSet>): void 768 769根据谓词条件匹配的数据记录查找对应记录的共享资源,返回查找的结果集,使用callback异步回调。 770 771**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 772 773**系统接口:** 此接口为系统接口。 774 775**参数:** 776 777| 参数名 | 类型 | 必填 | 说明 | 778| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 779| predicates | [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | 是 | 表示查询的谓词条件。 | 780| callback | AsyncCallback<[ResultSet](#resultset)> | 是 | 回调函数。返回查询的结果集。 | 781 782**错误码:** 783 784以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 785 786| **错误码ID** | **错误信息** | 787|-----------|------| 788| 401 | Parameter error. Possible causes: 1. Need 1 - 3 parameter(s)! 2. The RdbStore must be not nullptr. 3. The predicates must be an RdbPredicates. 4. The columns must be a string array. | 789| 801 | Capability not supported. | 790| 14800000 | Inner error. | 791| 14800011 | Database corrupted. | 792| 14800014 | Already closed. | 793| 14800015 | The database does not respond. | 794| 14800021 | SQLite: Generic error. | 795| 14800022 | SQLite: Callback routine requested an abort. | 796| 14800023 | SQLite: Access permission denied. | 797| 14800024 | SQLite: The database file is locked. | 798| 14800025 | SQLite: A table in the database is locked. | 799| 14800026 | SQLite: The database is out of memory. | 800| 14800027 | SQLite: Attempt to write a readonly database. | 801| 14800028 | SQLite: Some kind of disk I/O error occurred. | 802| 14800029 | SQLite: The database is full. | 803| 14800030 | SQLite: Unable to open the database file. | 804| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 805| 14800032 | SQLite: Abort due to constraint violation. | 806| 14800033 | SQLite: Data type mismatch. | 807| 14800034 | SQLite: Library used incorrectly. | 808 809 810**示例:** 811 812```ts 813let sharingResource: string; 814let predicates = new relationalStore.RdbPredicates('test_table'); 815predicates.equalTo('data', 'data_test'); 816if(store != undefined) { 817 (store as relationalStore.RdbStore).querySharingResource(predicates,(err, resultSet) => { 818 if (err) { 819 console.error(`sharing resource failed, code is ${err.code},message is ${err.message}`); 820 return; 821 } 822 if (!resultSet.goToFirstRow()) { 823 console.error(`resultSet error`); 824 return; 825 } 826 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 827 console.info(`sharing resource: ${res}`); 828 sharingResource = res; 829 }) 830} 831 832``` 833 834### querySharingResource<sup>11+</sup> 835 836querySharingResource(predicates: RdbPredicates, columns: Array<string>, callback: AsyncCallback<ResultSet>): void 837 838根据谓词条件匹配的数据记录查找对应记录的共享资源,返回查找到的共享资源的结果集,同时在结果集中返回谓词条件匹配的指定列名的字段值,使用callback异步回调。 839 840**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Client 841 842**系统接口:** 此接口为系统接口。 843 844**参数:** 845 846| 参数名 | 类型 | 必填 | 说明 | 847| -------- | ----------------------------------------------------- | ---- | -------------------------------------------------- | 848| predicates | [RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | 是 | 表示查询的谓词条件。 | 849| columns | Array<string> | 是 | 表示要查找的列字段名。 | 850| callback | AsyncCallback<[ResultSet](#resultset)> | 是 | 回调函数。返回查询的结果集。 | 851 852**错误码:** 853 854以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 855 856| **错误码ID** | **错误信息** | 857|-----------|--------------| 858| 401 | Parameter error. Possible causes: 1. Need 1 - 3 parameter(s)! 2. The RdbStore must be not nullptr. 3. The predicates must be an RdbPredicates. 4. The columns must be a string array. | 859| 801 | Capability not supported. | 860| 14800000 | Inner error. | 861| 14800011 | Database corrupted. | 862| 14800014 | Already closed. | 863| 14800015 | The database does not respond. | 864| 14800021 | SQLite: Generic error. | 865| 14800022 | SQLite: Callback routine requested an abort. | 866| 14800023 | SQLite: Access permission denied. | 867| 14800024 | SQLite: The database file is locked. | 868| 14800025 | SQLite: A table in the database is locked. | 869| 14800026 | SQLite: The database is out of memory. | 870| 14800027 | SQLite: Attempt to write a readonly database. | 871| 14800028 | SQLite: Some kind of disk I/O error occurred. | 872| 14800029 | SQLite: The database is full. | 873| 14800030 | SQLite: Unable to open the database file. | 874| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 875| 14800032 | SQLite: Abort due to constraint violation. | 876| 14800033 | SQLite: Data type mismatch. | 877| 14800034 | SQLite: Library used incorrectly. | 878 879 880**示例:** 881 882```ts 883let sharingResource: string; 884let predicates = new relationalStore.RdbPredicates('test_table'); 885predicates.equalTo('data', 'data_test'); 886if(store != undefined) { 887 (store as relationalStore.RdbStore).querySharingResource(predicates, ['uuid', 'data'], (err, resultSet) => { 888 if (err) { 889 console.error(`sharing resource failed, code is ${err.code},message is ${err.message}`); 890 return; 891 } 892 if (!resultSet.goToFirstRow()) { 893 console.error(`resultSet error`); 894 return; 895 } 896 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 897 console.info(`sharing resource: ${res}`); 898 sharingResource = res; 899 }) 900} 901 902``` 903 904 905### lockCloudContainer<sup>12+</sup> 906 907lockCloudContainer(): Promise<number> 908 909手动对应用云端数据库加锁,使用Promise异步处理。 910 911> **说明:** 912> 913> 若手动加锁成功,则其他同账户设备的同应用禁止同步到云端。使用该接口需要实现云同步功能。 914 915**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 916 917**系统接口:** 此接口为系统接口。 918 919**返回值**: 920 921| 类型 | 说明 | 922| ------------------- | ---------------------------------------| 923| Promise<number> | Promise对象,如果加锁成功,返回锁的有效时长,如果加锁失败,返回0,单位:ms。 | 924 925**错误码:** 926 927以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 928 929| **错误码ID** | **错误信息** | 930|-----------|---------------------------| 931| 202 | Permission verification failed, application which is not a system application uses system API. | 932 933**示例:** 934 935```ts 936import { BusinessError } from '@kit.BasicServicesKit'; 937 938if(store != undefined) { 939 (store as relationalStore.RdbStore).lockCloudContainer().then((time: Number) => { 940 console.info('lockCloudContainer succeeded time:' + time); 941 }).catch((err: BusinessError) => { 942 console.error(`lockCloudContainer failed, code is ${err.code},message is ${err.message}`); 943 }) 944} 945``` 946 947### unlockCloudContainer<sup>12+</sup> 948 949unlockCloudContainer(): Promise<void> 950 951手动对应用云端数据库解锁,使用Promise异步处理。使用该接口需要实现云同步功能。 952 953**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 954 955**系统接口:** 此接口为系统接口。 956 957**返回值**: 958 959| 类型 | 说明 | 960| ------------------- | --------------------------------------- | 961| Promise<void> | 无返回结果的Promise对象。 | 962 963**错误码:** 964 965以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 966 967| **错误码ID** | **错误信息** | 968|-----------|---------------------------| 969| 202 | Permission verification failed, application which is not a system application uses system API. | 970 971**示例:** 972 973```ts 974import { BusinessError } from '@kit.BasicServicesKit'; 975 976if(store != undefined) { 977 (store as relationalStore.RdbStore).unlockCloudContainer().then(() => { 978 console.info('unlockCloudContainer succeeded'); 979 }).catch((err: BusinessError) => { 980 console.error(`unlockCloudContainer failed, code is ${err.code},message is ${err.message}`); 981 }) 982} 983``` 984 985### restore<sup>12+</sup> 986 987restore(): Promise<void> 988 989从副本关系型数据库文件恢复数据库,使用Promise异步回调。此接口仅供[HAMode](#hamode12)为MAIN_REPLICA时使用,且不支持在事务中使用。 990 991**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 992 993**系统接口:** 此接口为系统接口。 994 995**返回值**: 996 997| 类型 | 说明 | 998| ------------------- | ------------------------- | 999| Promise<void> | 无返回结果的Promise对象。 | 1000 1001**错误码:** 1002 1003以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 1004 1005| **错误码ID** | **错误信息** | 1006|-----------| ------------------------------------------------------------ | 1007| 202 | Permission verification failed, application which is not a system application uses system API. | 1008| 14800000 | Inner error. | 1009| 14800010 | Invalid database path. | 1010| 14800011 | Database corrupted. | 1011| 14800014 | Already closed. | 1012| 14800015 | The database does not respond. | 1013| 14800021 | SQLite: Generic error. | 1014| 14800022 | SQLite: Callback routine requested an abort. | 1015| 14800023 | SQLite: Access permission denied. | 1016| 14800024 | SQLite: The database file is locked. | 1017| 14800025 | SQLite: A table in the database is locked. | 1018| 14800026 | SQLite: The database is out of memory. | 1019| 14800027 | SQLite: Attempt to write a readonly database. | 1020| 14800028 | SQLite: Some kind of disk I/O error occurred. | 1021| 14800029 | SQLite: The database is full. | 1022| 14800030 | SQLite: Unable to open the database file. | 1023| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 1024| 14800032 | SQLite: Abort due to constraint violation. | 1025| 14800033 | SQLite: Data type mismatch. | 1026| 14800034 | SQLite: Library used incorrectly. | 1027 1028**示例:** 1029 1030```ts 1031import { BusinessError } from '@kit.BasicServicesKit'; 1032 1033let store: relationalStore.RdbStore | undefined = undefined; 1034if(store != undefined) { 1035 let promiseRestore = (store as relationalStore.RdbStore).restore(); 1036 promiseRestore.then(() => { 1037 console.info('Succeeded in restoring.'); 1038 }).catch((err: BusinessError) => { 1039 console.error(`Failed to restore, code is ${err.code},message is ${err.message}`); 1040 }) 1041} 1042``` 1043 1044## ResultSet 1045 1046提供通过查询数据库生成的数据库结果集的访问方法。结果集是指用户调用关系型数据库查询接口之后返回的结果集合,提供了多种灵活的数据访问方式,以便用户获取各项数据。 1047 1048### getFloat32Array<sup>12+</sup> 1049 1050getFloat32Array(columnIndex: number): Float32Array 1051 1052以浮点数组的形式获取当前行中指定列的值,仅可在[向量数据库](#storeconfig)下可用。 1053 1054**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core 1055 1056**参数:** 1057 1058| 参数名 | 类型 | 必填 | 说明 | 1059| ----------- | ------ | ---- | ----------------------- | 1060| columnIndex | number | 是 | 指定的列索引,从0开始。 | 1061 1062**返回值:** 1063 1064| 类型 | 说明 | 1065| ---------- | -------------------------------- | 1066| Float32Array | 以浮点数组的形式返回指定列的值。 | 1067 1068**错误码:** 1069 1070以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[关系型数据库错误码](errorcode-data-rdb.md)。 1071 1072| **错误码ID** | **错误信息** | 1073|-----------| ------------ | 1074| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1075| 801 | The capability is not supported because the database is not a vector DB. | 1076| 14800011 | Database corrupted. | 1077| 14800013 | Column out of bounds. | 1078| 14800014 | Already closed. | 1079| 14800021 | SQLite: Generic error. | 1080| 14800022 | SQLite: Callback routine requested an abort. | 1081| 14800023 | SQLite: Access permission denied. | 1082| 14800024 | SQLite: The database file is locked. | 1083| 14800025 | SQLite: A table in the database is locked. | 1084| 14800026 | SQLite: The database is out of memory. | 1085| 14800027 | SQLite: Attempt to write a readonly database. | 1086| 14800028 | SQLite: Some kind of disk I/O error occurred. | 1087| 14800029 | SQLite: The database is full. | 1088| 14800030 | SQLite: Unable to open the database file. | 1089| 14800031 | SQLite: TEXT or BLOB exceeds size limit. | 1090| 14800032 | SQLite: Abort due to constraint violation. | 1091| 14800033 | SQLite: Data type mismatch. | 1092| 14800034 | SQLite: Library used incorrectly. | 1093 1094**示例:** 1095 1096```ts 1097let resultSet: relationalStore.ResultSet | undefined; 1098if(resultSet != undefined) { 1099 const id = (resultSet as relationalStore.ResultSet).getFloat32Array(0); 1100} 1101```