The relational database (RDB) store manages data based on relational models. With the underlying SQLite database, the RDB store provides a complete mechanism for managing local databases. To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements.
The relational database (RDB) store manages data based on relational models. With the underlying SQLite database, the RDB store provides a complete mechanism for managing local databases. To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements. The worker threads are not supported.
The **relationalStore** module provides the following functions:
...
...
@@ -317,6 +317,10 @@ Defines the RDB store configuration.
Enumerates the RDB store security levels.
> **NOTE**
>
> To perform data synchronization operations, the RDB store security level must be lower than or equal to that of the peer device. For details, see the [Cross-Device Data Synchronization Mechanism](../../database/sync-app-data-across-devices-overview.md#cross-device-data-synchronization-mechanism).
Before using the following APIs, use [executeSql](#executesql) to initialize the database table structure and related data. For details, see [RDB Development](../../database/database-relational-guidelines.md).
Before using the APIs of this class, use [executeSql](#executesql) to initialize the database table structure and related data.
### insert
...
...
@@ -1868,6 +1872,7 @@ Queries data from the RDB store of a remote device based on specified conditions
| bindArgs | Array<[ValueType](#valuetype)> | Yes | Arguments in the SQL statement. |
| callback | AsyncCallback<[ResultSet](#resultset)> | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| 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](#resultset)> | Yes | Callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
**Example**
...
...
@@ -1986,10 +1992,10 @@ Queries data using the specified SQL statement. This API uses a promise to retur
| 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**
...
...
@@ -2000,7 +2006,7 @@ Queries data using the specified SQL statement. This API uses a promise to retur
**Example**
```js
letpromise=store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?",['sanguo']);
letpromise=store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo'");
| 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.|
**Example**
```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)"
| 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**
...
...
@@ -2062,10 +2068,10 @@ Executes an SQL statement that contains specified arguments but returns no value
**Example**
```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)"
letpromise=store.executeSql(SQL_CREATE_TABLE);
constSQL_DELETE_TABLE="DELETE FROM test WHERE name = 'zhangsan'"
letpromise=store.executeSql(SQL_DELETE_TABLE);
promise.then(()=>{
console.info(`Create table done.`);
console.info(`Delete table done.`);
}).catch((err)=>{
console.error(`ExecuteSql failed, err: ${err}`);
})
...
...
@@ -2384,6 +2390,7 @@ Obtains the distributed table name of a remote device based on the local table n