未验证 提交 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'; ...@@ -22,8 +22,8 @@ import data_preferences from '@ohos.data.preferences';
| Name | Type| Readable| Writable| Description | | 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_KEY_LENGTH | number | 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_VALUE_LENGTH | number | Yes | No | Maximum length of a value. The value must be less than 8192 bytes.|
## data_preferences.getPreferences ## data_preferences.getPreferences
...@@ -50,16 +50,19 @@ FA model: ...@@ -50,16 +50,19 @@ FA model:
// Obtain the context. // Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
let preferences = null; let preferences = null;
data_preferences.getPreferences(context, 'mystore', function (err, object) {
if (err) { try {
console.info("Failed to get the preferences. Cause: " + err); data_preferences.getPreferences(context, 'mystore', function (err, val) {
return; if (err) {
} console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
preferences = object; return;
console.info("Got the preferences successfully."); }
}) console.info("Got the preferences successfully.");
})
} catch (err) {
console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
``` ```
Stage model: Stage model:
...@@ -75,14 +78,17 @@ class MainAbility extends Ability{ ...@@ -75,14 +78,17 @@ class MainAbility extends Ability{
} }
let preferences = null; let preferences = null;
data_preferences.getPreferences(context, 'mystore', function (err, object) { try {
if (err) { data_preferences.getPreferences(context, 'mystore', function (err, val) {
console.info("Failed to get the preferences. Cause: " + err); if (err) {
return; console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
} return;
preferences = object; }
console.info("Got the preferences successfully."); console.info("Got the preferences successfully.");
}) })
} catch (err) {
console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
}
``` ```
## data_preferences.getPreferences ## data_preferences.getPreferences
...@@ -116,13 +122,17 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -116,13 +122,17 @@ import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
let preferences = null; let preferences = null;
let promise = data_preferences.getPreferences(context, 'mystore'); try {
promise.then((object) => { let promise = data_preferences.getPreferences(context, 'mystore');
preferences = object; promise.then((object) => {
console.info("Got the preferences successfully."); preferences = object;
}).catch((err) => { console.info("Got the preferences successfully.");
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: Stage model:
...@@ -138,13 +148,17 @@ class MainAbility extends Ability{ ...@@ -138,13 +148,17 @@ class MainAbility extends Ability{
} }
let preferences = null; let preferences = null;
let promise = data_preferences.getPreferences(context, 'mystore'); try {
promise.then((object) => { let promise = data_preferences.getPreferences(context, 'mystore');
preferences = object; promise.then((object) => {
console.info("Got the preferences successfully."); preferences = object;
}).catch((err) => { console.info("Got the preferences successfully.");
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 ## data_preferences.deletePreferences
...@@ -167,6 +181,14 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi ...@@ -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. | | 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.| | 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** **Example**
FA model: FA model:
...@@ -176,13 +198,17 @@ FA model: ...@@ -176,13 +198,17 @@ FA model:
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
data_preferences.deletePreferences(context, 'mystore', function (err) { try {
if (err) { data_preferences.deletePreferences(context, 'mystore', function (err, val) {
console.info("Failed to delete the preferences. Cause: " + err); if (err) {
return; console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
} return;
console.info("Deleted the preferences successfully." ); }
}) console.info("Deleted the preferences successfully." );
})
} catch (err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
``` ```
Stage model: Stage model:
...@@ -197,13 +223,17 @@ class MainAbility extends Ability{ ...@@ -197,13 +223,17 @@ class MainAbility extends Ability{
} }
} }
data_preferences.deletePreferences(context, 'mystore', function (err) { try {
if (err) { data_preferences.deletePreferences(context, 'mystore', function (err, val) {
console.info("Failed to delete the preferences. Cause: " + err); if (err) {
return; console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
} return;
console.info("Deleted the preferences successfully." ); }
}) console.info("Deleted the preferences successfully." );
})
} catch (err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
}
``` ```
## data_preferences.deletePreferences ## data_preferences.deletePreferences
...@@ -231,6 +261,14 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi ...@@ -231,6 +261,14 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
| ------------------- | ------------------------- | | ------------------- | ------------------------- |
| Promise<void> | Promise that returns no value.| | 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** **Example**
FA model: FA model:
...@@ -240,12 +278,16 @@ FA model: ...@@ -240,12 +278,16 @@ FA model:
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
let promise = data_preferences.deletePreferences(context, 'mystore'); try {
promise.then(() => { let promise = data_preferences.deletePreferences(context, 'mystore');
console.info("Deleted the preferences successfully."); promise.then(() => {
}).catch((err) => { console.info("Deleted the preferences successfully.");
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: Stage model:
...@@ -260,12 +302,16 @@ class MainAbility extends Ability{ ...@@ -260,12 +302,16 @@ class MainAbility extends Ability{
} }
} }
let promise = data_preferences.deletePreferences(context, 'mystore'); try{
promise.then(() => { let promise = data_preferences.deletePreferences(context, 'mystore');
console.info("Deleted the preferences successfully."); promise.then(() => {
}).catch((err) => { console.info("Deleted the preferences successfully.");
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 ## data_preferences.removePreferencesFromCache
...@@ -295,13 +341,17 @@ FA model: ...@@ -295,13 +341,17 @@ FA model:
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
data_preferences.removePreferencesFromCache(context, 'mystore', function (err) { try {
if (err) { data_preferences.removePreferencesFromCache(context, 'mystore', function (err, val) {
console.info("Failed to remove the preferences. Cause: " + err); if (err) {
return; console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
} return;
console.info("Removed the preferences successfully."); }
}) console.info("Removed the preferences successfully.");
})
} catch (err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}
``` ```
Stage model: Stage model:
...@@ -316,13 +366,18 @@ class MainAbility extends Ability{ ...@@ -316,13 +366,18 @@ class MainAbility extends Ability{
} }
} }
data_preferences.removePreferencesFromCache(context, 'mystore', function (err) { try {
if (err) { data_preferences.removePreferencesFromCache(context, 'mystore', function (err, val) {
console.info("Failed to remove the preferences. Cause: " + err); if (err) {
return; console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
} return;
console.info("Removed the preferences successfully."); }
}) console.info("Removed the preferences successfully.");
})
} catch (err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
}
``` ```
## data_preferences.removePreferencesFromCache ## data_preferences.removePreferencesFromCache
...@@ -357,12 +412,16 @@ FA model: ...@@ -357,12 +412,16 @@ FA model:
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
let promise = data_preferences.removePreferencesFromCache(context, 'mystore'); try {
promise.then(() => { let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
console.info("Removed the preferences successfully."); promise.then(() => {
}).catch((err) => { console.info("Removed the preferences successfully.");
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: Stage model:
...@@ -377,12 +436,16 @@ class MainAbility extends Ability{ ...@@ -377,12 +436,16 @@ class MainAbility extends Ability{
} }
} }
let promise = data_preferences.removePreferencesFromCache(context, 'mystore'); try {
promise.then(() => { let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
console.info("Removed the preferences successfully."); promise.then(() => {
}).catch((err) => { console.info("Removed the preferences successfully.");
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 ## Preferences
...@@ -411,13 +474,17 @@ Obtains the value of a key. This API uses an asynchronous callback to return the ...@@ -411,13 +474,17 @@ Obtains the value of a key. This API uses an asynchronous callback to return the
**Example** **Example**
```js ```js
preferences.get('startup', 'default', function(err, data) { try {
if (err) { preferences.get('startup', 'default', function (err, val) {
console.info("Failed to get the value of 'startup'. Cause: " + err); if (err) {
return; 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 ...@@ -445,12 +512,16 @@ Obtains the value of a key. This API uses a promise to return the result. If the
**Example** **Example**
```js ```js
let promise = preferences.get('startup', 'default'); try {
promise.then((data) => { let promise = preferences.get('startup', 'default');
console.info("Got the value of 'startup'. Data: " + data); promise.then((data) => {
}).catch((err) => { console.info("Got the value of 'startup'. Data: " + data);
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 ### getAll
...@@ -470,15 +541,19 @@ Obtains an **Object** instance that contains all KV pairs. This API uses an asyn ...@@ -470,15 +541,19 @@ Obtains an **Object** instance that contains all KV pairs. This API uses an asyn
**Example** **Example**
```js ```js
preferences.getAll(function (err, value) { try {
if (err) { preferences.getAll(function (err, value) {
console.info("Failed to get all KV pairs. Cause: " + err); if (err) {
return; console.info("Failed to get all KV pairs. code =" + err.code + ", message =" + err.message);
} return;
}
let allKeys = Object.keys(value); let allKeys = Object.keys(value);
console.info("getAll keys = " + allKeys); console.info("getAll keys = " + allKeys);
console.info("getAll object = " + JSON.stringify(value)); 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 ...@@ -499,14 +574,18 @@ Obtains an **Object** instance that contains all KV pairs. This API uses a promi
**Example** **Example**
```js ```js
let promise = preferences.getAll(); try {
promise.then((value) => { let promise = preferences.getAll();
let allKeys = Object.keys(value); promise.then((value) => {
console.info('getAll keys = ' + allKeys); let allKeys = Object.keys(value);
console.info("getAll object = " + JSON.stringify(value)); console.info('getAll keys = ' + allKeys);
}).catch((err) => { console.info("getAll object = " + JSON.stringify(value));
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 ### put
...@@ -528,13 +607,17 @@ Writes data to this **Preferences** instance. This API uses an asynchronous call ...@@ -528,13 +607,17 @@ Writes data to this **Preferences** instance. This API uses an asynchronous call
**Example** **Example**
```js ```js
preferences.put('startup', 'auto', function (err) { try {
if (err) { preferences.put('startup', 'auto', function (err) {
console.info("Failed to put the value of 'startup'. Cause: " + err); if (err) {
return; console.info("Failed to put the value of 'startup'. code =" + err.code + ", message =" + err.message);
} return;
console.info("Put the value of 'startup' successfully."); }
}) 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 ...@@ -562,12 +645,16 @@ Writes data to this **Preferences** instance. This API uses a promise to return
**Example** **Example**
```js ```js
let promise = preferences.put('startup', 'auto'); try {
promise.then(() => { let promise = preferences.put('startup', 'auto');
console.info("Put the value of 'startup' successfully."); promise.then(() => {
}).catch((err) => { console.info("Put the value of 'startup' successfully.");
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 ...@@ -589,17 +676,21 @@ Checks whether this **Preferences** instance contains a KV pair with the given k
**Example** **Example**
```js ```js
preferences.has('startup', function (err, isExist) { try {
if (err) { preferences.has('startup', function (err, val) {
console.info("Failed to check the key 'startup'. Cause: " + err); if (err) {
return; console.info("Failed to check the key 'startup'. code =" + err.code + ", message =" + err.message);
} return;
if (isExist) { }
console.info("The key 'startup' is contained."); if (val) {
} else { console.info("The key 'startup' is contained.");
console.info("The key 'startup' is not 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 ...@@ -626,16 +717,20 @@ Checks whether this **Preferences** instance contains a KV pair with the given k
**Example** **Example**
```js ```js
let promise = preferences.has('startup'); try {
promise.then((isExist) => { let promise = preferences.has('startup');
if (isExist) { promise.then((val) => {
console.info("The key 'startup' is contained."); if (val) {
} else { console.info("The key 'startup' is contained.");
console.info("The key 'startup' is not 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) => { ...@@ -643,7 +738,7 @@ promise.then((isExist) => {
delete(key: string, callback: AsyncCallback<void>): void 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 **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
...@@ -657,13 +752,17 @@ Deletes a KV pair from this **Preferences** instance. This API uses an asynchron ...@@ -657,13 +752,17 @@ Deletes a KV pair from this **Preferences** instance. This API uses an asynchron
**Example** **Example**
```js ```js
preferences.delete('startup', function (err) { try {
if (err) { preferences.delete('startup', function (err) {
console.info("Failed to delete the key 'startup'. Cause: " + err); if (err) {
return; console.info("Failed to delete the key 'startup'. code =" + err.code + ", message =" + err.message);
} return;
console.info("Deleted the key 'startup'."); }
}) 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 ...@@ -690,12 +789,16 @@ Deletes a KV pair from this **Preferences** instance. This API uses a promise to
**Example** **Example**
```js ```js
let promise = preferences.delete('startup'); try {
promise.then(() => { let promise = preferences.delete('startup');
console.info("Deleted the key 'startup'."); promise.then(() => {
}).catch((err) => { console.info("Deleted the key 'startup'.");
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 ...@@ -716,13 +819,17 @@ Saves the data of this **Preferences** instance to a file asynchronously. This A
**Example** **Example**
```js ```js
preferences.flush(function (err) { try {
if (err) { preferences.flush(function (err) {
console.info("Failed to flush data. Cause: " + err); if (err) {
return; console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
} return;
console.info("Flushed data successfully."); }
}) 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 ...@@ -743,12 +850,16 @@ Saves the data of this **Preferences** instance to a file asynchronously. This A
**Example** **Example**
```js ```js
let promise = preferences.flush(); try {
promise.then(() => { let promise = preferences.flush();
console.info("Flushed data to file successfully.") promise.then(() => {
}).catch((err) => { console.info("Flushed data successfully.");
console.info("Failed to flush data. Cause: " + err); }).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 ...@@ -769,13 +880,17 @@ Clears this **Preferences** instance. This API uses an asynchronous callback to
**Example** **Example**
```js ```js
preferences.clear(function (err) { try {
if (err) { preferences.clear(function (err) {
console.info("Failed to clear data. Cause: " + err); if (err) {
return; console.info("Failed to clear data. code =" + err.code + ", message =" + err.message);
} return;
console.info("Cleared data successfully."); }
}) 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 ...@@ -796,12 +911,16 @@ Clears this **Preferences** instance. This API uses a promise to return the resu
**Example** **Example**
```js ```js
let promise = preferences.clear() try {
promise.then(() => { let promise = preferences.clear();
console.info("Cleared data successfully."); promise.then(() => {
}).catch((err) => { console.info("Cleared data successfully.");
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,31 +942,35 @@ Subscribes to data changes. A callback will be triggered to return the new value ...@@ -823,31 +942,35 @@ Subscribes to data changes. A callback will be triggered to return the new value
**Example** **Example**
```js ```js
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) { try {
if (err) { data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
console.info("Failed to get the preferences."); if (err) {
return; console.info("Failed to get the preferences.");
} return;
let observer = function (key) { }
console.info("The key " + key + " changed."); let observer = function (key) {
} console.info("The key " + key + " changed.");
preferences.on('change', observer); }
preferences.put('startup', 'manual', function (err) { preferences.on('change', observer);
if (err) { preferences.put('startup', 'manual', function (err) {
console.info("Failed to put the value of 'startup'. Cause: " + err); if (err) {
return; console.info("Failed to put the value of 'startup'. Cause: " + err);
} return;
console.info("Put the value of 'startup' successfully."); }
console.info("Put the value of 'startup' successfully.");
preferences.flush(function (err) {
if (err) { preferences.flush(function (err) {
console.info("Failed to flush data. Cause: " + err); if (err) {
return; 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,32 +992,36 @@ Unsubscribes from data changes. ...@@ -869,32 +992,36 @@ Unsubscribes from data changes.
**Example** **Example**
```js ```js
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) { try {
if (err) { data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
console.info("Failed to get the preferences.");
return;
}
let observer = function (key) {
console.info("The key " + key + " changed.");
}
preferences.on('change', observer);
preferences.put('startup', 'auto', function (err) {
if (err) { if (err) {
console.info("Failed to put the value of 'startup'. Cause: " + err); console.info("Failed to get the preferences.");
return; return;
} }
console.info("Put the value of 'startup' successfully."); let observer = function (key) {
console.info("The key " + key + " changed.");
preferences.flush(function (err) { }
preferences.on('change', observer);
preferences.put('startup', 'auto', function (err) {
if (err) { if (err) {
console.info("Failed to flush data. Cause: " + err); console.info("Failed to put the value of 'startup'. Cause: " + err);
return; return;
} }
console.info("Flushed data successfully."); // The observer will be called. console.info("Put the value of 'startup' successfully.");
preferences.flush(function (err) {
if (err) {
console.info("Failed to flush data. Cause: " + err);
return;
}
console.info("Flushed data successfully.");
})
preferences.off('change', observer);
}) })
preferences.off('change', observer);
}) })
}) } catch (err) {
console.info("Failed to flush data. code =" + err.code + ", message =" + err.message);
}
``` ```
## ValueType ## ValueType
......
...@@ -2,13 +2,551 @@ ...@@ -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. 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. > 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 ```js
import dataRdb from '@ohos.data.rdb'; import dataRdb from '@ohos.data.rdb';
...@@ -21,11 +559,11 @@ promise.then((resultSet) => { ...@@ -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. > **NOTE**
>
### Attributes > 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 **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -41,25 +579,29 @@ Provides methods to access the result set, which is obtained by querying the RDB ...@@ -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.| | 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<sup>(deprecated)</sup>
getColumnIndex(columnName: string): number getColumnIndex(columnName: string): number
Obtains the column index based on the column name. 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 **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**
...@@ -71,25 +613,29 @@ Obtains the column index based on the column name. ...@@ -71,25 +613,29 @@ Obtains the column index based on the column name.
const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY")); const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
``` ```
### getColumnName ### getColumnName<sup>(deprecated)</sup>
getColumnName(columnIndex: number): string getColumnName(columnIndex: number): string
Obtains the column name based on the column index. 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 **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**
...@@ -99,32 +645,36 @@ Obtains the column name based on the column index. ...@@ -99,32 +645,36 @@ Obtains the column name based on the column index.
const age = resultSet.getColumnName(2); const age = resultSet.getColumnName(2);
``` ```
### goTo ### goTo<sup>(deprecated)</sup>
goTo(offset:number): boolean goTo(offset:number): boolean
Moves the cursor to the row based on the specified offset. 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 **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) => {
...@@ -132,32 +682,36 @@ Moves the cursor to the row based on the specified offset. ...@@ -132,32 +682,36 @@ Moves the cursor to the row based on the specified offset.
}); });
``` ```
### goToRow ### goToRow<sup>(deprecated)</sup>
goToRow(position: number): boolean goToRow(position: number): boolean
Moves the cursor to the specified row in the result set. 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 **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) => {
...@@ -165,27 +719,30 @@ Moves the cursor to the specified row in the result set. ...@@ -165,27 +719,30 @@ Moves the cursor to the specified row in the result set.
}); });
``` ```
### goToFirstRow ### goToFirstRow<sup>(deprecated)</sup>
goToFirstRow(): boolean goToFirstRow(): boolean
Moves the cursor to the first row of the result set. 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 **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) => {
...@@ -193,26 +750,30 @@ Moves the cursor to the first row of the result set. ...@@ -193,26 +750,30 @@ Moves the cursor to the first row of the result set.
}); });
``` ```
### goToLastRow ### goToLastRow<sup>(deprecated)</sup>
goToLastRow(): boolean goToLastRow(): boolean
Moves the cursor to the last row of the result set. 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 **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) => {
...@@ -220,26 +781,30 @@ Moves the cursor to the last row of the result set. ...@@ -220,26 +781,30 @@ Moves the cursor to the last row of the result set.
}); });
``` ```
### goToNextRow ### goToNextRow<sup>(deprecated)</sup>
goToNextRow(): boolean goToNextRow(): boolean
Moves the cursor to the next row in the result set. 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 **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) => {
...@@ -247,26 +812,30 @@ Moves the cursor to the next row in the result set. ...@@ -247,26 +812,30 @@ Moves the cursor to the next row in the result set.
}); });
``` ```
### goToPreviousRow ### goToPreviousRow<sup>(deprecated)</sup>
goToPreviousRow(): boolean goToPreviousRow(): boolean
Moves the cursor to the previous row in the result set. 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 **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) => {
...@@ -274,25 +843,29 @@ Moves the cursor to the previous row in the result set. ...@@ -274,25 +843,29 @@ Moves the cursor to the previous row in the result set.
}); });
``` ```
### getBlob ### getBlob<sup>(deprecated)</sup>
getBlob(columnIndex: number): Uint8Array getBlob(columnIndex: number): Uint8Array
Obtains the value in the specified column in the current row as a byte array. 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 **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**
...@@ -300,25 +873,29 @@ Obtains the value in the specified column in the current row as a byte array. ...@@ -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")); const codes = resultSet.getBlob(resultSet.getColumnIndex("CODES"));
``` ```
### getString ### getString<sup>(deprecated)</sup>
getString(columnIndex: number): string getString(columnIndex: number): string
Obtains the value in the specified column in the current row as a 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 **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**
...@@ -326,25 +903,29 @@ Obtains the value in the specified column in the current row as a string. ...@@ -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")); const name = resultSet.getString(resultSet.getColumnIndex("NAME"));
``` ```
### getLong ### getLong<sup>(deprecated)</sup>
getLong(columnIndex: number): number getLong(columnIndex: number): number
Obtains the value in the specified column in the current row as a Long. 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 **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**
...@@ -352,25 +933,29 @@ Obtains the value in the specified column in the current row as a Long. ...@@ -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")); const age = resultSet.getLong(resultSet.getColumnIndex("AGE"));
``` ```
### getDouble ### getDouble<sup>(deprecated)</sup>
getDouble(columnIndex: number): number getDouble(columnIndex: number): number
Obtains the value in the specified column in the current row as a double. 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 **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**
...@@ -378,25 +963,29 @@ Obtains the value in the specified column in the current row as a double. ...@@ -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")); const salary = resultSet.getDouble(resultSet.getColumnIndex("SALARY"));
``` ```
### isColumnNull ### isColumnNull<sup>(deprecated)</sup>
isColumnNull(columnIndex: number): boolean isColumnNull(columnIndex: number): boolean
Checks whether the value in the specified column of the current row is null. 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 **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**
...@@ -404,12 +993,16 @@ Checks whether the value in the specified column of the current row is null. ...@@ -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")); const isColumnNull = resultSet.isColumnNull(resultSet.getColumnIndex("CODES"));
``` ```
### close ### close<sup>(deprecated)</sup>
close(): void close(): void
Closes this result set. 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 **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
**Example** **Example**
...@@ -417,9 +1010,9 @@ Closes this result set. ...@@ -417,9 +1010,9 @@ Closes this result set.
```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 the resultset');
}); });
``` ```
...@@ -22,10 +22,10 @@ import data_storage from '@ohos.data.storage'; ...@@ -22,10 +22,10 @@ import data_storage from '@ohos.data.storage';
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
| Name | Type | Readable | Writable | Description | | Name | Type| Readable| Writable| Description |
| ---------------- | ------ | -------- | -------- | ----------------------------------------------------------- | | ---------------- | -------- | ---- | ---- | ------------------------------------- |
| MAX_KEY_LENGTH | string | Yes | No | Maximum length of a key. It must be less than 80 bytes. | | MAX_KEY_LENGTH | number | 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. | | MAX_VALUE_LENGTH | number | Yes | No | Maximum length of a value. It must be less than 8192 bytes.|
## data_storage.getStorageSync ## data_storage.getStorageSync
...@@ -53,8 +53,8 @@ Reads the specified file and loads its data to the **Storage** instance for data ...@@ -53,8 +53,8 @@ Reads the specified file and loads its data to the **Storage** instance for data
```js ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
var path; let path;
var context = featureAbility.getContext(); let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
...@@ -86,8 +86,8 @@ Reads the specified file and loads its data to the **Storage** instance for data ...@@ -86,8 +86,8 @@ Reads the specified file and loads its data to the **Storage** instance for data
```js ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
var path; let path;
var context = featureAbility.getContext(); let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
...@@ -129,8 +129,8 @@ Reads the specified file and loads its data to the **Storage** instance for data ...@@ -129,8 +129,8 @@ Reads the specified file and loads its data to the **Storage** instance for data
```js ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
var path; let path;
var context = featureAbility.getContext(); let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
...@@ -165,8 +165,8 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -165,8 +165,8 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
```js ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
var path; let path;
var context = featureAbility.getContext(); let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
...@@ -195,8 +195,8 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -195,8 +195,8 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
```js ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
var path; let path;
var context = featureAbility.getContext(); let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
...@@ -237,8 +237,8 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete ...@@ -237,8 +237,8 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete
```js ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
var path; let path;
var context = featureAbility.getContext(); let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
...@@ -271,8 +271,8 @@ Removes the singleton **Storage** instance of a file from the cache. The removed ...@@ -271,8 +271,8 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
```js ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
var path; let path;
var context = featureAbility.getContext(); let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
...@@ -302,8 +302,8 @@ Removes the singleton **Storage** instance of a file from the cache. The removed ...@@ -302,8 +302,8 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
```js ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
var path; let path;
var context = featureAbility.getContext(); let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
...@@ -344,8 +344,8 @@ Removes the singleton **Storage** instance of a file from the cache. The removed ...@@ -344,8 +344,8 @@ Removes the singleton **Storage** instance of a file from the cache. The removed
```js ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
var path; let path;
var context = featureAbility.getContext(); let context = featureAbility.getContext();
context.getFilesDir().then((filePath) => { context.getFilesDir().then((filePath) => {
path = filePath; path = filePath;
console.info("======================>getFilesDirPromise====================>"); console.info("======================>getFilesDirPromise====================>");
...@@ -864,15 +864,15 @@ Subscribes to data changes. The **StorageObserver** needs to be implemented. Whe ...@@ -864,15 +864,15 @@ Subscribes to data changes. The **StorageObserver** needs to be implemented. Whe
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ---------------------------------------- | | -------- | --------------------------------------------------- | ------ |---------------------------------------- |
| type | string | Event type. The value **change** indicates data change events.| | type | string |Yes| Event type. The value **change** indicates data change events.|
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. | | callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Yes|Callback used to return data changes. |
**Example** **Example**
```js ```js
var observer = function (key) { let observer = function (key) {
console.info("The key of " + key + " changed."); console.info("The key of " + key + " changed.");
} }
storage.on('change', observer); storage.on('change', observer);
...@@ -891,15 +891,15 @@ Unsubscribes from data changes. ...@@ -891,15 +891,15 @@ Unsubscribes from data changes.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ---------------------------------------- | | -------- | --------------------------------------------------- | ------ |---------------------------------------- |
| type | string | Event type. The value **change** indicates data change events.| | type | string |Yes| Event type. The value **change** indicates data change events.|
| callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Callback used to return data changes. | | callback | Callback&lt;[StorageObserver](#storageobserver)&gt; | Yes|Callback used to return data changes. |
**Example** **Example**
```js ```js
var observer = function (key) { let observer = function (key) {
console.info("The key of " + key + " changed."); console.info("The key of " + key + " changed.");
} }
storage.off('change', observer); 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.
先完成此消息的编辑!
想要评论请 注册