oh_preferences_value.h
Overview
Provides APIs, enums, and structs for accessing the PreferencesValue object.
File to include: <database/preferences/oh_preferences_value.h>
Library: libohpreferences.so
System capability: SystemCapability.DistributedDataManager.Preferences.Core
Since: 13
Related module: Preferences
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| OH_PreferencesPair | OH_PreferencesPair | Defines a struct for the Preferences data in KV format. |
| OH_PreferencesValue | OH_PreferencesValue | Defines a struct for the PreferencesValue object. |
Enums
| Name | typedef Keyword | Description |
|---|---|---|
| Preference_ValueType | Preference_ValueType | Enumerates the data types of PreferencesValue. |
Functions
Enum Description
Preference_ValueType
enum Preference_ValueType
Description
Enumerates the data types of PreferencesValue.
Since: 13
| Enum Item | Description |
|---|---|
| PREFERENCE_TYPE_NULL = 0 | Null. |
| PREFERENCE_TYPE_INT | Integer. |
| PREFERENCE_TYPE_BOOL | Boolean. |
| PREFERENCE_TYPE_STRING | String. |
| PREFERENCE_TYPE_INT64 | 64-bit integer. Since: 23 |
| PREFERENCE_TYPE_DOUBLE | Double. Since: 23 |
| PREFERENCE_TYPE_INT_ARRAY | Integer array. Since: 23 |
| PREFERENCE_TYPE_BOOL_ARRAY | Boolean array. Since: 23 |
| PREFERENCE_TYPE_STRING_ARRAY | String array. Since: 23 |
| PREFERENCE_TYPE_INT64_ARRAY | 64-bit integer array. Since: 23 |
| PREFERENCE_TYPE_DOUBLE_ARRAY | Double array. Since: 23 |
| PREFERENCE_TYPE_BLOB | Blob. Since: 23 |
| PREFERENCE_TYPE_BUTT | End type. |
Function Description
OH_PreferencesPair_GetKey()
const char *OH_PreferencesPair_GetKey(const OH_PreferencesPair *pairs, uint32_t index)
Description
Obtains the key based on the specified index from the KV data.
Since: 13
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesPair *pairs | Pointer to the target OH_PreferencesPair. |
| uint32_t index | Index of the target OH_PreferencesPair. |
Returns
| Type | Description |
|---|---|
| const char * | Returns the pointer to the key obtained if the operation is successful; returns a null pointer if the operation fails or invalid parameters are specified. |
OH_PreferencesPair_GetPreferencesValue()
const OH_PreferencesValue *OH_PreferencesPair_GetPreferencesValue(const OH_PreferencesPair *pairs, uint32_t index)
Description
Obtains the value based on the specified index from the KV pairs.
Since: 13
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesPair *pairs | Pointer to the target OH_PreferencesPair. |
| uint32_t index | Index of the target OH_PreferencesPair. |
Returns
| Type | Description |
|---|---|
| const OH_PreferencesValue | Returns the pointer to the value obtained if the operation is successful; returns a null pointer if the operation fails or invalid parameters are specified. |
OH_PreferencesValue_GetValueType()
Preference_ValueType OH_PreferencesValue_GetValueType(const OH_PreferencesValue *object)
Description
Obtains the data type of a PreferencesValue instance.
Since: 13
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the OH_PreferencesValue instance. |
Returns
| Type | Description |
|---|---|
| Preference_ValueType | Returns the obtained data type. If PREFERENCE_TYPE_NULL is returned, invalid parameters are passed in. |
OH_PreferencesValue_GetInt()
int OH_PreferencesValue_GetInt(const OH_PreferencesValue *object, int *value)
Description
Obtains an integer from an OH_PreferencesValue instance.
Since: 13
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the OH_PreferencesValue instance. |
| int *value | Pointer to the integer value obtained. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_GetBool()
int OH_PreferencesValue_GetBool(const OH_PreferencesValue *object, bool *value)
Description
Obtains a Boolean value from an OH_PreferencesValue instance.
Since: 13
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the OH_PreferencesValue instance. |
| bool *value | Pointer to the Boolean value obtained. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_GetString()
int OH_PreferencesValue_GetString(const OH_PreferencesValue *object, char **value, uint32_t *valueLen)
Description
Obtains a string from an OH_PreferencesValue instance.
Since: 13
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the OH_PreferencesValue instance. |
| char **value | Double pointer to the string obtained. If the string is not required, you can use OH_Preferences_FreeString to free the string (release the memory occupied by the string). |
| uint32_t *valueLen | Pointer to the length of the string obtained. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesPair_Destroy()
void OH_PreferencesPair_Destroy(OH_PreferencesPair *pairs, uint32_t count)
Description
Destroys an OH_PreferencesPair instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| OH_PreferencesPair *pairs | Pointer to the target OH_PreferencesPair instance. |
| uint32_t count | Size of the KV array to be destroyed. |
OH_PreferencesValue_Create()
OH_PreferencesValue* OH_PreferencesValue_Create(void)
Description
Creates an OH_PreferencesValue instance.
Since: 23
Returns
| Type | Description |
|---|---|
| OH_PreferencesValue* | Returns the pointer to the OH_PreferencesValue object; returns a null pointer otherwise. |
OH_PreferencesValue_Destroy()
void OH_PreferencesValue_Destroy(OH_PreferencesValue *value)
Description
Destroys an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| OH_PreferencesValue *value | Pointer to the target OH_PreferencesValue instance. |
OH_PreferencesValue_SetInt()
int OH_PreferencesValue_SetInt(const OH_PreferencesValue *object, int value)
Description
Sets an integer value for an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| int value | Integer value to be set. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_SetBool()
int OH_PreferencesValue_SetBool(const OH_PreferencesValue *object, bool value)
Description
Sets a boolean value for an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| bool value | Boolean value to be set. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_SetString()
int OH_PreferencesValue_SetString(const OH_PreferencesValue *object, const char *value)
Description
Sets a string value for an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| const char *value | String value to be set. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_SetInt64()
int OH_PreferencesValue_SetInt64(const OH_PreferencesValue *object, int64_t value)
Description
Sets an int64 value for an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| int64_t value | Int64 value to be set. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_GetInt64()
int OH_PreferencesValue_GetInt64(const OH_PreferencesValue *object, int64_t *value)
Description
Obtains an int64 value from an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| int64_t *value | Pointer to the obtained int64 value. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_SetDouble()
int OH_PreferencesValue_SetDouble(const OH_PreferencesValue *object, double value)
Description
Sets a double value for an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| double value | Double value to be set. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_GetDouble()
int OH_PreferencesValue_GetDouble(const OH_PreferencesValue *object, double *value)
Description
Obtains a double value from an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| double *value | Pointer to the obtained double value. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_SetIntArray()
int OH_PreferencesValue_SetIntArray(const OH_PreferencesValue *object, const int *value, uint32_t count)
Description
Sets an integer array for an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| const int *value | Integer array to be set. |
| uint32_t count | Pointer to the size of the array to be set. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_GetIntArray()
int OH_PreferencesValue_GetIntArray(const OH_PreferencesValue *object, int **value, uint32_t *count)
Description
Obtains an integer array from an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| int **value | Double pointer to the obtained integer array. |
| uint32_t *count | Pointer to the size of the array obtained. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_SetBoolArray()
int OH_PreferencesValue_SetBoolArray(const OH_PreferencesValue *object, const bool *value, uint32_t count)
Description
Sets a boolean array for an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| const bool *value | Boolean array to be set. |
| uint32_t count | Pointer to the size of the array to be set. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_GetBoolArray()
int OH_PreferencesValue_GetBoolArray(const OH_PreferencesValue *object, bool **value, uint32_t *count)
Description
Obtains a boolean array from an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| bool **value | Double pointer to the obtained boolean array. |
| uint32_t *count | Pointer to the size of the array obtained. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_SetStringArray()
int OH_PreferencesValue_SetStringArray(const OH_PreferencesValue *object, const char **value, uint32_t count)
Description
Sets a string array for an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| const char **value | String array to be set. |
| uint32_t count | Pointer to the size of the array to be set. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_GetStringArray()
int OH_PreferencesValue_GetStringArray(const OH_PreferencesValue *object, char ***value, uint32_t *count)
Description
Obtains a string array of an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| char ***value | Double pointer to the obtained string array. |
| uint32_t *count | Pointer to the size of the array obtained. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_SetInt64Array()
int OH_PreferencesValue_SetInt64Array(const OH_PreferencesValue *object, const int64_t *value, uint32_t count)
Description
Sets an int64 array for an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| const int64_t *value | Int64 array to be set. |
| uint32_t count | Pointer to the size of the array to be set. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_GetInt64Array()
int OH_PreferencesValue_GetInt64Array(const OH_PreferencesValue *object, int64_t **value, uint32_t *count)
Description
Obtains an int64 array from an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| int64_t **value | Double pointer to the obtained int64 array. |
| uint32_t *count | Pointer to the size of the array obtained. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_SetDoubleArray()
int OH_PreferencesValue_SetDoubleArray(const OH_PreferencesValue *object, const double *value, uint32_t count)
Description
Sets a double array for an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| const double *value | Double array to be set. |
| uint32_t count | Pointer to the size of the array to be set. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_GetDoubleArray()
int OH_PreferencesValue_GetDoubleArray(const OH_PreferencesValue *object, double **value, uint32_t *count)
Description
Obtains a double array of an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| double **value | Double pointer to the obtained double array. |
| uint32_t *count | Pointer to the size of the array obtained. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_SetBlob()
int OH_PreferencesValue_SetBlob(const OH_PreferencesValue *object, const uint8_t *value, uint32_t count)
Description
Sets a blob value for an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| const uint8_t *value | Blob value to be set. |
| uint32_t count | Pointer to the size of the blob value to be set. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
OH_PreferencesValue_GetBlob()
int OH_PreferencesValue_GetBlob(const OH_PreferencesValue *object, uint8_t **value, uint32_t *count)
Description
Obtains a blob value from an OH_PreferencesValue instance.
Since: 23
Parameters
| Name | Description |
|---|---|
| const OH_PreferencesValue *object | Pointer to the target OH_PreferencesValue instance. |
| uint8_t **value | Double pointer to the obtained blob value. |
| uint32_t *count | Pointer to the size of the blob value obtained. |
Returns
| Type | Description |
|---|---|
| int | Returns an error code. PREFERENCES_OK indicates the operation is successful. PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified. PREFERENCES_ERROR_STORAGE indicates a storage exception. PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation. |
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 js-apis-distributedKVStore-sys
openharmony 鸿蒙 capi-oh-preferences-h
openharmony 鸿蒙 capi-udmf-oh-udshyperlink
openharmony 鸿蒙 js-apis-data-dataSharePredicates
openharmony 鸿蒙 capi-udmf-oh-udsappitem
openharmony 鸿蒙 capi-rdb-oh-data-vbuckets
openharmony 鸿蒙 capi-rdb-oh-predicates
openharmony 鸿蒙 capi-rdb-oh-data-value