We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesApplication FrameworkArkDataArkTS APIsAPIs No Longer Maintaineddata/rdbresultSet

resultSet

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

A result set is a set of results returned after the relational database (RDB) query APIs are called. You can use the resultset APIs to obtain required data.

NOTE

The initial APIs of this module are supported since API version 7. New APIs will be marked with a superscript to indicate their earliest API version.

Since API version 9, this API is no longer maintained. You are advised to use ResultSet.

ResultSet

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

Provides methods to access the result set, which is obtained by querying the RDB store.

Usage

You need to obtain a resultSet object by using RdbStore.query().

Collapse
Word wrap
Dark theme
Copy code
  1. import dataRdb from '@ohos.data.rdb';
  2. let predicates = new dataRdb.RdbPredicates("EMPLOYEE");
  3. predicates.equalTo("AGE", 18);
  4. let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
  5. promise.then((resultSet) => {
  6. console.info("resultSet columnNames:" + resultSet.columnNames);
  7. console.info("resultSet columnCount:" + resultSet.columnCount);
  8. resultSet.close();
  9. });

Attributes

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Expand
Name Type Read-Only Optional Description
columnNames Array<string> Yes No Names of all columns in the result set.
columnCount number Yes No Number of columns in the result set.
rowCount number Yes No Number of rows in the result set.
rowIndex number Yes No Index of the current row in the result set.
isAtFirstRow boolean Yes No Whether the cursor is in the first row of the result set.
isAtLastRow boolean Yes No Whether the cursor is in the last row of the result set.
isEnded boolean Yes No Whether the cursor is after the last row of the result set.
isStarted boolean Yes No Whether the cursor has been moved.
isClosed boolean Yes No Whether the result set is closed.

getColumnIndex

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

getColumnIndex(columnName: string): number

Obtains the column index based on the column name.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

Expand
Name Type Mandatory Description
columnName string Yes Column name specified.

Return value

Expand
Type Description
number Index of the column obtained.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. const success = resultSet.goToFirstRow();
  2. if (success) {
  3. const id = resultSet.getLong(resultSet.getColumnIndex("ID"));
  4. const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
  5. const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
  6. const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
  7. }

getColumnName

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

getColumnName(columnIndex: number): string

Obtains the column name based on the column index.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

Expand
Name Type Mandatory Description
columnIndex number Yes Column index specified.

Return value

Expand
Type Description
string Column name obtained.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. const id = resultSet.getColumnName(0);
  2. const name = resultSet.getColumnName(1);
  3. const age = resultSet.getColumnName(2);

goTo

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

goTo(offset:number): boolean

Moves the result set forward or backward to the specified row with an offset relative to the current position.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

Expand
Name Type Mandatory Description
offset number Yes Offset relative to the current position.

Return value

Expand
Type Description
boolean Returns true if the operation is successful; returns false otherwise.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let predicatesgoto = new dataRdb.RdbPredicates("EMPLOYEE");
  2. let promisequerygoto = rdbStore.query(predicatesgoto, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
  3. promisequerygoto.then((resultSet) => {
  4. resultSet.goTo(1);
  5. resultSet.close();
  6. }).catch((err) => {
  7. console.error('query failed');
  8. });

goToRow

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

goToRow(position: number): boolean

Moves the cursor to the specified row in the result set.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

Expand
Name Type Mandatory Description
position number Yes Position to which the cursor is to be moved.

Return value

Expand
Type Description
boolean Returns true if the operation is successful; returns false otherwise.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let predicatesgotorow = new dataRdb.RdbPredicates("EMPLOYEE");
  2. let promisequerygotorow = rdbStore.query(predicatesgotorow, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
  3. promisequerygotorow.then((resultSet) => {
  4. resultSet.goToRow(5);
  5. resultSet.close();
  6. }).catch((err) => {
  7. console.error('query failed');
  8. });

goToFirstRow

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

goToFirstRow(): boolean

Moves the cursor to the first row of the result set.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Return value

Expand
Type Description
boolean true if the result set is successfully moved to the first row; false otherwise.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let predicatesgoFirst = new dataRdb.RdbPredicates("EMPLOYEE");
  2. let promisequerygoFirst = rdbStore.query(predicatesgoFirst, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
  3. promisequerygoFirst.then((resultSet) => {
  4. resultSet.goToFirstRow();
  5. resultSet.close();
  6. }).catch((err) => {
  7. console.error('query failed');
  8. });

goToLastRow

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

goToLastRow(): boolean

Moves the cursor to the last row of the result set.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Return value

Expand
Type Description
boolean true if the result set is successfully moved to the last row; false otherwise.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let predicatesgoLast = new dataRdb.RdbPredicates("EMPLOYEE");
  2. let promisequerygoLast = rdbStore.query(predicatesgoLast, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
  3. promisequerygoLast.then((resultSet) => {
  4. resultSet.goToLastRow();
  5. resultSet.close();
  6. }).catch((err) => {
  7. console.error('query failed');
  8. });

goToNextRow

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

goToNextRow(): boolean

Moves the cursor to the next row in the result set.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Return value

Expand
Type Description
boolean true if the resultSet is successfully moved to the next row; false otherwise.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let predicatesgoNext = new dataRdb.RdbPredicates("EMPLOYEE");
  2. let promisequerygoNext = rdbStore.query(predicatesgoNext, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
  3. promisequerygoNext.then((resultSet) => {
  4. resultSet.goToNextRow();
  5. resultSet.close();
  6. }).catch((err) => {
  7. console.error('query failed');
  8. });

goToPreviousRow

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

goToPreviousRow(): boolean

Moves the cursor to the previous row in the result set.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Return value

Expand
Type Description
boolean true if the result set is successfully moved to the previous row; false otherwise.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let predicatesgoPrev = new dataRdb.RdbPredicates("EMPLOYEE");
  2. let promisequerygoPrev = rdbStore.query(predicatesgoPrev, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
  3. promisequerygoPrev.then((resultSet) => {
  4. resultSet.goToPreviousRow();
  5. resultSet.close();
  6. }).catch((err) => {
  7. console.error('query failed');
  8. });

getBlob

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

getBlob(columnIndex: number): Uint8Array

Obtains the value from the specified column in the current row as a byte array.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

Expand
Name Type Mandatory Description
columnIndex number Yes Index of the specified column, starting from 0.

Return value

Expand
Type Description
Uint8Array Value in the specified column as a byte array.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. const codes = resultSet.getBlob(resultSet.getColumnIndex("CODES"));

getString

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

getString(columnIndex: number): string

Obtains the value from the specified column in the current row as a string.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

Expand
Name Type Mandatory Description
columnIndex number Yes Index of the specified column, starting from 0.

Return value

Expand
Type Description
string Value in the specified column as a string.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. const name = resultSet.getString(resultSet.getColumnIndex("NAME"));

getLong

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

getLong(columnIndex: number): number

Obtains the value from the specified column in the current row as a Long.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

Expand
Name Type Mandatory Description
columnIndex number Yes Index of the specified column, starting from 0.

Return value

Expand
Type Description
number

Value in the specified column as a Long.

The value range supported by this API is Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER. If the value is out of this range, use getDouble.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));

getDouble

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

getDouble(columnIndex: number): number

Obtains the value from the specified column in the current row as a Double.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

Expand
Name Type Mandatory Description
columnIndex number Yes Index of the specified column, starting from 0.

Return value

Expand
Type Description
number Value in the specified column as a Double.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));

isColumnNull

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

isColumnNull(columnIndex: number): boolean

Checks whether the value in the specified column of the current row is null.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

Expand
Name Type Mandatory Description
columnIndex number Yes Index of the specified column, starting from 0.

Return value

Expand
Type Description
boolean Returns true if the value is null; returns false otherwise.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. const isColumnNull = resultSet.isColumnNull(resultSet.getColumnIndex("CODES"));

close

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

close(): void

Closes this result set.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Example

Collapse
Word wrap
Dark theme
Copy code
  1. let predicatesClose = new dataRdb.RdbPredicates("EMPLOYEE");
  2. let promiseClose = rdbStore.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
  3. promiseClose.then((resultSet) => {
  4. resultSet.close();
  5. }).catch((err) => {
  6. console.error('resultset close failed');
  7. });