提交 7f23e5ff 编写于 作者: A Annie_wang

📃 docs: update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 05632893
# @ohos.data.rdb # @ohos.data.rdb
The relational database (RDB) manages data based on relational models. With the underlying SQLite database, the RDB provides a complete mechanism for managing local databases. To satisfy different needs in complicated scenarios, the RDB offers a series of methods for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements. After an application is deleted, the related RDB store will be automatically deleted. The relational database (RDB) manages data based on relational models. With the underlying SQLite database, the RDB provides a complete mechanism for managing local databases. To satisfy different needs in complicated scenarios, the RDB offers a series of methods for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements.
This module provides the following RDB-related functions: This module provides the following RDB-related functions:
- [RdbPredicates](#rdbpredicates): provides predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store. - [RdbPredicates](#rdbpredicates): provides predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store.
- [RdbStore](#rdbstore): provides APIs for managing an RDB store. - [RdbStore](#rdbstore): provides APIs for managing an RDB store.
> **NOTE**<br/> > **NOTE**
> >
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> >
> The APIs of this module are no longer maintained since API version 9. You are advised to use [@ohos.data.relationalStore](js-apis-data-relationalStore.md). > The APIs of this module are no longer maintained since API version 9. You are advised to use [@ohos.data.relationalStore](js-apis-data-relationalStore.md).
## Modules to Import
```js
import data_rdb from '@ohos.data.rdb';
```
## data_rdb.getRdbStoreV9<sup>9+</sup>
getRdbStoreV9(context: Context, config: StoreConfigV9, version: number, callback: AsyncCallback&lt;RdbStoreV9&gt;): void
Obtains an **RdbStoreV9** instance. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| config | [StoreConfigV9](#storeconfigv99) | Yes | Configuration of the RDB store. |
| version | number | Yes | RDB store version.<br>Currently, automatic RDB upgrades and downgrades performed based on **version** is not supported. |
| callback | AsyncCallback&lt;[RdbStoreV9](#rdbstorev99)&gt; | Yes | Callback invoked to return the **RdbStoreV9** instance obtained. |
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800010 | Invalid database name. |
| 14800011 | Database corrupted. |
**Example**
FA model:
```js
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext()
// Call getRdbStoreV9 after obtaining the context.
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 model:
```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
let context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
// Call getRdbStoreV9 after obtaining the context.
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.getRdbStoreV9<sup>9+</sup>
getRdbStoreV9(context: Context, config: StoreConfigV9, version: number): Promise&lt;RdbStoreV9&gt;
Obtains an **RdbStoreV9** instance. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | -------------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| config | [StoreConfigV9](#storeconfigv99) | Yes | Configuration of the RDB store. |
| version | number | Yes | RDB store version.<br>Currently, automatic RDB upgrades and downgrades performed based on **version** is not supported. |
**Return value**
| Type | Description |
| ----------------------------------------- | --------------------------------- |
| Promise&lt;[RdbStoreV9](#rdbstorev999)&gt; | Promise used to return the **RdbStoreV9** instance obtained.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800010 | Invalid database name. |
| 14800011 | Database corrupted. |
**Example**
FA model:
```js
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext()
// Call getRdbStoreV9 after obtaining the context.
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 model:
```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
let context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
// Call getRdbStoreV9 after obtaining the context.
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.deleteRdbStoreV9<sup>9+</sup>
deleteRdbStoreV9(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
Deletes an RDB store. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| name | string | Yes | Name of the RDB store to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800010 | Invalid database name. |
**Example**
FA model:
```js
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext()
// Call deleteRdbStoreV9 after obtaining the context.
data_rdb.deleteRdbStoreV9(context, "RdbTest.db", function (err) {
if (err) {
console.info("Delete RdbStorev9 failed, err: " + err)
return
}
console.log("Delete RdbStorev9 successfully.")
})
```
Stage model:
```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
let context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
// Call deleteRdbStoreV9 after obtaining the context.
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.deleteRdbStoreV9<sup>9+</sup>
deleteRdbStoreV9(context: Context, name: string): Promise&lt;void&gt;
Deletes an RDB store. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| name | string | Yes | Name of the RDB store to delete. |
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800010 | Invalid database name. |
**Example**
FA model:
```js
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext()
// Call deleteRdbStoreV9 after obtaining the context.
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 model:
```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
let context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
// Call deleteRdbStoreV9 after obtaining the context.
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&lt;RdbStore&gt;): void
Obtains an RDB store. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| version | number | Yes | RDB store version.<br>Currently, automatic RDB upgrades and downgrades performed based on **version** is not supported. |
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes | Callback invoked to return the RDB store obtained. |
**Example**
FA model:
```js
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext()
// Call getRdbStore.
const STORE_CONFIG = { name: "RdbTest.db"}
data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) {
if (err) {
console.info("Failed to get RdbStore, err: " + err)
return
}
console.log("Got RdbStore successfully.")
})
```
Stage model:
```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
let context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
// Call getRdbStore.
const STORE_CONFIG = { name: "RdbTest.db"}
data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) {
if (err) {
console.info("Failed to get RdbStore, err: " + err)
return
}
console.log("Got RdbStore successfully.")
})
```
## data_rdb.getRdbStore
getRdbStore(context: Context, config: StoreConfig, version: number): Promise&lt;RdbStore&gt;
Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | --------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| version | number | Yes | RDB store version.<br>Currently, automatic RDB upgrades and downgrades performed based on **version** is not supported. |
**Return value**
| Type | Description |
| ------------------------------------ | ------------------------------- |
| Promise&lt;[RdbStore](#rdbstore)&gt; | Promise used to return the RDB store obtained.|
**Example**
FA model:
```js
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext()
// Call getRdbStore.
const STORE_CONFIG = { name: "RdbTest.db" }
let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1);
promise.then(async (rdbStore) => {
console.log("Got RdbStore successfully.")
}).catch((err) => {
console.log("Failed to get RdbStore, err: " + err)
})
```
Stage model:
```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
let context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
// Call getRdbStore.
const STORE_CONFIG = { name: "RdbTest.db" }
let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1);
promise.then(async (rdbStore) => {
console.log("Got RdbStore successfully.")
}).catch((err) => {
console.log("Failed to get RdbStore, err: " + err)
})
```
## data_rdb.deleteRdbStore
deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
Deletes an RDB store. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| name | string | Yes | Name of the RDB store to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
FA model:
```js
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext()
// Call deleteRdbStore.
data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) {
if (err) {
console.info("Failed to delete RdbStore, err: " + err)
return
}
console.log("Deleted RdbStore successfully.")
})
```
Stage model:
```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
let context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
// Call deleteRdbStore.
data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) {
if (err) {
console.info("Failed to delete RdbStore, err: " + err)
return
}
console.log("Deleted RdbStore successfully.")
})
```
## data_rdb.deleteRdbStore
deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;
Deletes an RDB store. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| name | string | Yes | Name of the RDB store to delete. |
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
FA model:
```js
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext()
// Call deleteRdbStore.
let promise = data_rdb.deleteRdbStore(context, "RdbTest.db")
promise.then(() => {
console.log("Deleted RdbStore successfully.")
}).catch((err) => {
console.info("Failed to delete RdbStore, err: " + err)
})
```
Stage model:
```ts
// Obtain the context.
import Ability from '@ohos.application.Ability'
let context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
// Call deleteRdbStore.
let promise = data_rdb.deleteRdbStore(context, "RdbTest.db")
promise.then(()=>{
console.log("Deleted RdbStore successfully.")
}).catch((err) => {
console.info("Failed to delete RdbStore, err: " + err)
})
```
## RdbPredicatesV9<sup>9+</sup>
Defines predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false.
### constructor<sup>9+</sup>
constructor(name: string)
A constructor used to create an **RdbPredicates** object.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------ |
| name | string | Yes | Database table name.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
```
### inDevices<sup>9+</sup>
inDevices(devices: Array&lt;string&gt;): RdbPredicatesV9
Sets an **RdbPredicatesV9** to specify the remote devices to connect on the network during distributed database synchronization.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | -------------------------- |
| devices | Array&lt;string&gt; | Yes | IDs of the remote devices in the same network.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.inDevices(['12345678abcde'])
```
### inAllDevices<sup>9+</sup>
inAllDevices(): RdbPredicatesV9
Sets an **RdbPredicatesV9** to specify all remote devices on the network to connect during distributed database synchronization.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesv9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.inAllDevices()
```
### equalTo<sup>9+</sup>
equalTo(field: string, value: ValueType): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field with data type **ValueType** and value equal to the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ---------------------- |
| field | string | Yes | Column name in the database table. |
| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.equalTo("NAME", "lisi")
```
### notEqualTo<sup>9+</sup>
notEqualTo(field: string, value: ValueType): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field with data type **ValueType** and value not equal to the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ---------------------- |
| field | string | Yes | Column name in the database table. |
| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.notEqualTo("NAME", "lisi")
```
### beginWrap<sup>9+</sup>
beginWrap(): RdbPredicatesV9
Adds a left parenthesis to the **RdbPredicatesV9**.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------------------------------------ | ------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** with a left parenthesis.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.equalTo("NAME", "lisi")
.beginWrap()
.equalTo("AGE", 18)
.or()
.equalTo("SALARY", 200.5)
.endWrap()
```
### endWrap<sup>9+</sup>
endWrap(): RdbPredicatesV9
Adds a right parenthesis to the **RdbPredicatesV9**.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------------------------------------ | ------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** with a right parenthesis.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.equalTo("NAME", "lisi")
.beginWrap()
.equalTo("AGE", 18)
.or()
.equalTo("SALARY", 200.5)
.endWrap()
```
### or<sup>9+</sup>
or(): RdbPredicatesV9
Adds the OR condition to the **RdbPredicatesV9**.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------------------------------------ | ------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** with the OR condition.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.equalTo("NAME", "Lisa")
.or()
.equalTo("NAME", "Rose")
```
### and<sup>9+</sup>
and(): RdbPredicatesV9
Adds the AND condition to the **RdbPredicatesV9**.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------------------------------------ | ------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** with the AND condition.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.equalTo("NAME", "Lisa")
.and()
.equalTo("SALARY", 200.5)
```
### contains<sup>9+</sup>
contains(field: string, value: string): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match a string containing the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------- |
| field | string | Yes | Column name in the database table. |
| value | string | Yes | Value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.contains("NAME", "os")
```
### beginsWith<sup>9+</sup>
beginsWith(field: string, value: string): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match a string that starts with the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------- |
| field | string | Yes | Column name in the database table. |
| value | string | Yes | Value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.beginsWith("NAME", "os")
```
### endsWith<sup>9+</sup>
endsWith(field: string, value: string): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match a string that ends with the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------- |
| field | string | Yes | Column name in the database table. |
| value | string | Yes | Value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.endsWith("NAME", "se")
```
### isNull<sup>9+</sup>
isNull(field: string): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field whose value is null.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| field | string | Yes | Column name in the database table.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.isNull("NAME")
```
### isNotNull<sup>9+</sup>
isNotNull(field: string): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field whose value is not null.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| field | string | Yes | Column name in the database table.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.isNotNull("NAME")
```
### like<sup>9+</sup>
like(field: string, value: string): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match a string that is similar to the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------- |
| field | string | Yes | Column name in the database table. |
| value | string | Yes | Value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.like("NAME", "%os%")
```
### glob<sup>9+</sup>
glob(field: string, value: string): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the specified string.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| field | string | Yes | Column name in the database table. |
| value | string | Yes | Value to match the **RdbPredicatesV9**.<br><br>Wildcards are supported. * indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.glob("NAME", "?h*g")
```
### between<sup>9+</sup>
between(field: string, low: ValueType, high: ValueType): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field with data type **ValueType** and value within the specified range.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | -------------------------- |
| field | string | Yes | Column name in the database table. |
| low | [ValueType](#valuetype) | Yes | Minimum value to match the **RdbPredicatesV9**. |
| high | [ValueType](#valuetype) | Yes | Maximum value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.between("AGE", 10, 50)
```
### notBetween<sup>9+</sup>
notBetween(field: string, low: ValueType, high: ValueType): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field with data type **ValueType** and value out of the specified range.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | -------------------------- |
| field | string | Yes | Column name in the database table. |
| low | [ValueType](#valuetype) | Yes | Minimum value to match the **RdbPredicatesV9**. |
| high | [ValueType](#valuetype) | Yes | Maximum value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.notBetween("AGE", 10, 50)
```
### greaterThan<sup>9+</sup>
greaterThan(field: string, value: ValueType): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field with data type **ValueType** and value greater than the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ---------------------- |
| field | string | Yes | Column name in the database table. |
| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.greaterThan("AGE", 18)
```
### lessThan<sup>9+</sup>
lessThan(field: string, value: ValueType): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field with data type **ValueType** and value less than the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ---------------------- |
| field | string | Yes | Column name in the database table. |
| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.lessThan("AGE", 20)
```
### greaterThanOrEqualTo<sup>9+</sup>
greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field with data type **ValueType** and value greater than or equal to the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ---------------------- |
| field | string | Yes | Column name in the database table. |
| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.greaterThanOrEqualTo("AGE", 18)
```
### lessThanOrEqualTo<sup>9+</sup>
lessThanOrEqualTo(field: string, value: ValueType): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field with data type **ValueType** and value less than or equal to the specified value.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ---------------------- |
| field | string | Yes | Column name in the database table. |
| value | [ValueType](#valuetype) | Yes | Value to match the **RdbPredicatesV9**.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.lessThanOrEqualTo("AGE", 20)
```
### orderByAsc<sup>9+</sup>
orderByAsc(field: string): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the column with values sorted in ascending order.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| field | string | Yes | Column name in the database table.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.orderByAsc("NAME")
```
### orderByDesc<sup>9+</sup>
orderByDesc(field: string): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the column with values sorted in descending order.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| field | string | Yes | Column name in the database table.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.orderByDesc("AGE")
```
### distinct<sup>9+</sup>
distinct(): RdbPredicatesV9
Sets an **RdbPredicatesV9** to filter out duplicate records.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------------------------------------ | ------------------------------ |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object that can filter out duplicate records.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.equalTo("NAME", "Rose").distinct()
```
### limitAs<sup>9+</sup>
limitAs(value: number): RdbPredicatesV9
Sets an **RdbPredicatesV9** to specify the maximum number of records.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------- |
| value | number | Yes | Maximum number of records.|
**Return value**
| Type | Description |
| ------------------------------------ | ------------------------------------ |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object that specifies the maximum number of records.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.equalTo("NAME", "Rose").limitAs(3)
```
### offsetAs<sup>9+</sup>
offsetAs(rowOffset: number): RdbPredicatesV9
Sets an **RdbPredicatesV9** to specify the start position of the returned result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ---------------------------------- |
| rowOffset | number | Yes | Number of rows to offset from the beginning. The value is a positive integer.|
**Return value**
| Type | Description |
| ------------------------------------ | ------------------------------------ |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object that specifies the start position of the returned result.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.equalTo("NAME", "Rose").offsetAs(3)
```
### groupBy<sup>9+</sup>
groupBy(fields: Array&lt;string&gt;): RdbPredicatesV9
Sets an **RdbPredicatesV9** to group rows that have the same value into summary rows.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------- | ---- | -------------------- |
| fields | Array&lt;string&gt; | Yes | Names of columns to group.|
**Return value**
| Type | Description |
| ------------------------------------ | ---------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object that groups rows with the same value.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.groupBy(["AGE", "NAME"])
```
### indexedBy<sup>9+</sup>
indexedBy(field: string): RdbPredicatesV9
Sets an **RdbPredicatesV9** to specify the index column.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------- |
| field | string | Yes | Name of the index column.|
**Return value**
| Type | Description |
| ------------------------------------ | ------------------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object that specifies the index column.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.indexedBy("SALARY_INDEX")
```
### in<sup>9+</sup>
in(field: string, value: Array&lt;ValueType&gt;): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------------ | ---- | --------------------------------------- |
| field | string | Yes | Column name in the database table. |
| value | Array&lt;[ValueType](#valuetype)&gt; | Yes | Array of **ValueType**s to match.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.in("AGE", [18, 20])
```
### notIn<sup>9+</sup>
notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicatesV9
Sets an **RdbPredicatesV9** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------------ | ---- | ------------------------------------- |
| field | string | Yes | Column name in the database table. |
| value | Array&lt;[ValueType](#valuetype)&gt; | Yes | Array of **ValueType**s to match.|
**Return value**
| Type | Description |
| ------------------------------------ | -------------------------- |
| [RdbPredicatesV9](#rdbpredicatesv99) | **RdbPredicatesV9** object created.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.notIn("NAME", ["Lisa", "Rose"])
```
## RdbStoreV9<sup>9+</sup>
Provides methods to manage an RDB store.
Before using the following APIs, use [executeSql](#executesql) to initialize the database table structure and related data. For details, see [RDB Development](../../database/database-relational-guidelines.md).
### insert<sup>9+</sup>
insert(table: string, values: ValuesBucket, callback: AsyncCallback&lt;number&gt;):void
Inserts a row of data into a table. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------- | ---- | ---------------------------------------------------------- |
| table | string | Yes | Name of the target table. |
| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
**Example**
```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("Failed to insert data");
return;
}
console.log("Inserted data successfully, rowId = " + rowId);
})
```
### insert<sup>9+</sup>
insert(table: string, values: ValuesBucket):Promise&lt;number&gt;
Inserts a row of data into a table. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------- | ---- | -------------------------- |
| table | string | Yes | Name of the target table. |
| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert.|
**Return value**
| Type | Description |
| --------------------- | ------------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
**Example**
```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("Inserted data successfully, rowId = " + rowId);
}).catch((status) => {
console.log("Failed to insert data");
})
```
### batchInsert<sup>9+</sup>
batchInsert(table: string, values: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;):void
Batch inserts data into a table. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
| table | string | Yes | Name of the target table. |
| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | Yes | An array of data to insert. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.|
**Example**
```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);
})
```
### batchInsert<sup>9+</sup>
batchInsert(table: string, values: Array&lt;ValuesBucket&gt;):Promise&lt;number&gt;
Batch inserts data into a table. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------------------ | ---- | ---------------------------- |
| table | string | Yes | Name of the target table. |
| values | Array&lt;[ValuesBucket](#valuesbucket)&gt; | Yes | An array of data to insert.|
**Return value**
| Type | Description |
| --------------------- | ----------------------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.|
**Example**
```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);
})
```
### update<sup>9+</sup>
update(values: ValuesBucket, predicates: RdbPredicatesV9, callback: AsyncCallback&lt;number&gt;):void
Updates data based on the specified **RdbPredicatesV9** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| values | [ValuesBucket](#valuesbucket) | Yes | Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | Yes | Update conditions specified by the **RdbPredicatesV9** object. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the number of rows updated. |
**Example**
```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("Failed to update data, err: " + err)
return
}
console.log("Updated row count: " + ret)
})
```
### update<sup>9+</sup>
update(values: ValuesBucket, predicates: RdbPredicatesV9):Promise&lt;number&gt;
Updates data based on the specified **RdbPredicatesV9** object. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------------------------------------ | ---- | ------------------------------------------------------------ |
| values | [ValuesBucket](#valuesbucket) | Yes | Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
| predicatesV9 | [RdbPredicatesV9](#rdbpredicatesv99) | Yes | Update conditions specified by the **RdbPredicatesV9** object. |
**Return value**
| Type | Description |
| --------------------- | ----------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|
**Example**
```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("Failed to update data, err: " + err)
})
```
### update<sup>9+</sup>
update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void
Updates data based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| table | string | Yes | Name of the target table. |
| values | [ValuesBucket](#valuesbucket) | Yes | Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Update conditions specified by the **DataSharePredicates** object. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the number of rows updated. |
**Example**
```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("Failed to update data, err: " + err)
return
}
console.log("Updated row count: " + ret)
})
```
### update<sup>9+</sup>
update(table: string, values: ValuesBucket, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt;
Updates data based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| table | string | Yes | Name of the target table. |
| values | [ValuesBucket](#valuesbucket) | Yes | Rows of data to update in the RDB store. The key-value pair is associated with the column name in the target table.|
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Update conditions specified by the **DataSharePredicates** object. |
**Return value**
| Type | Description |
| --------------------- | ----------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of rows updated.|
**Example**
```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("Failed to update data, err: " + err)
})
```
### delete<sup>9+</sup>
delete(predicates: RdbPredicatesV9, callback: AsyncCallback&lt;number&gt;):void
Deletes data from the RDB store based on the specified **RdbPredicatesV9** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | Yes | Conditions specified by the **RdbPredicatesV9** object for deleting data.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the number of rows deleted. |
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.equalTo("NAME", "Lisa")
rdbStoreV9.delete(predicatesV9, function (err, rows) {
if (err) {
console.info("Failed to delete data, err: " + err)
return
}
console.log("Deleted rows: " + rows)
})
```
### delete<sup>9+</sup>
delete(predicates: RdbPredicatesV9):Promise&lt;number&gt;
Deletes data from the RDB store based on the specified **RdbPredicatesV9** object. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | ----------------------------------------- |
| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | Yes | Conditions specified by the **RdbPredicatesV9** object for deleting data.|
**Return value**
| Type | Description |
| --------------------- | ------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of rows deleted.|
**Example**
```js
let predicatesV9 = new data_rdb.RdbPredicatesV9("EMPLOYEE")
predicatesV9.equalTo("NAME", "Lisa")
let promise = rdbStoreV9.delete(predicatesV9)
promise.then((rows) => {
console.log("Deleted rows: " + rows)
}).catch((err) => {
console.info("Failed to delete data, err: " + err)
})
```
### delete<sup>9+</sup>
delete(table: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;):void
Deletes data from the RDB store based on the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- |
| table | string | Yes | Name of the target table. |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Conditions specified by the **DataSharePredicates** object for deleting data.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the number of rows deleted. |
**Example**
```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("Failed to delete data, err: " + err)
return
}
console.log("Deleted rows: " + rows)
})
```
### delete<sup>9+</sup>
delete(table: string, predicates: dataSharePredicates.DataSharePredicates):Promise&lt;number&gt;
Deletes data from the RDB store based on the specified **DataSharePredicates** object. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | --------------------------------------------- |
| table | string | Yes | Name of the target table. |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Conditions specified by the **DataSharePredicates** object for deleting data.|
**Return value**
| Type | Description |
| --------------------- | ------------------------------- |
| Promise&lt;number&gt; | Promise used to return the number of rows deleted.|
**Example**
```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("Deleted rows: " + rows)
}).catch((err) => {
console.info("Failed to delete data, err: " + err)
})
```
### query<sup>9+</sup>
query(predicates: RdbPredicatesV9, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSetV9&gt;):void
Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | Yes | Query conditions specified by the **RdbPredicatesV9** object. |
| columns | Array&lt;string&gt; | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. |
| callback | AsyncCallback&lt;[ResultSetV9](js-apis-data-resultset.md)&gt; | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSetV9** object will be returned.|
**Example**
```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("Failed to query data, err: " + err)
return
}
console.log("ResultSet column names: " + resultSetV9.columnNames)
console.log("ResultSet column count: " + resultSetV9.columnCount)
})
```
### query<sup>9+</sup>
query(predicates: RdbPredicatesV9, columns?: Array&lt;string&gt;):Promise&lt;ResultSetV9&gt;
Queries data from the RDB store based on specified conditions. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | Yes | Query conditions specified by the **RdbPredicatesV9** object. |
| columns | Array&lt;string&gt; | No | Columns to query. If this parameter is not specified, the query applies to all columns.|
**Return value**
| Type | Description |
| ------------------------------------------------------- | -------------------------------------------------- |
| Promise&lt;[ResultSetV9](js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSetV9** object will be returned.|
**Example**
```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("Failed to query data, err: " + err)
})
```
### query<sup>9+</sup>
query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;ResultSetV9&gt;):void
Queries data from the RDB store based on specified conditions. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| table | string | Yes | Name of the target table. |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Query conditions specified by the **DataSharePredicates** object. |
| columns | Array&lt;string&gt; | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. |
| callback | AsyncCallback&lt;[ResultSetV9](js-apis-data-resultset.md)&gt; | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSetV9** object will be returned.|
**Example**
```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("Failed to query data, err: " + err)
return
}
console.log("ResultSet column names: " + resultSetV9.columnNames)
console.log("ResultSet column count: " + resultSetV9.columnCount)
})
```
### query<sup>9+</sup>
query(table: string, predicates: dataSharePredicates.DataSharePredicates, columns?: Array&lt;string&gt;):Promise&lt;ResultSetV9&gt;
Queries data from the RDB store based on specified conditions. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ |
| table | string | Yes | Name of the target table. |
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Query conditions specified by the **DataSharePredicates** object. |
| columns | Array&lt;string&gt; | No | Columns to query. If this parameter is not specified, the query applies to all columns.|
**Return value**
| Type | Description |
| ------------------------------------------------------- | -------------------------------------------------- |
| Promise&lt;[ResultSetV9](js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSetV9** object will be returned.|
**Example**
```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("Failed to query data, err: " + err)
})
```
### remoteQuery<sup>9+</sup>
remoteQuery(device: string, table: string, predicates: RdbPredicatesV9, columns: Array&lt;string&gt; , callback: AsyncCallback&lt;ResultSetV9&gt;): void
Queries data from the RDB store of a remote device based on specified conditions. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| device | string | Yes | Network ID of the remote device. |
| table | string | Yes | Name of the target table. |
| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | Yes | Query conditions specified by the **RdbPredicatesV9** object. |
| columns | Array&lt;string&gt; | Yes | Columns to query. If this parameter is not specified, the query applies to all columns. |
| callback | AsyncCallback&lt;[ResultSetV9](js-apis-data-resultset.md#resultset)&gt; | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSetV9** object will be returned.|
**Example**
```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)
})
```
### remoteQuery<sup>9+</sup>
remoteQuery(device: string, table: string, predicates: RdbPredicatesV9, columns: Array&lt;string&gt;): Promise&lt;ResultSetV9&gt;
Queries data from the RDB store of a remote device based on specified conditions. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | ------------------------------------------------ |
| device | string | Yes | Network ID of the remote device. |
| table | string | Yes | Name of the target table. |
| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | Yes | Query conditions specified by the **RdbPredicatesV9** object. |
| columns | Array&lt;string&gt; | Yes | Columns to query. If this parameter is not specified, the query applies to all columns.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | -------------------------------------------------- |
| Promise&lt;[ResultSetV9](js-apis-data-resultset.md#resultset)&gt; | Promise used to return the result. If the operation is successful, a **ResultSetV9** object will be returned.|
**Example**
```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)
})
```
### querySql<sup>9+</sup>
querySql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;ResultSetV9&gt;):void
Queries data using the specified SQL statement. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| sql | string | Yes | SQL statement to run. |
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes | Arguments in the SQL statement. |
| callback | AsyncCallback&lt;[ResultSetV9](js-apis-data-resultset.md)&gt; | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSetV9** object will be returned.|
**Example**
```js
rdbStoreV9.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSetV9) {
if (err) {
console.info("Failed to query data, err: " + err)
return
}
console.log("ResultSet column names: " + resultSetV9.columnNames)
console.log("ResultSet column count: " + resultSetV9.columnCount)
})
```
### querySql<sup>9+</sup>
querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSetV9&gt;
Queries data using the specified SQL statement. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** ## Modules to Import
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | --------------------- |
| sql | string | Yes | SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No | Arguments in the SQL statement. |
**Return value**
| Type | Description |
| ------------------------------------------------------- | -------------------------------------------------- |
| Promise&lt;[ResultSetV9](js-apis-data-resultset.md)&gt; | Promise used to return the result. If the operation is successful, a **ResultSetV9** object will be returned.|
**Example**
```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("Failed to query data, err: " + err)
})
```
### executeSql<sup>9+</sup>
executeSql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;void&gt;):void
Executes an SQL statement that contains specified arguments but returns no value. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ---------------------- |
| sql | string | Yes | SQL statement to run. |
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes | Arguments in the SQL statement. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
```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("Failed to execute SQL, err: " + err)
return
}
console.info('Created table successfully.')
})
```
### executeSql<sup>9+</sup>
executeSql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;void&gt;
Executes an SQL statement that contains specified arguments but returns no value. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | --------------------- |
| sql | string | Yes | SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No | Arguments in the SQL statement. |
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```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('Created table successfully.')
}).catch((err) => {
console.info("Failed to execute SQL, err: " + err)
})
```
### beginTransaction<sup>9+</sup>
beginTransaction():void
Starts the transaction before executing an SQL statement.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Example**
```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()
})
```
### commit<sup>9+</sup>
commit():void
Commits the executed SQL statements.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Example**
```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()
})
```
### rollBack<sup>9+</sup>
rollBack():void
Rolls back the SQL statements that have been executed.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Example**
```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()
}
})
```
### backup<sup>9+</sup>
backup(destName:string, callback: AsyncCallback&lt;void&gt;):void
Backs up an RDB store. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------ |
| destName | string | Yes | Name of the RDB store backup file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
```js
rdbStoreV9.backup("dbBackup.db", function(err) {
if (err) {
console.info('Backup failed, err: ' + err)
return
}
console.info('Backup success.')
})
```
### backup<sup>9+</sup>
backup(destName:string): Promise&lt;void&gt;
Backs up an RDB store. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------ |
| destName | string | Yes | Name of the RDB store backup file.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let promiseBackup = rdbStoreV9.backup("dbBackup.db")
promiseBackup.then(()=>{
console.info('Backup success.')
}).catch((err)=>{
console.info('Backup failed, err: ' + err)
})
```
### restore<sup>9+</sup>
restore(srcName:string, callback: AsyncCallback&lt;void&gt;):void
Restores an RDB store from a backup file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------ |
| srcName | string | Yes | Name of the RDB store backup file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
```js
rdbStoreV9.restore("dbBackup.db", function(err) {
if (err) {
console.info('Restore failed, err: ' + err)
return
}
console.info('Restore success.')
})
```
### restore<sup>9+</sup>
restore(srcName:string): Promise&lt;void&gt;
Restores an RDB store from a backup file. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------------------------ |
| srcName | string | Yes | Name of the RDB store backup file.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let promiseRestore = rdbStoreV9.restore("dbBackup.db")
promiseRestore.then(()=>{
console.info('Restore success.')
}).catch((err)=>{
console.info('Restore failed, err: ' + err)
})
```
### setDistributedTables<sup>9+</sup>
setDistributedTables(tables: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
Sets distributed tables. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------- |
| tables | Array&lt;string&gt; | Yes | Names of the distributed tables to set.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
rdbStoreV9.setDistributedTables(["EMPLOYEE"], function (err) {
if (err) {
console.info('Failed to set distributed tables, err: ' + err)
return
}
console.info('Set distributed tables successfully.')
})
```
### setDistributedTables<sup>9+</sup>
setDistributedTables(tables: Array&lt;string&gt;): Promise&lt;void&gt;
Sets distributed tables. This API uses a promise to return the result.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------- | ---- | ------------------------ |
| tables | Array&lt;string&gt; | Yes | Names of the distributed tables to set.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js ```js
let promise = rdbStoreV9.setDistributedTables(["EMPLOYEE"]) import data_rdb from '@ohos.data.rdb';
promise.then(() => { ```
console.info("Set distributed tables successfully.") ## data_rdb.getRdbStore
}).catch((err) => {
console.info("Failed to set distributed tables, err: " + err)
})
```
### obtainDistributedTableName<sup>9+</sup>
obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void
Obtains the distributed table name for a remote device based on the local table name. This API uses an asynchronous callback to return the result. The distributed table name is required when the RDB store of a remote device is queried. getRdbStore(context: Context, config: StoreConfig, version: number, callback: AsyncCallback&lt;RdbStore&gt;): void
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC Obtains an RDB store. This API uses an asynchronous callback to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
| device | string | Yes | Remote device. | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| table | string | Yes | Local table name. | | config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| | version | number | Yes | RDB store version.<br>Currently, automatic RDB upgrades and downgrades performed based on **version** is not supported. |
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes | Callback invoked to return the RDB store obtained. |
**Example** **Example**
FA model:
```js ```js
rdbStoreV9.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, tableName) { // Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext()
// Call getRdbStore.
const STORE_CONFIG = { name: "RdbTest.db"}
data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) {
if (err) { if (err) {
console.info('Failed to obtain DistributedTableName, err: ' + err) console.info("Failed to get RdbStore, err: " + err)
return return
} }
console.info('Obtained distributed table name successfully, tableName=.' + tableName) console.log("Got RdbStore successfully.")
}) })
``` ```
### obtainDistributedTableName<sup>9+</sup> Stage model:
obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt; ```ts
// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility';
Obtains the distributed table name for a remote device based on the local table name. This API uses a promise to return the result. The distributed table name is required when the RDB store of a remote device is queried. let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
context = this.context
}
}
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC // Call getRdbStore.
const STORE_CONFIG = { name: "RdbTest.db"}
data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) {
if (err) {
console.info("Failed to get RdbStore, err: " + err)
return
}
console.log("Got RdbStore successfully.")
})
```
## data_rdb.getRdbStore
getRdbStore(context: Context, config: StoreConfig, version: number): Promise&lt;RdbStore&gt;
Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------ | ------ | ---- | ---------- | | ------- | --------------------------- | ---- | ------------------------------------------------------------ |
| device | string | Yes | Remote device.| | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| table | string | Yes | Local table name.| | config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| version | number | Yes | RDB store version.<br>Currently, automatic RDB upgrades and downgrades performed based on **version** is not supported. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ----------------------------------------------------- | | ------------------------------------ | ------------------------------- |
| Promise&lt;string&gt; | Promise used to return the result. If the operation succeeds, the distributed table name of the remote device is returned.| | Promise&lt;[RdbStore](#rdbstore)&gt; | Promise used to return the RDB store obtained.|
**Example** **Example**
FA model:
```js ```js
let promise = rdbStoreV9.obtainDistributedTableName("12345678abcde", "EMPLOYEE") // Obtain the context.
promise.then((tableName) => { import featureAbility from '@ohos.ability.featureAbility'
console.info('Obtained distributed table name successfully, tableName= ' + tableName) let context = featureAbility.getContext()
// Call getRdbStore.
const STORE_CONFIG = { name: "RdbTest.db" }
let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1);
promise.then(async (rdbStore) => {
console.log("Got RdbStore successfully.")
}).catch((err) => { }).catch((err) => {
console.info('Failed to obtain DistributedTableName, err: ' + err) console.log("Failed to get RdbStore, err: " + err)
}) })
``` ```
### sync<sup>9+</sup> Stage model:
sync(mode: SyncMode, predicates: RdbPredicatesV9, callback: AsyncCallback&lt;Array&lt;[string, number]&gt;&gt;): void
Synchronizes data between devices. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
| mode | [SyncMode](#syncmode8) | Yes | Data synchronization mode. The value can be **push** or **pull**. |
| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. |
| callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes | Callback invoked to send the synchronization result to the caller. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example** ```ts
// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility';
```js let context;
let predicatesV9 = new data_rdb.RdbPredicatesV9('EMPLOYEE') class EntryAbility extends UIAbility {
predicatesV9.inDevices(['12345678abcde']) onWindowStageCreate(windowStage){
rdbStoreV9.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicatesV9, function (err, result) { context = this.context
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])
} }
}
// Call getRdbStore.
const STORE_CONFIG = { name: "RdbTest.db" }
let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1);
promise.then(async (rdbStore) => {
console.log("Got RdbStore successfully.")
}).catch((err) => {
console.log("Failed to get RdbStore, err: " + err)
}) })
``` ```
### sync<sup>9+</sup> ## data_rdb.deleteRdbStore
sync(mode: SyncMode, predicates: RdbPredicatesV9): Promise&lt;Array&lt;[string, number]&gt;&gt;
Synchronizes data between devices. This API uses a promise to return the result. deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC Deletes an RDB store. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | ------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| mode | [SyncMode](#syncmode8) | Yes | Data synchronization mode. The value can be **push** or **pull**.| | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| predicates | [RdbPredicatesV9](#rdbpredicatesv99) | Yes | **RdbPredicates** object that specifies the data and devices to synchronize. | | name | string | Yes | Name of the RDB store to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Return value**
| Type | Description |
| -------------------------------------------- | ------------------------------------------------------------ |
| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to send the synchronization result. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example** **Example**
FA model:
```js ```js
let predicatesV9 = new data_rdb.RdbPredicatesV9('EMPLOYEE') // Obtain the context.
predicatesV9.inDevices(['12345678abcde']) import featureAbility from '@ohos.ability.featureAbility'
let promise = rdbStoreV9.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicatesV9) let context = featureAbility.getContext()
promise.then((resultSetV9) =>{
console.log('Sync done.') // Call deleteRdbStore.
for (let i = 0; i < resultSetV9.length; i++) { data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) {
console.log('device=' + resultSetV9[i][0] + ' status=' + resultSetV9[i][1]) if (err) {
console.info("Failed to delete RdbStore, err: " + err)
return
} }
}).catch((err) => { console.log("Deleted RdbStore successfully.")
console.log('Sync failed')
}) })
``` ```
### on('dataChange')<sup>9+</sup> Stage model:
on(event: 'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void
Registers an observer for this RDB store. When the data in the RDB store changes, a callback is invoked to return the data changes.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------------------------- |
| event | string | Yes | The value is'dataChange', which indicates a data change event. |
| type | [SubscribeType](#subscribetype8) | Yes| Subscription type to register.|
| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes | Observer that listens for the data changes in the RDB store. |
**Example** ```ts
// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility';
```js let context;
function storeObserver(devices) { class EntryAbility extends UIAbility {
for (let i = 0; i < devices.length; i++) { onWindowStageCreate(windowStage){
console.log('device=' + devices[i] + ' data changed') context = this.context
} }
} }
try {
rdbStoreV9.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) // Call deleteRdbStore.
} catch (err) { data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) {
console.log('Failed to register observer') if (err) {
} console.info("Failed to delete RdbStore, err: " + err)
return
}
console.log("Deleted RdbStore successfully.")
})
``` ```
### off('dataChange')<sup>9+</sup> ## data_rdb.deleteRdbStore
off(event:'dataChange', type: SubscribeType, observer: Callback&lt;Array&lt;string&gt;&gt;): void deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;
Unregisters the observer of the specified type from the RDB store. This API uses a callback to return the result. Deletes an RDB store. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | ------------------------------------------- | | ------- | ------- | ---- | ------------------------------------------------------------ |
| event | string | Yes | The value is'dataChange', which indicates a data change event. | | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| type | [SubscribeType](#subscribetype8) | Yes| Subscription type to unregister.| | name | string | Yes | Name of the RDB store to delete. |
| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes | Data change observer registered. |
**Example** **Return value**
```js | Type | Description |
function storeObserver(devices) { | ------------------- | ------------------------- |
for (let i = 0; i < devices.length; i++) { | Promise&lt;void&gt; | Promise that returns no value.|
console.log('device=' + devices[i] + ' data changed')
}
}
try {
rdbStoreV9.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver)
} catch (err) {
console.log('Failed to unregister observer')
}
```
## StoreConfigV9<sup>9+</sup> **Example**
Defines the RDB store configuration. FA model:
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core ```js
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext()
| Name | Type | Mandatory| Description | // Call deleteRdbStore.
| ------------- | ------------- | ---- | --------------------------------------------------------- | let promise = data_rdb.deleteRdbStore(context, "RdbTest.db")
| name | string | Yes | Database file name. | promise.then(() => {
| securityLevel | SecurityLevel | Yes | Security level of the RDB store. | console.log("Deleted RdbStore successfully.")
| encrypt | boolean | No | Whether to encrypt the RDB store.<br> The value **true** means to encrypt the RDB store;<br> the value **false** means the opposite.| }).catch((err) => {
console.info("Failed to delete RdbStore, err: " + err)
})
```
## SecurityLevel<sup>9+</sup> Stage model:
Enumerates the RDB store security levels. ```ts
// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility';
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
context = this.context
}
}
| Name| Value | Description | // Call deleteRdbStore.
| ---- | ---- | ------------------------------------------------------------ | let promise = data_rdb.deleteRdbStore(context, "RdbTest.db")
| S1 | 1 | The RDB store security level is low. If data leakage occurs, minor impact will be caused on the database. For example, an RDB store that contains system data such as wallpapers.| promise.then(()=>{
| S2 | 2 | The RDB store security level is medium. If data leakage occurs, moderate impact will be caused on the database. For example, an RDB store that contains information created by users or call records, such as audio or video clips.| console.log("Deleted RdbStore successfully.")
| S3 | 3 | The RDB store security level is high. If data leakage occurs, major impact will be caused on the database. For example, an RDB store that contains information such as user fitness, health, and location data.| }).catch((err) => {
| S4 | 4 | The RDB store security level is critical. If data leakage occurs, severe impact will be caused on the database. For example, an RDB store that contains information such as authentication credentials and financial data.| console.info("Failed to delete RdbStore, err: " + err)
})
```
## ValueType ## ValueType
...@@ -2711,12 +301,24 @@ Defines the database synchronization mode. ...@@ -2711,12 +301,24 @@ Defines the database synchronization mode.
Defines the subscription type. Defines the subscription type.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
| Name | Value | Description | | Name | Value | Description |
| --------------------- | ---- | ------------------ | | --------------------- | ---- | ------------------ |
| SUBSCRIBE_TYPE_REMOTE | 0 | Subscribe to remote data changes.| | SUBSCRIBE_TYPE_REMOTE | 0 | Subscribe to remote data changes.|
## StoreConfig
Defines the RDB store configuration.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Database file name.|
## RdbPredicates ## RdbPredicates
Defines predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false. Defines predicates for an RDB store. This class determines whether the conditional expression for the RDB store is true or false.
...@@ -2802,7 +404,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -2802,7 +404,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.| | value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -2831,7 +433,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -2831,7 +433,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.| | value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -2958,7 +560,7 @@ Sets an **RdbPredicates** to match a string containing the specified value. ...@@ -2958,7 +560,7 @@ Sets an **RdbPredicates** to match a string containing the specified value.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.| | value | string | Yes| Value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -2986,7 +588,7 @@ Sets an **RdbPredicates** to match a string that starts with the specified value ...@@ -2986,7 +588,7 @@ Sets an **RdbPredicates** to match a string that starts with the specified value
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.| | value | string | Yes| Value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -3014,7 +616,7 @@ Sets an **RdbPredicates** to match a string that ends with the specified value. ...@@ -3014,7 +616,7 @@ Sets an **RdbPredicates** to match a string that ends with the specified value.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.| | value | string | Yes| Value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -3095,7 +697,7 @@ Sets an **RdbPredicates** to match a string that is similar to the specified val ...@@ -3095,7 +697,7 @@ Sets an **RdbPredicates** to match a string that is similar to the specified val
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.| | value | string | Yes| Value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -3123,7 +725,7 @@ Sets an **RdbPredicates** to match the specified string. ...@@ -3123,7 +725,7 @@ Sets an **RdbPredicates** to match the specified string.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.<br><br>Wildcards are supported. * indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character.| | value | string | Yes| Value to match the **RdbPredicates**.<br><br>Wildcards are supported. * indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character. |
**Return value** **Return value**
...@@ -3151,8 +753,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -3151,8 +753,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| low | [ValueType](#valuetype) | Yes| Minimum value to match the **RdbPredicates**.| | low | [ValueType](#valuetype) | Yes| Minimum value to match the **RdbPredicates**. |
| high | [ValueType](#valuetype) | Yes| Maximum value to match the **RdbPredicates**.| | high | [ValueType](#valuetype) | Yes| Maximum value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -3180,8 +782,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -3180,8 +782,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| low | [ValueType](#valuetype) | Yes| Minimum value to match the **RdbPredicates**.| | low | [ValueType](#valuetype) | Yes| Minimum value to match the **RdbPredicates**. |
| high | [ValueType](#valuetype) | Yes| Maximum value to match the **RdbPredicates**.| | high | [ValueType](#valuetype) | Yes| Maximum value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -3209,7 +811,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -3209,7 +811,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.| | value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -3237,7 +839,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -3237,7 +839,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.| | value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -3265,7 +867,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -3265,7 +867,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.| | value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -3293,7 +895,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -3293,7 +895,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.| | value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
**Return value** **Return value**
...@@ -3552,7 +1154,7 @@ predicates.notIn("NAME", ["Lisa", "Rose"]) ...@@ -3552,7 +1154,7 @@ predicates.notIn("NAME", ["Lisa", "Rose"])
Provides methods to manage an RDB store. Provides methods to manage an RDB store.
Before using the following APIs, use [executeSql](#executesql) to initialize the database table structure and related data. For details, see [RDB Development](../../database/database-relational-guidelines.md). Before using the following APIs, use [executeSql](#executesql8) to initialize the database table structure and related data. For details, see [RDB Development](../../database/database-relational-guidelines.md).
### insert ### insert
...@@ -3753,12 +1355,12 @@ const valueBucket = { ...@@ -3753,12 +1355,12 @@ const valueBucket = {
} }
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
rdbStore.update(valueBucket, predicates, function (err, ret) { rdbStore.update(valueBucket, predicates, function (err, rows) {
if (err) { if (err) {
console.info("Failed to update data, err: " + err) console.info("Failed to update data, err: " + err)
return return
} }
console.log("Updated row count: " + ret) console.log("Updated row count: " + rows)
}) })
``` ```
...@@ -3795,8 +1397,8 @@ const valueBucket = { ...@@ -3795,8 +1397,8 @@ const valueBucket = {
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new data_rdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
let promise = rdbStore.update(valueBucket, predicates) let promise = rdbStore.update(valueBucket, predicates)
promise.then(async (ret) => { promise.then(async (rows) => {
console.log("Updated row count: " + ret) console.log("Updated row count: " + rows)
}).catch((err) => { }).catch((err) => {
console.info("Failed to update data, err: " + err) console.info("Failed to update data, err: " + err)
}) })
...@@ -4017,7 +1619,7 @@ rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) { ...@@ -4017,7 +1619,7 @@ rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) {
console.info("Failed to execute SQL, err: " + err) console.info("Failed to execute SQL, err: " + err)
return return
} }
console.info('Create table done.') console.info('Created table successfully.')
}) })
``` ```
...@@ -4048,7 +1650,7 @@ Executes an SQL statement that contains specified arguments but returns no value ...@@ -4048,7 +1650,7 @@ Executes an SQL statement that contains specified arguments but returns no value
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)" 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 = rdbStore.executeSql(SQL_CREATE_TABLE) let promise = rdbStore.executeSql(SQL_CREATE_TABLE)
promise.then(() => { promise.then(() => {
console.info('Create table done.') console.info('Created table successfully.')
}).catch((err) => { }).catch((err) => {
console.info("Failed to execute SQL, err: " + err) console.info("Failed to execute SQL, err: " + err)
}) })
...@@ -4352,8 +1954,8 @@ Registers an observer for this RDB store. When the data in the RDB store changes ...@@ -4352,8 +1954,8 @@ Registers an observer for this RDB store. When the data in the RDB store changes
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes| The value is **dataChange**, which indicates a data change event.| | event | string | Yes| The value is'dataChange', which indicates a data change event.|
| type | [SubscribeType](#subscribetype8) | Yes| Type defined in **SubscribeType**.| | type | [SubscribeType](#subscribetype8) | Yes| Subscription type to register.|
| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Observer that listens for the data changes in the RDB store.| | observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Observer that listens for the data changes in the RDB store.|
**Example** **Example**
...@@ -4384,7 +1986,7 @@ Unregisters the observer of the specified type from the RDB store. This API uses ...@@ -4384,7 +1986,7 @@ Unregisters the observer of the specified type from the RDB store. This API uses
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| event | string | Yes| The value is'dataChange', which indicates a data change event.| | event | string | Yes| The value is'dataChange', which indicates a data change event.|
| type | [SubscribeType](#subscribetype8) | Yes| Type defined in **SubscribeType**.| | type | [SubscribeType](#subscribetype8) | Yes| Subscription type to unregister.|
| observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Data change observer registered.| | observer | Callback&lt;Array&lt;string&gt;&gt; | Yes| Data change observer registered.|
**Example** **Example**
...@@ -4401,13 +2003,3 @@ try { ...@@ -4401,13 +2003,3 @@ try {
console.log('Failed to unregister observer') console.log('Failed to unregister observer')
} }
``` ```
## StoreConfig
Defines the RDB store configuration.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Database file name.|
...@@ -8,536 +8,6 @@ A result set is a set of results returned after the relational database (RDB) qu ...@@ -8,536 +8,6 @@ A result set is a set of results returned after the relational database (RDB) qu
> >
> The APIs of this module are no longer maintained since API version 9. You are advised to use [@ohos.data.relationalStore#ResultSet](js-apis-data-relationalStore.md#resultset). > The APIs of this module are no longer maintained since API version 9. You are advised to use [@ohos.data.relationalStore#ResultSet](js-apis-data-relationalStore.md#resultset).
## ResultSetV9<sup>9+</sup>
Provides APIs to access the result set, which is obtained by querying the RDB store.
### Usage
Use [RdbStoreV9.query()](js-apis-data-rdb.md#query) to obtain the **resultSetV9** instance.
```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);
});
```
### Attributes<sup>9+</sup>
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
| Name | Type | Mandatory| Description |
| ------------ | ------------------- | ---- | -------------------------------- |
| columnNames | Array&lt;string&gt; | Yes | Names of all columns in the result set. |
| columnCount | number | Yes | Number of columns in the result set. |
| rowCount | number | Yes | Number of rows in the result set. |
| rowIndex | number | Yes | Index of the current row in the result set. |
| isAtFirstRow | boolean | Yes | Whether the cursor is in the first row of the result set. |
| isAtLastRow | boolean | Yes | Whether the cursor is in the last row of the result set. |
| isEnded | boolean | Yes | Whether the cursor is after the last row of the result set.|
| isStarted | boolean | Yes | Whether the cursor has been moved. |
| isClosed | boolean | Yes | Whether the result set is closed. |
### getColumnIndex<sup>9+</sup>
getColumnIndex(columnName: string): number
Obtains the column index based on the column name.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | -------------------------- |
| columnName | string | Yes | Column name specified.|
**Return value**
| Type | Description |
| ------ | ------------------ |
| number | Index of the column obtained.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```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"));
```
### getColumnName<sup>9+</sup>
getColumnName(columnIndex: number): string
Obtains the column name based on the column index.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------------------------- |
| columnIndex | number | Yes | Column index specified.|
**Return value**
| Type | Description |
| ------ | ------------------ |
| string | Column name obtained.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const id = resultSetV9.getColumnName(0);
const name = resultSetV9.getColumnName(1);
const age = resultSetV9.getColumnName(2);
```
### goTo<sup>9+</sup>
goTo(offset:number): boolean
Moves the cursor to the row based on the specified offset.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------------- |
| offset | number | Yes | Offset relative to the current position.|
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```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');
});
```
### goToRow<sup>9+</sup>
goToRow(position: number): boolean
Moves the cursor to the specified row in the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------ |
| position | number | Yes | Position to which the cursor is to be moved.|
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```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');
});
```
### goToFirstRow<sup>9+</sup>
goToFirstRow(): boolean
Moves the cursor to the first row of the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```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');
});
```
### goToLastRow<sup>9+</sup>
goToLastRow(): boolean
Moves the cursor to the last row of the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```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');
});
```
### goToNextRow<sup>9+</sup>
goToNextRow(): boolean
Moves the cursor to the next row in the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```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');
});
```
### goToPreviousRow<sup>9+</sup>
goToPreviousRow(): boolean
Moves the cursor to the previous row in the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```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');
});
```
### getBlob<sup>9+</sup>
getBlob(columnIndex: number): Uint8Array
Obtains the value in the specified column in the current row as a byte array.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes | Index of the specified column, starting from 0.|
**Return value**
| Type | Description |
| ---------- | -------------------------------- |
| Uint8Array | Value in the specified column as a byte array.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const codes = resultSetV9.getBlob(resultSetV9.getColumnIndex("CODES"));
```
### getString<sup>9+</sup>
getString(columnIndex: number): string
Obtains the value in the specified column in the current row as a string.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes | Index of the specified column, starting from 0.|
**Return value**
| Type | Description |
| ------ | ---------------------------- |
| string | Value in the specified column as a string.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const name = resultSetV9.getString(resultSetV9.getColumnIndex("NAME"));
```
### getLong<sup>9+</sup>
getLong(columnIndex: number): number
Obtains the value in the specified column in the current row as a Long.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes | Index of the specified column, starting from 0.|
**Return value**
| Type | Description |
| ------ | -------------------------- |
| number | Value in the specified column as a Long.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const age = resultSetV9.getLong(resultSetV9.getColumnIndex("AGE"));
```
### getDouble<sup>9+</sup>
getDouble(columnIndex: number): number
Obtains the value in the specified column in the current row as a double.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes | Index of the specified column, starting from 0.|
**Return value**
| Type | Description |
| ------ | ---------------------------- |
| number | Value in the specified column as a double.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const salary = resultSetV9.getDouble(resultSetV9.getColumnIndex("SALARY"));
```
### isColumnNull<sup>9+</sup>
isColumnNull(columnIndex: number): boolean
Checks whether the value in the specified column of the current row is null.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes | Index of the specified column, starting from 0.|
**Return value**
| Type | Description |
| ------- | --------------------------------------------------------- |
| boolean | Returns **true** if the value is null; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const isColumnNull = resultSetV9.isColumnNull(resultSetV9.getColumnIndex("CODES"));
```
### close<sup>9+</sup>
close(): void
Closes this result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Example**
```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');
});
```
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
## ResultSet ## ResultSet
Provides methods to access the result set, which is obtained by querying the RDB store. Provides methods to access the result set, which is obtained by querying the RDB store.
...@@ -861,7 +331,7 @@ Obtains the value in the specified column in the current row as a string. ...@@ -861,7 +331,7 @@ Obtains the value in the specified column in the current row as a string.
getLong(columnIndex: number): number getLong(columnIndex: number): number
Obtains the value in the specified column in the current row as a Long integer. Obtains the value in the specified column in the current row as a long integer.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -875,7 +345,7 @@ Obtains the value in the specified column in the current row as a Long integer. ...@@ -875,7 +345,7 @@ Obtains the value in the specified column in the current row as a Long integer.
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Value in the specified column as a Long integer.<br>The value range supported by this API is **Number.MIN_SAFE_INTEGER** to **Number.MAX_SAFE_INTEGER**. If the value is out of this range, use [getDouble](#getdouble).| | number | Value in the specified column as a long integer.<br>The value range supported by this API is **Number.MIN_SAFE_INTEGER** to **Number.MAX_SAFE_INTEGER**. If the value is out of this range, use [getDouble](#getdouble).|
**Example** **Example**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册