openharmony 鸿蒙 capi-data-asset-h

2026-08-25 浏览 (1)

data_asset.h

Overview

Defines data asset structs.
Asset is a data struct used in data management. You can use it to set and obtain file attributes, including the name, absolute path, relative path, creation time, modification time, status, and size of a file.

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

Library: libnative_rdb_ndk.z.so

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Since: 11

Related module: RDB

Summary

Structs

Nametypedef KeywordDescription
Data_AssetData_AssetDefines a struct for a data asset,
which provides information about a data asset.

Enums

Nametypedef KeywordDescription
Data_AssetStatusData_AssetStatusEnumerates the data asset statuses.

Functions

NameDescription
int OH_Data_Asset_SetName(Data_Asset *asset, const char *name)Sets the name of an asset.
int OH_Data_Asset_SetUri(Data_Asset *asset, const char *uri)Sets the absolute path (URI) of an asset in the system.
int OH_Data_Asset_SetPath(Data_Asset *asset, const char *path)Sets the relative path of an asset in the application sandbox directory.
int OH_Data_Asset_SetCreateTime(Data_Asset *asset, int64_t createTime)Sets the creation time for an asset.
int OH_Data_Asset_SetModifyTime(Data_Asset *asset, int64_t modifyTime)Sets the last modification time for an asset.
int OH_Data_Asset_SetSize(Data_Asset *asset, size_t size)Sets the size of an asset.
int OH_Data_Asset_SetStatus(Data_Asset *asset, Data_AssetStatus status)Sets the status of an asset.
int OH_Data_Asset_GetName(Data_Asset *asset, char *name, size_t *length)Obtains the name of a data asset.
int OH_Data_Asset_GetUri(Data_Asset *asset, char *uri, size_t *length)Obtains the absolute path of a data asset.
int OH_Data_Asset_GetPath(Data_Asset *asset, char *path, size_t *length)Obtains the relative path of an asset.
int OH_Data_Asset_GetCreateTime(Data_Asset *asset, int64_t *createTime)Obtains the creation time of a data asset.
int OH_Data_Asset_GetModifyTime(Data_Asset *asset, int64_t *modifyTime)Obtains the last modification time of an asset.
int OH_Data_Asset_GetSize(Data_Asset *asset, size_t *size)Obtains the space occupied by an asset.
int OH_Data_Asset_GetStatus(Data_Asset *asset, Data_AssetStatus *status)Obtains the status of a data asset.
Data_Asset *OH_Data_Asset_CreateOne(void)Creates a Data_Asset instance.
int OH_Data_Asset_DestroyOne(Data_Asset *asset)Destroys a Data_Asset object and reclaims the memory occupied by the object.
Data_Asset **OH_Data_Asset_CreateMultiple(uint32_t count)Creates a specified number of Data_Asset instances.
int OH_Data_Asset_DestroyMultiple(Data_Asset **assets, uint32_t count)Destroys multiple Data_Asset objects and reclaims the memory occupied by the objects.

Enum Description

Data_AssetStatus

enum Data_AssetStatus

Description

Enumerates the data asset statuses.

Since: 11

Enum ItemDescription
ASSET_NULL = 0The data asset is null.
ASSET_NORMALThe asset is in normal status.
ASSET_INSERTThe asset is to be inserted to the cloud.
ASSET_UPDATEThe asset is to be updated to the cloud.
ASSET_DELETEThe asset is to be deleted from the cloud.
ASSET_ABNORMALThe asset is in abnormal status.
ASSET_DOWNLOADINGThe asset is being downloaded to a local device.

Function Description

OH_Data_Asset_SetName()

int OH_Data_Asset_SetName(Data_Asset *asset, const char *name)

Description

Sets the name of an asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
const char *namePointer to the name to set.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_SetUri()

int OH_Data_Asset_SetUri(Data_Asset *asset, const char *uri)

Description

Sets the absolute path (URI) of an asset in the system.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
const char *uriPointer to the URI to set.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_SetPath()

int OH_Data_Asset_SetPath(Data_Asset *asset, const char *path)

Description

Sets the relative path of an asset in the application sandbox directory.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
const char *pathPointer to the relative path to set.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_SetCreateTime()

int OH_Data_Asset_SetCreateTime(Data_Asset *asset, int64_t createTime)

Description

Sets the creation time for an asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
int64_t createTimeCreation time to set. No specific unit. You can specify it.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_SetModifyTime()

int OH_Data_Asset_SetModifyTime(Data_Asset *asset, int64_t modifyTime)

Description

Sets the last modification time for a data asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
int64_t modifyTimeLast modification time to set. No specific unit. You can specify it.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_SetSize()

int OH_Data_Asset_SetSize(Data_Asset *asset, size_t size)

Description

Sets the size of an asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
size_t sizeSize of the data asset to set.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_SetStatus()

int OH_Data_Asset_SetStatus(Data_Asset *asset, Data_AssetStatus status)

Description

Sets the status of an asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
Data_AssetStatus statusStatus to set. For details, see Data_AssetStatus.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_GetName()

int OH_Data_Asset_GetName(Data_Asset *asset, char *name, size_t *length)

Description

Obtains the name of a data asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
char *namePointer to the data asset name obtained, in the form of a string.
size_t *lengthPointer to the length of the name.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_ERR indicates that the operation fails.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_GetUri()

int OH_Data_Asset_GetUri(Data_Asset *asset, char *uri, size_t *length)

Description

Obtains the absolute path (URI) of a data asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
char *uriPointer to the absolute path of the data asset obtained, in the form of a string.
size_t *lengthPointer to the length of the URI.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_ERR indicates that the operation fails.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_GetPath()

int OH_Data_Asset_GetPath(Data_Asset *asset, char *path, size_t *length)

Description

Obtains the relative path of a data asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
char *pathPointer to the relative path of the data asset obtained, in the form of a string.
size_t *lengthPointer to the length of the relative path.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_ERR indicates that the operation fails.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_GetCreateTime()

int OH_Data_Asset_GetCreateTime(Data_Asset *asset, int64_t *createTime)

Description

Obtains the creation time of a data asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
int64_t *createTimePointer to the creation time obtained, in int64_t format. No specific unit. You can specify it.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_ERR indicates that the operation fails.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

See

Data_Asset

OH_Data_Asset_GetModifyTime()

int OH_Data_Asset_GetModifyTime(Data_Asset *asset, int64_t *modifyTime)

Description

Obtains the last modification time of an asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
int64_t *modifyTimePointer to the last modification time obtained, in int64_t format. No specific unit. You can specify it.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_ERR indicates that the operation fails.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_GetSize()

int OH_Data_Asset_GetSize(Data_Asset *asset, size_t *size)

Description

Obtains the space occupied by an asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
size_t *sizePointer to the data asset size obtained, in the format of size_t.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_ERR indicates that the operation fails.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_GetStatus()

int OH_Data_Asset_GetStatus(Data_Asset *asset, Data_AssetStatus *status)

Description

Obtains the status of a data asset.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.
Data_AssetStatus *statusPointer to the Data_AssetStatus obtained.

Returns

TypeDescription
intReturns an error code. For details, see OH_Rdb_ErrCode.
RDB_OK indicates the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Data_Asset_CreateOne()

Data_Asset *OH_Data_Asset_CreateOne(void)

Description

Creates a Data_Asset instance.

Since: 11

Returns

TypeDescription
Data_AssetReturns the pointer to the Data_Asset instance created if the operation is successful; returns null otherwise.
After the instance is used, call the OH_Data_Asset_DestroyOne API to release the memory.

OH_Data_Asset_DestroyOne()

int OH_Data_Asset_DestroyOne(Data_Asset *asset)

Description

Destroys a Data_Asset object and reclaims the memory occupied by the object.

Since: 11

Parameters

NameDescription
Data_Asset *assetPointer to the Data_Asset instance.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise. For details, see OH_Rdb_ErrCode.

OH_Data_Asset_CreateMultiple()

Data_Asset **OH_Data_Asset_CreateMultiple(uint32_t count)

Description

Creates a specified number of Data_Asset instances.

Since: 11

Parameters

NameDescription
uint32_t countNumber of data assets to create.

Returns

TypeDescription
Data_AssetReturns the pointer to the Data_Asset instance created if the operation is successful; returns null otherwise.
After the instance is used, call the OH_Data_Asset_DestroyMultiple API to release the memory.

OH_Data_Asset_DestroyMultiple()

int OH_Data_Asset_DestroyMultiple(Data_Asset **assets, uint32_t count)

Description

Destroys multiple Data_Asset objects and reclaims the memory occupied by the objects.

Since: 11

Parameters

NameDescription
Data_Asset **assetsPointer to the Data_Asset instance.
uint32_t countNumber of Data_Asset objects to be destroyed.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise. For details, see OH_Rdb_ErrCode.

你可能感兴趣的鸿蒙文章

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/EcbIgnsr