On the basis of the SQLite database, the RDB allows you to operate data with or without native SQL statements. An RDB is also called RDB store.
On the basis of the SQLite database, the relational database (RDB) allows you to operate data with or without native SQL statements. In OpenHarmony, an RDB is also called RDB store.
## Available APIs<a name="section5504175713016"></a>
## Available APIs
**Creating and Deleting an RDB Store**
The following table describes APIs available for creating and deleting an RDB store.
**Table 1** APIs for creating and deleting an RDB store
<tdclass="cellrowborder"valign="top"width="52.739999999999995%"headers="mcps1.2.4.1.3 "><pid="p9186112481614"><aname="p9186112481614"></a><aname="p9186112481614"></a>Obtains an RDB store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a callback to return the result.</p>
<aname="ul20498114912320"></a><aname="ul20498114912320"></a><ulid="ul20498114912320"><li><strongid="b4112115595818"><aname="b4112115595818"></a><aname="b4112115595818"></a>config</strong>: configuration of the RDB store.</li><li><strongid="b11397121135919"><aname="b11397121135919"></a><aname="b11397121135919"></a>version</strong>: version of the RDB store.</li><li><strongid="b43570718591"><aname="b43570718591"></a><aname="b43570718591"></a>callback</strong>: callback invoked to return the RDB store.</li></ul>
<tdclass="cellrowborder"valign="top"width="52.739999999999995%"headers="mcps1.2.4.1.3 "><pid="p17526162133220"><aname="p17526162133220"></a><aname="p17526162133220"></a>Obtains an RDB store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a promise to return the result.</p>
<aname="ul19719610863"></a><aname="ul19719610863"></a><ulid="ul19719610863"><li><strongid="b153861822027"><aname="b153861822027"></a><aname="b153861822027"></a>config</strong>: configuration of the RDB store.</li><li><strongid="b175492306216"><aname="b175492306216"></a><aname="b175492306216"></a>version</strong>: version of the RDB store.</li></ul>
<tdclass="cellrowborder"valign="top"width="52.739999999999995%"headers="mcps1.2.4.1.3 "><pid="p761845132510"><aname="p761845132510"></a><aname="p761845132510"></a>Deletes an RDB store. This method uses a callback to return the result.</p>
<aname="ul11527402717"></a><aname="ul11527402717"></a><ulid="ul11527402717"><li><strongid="b152695571624"><aname="b152695571624"></a><aname="b152695571624"></a>name</strong>: name of the RDB store to delete.</li><li><strongid="b11959131911316"><aname="b11959131911316"></a><aname="b11959131911316"></a>callback</strong>: callback invoked to return the result. If the RDB store is deleted, <strongid="b717583515112554"><aname="b717583515112554"></a><aname="b717583515112554"></a>true</strong> will be returned. Otherwise, <strongid="b1492094045112554"><aname="b1492094045112554"></a><aname="b1492094045112554"></a>false</strong> will be returned.</li></ul>
<tdclass="cellrowborder"valign="top"width="52.739999999999995%"headers="mcps1.2.4.1.3 "><pid="p1112512307296"><aname="p1112512307296"></a><aname="p1112512307296"></a>Deletes an RDB store. This method uses a promise to return the result.</p>
<aname="ul114112033"></a><aname="ul114112033"></a><ulid="ul114112033"><li><strongid="b8147125819315"><aname="b8147125819315"></a><aname="b8147125819315"></a>name</strong>: name of the RDB store to delete.</li></ul>
</td>
</tr>
</tbody>
</table>
The following table describes the APIs available for creating and deleting an RDB store.
**Managing Data in an RDB Store**
**Table 1** APIs for creating and deleting an RDB store
| Class| API| Description|
| -------- | -------- | -------- |
| dataRdb | getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): void | Obtains an RDB store. This method uses a callback to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>- **config**: configuration of the RDB store.<br>- **version**: RDB version.<br>- **callback**: callback invoked to return the RDB store obtained.|
| dataRdb | getRdbStore(config: StoreConfig, version: number): Promise<RdbStore> | Obtains an RDB store. This method uses a promise to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>- **config**: configuration of the RDB store.<br>- **version**: RDB version.|
| dataRdb | deleteRdbStore(name: string, callback: AsyncCallback<void>): void | Deletes an RDB store. This method uses a callback to return the result. <br>- **name**: RDB store to delete.<br>- **callback**: callback invoked to return the result. If the RDB store is deleted, **true** will be returned. Otherwise, **false** will be returned.|
| dataRdb | deleteRdbStore(name: string): Promise<void> | Deletes an RDB store. This method uses a promise to return the result.<br>- **name**: RDB store to delete.|
The RDB provides APIs for inserting, deleting, modifying, and querying data in the local RDB store.
-**Inserting data**
The RDB provides methods for inserting data through **ValuesBucket** in a data table. If the data is inserted successfully, the row number of the data inserted is returned; otherwise, **-1** is returned.
**Table 2** APIs for inserting data to a data table
<td class="cellrowborder" valign="top" width="46.239999999999995%" headers="mcps1.2.4.1.3 "><p id="p891981214423"><a name="p891981214423"></a><a name="p891981214423"></a>Inserts a row of data into a table. This method uses a callback to return the result.</p>
<a name="ul929362324319"></a><a name="ul929362324319"></a><ul id="ul929362324319"><li><strong id="b791810215118"><a name="b791810215118"></a><a name="b791810215118"></a>name</strong>: name of the target table.</li><li><strong id="b1168133481113"><a name="b1168133481113"></a><a name="b1168133481113"></a>values</strong>: data to be inserted into the table.</li><li><strong id="b153601828111218"><a name="b153601828111218"></a><a name="b153601828111218"></a>callback</strong>: callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, <strong id="b1062976631112554"><a name="b1062976631112554"></a><a name="b1062976631112554"></a>-1</strong> will be returned.</li></ul>
<td class="cellrowborder" valign="top" width="46.239999999999995%" headers="mcps1.2.4.1.3 "><p id="p579311300812"><a name="p579311300812"></a><a name="p579311300812"></a>Inserts a row of data into a table. This method uses a promise to return the result.</p>
<a name="ul121533410439"></a><a name="ul121533410439"></a><ul id="ul121533410439"><li><strong id="b928413422120"><a name="b928413422120"></a><a name="b928413422120"></a>name</strong>: name of the target table.</li><li><strong id="b17334499123"><a name="b17334499123"></a><a name="b17334499123"></a>values</strong>: data to be inserted into the table.</li></ul>
</td>
</tr>
</tbody>
</table>
-**Updating data**
Call the **update\(\)** method to pass the new data and specify the update conditions by using **RdbPredicates**. If the data is successfully updated, the row number of the updated data is returned; otherwise, **0** is returned.
<td class="cellrowborder" valign="top" width="46.03%" headers="mcps1.2.4.1.3 "><p id="p173581429117"><a name="p173581429117"></a><a name="p173581429117"></a>Updates the data that meets the conditions specified by the <strong id="b656572122112554"><a name="b656572122112554"></a><a name="b656572122112554"></a>RdbPredicates</strong> object. This method uses a callback to return the result.</p>
<a name="ul192831157114818"></a><a name="ul192831157114818"></a><ul id="ul192831157114818"><li><strong id="b174257709112554"><a name="b174257709112554"></a><a name="b174257709112554"></a>values</strong>: data to update, which is stored in <strong id="b721764115206"><a name="b721764115206"></a><a name="b721764115206"></a>ValuesBucket</strong>.</li><li><strong id="b09125491559"><a name="b09125491559"></a><a name="b09125491559"></a>rdbPredicates</strong>: conditions for updating data.</li><li><strong id="b10866112471917"><a name="b10866112471917"></a><a name="b10866112471917"></a>callback</strong>: callback invoked to return the number of rows updated.</li></ul>
<td class="cellrowborder" valign="top" width="46.03%" headers="mcps1.2.4.1.3 "><p id="p102077125277"><a name="p102077125277"></a><a name="p102077125277"></a>Updates the data that meets the conditions specified by the <strong id="b11262847102416"><a name="b11262847102416"></a><a name="b11262847102416"></a>RdbPredicates</strong> object. This method uses a promise to return the result.</p>
<a name="ul3397556155017"></a><a name="ul3397556155017"></a><ul id="ul3397556155017"><li><strong id="b694170152510"><a name="b694170152510"></a><a name="b694170152510"></a>values</strong>: data to update, which is stored in <strong id="b3949012512"><a name="b3949012512"></a><a name="b3949012512"></a>ValuesBucket</strong>.</li><li><strong id="b1992219615"><a name="b1992219615"></a><a name="b1992219615"></a>rdbPredicates</strong>: conditions for updating data.</li></ul>
</td>
</tr>
</tbody>
</table>
-**Deleting data**
Call the **delete\(\)** method to delete data meeting the conditions specified by **RdbPredicates**. If the data is deleted, the row number of the deleted data is returned; otherwise, **0** is returned.
<td class="cellrowborder" valign="top" width="57.54%" headers="mcps1.2.4.1.3 "><p id="p1746563812810"><a name="p1746563812810"></a><a name="p1746563812810"></a>Deletes data based on the conditions specified by <strong id="b25823275112554"><a name="b25823275112554"></a><a name="b25823275112554"></a>RdbPredicates</strong>. This method uses a callback to return the result.</p>
<a name="ul199371937131312"></a><a name="ul199371937131312"></a><ul id="ul199371937131312"><li><strong id="b9647017192914"><a name="b9647017192914"></a><a name="b9647017192914"></a>rdbPredicates</strong>: conditions for deleting data.</li><li><strong id="b99708313304"><a name="b99708313304"></a><a name="b99708313304"></a>callback</strong>: callback invoked to return the number of rows deleted.</li></ul>
<td class="cellrowborder" valign="top" width="57.54%" headers="mcps1.2.4.1.3 "><p id="p124258512483"><a name="p124258512483"></a><a name="p124258512483"></a>Deletes data based on the conditions specified by <strong id="b801327406112554"><a name="b801327406112554"></a><a name="b801327406112554"></a>RdbPredicates</strong>. This method uses a promise to return the result.</p>
<td class="cellrowborder" valign="top" width="46.57%" headers="mcps1.2.4.1.3 "><p id="p854321661212"><a name="p854321661212"></a><a name="p854321661212"></a>Queries data in the database based on specified conditions. This method uses a callback to return the result.</p>
<a name="ul976011905112"></a><a name="ul976011905112"></a><ul id="ul976011905112"><li><strong id="b017915301348"><a name="b017915301348"></a><a name="b017915301348"></a>columns</strong>: columns to query. If this parameter is not specified, the query applies to all columns.</li><li><strong id="b45789585356"><a name="b45789585356"></a><a name="b45789585356"></a>callback</strong>: callback invoked to return the result. If the operation is successful, a <strong id="b575560452112554"><a name="b575560452112554"></a><a name="b575560452112554"></a>ResultSet</strong> object will be returned.</li></ul>
<td class="cellrowborder" valign="top" width="46.57%" headers="mcps1.2.4.1.3 "><p id="p3681422175117"><a name="p3681422175117"></a><a name="p3681422175117"></a>Queries data in the database based on specified conditions. This method uses a promise to return the result.</p>
<a name="ul982714175553"></a><a name="ul982714175553"></a><ul id="ul982714175553"><li><strong id="b1556413233711"><a name="b1556413233711"></a><a name="b1556413233711"></a>columns</strong>: columns to query. If this parameter is not specified, the query applies to all columns.</li></ul>
<td class="cellrowborder" valign="top" width="46.57%" headers="mcps1.2.4.1.3 "><p id="p767418510287"><a name="p767418510287"></a><a name="p767418510287"></a>Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result.</p>
<a name="ul982192010316"></a><a name="ul982192010316"></a><ul id="ul982192010316"><li><strong id="b125394844210"><a name="b125394844210"></a><a name="b125394844210"></a>bindArgs</strong>: arguments in the SQL statement.</li><li><strong id="b126351142164316"><a name="b126351142164316"></a><a name="b126351142164316"></a>callback</strong>: callback invoked to return the result. If the operation is successful, a <strong id="b1798798407112554"><a name="b1798798407112554"></a><a name="b1798798407112554"></a>ResultSet</strong> object will be returned.</li></ul>
<td class="cellrowborder" valign="top" width="46.57%" headers="mcps1.2.4.1.3 "><p id="p15262131018288"><a name="p15262131018288"></a><a name="p15262131018288"></a>Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result.</p>
<a name="ul36551222123116"></a><a name="ul36551222123116"></a><ul id="ul36551222123116"><li><strong id="b19751173811446"><a name="b19751173811446"></a><a name="b19751173811446"></a>bindArgs</strong>: arguments in the SQL statement.</li></ul>
</td>
</tr>
</tbody>
</table>
**Managing Data in an RDB Store**
The RDB provides APIs for inserting, deleting, updating, and querying data in the local RDB store.
-**Inserting data**
The RDB provides APIs for inserting data through a **ValuesBucket** in a data table. If the data is inserted, the row ID of the data inserted will be returned; otherwise, **-1** will be returned.
**Table 2** APIs for inserting data
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | insert(name: string, values: ValuesBucket, callback: AsyncCallback<number>):void | Inserts a row of data into a table. This method uses a callback to return the result.<br>- **name**: name of the target table.<br>- **values**: data to be inserted into the table.<br>- **callback**: callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
| RdbStore | insert(name: string, values: ValuesBucket): Promise<number> | Inserts a row of data into a table. This method uses a promise to return the result.<br>- **name**: name of the target table.<br>- **values**: data to be inserted into the table.|
-**Updating data**
Call the **update()** method to pass new data and specify the update conditions by using **RdbPredicates**. If the data is updated, the number of rows of the updated data will be returned; otherwise, **0** will be returned.
**Table 3** APIs for updating data
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>- **values**: data to update, which is stored in a **ValuesBucket**.<br>- **rdbPredicates**: conditions for updating data.<br>- **callback**: callback invoked to return the number of rows updated.|
| RdbStore | update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>- **values**: data to update, which is stored in a **ValuesBucket**.<br>- **rdbPredicates**: conditions for updating data.|
-**Deleting data**
Call the **delete()** method to delete data meeting the conditions specified by **RdbPredicates**. If the data is deleted, the number of rows of the deleted data will be returned; otherwise, **0** will be returned.
**Table 4** APIs for deleting data
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | delete(rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>- **rdbPredicates**: conditions for deleting data.<br>- **callback**: callback invoked to return the number of rows deleted.|
| RdbStore | delete(rdbPredicates: RdbPredicates): Promise | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>- **rdbPredicates**: conditions for deleting data.|
-**Querying data**
You can query data in an RDB store in either of the following ways:
- Call the **query()** method to query data based on the predicates, without passing any SQL statement.
- Run the native SQL statement.
**Table 5** APIs for querying data
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback<ResultSet>): void | Queries data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>- **rdbPredicates**: conditions for querying data.<br>- **columns**: columns to query. If this parameter is not specified, the query applies to all columns.<br>- **callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| RdbStore | query(rdbPredicates: RdbPredicates, columns: Array): Promise<ResultSet> | Queries data in the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>- **rdbPredicates**: conditions for querying data.<br>- **columns**: columns to query. If this parameter is not specified, the query applies to all columns.|
| RdbStore | querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void | Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result.<br>- **sql**: SQL statement.<br>- **bindArgs**: arguments in the SQL statement.<br>- **callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| RdbStore | querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> | Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result.<br>- **sql**: SQL statement.<br>- **bindArgs**: arguments in the SQL statement.|
**Using Predicates**
The RDB provides **RdbPredicates** for you to set database operation conditions.
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p10345221143519"><aname="p10345221143519"></a><aname="p10345221143519"></a>Sets the <strongid="b438950696112554"><aname="b438950696112554"></a><aname="b438950696112554"></a>RdbPredicates</strong> to match the field with data type <strongid="b749976932112554"><aname="b749976932112554"></a><aname="b749976932112554"></a>ValueType</strong> and value equal to the specified value.</p>
<aname="ul39107814371"></a><aname="ul39107814371"></a><ulid="ul39107814371"><li><strongid="b15195122118513"><aname="b15195122118513"></a><aname="b15195122118513"></a>field</strong>: column name in the database table.</li><li><strongid="b18580195411521"><aname="b18580195411521"></a><aname="b18580195411521"></a>value</strong>: value to match the <strongid="b119217321114"><aname="b119217321114"></a><aname="b119217321114"></a>RdbPredicates</strong>.</li><li><strongid="b82912449110"><aname="b82912449110"></a><aname="b82912449110"></a>RdbPredicates</strong>: <strongid="b20646112018129"><aname="b20646112018129"></a><aname="b20646112018129"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p1634522183511"><aname="p1634522183511"></a><aname="p1634522183511"></a>Sets the <strongid="b1712658660112554"><aname="b1712658660112554"></a><aname="b1712658660112554"></a>RdbPredicates</strong> to match the field with data type <strongid="b726568859112554"><aname="b726568859112554"></a><aname="b726568859112554"></a>ValueType</strong> and value not equal to the specified value.</p>
<aname="ul415220710398"></a><aname="ul415220710398"></a><ulid="ul415220710398"><li><strongid="b066019819910"><aname="b066019819910"></a><aname="b066019819910"></a>field</strong>: column name in the database table.</li><li><strongid="b1810912616128"><aname="b1810912616128"></a><aname="b1810912616128"></a>value</strong>: value to match the <strongid="b1010920661216"><aname="b1010920661216"></a><aname="b1010920661216"></a>RdbPredicates</strong>.</li><li><strongid="b63152431127"><aname="b63152431127"></a><aname="b63152431127"></a>RdbPredicates</strong>: <strongid="b133155430127"><aname="b133155430127"></a><aname="b133155430127"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p1334652112353"><aname="p1334652112353"></a><aname="p1334652112353"></a>Adds a left parenthesis to the <strongid="b183257951112554"><aname="b183257951112554"></a><aname="b183257951112554"></a>RdbPredicates</strong>.</p>
<aname="ul3808195613915"></a><aname="ul3808195613915"></a><ulid="ul3808195613915"><li><strongid="b1146415308136"><aname="b1146415308136"></a><aname="b1146415308136"></a>RdbPredicates</strong>: <strongid="b145191852171313"><aname="b145191852171313"></a><aname="b145191852171313"></a>RdbPredicates</strong> with a left parenthesis.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p1634620216353"><aname="p1634620216353"></a><aname="p1634620216353"></a>Adds a right parenthesis to the <strongid="b717084362112554"><aname="b717084362112554"></a><aname="b717084362112554"></a>RdbPredicates</strong>.</p>
<aname="ul952384823816"></a><aname="ul952384823816"></a><ulid="ul952384823816"><li><strongid="b622114010147"><aname="b622114010147"></a><aname="b622114010147"></a>RdbPredicates</strong>: <strongid="b92234051419"><aname="b92234051419"></a><aname="b92234051419"></a>RdbPredicates</strong> with a right parenthesis.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p934672153514"><aname="p934672153514"></a><aname="p934672153514"></a>Adds the OR condition to the <strongid="b1180485437112554"><aname="b1180485437112554"></a><aname="b1180485437112554"></a>RdbPredicates</strong>.</p>
<aname="ul1431681603915"></a><aname="ul1431681603915"></a><ulid="ul1431681603915"><li><strongid="b439496101515"><aname="b439496101515"></a><aname="b439496101515"></a>RdbPredicates</strong>: <strongid="b1839456191515"><aname="b1839456191515"></a><aname="b1839456191515"></a>RdbPredicates</strong> with the OR condition.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p1388710815510"><aname="p1388710815510"></a><aname="p1388710815510"></a>Adds the AND condition to the <strongid="b257471589112554"><aname="b257471589112554"></a><aname="b257471589112554"></a>RdbPredicates</strong>.</p>
<aname="ul1727699185710"></a><aname="ul1727699185710"></a><ulid="ul1727699185710"><li><strongid="b18566227141510"><aname="b18566227141510"></a><aname="b18566227141510"></a>RdbPredicates</strong>: <strongid="b185661227171511"><aname="b185661227171511"></a><aname="b185661227171511"></a>RdbPredicates</strong> with the AND condition.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p138987821811"><aname="p138987821811"></a><aname="p138987821811"></a>Sets the <strongid="b1636898418112554"><aname="b1636898418112554"></a><aname="b1636898418112554"></a>RdbPredicates</strong> to match a string containing the specified value.</p>
<aname="ul187302357573"></a><aname="ul187302357573"></a><ulid="ul187302357573"><li><strongid="b0662138791"><aname="b0662138791"></a><aname="b0662138791"></a>field</strong>: column name in the database table.</li><li><strongid="b7114767121"><aname="b7114767121"></a><aname="b7114767121"></a>value</strong>: value to match the <strongid="b611466151215"><aname="b611466151215"></a><aname="b611466151215"></a>RdbPredicates</strong>.</li><li>RdbPredicates: <strongid="b14967161332010"><aname="b14967161332010"></a><aname="b14967161332010"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p102321950135210"><aname="p102321950135210"></a><aname="p102321950135210"></a>Sets the <strongid="b895587112554"><aname="b895587112554"></a><aname="b895587112554"></a>RdbPredicates</strong> to match a string that starts with the specified value.</p>
<aname="ul3643102216597"></a><aname="ul3643102216597"></a><ulid="ul3643102216597"><li><strongid="b176634812918"><aname="b176634812918"></a><aname="b176634812918"></a>field</strong>: column name in the database table.</li><li><strongid="b91196671210"><aname="b91196671210"></a><aname="b91196671210"></a>value</strong>: value to match the <strongid="b12119865128"><aname="b12119865128"></a><aname="b12119865128"></a>RdbPredicates</strong>.</li><li><strongid="b163192043181211"><aname="b163192043181211"></a><aname="b163192043181211"></a>RdbPredicates</strong>: <strongid="b13191043101217"><aname="b13191043101217"></a><aname="b13191043101217"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p1063562529"><aname="p1063562529"></a><aname="p1063562529"></a>Sets the <strongid="b1056875172112554"><aname="b1056875172112554"></a><aname="b1056875172112554"></a>RdbPredicates</strong> to match a string that ends with the specified value.</p>
<aname="ul6905132213012"></a><aname="ul6905132213012"></a><ulid="ul6905132213012"><li><strongid="b46643820919"><aname="b46643820919"></a><aname="b46643820919"></a>field</strong>: column name in the database table.</li><li><strongid="b121239671216"><aname="b121239671216"></a><aname="b121239671216"></a>value</strong>: value to match the <strongid="b912317619121"><aname="b912317619121"></a><aname="b912317619121"></a>RdbPredicates</strong>.</li><li><strongid="b103211043131213"><aname="b103211043131213"></a><aname="b103211043131213"></a>RdbPredicates</strong>: <strongid="b20321104319124"><aname="b20321104319124"></a><aname="b20321104319124"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p2822172913538"><aname="p2822172913538"></a><aname="p2822172913538"></a>Sets the <strongid="b1194045299112554"><aname="b1194045299112554"></a><aname="b1194045299112554"></a>RdbPredicates</strong> to match the field whose value is <strongid="b1890023078112554"><aname="b1890023078112554"></a><aname="b1890023078112554"></a>null</strong>.</p>
<aname="ul152823233592"></a><aname="ul152823233592"></a><ulid="ul152823233592"><li><strongid="b206641881994"><aname="b206641881994"></a><aname="b206641881994"></a>field</strong>: column name in the database table.</li><li><strongid="b1774115571093"><aname="b1774115571093"></a><aname="b1774115571093"></a>RdbPredicates</strong>: <strongid="b18741165710911"><aname="b18741165710911"></a><aname="b18741165710911"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p7520112182316"><aname="p7520112182316"></a><aname="p7520112182316"></a>Sets the <strongid="b1059930094112554"><aname="b1059930094112554"></a><aname="b1059930094112554"></a>RdbPredicates</strong> to match the field whose value is not <strongid="b172403177112554"><aname="b172403177112554"></a><aname="b172403177112554"></a>null</strong>.</p>
<aname="ul5646142816017"></a><aname="ul5646142816017"></a><ulid="ul5646142816017"><li><strongid="b1366598494"><aname="b1366598494"></a><aname="b1366598494"></a>field</strong>: column name in the database table.</li><li><strongid="b355418851019"><aname="b355418851019"></a><aname="b355418851019"></a>RdbPredicates</strong>: <strongid="b15541983103"><aname="b15541983103"></a><aname="b15541983103"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p753485217231"><aname="p753485217231"></a><aname="p753485217231"></a>Sets the <strongid="b964300928112554"><aname="b964300928112554"></a><aname="b964300928112554"></a>RdbPredicates</strong> to match a string that is similar to the specified value.</p>
<aname="ul15439141112"></a><aname="ul15439141112"></a><ulid="ul15439141112"><li><strongid="b1366618991"><aname="b1366618991"></a><aname="b1366618991"></a>field</strong>: column name in the database table.</li><li><strongid="b11277641210"><aname="b11277641210"></a><aname="b11277641210"></a>value</strong>: value to match the <strongid="b121272065124"><aname="b121272065124"></a><aname="b121272065124"></a>RdbPredicates</strong>.</li><li><strongid="b19556158101012"><aname="b19556158101012"></a><aname="b19556158101012"></a>RdbPredicates</strong>: <strongid="b1556484106"><aname="b1556484106"></a><aname="b1556484106"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p14252854172320"><aname="p14252854172320"></a><aname="p14252854172320"></a>Sets the <strongid="b644369182112554"><aname="b644369182112554"></a><aname="b644369182112554"></a>RdbPredicates</strong> to match the specified string.</p>
<aname="ul18503142413115"></a><aname="ul18503142413115"></a><ulid="ul18503142413115"><li><strongid="b5667581899"><aname="b5667581899"></a><aname="b5667581899"></a>field</strong>: column name in the database table.</li><li><strongid="b10131460122"><aname="b10131460122"></a><aname="b10131460122"></a>value</strong>: value to match the <strongid="b1313176191214"><aname="b1313176191214"></a><aname="b1313176191214"></a>RdbPredicates</strong>.</li><li><strongid="b125581984106"><aname="b125581984106"></a><aname="b125581984106"></a>RdbPredicates</strong>: <strongid="b955819810103"><aname="b955819810103"></a><aname="b955819810103"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p1827513201020"><aname="p1827513201020"></a><aname="p1827513201020"></a>Sets the <strongid="b625856712112554"><aname="b625856712112554"></a><aname="b625856712112554"></a>RdbPredicates</strong> to match the field with data type <strongid="b489101076112554"><aname="b489101076112554"></a><aname="b489101076112554"></a>ValueType</strong> and value within the specified range.</p>
<aname="ul3448133612117"></a><aname="ul3448133612117"></a><ulid="ul3448133612117"><li><strongid="b46682814917"><aname="b46682814917"></a><aname="b46682814917"></a>field</strong>: column name in the database table.</li><li><strongid="b062216817256"><aname="b062216817256"></a><aname="b062216817256"></a>low</strong>: minimum value that matches the <strongid="b4408649182510"><aname="b4408649182510"></a><aname="b4408649182510"></a>RdbPredicates</strong>.</li><li><strongid="b1336881318253"><aname="b1336881318253"></a><aname="b1336881318253"></a>high</strong>: maximum value that matches the <strongid="b05634512611"><aname="b05634512611"></a><aname="b05634512611"></a>RdbPredicates</strong>.</li><li><strongid="b135596841010"><aname="b135596841010"></a><aname="b135596841010"></a>RdbPredicates</strong>: <strongid="b1555913891013"><aname="b1555913891013"></a><aname="b1555913891013"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p1073914511013"><aname="p1073914511013"></a><aname="p1073914511013"></a>Sets the <strongid="b480030174112554"><aname="b480030174112554"></a><aname="b480030174112554"></a>RdbPredicates</strong> to match the field with data type <strongid="b591370903112554"><aname="b591370903112554"></a><aname="b591370903112554"></a>ValueType</strong> and value out of the specified range.</p>
<aname="ul697416399210"></a><aname="ul697416399210"></a><ulid="ul697416399210"><li><strongid="b136681086914"><aname="b136681086914"></a><aname="b136681086914"></a>field</strong>: column name in the database table.</li><li><strongid="b4395132016267"><aname="b4395132016267"></a><aname="b4395132016267"></a>low</strong>: minimum value that matches the <strongid="b0396182092615"><aname="b0396182092615"></a><aname="b0396182092615"></a>RdbPredicates</strong>.</li><li><strongid="b16568182820262"><aname="b16568182820262"></a><aname="b16568182820262"></a>high</strong>: maximum value that matches the <strongid="b12568128132611"><aname="b12568128132611"></a><aname="b12568128132611"></a>RdbPredicates</strong>.</li><li><strongid="b25607881011"><aname="b25607881011"></a><aname="b25607881011"></a>RdbPredicates</strong>: <strongid="b256013819104"><aname="b256013819104"></a><aname="b256013819104"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p129461514117"><aname="p129461514117"></a><aname="p129461514117"></a>Sets the <strongid="b299934469112554"><aname="b299934469112554"></a><aname="b299934469112554"></a>RdbPredicates</strong> to match the field with data type <strongid="b297820682112554"><aname="b297820682112554"></a><aname="b297820682112554"></a>ValueType</strong> and value greater than the specified value.</p>
<aname="ul11811341539"></a><aname="ul11811341539"></a><ulid="ul11811341539"><li><strongid="b116691285910"><aname="b116691285910"></a><aname="b116691285910"></a>field</strong>: column name in the database table.</li><li><strongid="b7135166141214"><aname="b7135166141214"></a><aname="b7135166141214"></a>value</strong>: value to match the <strongid="b71351460123"><aname="b71351460123"></a><aname="b71351460123"></a>RdbPredicates</strong>.</li><li><strongid="b9561138131015"><aname="b9561138131015"></a><aname="b9561138131015"></a>RdbPredicates</strong>: <strongid="b1561584103"><aname="b1561584103"></a><aname="b1561584103"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p1150510191493"><aname="p1150510191493"></a><aname="p1150510191493"></a>Sets the <strongid="b998950278112554"><aname="b998950278112554"></a><aname="b998950278112554"></a>RdbPredicates</strong> to match the field with data type <strongid="b1745313530112554"><aname="b1745313530112554"></a><aname="b1745313530112554"></a>ValueType</strong> and value less than the specified value.</p>
<aname="ul1641512392313"></a><aname="ul1641512392313"></a><ulid="ul1641512392313"><li><strongid="b367014815919"><aname="b367014815919"></a><aname="b367014815919"></a>field</strong>: column name in the database table.</li><li><strongid="b213966181219"><aname="b213966181219"></a><aname="b213966181219"></a>value</strong>: value to match the <strongid="b161391269123"><aname="b161391269123"></a><aname="b161391269123"></a>RdbPredicates</strong>.</li><li><strongid="b17562183104"><aname="b17562183104"></a><aname="b17562183104"></a>RdbPredicates</strong>: <strongid="b156228141013"><aname="b156228141013"></a><aname="b156228141013"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p1496111155113"><aname="p1496111155113"></a><aname="p1496111155113"></a>Sets the <strongid="b349869843112554"><aname="b349869843112554"></a><aname="b349869843112554"></a>RdbPredicates</strong> to match the field with data type <strongid="b634300709112554"><aname="b634300709112554"></a><aname="b634300709112554"></a>ValueType</strong> and value greater than or equal to the specified value.</p>
<aname="ul1169911541738"></a><aname="ul1169911541738"></a><ulid="ul1169911541738"><li><strongid="b86711689917"><aname="b86711689917"></a><aname="b86711689917"></a>field</strong>: column name in the database table.</li><li><strongid="b71443641215"><aname="b71443641215"></a><aname="b71443641215"></a>value</strong>: value to match the <strongid="b414420621215"><aname="b414420621215"></a><aname="b414420621215"></a>RdbPredicates</strong>.</li><li><strongid="b3563189109"><aname="b3563189109"></a><aname="b3563189109"></a>RdbPredicates</strong>: <strongid="b6563168171010"><aname="b6563168171010"></a><aname="b6563168171010"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p12181611535"><aname="p12181611535"></a><aname="p12181611535"></a>Sets the <strongid="b312137118112554"><aname="b312137118112554"></a><aname="b312137118112554"></a>RdbPredicates</strong> to match the field with data type <strongid="b304585139112554"><aname="b304585139112554"></a><aname="b304585139112554"></a>ValueType</strong> and value less than or equal to the specified value.</p>
<aname="ul954651146"></a><aname="ul954651146"></a><ulid="ul954651146"><li><strongid="b3672785911"><aname="b3672785911"></a><aname="b3672785911"></a>field</strong>: column name in the database table.</li><li><strongid="b14148146141213"><aname="b14148146141213"></a><aname="b14148146141213"></a>value</strong>: value to match the <strongid="b21481362121"><aname="b21481362121"></a><aname="b21481362121"></a>RdbPredicates</strong>.</li><li><strongid="b1056414811010"><aname="b1056414811010"></a><aname="b1056414811010"></a>RdbPredicates</strong>: <strongid="b20564128141016"><aname="b20564128141016"></a><aname="b20564128141016"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p31119384125"><aname="p31119384125"></a><aname="p31119384125"></a>Sets the <strongid="b688515142112554"><aname="b688515142112554"></a><aname="b688515142112554"></a>RdbPredicates</strong> to match the column with values sorted in ascending order.</p>
<aname="ul12611201211416"></a><aname="ul12611201211416"></a><ulid="ul12611201211416"><li><strongid="b20672881395"><aname="b20672881395"></a><aname="b20672881395"></a>field</strong>: column name in the database table.</li><li><strongid="b4565481101"><aname="b4565481101"></a><aname="b4565481101"></a>RdbPredicates</strong>: <strongid="b1956515816107"><aname="b1956515816107"></a><aname="b1956515816107"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p152261741201214"><aname="p152261741201214"></a><aname="p152261741201214"></a>Sets the <strongid="b1784358755112554"><aname="b1784358755112554"></a><aname="b1784358755112554"></a>RdbPredicates</strong> to match the column with values sorted in descending order.</p>
<aname="ul17931024747"></a><aname="ul17931024747"></a><ulid="ul17931024747"><li><strongid="b106731081197"><aname="b106731081197"></a><aname="b106731081197"></a>field</strong>: column name in the database table.</li><li><strongid="b15661871013"><aname="b15661871013"></a><aname="b15661871013"></a>RdbPredicates</strong>: <strongid="b55664821014"><aname="b55664821014"></a><aname="b55664821014"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p79613373335"><aname="p79613373335"></a><aname="p79613373335"></a>Sets the <strongid="b1849038781112554"><aname="b1849038781112554"></a><aname="b1849038781112554"></a>RdbPredicates</strong> to filter out duplicate records.</p>
<aname="ul9247643548"></a><aname="ul9247643548"></a><ulid="ul9247643548"><li><strongid="b8216555102712"><aname="b8216555102712"></a><aname="b8216555102712"></a>RdbPredicates</strong>: <strongid="b154056214288"><aname="b154056214288"></a><aname="b154056214288"></a>RdbPredicates</strong> that can filter out duplicate records.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p167441813355"><aname="p167441813355"></a><aname="p167441813355"></a>Sets the <strongid="b1852235509112554"><aname="b1852235509112554"></a><aname="b1852235509112554"></a>RdbPredicates</strong> to specify the maximum number of records to match in a column.</p>
<aname="ul99331016519"></a><aname="ul99331016519"></a><ulid="ul99331016519"><li><strongid="b1066132843113"><aname="b1066132843113"></a><aname="b1066132843113"></a>value</strong>: maximum number of records in a column.</li><li><strongid="b2596134933112"><aname="b2596134933112"></a><aname="b2596134933112"></a>RdbPredicates</strong>: <strongid="b17201911321"><aname="b17201911321"></a><aname="b17201911321"></a>RdbPredicates</strong> that can be used to set the maximum number of records to match in a column.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p621595810347"><aname="p621595810347"></a><aname="p621595810347"></a>Sets the <strongid="b330697748112554"><aname="b330697748112554"></a><aname="b330697748112554"></a>RdbPredicates</strong> to specify the start position of the returned result.</p>
<aname="ul16890144017919"></a><aname="ul16890144017919"></a><ulid="ul16890144017919"><li><strongid="b4801398332"><aname="b4801398332"></a><aname="b4801398332"></a>rowOffset</strong>: start position of the returned result. The value is a positive integer.</li><li><strongid="b15974182419334"><aname="b15974182419334"></a><aname="b15974182419334"></a>RdbPredicates</strong>: <strongid="b117772378336"><aname="b117772378336"></a><aname="b117772378336"></a>RdbPredicates</strong> object that specifies the start position of the returned result.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p315610216119"><aname="p315610216119"></a><aname="p315610216119"></a>Sets the <strongid="b922906078112554"><aname="b922906078112554"></a><aname="b922906078112554"></a>RdbPredicates</strong> to group rows that have the same value into summary rows.</p>
<aname="ul048292611102"></a><aname="ul048292611102"></a><ulid="ul048292611102"><li><strongid="b12152152614219"><aname="b12152152614219"></a><aname="b12152152614219"></a>fields</strong>: names of the columns grouped for querying data.</li><li><strongid="b107111444315"><aname="b107111444315"></a><aname="b107111444315"></a>RdbPredicates</strong>: <strongid="b1693008184315"><aname="b1693008184315"></a><aname="b1693008184315"></a>RdbPredicates</strong> that groups rows that have the same value.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p784844513588"><aname="p784844513588"></a><aname="p784844513588"></a>Sets the <strongid="b1547335609112554"><aname="b1547335609112554"></a><aname="b1547335609112554"></a>RdbPredicates</strong> object to specify the index column.</p>
<aname="ul14142173351011"></a><aname="ul14142173351011"></a><ulid="ul14142173351011"><li><strongid="b74784474315"><aname="b74784474315"></a><aname="b74784474315"></a>indexName</strong>: name of the index column.</li><li><strongid="b8808413154415"><aname="b8808413154415"></a><aname="b8808413154415"></a>RdbPredicates</strong>: <strongid="b3808141812449"><aname="b3808141812449"></a><aname="b3808141812449"></a>RdbPredicates</strong> object that specifies the index column.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p12468144012181"><aname="p12468144012181"></a><aname="p12468144012181"></a>Sets the <strongid="b1089824940112554"><aname="b1089824940112554"></a><aname="b1089824940112554"></a>RdbPredicates</strong> to match the field with data type <strongid="b1982339248112554"><aname="b1982339248112554"></a><aname="b1982339248112554"></a>Array<ValueType></strong> and value within the specified range.</p>
<aname="ul1261343010160"></a><aname="ul1261343010160"></a><ulid="ul1261343010160"><li><strongid="b2674281693"><aname="b2674281693"></a><aname="b2674281693"></a>field</strong>: column name in the database table.</li></ul>
<aname="ul12498383105"></a><aname="ul12498383105"></a><ulid="ul12498383105"><li><strongid="b495499154512"><aname="b495499154512"></a><aname="b495499154512"></a>value</strong>: array of <strongid="b161531382454"><aname="b161531382454"></a><aname="b161531382454"></a>ValueType</strong> to match.</li><li><strongid="b145677817100"><aname="b145677817100"></a><aname="b145677817100"></a>RdbPredicates</strong>: <strongid="b8567178151019"><aname="b8567178151019"></a><aname="b8567178151019"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
<tdclass="cellrowborder"valign="top"width="46.239999999999995%"headers="mcps1.2.4.1.3 "><pid="p2066842875317"><aname="p2066842875317"></a><aname="p2066842875317"></a>Sets the <strongid="b2092907677112554"><aname="b2092907677112554"></a><aname="b2092907677112554"></a>RdbPredicates</strong> to match the field with data type <strongid="b30969258112554"><aname="b30969258112554"></a><aname="b30969258112554"></a>Array<ValueType></strong> and value out of the specified range.</p>
<aname="ul2699143755811"></a><aname="ul2699143755811"></a><ulid="ul2699143755811"><li><strongid="b56756812910"><aname="b56756812910"></a><aname="b56756812910"></a>field</strong>: column name in the database table.</li></ul>
<aname="ul93771585122"></a><aname="ul93771585122"></a><ulid="ul93771585122"><li><strongid="b447917884619"><aname="b447917884619"></a><aname="b447917884619"></a>value</strong>: array of <strongid="b144791884611"><aname="b144791884611"></a><aname="b144791884611"></a>ValueType</strong> to match.</li><li><strongid="b155684813104"><aname="b155684813104"></a><aname="b155684813104"></a>RdbPredicates</strong>: <strongid="b115680813101"><aname="b115680813101"></a><aname="b115680813101"></a>RdbPredicates</strong> object that matches the specified field.</li></ul>
</td>
</tr>
</tbody>
</table>
The RDB provides **RdbPredicates** for you to set database operation conditions.
**Table 6** APIs for using RDB store predicates
| Class| API| Description|
| -------- | -------- | -------- |
| RdbPredicates |inDevices(devices: Array<string>): RdbPredicates | Specifies remote devices on the network with RDB stores to be synchronized.<br>- **devices**: IDs of the remote devices on the network.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates |inAllDevices(): RdbPredicates | Connects to all remote devices on the network with RDB stores to be synchronized.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | equalTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | notEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | beginWrap(): RdbPredicates | Adds a left parenthesis to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with a left parenthesis. |
| RdbPredicates | endWrap(): RdbPredicates | Adds a right parenthesis to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with a right parenthesis. |
| RdbPredicates | or(): RdbPredicates | Adds the OR condition to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with the OR condition. |
| RdbPredicates | and(): RdbPredicates | Adds the AND condition to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with the AND condition. |
| RdbPredicates | contains(field: string, value: string): RdbPredicats | Sets the **RdbPredicates** to match a string containing the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string. |
| RdbPredicates | beginsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that starts with the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string. |
| RdbPredicates | endsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that ends with the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string. |
| RdbPredicates | isNull(field: string): RdbPredicates | Sets the **RdbPredicates** to match the field whose value is null.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | isNotNull(field: string): RdbPredicates | Sets the **RdbPredicates** to match the field whose value is not null.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | like(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that is similar to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string. |
| RdbPredicates | glob(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match the specified string.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string. |
| RdbPredicates | between(field: string, low: ValueType, high: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value within the specified range.<br>- **field**: column name in the database table.<br>- **low**: minimum value that matches the **RdbPredicates**.<br>- **high**: maximum value that matches the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range.<br>- **field**: column name in the database table.<br>- **low**: minimum value that matches the **RdbPredicates**.<br>- **high**: maximum value that matches the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | greaterThan(field: string, value: ValueType): RdbPredicatesgr | Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | lessThan(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | orderByAsc(field: string): RdbPredicates | Sets the **RdbPredicates** to match the column with values sorted in ascending order.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that sorts the values in ascending order. |
| RdbPredicates | orderByDesc(field: string): RdbPredicates | Sets the **RdbPredicates** to match the column with values sorted in descending order.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that sorts the values in descending order. |
| RdbPredicates | distinct(): RdbPredicates | Sets the **RdbPredicates** to filter out duplicate records.<br>- **RdbPredicates**: returns a **RdbPredicates** object that can filter out duplicate records. |
| RdbPredicates | limitAs(value: number): RdbPredicates | Sets the **RdbPredicates** to specify the maximum number of records.<br>- **value**: maximum number of records.<br>- **RdbPredicates**: returns a **RdbPredicates** object that can be used to set the maximum number of records. |
| RdbPredicates | offsetAs(rowOffset: number): RdbPredicates | Sets the **RdbPredicates** to specify the start position of the returned result.<br>- **rowOffset**: start position of the returned result. The value is a positive integer.<br>- **RdbPredicates**: returns a **RdbPredicates** object that specifies the start position of the returned result. |
| RdbPredicates | groupBy(fields: Array<string>): RdbPredicates | Sets the **RdbPredicates** to group rows that have the same value into summary rows.<br>- **fields**: names of the columns grouped for querying data.<br>- **RdbPredicates**: returns a **RdbPredicates** object that groups rows with the same value. |
| RdbPredicates | indexedBy(indexName: string): RdbPredicates | Sets the **RdbPredicates** to specify the index column.<br>- **indexName**: name of the index column.<br>- **RdbPredicates**: returns a **RdbPredicates** object that specifies the index column. |
| RdbPredicates | in(field: string, value: Array<ValueType>): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array<ValueType>** and value within the specified range.<br>- **field**: column name in the database table.<br>- **value**: array of **ValueType** to match.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
| RdbPredicates | notIn(field: string, value: Array<ValueType>): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array<ValueType>** and value out of the specified range.<br>- **field**: column name in the database table.<br>- **value**: array of **ValueType** to match.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. |
**Using the Result Set**
A result set can be regarded as rows of data in the queried results. It allows you to traverse and access the data you have queried. The following table describes the external APIs of **ResultSet**.
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p9210183113187"><aname="p9210183113187"></a><aname="p9210183113187"></a>Moves the result set forwards or backwards by an offset relative to its current position.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p141113153210"><aname="p141113153210"></a><aname="p141113153210"></a>Moves the result set to a specified row.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p627132327"><aname="p627132327"></a><aname="p627132327"></a>Moves the result set to the next row.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p1321813143210"><aname="p1321813143210"></a><aname="p1321813143210"></a>Moves the result set to the previous row.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p0315135329"><aname="p0315135329"></a><aname="p0315135329"></a>Obtains the column index based on the specified column name.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p4341363212"><aname="p4341363212"></a><aname="p4341363212"></a>Obtains the column name based on the specified column index.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p153513123219"><aname="p153513123219"></a><aname="p153513123219"></a>Checks whether the result set is located in the first row.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p13381311321"><aname="p13381311321"></a><aname="p13381311321"></a>Checks whether the result set is located in the last row.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p1651713173216"><aname="p1651713173216"></a><aname="p1651713173216"></a>Obtains the values in the specified column of the current row, in strings.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p1553134322"><aname="p1553134322"></a><aname="p1553134322"></a>Obtains the values in the specified column of the current row, in a byte array.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p1854135329"><aname="p1854135329"></a><aname="p1854135329"></a>Obtains the values in the specified column of the current row, in double.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p929814244115"><aname="p929814244115"></a><aname="p929814244115"></a>Checks whether the values in the specified column of the current row are <strongid="b1342751713112554"><aname="b1342751713112554"></a><aname="b1342751713112554"></a>null</strong>.</p>
<tdclass="cellrowborder"valign="top"width="46.300000000000004%"headers="mcps1.2.4.1.3 "><pid="p16240104519118"><aname="p16240104519118"></a><aname="p16240104519118"></a>Closes the result set.</p>
</td>
</tr>
</tbody>
</table>
**Encrypting an RDB Store**
A result set can be regarded as a row of data in the queried results. It allows you to traverse and access the data you have queried. The following table describes the external APIs of **ResultSet**.
> After a result set is used, you must call the **close()** method to close it explicitly.
**Table 7** APIs for using the result set
| Class| API| Description|
| -------- | -------- | -------- |
| ResultSet | goTo(offset:number): boolean | Moves the result set forwards or backwards by the specified offset relative to its current position.|
| ResultSet | goToRow(position: number): boolean | Moves the result set to the specified row.|
| ResultSet | goToNextRow(): boolean | Moves the result set to the next row.|
| ResultSet | goToPreviousRow(): boolean | Moves the result set to the previous row.|
| ResultSet | getColumnIndex(columnName: string): number | Obtains the column index based on the specified column name.|
| ResultSet | getColumnName(columnIndex: number): string | Obtains the column name based on the specified column index.|
| ResultSet | goToFirstRow(): boolean | Checks whether the result set is located in the first row.|
| ResultSet | goToLastRow(): boolean | Checks whether the result set is located in the last row.|
| ResultSet | getString(columnIndex: number): string | Obtains the value in the specified column of the current row, in a string.|
| ResultSet | getBlob(columnIndex: number): Uint8Array | Obtains the values in the specified column of the current row, in a byte array.|
| ResultSet | getDouble(columnIndex: number): number | Obtains the values in the specified column of the current row, in double.|
| ResultSet | isColumnNull(columnIndex: number): boolean | Checks whether the value in the specified column of the current row is null.|
| ResultSet | close(): void | Closes the result set.|
**Changing the Encryption Key for an RDB Store**
You can encrypt an RDB store.
When creating an RDB store, you can add a key for security purposes. After that, the RDB store can be accessed only with the correct key. You can change the key but cannot delete it.
Once an RDB store is created without a key, you cannot add a key any longer.
<tdclass="cellrowborder"valign="top"width="43.55%"headers="mcps1.2.4.1.3 "><pid="p4625115845012"><aname="p4625115845012"></a><aname="p4625115845012"></a>Changes the encryption key for an RDB store. This method uses a callback to return the result. If the key is changed, <strongid="b17911183611517"><aname="b17911183611517"></a><aname="b17911183611517"></a>0</strong> is returned. Otherwise, a non-zero value is returned.</p>
<tdclass="cellrowborder"valign="top"width="43.55%"headers="mcps1.2.4.1.3 "><pid="p186252058175012"><aname="p186252058175012"></a><aname="p186252058175012"></a>Changes the encryption key for an RDB store. This method uses a promise to return the result. If the key is changed, <strongid="b4886609720"><aname="b4886609720"></a><aname="b4886609720"></a>0</strong> is returned. Otherwise, a non-zero value is returned.</p>
</td>
</tr>
</tbody>
</table>
## How to Develop<a name="section116922712311"></a>
1. Create an RDB store.
1. Configure the RDB attributes, including the name and storage mode of the database and whether it is read-only.
2. Initialize the table structure and related data in the database.
3. Create an RDB store.
Once an RDB store is created without a key, you can no longer add a key for it.
The sample code is as follows:
**Table 8** APIs for changing the encryption key
```
import dataRdb from '@ohos.data.rdb';
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = {name: "rdbstore.db",}
let rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST);
```
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | changeEncryptKey(newEncryptKey:Uint8Array, callback: AsyncCallback<number>):void; | Changes the encryption key for this RDB store. This method uses a callback to return the result. If the operation is successful, **0** will be returned. Otherwise, a non-zero value will be returned.|
| RdbStore | changeEncryptKey(newEncryptKey:Uint8Array): Promise<number>; | Changes the encryption key for this RDB store. This method uses a promise to return the result. If the operation is successful, **0** will be returned. Otherwise, a non-zero value will be returned.|
**Setting Distributed Tables**
You can set a list of distributed tables for data operations across devices.
**Table 9** APIs for setting distributed tables
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | setDistributedTables(tables: Array<string>, callback: AsyncCallback<void>): void;| Sets a list of distributed tables. This method uses a callback to return the result.<br>- **tables**: names of the distributed tables to set.<br>- **callback**: callback invoked to return the result.|
| RdbStore | setDistributedTables(tables: Array<string>): Promise<void>; | Sets a list of distributed tables. This method uses a promise to return the result.<br>- **tables**: names of the distributed tables to set.|
**Obtaining the Distributed Table Name for a Remote Device**
You can obtain the distributed table name for a remote device based on the local table name. The distributed table name can be used to query the RDB store of the remote device.
**Table 10** API for obtaining the distributed table name of a remote device
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | 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 used to query the RDB store of the remote device. This method uses a callback to return the result.<br>- **device**: remote device.<br>- **table**: local table name.<br>- **callback**: callback used to return the result. If the operation is successful, the distributed table name of the remote device will be returned. |
| RdbStore | 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 used to query the RDB store of the remote device. This method uses a promise to return the result.<br>- **device**: remote device.<br>- **table**: local table name.|
**Synchronizing Data Between Devices**
**Table 11** APIs for synchronizing data between devices
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string,number]>>): void;| Synchronizes data between devices. This method uses a callback to return the result.<br>- **mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>- **predicates**: data and devices to be synchronized.<br>- **callback**: callback invoked to return the result. In the result, **string** indicates the device ID, and **number** indicates the synchronization status of each device. The value **0** indicates a success, and other values indicate a failure.|
| RdbStore | sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string,number]>>;| Synchronizes data between devices. This method uses a promise to return the result.<br>- **mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>- **predicates**: data and devices to be synchronized. |
**Registering an RDB Store Observer**
2. Insert data.
**Table 12** API for registering an observer
1. Create a **ValuesBucket** object to store the data you need to insert.
2. Call the **insert\(\)** method to insert data into the RDB store.
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore |on(event: 'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void;| Registers an observer for this RDB store to subscribe to distributed data changes. When data in the RDB store changes, a callback will be invoked to return the data changes.<br>- **type**: subscription type. **SUBSCRIBE\_TYPE\_REMOTE** means to subscribe to remote data changes.<br>- **observer**: observer that listens for data changes in the RDB store.|
**Unregistering an RDB Store Observer**
**Table 13** API for unregistering an observer
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore |off(event:'dataChange', type: SubscribeType, observer: Callback<Array<string>>): void;| Unregisters the observer of the specified type for the RDB store. This method uses a callback to return the result.<br>- **type**: subscription type. **SUBSCRIBE\_TYPE\_REMOTE** means to subscribe to remote data changes.<br>- **observer**: observer to unregister.|
## How to Develop
1. Create an RDB store.
1. Configure the RDB store attributes, including the RDB store name, storage mode, and whether read-only mode is used.
2. Initialize the table structure and related data in the RDB store.
3. Create the RDB store.
The sample code is as follows:
```
import dataRdb from '@ohos.data.rdb';
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = {name: "rdbstore.db",}
let rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST);
```
2. Insert data.
1. Create a **ValuesBucket** to store the data you need to insert.
2. Call the **insert()** method to insert data into the RDB store.
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import account_osAccount from '@ohos.account.osAccount';
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If multiple OS accounts are supported, **true** will be returned. Otherwise, **false** will be returned.|
| Promise<boolean> | Promise used to return the result. If multiple OS accounts are supported, **true** will be returned. Otherwise, **false** will be returned.|
| localId | number | Yes | ID of the target OS account. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the OS account is activated, **true** will be returned. Otherwise, **false** will be returned.|
| Promise<boolean> | Promise used to return the result. If the OS account is activated, **true** will be returned. Otherwise, **false** will be returned.|
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the constraint is enabled for the OS account, **true** will be returned. Otherwise, **false** will be returned.|
- Example
Check whether OS account 100 is forbidden to use Wi-Fi.
| Promise<boolean> | Promise used to return the result. If the constraint is enabled for the OS account, **true** will be returned. Otherwise, **false** will be returned.|
- Example
Check whether OS account 100 is forbidden to use Wi-Fi.
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the account is a test account, **true** will be returned. Otherwise, **false** will be returned.|
| Promise<boolean> | Promise used to return the result. If the account is a test account, **true** will be returned. Otherwise, **false** will be returned.|
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the OS account has been verified, **true** will be returned. Otherwise, **false** will be returned.|
| localId | number | No | ID of the target OS account. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the OS account has been verified, **true** will be returned. Otherwise, **false** will be returned.|
| Promise<boolean> | Promise used to return the result. If the OS account has been verified, **true** will be returned. Otherwise, **false** will be returned.|
| type | 'activate' \| 'activating' | Yes | Type of the event to subscribe to. The value **activate** means an event indicating that an OS account is activated, and **activating** means an event indicating that an OS account is being activated. |
| name | string | Yes | Subscription name, which can be customized. The value cannot be empty or exceed 1024 bytes.|
| callback | Callback<number> | Yes | Callback used to return the OS account ID and status changes.|
| type | 'activate' \| 'activating' | Yes | Type of the event to unsubscribe from. The value **activate** means an event indicating that an OS account is activated, and **activating** means an event indicating that an OS account is being activated. |
| name | string | Yes | Subscription name, which can be customized. The value cannot be empty or exceed 1024 bytes, and must be the same as the value passed by **on()**.|
| callback | Callback<number> | No | Callback used to return the OS account changes. By default, **0** is returned.|
@@ -9,11 +9,11 @@ On the basis of the SQLite database, the RDB allows you to operate data with or
The following table describes APIs available for creating and deleting an RDB store.
Table 1 APIs for creating and deleting an RDB store
**Table 1** APIs for creating and deleting an RDB store
| Class| API| Description|
| ---- | ---- | ---- |
| RdbStoreConfig | RdbStoreConfig(const std::string &path, <br> StorageMode storageMode = StorageMode::MODE_DISK, <br> bool readOnly = false, <br> const std::vector<uint8_t> &encryptKey = std::vector<uint8_t>(), <br> const std::string &journalMode = "", <br> const std::string &syncMode = "", <br> const std::string &databaseFileType = "", <br> const std::string &databaseFileSecurityLevel = "") | Configures an RDB store, including setting the name, storage mode, log mode, synchronization mode, and read-only mode, and encrypting the database. <ul><li>**path**: path of the database. </li><li>**readOnly**: whether the database is read-only. </li><li>**storageMode**: storage mode. </li><li>**encryptKey**: key used for database encryption. </li><li>**journalMode**: database logging mode. </li><li>**syncMode**: data synchronization mode. </li><li>**databaseFileType**: database type. </li><li>**databaseFileSecurityLevel**: security level. </li></ul>|
| RdbStoreConfig | RdbStoreConfig(const std::string &path, <br> StorageMode storageMode = StorageMode::MODE_DISK, <br> bool readOnly = false, <br> const std::vector<uint8_t> &encryptKey = std::vector<uint8_t>(), <br> const std::string &journalMode = "", <br> const std::string &syncMode = "", <br> const std::string &databaseFileType = "", <br> const std::string &databaseFileSecurityLevel = "") | Configures an RDB store, including setting the name, storage mode, log mode, synchronization mode, and read-only mode, and encrypting the RDB store.<br/> - **path**: path of the database.<br/> - **readOnly**: whether the database is read-only.<br/> - **storageMode**: storage mode.<br/> - **encryptKey**: key used for database encryption.<br/> - **journalMode**: database logging mode.<br/> - **syncMode**: data synchronization mode.<br/> - **databaseFileType**: database type.<br/> - **databaseFileSecurityLevel**: security level. |
| RdbOpenCallback | int OnCreate(RdbStore &rdbStore) | Called when an RDB store is created. You can add the method for initializing the table structure and add initialization data used by your application in the callback.|
| RdbOpenCallback | int OnUpgrade(RdbStore &rdbStore, int currentVersion, int targetVersion) | Called when the RDB store is upgraded.|
| RdbOpenCallback | int OnDowngrade(RdbStore &rdbStore, int currentVersion, int targetVersion) | Called when the RDB store is downgraded.|
...
...
@@ -22,12 +22,12 @@ Table 1 APIs for creating and deleting an RDB store
### Encrypting an RDB Store
The RDB provides the database encryption capability. When creating an RDB store, you can add a key for security purposes. After that, the RDB store can be accessed only with the correct key.
The RDB provides the database encryption capability. When creating an RDB store, you can add a key for security purposes. After that, the RDB store can be accessed only with the correct key.
Table 2 API for changing the key
**Table 2** API for changing the key
| Class| API| Description|
| ---- | ---- | ---- |
| RdbStore | int ChangeEncryptKey(const std::vector<uint8_t> &newKey) | Changes the encryption key for an RDB store. <br>Note: The encryption key can be changed only for an encrypted database.|
| RdbStore | int ChangeEncryptKey(const std::vector<uint8_t> &newKey) | Changes the encryption key for an RDB store. <br>Note: The encryption key can be changed only for an encrypted RDB store.|
### Using Predicates
...
...
@@ -36,7 +36,7 @@ The RDB provides **AbsRdbPredicates** for you to set database operation conditio
-**RdbPredicates**: With this class, you do not need to write complex SQL statements. Instead, you can combine SQL statements simply by calling methods in this class, such as **equalTo**, **notEqualTo**, **groupBy**, **orderByAsc**, and **beginsWith**.
-**RawRdbPredicates**: With this class, you can set **whereClause** and **whereArgs**, but cannot call methods such as **equalTo**.
Table 7 APIs for RDB predicates
**Table 3** APIs for RDB store predicates
| Class| API| Description|
| ---- | ---- | ---- |
| RdbPredicates | AbsPredicates *EqualTo(std::string field, std::string value) | Sets the **AbsPredicates** to match the field that is equal to the specified value.|
...
...
@@ -46,6 +46,9 @@ The RDB provides **AbsRdbPredicates** for you to set database operation conditio
| RdbPredicates | AbsPredicates *OrderByAsc(std::string field) | Sets the **AbsPredicates** to match the column with values sorted in ascending order.|
| RdbPredicates | void SetWhereArgs(std::vector\<std::string\> whereArgs) | Sets **whereArgs**, which indicates the value of the placeholder in **whereClause**.|
| RdbPredicates | AbsRdbPredicates *InDevices(std::vector<std::string>& devices) | Sets the **AbsPredicates** to specify the remote devices on the network with databases to be synchronized.|
| RdbPredicates | AbsRdbPredicates *InAllDevices() | Sets the **AbsPredicates** to connect to all remote devices on the network when synchronizing distributed databases.|
### Managing Data in an RDB Store
...
...
@@ -55,29 +58,29 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
The RDB provides an API for inserting data through **ValuesBucket** in a data table. If the data is added, the row number of the data inserted is returned; otherwise, **-1** is returned.
Table 3 API for inserting data to a data table
**Table 4** APIs for inserting data tables
| Class| API| Description|
| ---- | ---- | ---- |
| RdbStore | int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) | Inserts data based on the passed table name and data in **ValuesBucket**. <ul><li>**table**: specifies the name of the target table. </li><li>**initialValues**: specifies the data, stored in **ValuesBucket**, to insert. A series of **put()** methods, such as **PutString(const std::string &columnName, const std::string &value)** and **PutDouble(const std::string &columnName, double value)**, are provided to add data to **ValuesBucket**.</li></ul> |
| RdbStore | int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) | Inserts data based on the passed table name and data in **ValuesBucket**. <br/>- **table**: specifies the name of the target table.<br/> - **initialValues**: specifies the data, stored in **ValuesBucket**, to insert. A series of **put()** methods, such as **PutString(const std::string &columnName, const std::string &value)** and **PutDouble(const std::string &columnName, double value)**, are provided to add data to **ValuesBucket**. |
- Deleting data
Call the **delete()** method to delete data meeting the conditions specified by **AbsRdbPredicates**. If the data is deleted, the row number of the deleted data is returned; otherwise, **0** is returned.
Table 5 API for deleting data
**Table 5** API for deleting data
| Class| API| Description|
| ---- | ---- | ---- |
| RdbStore | int Delete(int &deletedRows, const AbsRdbPredicates &predicates) | Deletes data. <ul><li>**deletedRows**: specifies the number of rows to delete. </li><li>**predicates**: specifies the table name and conditions for deleting the data. **AbsRdbPredicates** has the following classes: <ul><li>**RdbPredicates**: specifies delete conditions by calling its methods, such as **equalTo**. </li><li>**RawRdbPredicates**: specifies the table name, **whereClause** and **whereArgs** only. </li></ul></li></ul> |
| RdbStore | int Delete(int &deletedRows, const AbsRdbPredicates &predicates) | Deletes data. <br/>- **deletedRows**: specifies the number of rows to delete.<br/> - **predicates**: specifies the table name and conditions for deleting the data.<br/>**AbsRdbPredicates** has the following classes:<br/> - **RdbPredicates**: specifies update conditions by calling its methods, such as **equalTo**.<br/> - **RawRdbPredicates**: specifies the table name, **whereClause** and **whereArgs** only. |
- Updating data
Call the **update()** method to modify data based on the passed data and the conditions specified by **AbsRdbPredicates**. If the data is updated, the row number of the updated data is returned; otherwise, **0** is returned.
Table 4 API for updating data
**Table 6** API for updating data
| Class| API| Description|
| ---- | ---- | ---- |
| RdbStore | int Update(int &changedRows, const ValuesBucket &values, const AbsRdbPredicates &predicates) | Updates the data that meets the conditions specified by predicates.<ul><li>**changedRows**: specifies the number of rows to update. </li><li>**values**: specifies the new data stored in **ValuesBucket**. </li><li>**predicates**: specifies the table name and conditions for the update operation. **AbsRdbPredicates** has the following classes: <ul><li>**RdbPredicates**: specifies update conditions by calling its methods, such as **equalTo**. </li><li>**RawRdbPredicates**: specifies the table name, **whereClause** and **whereArgs** only. </li></ul></li></ul> |
| RdbStore | int Update(int &changedRows, const ValuesBucket &values, const AbsRdbPredicates &predicates) | Updates the data that meets the conditions specified by predicates.<br/> - **changedRows**: specifies the number of rows to update.<br/> - **values**: specifies the new data stored in **ValuesBucket**.<br/> - **predicates**: specifies the table name and conditions for the update operation. **AbsRdbPredicates** has the following classes: <br/>- **RdbPredicates**: specifies update conditions by calling its methods, such as **equalTo**.<br/> - **RawRdbPredicates**: specifies the table name, **whereClause** and **whereArgs** only. |
- Querying data
...
...
@@ -86,32 +89,75 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
- Call the **query()** method to query data based on the predicates, without passing any SQL statement.
- Run the native SQL statement.
Table 6 APIs for querying data
**Table 7** APIs for querying data
| Class| API| Description|
| ---- | ---- | ---- |
| RdbStore | std::unique_ptr<AbsSharedResultSet> Query(const AbsRdbPredicates &predicates, const std::vector\<std::string\> columns) | Queries data. <ul><li>**predicates**: specifies the query conditions. **AbsRdbPredicates** has the following classes: <ul><li>**RdbPredicates**: specifies the query conditions by calling its methods, such as **equalTo**. </li><li>**RawRdbPredicates**: specifies the table name, **whereClause**, and **whereArgs** only. </li></ul><li>**columns**: specifies the number of columns returned.</li></ul></li></ul> |
| RdbStore | std::unique_ptr<AbsSharedResultSet> QuerySql(const std::string &sql, const std::vector\<std::string\> &selectionArgs = std::vector\<std::string\>()) | Executes the native SQL statements to query data. <ul><li>**sql**: specifies the native SQL statement. </li><li>**selectionArgs**: specifies the parameter values corresponding to the placeholders in the SQL statements. Set it to **null** if the **select** statement has no placeholder.</li></ul> |
| RdbStore | std::unique_ptr<AbsSharedResultSet> Query(const AbsRdbPredicates &predicates, const std::vector\<std::string\> columns) | Queries data. <br/>- **predicates**: specifies the query conditions. **AbsRdbPredicates** has the following classes: <br/>- **RdbPredicates**: specifies update conditions by calling its methods, such as **equalTo**. <br/>- **RawRdbPredicates**: specifies the table name, **whereClause**, and **whereArgs** only. <br/>- **columns**: specifies the number of columns returned. |
| RdbStore | std::unique_ptr<AbsSharedResultSet> QuerySql(const std::string &sql, const std::vector\<std::string\> &selectionArgs = std::vector\<std::string\>()) | Executes the native SQL statements to query data. <br/>- **sql**: specifies the native SQL statement. <br/>- **selectionArgs**: specifies the parameter values corresponding to the placeholders in the SQL statements. Set it to **null** if the **select** statement has no placeholder. |
### Using the Result Set
A result set can be regarded as rows of data in the queried results. It allows you to traverse and access the data you have queried. The following table describes the external APIs of **ResultSet**.
Table 8 APIs for using the result set
| Class| API| Description|
| ---- | ---- | ---- |
| ResultSet | int GoTo(int offset) | Moves the result set forwards or backwards by the specified offset relative to its current position.|
| ResultSet | int GoToRow(int position) | Moves the result set to the specified row.|
| ResultSet | int GoToNextRow() | Moves the result set to the next row.|
| ResultSet | int GoToPreviousRow() | Moves the result set to the previous row.|
| ResultSet | int IsStarted(bool &result) | Checks whether the result set has been moved.|
| ResultSet | int IsEnded(bool &result) | Checks whether the result set is moved after the last line.|
| ResultSet | int IsAtFirstRow(bool &result) | Checks whether the result set is located in the first row.|
| ResultSet | int IsAtLastRow(bool &result) | Checks whether the result set is located in the last row.|
| ResultSet | int GetRowCount(int &count) | Obtains the number of rows in the result set.|
| ResultSet | int GetColumnCount(int &count) | Obtains the number of columns in the result set.|
| ResultSet | int GetString(int columnIndex, std::string &value) | Obtains the values in the specified column of the current row, in strings.|
| ResultSet | int GetBlob(int columnIndex, std::vector\<uint8_t\> &blob) | Obtains the values in the specified column of the current row, in a byte array.|
| ResultSet | int GetDouble(int columnIndex, double &value) | Obtains the values in the specified column of the current row, in double.|
**Table 8** APIs for using the result set
| Class| API| Description|
| ---- | ---- | ---- |
| ResultSet | int GoTo(int offset) | Moves the result set forwards or backwards by the specified offset relative to its current position.|
| ResultSet | int GoToRow(int position) | Moves the result set to the specified row.|
| ResultSet | int GoToNextRow() | Moves the result set to the next row.|
| ResultSet | int GoToPreviousRow() | Moves the result set to the previous row.|
| ResultSet | int IsStarted(bool &result) | Checks whether the result set has been moved.|
| ResultSet | int IsEnded(bool &result) | Checks whether the result set is moved after the last line.|
| ResultSet | int IsAtFirstRow(bool &result) | Checks whether the result set is located in the first row.|
| ResultSet | int IsAtLastRow(bool &result) | Checks whether the result set is located in the last row.|
| ResultSet | int GetRowCount(int &count) | Obtains the number of rows in the result set.|
| ResultSet | int GetColumnCount(int &count) | Obtains the number of columns in the result set.|
| ResultSet | int GetString(int columnIndex, std::string &value) | Obtains the values in the specified column of the current row, in strings.|
| ResultSet | int GetBlob(int columnIndex, std::vector\<uint8_t\> &blob) | Obtains the values in the specified column of the current row, in a byte array.|
| ResultSet | int GetDouble(int columnIndex, double &value) | Obtains the values in the specified column of the current row, in double.|
### Setting a List of Distributed Tables
You can set a list of distributed tables for data operations across devices.
**Table 9** API for setting a distributed table list
| Class| API| Description|
| ---- | ---- | ---- |
| RdbStore | bool SetDistributedTables(const std::vector<std::string>& tables) | Sets a list of distributed tables.<br/> - **tables**: specifies the names of the distributed tables to set. |
### Obtaining the Distributed Table Name for a Remote Device
When querying the RDB store of a remote device, you need to use the distributed table name. You can obtain the distributed table name of a remote device based on the local table name.
**Table 10** API for obtaining the distributed table name of a remote device
| Class| API| Description|
| ---- | ---- | ---- |
| RdbStore | std::string ObtainDistributedTableName(const std::string& device, const std::string& table) | Obtains the distributed table name of a remote device based on the local table name. The distributed table name can be used to query the RDB store of the remote device.<br> - **device**: specifies the ID of the remote device.<br/> - **table**: specifies the name of the local table. |
### Synchronizing Data Between Devices
**Table 11** API for cross-device data synchronization
| Class| API| Description|
| ---- | ---- | ---- |
| RdbStore | bool Sync(const SyncOption& option, const AbsRdbPredicates& predicate, const SyncCallback& callback) | Synchronizes data between devices.<br/> - **option**: specifies synchronization options, which include the following: <br/>**mode**: specifies how data is synchronized. The value **push** means to push data from the local device to the remote device; the value **pull** means to pull data from the remote device to the local device. <br/>**isBlock**: specifies whether the invocation of this function is blocked. <br/>- **callback**: specifies the callback used to return the result. |
### Registering an RDB Store Observer
**Table 12** API for registering an observer
| Class| API| Description|
| ---- | ---- | ---- |
| RdbStore | bool Subscribe(const SubscribeOption& option, RdbStoreObserver *observer) | Registers an observer for this RDB store to subscribe to distributed data changes. When data in the RDB store changes, a callback will be invoked to return the data changes.<br/> - **option**: specifies the subscription type.<br/>- **observer**: specifies the observer of data changes in the RDB store. |
### Unregistering an RDB Store Observer
**Table 13** API for unregistering an observer
| Class| API| Description|
| ---- | ---- | ---- |
| RdbStore | bool UnSubscribe(const SubscribeOption& option, RdbStoreObserver *observer) | Unregisters the observer of the specified type to unsubscribe from distributed data changes.<br/> - **option**: specifies the subscription type to unregister.<br/>- **observer**: specifies the observer to unregister. |
## Constraints
...
...
@@ -121,7 +167,7 @@ None.
1. Create an RDB store.
a. Configure the RDB store attributes, including the database name, storage mode, and read-only mode.
a. Configure the RDB store attributes, including the RDB store name, storage mode, and read-only mode.
b. Initialize the table structure and related data in the RDB store.
...
...
@@ -155,6 +201,8 @@ None.
b. Call the **insert()** method to insert data into the RDB store.