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 /** 17 * @addtogroup RDB 18 * @{ 19 * 20 * @brief The relational database (RDB) store manages data based on relational models. 21 * With the underlying SQLite database, the RDB store provides a complete mechanism for managing local databases. 22 * To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations 23 * such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements. 24 * 25 * @since 10 26 */ 27 28 /** 29 * @file oh_values_bucket.h 30 * 31 * @brief Define the type of stored key value pairs. 32 * 33 * @kit ArkData 34 * @library libnative_rdb_ndk.so 35 * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core 36 * @since 10 37 */ 38 39 #ifndef OH_VALUES_BUCKET_H 40 #define OH_VALUES_BUCKET_H 41 42 #ifdef __cplusplus 43 #include <cstdint> 44 #else 45 #include <stdint.h> 46 #endif 47 48 #include "database/data/data_asset.h" 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 /** 54 * @brief Define the OH_VBucket structure type. 55 * 56 * @since 10 57 */ 58 typedef struct OH_VBucket OH_VBucket; 59 60 61 /** 62 * @brief Define the OH_VBucket structure type. 63 * 64 * @since 10 65 */ 66 struct OH_VBucket { 67 /** 68 * The id used to uniquely identify the OH_VBucket struct. 69 */ 70 int64_t id; 71 72 /** 73 * Indicates the capability of OH_VBucket. 74 */ 75 uint16_t capability; 76 77 /** 78 * @brief Put the const char * value to this {@link OH_VBucket} object for the given column name. 79 * 80 * @param bucket Represents a pointer to an {@link OH_VBucket} instance. 81 * @param field Indicates the name of the column. 82 * @param value Indicates the const char * value. 83 * @return Returns the status code of the execution. 84 * @see OH_VBucket. 85 * @since 10 86 */ 87 int (*putText)(OH_VBucket *bucket, const char *field, const char *value); 88 89 /** 90 * @brief Put the int64 value to this {@link OH_VBucket} object for the given column name. 91 * 92 * @param bucket Represents a pointer to an {@link OH_VBucket} instance. 93 * @param field Indicates the name of the column. 94 * @param value Indicates the int64 value. 95 * @return Returns the status code of the execution. 96 * @see OH_VBucket. 97 * @since 10 98 */ 99 int (*putInt64)(OH_VBucket *bucket, const char *field, int64_t value); 100 101 /** 102 * @brief Put the double value to this {@link OH_VBucket} object for the given column name. 103 * 104 * @param bucket Represents a pointer to an {@link OH_VBucket} instance. 105 * @param field Indicates the name of the column. 106 * @param value Indicates the double value. 107 * @return Returns the status code of the execution. 108 * @see OH_VBucket. 109 * @since 10 110 */ 111 int (*putReal)(OH_VBucket *bucket, const char *field, double value); 112 113 /** 114 * @brief Put the const uint8_t * value to this {@link OH_VBucket} object for the given column name. 115 * 116 * @param bucket Represents a pointer to an {@link OH_VBucket} instance. 117 * @param field Indicates the name of the column. 118 * @param value Indicates the const uint8_t * value. 119 * @param size Indicates the size of value. 120 * @return Returns the status code of the execution. 121 * @see OH_VBucket. 122 * @since 10 123 */ 124 int (*putBlob)(OH_VBucket *bucket, const char *field, const uint8_t *value, uint32_t size); 125 126 /** 127 * @brief Put NULL to this {@link OH_VBucket} object for the given column name. 128 * 129 * @param bucket Represents a pointer to an {@link OH_VBucket} instance. 130 * @param field Indicates the name of the column. 131 * @return Returns the status code of the execution. 132 * @see OH_VBucket. 133 * @since 10 134 */ 135 int (*putNull)(OH_VBucket *bucket, const char *field); 136 137 /** 138 * @brief Clear the {@link OH_VBucket} object's values. 139 * 140 * @param bucket Represents a pointer to an {@link OH_VBucket} instance. 141 * @return Returns the status code of the execution. 142 * @see OH_VBucket. 143 * @since 10 144 */ 145 int (*clear)(OH_VBucket *bucket); 146 147 /** 148 * @brief Destroy the {@link OH_VBucket} object and reclaim the memory occupied by the object. 149 * 150 * @param bucket Represents a pointer to an {@link OH_VBucket} instance. 151 * @return Returns the status code of the execution. 152 * @see OH_VBucket. 153 * @since 10 154 */ 155 int (*destroy)(OH_VBucket *bucket); 156 }; 157 158 /** 159 * @brief Put the {@link Data_Asset} * value 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 const {@link Data_Asset} * 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_PutAsset(OH_VBucket *bucket, const char *field, Data_Asset *value); 171 172 /** 173 * @brief Put the {@link Data_Asset} * value of given count to this {@link OH_VBucket} object for the given column name. 174 * 175 * @param bucket Represents a pointer to an {@link OH_VBucket} instance. 176 * @param field Indicates the name of the column. 177 * @param value Indicates the {@link Data_Asset} value of given count. 178 * @param count Indicates the count of value. 179 * @return Returns the status code of the execution. 180 * {@link RDB_OK} - success. 181 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 182 * @see OH_VBucket. 183 * @since 11 184 */ 185 int OH_VBucket_PutAssets(OH_VBucket *bucket, const char *field, Data_Asset **value, uint32_t count); 186 187 /** 188 * @brief Put the float vector to the OH_VBucket object. 189 * 190 * @param bucket Represents a pointer to an {@link OH_VBucket} instance. 191 * @param field Represents the name of the column. 192 * @param vec Represents a pointer to float array. 193 * @param len Represents the size of float array. 194 * @return Returns the status code of the execution. 195 * {@link RDB_OK} - success. 196 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 197 * @see OH_VBucket. 198 * @since 18 199 */ 200 int OH_VBucket_PutFloatVector(OH_VBucket *bucket, const char *field, const float *vec, size_t len); 201 202 /** 203 * @brief Put the an integer of any length to the OH_VBucket object. 204 * 205 * @param bucket Represents a pointer to an {@link OH_VBucket} instance. 206 * @param field Represents the name of the column. 207 * @param sign Represents 0 is positive integer, 1 is negative integer. 208 * @param trueForm Represents a pointer to integer array. 209 * @param len Represents the size of integer array. 210 * @return Returns the status code of the execution. 211 * {@link RDB_OK} - success. 212 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 213 * @see OH_VBucket. 214 * @since 18 215 */ 216 int OH_VBucket_PutUnlimitedInt(OH_VBucket *bucket, const char *field, int sign, const uint64_t *trueForm, size_t len); 217 #ifdef __cplusplus 218 }; 219 #endif 220 221 /** @} */ 222 223 #endif // OH_VALUES_BUCKET_H 224