diff --git a/en/application-dev/reference/apis/js-apis-data-rdb.md b/en/application-dev/reference/apis/js-apis-data-rdb.md index 04dcfb83d02cc263ff739c4e2618a65b2eeee181..2924cc05735a40236985ba921d39839ee796afad 100644 --- a/en/application-dev/reference/apis/js-apis-data-rdb.md +++ b/en/application-dev/reference/apis/js-apis-data-rdb.md @@ -1,6 +1,6 @@ # @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: @@ -372,6 +372,7 @@ Sets an **RdbPredicates** to specify the remote devices to connect on the networ ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceIds = []; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -380,7 +381,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceIds = []; for (var i = 0; i < devices.length; i++) { deviceIds[i] = devices[i].deviceId; } @@ -1174,7 +1174,7 @@ predicates.notIn("NAME", ["Lisa", "Rose"]) 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 @@ -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 = ?", querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> -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 @@ -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 -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) => { console.log("ResultSet column names: " + resultSet.columnNames) console.log("ResultSet column count: " + resultSet.columnCount) @@ -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 -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) { +const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?" +rdbStore.executeSql(SQL_CREATE_TABLE, ['zhangsan'], function(err) { if (err) { console.info("Failed to execute SQL, err: " + err) 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 | 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 -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) +const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" +let promise = rdbStore.executeSql(SQL_DELETE_TABLE) promise.then(() => { - console.info('Create table done.') + console.info('Delete table done.') }).catch((err) => { console.info("Failed to execute SQL, err: " + err) }) @@ -1828,9 +1828,9 @@ promise.then(() => { obtainDistributedTableName(device: string, table: string, callback: AsyncCallback<string>): 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**
+> **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 ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceId = null; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -1859,7 +1860,7 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceId = devices[0].deviceId; + deviceId = devices[0].deviceId; }) @@ -1876,9 +1877,9 @@ rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableNa obtainDistributedTableName(device: string, table: string): Promise<string> -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**
+> **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 ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceId = null; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -1912,7 +1914,7 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceId = devices[0].deviceId; + deviceId = devices[0].deviceId; }) let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE") @@ -1946,6 +1948,7 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceIds = []; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -1954,7 +1957,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceIds = []; for (var i = 0; i < devices.length; i++) { deviceIds[i] = devices[i].deviceId; } @@ -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.
**string** indicates the device ID.
**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.
**string** indicates the device ID.
**number** indicates the synchronization status of that device. The value **0** indicates a successful synchronization. Other values indicate a synchronization failure. | **Example** ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceIds = []; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -2010,7 +2013,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceIds = []; for (var i = 0; i < devices.length; i++) { deviceIds[i] = devices[i].deviceId; } diff --git a/en/application-dev/reference/apis/js-apis-data-relationalStore.md b/en/application-dev/reference/apis/js-apis-data-relationalStore.md index 5694b698b4f81cca15db7cad6777a156765df6d2..3e7e078f595f8468bf78cc953f5267c5515360a2 100644 --- a/en/application-dev/reference/apis/js-apis-data-relationalStore.md +++ b/en/application-dev/reference/apis/js-apis-data-relationalStore.md @@ -1,12 +1,12 @@ # @ohos.data.relationalStore (RDB Store) -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). + **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | Name| Value | Description | @@ -416,7 +420,7 @@ inDevices(devices: Array<string>): RdbPredicates Sets an **RdbPredicates** to specify the remote devices to connect on the network during distributed database synchronization. -> **NOTE**
+> **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 ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceIds = []; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -447,7 +452,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceIds = []; for (var i = 0; i < devices.length; i++) { deviceIds[i] = devices[i].deviceId; } @@ -1244,9 +1248,9 @@ predicates.notIn("NAME", ["Lisa", "Rose"]); ## RdbStore -Provides methods to manage an RDB store. +Provides APIs to manage an RDB store. -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. ### Attributes10+ @@ -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 | --------------------- | ----------------------------------------- | | Promise<number> | Promise used 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 @@ -1646,6 +1722,14 @@ Updates data based on the specified **RdbPredicates** object. This API uses a pr | --------------------- | ----------------------------------------- | | Promise<number> | Promise used 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 @@ -1684,6 +1768,14 @@ Updates data based on the specified **DataSharePredicates** object. This API use | predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Update conditions specified by the **DataSharePredicates** 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 @@ -1729,6 +1821,14 @@ Updates data based on the specified **DataSharePredicates** object. This API use | --------------------- | ----------------------------------------- | | Promise<number> | Promise used 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 @@ -1764,6 +1864,14 @@ Deletes data from the RDB store based on the specified **RdbPredicates** object. | predicates | [RdbPredicates](#rdbpredicates) | Yes | Conditions specified by the **RdbPredicates** object for deleting data.| | callback | AsyncCallback<number> | Yes | Callback invoked to return the number of rows deleted. | +**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 @@ -1798,6 +1906,14 @@ Deletes data from the RDB store based on the specified **RdbPredicates** object. | --------------------- | ------------------------------- | | Promise<number> | Promise used to return the number of rows deleted.| +**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 @@ -1829,6 +1945,14 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o | predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Conditions specified by the **DataSharePredicates** object for deleting data.| | callback | AsyncCallback<number> | Yes | Callback invoked to return the number of rows deleted. | +**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 @@ -1867,6 +1991,14 @@ Deletes data from the RDB store based on the specified **DataSharePredicates** o | --------------------- | ------------------------------- | | Promise<number> | Promise used to return the number of rows deleted.| +**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 @@ -2027,7 +2159,7 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A 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**
+> **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 ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceId = null; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -2056,7 +2189,7 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceId = devices[0].deviceId; + deviceId = devices[0].deviceId; }) let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); @@ -2079,7 +2212,7 @@ remoteQuery(device: string, table: string, predicates: RdbPredicates, columns: A Queries data from the RDB store of a remote device based on specified conditions. This API uses a promise to return the result. -> **NOTE**
+> **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 ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceId = null; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -2113,12 +2247,12 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceId = devices[0].deviceId; + deviceId = devices[0].deviceId; }) let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); predicates.greaterThan("id", 0); -let promise = store.remoteQuery("deviceId", "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); +let promise = store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); promise.then((resultSet) => { console.info(`ResultSet column names: ${resultSet.columnNames}`); console.info(`ResultSet column count: ${resultSet.columnCount}`); @@ -2137,11 +2271,11 @@ Queries data using the specified SQL statement. This API uses an asynchronous ca **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | -| sql | string | Yes | SQL statement to run. | -| 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.| +| Name | Type | Mandatory| Description | +| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | +| sql | string | Yes | SQL statement to run. | +| 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** @@ -2166,10 +2300,10 @@ Queries data using the specified SQL statement. This API uses a promise to retur **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------ | ---- | --------------------- | -| sql | string | Yes | SQL statement to run.| -| bindArgs | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | +| sql | string | Yes | SQL statement to run. | +| 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 -let promise = store.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) => { console.info(`ResultSet column names: ${resultSet.columnNames}`); console.info(`ResultSet column count: ${resultSet.columnCount}`); @@ -2199,22 +2333,30 @@ Executes an SQL statement that contains specified arguments but returns no value **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------ | ---- | ---------------------- | -| sql | string | Yes | SQL statement to run. | -| bindArgs | Array<[ValueType](#valuetype)> | Yes | Arguments in the SQL statement. | -| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | +| sql | string | Yes | SQL statement to run. | +| 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 -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)" -store.executeSql(SQL_CREATE_TABLE, null, function(err) { +const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = ?" +store.executeSql(SQL_DELETE_TABLE, ['zhangsan'], function(err) { if (err) { console.error(`ExecuteSql failed, err: ${err}`); return; } - console.info(`Create table done.`); + console.info(`Delete table done.`); }) ``` @@ -2228,10 +2370,10 @@ Executes an SQL statement that contains specified arguments but returns no value **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------ | ---- | --------------------- | -| sql | string | Yes | SQL statement to run.| -| bindArgs | Array<[ValueType](#valuetype)> | No | Arguments in the SQL statement. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | +| sql | string | Yes | SQL statement to run. | +| 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 -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 = store.executeSql(SQL_CREATE_TABLE); +const SQL_DELETE_TABLE = "DELETE FROM test WHERE name = 'zhangsan'" +let promise = 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. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core +**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 @@ -2541,9 +2699,9 @@ promise.then(() => { obtainDistributedTableName(device: string, table: string, callback: AsyncCallback<string>): 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**
+> **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 ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceId = null; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -2572,7 +2731,7 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceId = devices[0].deviceId; + deviceId = devices[0].deviceId; }) store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) { @@ -2588,9 +2747,9 @@ store.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableName) obtainDistributedTableName(device: string, table: string): Promise<string> -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**
+> **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 ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceId = null; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -2624,7 +2784,7 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceId = devices[0].deviceId; + deviceId = devices[0].deviceId; }) let promise = store.obtainDistributedTableName(deviceId, "EMPLOYEE"); @@ -2658,6 +2818,7 @@ Synchronizes data between devices. This API uses an asynchronous callback to ret ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceIds = []; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -2666,7 +2827,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceIds = []; for (var i = 0; i < devices.length; i++) { deviceIds[i] = devices[i].deviceId; } @@ -2714,6 +2874,7 @@ Synchronizes data between devices. This API uses a promise to return the result. ```js import deviceManager from '@ohos.distributedHardware.deviceManager'; let dmInstance = null; +let deviceIds = []; deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) => { if (err) { @@ -2722,7 +2883,6 @@ deviceManager.createDeviceManager("com.example.appdatamgrverify", (err, manager) } dmInstance = manager; let devices = dmInstance.getTrustedDeviceListSync(); - let deviceIds = []; for (var i = 0; i < devices.length; i++) { deviceIds[i] = devices[i].deviceId; } @@ -2786,7 +2946,7 @@ Unregisters the observer of the specified type from the RDB store. This API uses | -------- | ---------------------------------- | ---- | ------------------------------------------ | | event | string | Yes | Event type. The value is **dataChange**, which indicates a data change event. | | type | [SubscribeType](#subscribetype) | Yes | Subscription type to unregister. | -| observer | Callback<Array<string>> | Yes | Callback for the data change event. | +| observer | Callback<Array<string>> | Yes | Callback for the data change event. | **Example** @@ -3301,3 +3461,5 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode | **ID**| **Error Message** | | ------------ | ------------------------------------------------------------ | | 14800012 | The result set is empty or the specified location is invalid. | + + diff --git a/en/application-dev/reference/errorcodes/errorcode-data-rdb.md b/en/application-dev/reference/errorcodes/errorcode-data-rdb.md index 7da8eb85ea4d4c94d68f8057900a204743afbf5b..d0e4a40e4ce19f10f5470b6a4b83caaa72707611 100644 --- a/en/application-dev/reference/errorcodes/errorcode-data-rdb.md +++ b/en/application-dev/reference/errorcodes/errorcode-data-rdb.md @@ -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. 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. + +## 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.