openharmony 鸿蒙 capi-oh-data-value-h

2026-08-25 浏览 (1)

oh_data_value.h

Overview

Defines APIs and enums related to a single data value.
Since API version 18, OH_ColumnType is moved from oh_cursor.h to this file. This type is supported in versions earlier than API version 18 and can be used in all versions.

File to include: <database/data/oh_data_value.h>

Library: libnative_rdb_ndk.z.so

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Since: 18

Related module: RDB

Summary

Structs

Nametypedef KeywordDescription
OH_Data_ValueOH_Data_ValueDefines the OH_Data_Value struct.

Enums

Nametypedef KeywordDescription
OH_ColumnTypeOH_ColumnTypeEnumerates the column types.

Functions

NameDescription
OH_Data_Value *OH_Value_Create(void)Creates an OH_Data_Values instance to store a single KV pair.
int OH_Value_Destroy(OH_Data_Value *value)Destroys an OH_Data_Value instance.
int OH_Value_PutNull(OH_Data_Value *value)Adds empty data to an OH_Data_Value instance.
int OH_Value_PutInt(OH_Data_Value *value, int64_t val)Adds an integer to an OH_Data_Value instance.
int OH_Value_PutReal(OH_Data_Value *value, double val)Adds REAL data to an OH_Data_Value instance.
int OH_Value_PutText(OH_Data_Value *value, const char *val)Adds a string to an OH_Data_Value instance.
int OH_Value_PutBlob(OH_Data_Value *value, const unsigned char *val, size_t length)Adds BLOB data to an OH_Data_Value instance.
int OH_Value_PutAsset(OH_Data_Value *value, const Data_Asset *val)Adds an asset to an OH_Data_Value instance.
int OH_Value_PutAssets(OH_Data_Value *value, const Data_Asset * const * val, size_t length)Adds assets to an OH_Data_Value instance.
int OH_Value_PutFloatVector(OH_Data_Value *value, const float *val, size_t length)Adds a float array to an OH_Data_Value instance.
int OH_Value_PutUnlimitedInt(OH_Data_Value *value, int sign, const uint64_t *trueForm, size_t length)Adds an integer array of any length to an OH_Data_Value instance.
int OH_Value_GetType(OH_Data_Value *value, OH_ColumnType *type)Obtains the type of a value in an OH_Data_Values instance.
int OH_Value_IsNull(OH_Data_Value *value, bool *val)Checks whether a value is null.
int OH_Value_GetInt(OH_Data_Value *value, int64_t *val)Obtains the integer from an OH_Data_Value instance.
int OH_Value_GetReal(OH_Data_Value *value, double *val)Obtains the REAL data from an OH_Data_Value instance.
int OH_Value_GetText(OH_Data_Value *value, const char **val)Obtains the string from an OH_Data_Value instance.
int OH_Value_GetBlob(OH_Data_Value *value, const uint8_t **val, size_t *length)Obtains the BLOB data from an OH_Data_Value instance.
int OH_Value_GetAsset(OH_Data_Value *value, Data_Asset *val)Obtains the asset from an OH_Data_Value instance.
int OH_Value_GetAssetsCount(OH_Data_Value *value, size_t *length)Obtains the length of the assets in an OH_Data_Value instance.
int OH_Value_GetAssets(OH_Data_Value *value, Data_Asset **val, size_t inLen, size_t *outLen)Obtains the assets from an OH_Data_Value instance.
int OH_Value_GetFloatVectorCount(OH_Data_Value *value, size_t *length)Obtains the length of the float array in an OH_Data_Values instance.
int OH_Value_GetFloatVector(OH_Data_Value *value, float *val, size_t inLen, size_t *outLen)Obtains the float array from an OH_Data_Values instance.
int OH_Value_GetUnlimitedIntBand(OH_Data_Value *value, size_t *length)Obtains the length of the unlimited integer from an OH_Data_Value instance.
int OH_Value_GetUnlimitedInt(OH_Data_Value *value, int *sign, uint64_t *trueForm, size_t inLen, size_t *outLen)Obtains the unlimited integer from an OH_Data_Value instance.

Enum Description

OH_ColumnType

enum OH_ColumnType

Description

Enumerates the column types.

Since: 10

Enum ItemDescription
TYPE_NULL = 0NULL.
TYPE_INT64INT64.
TYPE_REALREAL.
TYPE_TEXTTEXT.
TYPE_BLOBBLOB.
TYPE_ASSETASSET (asset attachment).
Since: 11
TYPE_ASSETSASSETS (multiple asset attachments).
Since: 11
TYPE_FLOAT_VECTORFLOAT VECTOR.
Since: 18
TYPE_UNLIMITED_INTNumber longer than 64 digits.
Since: 18

Function Description

OH_Value_Create()

OH_Data_Value *OH_Value_Create(void)

Description

Creates an OH_Data_Values instance to store a single KV pair.

Since: 18

Returns

TypeDescription
OH_Data_ValueReturns a pointer to the OH_Data_Value instance if the operation is successful; returns nullptr otherwise.
Use OH_Value_Destroy to release the memory in time.

OH_Value_Destroy()

int OH_Value_Destroy(OH_Data_Value *value)

Description

Destroys an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_PutNull()

int OH_Value_PutNull(OH_Data_Value *value)

Description

Adds empty data to an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_PutInt()

int OH_Value_PutInt(OH_Data_Value *value, int64_t val)

Description

Adds an integer to an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
int64_t valInteger to add.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_PutReal()

int OH_Value_PutReal(OH_Data_Value *value, double val)

Description

Adds REAL data to an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
double valREAL data to add.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_PutText()

int OH_Value_PutText(OH_Data_Value *value, const char *val)

Description

Adds a string to an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
const char *valPointer to the string to add.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_PutBlob()

int OH_Value_PutBlob(OH_Data_Value *value, const unsigned char *val, size_t length)

Description

Adds BLOB data to an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
const unsigned char *valPointer to the BLOB data to add.
size_t lengthLength of the BLOB data to add.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_PutAsset()

int OH_Value_PutAsset(OH_Data_Value *value, const Data_Asset *val)

Description

Adds an asset to an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
const Data_Asset *valPointer to the Data_Asset instance.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_PutAssets()

int OH_Value_PutAssets(OH_Data_Value *value, const Data_Asset * const * val, size_t length)

Description

Adds assets to an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
const Data_Asset * const * valPointer to the Data_Asset instance.
size_t lengthNumber of elements in the Data_Asset object to add.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_PutFloatVector()

int OH_Value_PutFloatVector(OH_Data_Value *value, const float *val, size_t length)

Description

Adds a float array to an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
const float *valPointer to the float array to add.
size_t lengthLength of the float array to add.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_PutUnlimitedInt()

int OH_Value_PutUnlimitedInt(OH_Data_Value *value, int sign, const uint64_t *trueForm, size_t length)

Description

Adds an integer array of any length to an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
int signSign notation of the integer array to add. The value 0 indicates a positive integer, and the value 1 indicates a negative integer.
const uint64_t *trueFormPointer to the integer array to add.
size_t lengthLength of the integer array to add.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_GetType()

int OH_Value_GetType(OH_Data_Value *value, OH_ColumnType *type)

Description

Obtains the data type.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
OH_ColumnType *typePointer to the data type obtained.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_IsNull()

int OH_Value_IsNull(OH_Data_Value *value, bool *val)

Description

Checks whether a value is null.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
bool *valPointer to the check result. The value true means the value is empty, and the value false means the opposite.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.

OH_Value_GetInt()

int OH_Value_GetInt(OH_Data_Value *value, int64_t *val)

Description

Obtains the integer from an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
int64_t *valPointer to the integer data obtained.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.
RDB_E_DATA_TYPE_NULL indicates the stored data is empty.
RDB_E_TYPE_MISMATCH indicates the data types do not match.

OH_Value_GetReal()

int OH_Value_GetReal(OH_Data_Value *value, double *val)

Description

Obtains the REAL data from an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
double *valPointer to the REAL data obtained.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.
RDB_E_DATA_TYPE_NULL indicates the stored data is empty.
RDB_E_TYPE_MISMATCH indicates the data types do not match.

OH_Value_GetText()

int OH_Value_GetText(OH_Data_Value *value, const char **val)

Description

Obtains the string from an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
const char **valDouble pointer to the string obtained.
You do not need to apply for or release memory for it.
The lifecycle of val complies with the value of index in value.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.
RDB_E_DATA_TYPE_NULL indicates the stored data is empty.
RDB_E_TYPE_MISMATCH indicates the data types do not match.

OH_Value_GetBlob()

int OH_Value_GetBlob(OH_Data_Value *value, const uint8_t **val, size_t *length)

Description

Obtains the BLOB data from an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
const uint8_t **valDouble pointer to the BLOB data obtained.
You do not need to apply for or release memory for it.
The lifecycle of val complies with the value of index in value.
size_t *lengthPointer to the length of the BLOB data obtained.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.
RDB_E_DATA_TYPE_NULL indicates the stored data is empty.
RDB_E_TYPE_MISMATCH indicates the data types do not match.

OH_Value_GetAsset()

int OH_Value_GetAsset(OH_Data_Value *value, Data_Asset *val)

Description

Obtains the asset from an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
Data_Asset *valPointer to the Data_Asset instance.
Data memory should be requested.
This function is used to fill in data only. Otherwise, the operation fails.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.
RDB_E_DATA_TYPE_NULL indicates the stored data is empty.
RDB_E_TYPE_MISMATCH indicates the data types do not match.

OH_Value_GetAssetsCount()

int OH_Value_GetAssetsCount(OH_Data_Value *value, size_t *length)

Description

Obtains the length of the assets in an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
size_t *lengthPointer to the length of the ASSETS data obtained.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.
RDB_E_DATA_TYPE_NULL indicates the stored data is empty.
RDB_E_TYPE_MISMATCH indicates the data types do not match.

OH_Value_GetAssets()

int OH_Value_GetAssets(OH_Data_Value *value, Data_Asset **val, size_t inLen, size_t *outLen)

Description

Obtains the assets from an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
Data_Asset **valDouble pointer to the Data_Asset instance.
Data memory should be requested.
This function is used to fill in data only. Otherwise, the operation fails.
size_t inLenSize of val, which can be obtained using OH_Values_GetAssetsCount.
size_t *outLenPointer to the actual length of the data obtained.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.
RDB_E_DATA_TYPE_NULL indicates the stored data is empty.
RDB_E_TYPE_MISMATCH indicates the data types do not match.

OH_Value_GetFloatVectorCount()

int OH_Value_GetFloatVectorCount(OH_Data_Value *value, size_t *length)

Description

Obtains the length of the float array in an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
size_t *lengthPointer to the length of the float data obtained.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.
RDB_E_DATA_TYPE_NULL indicates the stored data is empty.
RDB_E_TYPE_MISMATCH indicates the data types do not match.

OH_Value_GetFloatVector()

int OH_Value_GetFloatVector(OH_Data_Value *value, float *val, size_t inLen, size_t *outLen)

Description

Obtains the float array from an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
float *valPointer to the float array obtained.
Data memory should be requested.
This function is used to fill in data only. Otherwise, the operation fails.
size_t inLenSize of val, which can be obtained using OH_Values_GetFloatVectorCount.
size_t *outLenPointer to the actual length of the data obtained.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.
RDB_E_DATA_TYPE_NULL indicates the stored data is empty.
RDB_E_TYPE_MISMATCH indicates the data types do not match.

OH_Value_GetUnlimitedIntBand()

int OH_Value_GetUnlimitedIntBand(OH_Data_Value *value, size_t *length)

Description

Obtains the length of the unlimited integer from an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
size_t *lengthPointer to the length of the integer obtained.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.
RDB_E_DATA_TYPE_NULL indicates the stored data is empty.
RDB_E_TYPE_MISMATCH indicates the data types do not match.

OH_Value_GetUnlimitedInt()

int OH_Value_GetUnlimitedInt(OH_Data_Value *value, int *sign, uint64_t *trueForm, size_t inLen, size_t *outLen)

Description

Obtains the unlimited integer from an OH_Data_Value instance.

Since: 18

Parameters

NameDescription
OH_Data_Value *valuePointer to the OH_Data_Value instance.
int *signPointer to the sign notation of the integer obtained. The value 0 indicates a positive integer, and the value 1 indicates a negative integer.
uint64_t *trueFormPointer to the integer array obtained.
Data memory should be requested.
This function is used to fill in data only. Otherwise, the operation fails.
size_t inLentrueForm length, which can be obtained using OH_Values_GetUnlimitedIntBand.
size_t *outLenPointer to the actual length of the data obtained.

Returns

TypeDescription
intReturns an error code.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates the parameters are invalid.
RDB_E_DATA_TYPE_NULL indicates the stored data is empty.
RDB_E_TYPE_MISMATCH indicates the data types do not match.

你可能感兴趣的鸿蒙文章

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

openharmony 鸿蒙 capi-preferences-oh-preferencespair

openharmony 鸿蒙 errorcode-datashare

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/2HbkgsGF