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
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<[ValueType](#valuetype)> | Yes| Arguments in the SQL statement.|
| bindArgs | Array<[ValueType](#valuetype)> | 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<[ResultSet](js-apis-data-resultset.md)> | Yes| Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| callback | AsyncCallback<[ResultSet](js-apis-data-resultset.md)> | 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 = ?",
@@ -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<[ValueType](#valuetype)> | No| Arguments in the SQL statement.|
| bindArgs | Array<[ValueType](#valuetype)> | 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
letpromise=rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?",['sanguo'])
letpromise=rdbStore.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'")
@@ -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<[ValueType](#valuetype)> | Yes| Arguments in the SQL statement.|
| bindArgs | Array<[ValueType](#valuetype)> | 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<void> | Yes| Callback invoked to return the result.|
| callback | AsyncCallback<void> | Yes| Callback invoked to return the result.|
**Example**
**Example**
```js
```js
constSQL_CREATE_TABLE="CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
constSQL_DELETE_TABLE="DELETE FROM test WHERE name = ?"
@@ -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<[ValueType](#valuetype)> | No| Arguments in the SQL statement.|
| bindArgs | Array<[ValueType](#valuetype)> | 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
constSQL_CREATE_TABLE="CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)"
constSQL_DELETE_TABLE="DELETE FROM test WHERE name = 'zhangsan'"
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
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
@@ -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<Array<[string, number]>> | 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<Array<[string, number]>> | 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. |