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