# Result Set
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>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.
## System Capabilities
SystemCapability.DistributedDataManager.RelationalStore.Core
## Usage
The **resultSet** object is obtained by using [**RdbStore.query\(\)**](js-apis-data-rdb.md#section6231155031814).
```
import dataRdb from '@ohos.data.rdb';
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("AGE", 18)
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
promise.then((resultSet) => {
console.log("resultSet columnNames:" + resultSet.columnNames);
console.log("resultSet columnCount:" + resultSet.columnCount);
```
## Required Permissions
None
## ResultSet
Provides methods to access the result set, which is obtained by querying the relational database \(RDB\) store.
### Attributes
Name
|
Type
|
Mandatory
|
Description
|
columnNames
|
Array<string>
|
Yes
|
Names of all columns in the result set.
|
columnCount
|
number
|
Yes
|
Number of columns in the result set.
|
rowCount
|
number
|
Yes
|
Number of rows in the result set.
|
rowIndex
|
number
|
Yes
|
Index of the current row in the result set.
|
isAtFirstRow
|
boolean
|
Yes
|
Specifies whether the cursor is in the first row of the result set.
|
isAtLastRow
|
boolean
|
Yes
|
Whether the cursor is in the last row of the result set.
|
isEnded
|
boolean
|
Yes
|
Whether the cursor is after the last row of the result set.
|
isStarted
|
boolean
|
Yes
|
Whether the cursor has been moved.
|
isClosed
|
boolean
|
Yes
|
Whether the result set is closed.
|
### getColumnIndex
getColumnIndex\(columnName: string\): number
Obtains the column index based on the specified column name.
- Parameters
Name
|
Type
|
Mandatory
|
Description
|
columnName
|
string
|
Yes
|
Name of the column.
|
- Return values
Type
|
Description
|
number
|
Index of the column.
|
- Example
```
resultSet.goToFirstRow()
const id = resultSet.getLong(resultSet.getColumnIndex("ID"))
const name = resultSet.getString(resultSet.getColumnIndex("NAME"))
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"))
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"))
```
### getColumnName
getColumnName\(columnIndex: number\): string
Obtains the column name based on the specified column index.
- Parameters
Name
|
Type
|
Mandatory
|
Description
|
columnIndex
|
number
|
Yes
|
Index of the column.
|
- Return values
Type
|
Description
|
string
|
Name of the column.
|
- Example
```
const id = resultSet.getColumnName(0)
const name = resultSet.getColumnName(1)
const age = resultSet.getColumnName(2)
```
### goTo
goTo\(offset:number\): boolean
Moves the cursor to the row based on the specified offset.
- Parameters
Name
|
Type
|
Mandatory
|
Description
|
offset
|
number
|
Yes
|
Offset relative to the current position.
|
- Return values
Type
|
Description
|
boolean
|
Returns true if the operation is successful; returns false otherwise.
|
- Example
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goTo(1);
resultSet.close();
resultSet = null;
})
```
### goToRow
goToRow\(position: number\): boolean
Moves the cursor to the specified row in the result set.
- Parameters
Name
|
Type
|
Mandatory
|
Description
|
position
|
number
|
Yes
|
Position to which the cursor is to be moved.
|
- Return values
Type
|
Description
|
boolean
|
Returns true if the operation is successful; returns false otherwise.
|
- Example
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToRow(1);
resultSet.close();
resultSet = null
})
```
### goToFirstRow
goToFirstRow\(\): boolean
Moves the cursor to the first row of the result set.
- Return values
Type
|
Description
|
boolean
|
Returns true if the operation is successful; returns false otherwise.
|
- Example
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToFirstRow();
resultSet.close();
resultSet = null;
})
```
### goToLastRow
goToLastRow\(\): boolean
Moves the cursor to the last row of the result set.
- Return values
Type
|
Description
|
boolean
|
Returns true if the operation is successful; returns false otherwise.
|
- Example
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToLastRow();
resultSet.close();
resultSet = null;
})
```
### goToNextRow
goToNextRow\(\): boolean
Moves the cursor to the next row in the result set.
- Return values
Type
|
Description
|
boolean
|
Returns true if the operation is successful; returns false otherwise.
|
- Example
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToNextRow()
resultSet.close()
resultSet = null;
})
```
### goToPreviousRow
goToPreviousRow\(\): boolean
Moves the cursor to the previous row in the result set.
- Return values
Type
|
Description
|
boolean
|
Returns true if the operation is successful; returns false otherwise.
|
- Example
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToPreviousRow();
resultSet.close();
resultSet = null
})
```
### getBlob
getBlob\(columnIndex: number\): Uint8Array
Obtains the value in the specified column in the current row as a byte array.
- Parameters
Name
|
Type
|
Mandatory
|
Description
|
columnIndex
|
number
|
Yes
|
Index of the specified column, starting from 0.
|
- Return values
Type
|
Description
|
Uint8Array
|
Value in the specified column as a byte array.
|
- Example
```
const codes = resultSet.getBlob(resultSet.getColumnIndex("CODES"))
```
### getString
getString\(columnIndex: number\): string
Obtains the value in the specified column in the current row as a string.
- Parameters
Name
|
Type
|
Mandatory
|
Description
|
columnIndex
|
number
|
Yes
|
Index of the specified column, starting from 0.
|
- Return values
Type
|
Description
|
string
|
Value in the specified column as a string.
|
- Example
```
const name = resultSet.getString(resultSet.getColumnIndex("NAME"))
```
### getLong
getLong\(columnIndex: number\): number
Obtains the value in the specified column in the current row as a **Long**.
- Parameters
Name
|
Type
|
Mandatory
|
Description
|
columnIndex
|
number
|
Yes
|
Index of the specified column, starting from 0.
|
- Return values
Type
|
Description
|
number
|
Value in the specified column as a Long.
|
- Example
```
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"))
```
### getDouble
getDouble\(columnIndex: number\): number
Obtains the value in the specified column in the current row as a **double**.
- Parameters
Name
|
Type
|
Mandatory
|
Description
|
columnIndex
|
number
|
Yes
|
Index of the specified column, starting from 0.
|
- Return values
Type
|
Description
|
number
|
Value in the specified column as a double.
|
- Example
```
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"))
```
### isColumnNull
isColumnNull\(columnIndex: number\): boolean
Checks whether the value in the specified column in the current row is **null**.
- Parameters
Name
|
Type
|
Mandatory
|
Description
|
columnIndex
|
number
|
Yes
|
Index of the specified column, starting from 0.
|
- Return values
Type
|
Description
|
boolean
|
Returns true if the value is null; returns false otherwise.
|
- Example
```
const isColumnNull = resultSet.isColumnNull(resultSet.getColumnIndex("CODES"))
```
### close
close\(\): void
Closes the result set.
- Example
```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.close();
resultSet = null
})
```