未验证 提交 c509cc55 编写于 作者: O openharmony_ci 提交者: Gitee

!17447 [翻译完成】#I6SP6F (16833+17181+16736+16919)

Merge pull request !17447 from Annie_wang/PR16833A
# @ohos.data.rdb (RDB) # @ohos.data.rdb (RDB)
The relational database (RDB) manages data based on relational models. With the underlying SQLite database, the RDB provides a complete mechanism for managing local databases. To satisfy different needs in complicated scenarios, the RDB offers a series of methods for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements. The relational database (RDB) manages data based on relational models. With the underlying SQLite database, the RDB provides a complete mechanism for managing local databases. To satisfy different needs in complicated scenarios, the RDB offers a series of methods for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements. The worker threads are not supported.
This module provides the following RDB-related functions: This module provides the following RDB-related functions:
...@@ -372,6 +372,7 @@ Sets an **RdbPredicates** to specify the remote devices to connect on the networ ...@@ -372,6 +372,7 @@ Sets an **RdbPredicates** to specify the remote devices to connect on the networ
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null; let dmInstance = null;
let deviceIds = [];
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
if (err) { if (err) {
...@@ -380,7 +381,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) ...@@ -380,7 +381,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager)
} }
dmInstance = manager; dmInstance = manager;
let devices = dmInstance.getTrustedDeviceListSync(); let devices = dmInstance.getTrustedDeviceListSync();
let deviceIds = [];
for (var i = 0; i < devices.length; i++) { for (var i = 0; i < devices.length; i++) {
deviceIds[i] = devices[i].deviceId; deviceIds[i] = devices[i].deviceId;
} }
...@@ -1174,7 +1174,7 @@ predicates.notIn("NAME", ["Lisa", "Rose"]) ...@@ -1174,7 +1174,7 @@ predicates.notIn("NAME", ["Lisa", "Rose"])
Provides methods to manage an RDB store. Provides methods to manage an RDB store.
Before using the following APIs, use [executeSql](#executesql8) to initialize the database table structure and related data. For details, see [RDB Development](../../database/database-relational-guidelines.md). Before using the APIs of this class, use [executeSql](#executesql) to initialize the database table structure and related data.
### insert ### insert
...@@ -1565,7 +1565,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a ...@@ -1565,7 +1565,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.| | sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Arguments in the SQL statement.| | bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, the value of this parameter must be an empty array.|
| callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | callback | AsyncCallback&lt;[ResultSet](js-apis-data-resultset.md)&gt; | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example** **Example**
...@@ -1585,7 +1585,7 @@ rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ...@@ -1585,7 +1585,7 @@ rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?",
querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt; querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt;
Queries data in the RDB store using the specified SQL statement. This API uses a promise to return the result. Queries data using the specified SQL statement. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -1594,7 +1594,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a ...@@ -1594,7 +1594,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.| | sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Arguments in the SQL statement.| | bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank.|
**Return value** **Return value**
...@@ -1605,7 +1605,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a ...@@ -1605,7 +1605,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
**Example** **Example**
```js ```js
let promise = rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['sanguo']) let promise = rdbStore.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.log("ResultSet column names: " + resultSet.columnNames)
console.log("ResultSet column count: " + resultSet.columnCount) console.log("ResultSet column count: " + resultSet.columnCount)
...@@ -1627,19 +1627,19 @@ Executes an SQL statement that contains specified arguments but returns no value ...@@ -1627,19 +1627,19 @@ Executes an SQL statement that contains specified arguments but returns no value
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.| | sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Arguments in the SQL statement.| | bindArgs | Array&lt;[ValueType](#valuetype)&gt; | Yes| Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, the value of this parameter must be an empty array.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result.|
**Example** **Example**
```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_DELETE_TABLE = "DELETE FROM test WHERE name = ?"
rdbStore.executeSql(SQL_CREATE_TABLE, null, function(err) { rdbStore.executeSql(SQL_CREATE_TABLE, ['zhangsan'], function(err) {
if (err) { if (err) {
console.info("Failed to execute SQL, err: " + err) console.info("Failed to execute SQL, err: " + err)
return return
} }
console.info('Create table done.') console.info('Delete table done.')
}) })
``` ```
...@@ -1656,7 +1656,7 @@ Executes an SQL statement that contains specified arguments but returns no value ...@@ -1656,7 +1656,7 @@ Executes an SQL statement that contains specified arguments but returns no value
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sql | string | Yes| SQL statement to run.| | sql | string | Yes| SQL statement to run.|
| bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Arguments in the SQL statement.| | bindArgs | Array&lt;[ValueType](#valuetype)&gt; | No| Arguments in the SQL statement. The value corresponds to the placeholders in the SQL parameter statement. If the SQL parameter statement is complete, leave this parameter blank.|
**Return value** **Return value**
...@@ -1667,10 +1667,10 @@ Executes an SQL statement that contains specified arguments but returns no value ...@@ -1667,10 +1667,10 @@ Executes an SQL statement that contains specified arguments but returns no value
**Example** **Example**
```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_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'"
let promise = rdbStore.executeSql(SQL_CREATE_TABLE) let promise = rdbStore.executeSql(SQL_DELETE_TABLE)
promise.then(() => { promise.then(() => {
console.info('Create table done.') console.info('Delete table done.')
}).catch((err) => { }).catch((err) => {
console.info("Failed to execute SQL, err: " + err) console.info("Failed to execute SQL, err: " + err)
}) })
...@@ -1828,9 +1828,9 @@ promise.then(() => { ...@@ -1828,9 +1828,9 @@ promise.then(() => {
obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void obtainDistributedTableName(device: string, table: string, callback: AsyncCallback&lt;string&gt;): void
Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the RDB store of a remote device is queried. Obtains the distributed table name of a remote device based on the local table name of the device. The distributed table name is required when the RDB store of a remote device is queried.
> **NOTE**<br/> > **NOTE**
> >
> The value of **device** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications. > The value of **device** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications.
...@@ -1851,6 +1851,7 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -1851,6 +1851,7 @@ Obtains the distributed table name for a remote device based on the local table
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null; let dmInstance = null;
let deviceId = null;
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
if (err) { if (err) {
...@@ -1859,7 +1860,7 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) ...@@ -1859,7 +1860,7 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager)
} }
dmInstance = manager; dmInstance = manager;
let devices = dmInstance.getTrustedDeviceListSync(); let devices = dmInstance.getTrustedDeviceListSync();
let deviceId = devices[0].deviceId; deviceId = devices[0].deviceId;
}) })
...@@ -1876,9 +1877,9 @@ rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableNa ...@@ -1876,9 +1877,9 @@ rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableNa
obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt; obtainDistributedTableName(device: string, table: string): Promise&lt;string&gt;
Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the RDB store of a remote device is queried. Obtains the distributed table name of a remote device based on the local table name of the device. The distributed table name is required when the RDB store of a remote device is queried.
> **NOTE**<br/> > **NOTE**
> >
> The value of **device** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications. > The value of **device** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications.
...@@ -1904,6 +1905,7 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -1904,6 +1905,7 @@ Obtains the distributed table name for a remote device based on the local table
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null; let dmInstance = null;
let deviceId = null;
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
if (err) { if (err) {
...@@ -1912,7 +1914,7 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) ...@@ -1912,7 +1914,7 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager)
} }
dmInstance = manager; dmInstance = manager;
let devices = dmInstance.getTrustedDeviceListSync(); let devices = dmInstance.getTrustedDeviceListSync();
let deviceId = devices[0].deviceId; deviceId = devices[0].deviceId;
}) })
let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE") let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE")
...@@ -1946,6 +1948,7 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret ...@@ -1946,6 +1948,7 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null; let dmInstance = null;
let deviceIds = [];
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
if (err) { if (err) {
...@@ -1954,7 +1957,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) ...@@ -1954,7 +1957,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager)
} }
dmInstance = manager; dmInstance = manager;
let devices = dmInstance.getTrustedDeviceListSync(); let devices = dmInstance.getTrustedDeviceListSync();
let deviceIds = [];
for (var i = 0; i < devices.length; i++) { for (var i = 0; i < devices.length; i++) {
deviceIds[i] = devices[i].deviceId; deviceIds[i] = devices[i].deviceId;
} }
...@@ -1995,13 +1997,14 @@ Synchronizes data between devices. This API uses a promise to return the result. ...@@ -1995,13 +1997,14 @@ Synchronizes data between devices. This API uses a promise to return the result.
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the synchronization result. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | | Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to send the synchronization result. <br>**string** indicates the device ID. <br>**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. |
**Example** **Example**
```js ```js
import deviceManager from '@ohos.distributedHardware.deviceManager'; import deviceManager from '@ohos.distributedHardware.deviceManager';
let dmInstance = null; let dmInstance = null;
let deviceIds = [];
deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => {
if (err) { if (err) {
...@@ -2010,7 +2013,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) ...@@ -2010,7 +2013,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager)
} }
dmInstance = manager; dmInstance = manager;
let devices = dmInstance.getTrustedDeviceListSync(); let devices = dmInstance.getTrustedDeviceListSync();
let deviceIds = [];
for (var i = 0; i < devices.length; i++) { for (var i = 0; i < devices.length; i++) {
deviceIds[i] = devices[i].deviceId; deviceIds[i] = devices[i].deviceId;
} }
......
...@@ -81,3 +81,22 @@ The column value is null, or the column data type is incompatible with the API c ...@@ -81,3 +81,22 @@ The column value is null, or the column data type is incompatible with the API c
1. Check whether the result set is empty. 1. Check whether the result set is empty.
2. Check whether the row number and column number of the result set are out of range. 2. Check whether the row number and column number of the result set are out of range.
3. Check whether the column data type is supported. 3. Check whether the column data type is supported.
## 14800047 WAL File Size Exceeds the Default Limit
**Error Message**
The WAL file size exceeds the default limit.
**Description**
The WAL file size exceeds 200 MB, which is the default limit.
**Possible Causes**
Data is added, deleted, and modified continuously without closing the read transaction or result set.
**Solution**
1. Check for unclosed result sets or transactions.
2. Closes all result sets or transactions.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册