1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OH_VALUES_BUCKET_H
17 #define OH_VALUES_BUCKET_H
18 
19 /**
20  * @addtogroup RDB
21  * @{
22  *
23  * @brief The relational database (RDB) store manages data based on relational models.
24  * With the underlying SQLite database, the RDB store provides a complete mechanism for managing local databases.
25  * To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations
26  * such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements.
27  *
28  * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core
29  * @since 10
30  */
31 
32 /**
33  * @file oh_values_bucket.h
34  *
35  * @brief Define the type of stored key value pairs.
36  *
37  * @kit ArkData
38  * @since 10
39  */
40 
41 #include <cstdint>
42 #include "database/data/data_asset.h"
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /**
48  * @brief Define the OH_VBucket structure type.
49  *
50  * @since 10
51  */
52 typedef struct OH_VBucket {
53     /**
54      * The id used to uniquely identify the OH_VBucket struct.
55      */
56     int64_t id;
57 
58     /**
59      * Indicates the capability of OH_VBucket.
60      */
61     uint16_t capability;
62 
63     /**
64      * @brief Put the const char * value to this {@link OH_VBucket} object for the given column name.
65      *
66      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
67      * @param field Indicates the name of the column.
68      * @param value Indicates the const char * value.
69      * @return Returns the status code of the execution.
70      * @see OH_VBucket.
71      * @since 10
72      */
73     int (*putText)(OH_VBucket *bucket, const char *field, const char *value);
74 
75     /**
76      * @brief Put the int64 value to this {@link OH_VBucket} object for the given column name.
77      *
78      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
79      * @param field Indicates the name of the column.
80      * @param value Indicates the int64 value.
81      * @return Returns the status code of the execution.
82      * @see OH_VBucket.
83      * @since 10
84      */
85     int (*putInt64)(OH_VBucket *bucket, const char *field, int64_t value);
86 
87     /**
88      * @brief Put the double value to this {@link OH_VBucket} object for the given column name.
89      *
90      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
91      * @param field Indicates the name of the column.
92      * @param value Indicates the double value.
93      * @return Returns the status code of the execution.
94      * @see OH_VBucket.
95      * @since 10
96      */
97     int (*putReal)(OH_VBucket *bucket, const char *field, double value);
98 
99     /**
100      * @brief Put the const uint8_t * value to this {@link OH_VBucket} object for the given column name.
101      *
102      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
103      * @param field Indicates the name of the column.
104      * @param value Indicates the const uint8_t * value.
105      * @param size Indicates the size of value.
106      * @return Returns the status code of the execution.
107      * @see OH_VBucket.
108      * @since 10
109      */
110     int (*putBlob)(OH_VBucket *bucket, const char *field, const uint8_t *value, uint32_t size);
111 
112     /**
113      * @brief Put NULL to this {@link OH_VBucket} object for the given column name.
114      *
115      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
116      * @param field Indicates the name of the column.
117      * @return Returns the status code of the execution.
118      * @see OH_VBucket.
119      * @since 10
120      */
121     int (*putNull)(OH_VBucket *bucket, const char *field);
122 
123     /**
124      * @brief Clear the {@link OH_VBucket} object's values.
125      *
126      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
127      * @return Returns the status code of the execution.
128      * @see OH_VBucket.
129      * @since 10
130      */
131     int (*clear)(OH_VBucket *bucket);
132 
133     /**
134      * @brief Destroy the {@link OH_VBucket} object and reclaim the memory occupied by the object.
135      *
136      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
137      * @return Returns the status code of the execution.
138      * @see OH_VBucket.
139      * @since 10
140      */
141     int (*destroy)(OH_VBucket *bucket);
142 } OH_VBucket;
143 
144 /**
145  * @brief Put the {@link Data_Asset} * value to this {@link OH_VBucket} object for the given column name.
146  *
147  * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
148  * @param field Indicates the name of the column.
149  * @param value Indicates the const {@link Data_Asset} * value.
150  * @return Returns the status code of the execution.
151  *     {@link RDB_OK} - success.
152  *     {@link RDB_E_INVALID_ARGS} - The error code for common invalid args.
153  * @see OH_VBucket.
154  * @since 11
155  */
156 int OH_VBucket_PutAsset(OH_VBucket *bucket, const char *field, Data_Asset *value);
157 
158 /**
159  * @brief Put the {@link Data_Asset} * value of given count to this {@link OH_VBucket} object for the given column name.
160  *
161  * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
162  * @param field Indicates the name of the column.
163  * @param value Indicates the {@link Data_Asset} value of given count.
164  * @param count Indicates the count of value.
165  * @return Returns the status code of the execution.
166  *     {@link RDB_OK} - success.
167  *     {@link RDB_E_INVALID_ARGS} - The error code for common invalid args.
168  * @see OH_VBucket.
169  * @since 11
170  */
171 int OH_VBucket_PutAssets(OH_VBucket *bucket, const char *field, Data_Asset **value, uint32_t count);
172 #ifdef __cplusplus
173 };
174 #endif
175 
176 #endif // OH_VALUES_BUCKET_H
177