• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# data_asset.h
2
3## Overview
4
5Defines data asset structs.<br>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.
6
7**File to include**: <database/rdb/data_asset.h>
8
9**Library**: libnative_rdb_ndk.z.so
10
11**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
12
13**Since**: 11
14
15**Related module**: [RDB](capi-rdb.md)
16
17## Summary
18
19### Structs
20
21| Name| typedef Keyword| Description|
22| -- | -- | -- |
23| [Data_Asset](capi-rdb-data-asset.md) | Data_Asset | Defines a struct for a data asset, which provides information about a data asset. |
24
25### Enums
26
27| Name| typedef Keyword| Description|
28| -- | -- | -- |
29| [Data_AssetStatus](#data_assetstatus) | Data_AssetStatus | Enumerates the data asset statuses.|
30
31### Functions
32
33| Name| Description|
34| -- | -- |
35| [int OH_Data_Asset_SetName(Data_Asset *asset, const char *name)](#oh_data_asset_setname) | Sets the name of an asset.|
36| [int OH_Data_Asset_SetUri(Data_Asset *asset, const char *uri)](#oh_data_asset_seturi) | Sets the absolute path (URI) of an asset in the system.|
37| [int OH_Data_Asset_SetPath(Data_Asset *asset, const char *path)](#oh_data_asset_setpath) | Sets the relative path of an asset in the application sandbox directory.|
38| [int OH_Data_Asset_SetCreateTime(Data_Asset *asset, int64_t createTime)](#oh_data_asset_setcreatetime) | Sets the creation time for an asset.|
39| [int OH_Data_Asset_SetModifyTime(Data_Asset *asset, int64_t modifyTime)](#oh_data_asset_setmodifytime) | Sets the last modification time for an asset.|
40| [int OH_Data_Asset_SetSize(Data_Asset *asset, size_t size)](#oh_data_asset_setsize) | Sets the size of an asset.|
41| [int OH_Data_Asset_SetStatus(Data_Asset *asset, Data_AssetStatus status)](#oh_data_asset_setstatus) | Sets the status of an asset.|
42| [int OH_Data_Asset_GetName(Data_Asset *asset, char *name, size_t *length)](#oh_data_asset_getname) | Obtains the name of a data asset.|
43| [int OH_Data_Asset_GetUri(Data_Asset *asset, char *uri, size_t *length)](#oh_data_asset_geturi) | Obtains the absolute path of a data asset.|
44| [int OH_Data_Asset_GetPath(Data_Asset *asset, char *path, size_t *length)](#oh_data_asset_getpath) | Obtains the relative path of an asset.|
45| [int OH_Data_Asset_GetCreateTime(Data_Asset *asset, int64_t *createTime)](#oh_data_asset_getcreatetime) | Obtains the creation time of a data asset.|
46| [int OH_Data_Asset_GetModifyTime(Data_Asset *asset, int64_t *modifyTime)](#oh_data_asset_getmodifytime) | Obtains the last modification time of an asset.|
47| [int OH_Data_Asset_GetSize(Data_Asset *asset, size_t *size)](#oh_data_asset_getsize) | Obtains the space occupied by an asset.|
48| [int OH_Data_Asset_GetStatus(Data_Asset *asset, Data_AssetStatus *status)](#oh_data_asset_getstatus) | Obtains the status of a data asset.|
49| [Data_Asset *OH_Data_Asset_CreateOne(void)](#oh_data_asset_createone) | Creates a [Data_Asset](capi-rdb-data-asset.md) instance.|
50| [int OH_Data_Asset_DestroyOne(Data_Asset *asset)](#oh_data_asset_destroyone) | Destroys an [Data_Asset](capi-rdb-data-asset.md) object and reclaims the memory occupied by the object.|
51| [Data_Asset **OH_Data_Asset_CreateMultiple(uint32_t count)](#oh_data_asset_createmultiple) | Creates a specified number of [Data_Asset](capi-rdb-data-asset.md) instances.|
52| [int OH_Data_Asset_DestroyMultiple(Data_Asset **assets, uint32_t count)](#oh_data_asset_destroymultiple) | Destroys multiple [Data_Asset](capi-rdb-data-asset.md) objects and reclaims the memory occupied by the objects.|
53
54## Enum Description
55
56### Data_AssetStatus
57
58```
59enum Data_AssetStatus
60```
61
62**Description**
63
64Enumerates the data asset statuses.
65
66**Since**: 11
67
68| Enum Item| Description|
69| -- | -- |
70| ASSET_NULL = 0 | The data asset is null.|
71| ASSET_NORMAL | The asset is in normal status.|
72| ASSET_INSERT | The asset is to be inserted to the cloud.|
73| ASSET_UPDATE | The asset is to be updated to the cloud.|
74| ASSET_DELETE | The asset is to be deleted from the cloud.|
75| ASSET_ABNORMAL | The asset is in abnormal status.|
76| ASSET_DOWNLOADING | The asset is being downloaded to a local device.|
77
78
79## Function Description
80
81### OH_Data_Asset_SetName()
82
83```
84int OH_Data_Asset_SetName(Data_Asset *asset, const char *name)
85```
86
87**Description**
88
89Sets the name of a data asset.
90
91**Since**: 11
92
93
94**Parameters**
95
96| Name| Description|
97| -- | -- |
98| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
99| const char *name | Pointer to the name to set.|
100
101**Returns**
102
103| Type| Description|
104| -- | -- |
105| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
106
107### OH_Data_Asset_SetUri()
108
109```
110int OH_Data_Asset_SetUri(Data_Asset *asset, const char *uri)
111```
112
113**Description**
114
115Sets the absolute path (URI) of an asset in the system.
116
117**Since**: 11
118
119
120**Parameters**
121
122| Name| Description|
123| -- | -- |
124| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
125| uri |  Pointer to the URI to set.|
126
127**Returns**
128
129| Type| Description                                                                                                                                         |
130| -- |---------------------------------------------------------------------------------------------------------------------------------------------|
131| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
132
133### OH_Data_Asset_SetPath()
134
135```
136int OH_Data_Asset_SetPath(Data_Asset *asset, const char *path)
137```
138
139**Description**
140
141Sets the relative path of an asset in the application sandbox directory.
142
143**Since**: 11
144
145
146**Parameters**
147
148| Name| Description|
149| -- | -- |
150| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
151| const char *path | Pointer to the relative path to set.|
152
153**Returns**
154
155| Type| Description|
156| -- | -- |
157| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
158
159### OH_Data_Asset_SetCreateTime()
160
161```
162int OH_Data_Asset_SetCreateTime(Data_Asset *asset, int64_t createTime)
163```
164
165**Description**
166
167Sets the creation time for an asset.
168
169**Since**: 11
170
171
172**Parameters**
173
174| Name| Description|
175| -- | -- |
176| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
177| int64_t createTime | Creation time to set.|
178
179**Returns**
180
181| Type| Description|
182| -- | -- |
183| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
184
185### OH_Data_Asset_SetModifyTime()
186
187```
188int OH_Data_Asset_SetModifyTime(Data_Asset *asset, int64_t modifyTime)
189```
190
191**Description**
192
193Sets the last modification time for a data asset.
194
195**Since**: 11
196
197
198**Parameters**
199
200| Name| Description|
201| -- | -- |
202| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
203| int64_t modifyTime | Last modification time to set.|
204
205**Returns**
206
207| Type| Description|
208| -- | -- |
209| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
210
211### OH_Data_Asset_SetSize()
212
213```
214int OH_Data_Asset_SetSize(Data_Asset *asset, size_t size)
215```
216
217**Description**
218
219Sets the size of an asset.
220
221**Since**: 11
222
223
224**Parameters**
225
226| Name| Description|
227| -- | -- |
228| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
229| size_t size | Size of the data asset to set.|
230
231**Returns**
232
233| Type| Description|
234| -- | -- |
235| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
236
237### OH_Data_Asset_SetStatus()
238
239```
240int OH_Data_Asset_SetStatus(Data_Asset *asset, Data_AssetStatus status)
241```
242
243**Description**
244
245Sets the status of an asset.
246
247**Since**: 11
248
249
250**Parameters**
251
252| Name| Description|
253| -- | -- |
254| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
255| [Data_AssetStatus](#data_assetstatus) status | Status to set. For details, see [Data_AssetStatus](capi-data-asset-h.md#data_assetstatus).|
256
257**Returns**
258
259| Type| Description|
260| -- | -- |
261| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
262
263### OH_Data_Asset_GetName()
264
265```
266int OH_Data_Asset_GetName(Data_Asset *asset, char *name, size_t *length)
267```
268
269**Description**
270
271Obtains the name of a data asset.
272
273**Since**: 11
274
275
276**Parameters**
277
278| Name| Description|
279| -- | -- |
280| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
281| char *name | Pointer to the data asset name obtained, in the form of a string.|
282| size_t *length | Pointer to the length of the name.|
283
284**Returns**
285
286| Type| Description|
287| -- | -- |
288| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_ERR** indicates that the execute function is abnormal.<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
289
290### OH_Data_Asset_GetUri()
291
292```
293int OH_Data_Asset_GetUri(Data_Asset *asset, char *uri, size_t *length)
294```
295
296**Description**
297
298Obtains the absolute path (URI) of a data asset.
299
300**Since**: 11
301
302
303**Parameters**
304
305| Name| Description|
306| -- | -- |
307| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
308| char *uri | Pointer to the absolute path of the data asset obtained, in the form of a string.|
309| size_t *length | Pointer to the length of the URI.|
310
311**Returns**
312
313| Type| Description|
314| -- | -- |
315| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_ERR** indicates that the execute function is abnormal.<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
316
317### OH_Data_Asset_GetPath()
318
319```
320int OH_Data_Asset_GetPath(Data_Asset *asset, char *path, size_t *length)
321```
322
323**Description**
324
325Obtains the relative path of a data asset.
326
327**Since**: 11
328
329
330**Parameters**
331
332| Name| Description|
333| -- | -- |
334| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
335| char *path | Pointer to the relative path of the data asset obtained, in the form of a string.|
336| size_t *length | Pointer to the length of the relative path.|
337
338**Returns**
339
340| Type| Description|
341| -- | -- |
342| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_ERR** indicates that the execute function is abnormal.<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
343
344### OH_Data_Asset_GetCreateTime()
345
346```
347int OH_Data_Asset_GetCreateTime(Data_Asset *asset, int64_t *createTime)
348```
349
350**Description**
351
352Obtains the creation time of a data asset.
353
354**Since**: 11
355
356
357**Parameters**
358
359| Name| Description|
360| -- | -- |
361| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
362| int64_t *createTime | Ponter to the creation time obtained, in int64_t format.|
363
364**Returns**
365
366| Type| Description|
367| -- | -- |
368| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_ERR** indicates that the execute function is abnormal.<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
369
370**See**
371
372Data_Asset
373
374### OH_Data_Asset_GetModifyTime()
375
376```
377int OH_Data_Asset_GetModifyTime(Data_Asset *asset, int64_t *modifyTime)
378```
379
380**Description**
381
382Obtains the last modification time of an asset.
383
384**Since**: 11
385
386
387**Parameters**
388
389| Name| Description|
390| -- | -- |
391| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
392| int64_t *modifyTime | Pointer to the last modification time obtained, in int64_t format.|
393
394**Returns**
395
396| Type| Description|
397| -- | -- |
398| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_ERR** indicates that the execute function is abnormal.<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
399
400### OH_Data_Asset_GetSize()
401
402```
403int OH_Data_Asset_GetSize(Data_Asset *asset, size_t *size)
404```
405
406**Description**
407
408Obtains the space occupied by an asset.
409
410**Since**: 11
411
412
413**Parameters**
414
415| Name| Description|
416| -- | -- |
417| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
418| size_t *size | Pointer to the data asset size obtained, in the format of size_t.|
419
420**Returns**
421
422| Type| Description|
423| -- | -- |
424| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_ERR** indicates that the execute function is abnormal.<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
425
426### OH_Data_Asset_GetStatus()
427
428```
429int OH_Data_Asset_GetStatus(Data_Asset *asset, Data_AssetStatus *status)
430```
431
432**Description**
433
434Obtains the status of a data asset.
435
436**Since**: 11
437
438
439**Parameters**
440
441| Name| Description|
442| -- | -- |
443| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
444| [Data_AssetStatus](#data_assetstatus) *status | Pointer to the [Data_AssetStatus](capi-data-asset-h.md#data_assetstatus) obtained.|
445
446**Returns**
447
448| Type| Description|
449| -- | -- |
450| int | Returns an error code. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).<br>**RDB_OK** indicates the operation is successful.<br>**RDB_E_INVALID_ARGS** indicates that invalid parameters are specified.|
451
452### OH_Data_Asset_CreateOne()
453
454```
455Data_Asset *OH_Data_Asset_CreateOne(void)
456```
457
458**Description**
459
460Creates a [Data_Asset](capi-rdb-data-asset.md) instance.
461
462**Since**: 11
463
464**Returns**
465
466| Type| Description|
467| -- | -- |
468| [Data_Asset](capi-rdb-data-asset.md) | Returns the pointer to the [Data_Asset](capi-rdb-data-asset.md) instance created if the operation is successful; returns null otherwise.|
469
470### OH_Data_Asset_DestroyOne()
471
472```
473int OH_Data_Asset_DestroyOne(Data_Asset *asset)
474```
475
476**Description**
477
478Destroys an [Data_Asset](capi-rdb-data-asset.md) object and reclaims the memory occupied by the object.
479
480**Since**: 11
481
482
483**Parameters**
484
485| Name| Description|
486| -- | -- |
487| [Data_Asset](capi-rdb-data-asset.md) *asset | Pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
488
489**Returns**
490
491| Type| Description|
492| -- | -- |
493| int | Returns **RDB_OK** if the operation is successful; returns an error code otherwise. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).|
494
495### OH_Data_Asset_CreateMultiple()
496
497```
498Data_Asset **OH_Data_Asset_CreateMultiple(uint32_t count)
499```
500
501**Description**
502
503Creates a specified number of [Data_Asset](capi-rdb-data-asset.md) instances.
504
505**Since**: 11
506
507
508**Parameters**
509
510| Name| Description|
511| -- | -- |
512| uint32_t count | Number of data assets to create.|
513
514**Returns**
515
516| Type| Description|
517| -- | -- |
518| [Data_Asset](capi-rdb-data-asset.md) | Returns the pointer to the [Data_Asset](capi-rdb-data-asset.md) instance created if the operation is successful; returns null otherwise.|
519
520### OH_Data_Asset_DestroyMultiple()
521
522```
523int OH_Data_Asset_DestroyMultiple(Data_Asset **assets, uint32_t count)
524```
525
526**Description**
527
528Destroys multiple [Data_Asset](capi-rdb-data-asset.md) objects and reclaims the memory occupied by the objects.
529
530**Since**: 11
531
532
533**Parameters**
534
535| Name| Description|
536| -- | -- |
537| [Data_Asset](capi-rdb-data-asset.md) **assets | Double pointer to the [Data_Asset](capi-rdb-data-asset.md) instance.|
538| uint32_t count | Number of [Data_Asset](capi-rdb-data-asset.md) objects to be destroyed.|
539
540**Returns**
541
542| Type| Description|
543| -- | -- |
544| int | Returns **RDB_OK** if the operation is successful; returns an error code otherwise. For details, see [OH_Rdb_ErrCode](capi-relational-store-error-code-h.md#oh_rdb_errcode).|
545