diff --git a/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md b/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md index d89c8206986fa4a06834f22990b2049d3761114d..28ab08ee63ca43fe7e34fce781ee3ba8282241b3 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md +++ b/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md @@ -1,6 +1,6 @@ # @ohos.data.rdb (关系型数据库) -关系型数据库(Relational Database,RDB)是一种基于关系模型来管理数据的数据库。关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制,对外提供了一系列的增、删、改、查等接口,也可以直接运行用户输入的SQL语句来满足复杂的场景需要。当应用删除后,其相关数据库会被自动清除。 +关系型数据库(Relational Database,RDB)是一种基于关系模型来管理数据的数据库。关系型数据库基于SQLite组件提供了一套完整的对本地数据库进行管理的机制,对外提供了一系列的增、删、改、查等接口,也可以直接运行用户输入的SQL语句来满足复杂的场景需要。 该模块提供以下关系型数据库相关的常用功能: @@ -13,2665 +13,255 @@ > > 从API Version 9开始,该接口不再维护,推荐使用新接口[@ohos.data.relationalStore](js-apis-data-relationalStore.md)。 -## 导入模块 - -```js -import data_rdb from '@ohos.data.rdb'; -``` - -## data_rdb.getRdbStoreV99+ - -getRdbStoreV9(context: Context, config: StoreConfigV9, version: number, callback: AsyncCallback<RdbStoreV9>): void - -获得一个相关的RdbStoreV9,操作关系型数据库,用户可以根据自己的需求配置RdbStoreV9的参数,然后通过RdbStoreV9调用相关接口可以执行相关的数据操作,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | -| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | -| config | [StoreConfigV9](#storeconfigv99) | 是 | 与此RDB存储相关的数据库配置。 | -| version | number | 是 | 数据库版本。
目前暂不支持通过version自动识别数据库升级降级操作,只能由开发者自行维护。 | -| callback | AsyncCallback<[RdbStoreV9](#rdbstorev99)> | 是 | 指定callback回调函数,返回RdbStoreV9对象。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ----------------------- | -| 14800010 | Invalid database name. | -| 14800011 | Database corrupted. | - -**示例:** - -FA模型示例: - -```js -// 获取context -import featureAbility from '@ohos.ability.featureAbility' -let context = featureAbility.getContext() - -// 获取context后调用getRdbStoreV9 -const STORE_CONFIGV9 = { name: "RdbTest.db", - securityLevel: data_rdb.SecurityLevel.S1} -data_rdb.getRdbStoreV9(context, STORE_CONFIGV9, 1, function (err, rdbStoreV9) { - if (err) { - console.info("Get RdbStoreV9 failed, err: " + err) - return - } - console.log("Get RdbStoreV9 successfully.") -}) -``` - -Stage模型示例: - -```ts -// 获取context -import Ability from '@ohos.application.Ability' -let context -class MainAbility extends Ability{ - onWindowStageCreate(windowStage){ - context = this.context - } -} - -// 获取context后调用getRdbStoreV9 -const STORE_CONFIGV9 = { name: "RdbTest.db", - securityLevel: data_rdb.SecurityLevel.S1} -data_rdb.getRdbStoreV9(context, STORE_CONFIGV9, 1, function (err, rdbStoreV9) { - if (err) { - console.info("Get RdbStoreV9 failed, err: " + err) - return - } - console.log("Get RdbStoreV9 successfully.") -}) -``` - -## data_rdb.getRdbStoreV99+ - -getRdbStoreV9(context: Context, config: StoreConfigV9, version: number): Promise<RdbStoreV9> - -获得一个相关的RdbStoreV9,操作关系型数据库,用户可以根据自己的需求配置RdbStoreV9的参数,然后通过RdbStoreV9调用相关接口可以执行相关的数据操作,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | -------------------------------- | ---- | ------------------------------------------------------------ | -| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | -| config | [StoreConfigV9](#storeconfigv99) | 是 | 与此RDB存储相关的数据库配置。 | -| version | number | 是 | 数据库版本。
目前暂不支持通过version自动识别数据库升级降级操作,只能由开发者自行维护。 | - -**返回值**: - -| 类型 | 说明 | -| ----------------------------------------- | --------------------------------- | -| Promise<[RdbStoreV9](#rdbstorev999)> | Promise对象。返回RdbStoreV9对象。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ----------------------- | -| 14800010 | Invalid database name. | -| 14800011 | Database corrupted. | - -**示例:** - -FA模型示例: - -```js -// 获取context -import featureAbility from '@ohos.ability.featureAbility' -let context = featureAbility.getContext() - -// 获取context后调用getRdbStoreV9 -const STORE_CONFIGV9 = { name: "RdbTest.db", - securityLevel: data_rdb.SecurityLevel.S1} -let promise = data_rdb.getRdbStoreV9(context, STORE_CONFIGV9, 1); -promise.then(async (rdbStoreV9) => { - console.log("Get RdbStoreV9 successfully.") -}).catch((err) => { - console.log("Get RdbStoreV9 failed, err: " + err) -}) -``` - -Stage模型示例: - -```ts -// 获取context -import Ability from '@ohos.application.Ability' -let context -class MainAbility extends Ability{ - onWindowStageCreate(windowStage){ - context = this.context - } -} - -// 获取context后调用getRdbStoreV9 -const STORE_CONFIGV9 = { name: "RdbTest.db", - securityLevel: data_rdb.SecurityLevel.S1} -let promise = data_rdb.getRdbStoreV9(context, STORE_CONFIGV9, 1); -promise.then(async (rdbStoreV9) => { - console.log("Get RdbStoreV9 successfully.") -}).catch((err) => { - console.log("Get RdbStoreV9 failed, err: " + err) -}) -``` - -## data_rdb.deleteRdbStoreV99+ - -deleteRdbStoreV9(context: Context, name: string, callback: AsyncCallback<void>): void - -删除数据库,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------- | ---- | ------------------------------------------------------------ | -| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | -| name | string | 是 | 数据库名称。 | -| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ----------------------- | -| 14800010 | Invalid database name. | - -**示例:** - -FA模型示例: - -```js -// 获取context -import featureAbility from '@ohos.ability.featureAbility' -let context = featureAbility.getContext() - -// 获取context后调用deleteRdbStoreV9 -data_rdb.deleteRdbStoreV9(context, "RdbTest.db", function (err) { - if (err) { - console.info("Delete RdbStorev9 failed, err: " + err) - return - } - console.log("Delete RdbStorev9 successfully.") -}) -``` - -Stage模型示例: - -```ts -// 获取context -import Ability from '@ohos.application.Ability' -let context -class MainAbility extends Ability{ - onWindowStageCreate(windowStage){ - context = this.context - } -} - -// 获取context后调用deleteRdbStoreV9 -data_rdb.deleteRdbStoreV9(context, "RdbTest.db", function (err) { - if (err) { - console.info("Delete RdbStoreV9 failed, err: " + err) - return - } - console.log("Delete RdbStoreV9 successfully.") -}) -``` - -## data_rdb.deleteRdbStoreV99+ - -deleteRdbStoreV9(context: Context, name: string): Promise<void> - -使用指定的数据库文件配置删除数据库,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------- | ---- | ------------------------------------------------------------ | -| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | -| name | string | 是 | 数据库名称。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------- | ------------------------- | -| Promise<void> | 无返回结果的Promise对象。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ----------------------- | -| 14800010 | Invalid database name. | - -**示例:** - -FA模型示例: - -```js -// 获取context -import featureAbility from '@ohos.ability.featureAbility' -let context = featureAbility.getContext() - -// 获取context后调用deleteRdbStoreV9 -let promise = data_rdb.deleteRdbStoreV9(context, "RdbTest.db") -promise.then(()=>{ - console.log("Delete RdbStoreV9 successfully.") -}).catch((err) => { - console.info("Delete RdbStoreV9 failed, err: " + err) -}) -``` - -Stage模型示例: - -```ts -// 获取context -import Ability from '@ohos.application.Ability' -let context -class MainAbility extends Ability{ - onWindowStageCreate(windowStage){ - context = this.context - } -} - -// 获取context后调用deleteRdbStoreV9 -let promise = data_rdb.deleteRdbStoreV9(context, "RdbTest.db") -promise.then(()=>{ - console.log("Delete RdbStoreV9 successfully.") -}).catch((err) => { - console.info("Delete RdbStoreV9 failed, err: " + err) -}) -``` - -## data_rdb.getRdbStore - -getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): void - -获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ | -| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | -| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 | -| version | number | 是 | 数据库版本。
目前暂不支持通过version自动识别数据库升级降级操作,只能由开发者自行维护。 | -| callback | AsyncCallback<[RdbStore](#rdbstore)> | 是 | 指定callback回调函数,返回RdbStore对象。 | - -**示例:** - -FA模型示例: - -```js -// 获取context -import featureAbility from '@ohos.ability.featureAbility' -let context = featureAbility.getContext() - -// 获取context后调用getRdbStore -const STORE_CONFIG = { name: "RdbTest.db"} -data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) { - if (err) { - console.info("Get RdbStore failed, err: " + err) - return - } - console.log("Get RdbStore successfully.") -}) -``` - -Stage模型示例: - -```ts -// 获取context -import Ability from '@ohos.application.Ability' -let context -class MainAbility extends Ability{ - onWindowStageCreate(windowStage){ - context = this.context - } -} - -// 获取context后调用getRdbStore -const STORE_CONFIG = { name: "RdbTest.db"} -data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) { - if (err) { - console.info("Get RdbStore failed, err: " + err) - return - } - console.log("Get RdbStore successfully.") -}) -``` - -## data_rdb.getRdbStore - -getRdbStore(context: Context, config: StoreConfig, version: number): Promise<RdbStore> - -获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | --------------------------- | ---- | ------------------------------------------------------------ | -| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | -| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 | -| version | number | 是 | 数据库版本。
目前暂不支持通过version自动识别数据库升级降级操作,只能由开发者自行维护。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | ------------------------------- | -| Promise<[RdbStore](#rdbstore)> | Promise对象。返回RdbStore对象。 | - -**示例:** - -FA模型示例: - -```js -// 获取context -import featureAbility from '@ohos.ability.featureAbility' -let context = featureAbility.getContext() - -// 获取context后调用getRdbStore -const STORE_CONFIG = { name: "RdbTest.db" } -let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1); -promise.then(async (rdbStore) => { - console.log("Get RdbStore successfully.") -}).catch((err) => { - console.log("Get RdbStore failed, err: " + err) -}) -``` - -Stage模型示例: - -```ts -// 获取context -import Ability from '@ohos.application.Ability' -let context -class MainAbility extends Ability{ - onWindowStageCreate(windowStage){ - context = this.context - } -} - -// 获取context后调用getRdbStore -const STORE_CONFIG = { name: "RdbTest.db" } -let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1); -promise.then(async (rdbStore) => { - console.log("Get RdbStore successfully.") -}).catch((err) => { - console.log("Get RdbStore failed, err: " + err) -}) -``` - -## data_rdb.deleteRdbStore - -deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void - -删除数据库,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------- | ---- | ------------------------------------------------------------ | -| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | -| name | string | 是 | 数据库名称。 | -| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | - -**示例:** - -FA模型示例: - -```js -// 获取context -import featureAbility from '@ohos.ability.featureAbility' -let context = featureAbility.getContext() - -// 获取context后调用deleteRdbStore -data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) { - if (err) { - console.info("Delete RdbStore failed, err: " + err) - return - } - console.log("Delete RdbStore successfully.") -}) -``` - -Stage模型示例: - -```ts -// 获取context -import Ability from '@ohos.application.Ability' -let context -class MainAbility extends Ability{ - onWindowStageCreate(windowStage){ - context = this.context - } -} - -// 获取context后调用deleteRdbStore -data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) { - if (err) { - console.info("Delete RdbStore failed, err: " + err) - return - } - console.log("Delete RdbStore successfully.") -}) -``` - -## data_rdb.deleteRdbStore - -deleteRdbStore(context: Context, name: string): Promise<void> - -使用指定的数据库文件配置删除数据库,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------- | ---- | ------------------------------------------------------------ | -| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | -| name | string | 是 | 数据库名称。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------- | ------------------------- | -| Promise<void> | 无返回结果的Promise对象。 | - -**示例:** - -FA模型示例: - -```js -// 获取context -import featureAbility from '@ohos.ability.featureAbility' -let context = featureAbility.getContext() - -// 获取context后调用deleteRdbStore -let promise = data_rdb.deleteRdbStore(context, "RdbTest.db") -promise.then(() => { - console.log("Delete RdbStore successfully.") -}).catch((err) => { - console.info("Delete RdbStore failed, err: " + err) -}) -``` - -Stage模型示例: - -```ts -// 获取context -import Ability from '@ohos.application.Ability' -let context -class MainAbility extends Ability{ - onWindowStageCreate(windowStage){ - context = this.context - } -} - -// 获取context后调用deleteRdbStore -let promise = data_rdb.deleteRdbStore(context, "RdbTest.db") -promise.then(()=>{ - console.log("Delete RdbStore successfully.") -}).catch((err) => { - console.info("Delete RdbStore failed, err: " + err) -}) -``` - -## RdbPredicatesV99+ - -表示关系型数据库(RDB)的谓词。该类确定RDB中条件表达式的值是true还是false。 - - -### constructor9+ - -constructor(name: string) - - -构造函数。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------------ | -| name | string | 是 | 数据库表名。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -``` - -### inDevices9+ - -inDevices(devices: Array<string>): RdbPredicatesV9 - - -同步分布式数据库时连接到组网内指定的远程设备。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------- | ---- | -------------------------- | -| devices | Array<string> | 是 | 指定的组网内的远程设备ID。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.inDevices(['12345678abcde']) -``` - -### inAllDevices9+ - -inAllDevices(): RdbPredicatesV9 - - -同步分布式数据库时连接到组网内所有的远程设备。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesv9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.inAllDevices() -``` - -### equalTo9+ - -equalTo(field: string, value: ValueType): RdbPredicatesV9 - - -配置谓词以匹配数据字段为ValueType且值等于指定值的字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ----------------------- | ---- | ---------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "lisi") -``` - - -### notEqualTo9+ - -notEqualTo(field: string, value: ValueType): RdbPredicatesV9 - - -配置谓词以匹配数据字段为ValueType且值不等于指定值的字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ----------------------- | ---- | ---------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.notEqualTo("NAME", "lisi") -``` - - -### beginWrap9+ - -beginWrap(): RdbPredicatesV9 - - -向谓词添加左括号。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | ------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回带有左括号的Rdb谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "lisi") - .beginWrap() - .equalTo("AGE", 18) - .or() - .equalTo("SALARY", 200.5) - .endWrap() -``` - -### endWrap9+ - -endWrap(): RdbPredicatesV9 - -向谓词添加右括号。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | ------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回带有右括号的Rdb谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "lisi") - .beginWrap() - .equalTo("AGE", 18) - .or() - .equalTo("SALARY", 200.5) - .endWrap() -``` - -### or9+ - -or(): RdbPredicatesV9 - -将或条件添加到谓词中。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | ------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回带有或条件的Rdb谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "Lisa") - .or() - .equalTo("NAME", "Rose") -``` - -### and9+ - -and(): RdbPredicatesV9 - -向谓词添加和条件。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | ------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回带有和条件的Rdb谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "Lisa") - .and() - .equalTo("SALARY", 200.5) -``` - -### contains9+ - -contains(field: string, value: string): RdbPredicatesV9 - -配置谓词以匹配数据字段为string且value包含指定值的字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ---------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | string | 是 | 指示要与谓词匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.contains("NAME", "os") -``` - -### beginsWith9+ - -beginsWith(field: string, value: string): RdbPredicatesV9 - -配置谓词以匹配数据字段为string且值以指定字符串开头的字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ---------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | string | 是 | 指示要与谓词匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.beginsWith("NAME", "os") -``` - -### endsWith9+ - -endsWith(field: string, value: string): RdbPredicatesV9 - -配置谓词以匹配数据字段为string且值以指定字符串结尾的字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ---------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | string | 是 | 指示要与谓词匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.endsWith("NAME", "se") -``` - -### isNull9+ - -isNull(field: string): RdbPredicatesV9 - -配置谓词以匹配值为null的字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------------------ | -| field | string | 是 | 数据库表中的列名。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例**: - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.isNull("NAME") -``` - -### isNotNull9+ - -isNotNull(field: string): RdbPredicatesV9 - -配置谓词以匹配值不为null的指定字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------------------ | -| field | string | 是 | 数据库表中的列名。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.isNotNull("NAME") -``` - -### like9+ - -like(field: string, value: string): RdbPredicatesV9 - -配置谓词以匹配数据字段为string且值类似于指定字符串的字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ---------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | string | 是 | 指示要与谓词匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.like("NAME", "%os%") -``` - -### glob9+ - -glob(field: string, value: string): RdbPredicatesV9 - -配置RdbPredicatesV9匹配数据字段为string的指定字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------------------------------------------------------------ | -| field | string | 是 | 数据库表中的列名。 | -| value | string | 是 | 指示要与谓词匹配的值。
支持通配符,*表示0个、1个或多个数字或字符,?表示1个数字或字符。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.glob("NAME", "?h*g") -``` - -### between9+ - -between(field: string, low: ValueType, high: ValueType): RdbPredicatesV9 - -将谓词配置为匹配数据字段为ValueType且value在给定范围内的指定字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ----------------------- | ---- | -------------------------- | -| field | string | 是 | 数据库表中的列名。 | -| low | [ValueType](#valuetype) | 是 | 指示与谓词匹配的最小值。 | -| high | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的最大值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.between("AGE", 10, 50) -``` - -### notBetween9+ - -notBetween(field: string, low: ValueType, high: ValueType): RdbPredicatesV9 - -配置RdbPredicatesV9以匹配数据字段为ValueType且value超出给定范围的指定字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ----------------------- | ---- | -------------------------- | -| field | string | 是 | 数据库表中的列名。 | -| low | [ValueType](#valuetype) | 是 | 指示与谓词匹配的最小值。 | -| high | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的最大值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.notBetween("AGE", 10, 50) -``` - -### greaterThan9+ - -greaterThan(field: string, value: ValueType): RdbPredicatesV9 - -配置谓词以匹配数据字段为ValueType且值大于指定值的字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ----------------------- | ---- | ---------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.greaterThan("AGE", 18) -``` - -### lessThan9+ - -lessThan(field: string, value: ValueType): RdbPredicatesV9 - -配置谓词以匹配数据字段为valueType且value小于指定值的字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ----------------------- | ---- | ---------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.lessThan("AGE", 20) -``` - -### greaterThanOrEqualTo9+ - -greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicatesV9 - -配置谓词以匹配数据字段为ValueType且value大于或等于指定值的字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ----------------------- | ---- | ---------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.greaterThanOrEqualTo("AGE", 18) -``` - -### lessThanOrEqualTo9+ - -lessThanOrEqualTo(field: string, value: ValueType): RdbPredicatesV9 - -配置谓词以匹配数据字段为ValueType且value小于或等于指定值的字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ----------------------- | ---- | ---------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | [ValueType](#valuetype) | 是 | 指示要与谓词匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.lessThanOrEqualTo("AGE", 20) -``` - -### orderByAsc9+ - -orderByAsc(field: string): RdbPredicatesV9 - -配置谓词以匹配其值按升序排序的列。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------------------ | -| field | string | 是 | 数据库表中的列名。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.orderByAsc("NAME") -``` - -### orderByDesc9+ - -orderByDesc(field: string): RdbPredicatesV9 - -配置谓词以匹配其值按降序排序的列。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------------------ | -| field | string | 是 | 数据库表中的列名。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.orderByDesc("AGE") -``` - -### distinct9+ - -distinct(): RdbPredicatesV9 - -配置谓词以过滤重复记录并仅保留其中一个。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | ------------------------------ | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回可用于过滤重复记录的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "Rose").distinct() -``` - -### limitAs9+ - -limitAs(value: number): RdbPredicatesV9 - -设置最大数据记录数的谓词。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ---------------- | -| value | number | 是 | 最大数据记录数。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | ------------------------------------ | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回可用于设置最大数据记录数的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "Rose").limitAs(3) -``` - -### offsetAs9+ - -offsetAs(rowOffset: number): RdbPredicatesV9 - -配置RdbPredicatesV9以指定返回结果的起始位置。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| --------- | ------ | ---- | ---------------------------------- | -| rowOffset | number | 是 | 返回结果的起始位置,取值为正整数。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | ------------------------------------ | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回具有指定返回结果起始位置的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "Rose").offsetAs(3) -``` - -### groupBy9+ - -groupBy(fields: Array<string>): RdbPredicatesV9 - -配置RdbPredicatesV9按指定列分组查询结果。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------- | ---- | -------------------- | -| fields | Array<string> | 是 | 指定分组依赖的列名。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | ---------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回分组查询列的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.groupBy(["AGE", "NAME"]) -``` - -### indexedBy9+ - -indexedBy(field: string): RdbPredicatesV9 - -配置RdbPredicatesV9以指定索引列。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | -------------- | -| field | string | 是 | 索引列的名称。 | - -**返回值**: - - -| 类型 | 说明 | -| ------------------------------------ | ------------------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回具有指定索引列的RdbPredicatesV9。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.indexedBy("SALARY_INDEX") -``` - -### in9+ - -in(field: string, value: Array<ValueType>): RdbPredicatesV9 - -配置RdbPredicatesV9以匹配数据字段为ValueType数组且值在给定范围内的指定字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------------------------ | ---- | --------------------------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | Array<[ValueType](#valuetype)> | 是 | 以ValueType型数组形式指定的要匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.in("AGE", [18, 20]) -``` - -### notIn9+ - -notIn(field: string, value: Array<ValueType>): RdbPredicatesV9 - -将RdbPredicatesV9配置为匹配数据字段为ValueType且值超出给定范围的指定字段。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------------------------ | ---- | ------------------------------------- | -| field | string | 是 | 数据库表中的列名。 | -| value | Array<[ValueType](#valuetype)> | 是 | 以ValueType数组形式指定的要匹配的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------ | -------------------------- | -| [RdbPredicatesV9](#rdbpredicatesv99) | 返回与指定字段匹配的谓词。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.notIn("NAME", ["Lisa", "Rose"]) -``` - -## RdbStoreV99+ - -提供管理关系数据库(RDB)方法的接口。 - -在使用以下相关接口前,请使用[executeSql](#executesql)接口初始化数据库表结构和相关数据,具体可见[关系型数据库开发指导](../../database/database-relational-guidelines.md)。 - -### insert9+ - -insert(table: string, values: ValuesBucket, callback: AsyncCallback<number>):void - -向目标表中插入一行数据,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------- | ---- | ---------------------------------------------------------- | -| table | string | 是 | 指定的目标表名。 | -| values | [ValuesBucket](#valuesbucket) | 是 | 表示要插入到表中的数据行。 | -| callback | AsyncCallback<number> | 是 | 指定callback回调函数。如果操作成功,返回行ID;否则返回-1。 | - -**示例:** - -```js -const valueBucket = { - "NAME": "Lisa", - "AGE": 18, - "SALARY": 100.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), -} -rdbStoreV9.insert("EMPLOYEE", valueBucket, function (status, rowId) { - if (status) { - console.log("Insert is failed"); - return; - } - console.log("Insert is successful, rowId = " + rowId); -}) -``` - -### insert9+ - -insert(table: string, values: ValuesBucket):Promise<number> - -向目标表中插入一行数据,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ----------------------------- | ---- | -------------------------- | -| table | string | 是 | 指定的目标表名。 | -| values | [ValuesBucket](#valuesbucket) | 是 | 表示要插入到表中的数据行。 | - -**返回值**: - -| 类型 | 说明 | -| --------------------- | ------------------------------------------------- | -| Promise<number> | Promise对象。如果操作成功,返回行ID;否则返回-1。 | - -**示例:** - -```js -const valueBucket = { - "NAME": "Lisa", - "AGE": 18, - "SALARY": 100.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), -} -let promise = rdbStoreV9.insert("EMPLOYEE", valueBucket) -promise.then((rowId) => { - console.log("Insert is successful, rowId = " + rowId); -}).catch((status) => { - console.log("Insert is failed"); -}) -``` - -### batchInsert9+ - -batchInsert(table: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>):void - -向目标表中插入一组数据,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ | -| table | string | 是 | 指定的目标表名。 | -| values | Array<[ValuesBucket](#valuesbucket)> | 是 | 表示要插入到表中的一组数据。 | -| callback | AsyncCallback<number> | 是 | 指定callback回调函数。如果操作成功,返回插入的数据个数,否则返回-1。 | - -**示例:** - -```js -const valueBucket1 = { - "NAME": "Lisa", - "AGE": 18, - "SALARY": 100.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]) -} -const valueBucket2 = { - "NAME": "Jack", - "AGE": 19, - "SALARY": 101.5, - "CODES": new Uint8Array([6, 7, 8, 9, 10]) -} -const valueBucket3 = { - "NAME": "Tom", - "AGE": 20, - "SALARY": 102.5, - "CODES": new Uint8Array([11, 12, 13, 14, 15]) -} - -let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); -rdbStoreV9.batchInsert("EMPLOYEE", valueBuckets, function(status, insertNum) { - if (status) { - console.log("batchInsert is failed, status = " + status); - return; - } - console.log("batchInsert is successful, the number of values that were inserted = " + insertNum); -}) -``` - -### batchInsert9+ - -batchInsert(table: string, values: Array<ValuesBucket>):Promise<number> - -向目标表中插入一组数据,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------------------------------ | ---- | ---------------------------- | -| table | string | 是 | 指定的目标表名。 | -| values | Array<[ValuesBucket](#valuesbucket)> | 是 | 表示要插入到表中的一组数据。 | - -**返回值**: - -| 类型 | 说明 | -| --------------------- | ----------------------------------------------------------- | -| Promise<number> | Promise对象。如果操作成功,返回插入的数据个数,否则返回-1。 | - -**示例:** - -```js -const valueBucket1 = { - "NAME": "Lisa", - "AGE": 18, - "SALARY": 100.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]) -} -const valueBucket2 = { - "NAME": "Jack", - "AGE": 19, - "SALARY": 101.5, - "CODES": new Uint8Array([6, 7, 8, 9, 10]) -} -const valueBucket3 = { - "NAME": "Tom", - "AGE": 20, - "SALARY": 102.5, - "CODES": new Uint8Array([11, 12, 13, 14, 15]) -} - -let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); -let promise = rdbStoreV9.batchInsert("EMPLOYEE", valueBuckets); -promise.then((insertNum) => { - console.log("batchInsert is successful, the number of values that were inserted = " + insertNum); -}).catch((status) => { - console.log("batchInsert is failed, status = " + status); -}) -``` - -### update9+ - -update(values: ValuesBucket, predicates: RdbPredicatesV9, callback: AsyncCallback<number>):void - -根据RdbPredicatesV9的指定实例对象更新数据库中的数据,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ | -| values | [ValuesBucket](#valuesbucket) | 是 | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 | -| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | 是 | RdbPredicatesV9的实例对象指定的更新条件。 | -| callback | AsyncCallback<number> | 是 | 指定的callback回调方法。返回受影响的行数。 | - -**示例:** - -```js -const valueBucket = { - "NAME": "Rose", - "AGE": 22, - "SALARY": 200.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), -} -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "Lisa") -rdbStoreV9.update(valueBucket, predicatesV9, function (err, ret) { - if (err) { - console.info("Updated failed, err: " + err) - return - } - console.log("Updated row count: " + ret) -}) -``` - -### update9+ - -update(values: ValuesBucket, predicates: RdbPredicatesV9):Promise<number> - -根据RdbPredicatesV9的指定实例对象更新数据库中的数据,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ | -| values | [ValuesBucket](#valuesbucket) | 是 | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 | -| predicatesV9 | [RdbPredicatesV9](#rdbpredicatesv99) | 是 | RdbPredicatesV9的实例对象指定的更新条件。 | - -**返回值**: - -| 类型 | 说明 | -| --------------------- | ----------------------------------------- | -| Promise<number> | 指定的Promise回调方法。返回受影响的行数。 | - -**示例:** - -```js -const valueBucket = { - "NAME": "Rose", - "AGE": 22, - "SALARY": 200.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), -} -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "Lisa") -let promise = rdbStoreV9.update(valueBucket, predicatesV9) -promise.then(async (ret) => { - console.log("Updated row count: " + ret) -}).catch((err) => { - console.info("Updated failed, err: " + err) -}) -``` - -### update9+ - -update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>):void - -根据DataSharePredicates的指定实例对象更新数据库中的数据,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**系统接口:** 此接口为系统接口。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| table | string | 是 | 指定的目标表名。 | -| values | [ValuesBucket](#valuesbucket) | 是 | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 | -| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的更新条件。 | -| callback | AsyncCallback<number> | 是 | 指定的callback回调方法。返回受影响的行数。 | - -**示例:** - -```js -import dataSharePredicates from '@ohos.data.dataSharePredicates' -const valueBucket = { - "NAME": "Rose", - "AGE": 22, - "SALARY": 200.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), -} -let predicates = new dataSharePredicates.DataSharePredicates() -predicates.equalTo("NAME", "Lisa") -rdbStoreV9.update("EMPLOYEE", valueBucket, predicates, function (err, ret) { - if (err) { - console.info("Updated failed, err: " + err) - return - } - console.log("Updated row count: " + ret) -}) -``` - -### update9+ - -update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates):Promise<number> - -根据DataSharePredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**系统接口:** 此接口为系统接口。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| table | string | 是 | 指定的目标表名。 | -| values | [ValuesBucket](#valuesbucket) | 是 | values指示数据库中要更新的数据行。键值对与数据库表的列名相关联。 | -| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的更新条件。 | - -**返回值**: - -| 类型 | 说明 | -| --------------------- | ----------------------------------------- | -| Promise<number> | 指定的Promise回调方法。返回受影响的行数。 | - -**示例:** - -```js -import dataSharePredicates from '@ohos.data.dataSharePredicates' -const valueBucket = { - "NAME": "Rose", - "AGE": 22, - "SALARY": 200.5, - "CODES": new Uint8Array([1, 2, 3, 4, 5]), -} -let predicates = new dataSharePredicates.DataSharePredicates() -predicates.equalTo("NAME", "Lisa") -let promise = rdbStoreV9.update("EMPLOYEE", valueBucket, predicates) -promise.then(async (ret) => { - console.log("Updated row count: " + ret) -}).catch((err) => { - console.info("Updated failed, err: " + err) -}) -``` - -### delete9+ - -delete(predicates: RdbPredicatesV9, callback: AsyncCallback<number>):void - -根据RdbPredicatesV9的指定实例对象从数据库中删除数据,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------ | ---- | ----------------------------------------- | -| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | 是 | RdbPredicatesV9的实例对象指定的删除条件。 | -| callback | AsyncCallback<number> | 是 | 指定callback回调函数。返回受影响的行数。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "Lisa") -rdbStoreV9.delete(predicatesV9, function (err, rows) { - if (err) { - console.info("Delete failed, err: " + err) - return - } - console.log("Delete rows: " + rows) -}) -``` - -### delete9+ - -delete(predicates: RdbPredicatesV9):Promise<number> - -根据RdbPredicatesV9的指定实例对象从数据库中删除数据,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------ | ---- | ----------------------------------------- | -| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | 是 | RdbPredicatesV9的实例对象指定的删除条件。 | - -**返回值**: - -| 类型 | 说明 | -| --------------------- | ------------------------------- | -| Promise<number> | Promise对象。返回受影响的行数。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "Lisa") -let promise = rdbStoreV9.delete(predicatesV9) -promise.then((rows) => { - console.log("Delete rows: " + rows) -}).catch((err) => { - console.info("Delete failed, err: " + err) -}) -``` - -### delete9+ - -delete(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>):void - -根据DataSharePredicates的指定实例对象从数据库中删除数据,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**系统接口:** 此接口为系统接口。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- | -| table | string | 是 | 指定的目标表名。 | -| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的删除条件。 | -| callback | AsyncCallback<number> | 是 | 指定callback回调函数。返回受影响的行数。 | - -**示例:** - -```js -import dataSharePredicates from '@ohos.data.dataSharePredicates' -let predicates = new dataSharePredicates.DataSharePredicates() -predicates.equalTo("NAME", "Lisa") -rdbStoreV9.delete("EMPLOYEE", predicates, function (err, rows) { - if (err) { - console.info("Delete failed, err: " + err) - return - } - console.log("Delete rows: " + rows) -}) -``` - -### delete9+ - -delete(table: string, predicates: dataSharePredicates.DataSharePredicates):Promise<number> - -根据DataSharePredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**系统接口:** 此接口为系统接口。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- | -| table | string | 是 | 指定的目标表名。 | -| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的删除条件。 | - -**返回值**: - -| 类型 | 说明 | -| --------------------- | ------------------------------- | -| Promise<number> | Promise对象。返回受影响的行数。 | - -**示例:** - -```js -import dataSharePredicates from '@ohos.data.dataSharePredicates' -let predicates = new dataSharePredicates.DataSharePredicates() -predicates.equalTo("NAME", "Lisa") -let promise = rdbStoreV9.delete("EMPLOYEE", predicates) -promise.then((rows) => { - console.log("Delete rows: " + rows) -}).catch((err) => { - console.info("Delete failed, err: " + err) -}) -``` - -### query9+ - -query(predicates: RdbPredicatesV9, columns: Array<string>, callback: AsyncCallback<ResultSetV9>):void - -根据指定条件查询数据库中的数据,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | -| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | 是 | RdbPredicatesV9的实例对象指定的查询条件。 | -| columns | Array<string> | 是 | 表示要查询的列。如果值为空,则查询应用于所有列。 | -| callback | AsyncCallback<[ResultSetV9](js-apis-data-resultset.md)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSetV9对象。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "Rose") -rdbStoreV9.query(predicatesV9, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSetV9) { - if (err) { - console.info("Query failed, err: " + err) - return - } - console.log("ResultSet column names: " + resultSetV9.columnNames) - console.log("ResultSet column count: " + resultSetV9.columnCount) -}) -``` - -### query9+ - -query(predicates: RdbPredicatesV9, columns?: Array<string>):Promise<ResultSetV9> - -根据指定条件查询数据库中的数据,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | -| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | 是 | RdbPredicatesV9的实例对象指定的查询条件。 | -| columns | Array<string> | 否 | 表示要查询的列。如果值为空,则查询应用于所有列。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------------------------- | -------------------------------------------------- | -| Promise<[ResultSetV9](js-apis-data-resultset.md)> | Promise对象。如果操作成功,则返回ResultSetV9对象。 | - -**示例:** - - ```js -let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE") -predicatesV9.equalTo("NAME", "Rose") -let promise = rdbStoreV9.query(predicatesV9, ["ID", "NAME", "AGE", "SALARY", "CODES"]) -promise.then((resultSetV9) => { - console.log("ResultSet column names: " + resultSetV9.columnNames) - console.log("ResultSet column count: " + resultSetV9.columnCount) -}).catch((err) => { - console.info("Query failed, err: " + err) -}) - ``` - -### query9+ - -query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<ResultSetV9>):void - -根据指定条件查询数据库中的数据,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**系统接口:** 此接口为系统接口。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | -| table | string | 是 | 指定的目标表名。 | -| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的查询条件。 | -| columns | Array<string> | 是 | 表示要查询的列。如果值为空,则查询应用于所有列。 | -| callback | AsyncCallback<[ResultSetV9](js-apis-data-resultset.md)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSetV9对象。 | - -**示例:** - -```js -import dataSharePredicates from '@ohos.data.dataSharePredicates' -let predicates = new dataSharePredicates.DataSharePredicates() -predicates.equalTo("NAME", "Rose") -rdbStoreV9.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSetV9) { - if (err) { - console.info("Query failed, err: " + err) - return - } - console.log("ResultSet column names: " + resultSetV9.columnNames) - console.log("ResultSet column count: " + resultSetV9.columnCount) -}) -``` - -### query9+ - -query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns?: Array<string>):Promise<ResultSetV9> - -根据指定条件查询数据库中的数据,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**系统接口:** 此接口为系统接口。 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ | -| table | string | 是 | 指定的目标表名。 | -| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | DataSharePredicates的实例对象指定的查询条件。 | -| columns | Array<string> | 否 | 表示要查询的列。如果值为空,则查询应用于所有列。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------------------------- | -------------------------------------------------- | -| Promise<[ResultSetV9](js-apis-data-resultset.md)> | Promise对象。如果操作成功,则返回ResultSetV9对象。 | - -**示例:** - -```js -import dataSharePredicates from '@ohos.data.dataSharePredicates' -let predicates = new dataSharePredicates.DataSharePredicates() -predicates.equalTo("NAME", "Rose") -let promise = rdbStoreV9.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) -promise.then((resultSetV9) => { - console.log("ResultSet column names: " + resultSetV9.columnNames) - console.log("ResultSet column count: " + resultSetV9.columnCount) -}).catch((err) => { - console.info("Query failed, err: " + err) -}) -``` - -### remoteQuery9+ - -remoteQuery(device: string, table: string, predicates: RdbPredicatesV9, columns: Array<string> , callback: AsyncCallback<ResultSetV9>): void - -根据指定条件查询远程设备数据库中的数据。使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | -| device | string | 是 | 指定的远程设备的networkId。 | -| table | string | 是 | 指定的目标表名。 | -| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | 是 | RdbPredicatesV9的实例对象,指定查询的条件。 | -| columns | Array<string> | 是 | 表示要查询的列。如果值为空,则查询应用于所有列。 | -| callback | AsyncCallback<[ResultSetV9](js-apis-data-resultset.md#resultset)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSetV9对象。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9('EMPLOYEE') -predicatesV9.greaterThan("id", 0) -rdbStoreV9.remoteQuery("deviceId", "EMPLOYEE", predicatesV9, ["ID", "NAME", "AGE", "SALARY", "CODES"], - function(err, resultSetV9){ - if (err) { - console.info("Failed to remoteQuery, err: " + err) - return - } - console.info("ResultSet column names: " + resultSetV9.columnNames) - console.info("ResultSet column count: " + resultSetV9.columnCount) -}) -``` - -### remoteQuery9+ - -remoteQuery(device: string, table: string, predicates: RdbPredicatesV9, columns: Array<string>): Promise<ResultSetV9> - -根据指定条件查询远程设备数据库中的数据。使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------ | ---- | ------------------------------------------------ | -| device | string | 是 | 指定的远程设备的networkId。 | -| table | string | 是 | 指定的目标表名。 | -| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | 是 | RdbPredicatesV9的实例对象,指定查询的条件。 | -| columns | Array<string> | 是 | 表示要查询的列。如果值为空,则查询应用于所有列。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------------------------------ | -------------------------------------------------- | -| Promise<[ResultSetV9](js-apis-data-resultset.md#resultset)> | Promise对象。如果操作成功,则返回ResultSetV9对象。 | - -**示例:** - -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9('EMPLOYEE') -predicatesV9.greaterThan("id", 0) -let promise = rdbStoreV9.remoteQuery("deviceId", "EMPLOYEE", predicatesV9, ["ID", "NAME", "AGE", "SALARY", "CODES"]) -promise.then((resultSetV9) => { - console.info("ResultSet column names: " + resultSetV9.columnNames) - console.info("ResultSet column count: " + resultSetV9.columnCount) -}).catch((err) => { - console.info("Failed to remoteQuery , err: " + err) -}) -``` - -### querySql9+ - -querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSetV9>):void - -根据指定SQL语句查询数据库中的数据,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | -| sql | string | 是 | 指定要执行的SQL语句。 | -| bindArgs | Array<[ValueType](#valuetype)> | 是 | SQL语句中参数的值。 | -| callback | AsyncCallback<[ResultSetV9](js-apis-data-resultset.md)> | 是 | 指定callback回调函数。如果操作成功,则返回ResultSetV9对象。 | - -**示例:** - -```js -rdbStoreV9.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSetV9) { - if (err) { - console.info("Query failed, err: " + err) - return - } - console.log("ResultSet column names: " + resultSetV9.columnNames) - console.log("ResultSet column count: " + resultSetV9.columnCount) -}) -``` - -### querySql9+ - -querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSetV9> - -根据指定SQL语句查询数据库中的数据,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------ | ---- | --------------------- | -| sql | string | 是 | 指定要执行的SQL语句。 | -| bindArgs | Array<[ValueType](#valuetype)> | 否 | SQL语句中参数的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------------------------------------------- | -------------------------------------------------- | -| Promise<[ResultSetV9](js-apis-data-resultset.md)> | Promise对象。如果操作成功,则返回ResultSetV9对象。 | - -**示例:** - -```js -let promise = rdbStoreV9.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo']) -promise.then((resultSetV9) => { - console.log("ResultSet column names: " + resultSetV9.columnNames) - console.log("ResultSet column count: " + resultSetV9.columnCount) -}).catch((err) => { - console.info("Query failed, err: " + err) -}) -``` - -### executeSql9+ - -executeSql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<void>):void - -执行包含指定参数但不返回值的SQL语句,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------ | ---- | ---------------------- | -| sql | string | 是 | 指定要执行的SQL语句。 | -| bindArgs | Array<[ValueType](#valuetype)> | 是 | SQL语句中参数的值。 | -| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | - -**示例:** - -```js -const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" -rdbStoreV9.executeSql(SQL_CREATE_TABLE, null, function(err) { - if (err) { - console.info("ExecuteSql failed, err: " + err) - return - } - console.info('Create table done.') -}) -``` - -### executeSql9+ - -executeSql(sql: string, bindArgs?: Array<ValueType>):Promise<void> - -执行包含指定参数但不返回值的SQL语句,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------ | ---- | --------------------- | -| sql | string | 是 | 指定要执行的SQL语句。 | -| bindArgs | Array<[ValueType](#valuetype)> | 否 | SQL语句中参数的值。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------- | ------------------------- | -| Promise<void> | 无返回结果的Promise对象。 | - -**示例:** - -```js -const SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)" -let promise = rdbStoreV9.executeSql(SQL_CREATE_TABLE) -promise.then(() => { - console.info('Create table done.') -}).catch((err) => { - console.info("ExecuteSql failed, err: " + err) -}) -``` - -### beginTransaction9+ - -beginTransaction():void - -在开始执行SQL语句之前,开始事务。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -let context = featureAbility.getContext() -const STORE_CONFIG = { name: "RdbTest.db", - securityLevel: data_rdb.SecurityLevel.S1} -data_rdb.getRdbStoreV9(context, STORE_CONFIG, 1, async function (err, rdbStoreV9) { - rdbStoreV9.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": new Uint8Array([1, 2, 3]), - } - await rdbStoreV9.insert("test", valueBucket) - rdbStoreV9.commit() -}) -``` - -### commit9+ - -commit():void - -提交已执行的SQL语句。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -let context = featureAbility.getContext() -const STORE_CONFIG = { name: "RdbTest.db", - securityLevel: data_rdb.SecurityLevel.S1} -data_rdb.getRdbStoreV9(context, STORE_CONFIG, 1, async function (err, rdbStoreV9) { - rdbStoreV9.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": new Uint8Array([1, 2, 3]), - } - await rdbStoreV9.insert("test", valueBucket) - rdbStoreV9.commit() -}) -``` - -### rollBack9+ - -rollBack():void - -回滚已经执行的SQL语句。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**示例:** - -```js -import featureAbility from '@ohos.ability.featureAbility' -let context = featureAbility.getContext() -const STORE_CONFIG = { name: "RdbTest.db", - securityLevel: data_rdb.SecurityLevel.S1} -data_rdb.getRdbStoreV9(context, STORE_CONFIG, 1, async function (err, rdbStoreV9) { - try { - rdbStoreV9.beginTransaction() - const valueBucket = { - "id": 1, - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": new Uint8Array([1, 2, 3]), - } - await rdbStoreV9.insert("test", valueBucket) - rdbStoreV9.commit() - } catch (e) { - rdbStoreV9.rollBack() - } -}) -``` - -### backup9+ - -backup(destName:string, callback: AsyncCallback<void>):void - -以指定名称备份数据库,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------- | ---- | ------------------------ | -| destName | string | 是 | 指定数据库的备份文件名。 | -| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | - -**示例:** - -```js -rdbStoreV9.backup("dbBackup.db", function(err) { - if (err) { - console.info('Backup failed, err: ' + err) - return - } - console.info('Backup success.') -}) -``` - -### backup9+ - -backup(destName:string): Promise<void> - -以指定名称备份数据库,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------ | ---- | ------------------------ | -| destName | string | 是 | 指定数据库的备份文件名。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------- | ------------------------- | -| Promise<void> | 无返回结果的Promise对象。 | - -**示例:** - -```js -let promiseBackup = rdbStoreV9.backup("dbBackup.db") -promiseBackup.then(()=>{ - console.info('Backup success.') -}).catch((err)=>{ - console.info('Backup failed, err: ' + err) -}) -``` - -### restore9+ - -restore(srcName:string, callback: AsyncCallback<void>):void - -从指定的数据库备份文件恢复数据库,使用callback异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------- | ---- | ------------------------ | -| srcName | string | 是 | 指定数据库的备份文件名。 | -| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | - -**示例:** - -```js -rdbStoreV9.restore("dbBackup.db", function(err) { - if (err) { - console.info('Restore failed, err: ' + err) - return - } - console.info('Restore success.') -}) -``` - -### restore9+ - -restore(srcName:string): Promise<void> - -从指定的数据库备份文件恢复数据库,使用Promise异步回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------ | ---- | ------------------------ | -| srcName | string | 是 | 指定数据库的备份文件名。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------- | ------------------------- | -| Promise<void> | 无返回结果的Promise对象。 | - -**示例:** - -```js -let promiseRestore = rdbStoreV9.restore("dbBackup.db") -promiseRestore.then(()=>{ - console.info('Restore success.') -}).catch((err)=>{ - console.info('Restore failed, err: ' + err) -}) -``` - -### setDistributedTables9+ - -setDistributedTables(tables: Array<string>, callback: AsyncCallback<void>): void - -设置分布式列表,使用callback异步回调。 - -**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------- | ---- | ---------------------- | -| tables | Array<string> | 是 | 要设置的分布式列表表名 | -| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | - -**示例:** - -```js -rdbStoreV9.setDistributedTables(["EMPLOYEE"], function (err) { - if (err) { - console.info('SetDistributedTables failed, err: ' + err) - return - } - console.info('SetDistributedTables successfully.') -}) -``` - -### setDistributedTables9+ - - setDistributedTables(tables: Array<string>): Promise<void> - -设置分布式列表,使用Promise异步回调。 - -**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------- | ---- | ------------------------ | -| tables | Array<string> | 是 | 要设置的分布式列表表名。 | - -**返回值**: - -| 类型 | 说明 | -| ------------------- | ------------------------- | -| Promise<void> | 无返回结果的Promise对象。 | - -**示例:** - -```js -let promise = rdbStoreV9.setDistributedTables(["EMPLOYEE"]) -promise.then(() => { - console.info("SetDistributedTables successfully.") -}).catch((err) => { - console.info("SetDistributedTables failed, err: " + err) -}) -``` -### obtainDistributedTableName9+ +## 导入模块 -obtainDistributedTableName(device: string, table: string, callback: AsyncCallback<string>): void +```js +import data_rdb from '@ohos.data.rdb'; +``` +## data_rdb.getRdbStore -根据本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名, 使用callback异步回调。 +getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): void -**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC +获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用callback异步回调。 **系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | --------------------------- | ---- | ------------------------------------------------------------ | -| device | string | 是 | 远程设备 。 | -| table | string | 是 | 本地表名。 | -| callback | AsyncCallback<string> | 是 | 指定的callback回调函数。如果操作成功,返回远程设备的分布式表名。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ | +| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | +| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 | +| version | number | 是 | 数据库版本。
目前暂不支持通过version自动识别数据库升级降级操作,只能由开发者自行维护。 | +| callback | AsyncCallback<[RdbStore](#rdbstore)> | 是 | 指定callback回调函数,返回RdbStore对象。 | **示例:** +FA模型示例: + ```js -rdbStoreV9.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, tableName) { +// 获取context +import featureAbility from '@ohos.ability.featureAbility' +let context = featureAbility.getContext() + +// 获取context后调用getRdbStore +const STORE_CONFIG = { name: "RdbTest.db"} +data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) { if (err) { - console.info('ObtainDistributedTableName failed, err: ' + err) + console.info("Get RdbStore failed, err: " + err) return } - console.info('ObtainDistributedTableName successfully, tableName=.' + tableName) + console.log("Get RdbStore successfully.") }) ``` -### obtainDistributedTableName9+ +Stage模型示例: - obtainDistributedTableName(device: string, table: string): Promise<string> +```ts +// 获取context +import UIAbility from '@ohos.app.ability.UIAbility'; -根据本地表名获取指定远程设备的分布式表名。在查询远程设备数据库时,需要使用分布式表名,使用Promise异步回调。 +let context; +class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage){ + context = this.context + } +} -**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC +// 获取context后调用getRdbStore +const STORE_CONFIG = { name: "RdbTest.db"} +data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) { + if (err) { + console.info("Get RdbStore failed, err: " + err) + return + } + console.log("Get RdbStore successfully.") +}) +``` + +## data_rdb.getRdbStore + +getRdbStore(context: Context, config: StoreConfig, version: number): Promise<RdbStore> + +获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用Promise异步回调。 **系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ---------- | -| device | string | 是 | 远程设备。 | -| table | string | 是 | 本地表名。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | --------------------------- | ---- | ------------------------------------------------------------ | +| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | +| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 | +| version | number | 是 | 数据库版本。
目前暂不支持通过version自动识别数据库升级降级操作,只能由开发者自行维护。 | **返回值**: -| 类型 | 说明 | -| --------------------- | ----------------------------------------------------- | -| Promise<string> | Promise对象。如果操作成功,返回远程设备的分布式表名。 | +| 类型 | 说明 | +| ------------------------------------ | ------------------------------- | +| Promise<[RdbStore](#rdbstore)> | Promise对象。返回RdbStore对象。 | **示例:** +FA模型示例: + ```js -let promise = rdbStoreV9.obtainDistributedTableName("12345678abcde", "EMPLOYEE") -promise.then((tableName) => { - console.info('ObtainDistributedTableName successfully, tableName= ' + tableName) +// 获取context +import featureAbility from '@ohos.ability.featureAbility' +let context = featureAbility.getContext() + +// 获取context后调用getRdbStore +const STORE_CONFIG = { name: "RdbTest.db" } +let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1); +promise.then(async (rdbStore) => { + console.log("Get RdbStore successfully.") }).catch((err) => { - console.info('ObtainDistributedTableName failed, err: ' + err) + console.log("Get RdbStore failed, err: " + err) }) ``` -### sync9+ - -sync(mode: SyncMode, predicates: RdbPredicatesV9, callback: AsyncCallback<Array<[string, number]>>): void - -在设备之间同步数据, 使用callback异步回调。 - -**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ | -| mode | [SyncMode](#syncmode8) | 是 | 指同步模式。该值可以是推、拉。 | -| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | 是 | 约束同步数据和设备。 | -| callback | AsyncCallback<Array<[string, number]>> | 是 | 指定的callback回调函数,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 | +Stage模型示例: -**示例:** +```ts +// 获取context +import UIAbility from '@ohos.app.ability.UIAbility'; -```js -let predicatesV9 = new data_rdb.RdbPredicatesV9('EMPLOYEE') -predicatesV9.inDevices(['12345678abcde']) -rdbStoreV9.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicatesV9, function (err, result) { - if (err) { - console.log('Sync failed, err: ' + err) - return - } - console.log('Sync done.') - for (let i = 0; i < result.length; i++) { - console.log('device=' + result[i][0] + ' status=' + result[i][1]) +let context; +class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage){ + context = this.context } +} + +// 获取context后调用getRdbStore +const STORE_CONFIG = { name: "RdbTest.db" } +let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1); +promise.then(async (rdbStore) => { + console.log("Get RdbStore successfully.") +}).catch((err) => { + console.log("Get RdbStore failed, err: " + err) }) ``` -### sync9+ - - sync(mode: SyncMode, predicates: RdbPredicatesV9): Promise<Array<[string, number]>> +## data_rdb.deleteRdbStore -在设备之间同步数据,使用Promise异步回调。 +deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void>): void -**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC +删除数据库,使用callback异步回调。 **系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------------------------------------ | ---- | ------------------------------ | -| mode | [SyncMode](#syncmode8) | 是 | 指同步模式。该值可以是推、拉。 | -| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | 是 | 约束同步数据和设备。 | - -**返回值**: - -| 类型 | 说明 | -| -------------------------------------------- | ------------------------------------------------------------ | -| Promise<Array<[string, number]>> | Promise对象,用于向调用者发送同步结果。string:设备ID;number:每个设备同步状态,0表示成功,其他值表示失败。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------- | ---- | ------------------------------------------------------------ | +| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | +| name | string | 是 | 数据库名称。 | +| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 | **示例:** +FA模型示例: + ```js -let predicatesV9 = new data_rdb.RdbPredicatesV9('EMPLOYEE') -predicatesV9.inDevices(['12345678abcde']) -let promise = rdbStoreV9.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicatesV9) -promise.then((resultSetV9) =>{ - console.log('Sync done.') - for (let i = 0; i < resultSetV9.length; i++) { - console.log('device=' + resultSetV9[i][0] + ' status=' + resultSetV9[i][1]) +// 获取context +import featureAbility from '@ohos.ability.featureAbility' +let context = featureAbility.getContext() + +// 获取context后调用deleteRdbStore +data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) { + if (err) { + console.info("Delete RdbStore failed, err: " + err) + return } -}).catch((err) => { - console.log('Sync failed') + console.log("Delete RdbStore successfully.") }) ``` -### on('dataChange')9+ - -on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void - -注册数据库的观察者。当分布式数据库中的数据发生更改时,将调用回调。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------------- | ---- | ------------------------------------------- | -| event | string | 是 | 取值为'dataChange',表示数据更改。 | -| type | [SubscribeType](#subscribetype8) | 是 | 指在{@code SubscribeType}中定义的订阅类型。 | -| observer | Callback<Array<string>> | 是 | 指分布式数据库中数据更改事件的观察者。 | +Stage模型示例: -**示例:** +```ts +// 获取context +import UIAbility from '@ohos.app.ability.UIAbility'; -```js -function storeObserver(devices) { - for (let i = 0; i < devices.length; i++) { - console.log('device=' + devices[i] + ' data changed') +let context; +class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage){ + context = this.context } } -try { - rdbStoreV9.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) -} catch (err) { - console.log('Register observer failed') -} + +// 获取context后调用deleteRdbStore +data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) { + if (err) { + console.info("Delete RdbStore failed, err: " + err) + return + } + console.log("Delete RdbStore successfully.") +}) ``` -### off('dataChange')9+ +## data_rdb.deleteRdbStore -off(event:'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void +deleteRdbStore(context: Context, name: string): Promise<void> -从数据库中删除指定类型的指定观察者, 使用callback异步回调。 +使用指定的数据库文件配置删除数据库,使用Promise异步回调。 **系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core -**参数:** +**参数** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------------- | ---- | ------------------------------------------- | -| event | string | 是 | 取值为'dataChange',表示数据更改。 | -| type | [SubscribeType](#subscribetype8) | 是 | 指在{@code SubscribeType}中定义的订阅类型。 | -| observer | Callback<Array<string>> | 是 | 指已注册的数据更改观察者。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------- | ---- | ------------------------------------------------------------ | +| context | Context | 是 | 应用的上下文。
FA模型的应用Context定义见[Context](js-apis-inner-app-context.md)。
Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 | +| name | string | 是 | 数据库名称。 | -**示例:** +**返回值**: -```js -function storeObserver(devices) { - for (let i = 0; i < devices.length; i++) { - console.log('device=' + devices[i] + ' data changed') - } -} -try { - rdbStoreV9.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) -} catch (err) { - console.log('Unregister observer failed') -} -``` +| 类型 | 说明 | +| ------------------- | ------------------------- | +| Promise<void> | 无返回结果的Promise对象。 | -## StoreConfigV99+ +**示例:** -管理关系数据库配置。 +FA模型示例: -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core +```js +// 获取context +import featureAbility from '@ohos.ability.featureAbility' +let context = featureAbility.getContext() -| 名称 | 类型 | 必填 | 说明 | -| ------------- | ------------- | ---- | --------------------------------------------------------- | -| name | string | 是 | 数据库文件名。 | -| securityLevel | SecurityLevel | 是 | 设置数据库安全级别 | -| encrypt | boolean | 否 | 指定数据库是否加密。
true:加密。
false:非加密。 | +// 获取context后调用deleteRdbStore +let promise = data_rdb.deleteRdbStore(context, "RdbTest.db") +promise.then(() => { + console.log("Delete RdbStore successfully.") +}).catch((err) => { + console.info("Delete RdbStore failed, err: " + err) +}) +``` -## SecurityLevel9+ +Stage模型示例: -数据库的安全级别枚举。 +```ts +// 获取context +import UIAbility from '@ohos.app.ability.UIAbility'; -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core +let context; +class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage){ + context = this.context + } +} -| 名称 | 值 | 说明 | -| ---- | ---- | ------------------------------------------------------------ | -| S1 | 1 | 表示数据库的安全级别为低级别,当数据泄露时会产生较低影响。例如,包含壁纸等系统数据的数据库。 | -| S2 | 2 | 表示数据库的安全级别为中级别,当数据泄露时会产生较大影响。例如,包含录音、视频等用户生成数据或通话记录等信息的数据库。 | -| S3 | 3 | 表示数据库的安全级别为高级别,当数据泄露时会产生重大影响。例如,包含用户运动、健康、位置等信息的数据库。 | -| S4 | 4 | 表示数据库的安全级别为关键级别,当数据泄露时会产生严重影响。例如,包含认证凭据、财务数据等信息的数据库。 | +// 获取context后调用deleteRdbStore +let promise = data_rdb.deleteRdbStore(context, "RdbTest.db") +promise.then(()=>{ + console.log("Delete RdbStore successfully.") +}).catch((err) => { + console.info("Delete RdbStore failed, err: " + err) +}) +``` ## ValueType @@ -2700,7 +290,7 @@ try { 指数据库同步模式。 -**系统能力:**SystemCapability.DistributedDataManager.RelationalStore.Core +**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 名称 | 值 | 说明 | | -------------- | ---- | ---------------------------------- | @@ -2711,12 +301,24 @@ try { 描述订阅类型。 +**需要权限:** ohos.permission.DISTRIBUTED_DATASYNC + **系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core | 名称 | 值 | 说明 | | --------------------- | ---- | ------------------ | | SUBSCRIBE_TYPE_REMOTE | 0 | 订阅远程数据更改。 | +## StoreConfig + +管理关系数据库配置。 + +**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| name | string | 是 | 数据库文件名。 | + ## RdbPredicates 表示关系型数据库(RDB)的谓词。该类确定RDB中条件表达式的值是true还是false。 @@ -3552,7 +1154,7 @@ predicates.notIn("NAME", ["Lisa", "Rose"]) 提供管理关系数据库(RDB)方法的接口。 -在使用以下相关接口前,请使用[executeSql](#executesql)接口初始化数据库表结构和相关数据,具体可见[关系型数据库开发指导](../../database/database-relational-guidelines.md)。 +在使用以下相关接口前,请使用[executeSql](#executesql8)接口初始化数据库表结构和相关数据,具体可见[关系型数据库开发指导](../../database/database-relational-guidelines.md)。 ### insert @@ -3753,12 +1355,12 @@ const valueBucket = { } let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Lisa") -rdbStore.update(valueBucket, predicates, function (err, ret) { +rdbStore.update(valueBucket, predicates, function (err, rows) { if (err) { console.info("Updated failed, err: " + err) return } - console.log("Updated row count: " + ret) + console.log("Updated row count: " + rows) }) ``` @@ -3795,8 +1397,8 @@ const valueBucket = { let predicates = new data_rdb.RdbPredicates("EMPLOYEE") predicates.equalTo("NAME", "Lisa") let promise = rdbStore.update(valueBucket, predicates) -promise.then(async (ret) => { - console.log("Updated row count: " + ret) +promise.then(async (rows) => { + console.log("Updated row count: " + rows) }).catch((err) => { console.info("Updated failed, err: " + err) }) @@ -4353,7 +1955,7 @@ on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<stri | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | event | string | 是 | 取值为'dataChange',表示数据更改。 | -| type | [SubscribeType](#subscribetype8) | 是 | 指在{@code SubscribeType}中定义的订阅类型。 | +| type | [SubscribeType](#subscribetype8) | 是 | 订阅类型。 | | observer | Callback<Array<string>> | 是 | 指分布式数据库中数据更改事件的观察者。 | **示例:** @@ -4384,7 +1986,7 @@ off(event:'dataChange', type: SubscribeType, observer: Callback<Array<stri | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | event | string | 是 | 取值为'dataChange',表示数据更改。 | -| type | [SubscribeType](#subscribetype8) | 是 | 指在{@code SubscribeType}中定义的订阅类型。 | +| type | [SubscribeType](#subscribetype8) | 是 | 订阅类型。 | | observer | Callback<Array<string>> | 是 | 指已注册的数据更改观察者。| **示例:** @@ -4401,14 +2003,3 @@ try { console.log('Unregister observer failed') } ``` - -## StoreConfig - -管理关系数据库配置。 - -**系统能力:**SystemCapability.DistributedDataManager.RelationalStore.Core - -| 名称 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| name | string | 是 | 数据库文件名。 | - diff --git a/zh-cn/application-dev/reference/apis/js-apis-data-resultset.md b/zh-cn/application-dev/reference/apis/js-apis-data-resultset.md index be7540c08719a6481210892cb56927b88a8ef50d..01f92571bd0943cd12fd20c4a333e09b5627c570 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-data-resultset.md +++ b/zh-cn/application-dev/reference/apis/js-apis-data-resultset.md @@ -8,536 +8,6 @@ > > 从API Version 9开始,该接口不再维护,推荐使用新接口[@ohos.data.relationalStore#ResultSet](js-apis-data-relationalStore.md#resultset)。 -## ResultSetV99+ - -提供通过查询数据库生成的数据库结果集的访问方法。 - -### 使用说明 - -需要通过[RdbStoreV9.query()](js-apis-data-rdb.md#query)获取resultSetV9对象。 - -```js -import dataRdb from '@ohos.data.rdb'; -let predicatesV9 = new dataRdb.RdbPredicatesV9("EMPLOYEE"); -predicatesV9.equalTo("AGE", 18); -let promise = rdbStoreV9.query(predicatesV9, ["ID", "NAME", "AGE", "SALARY", "CODES"]); -promise.then((resultSetV9) => { - console.log(TAG + "resultSet columnNames:" + resultSetV9.columnNames); - console.log(TAG + "resultSet columnCount:" + resultSetV9.columnCount); -}); -``` - -### 属性9+ - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -| 名称 | 类型 | 必填 | 说明 | -| ------------ | ------------------- | ---- | -------------------------------- | -| columnNames | Array<string> | 是 | 获取结果集中所有列的名称。 | -| columnCount | number | 是 | 获取结果集中的列数。 | -| rowCount | number | 是 | 获取结果集中的行数。 | -| rowIndex | number | 是 | 获取结果集当前行的索引。 | -| isAtFirstRow | boolean | 是 | 检查结果集是否位于第一行。 | -| isAtLastRow | boolean | 是 | 检查结果集是否位于最后一行。 | -| isEnded | boolean | 是 | 检查结果集是否位于最后一行之后。 | -| isStarted | boolean | 是 | 检查指针是否移动过。 | -| isClosed | boolean | 是 | 检查当前结果集是否关闭。 | - -### getColumnIndex9+ - -getColumnIndex(columnName: string): number - -根据指定的列名获取列索引。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---------- | ------ | ---- | -------------------------- | -| columnName | string | 是 | 表示结果集中指定列的名称。 | - -**返回值:** - -| 类型 | 说明 | -| ------ | ------------------ | -| number | 返回指定列的索引。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800013 | The column value is null or the column type is incompatible. | - -**示例:** - - ```js -resultSetV9.goToFirstRow(); -const id = resultSetV9.getLong(resultSetV9.getColumnIndex("ID")); -const name = resultSetV9.getString(resultSetV9.getColumnIndex("NAME")); -const age = resultSetV9.getLong(resultSetV9.getColumnIndex("AGE")); -const salary = resultSetV9.getDouble(resultSetV9.getColumnIndex("SALARY")); - ``` - -### getColumnName9+ - -getColumnName(columnIndex: number): string - -根据指定的列索引获取列名。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | ------ | ---- | -------------------------- | -| columnIndex | number | 是 | 表示结果集中指定列的索引。 | - -**返回值:** - -| 类型 | 说明 | -| ------ | ------------------ | -| string | 返回指定列的名称。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800013 | The column value is null or the column type is incompatible. | - -**示例:** - - ```js -const id = resultSetV9.getColumnName(0); -const name = resultSetV9.getColumnName(1); -const age = resultSetV9.getColumnName(2); - ``` - -### goTo9+ - -goTo(offset:number): boolean - -向前或向后转至结果集的指定行,相对于其当前位置偏移。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ---------------------------- | -| offset | number | 是 | 表示相对于当前位置的偏移量。 | - -**返回值:** - -| 类型 | 说明 | -| ------- | --------------------------------------------- | -| boolean | 如果成功移动结果集,则为true;否则返回false。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | - -**示例:** - - ```js -let predicatesV9goto = new dataRdb.RdbPredicatesV9("EMPLOYEE"); -let promisequerygoto = rdbStoreV9.query(predicatesV9goto, ["ID", "NAME", "AGE", "SALARY", "CODES"]); -promisequerygoto.then((resultSetV9) => { - resultSetV9.goTo(1); - resultSetV9.close(); -}).catch((err) => { - console.log('query failed'); -}); - ``` - -### goToRow9+ - -goToRow(position: number): boolean - -转到结果集的指定行。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------ | ---- | ------------------------ | -| position | number | 是 | 表示要移动到的指定位置。 | - -**返回值:** - -| 类型 | 说明 | -| ------- | --------------------------------------------- | -| boolean | 如果成功移动结果集,则为true;否则返回false。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | - -**示例:** - - ```js -let predicatesV9gotorow = new dataRdb.RdbPredicatesV9("EMPLOYEE"); -let promisequerygotorow = rdbStoreV9.query(predicatesV9gotorow, ["ID", "NAME", "AGE", "SALARY", "CODES"]); -promisequerygotorow.then((resultSetV9) => { - resultSetV9.goToRow(5); - resultSetV9.close(); -}).catch((err) => { - console.log('query failed'); -}); - ``` - -### goToFirstRow9+ - -goToFirstRow(): boolean - - -转到结果集的第一行。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**返回值:** - -| 类型 | 说明 | -| ------- | --------------------------------------------- | -| boolean | 如果成功移动结果集,则为true;否则返回false。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | - -**示例:** - - ```js -let predicatesV9goFirst = new dataRdb.RdbPredicatesV9("EMPLOYEE"); -let promisequerygoFirst = rdbStoreV9.query(predicatesV9goFirst, ["ID", "NAME", "AGE", "SALARY", "CODES"]); -promisequerygoFirst.then((resultSetV9) => { - resultSetV9.goToFirstRow(); - resultSetV9.close(); -}).catch((err) => { - console.log('query failed'); -}); - ``` - -### goToLastRow9+ - -goToLastRow(): boolean - -转到结果集的最后一行。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**返回值:** - -| 类型 | 说明 | -| ------- | --------------------------------------------- | -| boolean | 如果成功移动结果集,则为true;否则返回false。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | - -**示例:** - - ```js -let predicatesV9goLast = new dataRdb.RdbPredicatesV9("EMPLOYEE"); -let promisequerygoLast = rdbStoreV9.query(predicatesV9goLast, ["ID", "NAME", "AGE", "SALARY", "CODES"]); -promisequerygoLast.then((resultSetV9) => { - resultSetV9.goToLastRow(); - resultSetV9.close(); -}).catch((err) => { - console.log('query failed'); -}); - ``` - -### goToNextRow9+ - -goToNextRow(): boolean - -转到结果集的下一行。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**返回值:** - -| 类型 | 说明 | -| ------- | --------------------------------------------- | -| boolean | 如果成功移动结果集,则为true;否则返回false。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | - -**示例:** - - ```js -let predicatesV9goNext = new dataRdb.RdbPredicatesV9("EMPLOYEE"); -let promisequerygoNext = rdbStoreV9.query(predicatesV9goNext, ["ID", "NAME", "AGE", "SALARY", "CODES"]); -promisequerygoNext.then((resultSetV9) => { - resultSetV9.goToNextRow(); - resultSetV9.close(); -}).catch((err) => { - console.log('query failed'); -}); - ``` - -### goToPreviousRow9+ - -goToPreviousRow(): boolean - -转到结果集的上一行。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**返回值:** - -| 类型 | 说明 | -| ------- | --------------------------------------------- | -| boolean | 如果成功移动结果集,则为true;否则返回false。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | - -**示例:** - - ```js -let predicatesV9goPrev = new dataRdb.RdbPredicatesV9("EMPLOYEE"); -let promisequerygoPrev = rdbStoreV9.query(predicatesV9goPrev, ["ID", "NAME", "AGE", "SALARY", "CODES"]); -promisequerygoPrev.then((resultSetV9) => { - resultSetV9.goToPreviousRow(); - resultSetV9.close(); -}).catch((err) => { - console.log('query failed'); -}); - ``` - -### getBlob9+ - -getBlob(columnIndex: number): Uint8Array - -以字节数组的形式获取当前行中指定列的值。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | ------ | ---- | ----------------------- | -| columnIndex | number | 是 | 指定的列索引,从0开始。 | - -**返回值:** - -| 类型 | 说明 | -| ---------- | -------------------------------- | -| Uint8Array | 以字节数组的形式返回指定列的值。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800013 | The column value is null or the column type is incompatible. | - -**示例:** - - ```js -const codes = resultSetV9.getBlob(resultSetV9.getColumnIndex("CODES")); - ``` - -### getString9+ - -getString(columnIndex: number): string - -以字符串形式获取当前行中指定列的值。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | ------ | ---- | ----------------------- | -| columnIndex | number | 是 | 指定的列索引,从0开始。 | - -**返回值:** - -| 类型 | 说明 | -| ------ | ---------------------------- | -| string | 以字符串形式返回指定列的值。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800013 | The column value is null or the column type is incompatible. | - -**示例:** - - ```js -const name = resultSetV9.getString(resultSetV9.getColumnIndex("NAME")); - ``` - -### getLong9+ - -getLong(columnIndex: number): number - -以Long形式获取当前行中指定列的值。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | ------ | ---- | ----------------------- | -| columnIndex | number | 是 | 指定的列索引,从0开始。 | - -**返回值:** - -| 类型 | 说明 | -| ------ | -------------------------- | -| number | 以Long形式返回指定列的值。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800013 | The column value is null or the column type is incompatible. | - -**示例:** - - ```js -const age = resultSetV9.getLong(resultSetV9.getColumnIndex("AGE")); - ``` - -### getDouble9+ - -getDouble(columnIndex: number): number - -以double形式获取当前行中指定列的值。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | ------ | ---- | ----------------------- | -| columnIndex | number | 是 | 指定的列索引,从0开始。 | - -**返回值:** - -| 类型 | 说明 | -| ------ | ---------------------------- | -| number | 以double形式返回指定列的值。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800013 | The column value is null or the column type is incompatible. | - -**示例:** - - ```js -const salary = resultSetV9.getDouble(resultSetV9.getColumnIndex("SALARY")); - ``` - -### isColumnNull9+ - -isColumnNull(columnIndex: number): boolean - -检查当前行中指定列的值是否为null。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | ------ | ---- | ----------------------- | -| columnIndex | number | 是 | 指定的列索引,从0开始。 | - -**返回值:** - -| 类型 | 说明 | -| ------- | --------------------------------------------------------- | -| boolean | 如果当前行中指定列的值为null,则返回true,否则返回false。 | - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800013 | The column value is null or the column type is incompatible. | - -**示例:** - - ```js -const isColumnNull = resultSetV9.isColumnNull(resultSetV9.getColumnIndex("CODES")); - ``` - -### close9+ - -close(): void - -关闭结果集。 - -**系统能力:** SystemCapability.DistributedDataManager.RelationalStore.Core - -**示例:** - - ```js -let predicatesV9Close = new dataRdb.RdbPredicatesV9("EMPLOYEE"); -let promiseClose = rdbStoreV9.query(predicatesV9Close, ["ID", "NAME", "AGE", "SALARY", "CODES"]); -promiseClose.then((resultSetV9) => { - resultSetV9.close(); -}).catch((err) => { - console.log('resultset close failed'); -}); - ``` - -**错误码:** - -以下错误码的详细介绍请参见[关系型数据库错误码](../errorcodes/errorcode-data-rdb.md)。 - -| **错误码ID** | **错误信息** | -| ------------ | ------------------------------------------------------------ | -| 14800012 | The result set is empty or the specified location is invalid. | - ## ResultSet 提供通过查询数据库生成的数据库结果集的访问方法。