未验证 提交 914afc1a 编写于 作者: O openharmony_ci 提交者: Gitee

!10663 [翻译完成】#I5SMRP (仅涉及代码修改)

Merge pull request !10663 from Annie_wang/PR9815
...@@ -6,26 +6,25 @@ A result set is a set of results returned after the relational database (RDB) qu ...@@ -6,26 +6,25 @@ A result set is a set of results returned after the relational database (RDB) qu
> >
> 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. > 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.
## Usage ## Usage
You need to use [RdbStore.query()](js-apis-data-rdb.md#query) to obtain a **resultSet** object. You need to use [RdbStore.query()](js-apis-data-rdb.md#query) to obtain a **resultSet** object.
```js ```js
import dataRdb from '@ohos.data.rdb'; import dataRdb from '@ohos.data.rdb';
let predicates = new dataRdb.RdbPredicates("EMPLOYEE") let predicates = new dataRdb.RdbPredicates("EMPLOYEE");
predicates.equalTo("AGE", 18) predicates.equalTo("AGE", 18);
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
console.log(TAG + "resultSet columnNames:" + resultSet.columnNames); console.log(TAG + "resultSet columnNames:" + resultSet.columnNames);
console.log(TAG + "resultSet columnCount:" + resultSet.columnCount);}) console.log(TAG + "resultSet columnCount:" + resultSet.columnCount);
});
``` ```
## ResultSet ## ResultSet
Provides methods to access the result set, which is obtained by querying the RDB store. Provides methods to access the result set, which is obtained by querying the RDB store.
### Attributes ### Attributes
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -42,7 +41,6 @@ Provides methods to access the result set, which is obtained by querying the RDB ...@@ -42,7 +41,6 @@ Provides methods to access the result set, which is obtained by querying the RDB
| isStarted | boolean | Yes| Whether the cursor has been moved.| | isStarted | boolean | Yes| Whether the cursor has been moved.|
| isClosed | boolean | Yes| Whether the result set is closed.| | isClosed | boolean | Yes| Whether the result set is closed.|
### getColumnIndex ### getColumnIndex
getColumnIndex(columnName: string): number getColumnIndex(columnName: string): number
...@@ -52,25 +50,27 @@ Obtains the column index based on the column name. ...@@ -52,25 +50,27 @@ Obtains the column index based on the column name.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| columnName | string | Yes| Column name specified.| | columnName | string | Yes| Column name specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Index of the column obtained.| | number | Index of the column obtained.|
**Example** **Example**
```js ```js
resultSet.goToFirstRow() resultSet.goToFirstRow();
const id = resultSet.getLong(resultSet.getColumnIndex("ID")) const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
const name = resultSet.getString(resultSet.getColumnIndex("NAME")) const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
const age = resultSet.getLong(resultSet.getColumnIndex("AGE")) const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")) const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
``` ```
### getColumnName ### getColumnName
getColumnName(columnIndex: number): string getColumnName(columnIndex: number): string
...@@ -80,23 +80,25 @@ Obtains the column name based on the column index. ...@@ -80,23 +80,25 @@ Obtains the column name based on the column index.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Column index specified.| | columnIndex | number | Yes| Column index specified.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Column name obtained.| | string | Column name obtained.|
**Example** **Example**
```js ```js
const id = resultSet.getColumnName(0) const id = resultSet.getColumnName(0);
const name = resultSet.getColumnName(1) const name = resultSet.getColumnName(1);
const age = resultSet.getColumnName(2) const age = resultSet.getColumnName(2);
``` ```
### goTo ### goTo
goTo(offset:number): boolean goTo(offset:number): boolean
...@@ -106,28 +108,30 @@ Moves the cursor to the row based on the specified offset. ...@@ -106,28 +108,30 @@ Moves the cursor to the row based on the specified offset.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| offset | number | Yes| Offset relative to the current position.| | offset | number | Yes| Offset relative to the current position.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example** **Example**
```js ```js
let predicatesgoto = new dataRdb.RdbPredicates("EMPLOYEE") let predicatesgoto = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygoto = rdbStore.query(predicatesgoto, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promisequerygoto = rdbStore.query(predicatesgoto, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoto.then((resultSet) { promisequerygoto.then((resultSet) {
resultSet.goTo(1) resultSet.goTo(1);
resultSet.close() resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed') console.log('query failed');
}) });
``` ```
### goToRow ### goToRow
goToRow(position: number): boolean goToRow(position: number): boolean
...@@ -137,28 +141,30 @@ Moves the cursor to the specified row in the result set. ...@@ -137,28 +141,30 @@ Moves the cursor to the specified row in the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| position | number | Yes| Position to which the cursor is to be moved.| | position | number | Yes| Position to which the cursor is to be moved.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example** **Example**
```js ```js
let predicatesgotorow = new dataRdb.RdbPredicates("EMPLOYEE") let predicatesgotorow = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygotorow = rdbStore.query(predicatesgotorow, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promisequerygotorow = rdbStore.query(predicatesgotorow, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygotorow.then((resultSet) { promisequerygotorow.then((resultSet) {
resultSet.goToRow(5) resultSet.goToRow(5);
resultSet.close() resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed') console.log('query failed');
}) });
``` ```
### goToFirstRow ### goToFirstRow
goToFirstRow(): boolean goToFirstRow(): boolean
...@@ -169,23 +175,24 @@ Moves the cursor to the first row of the result set. ...@@ -169,23 +175,24 @@ Moves the cursor to the first row of the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example** **Example**
```js ```js
let predicatesgoFirst = new dataRdb.RdbPredicates("EMPLOYEE") let predicatesgoFirst = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygoFirst = rdbStore.query(predicatesgoFirst, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promisequerygoFirst = rdbStore.query(predicatesgoFirst, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoFirst.then((resultSet) { promisequerygoFirst.then((resultSet) {
resultSet.goToFirstRow() resultSet.goToFirstRow();
resultSet.close() resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed') console.log('query failed');
}) });
``` ```
### goToLastRow ### goToLastRow
goToLastRow(): boolean goToLastRow(): boolean
...@@ -195,23 +202,24 @@ Moves the cursor to the last row of the result set. ...@@ -195,23 +202,24 @@ Moves the cursor to the last row of the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example** **Example**
```js ```js
let predicatesgoLast = new dataRdb.RdbPredicates("EMPLOYEE") let predicatesgoLast = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygoLast = rdbStore.query(predicatesgoLast, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promisequerygoLast = rdbStore.query(predicatesgoLast, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoLast.then((resultSet) { promisequerygoLast.then((resultSet) {
resultSet.goToLastRow() resultSet.goToLastRow();
resultSet.close() resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed') console.log('query failed');
}) });
``` ```
### goToNextRow ### goToNextRow
goToNextRow(): boolean goToNextRow(): boolean
...@@ -221,23 +229,24 @@ Moves the cursor to the next row in the result set. ...@@ -221,23 +229,24 @@ Moves the cursor to the next row in the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example** **Example**
```js ```js
let predicatesgoNext = new dataRdb.RdbPredicates("EMPLOYEE") let predicatesgoNext = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygoNext = rdbStore.query(predicatesgoNext, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promisequerygoNext = rdbStore.query(predicatesgoNext, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoNext.then((resultSet) { promisequerygoNext.then((resultSet) {
resultSet.goToNextRow() resultSet.goToNextRow();
resultSet.close() resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed') console.log('query failed');
}) });
``` ```
### goToPreviousRow ### goToPreviousRow
goToPreviousRow(): boolean goToPreviousRow(): boolean
...@@ -247,23 +256,24 @@ Moves the cursor to the previous row in the result set. ...@@ -247,23 +256,24 @@ Moves the cursor to the previous row in the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example** **Example**
```js ```js
let predicatesgoPrev = new dataRdb.RdbPredicates("EMPLOYEE") let predicatesgoPrev = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygoPrev = rdbStore.query(predicatesgoPrev, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promisequerygoPrev = rdbStore.query(predicatesgoPrev, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoPrev.then((resultSet) { promisequerygoPrev.then((resultSet) {
resultSet.goToPreviousRow() resultSet.goToPreviousRow();
resultSet.close() resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('query failed') console.log('query failed');
}) });
``` ```
### getBlob ### getBlob
getBlob(columnIndex: number): Uint8Array getBlob(columnIndex: number): Uint8Array
...@@ -273,21 +283,23 @@ Obtains the value in the specified column in the current row as a byte array. ...@@ -273,21 +283,23 @@ Obtains the value in the specified column in the current row as a byte array.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.| | columnIndex | number | Yes| Index of the specified column, starting from 0.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Uint8Array | Value in the specified column as a byte array.| | Uint8Array | Value in the specified column as a byte array.|
**Example** **Example**
```js ```js
const codes = resultSet.getBlob(resultSet.getColumnIndex("CODES")) const codes = resultSet.getBlob(resultSet.getColumnIndex("CODES"));
``` ```
### getString ### getString
getString(columnIndex: number): string getString(columnIndex: number): string
...@@ -297,21 +309,23 @@ Obtains the value in the specified column in the current row as a string. ...@@ -297,21 +309,23 @@ Obtains the value in the specified column in the current row as a string.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.| | columnIndex | number | Yes| Index of the specified column, starting from 0.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Value in the specified column as a string.| | string | Value in the specified column as a string.|
**Example** **Example**
```js ```js
const name = resultSet.getString(resultSet.getColumnIndex("NAME")) const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
``` ```
### getLong ### getLong
getLong(columnIndex: number): number getLong(columnIndex: number): number
...@@ -321,21 +335,23 @@ Obtains the value in the specified column in the current row as a Long. ...@@ -321,21 +335,23 @@ Obtains the value in the specified column in the current row as a Long.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.| | columnIndex | number | Yes| Index of the specified column, starting from 0.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Value in the specified column as a Long.| | number | Value in the specified column as a Long.|
**Example** **Example**
```js ```js
const age = resultSet.getLong(resultSet.getColumnIndex("AGE")) const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
``` ```
### getDouble ### getDouble
getDouble(columnIndex: number): number getDouble(columnIndex: number): number
...@@ -345,21 +361,23 @@ Obtains the value in the specified column in the current row as a double. ...@@ -345,21 +361,23 @@ Obtains the value in the specified column in the current row as a double.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.| | columnIndex | number | Yes| Index of the specified column, starting from 0.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Value in the specified column as a double.| | number | Value in the specified column as a double.|
**Example** **Example**
```js ```js
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")) const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
``` ```
### isColumnNull ### isColumnNull
isColumnNull(columnIndex: number): boolean isColumnNull(columnIndex: number): boolean
...@@ -369,21 +387,23 @@ Checks whether the value in the specified column of the current row is null. ...@@ -369,21 +387,23 @@ Checks whether the value in the specified column of the current row is null.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.| | columnIndex | number | Yes| Index of the specified column, starting from 0.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the value is null; returns **false** otherwise.| | boolean | Returns **true** if the value is null; returns **false** otherwise.|
**Example** **Example**
```js ```js
const isColumnNull = resultSet.isColumnNull(resultSet.getColumnIndex("CODES")) const isColumnNull = resultSet.isColumnNull(resultSet.getColumnIndex("CODES"));
``` ```
### close ### close
close(): void close(): void
...@@ -393,12 +413,13 @@ Closes this result set. ...@@ -393,12 +413,13 @@ Closes this result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Example** **Example**
```js ```js
let predicatesClose = new dataRdb.RdbPredicates("EMPLOYEE") let predicatesClose = new dataRdb.RdbPredicates("EMPLOYEE");
let promiseClose = rdbStore.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promiseClose = rdbStore.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promiseClose.then((resultSet) { promiseClose.then((resultSet) {
resultSet.close() resultSet.close();
}).catch((err) => { }).catch((err) => {
console.log('Failed to close resultset') console.log('Failed to close resultset');
}) });
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册