@@ -37,14 +37,14 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
...
@@ -37,14 +37,14 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
-**Updating Data**
-**Updating Data**
Call **update()** to update data based on the passed data and the conditions specified by**RdbPredicates**. If the data is updated, the number of rows of the updated data will be returned; otherwise, **0** will be returned.
Call **update()** to pass the new data and specify the update conditions by using**RdbPredicates**. If the data is updated, the number of rows of the updated data will be returned; otherwise, **0** will be returned.
| RdbStore | update(values: ValuesBucket, predicates: RdbPredicates): Promise<number> | Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the number of rows updated.<br>- **values**: data to update, which is stored in **ValuesBucket**.<br>- **predicates**: conditions for updating data.|
| RdbStore | update(values: ValuesBucket, predicates: RdbPredicates): Promise<number> | Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the number of rows updated.<br>- **values**: data to update, which is stored in **ValuesBucket**.<br>- **predicates**: conditions for updating data.|
-**Deleting Data**
-**Deleting Data**
...
@@ -55,7 +55,7 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
...
@@ -55,7 +55,7 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
| RdbStore | delete(predicates: RdbPredicates): Promise<number> | Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the number of rows deleted.<br>- **predicates**: conditions for deleting data.|
| RdbStore | delete(predicates: RdbPredicates): Promise<number> | Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the number of rows deleted.<br>- **predicates**: conditions for deleting data.|
-**Querying Data**
-**Querying Data**
...
@@ -201,76 +201,81 @@ You can obtain the distributed table name for a remote device based on the local
...
@@ -201,76 +201,81 @@ You can obtain the distributed table name for a remote device based on the local
FA model:
FA model:
```js
```js
import data_rdb from '@ohos.data.relationalStore'
import relationalStore from '@ohos.data.relationalStore'
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility'
var store;
// Obtain the context.
// Obtain the context.
let context = featureAbility.getContext()
let context = featureAbility.getContext();
const STORE_CONFIG = {
const STORE_CONFIG = {
name: "RdbTest.db",
name: "RdbTest.db",
securityLevel: data_rdb.SecurityLevel.S1
securityLevel: relationalStore.SecurityLevel.S1
}
};
// Assume that the current RDB store version is 3.
// Assume that the current RDB store version is 3.
data_rdb.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) {
relationalStore.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) {
// When an RDB store is created, the default version is 0.
store = rdbStore;
if (rdbStore.version == 0) {
// When an RDB store is created, the default version is 0.
rdbStore.executeSql("CREATE TABLE IF NOT EXISTS student (id INTEGER PRIMARY KEY AUTOINCREMENT, score REAL);", null)
if (store.version == 0) {
// Set the RDB store version. The input parameter must be an integer greater than 0.
store.executeSql("CREATE TABLE IF NOT EXISTS student (id INTEGER PRIMARY KEY AUTOINCREMENT, score REAL);", null);
rdbStore.version = 3
// Set the RDB store version. The input parameter must be an integer greater than 0.
}
store.version = 3;
}
// When an app is updated to the current version, the RDB store needs to be updated from version 1 to version 2.
// When an app is updated to the current version, the RDB store needs to be updated from version 1 to version 2.
if (rdbStore.version != 3 && rdbStore.version == 1) {
if (store.version != 3 && store.version == 1) {
// version = 1: table structure: student (id, age) => version = 2: table structure: student (id, age, score)
// version = 1: table structure: student (id, age) => version = 2: table structure: student (id, age, score)
@@ -2145,12 +2156,12 @@ Executes an SQL statement that contains specified arguments but returns no value
...
@@ -2145,12 +2156,12 @@ Executes an SQL statement that contains specified arguments but returns no value
```js
```js
constSQL_CREATE_TABLE="CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
constSQL_CREATE_TABLE="CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
@@ -2179,11 +2190,11 @@ Executes an SQL statement that contains specified arguments but returns no value
...
@@ -2179,11 +2190,11 @@ Executes an SQL statement that contains specified arguments but returns no value
```js
```js
constSQL_CREATE_TABLE="CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
constSQL_CREATE_TABLE="CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
letpromise=rdbStore.executeSql(SQL_CREATE_TABLE)
letpromise=store.executeSql(SQL_CREATE_TABLE);
promise.then(()=>{
promise.then(()=>{
console.info('Create table done.')
console.info(`Create table done.`);
}).catch((err)=>{
}).catch((err)=>{
console.info("Failed to execute SQL, err: "+err)
console.error(`ExecuteSql failed, err: ${err}`);
})
})
```
```
...
@@ -2199,19 +2210,25 @@ Starts the transaction before executing an SQL statement.
...
@@ -2199,19 +2210,25 @@ Starts the transaction before executing an SQL statement.
| number | Value obtained.<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).|