提交 e39714aa 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 a2cecc46
...@@ -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.
**Table 3** API for updating data **Table 3** API for updating data
| Class | API | Description | | Class | API | Description |
| ---------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | ---------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| RdbStore | update(values: ValuesBucket, predicates: RdbPredicates): Promise&lt;number&gt; | 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&lt;number&gt; | 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
| Class | API | Description | | Class | API | Description |
| ---------- | ---------------------------------------------------------- | ------------------------------------------------------------ | | ---------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
| RdbStore | delete(predicates: RdbPredicates): Promise&lt;number&gt; | 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&lt;number&gt; | 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)
rdbStore.executeSql("ALTER TABLE student ADD COLUMN score REAL", null) store.executeSql("ALTER TABLE student ADD COLUMN score REAL", null);
rdbStore.version = 2 store.version = 2;
} }
// When an app is updated to the current version, the RDB store needs to be updated from version 2 to version 3. // When an app is updated to the current version, the RDB store needs to be updated from version 2 to version 3.
if (rdbStore.version != 3 && rdbStore.version == 2) { if (store.version != 3 && store.version == 2) {
// version = 2: table structure: student (id, age, score) => version = 3: table structure: student (id, score) // version = 2: table structure: student (id, age, score) => version = 3: table structure: student (id, score)
rdbStore.executeSql("ALTER TABLE student DROP COLUMN age INTEGER", null) store.executeSql("ALTER TABLE student DROP COLUMN age INTEGER", null);
rdbStore.version = 3 store.version = 3;
} }
}) })
``` ```
Stage model: Stage model:
```ts ```ts
import data_rdb from '@ohos.data.relationalStore' import relationalStore from '@ohos.data.relationalStore'
import UIAbility from '@ohos.app.ability.UIAbility' import UIAbility from '@ohos.app.ability.UIAbility'
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
const STORE_CONFIG = { var store;
name: "rdbstore.db", const STORE_CONFIG = {
securityLevel: data_rdb.SecurityLevel.S1 name: "RdbTest.db",
} 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(this.context, STORE_CONFIG, function (err, rdbStore) { relationalStore.getRdbStore(this.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)
rdbStore.executeSql("ALTER TABLE student ADD COLUMN score REAL", null) store.executeSql("ALTER TABLE student ADD COLUMN score REAL", null);
rdbStore.version = 2 store.version = 2;
} }
// When an app is updated to the current version, the RDB store needs to be updated from version 2 to version 3. // When an app is updated to the current version, the RDB store needs to be updated from version 2 to version 3.
if (rdbStore.version != 3 && rdbStore.version == 2) { if (store.version != 3 && store.version == 2) {
// version = 2: table structure: student (id, age, score) => version = 3: table structure: student (id, score) // version = 2: table structure: student (id, age, score) => version = 3: table structure: student (id, score)
rdbStore.executeSql("ALTER TABLE student DROP COLUMN age INTEGER", null) store.executeSql("ALTER TABLE student DROP COLUMN age INTEGER", null);
rdbStore.version = 3 store.version = 3;
} }
}) })
} }
} }
``` ```
...@@ -284,23 +289,24 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -284,23 +289,24 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows: The sample code is as follows:
```js ```js
let u8 = new Uint8Array([1, 2, 3]) let u8 = new Uint8Array([1, 2, 3]);
const valueBucket = { "name": "Tom", "age": 18, "salary": 100.5, "blobType": u8 } const valueBucket = { "name": "Tom", "age": 18, "salary": 100.5, "blobType": u8 };
let insertPromise = rdbStore.insert("test", valueBucket) let insertPromise = store.insert("test", valueBucket);
``` ```
```js ```js
// Use a transaction to insert data. // Use a transaction to insert data.
beginTransaction()
try { try {
let u8 = new Uint8Array([1, 2, 3]) store.beginTransaction();
const valueBucket1 = { "name": "Tom", "age": 18, "salary": 100.5, "blobType": u8 } let u8 = new Uint8Array([1, 2, 3]);
const valueBucket2 = { "name": "Jam", "age": 19, "salary": 200.5, "blobType": u8 } const valueBucket = { "name": "Tom", "age": 18, "salary": 100.5, "blobType": u8 };
let insertPromise1 = rdbStore.insert("test", valueBucket1) let promise = store.insert("test", valueBucket);
let insertPromise2 = rdbStore.insert("test", valueBucket2) promise.then(() => {
commit() store.commit();
} catch (e) { })
rollBack() } catch (err) {
console.error(`Transaction failed, err: ${err}`);
store.rollBack();
} }
``` ```
...@@ -315,17 +321,17 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -315,17 +321,17 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows: The sample code is as follows:
```js ```js
let predicates = new data_rdb.RdbPredicates("test"); let predicates = new relationalStore.RdbPredicates("test");
predicates.equalTo("name", "Tom") predicates.equalTo("name", "Tom");
let promisequery = rdbStore.query(predicates) let promisequery = store.query(predicates);
promisequery.then((resultSet) => { promisequery.then((resultSet) => {
resultSet.goToFirstRow() resultSet.goToFirstRow();
const id = resultSet.getLong(resultSet.getColumnIndex("id")) const id = resultSet.getLong(resultSet.getColumnIndex("id"));
const name = resultSet.getString(resultSet.getColumnIndex("name")) const name = resultSet.getString(resultSet.getColumnIndex("name"));
const age = resultSet.getLong(resultSet.getColumnIndex("age")) const age = resultSet.getLong(resultSet.getColumnIndex("age"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"));
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"));
resultSet.close() resultSet.close();
}) })
``` ```
...@@ -335,9 +341,9 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -335,9 +341,9 @@ You can obtain the distributed table name for a remote device based on the local
```json ```json
"requestPermissions": "requestPermissions":
{ {
"name": "ohos.permission.DISTRIBUTED_DATASYNC" "name": "ohos.permission.DISTRIBUTED_DATASYNC"
} }
``` ```
(2) Obtain the required permissions. (2) Obtain the required permissions.
...@@ -351,13 +357,13 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -351,13 +357,13 @@ You can obtain the distributed table name for a remote device based on the local
```js ```js
let context = featureAbility.getContext(); let context = featureAbility.getContext();
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) { context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
console.info(`result.requestCode=${result.requestCode}`) console.info(`result.requestCode=${result.requestCode}`);
}) })
let promise = rdbStore.setDistributedTables(["test"]) let promise = store.setDistributedTables(["test"]);
promise.then(() => { promise.then(() => {
console.info("setDistributedTables success.") console.info(`setDistributedTables success.`);
}).catch((err) => { }).catch((err) => {
console.info("setDistributedTables failed.") console.error(`setDistributedTables failed, ${err}`);
}) })
``` ```
...@@ -372,16 +378,16 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -372,16 +378,16 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows: The sample code is as follows:
```js ```js
let predicate = new data_rdb.RdbPredicates('test') let predicate = new relationalStore.RdbPredicates('test');
predicate.inDevices(['12345678abcde']) predicate.inDevices(['12345678abcde']);
let promise = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicate) let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicate);
promise.then((result) => { promise.then((result) => {
console.log('sync done.') console.info(`sync done.`);
for (let i = 0; i < result.length; i++) { for (let i = 0; i < result.length; i++) {
console.log('device=' + result[i][0] + 'status=' + result[i][1]) console.info(`device=${result[i][0]}, status=${result[i][1]}`);
} }
}).catch((err) => { }).catch((err) => {
console.log('sync failed') console.error(`sync failed, err: ${err}`);
}) })
``` ```
...@@ -395,15 +401,15 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -395,15 +401,15 @@ You can obtain the distributed table name for a remote device based on the local
```js ```js
function storeObserver(devices) { function storeObserver(devices) {
for (let i = 0; i < devices.length; i++) { for (let i = 0; i < devices.length; i++) {
console.log('device=' + device[i] + 'data changed') console.info(`device= ${devices[i]} data changed`);
} }
} }
try { try {
rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) store.on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
} catch (err) { } catch (err) {
console.log('register observer failed') console.error(`register observer failed, err: ${err}`);
} }
``` ```
...@@ -416,8 +422,24 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -416,8 +422,24 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows: The sample code is as follows:
```js ```js
let tableName = rdbStore.obtainDistributedTableName(deviceId, "test"); import deviceManager from '@ohos.distributedHardware.deviceManager'
let resultSet = rdbStore.querySql("SELECT * FROM " + tableName)
let deviceIds = [];
deviceManager.createDeviceManager('bundleName', (err, value) => {
if (!err) {
let devManager = value;
if (devManager != null) {
// Obtain device IDs.
let devices = devManager.getTrustedDeviceListSync();
for (let i = 0; i < devices.length; i++) {
deviceIds[i] = devices[i].deviceId;
}
}
}
})
let tableName = store.obtainDistributedTableName(deviceIds[0], "test");
let resultSet = store.querySql("SELECT * FROM " + tableName);
``` ```
8. Query data of a remote device. 8. Query data of a remote device.
...@@ -429,19 +451,19 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -429,19 +451,19 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows: The sample code is as follows:
```js ```js
let rdbPredicate = new data_rdb.RdbPredicates('employee') let rdbPredicate = new relationalStore.RdbPredicates('employee');
predicates.greaterThan("id", 0) predicates.greaterThan("id", 0) ;
let promiseQuery = rdbStore.remoteQuery('12345678abcde', 'employee', rdbPredicate) let promiseQuery = store.remoteQuery('12345678abcde', 'employee', rdbPredicate);
promiseQuery.then((resultSet) => { promiseQuery.then((resultSet) => {
while (resultSet.goToNextRow()) { while (resultSet.goToNextRow()) {
let idx = resultSet.getLong(0); let idx = resultSet.getLong(0);
let name = resultSet.getString(1); let name = resultSet.getString(1);
let age = resultSet.getLong(2); let age = resultSet.getLong(2);
console.info(idx + " " + name + " " + age); console.info(`indx: ${idx}, name: ${name}, age: ${age}`);
} }
resultSet.close(); resultSet.close();
}).catch((err) => { }).catch((err) => {
console.info("failed to remoteQuery, err: " + err) console.error(`failed to remoteQuery, err: ${err}`);
}) })
``` ```
...@@ -452,11 +474,11 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -452,11 +474,11 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows: The sample code is as follows:
```js ```js
let promiseBackup = rdbStore.backup("dbBackup.db") let promiseBackup = store.backup("dbBackup.db");
promiseBackup.then(() => { promiseBackup.then(() => {
console.info('Backup success.') console.info(`Backup success.`);
}).catch((err) => { }).catch((err) => {
console.info('Backup failed, err: ' + err) console.error(`Backup failed, err: ${err}`);
}) })
``` ```
...@@ -465,10 +487,10 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -465,10 +487,10 @@ You can obtain the distributed table name for a remote device based on the local
The sample code is as follows: The sample code is as follows:
```js ```js
let promiseRestore = rdbStore.restore("dbBackup.db") let promiseRestore = store.restore("dbBackup.db");
promiseRestore.then(() => { promiseRestore.then(() => {
console.info('Restore success.') console.info(`Restore success.`);
}).catch((err) => { }).catch((err) => {
console.info('Restore failed, err: ' + err) console.error(`Restore failed, err: ${err}`);
}) })
``` ```
...@@ -15,10 +15,10 @@ The **relationalStore** module provides the following functions: ...@@ -15,10 +15,10 @@ The **relationalStore** module provides the following functions:
## Modules to Import ## Modules to Import
```js ```js
import data_rdb from '@ohos.data.relationalStore'; import relationalStore from '@ohos.data.relationalStore'
``` ```
## data_rdb.getRdbStore ## relationalStore.getRdbStore
getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback&lt;RdbStore&gt;): void getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback&lt;RdbStore&gt;): void
...@@ -51,20 +51,23 @@ FA model: ...@@ -51,20 +51,23 @@ FA model:
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
} };
data_rdb.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) { relationalStore.getRdbStore(context, STORE_CONFIG, function (err, rdbStore) {
if (err) { store = rdbStore;
console.info("Failed to get RdbStore, err: " + err) if (err) {
return console.error(`Get RdbStore failed, err: ${err}`);
} return;
console.log("Got RdbStore successfully.") }
console.info(`Get RdbStore successfully.`);
}) })
``` ```
...@@ -74,24 +77,26 @@ Stage model: ...@@ -74,24 +77,26 @@ Stage model:
import UIAbility from '@ohos.app.ability.UIAbility' import UIAbility from '@ohos.app.ability.UIAbility'
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage) {
const STORE_CONFIG = { var store;
name: "RdbTest.db", const STORE_CONFIG = {
securityLevel: data_rdb.SecurityLevel.S1 name: "RdbTest.db",
} securityLevel: relationalStore.SecurityLevel.S1
};
data_rdb.getRdbStore(this.context, STORE_CONFIG, function (err, rdbStore) { relationalStore.getRdbStore(this.context, STORE_CONFIG, function (err, rdbStore) {
if (err) { store = rdbStore;
console.info("Failed to get RdbStore, err: " + err) if (err) {
return console.error(`Get RdbStore failed, err: ${err}`);
} return;
console.log("Got RdbStore successfully.") }
}) console.info(`Get RdbStore successfully.`);
} })
}
} }
``` ```
## data_rdb.getRdbStore ## relationalStore.getRdbStore
getRdbStore(context: Context, config: StoreConfig): Promise&lt;RdbStore&gt; getRdbStore(context: Context, config: StoreConfig): Promise&lt;RdbStore&gt;
...@@ -128,19 +133,22 @@ FA model: ...@@ -128,19 +133,22 @@ FA model:
```js ```js
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
} };
let promise = data_rdb.getRdbStore(context, STORE_CONFIG); let promise = relationalStore.getRdbStore(context, STORE_CONFIG);
promise.then(async (rdbStore) => { promise.then(async (rdbStore) => {
console.log("Got RdbStore successfully.") store = rdbStore;
console.info(`Get RdbStore successfully.`);
}).catch((err) => { }).catch((err) => {
console.log("Failed to get RdbStore, err: " + err) console.error(`Get RdbStore failed, err: ${err}`);
}) })
``` ```
...@@ -150,23 +158,25 @@ Stage model: ...@@ -150,23 +158,25 @@ Stage model:
import UIAbility from '@ohos.app.ability.UIAbility' import UIAbility from '@ohos.app.ability.UIAbility'
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage) {
const STORE_CONFIG = { var store;
name: "RdbTest.db", const STORE_CONFIG = {
securityLevel: data_rdb.SecurityLevel.S1 name: "RdbTest.db",
} securityLevel: relationalStore.SecurityLevel.S1
};
let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG); let promise = relationalStore.getRdbStore(this.context, STORE_CONFIG);
promise.then(async (rdbStore) => { promise.then(async (rdbStore) => {
console.log("Got RdbStore successfully.") store = rdbStore;
}).catch((err) => { console.info(`Get RdbStore successfully.`)
console.log("Failed to get RdbStore, err: " + err) }).catch((err) => {
}) console.error(`Get RdbStore failed, err: ${err}`);
} })
}
} }
``` ```
## data_rdb.deleteRdbStore ## relationalStore.deleteRdbStore
deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void deleteRdbStore(context: Context, name: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -200,12 +210,12 @@ import featureAbility from '@ohos.ability.featureAbility' ...@@ -200,12 +210,12 @@ import featureAbility from '@ohos.ability.featureAbility'
// Obtain the context. // Obtain the context.
let context = featureAbility.getContext() let context = featureAbility.getContext()
data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) { relationalStore.deleteRdbStore(context, "RdbTest.db", function (err) {
if (err) { if (err) {
console.info("Failed to delete RdbStore, err: " + err) console.error(`Delete RdbStore failed, err: ${err}`);
return return;
} }
console.log("Deleted RdbStore successfully.") console.info(`Delete RdbStore successfully.`);
}) })
``` ```
...@@ -215,19 +225,19 @@ Stage model: ...@@ -215,19 +225,19 @@ Stage model:
import UIAbility from '@ohos.app.ability.UIAbility' import UIAbility from '@ohos.app.ability.UIAbility'
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err) { relationalStore.deleteRdbStore(this.context, "RdbTest.db", function (err) {
if (err) { if (err) {
console.info("Failed to delete RdbStore, err: " + err) console.error(`Delete RdbStore failed, err: ${err}`);
return return;
} }
console.log("Deleted RdbStore successfully.") console.info(`Delete RdbStore successfully.`);
}) })
} }
} }
``` ```
## data_rdb.deleteRdbStore ## relationalStore.deleteRdbStore
deleteRdbStore(context: Context, name: string): Promise&lt;void&gt; deleteRdbStore(context: Context, name: string): Promise&lt;void&gt;
...@@ -264,13 +274,13 @@ FA model: ...@@ -264,13 +274,13 @@ FA model:
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
// Obtain the context. // Obtain the context.
let context = featureAbility.getContext() let context = featureAbility.getContext();
let promise = data_rdb.deleteRdbStore(context, "RdbTest.db") let promise = relationalStore.deleteRdbStore(context, "RdbTest.db");
promise.then(()=>{ promise.then(()=>{
console.log("Deleted RdbStore successfully.") console.info(`Delete RdbStore successfully.`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to delete RdbStore, err: " + err) console.error(`Delete RdbStore failed, err: ${err}`);
}) })
``` ```
...@@ -280,14 +290,14 @@ Stage model: ...@@ -280,14 +290,14 @@ Stage model:
import UIAbility from '@ohos.app.ability.UIAbility' import UIAbility from '@ohos.app.ability.UIAbility'
class EntryAbility extends UIAbility { class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){ onWindowStageCreate(windowStage){
let promise = data_rdb.deleteRdbStore(this.context, "RdbTest.db") let promise = relationalStore.deleteRdbStore(this.context, "RdbTest.db");
promise.then(()=>{ promise.then(()=>{
console.log("Deleted RdbStore successfully.") console.info(`Delete RdbStore successfully.`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to delete RdbStore, err: " + err) console.error(`Delete RdbStore failed, err: ${err}`);
}) })
} }
} }
``` ```
...@@ -397,7 +407,7 @@ A constructor used to create an **RdbPredicates** object. ...@@ -397,7 +407,7 @@ A constructor used to create an **RdbPredicates** object.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
``` ```
### inDevices ### inDevices
...@@ -424,8 +434,8 @@ Sets an **RdbPredicates** to specify the remote devices to connect on the networ ...@@ -424,8 +434,8 @@ Sets an **RdbPredicates** to specify the remote devices to connect on the networ
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.inDevices(['12345678abcde']) predicates.inDevices(['12345678abcde']);
``` ```
### inAllDevices ### inAllDevices
...@@ -446,8 +456,8 @@ Sets an **RdbPredicates** to specify all remote devices on the network to connec ...@@ -446,8 +456,8 @@ Sets an **RdbPredicates** to specify all remote devices on the network to connec
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.inAllDevices() predicates.inAllDevices();
``` ```
### equalTo ### equalTo
...@@ -475,8 +485,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -475,8 +485,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "lisi") predicates.equalTo("NAME", "lisi");
``` ```
...@@ -505,8 +515,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -505,8 +515,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.notEqualTo("NAME", "lisi") predicates.notEqualTo("NAME", "lisi");
``` ```
...@@ -528,7 +538,7 @@ Adds a left parenthesis to the **RdbPredicates**. ...@@ -528,7 +538,7 @@ Adds a left parenthesis to the **RdbPredicates**.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "lisi") predicates.equalTo("NAME", "lisi")
.beginWrap() .beginWrap()
.equalTo("AGE", 18) .equalTo("AGE", 18)
...@@ -554,7 +564,7 @@ Adds a right parenthesis to the **RdbPredicates**. ...@@ -554,7 +564,7 @@ Adds a right parenthesis to the **RdbPredicates**.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "lisi") predicates.equalTo("NAME", "lisi")
.beginWrap() .beginWrap()
.equalTo("AGE", 18) .equalTo("AGE", 18)
...@@ -580,7 +590,7 @@ Adds the OR condition to the **RdbPredicates**. ...@@ -580,7 +590,7 @@ Adds the OR condition to the **RdbPredicates**.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
.or() .or()
.equalTo("NAME", "Rose") .equalTo("NAME", "Rose")
...@@ -603,7 +613,7 @@ Adds the AND condition to the **RdbPredicates**. ...@@ -603,7 +613,7 @@ Adds the AND condition to the **RdbPredicates**.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa")
.and() .and()
.equalTo("SALARY", 200.5) .equalTo("SALARY", 200.5)
...@@ -633,8 +643,8 @@ Sets an **RdbPredicates** to match a string containing the specified value. ...@@ -633,8 +643,8 @@ Sets an **RdbPredicates** to match a string containing the specified value.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.contains("NAME", "os") predicates.contains("NAME", "os");
``` ```
### beginsWith ### beginsWith
...@@ -661,8 +671,8 @@ Sets an **RdbPredicates** to match a string that starts with the specified value ...@@ -661,8 +671,8 @@ Sets an **RdbPredicates** to match a string that starts with the specified value
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.beginsWith("NAME", "os") predicates.beginsWith("NAME", "os");
``` ```
### endsWith ### endsWith
...@@ -689,8 +699,8 @@ Sets an **RdbPredicates** to match a string that ends with the specified value. ...@@ -689,8 +699,8 @@ Sets an **RdbPredicates** to match a string that ends with the specified value.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.endsWith("NAME", "se") predicates.endsWith("NAME", "se");
``` ```
### isNull ### isNull
...@@ -716,8 +726,8 @@ Sets an **RdbPredicates** to match the field whose value is null. ...@@ -716,8 +726,8 @@ Sets an **RdbPredicates** to match the field whose value is null.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.isNull("NAME") predicates.isNull("NAME");
``` ```
### isNotNull ### isNotNull
...@@ -743,8 +753,8 @@ Sets an **RdbPredicates** to match the field whose value is not null. ...@@ -743,8 +753,8 @@ Sets an **RdbPredicates** to match the field whose value is not null.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.isNotNull("NAME") predicates.isNotNull("NAME");
``` ```
### like ### like
...@@ -771,8 +781,8 @@ Sets an **RdbPredicates** to match a string that is similar to the specified val ...@@ -771,8 +781,8 @@ Sets an **RdbPredicates** to match a string that is similar to the specified val
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.like("NAME", "%os%") predicates.like("NAME", "%os%");
``` ```
### glob ### glob
...@@ -799,8 +809,8 @@ Sets an **RdbPredicates** to match the specified string. ...@@ -799,8 +809,8 @@ Sets an **RdbPredicates** to match the specified string.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.glob("NAME", "?h*g") predicates.glob("NAME", "?h*g");
``` ```
### between ### between
...@@ -828,8 +838,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -828,8 +838,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.between("AGE", 10, 50) predicates.between("AGE", 10, 50);
``` ```
### notBetween ### notBetween
...@@ -857,8 +867,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -857,8 +867,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.notBetween("AGE", 10, 50) predicates.notBetween("AGE", 10, 50);
``` ```
### greaterThan ### greaterThan
...@@ -885,8 +895,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -885,8 +895,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.greaterThan("AGE", 18) predicates.greaterThan("AGE", 18);
``` ```
### lessThan ### lessThan
...@@ -913,8 +923,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -913,8 +923,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.lessThan("AGE", 20) predicates.lessThan("AGE", 20);
``` ```
### greaterThanOrEqualTo ### greaterThanOrEqualTo
...@@ -941,8 +951,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -941,8 +951,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.greaterThanOrEqualTo("AGE", 18) predicates.greaterThanOrEqualTo("AGE", 18);
``` ```
### lessThanOrEqualTo ### lessThanOrEqualTo
...@@ -969,8 +979,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va ...@@ -969,8 +979,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.lessThanOrEqualTo("AGE", 20) predicates.lessThanOrEqualTo("AGE", 20);
``` ```
### orderByAsc ### orderByAsc
...@@ -996,8 +1006,8 @@ Sets an **RdbPredicates** to match the column with values sorted in ascending or ...@@ -996,8 +1006,8 @@ Sets an **RdbPredicates** to match the column with values sorted in ascending or
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.orderByAsc("NAME") predicates.orderByAsc("NAME");
``` ```
### orderByDesc ### orderByDesc
...@@ -1023,8 +1033,8 @@ Sets an **RdbPredicates** to match the column with values sorted in descending o ...@@ -1023,8 +1033,8 @@ Sets an **RdbPredicates** to match the column with values sorted in descending o
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.orderByDesc("AGE") predicates.orderByDesc("AGE");
``` ```
### distinct ### distinct
...@@ -1044,8 +1054,8 @@ Sets an **RdbPredicates** to filter out duplicate records. ...@@ -1044,8 +1054,8 @@ Sets an **RdbPredicates** to filter out duplicate records.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose").distinct() predicates.equalTo("NAME", "Rose").distinct();
``` ```
### limitAs ### limitAs
...@@ -1071,8 +1081,8 @@ Sets an **RdbPredicates** to specify the maximum number of records. ...@@ -1071,8 +1081,8 @@ Sets an **RdbPredicates** to specify the maximum number of records.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose").limitAs(3) predicates.equalTo("NAME", "Rose").limitAs(3);
``` ```
### offsetAs ### offsetAs
...@@ -1098,8 +1108,8 @@ Sets an **RdbPredicates** to specify the start position of the returned result. ...@@ -1098,8 +1108,8 @@ Sets an **RdbPredicates** to specify the start position of the returned result.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose").offsetAs(3) predicates.equalTo("NAME", "Rose").offsetAs(3);
``` ```
### groupBy ### groupBy
...@@ -1125,8 +1135,8 @@ Sets an **RdbPredicates** to group rows that have the same value into summary ro ...@@ -1125,8 +1135,8 @@ Sets an **RdbPredicates** to group rows that have the same value into summary ro
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.groupBy(["AGE", "NAME"]) predicates.groupBy(["AGE", "NAME"]);
``` ```
### indexedBy ### indexedBy
...@@ -1153,8 +1163,8 @@ Sets an **RdbPredicates** object to specify the index column. ...@@ -1153,8 +1163,8 @@ Sets an **RdbPredicates** object to specify the index column.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.indexedBy("SALARY_INDEX") predicates.indexedBy("SALARY_INDEX");
``` ```
### in ### in
...@@ -1181,8 +1191,8 @@ Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueTyp ...@@ -1181,8 +1191,8 @@ Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueTyp
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.in("AGE", [18, 20]) predicates.in("AGE", [18, 20]);
``` ```
### notIn ### notIn
...@@ -1209,8 +1219,8 @@ Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueTyp ...@@ -1209,8 +1219,8 @@ Sets an **RdbPredicates** to match the field with data type **Array&#60;ValueTyp
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.notIn("NAME", ["Lisa", "Rose"]) predicates.notIn("NAME", ["Lisa", "Rose"]);
``` ```
## RdbStore ## RdbStore
...@@ -1231,9 +1241,9 @@ Before using the following APIs, use [executeSql](#executesql) to initialize the ...@@ -1231,9 +1241,9 @@ Before using the following APIs, use [executeSql](#executesql) to initialize the
```js ```js
// Set the RDB store version. // Set the RDB store version.
rdbStore.version = 3 store.version = 3;
// Obtain the RDB store version. // Obtain the RDB store version.
console.info("Get RdbStore version is " + rdbStore.version) console.info(`RdbStore version is ${store.version}`);
``` ```
### insert ### insert
...@@ -1256,17 +1266,17 @@ Inserts a row of data into a table. This API uses an asynchronous callback to re ...@@ -1256,17 +1266,17 @@ Inserts a row of data into a table. This API uses an asynchronous callback to re
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Lisa", "NAME": "Lisa",
"AGE": 18, "AGE": 18,
"SALARY": 100.5, "SALARY": 100.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} };
rdbStore.insert("EMPLOYEE", valueBucket, function (status, rowId) { store.insert("EMPLOYEE", valueBucket, function (err, rowId) {
if (status) { if (err) {
console.log("Failed to insert data"); console.error(`Insert is failed, err: ${err}`);
return; return;
} }
console.log("Inserted data successfully, rowId = " + rowId); console.info(`Insert is successful, rowId = ${rowId}`);
}) })
``` ```
...@@ -1291,17 +1301,17 @@ Inserts a row of data into a table. This API uses an asynchronous callback to re ...@@ -1291,17 +1301,17 @@ Inserts a row of data into a table. This API uses an asynchronous callback to re
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Lisa", "NAME": "Lisa",
"AGE": 18, "AGE": 18,
"SALARY": 100.5, "SALARY": 100.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} };
rdbStore.insert("EMPLOYEE", valueBucket, data_rdb.ConflictResolution.ON_CONFLICT_REPLACE, function (status, rowId) { store.insert("EMPLOYEE", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, function (err, rowId) {
if (status) { if (err) {
console.log("Failed to insert data"); console.error(`Insert is failed, err: ${err}`);
return; return;
} }
console.log("Inserted data successfully, rowId = " + rowId); console.info(`Insert is successful, rowId = ${rowId}`);
}) })
``` ```
...@@ -1330,16 +1340,16 @@ Inserts a row of data into a table. This API uses a promise to return the result ...@@ -1330,16 +1340,16 @@ Inserts a row of data into a table. This API uses a promise to return the result
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Lisa", "NAME": "Lisa",
"AGE": 18, "AGE": 18,
"SALARY": 100.5, "SALARY": 100.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} };
let promise = rdbStore.insert("EMPLOYEE", valueBucket) let promise = store.insert("EMPLOYEE", valueBucket);
promise.then((rowId) => { promise.then((rowId) => {
console.log("Inserted data successfully, rowId = " + rowId); console.info(`Insert is successful, rowId = ${rowId}`);
}).catch((status) => { }).catch((err) => {
console.log("Failed to insert data"); console.error(`Insert is failed, err: ${err}`);
}) })
``` ```
...@@ -1369,16 +1379,16 @@ Inserts a row of data into a table. This API uses a promise to return the result ...@@ -1369,16 +1379,16 @@ Inserts a row of data into a table. This API uses a promise to return the result
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Lisa", "NAME": "Lisa",
"AGE": 18, "AGE": 18,
"SALARY": 100.5, "SALARY": 100.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} };
let promise = rdbStore.insert("EMPLOYEE", valueBucket, data_rdb.ConflictResolution.ON_CONFLICT_REPLACE) let promise = store.insert("EMPLOYEE", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
promise.then((rowId) => { promise.then((rowId) => {
console.log("Inserted data successfully, rowId = " + rowId); console.info(`Insert is successful, rowId = ${rowId}`);
}).catch((status) => { }).catch((err) => {
console.log("Failed to insert data"); console.error(`Insert is failed, err: ${err}`);
}) })
``` ```
...@@ -1402,31 +1412,31 @@ Batch inserts data into a table. This API uses an asynchronous callback to retur ...@@ -1402,31 +1412,31 @@ Batch inserts data into a table. This API uses an asynchronous callback to retur
```js ```js
const valueBucket1 = { const valueBucket1 = {
"NAME": "Lisa", "NAME": "Lisa",
"AGE": 18, "AGE": 18,
"SALARY": 100.5, "SALARY": 100.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]) "CODES": new Uint8Array([1, 2, 3, 4, 5])
} };
const valueBucket2 = { const valueBucket2 = {
"NAME": "Jack", "NAME": "Jack",
"AGE": 19, "AGE": 19,
"SALARY": 101.5, "SALARY": 101.5,
"CODES": new Uint8Array([6, 7, 8, 9, 10]) "CODES": new Uint8Array([6, 7, 8, 9, 10])
} };
const valueBucket3 = { const valueBucket3 = {
"NAME": "Tom", "NAME": "Tom",
"AGE": 20, "AGE": 20,
"SALARY": 102.5, "SALARY": 102.5,
"CODES": new Uint8Array([11, 12, 13, 14, 15]) "CODES": new Uint8Array([11, 12, 13, 14, 15])
} };
let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
rdbStore.batchInsert("EMPLOYEE", valueBuckets, function(status, insertNum) { store.batchInsert("EMPLOYEE", valueBuckets, function(err, insertNum) {
if (status) { if (err) {
console.log("batchInsert is failed, status = " + status); console.error(`batchInsert is failed, err: ${err}`);
return; return;
} }
console.log("batchInsert is successful, the number of values that were inserted = " + insertNum); console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
}) })
``` ```
...@@ -1455,30 +1465,30 @@ Batch inserts data into a table. This API uses a promise to return the result. ...@@ -1455,30 +1465,30 @@ Batch inserts data into a table. This API uses a promise to return the result.
```js ```js
const valueBucket1 = { const valueBucket1 = {
"NAME": "Lisa", "NAME": "Lisa",
"AGE": 18, "AGE": 18,
"SALARY": 100.5, "SALARY": 100.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]) "CODES": new Uint8Array([1, 2, 3, 4, 5])
} };
const valueBucket2 = { const valueBucket2 = {
"NAME": "Jack", "NAME": "Jack",
"AGE": 19, "AGE": 19,
"SALARY": 101.5, "SALARY": 101.5,
"CODES": new Uint8Array([6, 7, 8, 9, 10]) "CODES": new Uint8Array([6, 7, 8, 9, 10])
} };
const valueBucket3 = { const valueBucket3 = {
"NAME": "Tom", "NAME": "Tom",
"AGE": 20, "AGE": 20,
"SALARY": 102.5, "SALARY": 102.5,
"CODES": new Uint8Array([11, 12, 13, 14, 15]) "CODES": new Uint8Array([11, 12, 13, 14, 15])
} };
let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3); let valueBuckets = new Array(valueBucket1, valueBucket2, valueBucket3);
let promise = rdbStore.batchInsert("EMPLOYEE", valueBuckets); let promise = store.batchInsert("EMPLOYEE", valueBuckets);
promise.then((insertNum) => { promise.then((insertNum) => {
console.log("batchInsert is successful, the number of values that were inserted = " + insertNum); console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`);
}).catch((status) => { }).catch((err) => {
console.log("batchInsert is failed, status = " + status); console.error(`batchInsert is failed, err: ${err}`);
}) })
``` ```
...@@ -1502,19 +1512,19 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T ...@@ -1502,19 +1512,19 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Rose", "NAME": "Rose",
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} };
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa");
rdbStore.update(valueBucket, predicates, function (err, rows) { store.update(valueBucket, predicates, function (err, rows) {
if (err) { if (err) {
console.info("Failed to update data, err: " + err) console.error(`Updated failed, err: ${err}`);
return return;
} }
console.log("Updated row count: " + rows) console.info(`Updated row count: ${rows}`);
}) })
``` ```
...@@ -1539,19 +1549,19 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T ...@@ -1539,19 +1549,19 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Rose", "NAME": "Rose",
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} };
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa");
rdbStore.update(valueBucket, predicates, data_rdb.ConflictResolution.ON_CONFLICT_REPLACE, function (err, rows) { store.update(valueBucket, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE, function (err, rows) {
if (err) { if (err) {
console.info("Failed to update data, err: " + err) console.error(`Updated failed, err: ${err}`);
return return;
} }
console.log("Updated row count: " + rows) console.info(`Updated row count: ${rows}`);
}) })
``` ```
...@@ -1580,18 +1590,18 @@ Updates data based on the specified **RdbPredicates** object. This API uses a pr ...@@ -1580,18 +1590,18 @@ Updates data based on the specified **RdbPredicates** object. This API uses a pr
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Rose", "NAME": "Rose",
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} };
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa");
let promise = rdbStore.update(valueBucket, predicates) let promise = store.update(valueBucket, predicates);
promise.then(async (rows) => { promise.then(async (rows) => {
console.log("Updated row count: " + rows) console.info(`Updated row count: ${rows}`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to update data, err: " + err) console.error(`Updated failed, err: ${err}`);
}) })
``` ```
...@@ -1621,18 +1631,18 @@ Updates data based on the specified **RdbPredicates** object. This API uses a pr ...@@ -1621,18 +1631,18 @@ Updates data based on the specified **RdbPredicates** object. This API uses a pr
```js ```js
const valueBucket = { const valueBucket = {
"NAME": "Rose", "NAME": "Rose",
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} };
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa");
let promise = rdbStore.update(valueBucket, predicates, data_rdb.ConflictResolution.ON_CONFLICT_REPLACE) let promise = store.update(valueBucket, predicates, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE);
promise.then(async (rows) => { promise.then(async (rows) => {
console.log("Updated row count: " + rows) console.info(`Updated row count: ${rows}`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to update data, err: " + err) console.error(`Updated failed, err: ${err}`);
}) })
``` ```
...@@ -1664,15 +1674,15 @@ const valueBucket = { ...@@ -1664,15 +1674,15 @@ const valueBucket = {
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} };
let predicates = new dataSharePredicates.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa");
rdbStore.update("EMPLOYEE", valueBucket, predicates, function (err, rows) { store.update("EMPLOYEE", valueBucket, predicates, function (err, rows) {
if (err) { if (err) {
console.info("Failed to update data, err: " + err) console.error(`Updated failed, err: ${err}`);
return return;
} }
console.log("Updated row count: " + rows) console.info(`Updated row count: ${rows}`);
}) })
``` ```
...@@ -1705,18 +1715,18 @@ Updates data based on the specified **DataSharePredicates** object. This API use ...@@ -1705,18 +1715,18 @@ Updates data based on the specified **DataSharePredicates** object. This API use
```js ```js
import dataSharePredicates from '@ohos.data.dataSharePredicates' import dataSharePredicates from '@ohos.data.dataSharePredicates'
const valueBucket = { const valueBucket = {
"NAME": "Rose", "NAME": "Rose",
"AGE": 22, "AGE": 22,
"SALARY": 200.5, "SALARY": 200.5,
"CODES": new Uint8Array([1, 2, 3, 4, 5]), "CODES": new Uint8Array([1, 2, 3, 4, 5]),
} };
let predicates = new dataSharePredicates.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa");
let promise = rdbStore.update("EMPLOYEE", valueBucket, predicates) let promise = store.update("EMPLOYEE", valueBucket, predicates);
promise.then(async (rows) => { promise.then(async (rows) => {
console.log("Updated row count: " + rows) console.info(`Updated row count: ${rows}`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to update data, err: " + err) console.error(`Updated failed, err: ${err}`);
}) })
``` ```
...@@ -1738,14 +1748,14 @@ Deletes data from the RDB store based on the specified **RdbPredicates** object. ...@@ -1738,14 +1748,14 @@ Deletes data from the RDB store based on the specified **RdbPredicates** object.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa");
rdbStore.delete(predicates, function (err, rows) { store.delete(predicates, function (err, rows) {
if (err) { if (err) {
console.info("Failed to delete data, err: " + err) console.error(`Delete failed, err: ${err}`);
return return;
} }
console.log("Deleted rows: " + rows) console.info(`Delete rows: ${rows}`);
}) })
``` ```
...@@ -1772,13 +1782,13 @@ Deletes data from the RDB store based on the specified **RdbPredicates** object. ...@@ -1772,13 +1782,13 @@ Deletes data from the RDB store based on the specified **RdbPredicates** object.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa");
let promise = rdbStore.delete(predicates) let promise = store.delete(predicates);
promise.then((rows) => { promise.then((rows) => {
console.log("Deleted rows: " + rows) console.info(`Delete rows: ${rows}`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to delete data, err: " + err) console.error(`Delete failed, err: ${err}`);
}) })
``` ```
...@@ -1804,14 +1814,14 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o ...@@ -1804,14 +1814,14 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o
```js ```js
import dataSharePredicates from '@ohos.data.dataSharePredicates' import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa");
rdbStore.delete("EMPLOYEE", predicates, function (err, rows) { store.delete("EMPLOYEE", predicates, function (err, rows) {
if (err) { if (err) {
console.info("Failed to delete data, err: " + err) console.error(`Delete failed, err: ${err}`);
return return;
} }
console.log("Deleted rows: " + rows) console.info(`Delete rows: ${rows}`);
}) })
``` ```
...@@ -1842,13 +1852,13 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o ...@@ -1842,13 +1852,13 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o
```js ```js
import dataSharePredicates from '@ohos.data.dataSharePredicates' import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Lisa") predicates.equalTo("NAME", "Lisa");
let promise = rdbStore.delete("EMPLOYEE", predicates) let promise = store.delete("EMPLOYEE", predicates);
promise.then((rows) => { promise.then((rows) => {
console.log("Deleted rows: " + rows) console.info(`Delete rows: ${rows}`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to delete data, err: " + err) console.error(`Delete failed, err: ${err}`);
}) })
``` ```
...@@ -1871,15 +1881,15 @@ Queries data from the RDB store based on specified conditions. This API uses an ...@@ -1871,15 +1881,15 @@ Queries data from the RDB store based on specified conditions. This API uses an
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose");
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
if (err) { if (err) {
console.info("Failed to query data, err: " + err) console.error(`Query failed, err: ${err}`);
return return;
} }
console.log("ResultSet column names: " + resultSet.columnNames) console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.log("ResultSet column count: " + resultSet.columnCount) console.info(`ResultSet column count: ${resultSet.columnCount}`);
}) })
``` ```
...@@ -1907,14 +1917,14 @@ Queries data from the RDB store based on specified conditions. This API uses a p ...@@ -1907,14 +1917,14 @@ Queries data from the RDB store based on specified conditions. This API uses a p
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates("EMPLOYEE") let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose");
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
console.log("ResultSet column names: " + resultSet.columnNames) console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.log("ResultSet column count: " + resultSet.columnCount) console.info(`ResultSet column count: ${resultSet.columnCount}`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to query data, err: " + err) console.error(`Query failed, err: ${err}`);
}) })
``` ```
...@@ -1941,15 +1951,15 @@ Queries data from the RDB store based on specified conditions. This API uses an ...@@ -1941,15 +1951,15 @@ Queries data from the RDB store based on specified conditions. This API uses an
```js ```js
import dataSharePredicates from '@ohos.data.dataSharePredicates' import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose");
rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) { store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err, resultSet) {
if (err) { if (err) {
console.info("Failed to query data, err: " + err) console.error(`Query failed, err: ${err}`);
return return;
} }
console.log("ResultSet column names: " + resultSet.columnNames) console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.log("ResultSet column count: " + resultSet.columnCount) console.info(`ResultSet column count: ${resultSet.columnCount}`);
}) })
``` ```
...@@ -1981,14 +1991,14 @@ Queries data from the RDB store based on specified conditions. This API uses a p ...@@ -1981,14 +1991,14 @@ Queries data from the RDB store based on specified conditions. This API uses a p
```js ```js
import dataSharePredicates from '@ohos.data.dataSharePredicates' import dataSharePredicates from '@ohos.data.dataSharePredicates'
let predicates = new dataSharePredicates.DataSharePredicates() let predicates = new dataSharePredicates.DataSharePredicates();
predicates.equalTo("NAME", "Rose") predicates.equalTo("NAME", "Rose");
let promise = rdbStore.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promise = store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
console.log("ResultSet column names: " + resultSet.columnNames) console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.log("ResultSet column count: " + resultSet.columnCount) console.info(`ResultSet column count: ${resultSet.columnCount}`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to query data, err: " + err) console.error(`Query failed, err: ${err}`);
}) })
``` ```
...@@ -2013,17 +2023,18 @@ Queries data from the RDB store of a remote device based on specified conditions ...@@ -2013,17 +2023,18 @@ Queries data from the RDB store of a remote device based on specified conditions
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates('EMPLOYEE') let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.greaterThan("id", 0) predicates.greaterThan("id", 0);
rdbStore.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], store.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"],
function(err, resultSet){ function(err, resultSet) {
if (err) { if (err) {
console.info("Failed to remoteQuery, err: " + err) console.error(`Failed to remoteQuery, err: ${err}`);
return return;
} }
console.info("ResultSet column names: " + resultSet.columnNames) console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.info("ResultSet column count: " + resultSet.columnCount) console.info(`ResultSet column count: ${resultSet.columnCount}`);
}) }
)
``` ```
### remoteQuery ### remoteQuery
...@@ -2052,14 +2063,14 @@ Queries data from the RDB store of a remote device based on specified conditions ...@@ -2052,14 +2063,14 @@ Queries data from the RDB store of a remote device based on specified conditions
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates('EMPLOYEE') let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.greaterThan("id", 0) predicates.greaterThan("id", 0);
let promise = rdbStore.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promise = store.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
console.info("ResultSet column names: " + resultSet.columnNames) console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.info("ResultSet column count: " + resultSet.columnCount) console.info(`ResultSet column count: ${resultSet.columnCount}`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to remoteQuery , err: " + err) console.error(`Failed to remoteQuery, err: ${err}`);
}) })
``` ```
...@@ -2082,13 +2093,13 @@ Queries data using the specified SQL statement. This API uses an asynchronous ca ...@@ -2082,13 +2093,13 @@ Queries data using the specified SQL statement. This API uses an asynchronous ca
**Example** **Example**
```js ```js
rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) { store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo'], function (err, resultSet) {
if (err) { if (err) {
console.info("Failed to query data, err: " + err) console.error(`Query failed, err: ${err}`);
return return;
} }
console.log("ResultSet column names: " + resultSet.columnNames) console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.log("ResultSet column count: " + resultSet.columnCount) console.info(`ResultSet column count: ${resultSet.columnCount}`);
}) })
``` ```
...@@ -2116,12 +2127,12 @@ Queries data using the specified SQL statement. This API uses a promise to retur ...@@ -2116,12 +2127,12 @@ Queries data using the specified SQL statement. This API uses a promise to retur
**Example** **Example**
```js ```js
let promise = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo']) let promise = store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo']);
promise.then((resultSet) => { promise.then((resultSet) => {
console.log("ResultSet column names: " + resultSet.columnNames) console.info(`ResultSet column names: ${resultSet.columnNames}`);
console.log("ResultSet column count: " + resultSet.columnCount) console.info(`ResultSet column count: ${resultSet.columnCount}`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to query data, err: " + err) console.error(`Query failed, err: ${err}`);
}) })
``` ```
...@@ -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
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)"
rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) { store.executeSql(SQL_CREATE_TABLE, null, function(err) {
if (err) { if (err) {
console.info("Failed to execute SQL, err: " + err) console.error(`ExecuteSql failed, err: ${err}`);
return return;
} }
console.info('Create table done.') console.info(`Create table done.`);
}) })
``` ```
...@@ -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
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 = 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.
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext() let context = featureAbility.getContext();
const STORE_CONFIG = { name: "RdbTest.db", const STORE_CONFIG = {
securityLevel: data_rdb.SecurityLevel.S1} name: "RdbTest.db",
data_rdb.getRdbStore(context, STORE_CONFIG, async function (err, rdbStore) { securityLevel: relationalStore.SecurityLevel.S1
rdbStore.beginTransaction() };
const valueBucket = { relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
"name": "lisi", if (err) {
"age": 18, console.error(`GetRdbStore failed, err: ${err}`);
"salary": 100.5, return;
"blobType": new Uint8Array([1, 2, 3]), }
} store.beginTransaction();
await rdbStore.insert("test", valueBucket) const valueBucket = {
rdbStore.commit() "name": "lisi",
"age": 18,
"salary": 100.5,
"blobType": new Uint8Array([1, 2, 3]),
};
await store.insert("test", valueBucket);
store.commit();
}) })
``` ```
...@@ -2227,19 +2244,25 @@ Commits the executed SQL statements. ...@@ -2227,19 +2244,25 @@ Commits the executed SQL statements.
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext() let context = featureAbility.getContext();
const STORE_CONFIG = { name: "RdbTest.db", const STORE_CONFIG = {
securityLevel: data_rdb.SecurityLevel.S1} name: "RdbTest.db",
data_rdb.getRdbStore(context, STORE_CONFIG, async function (err, rdbStore) { securityLevel: relationalStore.SecurityLevel.S1
rdbStore.beginTransaction() };
const valueBucket = { relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
"name": "lisi", if (err) {
"age": 18, console.error(`GetRdbStore failed, err: ${err}`);
"salary": 100.5, return;
"blobType": new Uint8Array([1, 2, 3]), }
} store.beginTransaction();
await rdbStore.insert("test", valueBucket) const valueBucket = {
rdbStore.commit() "name": "lisi",
"age": 18,
"salary": 100.5,
"blobType": new Uint8Array([1, 2, 3]),
};
await store.insert("test", valueBucket);
store.commit();
}) })
``` ```
...@@ -2255,24 +2278,31 @@ Rolls back the SQL statements that have been executed. ...@@ -2255,24 +2278,31 @@ Rolls back the SQL statements that have been executed.
```js ```js
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext() let context = featureAbility.getContext();
const STORE_CONFIG = { name: "RdbTest.db", const STORE_CONFIG = {
securityLevel: data_rdb.SecurityLevel.S1} name: "RdbTest.db",
data_rdb.getRdbStore(context, STORE_CONFIG, async function (err, rdbStore) { securityLevel: relationalStore.SecurityLevel.S1
try { };
rdbStore.beginTransaction() relationalStore.getRdbStore(context, STORE_CONFIG, async function (err, store) {
const valueBucket = { if (err) {
"id": 1, console.error(`GetRdbStore failed, err: ${err}`);
"name": "lisi", return;
"age": 18, }
"salary": 100.5, try {
"blobType": new Uint8Array([1, 2, 3]), store.beginTransaction()
} const valueBucket = {
await rdbStore.insert("test", valueBucket) "id": 1,
rdbStore.commit() "name": "lisi",
} catch (e) { "age": 18,
rdbStore.rollBack() "salary": 100.5,
} "blobType": new Uint8Array([1, 2, 3]),
};
await store.insert("test", valueBucket);
store.commit();
} catch (err) {
console.error(`Transaction failed, err: ${err}`);
store.rollBack();
}
}) })
``` ```
...@@ -2294,12 +2324,12 @@ Backs up an RDB store. This API uses an asynchronous callback to return the resu ...@@ -2294,12 +2324,12 @@ Backs up an RDB store. This API uses an asynchronous callback to return the resu
**Example** **Example**
```js ```js
rdbStore.backup("dbBackup.db", function(err) { store.backup("dbBackup.db", function(err) {
if (err) { if (err) {
console.info('Backup failed, err: ' + err) console.error(`Backup failed, err: ${err}`);
return return;
} }
console.info('Backup success.') console.info(`Backup success.`);
}) })
``` ```
...@@ -2326,11 +2356,11 @@ Backs up an RDB store. This API uses a promise to return the result. ...@@ -2326,11 +2356,11 @@ Backs up an RDB store. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let promiseBackup = rdbStore.backup("dbBackup.db") let promiseBackup = store.backup("dbBackup.db");
promiseBackup.then(()=>{ promiseBackup.then(()=>{
console.info('Backup success.') console.info(`Backup success.`);
}).catch((err)=>{ }).catch((err)=>{
console.info('Backup failed, err: ' + err) console.error(`Backup failed, err: ${err}`);
}) })
``` ```
...@@ -2352,12 +2382,12 @@ Restores an RDB store from a backup file. This API uses an asynchronous callback ...@@ -2352,12 +2382,12 @@ Restores an RDB store from a backup file. This API uses an asynchronous callback
**Example** **Example**
```js ```js
rdbStore.restore("dbBackup.db", function(err) { store.restore("dbBackup.db", function(err) {
if (err) { if (err) {
console.info('Restore failed, err: ' + err) console.error(`Restore failed, err: ${err}`);
return return;
} }
console.info('Restore success.') console.info(`Restore success.`);
}) })
``` ```
...@@ -2384,11 +2414,11 @@ Restores an RDB store from a backup file. This API uses a promise to return the ...@@ -2384,11 +2414,11 @@ Restores an RDB store from a backup file. This API uses a promise to return the
**Example** **Example**
```js ```js
let promiseRestore = rdbStore.restore("dbBackup.db") let promiseRestore = store.restore("dbBackup.db");
promiseRestore.then(()=>{ promiseRestore.then(()=>{
console.info('Restore success.') console.info(`Restore success.`);
}).catch((err)=>{ }).catch((err)=>{
console.info('Restore failed, err: ' + err) console.error(`Restore failed, err: ${err}`);
}) })
``` ```
...@@ -2412,12 +2442,12 @@ Sets distributed tables. This API uses an asynchronous callback to return the re ...@@ -2412,12 +2442,12 @@ Sets distributed tables. This API uses an asynchronous callback to return the re
**Example** **Example**
```js ```js
rdbStore.setDistributedTables(["EMPLOYEE"], function (err) { store.setDistributedTables(["EMPLOYEE"], function (err) {
if (err) { if (err) {
console.info('Failed to set distributed tables, err: ' + err) console.error(`SetDistributedTables failed, err: ${err}`);
return return;
} }
console.info('Set distributed tables successfully.') console.info(`SetDistributedTables successfully.`);
}) })
``` ```
...@@ -2446,11 +2476,11 @@ Sets distributed tables. This API uses a promise to return the result. ...@@ -2446,11 +2476,11 @@ Sets distributed tables. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let promise = rdbStore.setDistributedTables(["EMPLOYEE"]) let promise = store.setDistributedTables(["EMPLOYEE"]);
promise.then(() => { promise.then(() => {
console.info("Set distributed tables successfully.") console.info(`SetDistributedTables successfully.`);
}).catch((err) => { }).catch((err) => {
console.info("Failed to set distributed tables, err: " + err) console.error(`SetDistributedTables failed, err: ${err}`);
}) })
``` ```
...@@ -2475,12 +2505,12 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -2475,12 +2505,12 @@ Obtains the distributed table name for a remote device based on the local table
**Example** **Example**
```js ```js
rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, tableName) { store.obtainDistributedTableName("12345678abcde", "EMPLOYEE", function (err, tableName) {
if (err) { if (err) {
console.info('Failed to obtain DistributedTableName, err: ' + err) console.error(`ObtainDistributedTableName failed, err: ${err}`);
return return;
} }
console.info('Obtained distributed table name successfully, tableName=.' + tableName) console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
}) })
``` ```
...@@ -2510,11 +2540,11 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -2510,11 +2540,11 @@ Obtains the distributed table name for a remote device based on the local table
**Example** **Example**
```js ```js
let promise = rdbStore.obtainDistributedTableName("12345678abcde", "EMPLOYEE") let promise = store.obtainDistributedTableName("12345678abcde", "EMPLOYEE");
promise.then((tableName) => { promise.then((tableName) => {
console.info('Obtained distributed table name successfully, tableName= ' + tableName) console.info(`ObtainDistributedTableName successfully, tableName= ${tableName}`);
}).catch((err) => { }).catch((err) => {
console.info('Failed to obtain DistributedTableName, err: ' + err) console.error(`ObtainDistributedTableName failed, err: ${err}`);
}) })
``` ```
...@@ -2539,17 +2569,17 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret ...@@ -2539,17 +2569,17 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates('EMPLOYEE') let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.inDevices(['12345678abcde']) predicates.inDevices(['12345678abcde']);
rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) { store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates, function (err, result) {
if (err) { if (err) {
console.log('Sync failed, err: ' + err) console.error(`Sync failed, err: ${err}`);
return return;
} }
console.log('Sync done.') console.info(`Sync done.`);
for (let i = 0; i < result.length; i++) { for (let i = 0; i < result.length; i++) {
console.log('device=' + result[i][0] + ' status=' + result[i][1]) console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
} }
}) })
``` ```
...@@ -2579,16 +2609,16 @@ Synchronizes data between devices. This API uses a promise to return the result. ...@@ -2579,16 +2609,16 @@ Synchronizes data between devices. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let predicates = new data_rdb.RdbPredicates('EMPLOYEE') let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.inDevices(['12345678abcde']) predicates.inDevices(['12345678abcde']);
let promise = rdbStore.sync(data_rdb.SyncMode.SYNC_MODE_PUSH, predicates) let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates);
promise.then((resultSet) =>{ promise.then((resultSet) =>{
console.log('Sync done.') console.info(`Sync done.`);
for (let i = 0; i < resultSet.length; i++) { for (let i = 0; i < resultSet.length; i++) {
console.log('device=' + resultSet[i][0] + ' status=' + resultSet[i][1]) console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
} }
}).catch((err) => { }).catch((err) => {
console.log('Sync failed') console.error(`Sync failed, err: ${err}`);
}) })
``` ```
...@@ -2604,22 +2634,22 @@ Registers an observer for this RDB store. When the data in the RDB store changes ...@@ -2604,22 +2634,22 @@ 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 | Event to observe. The value is **dataChange**, which indicates a data change event. |
| type | [SubscribeType](#subscribetype) | Yes | Subscription type to register.| | type | [SubscribeType](#subscribetype) | 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 | Callback invoked to return the data change event. |
**Example** **Example**
```js ```js
function storeObserver(devices) { function storeObserver(devices) {
for (let i = 0; i < devices.length; i++) { for (let i = 0; i < devices.length; i++) {
console.log('device=' + devices[i] + ' data changed') console.info(`device= ${devices[i]} data changed`);
} }
} }
try { try {
rdbStore.on('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) store.on('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
} catch (err) { } catch (err) {
console.log('Failed to register observer') console.error(`Register observer failed, err: ${err}`);
} }
``` ```
...@@ -2635,22 +2665,22 @@ Unregisters the observer of the specified type from the RDB store. This API uses ...@@ -2635,22 +2665,22 @@ 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 | Event type. The value is **dataChange**, which indicates a data change event. |
| type | [SubscribeType](#subscribetype) | Yes | Subscription type to register. | | type | [SubscribeType](#subscribetype) | 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 | Callback for the data change event. |
**Example** **Example**
```js ```js
function storeObserver(devices) { function storeObserver(devices) {
for (let i = 0; i < devices.length; i++) { for (let i = 0; i < devices.length; i++) {
console.log('device=' + devices[i] + ' data changed') console.info(`device= ${devices[i]} data changed`);
} }
} }
try { try {
rdbStore.off('dataChange', data_rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) store.off('dataChange', relationalStore.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver);
} catch (err) { } catch (err) {
console.log('Failed to unregister observer') console.error(`Unregister observer failed, err: ${err}`);
} }
``` ```
...@@ -2660,16 +2690,15 @@ Provides APIs to access the result set obtained by querying the RDB store. A res ...@@ -2660,16 +2690,15 @@ Provides APIs to access the result set obtained by querying the RDB store. A res
### Usage ### Usage
Obtain the **resultSet** object by [RdbStore.query()](#query). Obtain the **resultSet** object first.
```js ```js
import dataRdb from '@ohos.data.rdb'; let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let predicates = new dataRdb.RdbPredicates("EMPLOYEE");
predicates.equalTo("AGE", 18); predicates.equalTo("AGE", 18);
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
console.log(TAG + "resultSet columnNames:" + resultSet.columnNames); console.info(`resultSet columnNames: ${resultSet.columnNames}`);
console.log(TAG + "resultSet columnCount:" + resultSet.columnCount); console.info(`resultSet columnCount: ${resultSet.columnCount}`);
}); });
``` ```
...@@ -2794,13 +2823,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode ...@@ -2794,13 +2823,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example** **Example**
```js ```js
let predicates = new dataRdb.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise= rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise= store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
resultSet.goTo(1); resultSet.goTo(1);
resultSet.close(); resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed'); console.error(`query failed, err: ${err}`);
}); });
``` ```
...@@ -2835,13 +2864,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode ...@@ -2835,13 +2864,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example** **Example**
```js ```js
let predicates = new dataRdb.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
resultSet.(5); resultSet.(5);
resultSet.close(); resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed'); console.error(`query failed, err: ${err}`);
}); });
``` ```
...@@ -2871,13 +2900,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode ...@@ -2871,13 +2900,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example** **Example**
```js ```js
let predicates = new dataRdb.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
resultSet.goToFirstRow(); resultSet.goToFirstRow();
resultSet.close(); resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed'); console.error(`query failed, err: ${err}`);
}); });
``` ```
...@@ -2906,13 +2935,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode ...@@ -2906,13 +2935,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example** **Example**
```js ```js
let predicates = new dataRdb.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
resultSet.goToLastRow(); resultSet.goToLastRow();
resultSet.close(); resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed'); console.error(`query failed, err: ${err}`);
}); });
``` ```
...@@ -2941,13 +2970,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode ...@@ -2941,13 +2970,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example** **Example**
```js ```js
let predicates = new dataRdb.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
resultSet.goToNextRow(); resultSet.goToNextRow();
resultSet.close(); resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed'); console.error(`query failed, err: ${err}`);
}); });
``` ```
...@@ -2976,13 +3005,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode ...@@ -2976,13 +3005,13 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
**Example** **Example**
```js ```js
let predicates = new dataRdb.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
resultSet.goToPreviousRow(); resultSet.goToPreviousRow();
resultSet.close(); resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed'); console.error(`query failed, err: ${err}`);
}); });
``` ```
...@@ -3054,9 +3083,9 @@ Obtains the value of the Long type based on the specified column and the current ...@@ -3054,9 +3083,9 @@ Obtains the value of the Long type based on the specified column and the current
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------------------------- | | ------ | ------------------------------------------------------------ |
| number | Value obtained.| | 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).|
**Example** **Example**
...@@ -3135,12 +3164,12 @@ Closes this result set. ...@@ -3135,12 +3164,12 @@ Closes this result set.
**Example** **Example**
```js ```js
let predicatesClose = new dataRdb.RdbPredicates("EMPLOYEE"); let predicatesClose = new relationalStore.RdbPredicates("EMPLOYEE");
let promiseClose = rdbStore.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promiseClose = store.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promiseClose.then((resultSet) => { promiseClose.then((resultSet) => {
resultSet.close(); resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('resultset close failed'); console.error(`resultset close failed, err: ${err}`);
}); });
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册