未验证 提交 2433310d 编写于 作者: O openharmony_ci 提交者: Gitee

!11914 [翻译完成】#I5ZV59

Merge pull request !11914 from Annie_wang/PR11268
......@@ -22,8 +22,8 @@ import data_preferences from '@ohos.data.preferences';
| Name | Type| Readable| Writable| Description |
| ---------------- | -------- | ---- | ---- | --------------------------------------- |
| MAX_KEY_LENGTH | string | Yes | No | Maximum length of a key. The key must be less than 80 bytes. |
| MAX_VALUE_LENGTH | string | Yes | No | Maximum length of a value. The value must be less than 8192 bytes.|
| MAX_KEY_LENGTH | number | Yes | No | Maximum length of a key. The key must be less than 80 bytes. |
| MAX_VALUE_LENGTH | number | Yes | No | Maximum length of a value. The value must be less than 8192 bytes.|
## data_preferences.getPreferences
......@@ -50,16 +50,19 @@ FA model:
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let preferences = null;
data_preferences.getPreferences(context, 'mystore', function (err, object) {
try {
data_preferences.getPreferences(context, 'mystore', function (err, val) {
if (err) {
console.info("Failed to get the preferences. Cause: " + err);
console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
return;
}
preferences = object;
console.info("Got the preferences successfully.");
})
})
} catch (err) {
console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
```
Stage model:
......@@ -75,14 +78,17 @@ class MainAbility extends Ability{
}
let preferences = null;
data_preferences.getPreferences(context, 'mystore', function (err, object) {
try {
data_preferences.getPreferences(context, 'mystore', function (err, val) {
if (err) {
console.info("Failed to get the preferences. Cause: " + err);
console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
return;
}
preferences = object;
console.info("Got the preferences successfully.");
})
})
} catch (err) {
console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
```
## data_preferences.getPreferences
......@@ -116,13 +122,17 @@ import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let preferences = null;
let promise = data_preferences.getPreferences(context, 'mystore');
promise.then((object) => {
try {
let promise = data_preferences.getPreferences(context, 'mystore');
promise.then((object) => {
preferences = object;
console.info("Got the preferences successfully.");
}).catch((err) => {
console.info("Failed to get the preferences. Cause: " + err);
})
}).catch((err) => {
console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
```
Stage model:
......@@ -138,13 +148,17 @@ class MainAbility extends Ability{
}
let preferences = null;
let promise = data_preferences.getPreferences(context, 'mystore');
promise.then((object) => {
try {
let promise = data_preferences.getPreferences(context, 'mystore');
promise.then((object) => {
preferences = object;
console.info("Got the preferences successfully.");
}).catch((err) => {
console.info("Failed to get the preferences. Cause: " + err);
})
}).catch((err) => {
console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
```
## data_preferences.deletePreferences
......@@ -167,6 +181,14 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
| name | string | Yes | Name of the **Preferences** instance to delete. |
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
**Error codes**
For details about the following error codes, see [Preference Error Codes](../errorcodes/errorcode-preferences.md).
| ID| Error Message |
| -------- | ------------------------------|
| 15500010 | Failed to delete the preferences. |
**Example**
FA model:
......@@ -176,13 +198,17 @@ FA model:
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
data_preferences.deletePreferences(context, 'mystore', function (err) {
try {
data_preferences.deletePreferences(context, 'mystore', function (err, val) {
if (err) {
console.info("Failed to delete the preferences. Cause: " + err);
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Deleted the preferences successfully." );
})
})
} catch (err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
```
Stage model:
......@@ -197,13 +223,17 @@ class MainAbility extends Ability{
}
}
data_preferences.deletePreferences(context, 'mystore', function (err) {
try {
data_preferences.deletePreferences(context, 'mystore', function (err, val) {
if (err) {
console.info("Failed to delete the preferences. Cause: " + err);
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Deleted the preferences successfully." );
})
})
} catch (err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
```
## data_preferences.deletePreferences
......@@ -231,6 +261,14 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
| ------------------- | ------------------------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the following error codes, see [Preference Error Codes](../errorcodes/errorcode-preferences.md).
| ID| Error Message |
| -------- | ------------------------------|
| 15500010 | Failed to delete the preferences. |
**Example**
FA model:
......@@ -240,12 +278,16 @@ FA model:
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let promise = data_preferences.deletePreferences(context, 'mystore');
promise.then(() => {
try {
let promise = data_preferences.deletePreferences(context, 'mystore');
promise.then(() => {
console.info("Deleted the preferences successfully.");
}).catch((err) => {
console.info("Failed to delete the preferences. Cause: " + err);
})
}).catch((err) => {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
```
Stage model:
......@@ -260,12 +302,16 @@ class MainAbility extends Ability{
}
}
let promise = data_preferences.deletePreferences(context, 'mystore');
promise.then(() => {
try{
let promise = data_preferences.deletePreferences(context, 'mystore');
promise.then(() => {
console.info("Deleted the preferences successfully.");
}).catch((err) => {
console.info("Failed to delete the preferences. Cause: " + err);
})
}).catch((err) => {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
```
## data_preferences.removePreferencesFromCache
......@@ -295,13 +341,17 @@ FA model:
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
data_preferences.removePreferencesFromCache(context, 'mystore', function (err) {
try {
data_preferences.removePreferencesFromCache(context, 'mystore', function (err, val) {
if (err) {
console.info("Failed to remove the preferences. Cause: " + err);
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Removed the preferences successfully.");
})
})
} catch (err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}
```
Stage model:
......@@ -316,13 +366,18 @@ class MainAbility extends Ability{
}
}
data_preferences.removePreferencesFromCache(context, 'mystore', function (err) {
try {
data_preferences.removePreferencesFromCache(context, 'mystore', function (err, val) {
if (err) {
console.info("Failed to remove the preferences. Cause: " + err);
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Removed the preferences successfully.");
})
})
} catch (err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}
```
## data_preferences.removePreferencesFromCache
......@@ -357,12 +412,16 @@ FA model:
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
promise.then(() => {
try {
let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
promise.then(() => {
console.info("Removed the preferences successfully.");
}).catch((err) => {
console.info("Failed to remove the preferences. Cause: " + err);
})
}).catch((err) => {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}
```
Stage model:
......@@ -377,12 +436,16 @@ class MainAbility extends Ability{
}
}
let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
promise.then(() => {
try {
let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
promise.then(() => {
console.info("Removed the preferences successfully.");
}).catch((err) => {
console.info("Failed to remove the preferences. Cause: " + err);
})
}).catch((err) => {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}
```
## Preferences
......@@ -411,13 +474,17 @@ Obtains the value of a key. This API uses an asynchronous callback to return the
**Example**
```js
preferences.get('startup', 'default', function(err, data) {
try {
preferences.get('startup', 'default', function (err, val) {
if (err) {
console.info("Failed to get the value of 'startup'. Cause: " + err);
console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Got the value of 'startup'. Data: " + data);
})
console.info("Obtained the value of 'startup' successfully. val: " + val);
})
} catch (err) {
console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message);
}
```
......@@ -445,12 +512,16 @@ Obtains the value of a key. This API uses a promise to return the result. If the
**Example**
```js
let promise = preferences.get('startup', 'default');
promise.then((data) => {
try {
let promise = preferences.get('startup', 'default');
promise.then((data) => {
console.info("Got the value of 'startup'. Data: " + data);
}).catch((err) => {
console.info("Failed to get the value of 'startup'. Cause: " + err);
})
}).catch((err) => {
console.info("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message);
}
```
### getAll
......@@ -470,15 +541,19 @@ Obtains an **Object** instance that contains all KV pairs. This API uses an asyn
**Example**
```js
preferences.getAll(function (err, value) {
try {
preferences.getAll(function (err, value) {
if (err) {
console.info("Failed to get all KV pairs. Cause: " + err);
console.info("Failed to get all KV pairs. code =" + err.code + ", message =" + err.message);
return;
}
let allKeys = Object.keys(value);
console.info("getAll keys = " + allKeys);
console.info("getAll object = " + JSON.stringify(value));
});
})
} catch (err) {
console.info("Failed to get all KV pairs. code =" + err.code + ", message =" + err.message);
}
```
......@@ -499,14 +574,18 @@ Obtains an **Object** instance that contains all KV pairs. This API uses a promi
**Example**
```js
let promise = preferences.getAll();
promise.then((value) => {
try {
let promise = preferences.getAll();
promise.then((value) => {
let allKeys = Object.keys(value);
console.info('getAll keys = ' + allKeys);
console.info("getAll object = " + JSON.stringify(value));
}).catch((err) => {
console.info("Failed to get all KV pairs. Cause: " + err);
})
}).catch((err) => {
console.info("Failed to get all KV pairs. code =" + err.code + ", message =" + err.message);
})
} catch (err) {
console.info("Failed to get all KV pairs. code =" + err.code + ", message =" + err.message);
}
```
### put
......@@ -528,13 +607,17 @@ Writes data to this **Preferences** instance. This API uses an asynchronous call
**Example**
```js
preferences.put('startup', 'auto', function (err) {
try {
preferences.put('startup', 'auto', function (err) {
if (err) {
console.info("Failed to put the value of 'startup'. Cause: " + err);
console.info("Failed to put the value of 'startup'. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Put the value of 'startup' successfully.");
})
})
} catch (err) {
console.info("Failed to put the value of 'startup'. code =" + err.code + ", message =" + err.message);
}
```
......@@ -562,12 +645,16 @@ Writes data to this **Preferences** instance. This API uses a promise to return
**Example**
```js
let promise = preferences.put('startup', 'auto');
promise.then(() => {
try {
let promise = preferences.put('startup', 'auto');
promise.then(() => {
console.info("Put the value of 'startup' successfully.");
}).catch((err) => {
console.info("Failed to put the value of 'startup'. Cause: " + err);
})
}).catch((err) => {
console.info("Failed to put the value of 'startup'. code =" + err.code +", message =" + err.message);
})
} catch(err) {
console.info("Failed to put the value of 'startup'. code =" + err.code +", message =" + err.message);
}
```
......@@ -589,17 +676,21 @@ Checks whether this **Preferences** instance contains a KV pair with the given k
**Example**
```js
preferences.has('startup', function (err, isExist) {
try {
preferences.has('startup', function (err, val) {
if (err) {
console.info("Failed to check the key 'startup'. Cause: " + err);
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
return;
}
if (isExist) {
if (val) {
console.info("The key 'startup' is contained.");
} else {
console.info("The key 'startup' is not contained.");
}
})
})
} catch (err) {
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
}
```
......@@ -626,16 +717,20 @@ Checks whether this **Preferences** instance contains a KV pair with the given k
**Example**
```js
let promise = preferences.has('startup');
promise.then((isExist) => {
if (isExist) {
try {
let promise = preferences.has('startup');
promise.then((val) => {
if (val) {
console.info("The key 'startup' is contained.");
} else {
console.info("The key 'startup' is not contained.");
}
}).catch((err) => {
console.info("Failed to check the key 'startup'. Cause: " + err);
})
}).catch((err) => {
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
}
```
......@@ -643,7 +738,7 @@ promise.then((isExist) => {
delete(key: string, callback: AsyncCallback<void>): void
Deletes a KV pair from this **Preferences** instance. This API uses an asynchronous callback to return the result.
Deletes a KV pair from this **Preferences** instance based on the specified key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......@@ -657,13 +752,17 @@ Deletes a KV pair from this **Preferences** instance. This API uses an asynchron
**Example**
```js
preferences.delete('startup', function (err) {
try {
preferences.delete('startup', function (err) {
if (err) {
console.info("Failed to delete the key 'startup'. Cause: " + err);
console.info("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Deleted the key 'startup'.");
})
})
} catch (err) {
console.info("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message);
}
```
......@@ -690,12 +789,16 @@ Deletes a KV pair from this **Preferences** instance. This API uses a promise to
**Example**
```js
let promise = preferences.delete('startup');
promise.then(() => {
try {
let promise = preferences.delete('startup');
promise.then(() => {
console.info("Deleted the key 'startup'.");
}).catch((err) => {
console.info("Failed to delete the key 'startup'. Cause: " + err);
})
}).catch((err) => {
console.log("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
})
} catch(err) {
console.log("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
}
```
......@@ -716,13 +819,17 @@ Saves the data of this **Preferences** instance to a file asynchronously. This A
**Example**
```js
preferences.flush(function (err) {
try {
preferences.flush(function (err) {
if (err) {
console.info("Failed to flush data. Cause: " + err);
console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Flushed data successfully.");
})
})
} catch (err) {
console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
}
```
......@@ -743,12 +850,16 @@ Saves the data of this **Preferences** instance to a file asynchronously. This A
**Example**
```js
let promise = preferences.flush();
promise.then(() => {
console.info("Flushed data to file successfully.")
}).catch((err) => {
console.info("Failed to flush data. Cause: " + err);
})
try {
let promise = preferences.flush();
promise.then(() => {
console.info("Flushed data successfully.");
}).catch((err) => {
console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
})
} catch (err) {
console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
}
```
......@@ -769,13 +880,17 @@ Clears this **Preferences** instance. This API uses an asynchronous callback to
**Example**
```js
preferences.clear(function (err) {
try {
preferences.clear(function (err) {
if (err) {
console.info("Failed to clear data. Cause: " + err);
console.info("Failed to clear data. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Cleared data successfully.");
})
})
} catch (err) {
console.info("Failed to clear data. code =" + err.code + ", message =" + err.message);
}
```
......@@ -796,12 +911,16 @@ Clears this **Preferences** instance. This API uses a promise to return the resu
**Example**
```js
let promise = preferences.clear()
promise.then(() => {
try {
let promise = preferences.clear();
promise.then(() => {
console.info("Cleared data successfully.");
}).catch((err) => {
console.info("Failed to clear data. Cause: " + err);
})
}).catch((err) => {
console.info("Failed to clear data. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
console.info("Failed to clear data. code =" + err.code + ", message =" + err.message);
}
```
......@@ -823,7 +942,8 @@ Subscribes to data changes. A callback will be triggered to return the new value
**Example**
```js
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
try {
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
if (err) {
console.info("Failed to get the preferences.");
return;
......@@ -844,10 +964,13 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, preferen
console.info("Failed to flush data. Cause: " + err);
return;
}
console.info("Flushed data successfully."); // The observer will be called.
console.info("Flushed data successfully.");
})
})
})
})
} catch (err) {
console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
}
```
......@@ -869,7 +992,8 @@ Unsubscribes from data changes.
**Example**
```js
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
try {
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
if (err) {
console.info("Failed to get the preferences.");
return;
......@@ -890,11 +1014,14 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, preferen
console.info("Failed to flush data. Cause: " + err);
return;
}
console.info("Flushed data successfully."); // The observer will be called.
console.info("Flushed data successfully.");
})
preferences.off('change', observer);
})
})
})
} catch (err) {
console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
}
```
## ValueType
......
......@@ -2,13 +2,551 @@
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**<br/>
> **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.
## Usage
## ResultSetV9<sup>9+</sup>
You need to use [RdbStore.query()](js-apis-data-rdb.md#query) to obtain a **resultSet** object.
Provides methods to access the result set, which is obtained by querying the RDB store.
### Usage
You need to obtain the **resultSetV9** instance by using [RdbStoreV9.query()](js-apis-data-rdb.md#query).
```js
import dataRdb from '@ohos.data.rdb';
let predicatesV9 = new dataRdb.RdbPredicatesV9("EMPLOYEE");
predicatesV9.equalTo("AGE", 18);
let promise = rdbStoreV9.query(predicatesV9, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSetV9) => {
console.log(TAG + "resultSet columnNames:" + resultSetV9.columnNames);
console.log(TAG + "resultSet columnCount:" + resultSetV9.columnCount);
});
```
### Attributes<sup>9+</sup>
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
| Name | Type | Mandatory| Description |
| ------------ | ------------------- | ---- | -------------------------------- |
| columnNames | Array&lt;string&gt; | 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 | 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<sup>9+</sup>
getColumnIndex(columnName: string): number
Obtains the column index based on the column name.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | -------------------------- |
| columnName | string | Yes | Column name specified.|
**Return value**
| Type | Description |
| ------ | ------------------ |
| number | Index of the column obtained.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
resultSetV9.goToFirstRow();
const id = resultSetV9.getLong(resultSetV9.getColumnIndex("ID"));
const name = resultSetV9.getString(resultSetV9.getColumnIndex("NAME"));
const age = resultSetV9.getLong(resultSetV9.getColumnIndex("AGE"));
const salary = resultSetV9.getDouble(resultSetV9.getColumnIndex("SALARY"));
```
### getColumnName<sup>9+</sup>
getColumnName(columnIndex: number): string
Obtains the column name based on the column index.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------------------------- |
| columnIndex | number | Yes | Column index specified.|
**Return value**
| Type | Description |
| ------ | ------------------ |
| string | Column name obtained.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const id = resultSetV9.getColumnName(0);
const name = resultSetV9.getColumnName(1);
const age = resultSetV9.getColumnName(2);
```
### goTo<sup>9+</sup>
goTo(offset:number): boolean
Moves the cursor to the row based on the specified offset.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------------- |
| offset | number | Yes | Offset relative to the current position.|
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```js
let predicatesV9goto = new dataRdb.RdbPredicatesV9("EMPLOYEE");
let promisequerygoto = rdbStoreV9.query(predicatesV9goto, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoto.then((resultSetV9) => {
resultSetV9.goTo(1);
resultSetV9.close();
}).catch((err) => {
console.log('query failed');
});
```
### goToRow<sup>9+</sup>
goToRow(position: number): boolean
Moves the cursor to the specified row in the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------ |
| position | number | Yes | Position to which the cursor is to be moved.|
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```js
let predicatesV9gotorow = new dataRdb.RdbPredicatesV9("EMPLOYEE");
let promisequerygotorow = rdbStoreV9.query(predicatesV9gotorow, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygotorow.then((resultSetV9) => {
resultSetV9.goToRow(5);
resultSetV9.close();
}).catch((err) => {
console.log('query failed');
});
```
### goToFirstRow<sup>9+</sup>
goToFirstRow(): boolean
Moves the cursor to the first row of the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```js
let predicatesV9goFirst = new dataRdb.RdbPredicatesV9("EMPLOYEE");
let promisequerygoFirst = rdbStoreV9.query(predicatesV9goFirst, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoFirst.then((resultSetV9) => {
resultSetV9.goToFirstRow();
resultSetV9.close();
}).catch((err) => {
console.log('query failed');
});
```
### goToLastRow<sup>9+</sup>
goToLastRow(): boolean
Moves the cursor to the last row of the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```js
let predicatesV9goLast = new dataRdb.RdbPredicatesV9("EMPLOYEE");
let promisequerygoLast = rdbStoreV9.query(predicatesV9goLast, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoLast.then((resultSetV9) => {
resultSetV9.goToLastRow();
resultSetV9.close();
}).catch((err) => {
console.log('query failed');
});
```
### goToNextRow<sup>9+</sup>
goToNextRow(): boolean
Moves the cursor to the next row in the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```js
let predicatesV9goNext = new dataRdb.RdbPredicatesV9("EMPLOYEE");
let promisequerygoNext = rdbStoreV9.query(predicatesV9goNext, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoNext.then((resultSetV9) => {
resultSetV9.goToNextRow();
resultSetV9.close();
}).catch((err) => {
console.log('query failed');
});
```
### goToPreviousRow<sup>9+</sup>
goToPreviousRow(): boolean
Moves the cursor to the previous row in the result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
**Example**
```js
let predicatesV9goPrev = new dataRdb.RdbPredicatesV9("EMPLOYEE");
let promisequerygoPrev = rdbStoreV9.query(predicatesV9goPrev, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoPrev.then((resultSetV9) => {
resultSetV9.goToPreviousRow();
resultSetV9.close();
}).catch((err) => {
console.log('query failed');
});
```
### getBlob<sup>9+</sup>
getBlob(columnIndex: number): Uint8Array
Obtains the value in the specified column in the current row as a byte array.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes | Index of the specified column, starting from 0.|
**Return value**
| Type | Description |
| ---------- | -------------------------------- |
| Uint8Array | Value in the specified column as a byte array.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const codes = resultSetV9.getBlob(resultSetV9.getColumnIndex("CODES"));
```
### getString<sup>9+</sup>
getString(columnIndex: number): string
Obtains the value in the specified column in the current row as a string.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes | Index of the specified column, starting from 0.|
**Return value**
| Type | Description |
| ------ | ---------------------------- |
| string | Value in the specified column as a string.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const name = resultSetV9.getString(resultSetV9.getColumnIndex("NAME"));
```
### getLong<sup>9+</sup>
getLong(columnIndex: number): number
Obtains the value in the specified column in the current row as a Long.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes | Index of the specified column, starting from 0.|
**Return value**
| Type | Description |
| ------ | -------------------------- |
| number | Value in the specified column as a Long.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const age = resultSetV9.getLong(resultSetV9.getColumnIndex("AGE"));
```
### getDouble<sup>9+</sup>
getDouble(columnIndex: number): number
Obtains the value in the specified column in the current row as a double.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes | Index of the specified column, starting from 0.|
**Return value**
| Type | Description |
| ------ | ---------------------------- |
| number | Value in the specified column as a double.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const salary = resultSetV9.getDouble(resultSetV9.getColumnIndex("SALARY"));
```
### isColumnNull<sup>9+</sup>
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**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------- |
| columnIndex | number | Yes | Index of the specified column, starting from 0.|
**Return value**
| Type | Description |
| ------- | --------------------------------------------------------- |
| boolean | Returns **true** if the value is null; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800013 | The column value is null or the column type is incompatible. |
**Example**
```js
const isColumnNull = resultSetV9.isColumnNull(resultSetV9.getColumnIndex("CODES"));
```
### close<sup>9+</sup>
close(): void
Closes this result set.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Example**
```js
let predicatesV9Close = new dataRdb.RdbPredicatesV9("EMPLOYEE");
let promiseClose = rdbStoreV9.query(predicatesV9Close, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promiseClose.then((resultSetV9) => {
resultSetV9.close();
}).catch((err) => {
console.log('Failed to close the resultset');
});
```
**Error codes**
For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode-data-rdb.md).
| ID| **Error Message** |
| ------------ | ------------------------------------------------------------ |
| 14800012 | The result set is empty or the specified location is invalid. |
## ResultSet<sup>(deprecated)</sup>
Provides methods to access the result set, which is obtained by querying the RDB store.
> **NOTE**
>
> This object is supported since API version 7 and deprecated since API version 9. You are advised to use [ResultSetV9](#resultsetv99).
### Usage
You need to obtain a **resultSet** object by using [RdbStore.query()](js-apis-data-rdb.md#query).
```js
import dataRdb from '@ohos.data.rdb';
......@@ -21,11 +559,11 @@ promise.then((resultSet) => {
});
```
## ResultSet
### Attributes<sup>(deprecated)</sup>
Provides methods to access the result set, which is obtained by querying the RDB store.
### Attributes
> **NOTE**
>
> This parameter is supported since API version 7 and is deprecated since API version 9. You are advised to use [Attributes](#attributes9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
......@@ -41,25 +579,29 @@ Provides methods to access the result set, which is obtained by querying the RDB
| isStarted | boolean | Yes| Whether the cursor has been moved.|
| isClosed | boolean | Yes| Whether the result set is closed.|
### getColumnIndex
### getColumnIndex<sup>(deprecated)</sup>
getColumnIndex(columnName: string): number
Obtains the column index based on the column name.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getColumnIndex](#getcolumnindex9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnName | string | Yes| Column name specified.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnName | string | Yes| Column name specified.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Index of the column obtained.|
| Type| Description|
| -------- | -------- |
| number | Index of the column obtained.|
**Example**
......@@ -71,25 +613,29 @@ Obtains the column index based on the column name.
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
```
### getColumnName
### getColumnName<sup>(deprecated)</sup>
getColumnName(columnIndex: number): string
Obtains the column name based on the column index.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getColumnName](#getcolumnname9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Column index specified.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Column index specified.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | Column name obtained.|
| Type| Description|
| -------- | -------- |
| string | Column name obtained.|
**Example**
......@@ -99,32 +645,36 @@ Obtains the column name based on the column index.
const age = resultSet.getColumnName(2);
```
### goTo
### goTo<sup>(deprecated)</sup>
goTo(offset:number): boolean
Moves the cursor to the row based on the specified offset.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [goTo](#goto9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Offset relative to the current position.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Offset relative to the current position.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
let predicatesgoto = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygoto = rdbStore.query(predicatesgoto, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoto.then((resultSet) {
promisequerygoto.then((resultSet) => {
resultSet.goTo(1);
resultSet.close();
}).catch((err) => {
......@@ -132,32 +682,36 @@ Moves the cursor to the row based on the specified offset.
});
```
### goToRow
### goToRow<sup>(deprecated)</sup>
goToRow(position: number): boolean
Moves the cursor to the specified row in the result set.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [goToRow](#gotorow9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| position | number | Yes| Position to which the cursor is to be moved.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| position | number | Yes| Position to which the cursor is to be moved.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
let predicatesgotorow = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygotorow = rdbStore.query(predicatesgotorow, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygotorow.then((resultSet) {
promisequerygotorow.then((resultSet) => {
resultSet.goToRow(5);
resultSet.close();
}).catch((err) => {
......@@ -165,27 +719,30 @@ Moves the cursor to the specified row in the result set.
});
```
### goToFirstRow
### goToFirstRow<sup>(deprecated)</sup>
goToFirstRow(): boolean
Moves the cursor to the first row of the result set.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [goToFirstRow](#gotofirstrow9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
let predicatesgoFirst = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygoFirst = rdbStore.query(predicatesgoFirst, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoFirst.then((resultSet) {
promisequerygoFirst.then((resultSet) => {
resultSet.goToFirstRow();
resultSet.close();
}).catch((err) => {
......@@ -193,26 +750,30 @@ Moves the cursor to the first row of the result set.
});
```
### goToLastRow
### goToLastRow<sup>(deprecated)</sup>
goToLastRow(): boolean
Moves the cursor to the last row of the result set.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [goToLastRow](#gotolastrow9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
let predicatesgoLast = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygoLast = rdbStore.query(predicatesgoLast, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoLast.then((resultSet) {
promisequerygoLast.then((resultSet) => {
resultSet.goToLastRow();
resultSet.close();
}).catch((err) => {
......@@ -220,26 +781,30 @@ Moves the cursor to the last row of the result set.
});
```
### goToNextRow
### goToNextRow<sup>(deprecated)</sup>
goToNextRow(): boolean
Moves the cursor to the next row in the result set.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [goToNextRow](#gotonextrow9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
let predicatesgoNext = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygoNext = rdbStore.query(predicatesgoNext, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoNext.then((resultSet) {
promisequerygoNext.then((resultSet) => {
resultSet.goToNextRow();
resultSet.close();
}).catch((err) => {
......@@ -247,26 +812,30 @@ Moves the cursor to the next row in the result set.
});
```
### goToPreviousRow
### goToPreviousRow<sup>(deprecated)</sup>
goToPreviousRow(): boolean
Moves the cursor to the previous row in the result set.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [goToPreviousRow](#gotopreviousrow9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
let predicatesgoPrev = new dataRdb.RdbPredicates("EMPLOYEE");
let promisequerygoPrev = rdbStore.query(predicatesgoPrev, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promisequerygoPrev.then((resultSet) {
promisequerygoPrev.then((resultSet) => {
resultSet.goToPreviousRow();
resultSet.close();
}).catch((err) => {
......@@ -274,25 +843,29 @@ Moves the cursor to the previous row in the result set.
});
```
### getBlob
### getBlob<sup>(deprecated)</sup>
getBlob(columnIndex: number): Uint8Array
Obtains the value in the specified column in the current row as a byte array.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getBlob](#getblob9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.|
**Return value**
| Type| Description|
| -------- | -------- |
| Uint8Array | Value in the specified column as a byte array.|
| Type| Description|
| -------- | -------- |
| Uint8Array | Value in the specified column as a byte array.|
**Example**
......@@ -300,25 +873,29 @@ Obtains the value in the specified column in the current row as a byte array.
const codes = resultSet.getBlob(resultSet.getColumnIndex("CODES"));
```
### getString
### getString<sup>(deprecated)</sup>
getString(columnIndex: number): string
Obtains the value in the specified column in the current row as a string.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getString](#getstring9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | Value in the specified column as a string.|
| Type| Description|
| -------- | -------- |
| string | Value in the specified column as a string.|
**Example**
......@@ -326,25 +903,29 @@ Obtains the value in the specified column in the current row as a string.
const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
```
### getLong
### getLong<sup>(deprecated)</sup>
getLong(columnIndex: number): number
Obtains the value in the specified column in the current row as a Long.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getLong](#getlong9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Value in the specified column as a Long.|
| Type| Description|
| -------- | -------- |
| number | Value in the specified column as a Long.|
**Example**
......@@ -352,25 +933,29 @@ Obtains the value in the specified column in the current row as a Long.
const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
```
### getDouble
### getDouble<sup>(deprecated)</sup>
getDouble(columnIndex: number): number
Obtains the value in the specified column in the current row as a double.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDouble](#getdouble9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Value in the specified column as a double.|
| Type| Description|
| -------- | -------- |
| number | Value in the specified column as a double.|
**Example**
......@@ -378,25 +963,29 @@ Obtains the value in the specified column in the current row as a double.
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
```
### isColumnNull
### isColumnNull<sup>(deprecated)</sup>
isColumnNull(columnIndex: number): boolean
Checks whether the value in the specified column of the current row is null.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isColumnNull](#iscolumnnull9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| columnIndex | number | Yes| Index of the specified column, starting from 0.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value is null; returns **false** otherwise.|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the value is null; returns **false** otherwise.|
**Example**
......@@ -404,12 +993,16 @@ Checks whether the value in the specified column of the current row is null.
const isColumnNull = resultSet.isColumnNull(resultSet.getColumnIndex("CODES"));
```
### close
### close<sup>(deprecated)</sup>
close(): void
Closes this result set.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [close](#close9).
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Example**
......@@ -417,9 +1010,9 @@ Closes this result set.
```js
let predicatesClose = new dataRdb.RdbPredicates("EMPLOYEE");
let promiseClose = rdbStore.query(predicatesClose, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promiseClose.then((resultSet) {
promiseClose.then((resultSet) => {
resultSet.close();
}).catch((err) => {
console.log('Failed to close resultset');
console.log('Failed to close the resultset');
});
```
......@@ -22,10 +22,10 @@ import data_storage from '@ohos.data.storage';
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
| Name | Type | Readable | Writable | Description |
| ---------------- | ------ | -------- | -------- | ----------------------------------------------------------- |
| MAX_KEY_LENGTH | string | Yes | No | Maximum length of a key. It must be less than 80 bytes. |
| MAX_VALUE_LENGTH | string | Yes | No | Maximum length of a value. It must be less than 8192 bytes. |
| Name | Type| Readable| Writable| Description |
| ---------------- | -------- | ---- | ---- | ------------------------------------- |
| MAX_KEY_LENGTH | number | Yes | No | Maximum length of a key. It must be less than 80 bytes. |
| MAX_VALUE_LENGTH | number | Yes | No | Maximum length of a value. It must be less than 8192 bytes.|
## data_storage.getStorageSync
......@@ -53,8 +53,8 @@ Reads the specified file and loads its data to the **Storage** instance for data
```js
import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
let path;
let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
......@@ -86,8 +86,8 @@ Reads the specified file and loads its data to the **Storage** instance for data
```js
import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
let path;
let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
......@@ -129,8 +129,8 @@ Reads the specified file and loads its data to the **Storage** instance for data
```js
import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
let path;
let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
......@@ -165,8 +165,8 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
```js
import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
let path;
let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
......@@ -195,8 +195,8 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
```js
import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
let path;
let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
......@@ -237,8 +237,8 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
```js
import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
let path;
let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
......@@ -271,8 +271,8 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
```js
import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
let path;
let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
......@@ -302,8 +302,8 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
```js
import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
let path;
let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
......@@ -344,8 +344,8 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
```js
import featureAbility from '@ohos.ability.featureAbility';
var path;
var context = featureAbility.getContext();
let path;
let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => {
path = filePath;
console.info("======================>getFilesDirPromise====================>");
......@@ -864,15 +864,15 @@ Subscribes to data changes. The **StorageObserver** needs to be implemented. Whe
**Parameters**
| Name | Type | Description |
| -------- | --------------------------------------------------- | ---------------------------------------- |
| type | string | Event type. The value **change** indicates data change events.|
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. |
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ------ |---------------------------------------- |
| type | string |Yes| Event type. The value **change** indicates data change events.|
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Yes|Callback used to return data changes. |
**Example**
```js
var observer = function (key) {
let observer = function (key) {
console.info("The key of " + key + " changed.");
}
storage.on('change', observer);
......@@ -891,15 +891,15 @@ Unsubscribes from data changes.
**Parameters**
| Name | Type | Description |
| -------- | --------------------------------------------------- | ---------------------------------------- |
| type | string | Event type. The value **change** indicates data change events.|
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. |
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ------ |---------------------------------------- |
| type | string |Yes| Event type. The value **change** indicates data change events.|
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Yes|Callback used to return data changes. |
**Example**
```js
var observer = function (key) {
let observer = function (key) {
console.info("The key of " + key + " changed.");
}
storage.off('change', observer);
......
# RDB Error Codes
## 14800010 Invalid RDB Name
**Error Message**
Invalid database name.
**Description**
The RDB store name is invalid.
**Possible Causes**
The RDB store name is empty or exceeds 1024 bytes.
**Solution**
Check that the RDB store name is not empty and does not exceed 1024 bytes.
## 14800011 Database File Corrupted
**Error Message**
Database corrupted.
**Description**
The RDB store is corrupted when an API for adding, deleting, querying, or synchronizing data is invoked.
**Possible Causes**
The RDB store file has been corrupted.
**Solution**
1. Restore the RDB store using the backup file.
2. If no RDB backup file is available, delete the RDB store and create it again.
## 14800012 Empty Result Set or Invalid Position
**Error Message**
The result set is empty or the specified location is invalid.
**Description**
The result set is empty or the specified location is invalid.
**Possible Causes**
The result set is empty, or the specified row number in the result set is out of range [0, m - 1]. **m** is **resultsetV9.rowCount**.
**Solution**
Check whether the result set is empty or whether the specified row number is out of range.
## 14800013 Null Column Value or Column Data Type Incompatible With the API Called
**Error Message**
The column value is null or the column type is incompatible.
**Description**
The column value is null, or the column data type is incompatible with the API called.
**Possible Causes**
1. The result set is empty.
2. The current row number in the result set is out of range [0, m - 1]. **m** is **resultsetV9.rowCount**.
3. The column number is out of the range [0, n - 1]. **n** is **resultsetV9.columnCount**.
4. The API called does not support the type of the column data.
**Solution**
1. Check whether the result set is empty.
2. Check whether the row number and column number of the result set are out of range.
3. Check whether the column data type is supported.
# Preferences Error Codes
## 15500010 Failed to Delete Preferences
**Error Message**
Failed to delete preferences.
**Description**
Failed to delete the preference.
**Possible Causes**
The possible causes are as follows:
1. The file name is incorrect.
2. The file path is incorrect.
**Solution**
1. Check that the file name is correct.
2. Check that the file path is correct.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册