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:
...
...
@@ -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
...
...
@@ -1565,7 +1565,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
**Example**
...
...
@@ -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
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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**
...
...
@@ -1605,7 +1605,7 @@ Queries data in the RDB store using the specified SQL statement. This API uses a
**Example**
```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
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
**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)"
@@ -1656,7 +1656,7 @@ Executes an SQL statement that contains specified arguments but returns no value
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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**
...
...
@@ -1667,10 +1667,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=rdbStore.executeSql(SQL_CREATE_TABLE)
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.
...
...
@@ -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.
...
...
@@ -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.
| 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. |
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:
-[RdbPredicates](#rdbpredicates): provides predicates indicating the nature, feature, or relationship of a data entity in an RDB store. It is used to define the operation conditions for an RDB store.
-[RdbStore](#rdbstore): provides APIs for managing data in an RDB store.
-[ResultSet](#resultset): provides APIs for accessing the result set obtained from the RDB store.
-[Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store.
> **NOTE**
>
...
...
@@ -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).
Sets an **RdbPredicates** to specify the remote devices to connect on the network during distributed database synchronization.
> **NOTE**<br/>
> **NOTE**
>
> The value of **devices** 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.
...
...
@@ -439,6 +443,7 @@ Sets an **RdbPredicates** to specify the remote devices to connect on the networ
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.
### Attributes<sup>10+</sup>
...
...
@@ -1281,6 +1285,14 @@ Inserts a row of data into a table. This API uses an asynchronous callback to re
| values | [ValuesBucket](#valuesbucket) | Yes | Row of data to insert. |
| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800047 | The WAL file size exceeds the default limit.|
**Example**
```js
...
...
@@ -1316,6 +1328,14 @@ Inserts a row of data into a table. This API uses an asynchronous callback to re
| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. |
| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800047 | The WAL file size exceeds the default limit.|
**Example**
```js
...
...
@@ -1355,6 +1375,14 @@ Inserts a row of data into a table. This API uses a promise to return the result
| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800047 | The WAL file size exceeds the default limit.|
**Example**
```js
...
...
@@ -1394,6 +1422,14 @@ Inserts a row of data into a table. This API uses a promise to return the result
| Promise<number> | Promise used to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800047 | The WAL file size exceeds the default limit.|
**Example**
```js
...
...
@@ -1427,6 +1463,14 @@ Batch inserts data into a table. This API uses an asynchronous callback to retur
| values | Array<[ValuesBucket](#valuesbucket)> | Yes | An array of data to insert. |
| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800047 | The WAL file size exceeds the default limit.|
**Example**
```js
...
...
@@ -1480,6 +1524,14 @@ Batch inserts data into a table. This API uses a promise to return the result.
| Promise<number> | Promise used to return the result. If the operation is successful, the number of inserted data records is returned. Otherwise, **-1** is returned.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800047 | The WAL file size exceeds the default limit.|
**Example**
```js
...
...
@@ -1527,6 +1579,14 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T
| predicates | [RdbPredicates](#rdbpredicates) | Yes | Update conditions specified by the **RdbPredicates** object. |
| callback | AsyncCallback<number> | Yes | Callback invoked to return the number of rows updated. |
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800047 | The WAL file size exceeds the default limit.|
**Example**
```js
...
...
@@ -1564,6 +1624,14 @@ Updates data in the RDB store based on the specified **RdbPredicates** object. T
| conflict | [ConflictResolution](#conflictresolution10) | Yes | Resolution used to resolve the conflict. |
| callback | AsyncCallback<number> | Yes | Callback invoked to return the number of rows updated. |
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800047 | The WAL file size exceeds the default limit.|
**Example**
```js
...
...
@@ -1605,6 +1673,14 @@ Updates data based on the specified **RdbPredicates** object. This API uses a pr
Queries data from the RDB store of a remote device based on specified conditions. This API uses an asynchronous callback to return the result.
> **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.
...
...
@@ -2048,6 +2180,7 @@ Queries data from the RDB store of a remote device based on specified conditions
Queries data from the RDB store of a remote device based on specified conditions. This API uses a promise to return the result.
> **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.
...
...
@@ -2105,6 +2238,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**
...
...
@@ -2167,9 +2301,9 @@ 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**
...
...
@@ -2180,7 +2314,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. |
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.|
| 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. |
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800047 | The WAL file size exceeds the default limit.|
**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**
...
...
@@ -2239,13 +2381,21 @@ Executes an SQL statement that contains specified arguments but returns no value
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| **ID**| **Error Message** |
| ------------ | ----------------------- |
| 14800047 | The WAL file size exceeds the default limit.|
**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}`);
})
...
...
@@ -2259,6 +2409,14 @@ Starts the transaction before executing an SQL statement.
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.
...
...
@@ -2564,6 +2722,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.
...
...
@@ -2616,6 +2775,7 @@ Obtains the distributed table name for a remote device based on the local table