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  * @since 10
38  */
39 
40 #include <cstdint>
41 #include "data_asset.h"
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * @brief Define the OH_VBucket structure type.
48  *
49  * @since 10
50  */
51 typedef struct OH_VBucket {
52     /**
53      * The id used to uniquely identify the OH_VBucket struct.
54      */
55     int64_t id;
56 
57     /**
58      * Indicates the capability of OH_VBucket.
59      */
60     uint16_t capability;
61 
62     /**
63      * @brief Put the const char * value to this {@link OH_VBucket} object for the given column name.
64      *
65      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
66      * @param field Indicates the name of the column.
67      * @param value Indicates the const char * value.
68      * @return Returns the status code of the execution.
69      * @see OH_VBucket.
70      * @since 10
71      */
72     int (*putText)(OH_VBucket *bucket, const char *field, const char *value);
73 
74     /**
75      * @brief Put the int64 value to this {@link OH_VBucket} object for the given column name.
76      *
77      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
78      * @param field Indicates the name of the column.
79      * @param value Indicates the int64 value.
80      * @return Returns the status code of the execution.
81      * @see OH_VBucket.
82      * @since 10
83      */
84     int (*putInt64)(OH_VBucket *bucket, const char *field, int64_t value);
85 
86     /**
87      * @brief Put the double value to this {@link OH_VBucket} object for the given column name.
88      *
89      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
90      * @param field Indicates the name of the column.
91      * @param value Indicates the double value.
92      * @return Returns the status code of the execution.
93      * @see OH_VBucket.
94      * @since 10
95      */
96     int (*putReal)(OH_VBucket *bucket, const char *field, double value);
97 
98     /**
99      * @brief Put the const uint8_t * value to this {@link OH_VBucket} object for the given column name.
100      *
101      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
102      * @param field Indicates the name of the column.
103      * @param value Indicates the const uint8_t * value.
104      * @param size Indicates the size of value.
105      * @return Returns the status code of the execution.
106      * @see OH_VBucket.
107      * @since 10
108      */
109     int (*putBlob)(OH_VBucket *bucket, const char *field, const uint8_t *value, uint32_t size);
110 
111     /**
112      * @brief Put NULL to this {@link OH_VBucket} object for the given column name.
113      *
114      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
115      * @param field Indicates the name of the column.
116      * @return Returns the status code of the execution.
117      * @see OH_VBucket.
118      * @since 10
119      */
120     int (*putNull)(OH_VBucket *bucket, const char *field);
121 
122     /**
123      * @brief Clear the {@link OH_VBucket} object's values.
124      *
125      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
126      * @return Returns the status code of the execution.
127      * @see OH_VBucket.
128      * @since 10
129      */
130     int (*clear)(OH_VBucket *bucket);
131 
132     /**
133      * @brief Destroy the {@link OH_VBucket} object and reclaim the memory occupied by the object.
134      *
135      * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
136      * @return Returns the status code of the execution.
137      * @see OH_VBucket.
138      * @since 10
139      */
140     int (*destroy)(OH_VBucket *bucket);
141 } OH_VBucket;
142 
143 /**
144  * @brief Put the {@link Data_Asset} * value to this {@link OH_VBucket} object for the given column name.
145  *
146  * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
147  * @param field Indicates the name of the column.
148  * @param value Indicates the const {@link Data_Asset} * value.
149  * @return Returns the status code of the execution.
150  *     {@link RDB_OK} - success.
151  *     {@link RDB_E_INVALID_ARGS} - The error code for common invalid args.
152  * @see OH_VBucket.
153  * @since 11
154  */
155 int OH_VBucket_PutAsset(OH_VBucket *bucket, const char *field, Data_Asset *value);
156 
157 /**
158  * @brief Put the {@link Data_Asset} * value of given count to this {@link OH_VBucket} object for the given column name.
159  *
160  * @param bucket Represents a pointer to an {@link OH_VBucket} instance.
161  * @param field Indicates the name of the column.
162  * @param value Indicates the {@link Data_Asset} value of given count.
163  * @param count Indicates the count of value.
164  * @return Returns the status code of the execution.
165  *     {@link RDB_OK} - success.
166  *     {@link RDB_E_INVALID_ARGS} - The error code for common invalid args.
167  * @see OH_VBucket.
168  * @since 11
169  */
170 int OH_VBucket_PutAssets(OH_VBucket *bucket, const char *field, Data_Asset **value, uint32_t count);
171 #ifdef __cplusplus
172 };
173 #endif
174 
175 #endif // OH_VALUES_BUCKET_H
176