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 relational_store.h 30 * 31 * @brief Provides database related functions and enumerations. 32 * 33 * @kit ArkData 34 * @library libnative_rdb_ndk.so 35 * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core 36 * @since 10 37 */ 38 39 #ifndef RELATIONAL_STORE_H 40 #define RELATIONAL_STORE_H 41 42 #include "database/rdb/oh_cursor.h" 43 #include "database/rdb/oh_predicates.h" 44 #include "database/rdb/oh_value_object.h" 45 #include "database/rdb/oh_values_bucket.h" 46 #include "database/rdb/oh_rdb_transaction.h" 47 #include "database/rdb/oh_rdb_types.h" 48 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 /** 54 * @brief Describe the security level of the database. 55 * 56 * @since 10 57 */ 58 typedef enum OH_Rdb_SecurityLevel { 59 /** 60 * @brief Low-level security. Data leaks have a minor impact. 61 */ 62 S1 = 1, 63 /** 64 * @brief Medium-level security. Data leaks have a major impact. 65 */ 66 S2, 67 /** 68 * @brief High-level security. Data leaks have a severe impact. 69 */ 70 S3, 71 /** 72 * @brief Critical-level security. Data leaks have a critical impact. 73 */ 74 S4 75 } OH_Rdb_SecurityLevel; 76 77 /** 78 * @brief Describe the security area of the database. 79 * 80 * @since 11 81 */ 82 typedef enum Rdb_SecurityArea { 83 /** 84 * @brief Security Area 1. 85 */ 86 RDB_SECURITY_AREA_EL1 = 1, 87 /** 88 * @brief Security Area 2. 89 */ 90 RDB_SECURITY_AREA_EL2, 91 /** 92 * @brief Security Area 3. 93 */ 94 RDB_SECURITY_AREA_EL3, 95 /** 96 * @brief Security Area 4. 97 */ 98 RDB_SECURITY_AREA_EL4, 99 100 /** 101 * @brief Security Area 5. 102 * 103 * @since 12 104 */ 105 RDB_SECURITY_AREA_EL5, 106 } Rdb_SecurityArea; 107 108 /** 109 * @brief Manages relational database configurations. 110 * @since 10 111 */ 112 #pragma pack(1) 113 typedef struct { 114 /** 115 * Indicates the size of the {@link OH_Rdb_Config}. It is mandatory. 116 */ 117 int selfSize; 118 /** 119 * Indicates the directory of the database. 120 */ 121 const char *dataBaseDir; 122 /** 123 * Indicates the name of the database. 124 */ 125 const char *storeName; 126 /** 127 * Indicates the bundle name of the application. 128 */ 129 const char *bundleName; 130 /** 131 * Indicates the module name of the application. 132 */ 133 const char *moduleName; 134 /** 135 * Indicates whether the database is encrypted. 136 */ 137 bool isEncrypt; 138 /** 139 * Indicates the security level {@link OH_Rdb_SecurityLevel} of the database. 140 */ 141 int securityLevel; 142 /** 143 * Indicates the security area {@link Rdb_SecurityArea} of the database. 144 * 145 * @since 11 146 */ 147 int area; 148 } OH_Rdb_Config; 149 #pragma pack() 150 151 /** 152 * @brief Define OH_Rdb_Store type. 153 * 154 * @since 10 155 */ 156 typedef struct { 157 /** 158 * The id used to uniquely identify the OH_Rdb_Store struct. 159 */ 160 int64_t id; 161 } OH_Rdb_Store; 162 163 /** 164 * @brief Define OH_Rdb_ConfigV2 type. 165 * 166 * @since 14 167 */ 168 typedef struct OH_Rdb_ConfigV2 OH_Rdb_ConfigV2; 169 170 /** 171 * @brief Define Rdb_DBType type. 172 * 173 * @since 14 174 */ 175 typedef enum Rdb_DBType { 176 /** 177 * @brief Means using SQLITE as the db kernal 178 */ 179 RDB_SQLITE = 1, 180 /** 181 * @brief Means using CARLEY_DB as the db kernal 182 */ 183 RDB_CAYLEY = 2, 184 /** 185 * @brief Means largest value for Rdb_DBType 186 */ 187 DBTYPE_BUTT = 64, 188 } Rdb_DBType; 189 190 /** 191 * @brief Define Rdb_Tokenizer type. 192 * 193 * @since 17 194 */ 195 typedef enum Rdb_Tokenizer { 196 /** 197 * @brief Means not using tokenizer. 198 * @since 17 199 */ 200 RDB_NONE_TOKENIZER = 1, 201 /** 202 * @brief Means using native icu tokenizer. 203 * @since 17 204 */ 205 RDB_ICU_TOKENIZER = 2, 206 /** 207 * @brief Means using self-developed enhance tokenizer. 208 * @since 18 209 */ 210 RDB_CUSTOM_TOKENIZER = 3, 211 } Rdb_Tokenizer; 212 213 /** 214 * @brief Create OH_Rdb_ConfigV2 which is used to open store 215 * 216 * @return Returns the newly created OH_Rdb_ConfigV2 object. If NULL is returned, the creation fails. 217 * The possible cause is that the address space of the application is full, As a result, the space 218 * cannot be allocated. 219 * @see OH_Rdb_ConfigV2 220 * @since 14 221 */ 222 OH_Rdb_ConfigV2 *OH_Rdb_CreateConfig(); 223 224 /** 225 * @brief Destroy OH_Rdb_ConfigV2 which is created by OH_Rdb_CreateConfig 226 * 227 * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. 228 * Indicates the configuration of the database related to this RDB store. 229 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 230 * {@link RDB_OK} - success. 231 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 232 * @since 14 233 */ 234 int OH_Rdb_DestroyConfig(OH_Rdb_ConfigV2 *config); 235 236 /** 237 * @brief Set property databaseDir into config 238 * 239 * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. 240 * Indicates the configuration of the database related to this RDB store. 241 * @param databaseDir Indicates the directory of the database. 242 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 243 * {@link RDB_OK} - success. 244 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 245 * @since 14 246 */ 247 int OH_Rdb_SetDatabaseDir(OH_Rdb_ConfigV2 *config, const char *databaseDir); 248 249 /** 250 * @brief Set property storeName into config 251 * 252 * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. 253 * Indicates the configuration of the database related to this RDB store. 254 * @param storeName Indicates the name of the database. 255 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 256 * {@link RDB_OK} - success. 257 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 258 * @since 14 259 */ 260 int OH_Rdb_SetStoreName(OH_Rdb_ConfigV2 *config, const char *storeName); 261 262 /** 263 * @brief Set property bundleName into config 264 * 265 * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. 266 * Indicates the configuration of the database related to this RDB store. 267 * @param bundleName Indicates the bundle name of the application 268 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 269 * {@link RDB_OK} - success. 270 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 271 * @since 14 272 */ 273 int OH_Rdb_SetBundleName(OH_Rdb_ConfigV2 *config, const char *bundleName); 274 275 /** 276 * @brief Set property moduleName into config 277 * 278 * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. 279 * Indicates the configuration of the database related to this RDB store. 280 * @param moduleName Indicates the module name of the application. 281 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 282 * {@link RDB_OK} - success. 283 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 284 * @since 14 285 */ 286 int OH_Rdb_SetModuleName(OH_Rdb_ConfigV2 *config, const char *moduleName); 287 288 /** 289 * @brief Set property isEncrypted into config 290 * 291 * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. 292 * Indicates the configuration of the database related to this RDB store. 293 * @param isEncrypted Indicates whether the database is encrypted. 294 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 295 * {@link RDB_OK} - success. 296 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 297 * @since 14 298 */ 299 int OH_Rdb_SetEncrypted(OH_Rdb_ConfigV2 *config, bool isEncrypted); 300 301 /** 302 * @brief Set property securityLevel into config 303 * 304 * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. 305 * Indicates the configuration of the database related to this RDB store. 306 * @param securityLevel Indicates the security level {@link OH_Rdb_SecurityLevel} of the database. 307 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 308 * {@link RDB_OK} - success. 309 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 310 * @since 14 311 */ 312 int OH_Rdb_SetSecurityLevel(OH_Rdb_ConfigV2 *config, int securityLevel); 313 314 /** 315 * @brief Set property area into config 316 * 317 * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. 318 * Indicates the configuration of the database related to this RDB store 319 * @param area Represents the security area of the database. 320 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 321 * {@link RDB_OK} - success. 322 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 323 * @since 14 324 */ 325 int OH_Rdb_SetArea(OH_Rdb_ConfigV2 *config, int area); 326 327 /** 328 * @brief Set property dbType into config 329 * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. 330 * @param dbType Indicates the dbType {@link Rdb_DBType} of the database 331 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 332 * {@link RDB_OK} - success. 333 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 334 * {@link RDB_E_NOT_SUPPORTED} - The error code for not support db types. 335 * @since 14 336 */ 337 int OH_Rdb_SetDbType(OH_Rdb_ConfigV2 *config, int dbType); 338 339 /** 340 * @brief Set property tokenizer into config 341 * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. 342 * @param tokenizer Indicates the tokenizer {@link Rdb_Tokenizer} of the database 343 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 344 * {@link RDB_OK} - success. 345 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 346 * {@link RDB_E_NOT_SUPPORTED} - The error code for not support tokenizer. 347 * @since 17 348 */ 349 int OH_Rdb_SetTokenizer(OH_Rdb_ConfigV2 *config, Rdb_Tokenizer tokenizer); 350 351 /** 352 * @brief Set property persist into config 353 * 354 * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. 355 * Indicates the configuration of the database related to this RDB store. 356 * @param isPersistent Indicates whether the database need persistence. 357 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 358 * {@link RDB_OK} - success. 359 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 360 * @since 18 361 */ 362 int OH_Rdb_SetPersistent(OH_Rdb_ConfigV2 *config, bool isPersistent); 363 364 /** 365 * @brief Check if a tokenizer is supported or not. 366 * 367 * @param tokenizer the tokenizer type of {@Link Rdb_Tokenizer}. 368 * @param isSupported Pointer to the Boolean value obtained. 369 * @return Returns the status code of the execution. 370 * {@link RDB_OK} indicates the operation is successful. 371 * {@link RDB_E_INVALID_ARGS} indicates invalid args are passed in. 372 * @since 18 373 */ 374 int OH_Rdb_IsTokenizerSupported(Rdb_Tokenizer tokenizer, bool *isSupported); 375 376 /** 377 * @brief Get support db type list 378 * @param typeCount The output parameter, which is used to recieve the length of the support db type array. 379 * @return Return Rdb_DBType array contains supported db type, array length is number of support type 380 * @since 14 381 */ 382 const int *OH_Rdb_GetSupportedDbType(int *typeCount); 383 384 /** 385 * @brief Creates an {@link OH_VObject} instance. 386 * 387 * @return If the creation is successful, a pointer to the instance of the @link OH_VObject} structure is returned, 388 * otherwise NULL is returned. 389 * @see OH_VObject. 390 * @since 10 391 */ 392 OH_VObject *OH_Rdb_CreateValueObject(); 393 394 /** 395 * @brief Creates an {@link OH_VBucket} object. 396 * 397 * @return If the creation is successful, a pointer to the instance of the @link OH_VBucket} structure is returned, 398 * otherwise NULL is returned. 399 * @see OH_VBucket. 400 * @since 10 401 */ 402 OH_VBucket *OH_Rdb_CreateValuesBucket(); 403 404 /** 405 * @brief Creates an {@link OH_Predicates} instance. 406 * 407 * @param table Indicates the table name. 408 * @return If the creation is successful, a pointer to the instance of the @link OH_Predicates} structure is returned. 409 * If the table name is nullptr, Nullptr is returned. 410 * @see OH_Predicates. 411 * @since 10 412 */ 413 OH_Predicates *OH_Rdb_CreatePredicates(const char *table); 414 415 /** 416 * @brief Obtains an RDB store. 417 * 418 * You can set parameters of the RDB store as required. In general, 419 * this method is recommended to obtain a rdb store. 420 * 421 * @param config Represents a pointer to an {@link OH_Rdb_Config} instance. 422 * Indicates the configuration of the database related to this RDB store. 423 * @param errCode This parameter is the output parameter, 424 * and the execution status of a function is written to this variable. 425 * @return If the creation is successful, a pointer to the instance of the @link OH_Rdb_Store} structure is returned. 426 * If the Config is empty, config.size does not match, or errCode is empty. 427 * Get database path failed.Get RDB Store fail. Nullptr is returned. 428 * @see OH_Rdb_Config, OH_Rdb_Store. 429 * @since 10 430 */ 431 OH_Rdb_Store *OH_Rdb_GetOrOpen(const OH_Rdb_Config *config, int *errCode); 432 433 /** 434 * @brief Obtains an RDB store with OH_Rdb_ConfigV2. 435 * 436 * You can set parameters of the RDB store as required. In general, 437 * this method is recommended to obtain a rdb store. 438 * 439 * @param config Represents a pointer to an {@link OH_Rdb_ConfigV2} instance. 440 * Indicates the configuration of the database related to this RDB store. 441 * @param errCode This parameter is the output parameter, 442 * and the execution status of a function is written to this variable. 443 * @return If the creation is successful, a pointer to the instance of the @link OH_Rdb_Store} structure is returned. 444 * If the Config is empty, config.size does not match, or errCode is empty. 445 * Get database path failed.Get RDB Store fail. Nullptr is returned. 446 * @see OH_Rdb_ConfigV2, OH_Rdb_Store. 447 * @since 14 448 */ 449 OH_Rdb_Store *OH_Rdb_CreateOrOpen(const OH_Rdb_ConfigV2 *config, int *errCode); 450 451 /** 452 * @brief Close the {@link OH_Rdb_Store} object and reclaim the memory occupied by the object. 453 * 454 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 455 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 456 * {@link RDB_OK} - success. 457 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 458 * while failure returns a specific error code. Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 459 * @see OH_Rdb_Store, OH_Rdb_ErrCode. 460 * @since 10 461 */ 462 int OH_Rdb_CloseStore(OH_Rdb_Store *store); 463 464 /** 465 * @brief Deletes the database with a specified path. 466 * 467 * @param config Represents a pointer to an {@link OH_Rdb_Config} instance. 468 * Indicates the configuration of the database related to this RDB store. 469 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 470 * {@link RDB_OK} - success. 471 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 472 * while failure returns a specific error code. Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 473 * @see OH_Rdb_ErrCode. 474 * @since 10 475 */ 476 int OH_Rdb_DeleteStore(const OH_Rdb_Config *config); 477 478 /** 479 * @brief Deletes the database with a specified path. 480 * 481 * @param config Represents a pointer to an {@link OH_Rdb_ConfigV2} instance. 482 * Indicates the configuration of the database related to this RDB store. 483 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 484 * {@link RDB_OK} - success. 485 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 486 * while failure returns a specific error code. Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 487 * @see OH_Rdb_ErrCode. 488 * @since 14 489 */ 490 int OH_Rdb_DeleteStoreV2(const OH_Rdb_ConfigV2 *config); 491 492 /** 493 * @brief Inserts a row of data into the target table. 494 * 495 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 496 * @param table Indicates the target table. 497 * @param valuesBucket Indicates the row of data {@link OH_VBucket} to be inserted into the table. 498 * @return Returns the rowId if success, returns a specific error code. 499 * {@link RDB_ERR} - Indicates that the function execution exception. 500 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 501 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 502 * @see OH_Rdb_Store, OH_VBucket, OH_Rdb_ErrCode. 503 * @since 10 504 */ 505 int OH_Rdb_Insert(OH_Rdb_Store *store, const char *table, OH_VBucket *valuesBucket); 506 507 /** 508 * @brief Inserts a batch of data into the target table. 509 * 510 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 511 * @param table Represents the target table. 512 * @param rows Represents the rows data to be inserted into the table. 513 * @param resolution Represents the resolution when conflict occurs. 514 * @param changes Represents the number of successful insertions. 515 * @return Returns the status code of the execution. 516 * Returns {@link RDB_OK} if the execution is successful. 517 * Returns {@link RDB_E_ERROR} database common error. 518 * Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter. 519 * Returns {@link RDB_E_ALREADY_CLOSED} database already closed. 520 * Returns {@link RDB_E_WAL_SIZE_OVER_LIMIT} the WAL file size over default limit. 521 * Returns {@link RDB_E_SQLITE_FULL} SQLite: The database is full. 522 * Returns {@link RDB_E_SQLITE_CORRUPT} database corrupted. 523 * Returns {@link RDB_E_SQLITE_PERM} SQLite: Access permission denied. 524 * Returns {@link RDB_E_SQLITE_BUSY} SQLite: The database file is locked. 525 * Returns {@link RDB_E_SQLITE_LOCKED} SQLite: A table in the database is locked. 526 * Returns {@link RDB_E_SQLITE_NOMEM} SQLite: The database is out of memory. 527 * Returns {@link RDB_E_SQLITE_READONLY} SQLite: Attempt to write a readonly database. 528 * Returns {@link RDB_E_SQLITE_IOERR} SQLite: Some kind of disk I/O error occurred. 529 * Returns {@link RDB_E_SQLITE_TOO_BIG} SQLite: TEXT or BLOB exceeds size limit. 530 * Returns {@link RDB_E_SQLITE_MISMATCH} SQLite: Data type mismatch. 531 * Returns {@link RDB_E_SQLITE_CONSTRAINT} SQLite: Abort due to constraint violation. 532 * @since 18 533 */ 534 int OH_Rdb_BatchInsert(OH_Rdb_Store *store, const char *table, 535 const OH_Data_VBuckets *rows, Rdb_ConflictResolution resolution, int64_t *changes); 536 537 /** 538 * @brief Updates data in the database based on specified conditions. 539 * 540 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 541 * @param valuesBucket Indicates the row of data {@link OH__VBucket} to be updated in the database 542 * @param predicates Represents a pointer to an {@link OH_Predicates} instance. 543 * Indicates the specified update condition. 544 * @return Returns the number of rows changed if success, otherwise, returns a specific error code. 545 * {@link RDB_ERR} - Indicates that the function execution exception. 546 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 547 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 548 * @see OH_Rdb_Store, OH_Bucket, OH_Predicates, OH_Rdb_ErrCode. 549 * @since 10 550 */ 551 int OH_Rdb_Update(OH_Rdb_Store *store, OH_VBucket *valuesBucket, OH_Predicates *predicates); 552 553 /** 554 * @brief Deletes data from the database based on specified conditions. 555 * 556 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 557 * @param predicates Represents a pointer to an {@link OH_Predicates} instance. 558 * Indicates the specified delete condition. 559 * @return Returns the number of rows changed if success, otherwise, returns a specific error code. 560 * {@link RDB_ERR} - Indicates that the function execution exception. 561 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 562 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 563 * @see OH_Rdb_Store, OH_Predicates, OH_Rdb_ErrCode. 564 * @since 10 565 */ 566 int OH_Rdb_Delete(OH_Rdb_Store *store, OH_Predicates *predicates); 567 568 /** 569 * @brief Queries data in the database based on specified conditions. 570 * 571 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 572 * @param predicates Represents a pointer to an {@link OH_Predicates} instance. 573 * Indicates the specified query condition. 574 * @param columnNames Indicates the columns to query. If the value is empty array, the query applies to all columns. 575 * @param length Indicates the length of columnNames. 576 * @return If the query is successful, a pointer to the instance of the @link OH_Cursor} structure is returned. 577 * If Get store failed or resultSet is nullptr, nullptr is returned. 578 * @see OH_Rdb_Store, OH_Predicates, OH_Cursor. 579 * @since 10 580 */ 581 OH_Cursor *OH_Rdb_Query(OH_Rdb_Store *store, OH_Predicates *predicates, const char *const *columnNames, int length); 582 583 /** 584 * @brief Executes an SQL statement. 585 * 586 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 587 * @param sql Indicates the SQL statement to execute. 588 * @return Returns the status code of the execution. 589 * {@link RDB_OK} - success. 590 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 591 * @see OH_Rdb_Store. 592 * @since 10 593 */ 594 int OH_Rdb_Execute(OH_Rdb_Store *store, const char *sql); 595 596 /** 597 * @brief Executes an SQL statement. 598 * 599 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 600 * @param sql Indicates the SQL statement to execute. 601 * @param args Represents the values of the parameters in the SQL statement. 602 * @param result Represents a pointer to OH_Data_Value instance when the execution is successful. 603 * The memory must be released through the OH_Value_Destroy interface after the use is complete. 604 * @return Returns the status code of the execution. 605 * Returns {@link RDB_OK} if the execution is successful. 606 * Returns {@link RDB_E_ERROR} database common error. 607 * Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter. 608 * Returns {@link RDB_E_ALREADY_CLOSED} database already closed. 609 * Returns {@link RDB_E_WAL_SIZE_OVER_LIMIT} the WAL file size over default limit. 610 * Returns {@link RDB_E_SQLITE_FULL} SQLite: The database is full. 611 * Returns {@link RDB_E_SQLITE_CORRUPT} database corrupted. 612 * Returns {@link RDB_E_SQLITE_PERM} SQLite: Access permission denied. 613 * Returns {@link RDB_E_SQLITE_BUSY} SQLite: The database file is locked. 614 * Returns {@link RDB_E_SQLITE_LOCKED} SQLite: A table in the database is locked. 615 * Returns {@link RDB_E_SQLITE_NOMEM} SQLite: The database is out of memory. 616 * Returns {@link RDB_E_SQLITE_READONLY} SQLite: Attempt to write a readonly database. 617 * Returns {@link RDB_E_SQLITE_IOERR} SQLite: Some kind of disk I/O error occurred. 618 * Returns {@link RDB_E_SQLITE_TOO_BIG} SQLite: TEXT or BLOB exceeds size limit. 619 * Returns {@link RDB_E_SQLITE_MISMATCH} SQLite: Data type mismatch. 620 * @see OH_Value_Destroy. 621 * @since 18 622 */ 623 int OH_Rdb_ExecuteV2(OH_Rdb_Store *store, const char *sql, const OH_Data_Values *args, OH_Data_Value **result); 624 625 /** 626 * @brief Write operations are performed using the specified transaction represented by the transaction ID 627 * 628 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 629 * @param trxId The transaction ID of the specified transaction, must be greater than 0 630 * @param sql Indicates the SQL statement to execute. 631 * @return Returns the status code of the execution. 632 * {@link RDB_OK} - success. 633 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 634 * {@link RDB_E_NOT_SUPPORTED} - The error code for not supprt. 635 * @see OH_Rdb_Store. 636 * @since 14 637 */ 638 int OH_Rdb_ExecuteByTrxId(OH_Rdb_Store *store, int64_t trxId, const char *sql); 639 640 /** 641 * @brief Queries data in the database based on an SQL statement. 642 * 643 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 644 * @param sql Indicates the SQL statement to execute. 645 * @return If the query is successful, a pointer to the instance of the @link OH_Cursor} structure is returned. 646 * If Get store failed,sql is nullptr or resultSet is nullptr, nullptr is returned. 647 * @see OH_Rdb_Store. 648 * @since 10 649 */ 650 OH_Cursor *OH_Rdb_ExecuteQuery(OH_Rdb_Store *store, const char *sql); 651 652 /** 653 * @brief Queries data in the database based on an SQL statement. 654 * 655 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 656 * @param sql Indicates the SQL statement to execute. 657 * @param args Represents a pointer to an instance of OH_Data_Values and it is the selection arguments. 658 * @return If the query is successful, a pointer to the instance of the @link OH_Cursor} structure is returned. 659 * If sql statement is invalid or the memory allocate failed, nullptr is returned. 660 * @see OH_Rdb_Store. 661 * @since 18 662 */ 663 OH_Cursor *OH_Rdb_ExecuteQueryV2(OH_Rdb_Store *store, const char *sql, const OH_Data_Values *args); 664 665 /** 666 * @brief Begins a transaction in EXCLUSIVE mode. 667 * 668 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 669 * @return Returns the status code of the execution. 670 * {@link RDB_OK} - success. 671 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 672 * @see OH_Rdb_Store. 673 * @since 10 674 */ 675 int OH_Rdb_BeginTransaction(OH_Rdb_Store *store); 676 677 /** 678 * @brief Rolls back a transaction in EXCLUSIVE mode. 679 * 680 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 681 * @return Returns the status code of the execution. 682 * {@link RDB_OK} - success. 683 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 684 * @see OH_Rdb_Store. 685 * @since 10 686 */ 687 int OH_Rdb_RollBack(OH_Rdb_Store *store); 688 689 /** 690 * @brief Commits a transaction in EXCLUSIVE mode. 691 * 692 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 693 * @return Returns the status code of the execution. 694 * {@link RDB_OK} - success. 695 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 696 * @see OH_Rdb_Store. 697 * @since 10 698 */ 699 int OH_Rdb_Commit(OH_Rdb_Store *store); 700 701 /** 702 * @brief Begin a transaction and the transaction ID corresponding to the transaction. 703 * 704 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 705 * @param trxId The output parameter, which is used to receive the transaction ID corresponding to the transaction 706 * @return Returns the status code of the execution. 707 * {@link RDB_OK} - success. 708 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 709 * {@link RDB_E_NOT_SUPPORTED} - The error code for not supprt. 710 * @see OH_Rdb_Store. 711 * @since 14 712 */ 713 int OH_Rdb_BeginTransWithTrxId(OH_Rdb_Store *store, int64_t *trxId); 714 715 /** 716 * @brief Roll back a transaction that is represented by a specified transaction ID 717 * 718 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 719 * @param trxId The transaction ID of the specified transaction, must be greater than 0 720 * @return Returns the status code of the execution. 721 * {@link RDB_OK} - success. 722 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 723 * {@link RDB_E_NOT_SUPPORTED} - The error code for not supprt. 724 * @see OH_Rdb_Store. 725 * @since 14 726 */ 727 int OH_Rdb_RollBackByTrxId(OH_Rdb_Store *store, int64_t trxId); 728 729 /** 730 * @brief Commit a transaction that is represented by a specified transaction ID 731 * 732 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 733 * @param trxId The transaction ID of the specified transaction, must be greater than 0 734 * @return Returns the status code of the execution. 735 * {@link RDB_OK} - success. 736 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 737 * {@link RDB_E_NOT_SUPPORTED} - The error code for not supprt. 738 * @see OH_Rdb_Store. 739 * @since 14 740 */ 741 int OH_Rdb_CommitByTrxId(OH_Rdb_Store *store, int64_t trxId); 742 743 /** 744 * @brief Backs up a database on specified path. 745 * 746 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 747 * @param databasePath Indicates the database file path. 748 * @return Returns the status code of the execution. 749 * {@link RDB_OK} - success. 750 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 751 * @see OH_Rdb_Store. 752 * @since 10 753 */ 754 int OH_Rdb_Backup(OH_Rdb_Store *store, const char *databasePath); 755 756 /** 757 * @brief Restores a database from a specified database file. 758 * 759 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 760 * @param databasePath Indicates the database file path. 761 * @return Returns the status code of the execution. 762 * {@link RDB_OK} - success. 763 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 764 * @see OH_Rdb_Store. 765 * @since 10 766 */ 767 int OH_Rdb_Restore(OH_Rdb_Store *store, const char *databasePath); 768 769 /** 770 * @brief Gets the version of a database. 771 * 772 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 773 * @param version Indicates the version number. 774 * @return Returns the status code of the execution. 775 * {@link RDB_OK} - success. 776 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 777 * @see OH_Rdb_Store. 778 * @since 10 779 */ 780 int OH_Rdb_GetVersion(OH_Rdb_Store *store, int *version); 781 782 /** 783 * @brief Sets the version of a database. 784 * 785 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 786 * @param version Indicates the version number. 787 * @return Returns the status code of the execution. 788 * {@link RDB_OK} - success. 789 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 790 * @see OH_Rdb_Store. 791 * @since 10 792 */ 793 int OH_Rdb_SetVersion(OH_Rdb_Store *store, int version); 794 795 /** 796 * @brief Describes the distribution type of the tables. 797 * 798 * @since 11 799 */ 800 typedef enum Rdb_DistributedType { 801 /** 802 * @brief Indicates the table is distributed among the devices. 803 */ 804 RDB_DISTRIBUTED_CLOUD 805 } Rdb_DistributedType; 806 807 /** 808 * @brief Indicates version of {@link Rdb_DistributedConfig} 809 * 810 * @since 11 811 */ 812 #define DISTRIBUTED_CONFIG_VERSION 1 813 /** 814 * @brief Manages the distributed configuration of the table. 815 * 816 * @since 11 817 */ 818 typedef struct Rdb_DistributedConfig { 819 /** 820 * The version used to uniquely identify the Rdb_DistributedConfig struct. 821 */ 822 int version; 823 /** 824 * Specifies whether the table auto syncs. 825 */ 826 bool isAutoSync; 827 } Rdb_DistributedConfig; 828 829 /** 830 * @brief Set table to be distributed table. 831 * 832 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 833 * @param tables Indicates the table names you want to set. 834 * @param count Indicates the count of tables you want to set. 835 * @param type Indicates the distributed type {@link Rdb_DistributedType}. 836 * @param config Indicates the distributed config of the tables. For details, see {@link Rdb_DistributedConfig}. 837 * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. 838 * {@link RDB_OK} - success. 839 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 840 * @see OH_Rdb_Store. 841 * @see Rdb_DistributedConfig. 842 * @since 11 843 */ 844 int OH_Rdb_SetDistributedTables(OH_Rdb_Store *store, const char *tables[], uint32_t count, Rdb_DistributedType type, 845 const Rdb_DistributedConfig *config); 846 847 /** 848 * @brief Set table to be distributed table. 849 * 850 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 851 * @param tableName Indicates the name of the table to check. 852 * @param columnName Indicates the name of the column corresponding to the primary key. 853 * If the table has no primary key , please pass in "rowid". 854 * @param values Indicates the primary keys of the rows to check. 855 * If the table has no primary key , please pass in the row-ids of the rows to check. 856 * @return If the operation is successful, a pointer to the instance of the @link OH_Cursor} structure is returned. 857 * If Get store failed, NULL is returned. 858 * There are two columns, "data_key" and "timestamp". Otherwise NULL is returned. 859 * @see OH_Rdb_Store. 860 * @see OH_VObject. 861 * @see OH_Cursor. 862 * @since 11 863 */ 864 OH_Cursor *OH_Rdb_FindModifyTime(OH_Rdb_Store *store, const char *tableName, const char *columnName, 865 OH_VObject *values); 866 867 /** 868 * @brief Describes the change type. 869 * 870 * @since 11 871 */ 872 typedef enum Rdb_ChangeType { 873 /** 874 * @brief Means the change type is data change. 875 */ 876 RDB_DATA_CHANGE, 877 /** 878 * @brief Means the change type is asset change. 879 */ 880 RDB_ASSET_CHANGE 881 } Rdb_ChangeType; 882 883 /** 884 * @brief Describes the primary keys or row-ids of changed rows. 885 * 886 * @since 11 887 */ 888 typedef struct Rdb_KeyInfo { 889 /** 890 * Indicates the count of the primary keys or row-ids. 891 */ 892 int count; 893 894 /** 895 * Indicates data type {@link OH_ColumnType} of the key. 896 */ 897 int type; 898 899 /** 900 * Indicates the data of the key info. 901 */ 902 union Rdb_KeyData { 903 /** 904 * Indicates uint64_t type of the data. 905 */ 906 uint64_t integer; 907 908 /** 909 * Indicates double type of the data. 910 */ 911 double real; 912 913 /** 914 * Indicates const char * type of the data. 915 */ 916 const char *text; 917 } *data; 918 } Rdb_KeyInfo; 919 920 /** 921 * @brief Indicates version of {@link Rdb_ChangeInfo} 922 * 923 * @since 11 924 */ 925 #define DISTRIBUTED_CHANGE_INFO_VERSION 1 926 927 /** 928 * @brief Describes the notify info of data change. 929 * 930 * @since 11 931 */ 932 typedef struct Rdb_ChangeInfo { 933 /** 934 * The version used to uniquely identify the Rdb_ChangeInfo struct. 935 */ 936 int version; 937 938 /** 939 * The name of changed table. 940 */ 941 const char *tableName; 942 943 /** 944 * The {@link Rdb_ChangeType} of changed table. 945 */ 946 int ChangeType; 947 948 /** 949 * The {@link Rdb_KeyInfo} of inserted rows. 950 */ 951 Rdb_KeyInfo inserted; 952 953 /** 954 * The {@link Rdb_KeyInfo} of updated rows. 955 */ 956 Rdb_KeyInfo updated; 957 958 /** 959 * The {@link Rdb_KeyInfo} of deleted rows. 960 */ 961 Rdb_KeyInfo deleted; 962 } Rdb_ChangeInfo; 963 964 /** 965 * @brief Indicates the subscribe type. 966 * 967 * @since 11 968 */ 969 typedef enum Rdb_SubscribeType { 970 /** 971 * @brief Subscription to cloud data changes. 972 */ 973 RDB_SUBSCRIBE_TYPE_CLOUD, 974 975 /** 976 * @brief Subscription to cloud data change details. 977 */ 978 RDB_SUBSCRIBE_TYPE_CLOUD_DETAILS, 979 980 /** 981 * @brief Subscription to local data change details. 982 * @since 12 983 */ 984 RDB_SUBSCRIBE_TYPE_LOCAL_DETAILS, 985 } Rdb_SubscribeType; 986 987 /** 988 * @brief The callback function of cloud data change event. 989 * 990 * @param context Represents the context of data observer. 991 * @param values Indicates the cloud accounts that changed. 992 * @param count The count of changed cloud accounts. 993 * @since 11 994 */ 995 typedef void (*Rdb_BriefObserver)(void *context, const char *values[], uint32_t count); 996 997 /** 998 * @brief The callback function of cloud data change details event. 999 * 1000 * @param context Represents the context of data observer. 1001 * @param changeInfo Indicates the {@link Rdb_ChangeInfo} of changed tables. 1002 * @param count The count of changed tables. 1003 * @see Rdb_ChangeInfo. 1004 * @since 11 1005 */ 1006 typedef void (*Rdb_DetailsObserver)(void *context, const Rdb_ChangeInfo **changeInfo, uint32_t count); 1007 1008 /** 1009 * @brief Indicates the callback functions. 1010 * 1011 * @since 11 1012 */ 1013 typedef union Rdb_SubscribeCallback { 1014 /** 1015 * The callback function of cloud data change details event. 1016 */ 1017 Rdb_DetailsObserver detailsObserver; 1018 1019 /** 1020 * The callback function of cloud data change event. 1021 */ 1022 Rdb_BriefObserver briefObserver; 1023 } Rdb_SubscribeCallback; 1024 1025 /** 1026 * @brief Indicates the observer of data. 1027 * 1028 * @since 11 1029 */ 1030 typedef struct Rdb_DataObserver { 1031 /** 1032 * The context of data observer. 1033 */ 1034 void *context; 1035 1036 /** 1037 * The callback of data observer. 1038 */ 1039 Rdb_SubscribeCallback callback; 1040 } Rdb_DataObserver; 1041 1042 /** 1043 * @brief Registers an observer for the database. 1044 * When data in the distributed database or the local database changes, the callback will be invoked. 1045 * 1046 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 1047 * @param type Indicates the subscription type, which is defined in {@link Rdb_SubscribeType}. 1048 * If its value is RDB_SUBSCRIBE_TYPE_LOCAL_DETAILS, the callback will be invoked for data changes 1049 * in the local database. 1050 * @param observer The {@link Rdb_DataObserver} of change events in the database. 1051 * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. 1052 * {@link RDB_OK} - success. 1053 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 1054 * @see OH_Rdb_Store. 1055 * @see Rdb_DataObserver. 1056 * @since 11 1057 */ 1058 int OH_Rdb_Subscribe(OH_Rdb_Store *store, Rdb_SubscribeType type, const Rdb_DataObserver *observer); 1059 1060 /** 1061 * @brief Remove specified observer of specified type from the database. 1062 * 1063 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 1064 * @param type Indicates the subscription type, which is defined in {@link Rdb_SubscribeType}. 1065 * @param observer The {@link Rdb_DataObserver} of change events in the database. 1066 * If this is nullptr, remove all observers of the type. 1067 * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. 1068 * {@link RDB_OK} - success. 1069 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 1070 * @see OH_Rdb_Store. 1071 * @see Rdb_DataObserver. 1072 * @since 11 1073 */ 1074 int OH_Rdb_Unsubscribe(OH_Rdb_Store *store, Rdb_SubscribeType type, const Rdb_DataObserver *observer); 1075 1076 /** 1077 * @brief Indicates the database synchronization mode. 1078 * 1079 * @since 11 1080 */ 1081 typedef enum Rdb_SyncMode { 1082 /** 1083 * @brief Indicates that data is synchronized from the end with the closest modification time 1084 * to the end with a more distant modification time. 1085 */ 1086 RDB_SYNC_MODE_TIME_FIRST, 1087 /** 1088 * @brief Indicates that data is synchronized from local to cloud. 1089 */ 1090 RDB_SYNC_MODE_NATIVE_FIRST, 1091 /** 1092 * @brief Indicates that data is synchronized from cloud to local. 1093 */ 1094 RDB_SYNC_MODE_CLOUD_FIRST 1095 } Rdb_SyncMode; 1096 1097 /** 1098 * @brief Describes the statistic of the cloud sync process. 1099 * 1100 * @since 11 1101 */ 1102 typedef struct Rdb_Statistic { 1103 /** 1104 * Describes the total number of data to sync. 1105 */ 1106 int total; 1107 1108 /** 1109 * Describes the number of successfully synced data. 1110 */ 1111 int successful; 1112 1113 /** 1114 * Describes the number of data failed to sync. 1115 */ 1116 int failed; 1117 1118 /** 1119 * Describes the number of data remained to sync. 1120 */ 1121 int remained; 1122 } Rdb_Statistic; 1123 1124 /** 1125 * @brief Describes the {@link Rdb_Statistic} details of the table. 1126 * 1127 * @since 11 1128 */ 1129 typedef struct Rdb_TableDetails { 1130 /** 1131 * Indicates the name of changed table. 1132 */ 1133 const char *table; 1134 1135 /** 1136 * Describes the {@link Rdb_Statistic} details of the upload process. 1137 */ 1138 Rdb_Statistic upload; 1139 1140 /** 1141 * Describes the {@link Rdb_Statistic} details of the download process. 1142 */ 1143 Rdb_Statistic download; 1144 } Rdb_TableDetails; 1145 1146 /** 1147 * The cloud sync progress 1148 * 1149 * @since 11 1150 */ 1151 typedef enum Rdb_Progress { 1152 /** 1153 * @brief Means the sync process begin. 1154 */ 1155 RDB_SYNC_BEGIN, 1156 1157 /** 1158 * @brief Means the sync process is in progress 1159 */ 1160 RDB_SYNC_IN_PROGRESS, 1161 1162 /** 1163 * @brief Means the sync process is finished 1164 */ 1165 RDB_SYNC_FINISH 1166 } Rdb_Progress; 1167 1168 /** 1169 * Describes the status of cloud sync progress. 1170 * 1171 * @since 11 1172 */ 1173 typedef enum Rdb_ProgressCode { 1174 /** 1175 * @brief Means the status of progress is success. 1176 */ 1177 RDB_SUCCESS, 1178 1179 /** 1180 * @brief Means the progress meets unknown error. 1181 */ 1182 RDB_UNKNOWN_ERROR, 1183 1184 /** 1185 * @brief Means the progress meets network error. 1186 */ 1187 RDB_NETWORK_ERROR, 1188 1189 /** 1190 * @brief Means cloud is disabled. 1191 */ 1192 RDB_CLOUD_DISABLED, 1193 1194 /** 1195 * @brief Means the progress is locked by others. 1196 */ 1197 RDB_LOCKED_BY_OTHERS, 1198 1199 /** 1200 * @brief Means the record exceeds the limit. 1201 */ 1202 RDB_RECORD_LIMIT_EXCEEDED, 1203 1204 /** 1205 * Means the cloud has no space for the asset. 1206 */ 1207 RDB_NO_SPACE_FOR_ASSET 1208 } Rdb_ProgressCode; 1209 1210 /** 1211 * @brief Indicates version of {@link Rdb_ProgressDetails} 1212 * 1213 * @since 11 1214 */ 1215 #define DISTRIBUTED_PROGRESS_DETAIL_VERSION 1 1216 1217 /** 1218 * @brief Describes detail of the cloud sync progress. 1219 * 1220 * @since 11 1221 */ 1222 typedef struct Rdb_ProgressDetails { 1223 /** 1224 * The version used to uniquely identify the Rdb_ProgressDetails struct. 1225 */ 1226 int version; 1227 1228 /** 1229 * Describes the status of data sync progress. Defined in {@link Rdb_Progress}. 1230 */ 1231 int schedule; 1232 1233 /** 1234 * Describes the code of data sync progress. Defined in {@link Rdb_ProgressCode}. 1235 */ 1236 int code; 1237 1238 /** 1239 * Describes the length of changed tables in data sync progress. 1240 */ 1241 int32_t tableLength; 1242 } Rdb_ProgressDetails; 1243 1244 /** 1245 * @brief Get table details from progress details. 1246 * 1247 * @param progress Represents a pointer to an {@link Rdb_ProgressDetails} instance. 1248 * @param version Indicates the version of current {@link Rdb_ProgressDetails}. 1249 * @return If the operation is successful, a pointer to the instance of the {@link Rdb_TableDetails} 1250 * structure is returned.If get details is failed, nullptr is returned. 1251 * @see Rdb_ProgressDetails 1252 * @see Rdb_TableDetails 1253 * @since 11 1254 */ 1255 Rdb_TableDetails *OH_Rdb_GetTableDetails(Rdb_ProgressDetails *progress, int32_t version); 1256 1257 /** 1258 * @brief The callback function of progress. 1259 * 1260 * @param progressDetails The details of the sync progress. 1261 * @see Rdb_ProgressDetails. 1262 * @since 11 1263 */ 1264 typedef void (*Rdb_ProgressCallback)(void *context, Rdb_ProgressDetails *progressDetails); 1265 1266 /** 1267 * @brief The callback function of sync. 1268 * 1269 * @param progressDetails The details of the sync progress. 1270 * @see Rdb_ProgressDetails. 1271 * @since 11 1272 */ 1273 typedef void (*Rdb_SyncCallback)(Rdb_ProgressDetails *progressDetails); 1274 1275 /** 1276 * @brief The observer of progress. 1277 * 1278 * @since 11 1279 */ 1280 typedef struct Rdb_ProgressObserver { 1281 /** 1282 * The context of progress observer. 1283 */ 1284 void *context; 1285 1286 /** 1287 * The callback function of progress observer. 1288 */ 1289 Rdb_ProgressCallback callback; 1290 } Rdb_ProgressObserver; 1291 1292 /** 1293 * @brief Sync data to cloud. 1294 * 1295 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 1296 * @param mode Represents the {@link Rdb_SyncMode} of sync progress. 1297 * @param tables Indicates the names of tables to sync. 1298 * @param count The count of tables to sync. If value equals 0, sync all tables of the store. 1299 * @param observer The {@link Rdb_ProgressObserver} of cloud sync progress. 1300 * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. 1301 * {@link RDB_OK} - success. 1302 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 1303 * @see OH_Rdb_Store. 1304 * @see Rdb_ProgressObserver. 1305 * @since 11 1306 */ 1307 int OH_Rdb_CloudSync(OH_Rdb_Store *store, Rdb_SyncMode mode, const char *tables[], uint32_t count, 1308 const Rdb_ProgressObserver *observer); 1309 1310 /** 1311 * @brief Subscribes to the automatic synchronization progress of an RDB store. 1312 * A callback will be invoked when there is a notification of the automatic synchronization progress. 1313 * 1314 * @param store Indicates the pointer to the target {@Link OH_Rdb_Store} instance. 1315 * @param observer The {@link Rdb_ProgressObserver} for the automatic synchornizaiton progress. 1316 * Indicates the callback invoked to return the automatic synchronization progress. 1317 * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. 1318 * {@link RDB_OK} - success. 1319 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 1320 * @see OH_Rdb_Store. 1321 * @see Rdb_ProgressObserver. 1322 * @since 11 1323 **/ 1324 int OH_Rdb_SubscribeAutoSyncProgress(OH_Rdb_Store *store, const Rdb_ProgressObserver *observer); 1325 1326 /** 1327 * @brief Unsubscribes from the automatic synchronziation progress of an RDB store. 1328 * 1329 * @param store Indicates the pointer to the target {@Link OH_Rdb_Store} instance. 1330 * @param observer Indicates the {@link Rdb_ProgressObserver} callback for the automatic synchornizaiton progress. 1331 * If it is a null pointer, all callbacks for the automatic synchornizaiton progress will be unregistered. 1332 * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. 1333 * {@link RDB_OK} - success. 1334 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 1335 * @see OH_Rdb_Store. 1336 * @see Rdb_ProgressObserver. 1337 * @since 11 1338 */ 1339 int OH_Rdb_UnsubscribeAutoSyncProgress(OH_Rdb_Store *store, const Rdb_ProgressObserver *observer); 1340 1341 /** 1342 * @brief Lock data from the database based on specified conditions. 1343 * 1344 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 1345 * @param predicates Represents a pointer to an {@link OH_Predicates} instance. 1346 * Indicates the specified lock condition. 1347 * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. 1348 * {@link RDB_OK} - success. 1349 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 1350 * @see OH_Rdb_Store, OH_Predicates, OH_Rdb_ErrCode. 1351 * @since 12 1352 */ 1353 int OH_Rdb_LockRow(OH_Rdb_Store *store, OH_Predicates *predicates); 1354 1355 /** 1356 * @brief Unlock data from the database based on specified conditions. 1357 * 1358 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 1359 * @param predicates Represents a pointer to an {@link OH_Predicates} instance. 1360 * Indicates the specified unlock condition. 1361 * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. 1362 * {@link RDB_OK} - success. 1363 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 1364 * @see OH_Rdb_Store, OH_Predicates, OH_Rdb_ErrCode. 1365 * @since 12 1366 */ 1367 int OH_Rdb_UnlockRow(OH_Rdb_Store *store, OH_Predicates *predicates); 1368 1369 /** 1370 * @brief Queries locked data in the database based on specified conditions. 1371 * 1372 * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. 1373 * @param predicates Represents a pointer to an {@link OH_Predicates} instance. 1374 * Indicates the specified query condition. 1375 * @param columnNames Indicates the columns to query. If the value is empty array, the query applies to all columns. 1376 * @param length Indicates the length of columnNames. 1377 * @return If the query is successful, a pointer to the instance of the @link OH_Cursor} structure is returned. 1378 * If Get store failed or resultSet is nullptr, nullptr is returned. 1379 * @see OH_Rdb_Store, OH_Predicates, OH_Cursor. 1380 * @since 12 1381 */ 1382 OH_Cursor *OH_Rdb_QueryLockedRow( 1383 OH_Rdb_Store *store, OH_Predicates *predicates, const char *const *columnNames, int length); 1384 1385 /** 1386 * @brief Creates an OH_Rdb_Transaction instance object. 1387 * 1388 * @param store Represents a pointer to an instance of OH_Rdb_Store. 1389 * @param options Represents a pointer to an instance of OH_RDB_TransOptions. 1390 * @param trans Represents a pointer to OH_Rdb_Transaction instance when the execution is successful. 1391 * Otherwise, nullptr is returned. The memory must be released through the OH_RdbTrans_Destroy 1392 * interface after the use is complete. 1393 * @return Returns the error code. 1394 * Returns {@link RDB_OK} if the execution is successful. 1395 * Returns {@link RDB_E_ERROR} database common error. 1396 * Returns {@link RDB_E_INVALID_ARGS} if invalid input parameter. 1397 * Returns {@link RDB_E_ALREADY_CLOSED} database already closed. 1398 * Returns {@link RDB_E_DATABASE_BUSY} database does not respond. 1399 * Returns {@link RDB_E_SQLITE_FULL} SQLite: The database is full. 1400 * Returns {@link RDB_E_SQLITE_CORRUPT} database corrupted. 1401 * Returns {@link RDB_E_SQLITE_PERM} SQLite: Access permission denied. 1402 * Returns {@link RDB_E_SQLITE_BUSY} SQLite: The database file is locked. 1403 * Returns {@link RDB_E_SQLITE_NOMEM} SQLite: The database is out of memory. 1404 * Returns {@link RDB_E_SQLITE_IOERR} SQLite: Some kind of disk I/O error occurred. 1405 * Returns {@link RDB_E_SQLITE_CANT_OPEN} SQLite: Unable to open the database file. 1406 * @see OH_RdbTrans_Destroy. 1407 * @since 18 1408 */ 1409 int OH_Rdb_CreateTransaction(OH_Rdb_Store *store, const OH_RDB_TransOptions *options, OH_Rdb_Transaction **trans); 1410 1411 #ifdef __cplusplus 1412 }; 1413 #endif 1414 1415 /** @} */ 1416 1417 #endif // RELATIONAL_STORE_H 1418