From d601799fc5a77e05bc27d3cd899a9bccf9a737d2 Mon Sep 17 00:00:00 2001 From: "wy524668781@icloud.com" Date: Thu, 5 Sep 2024 14:29:40 +0800 Subject: [PATCH] add vector field for rdb Signed-off-by: wy524668781@icloud.com --- .../include/relational_store.h | 252 +++++++++++++++++- .../relational_store/libnative_rdb.ndk.json | 68 +++++ 2 files changed, 318 insertions(+), 2 deletions(-) diff --git a/distributeddatamgr/relational_store/include/relational_store.h b/distributeddatamgr/relational_store/include/relational_store.h index a48ed22ee..50ff91164 100644 --- a/distributeddatamgr/relational_store/include/relational_store.h +++ b/distributeddatamgr/relational_store/include/relational_store.h @@ -104,7 +104,6 @@ typedef enum Rdb_SecurityArea { /** * @brief Manages relational database configurations. - * * @since 10 */ #pragma pack(1) @@ -158,6 +157,166 @@ typedef struct { int64_t id; } OH_Rdb_Store; +/** + * @brief Define OH_Rdb_ConfigV2 type. + * + * @since 13 + */ +typedef struct OH_Rdb_ConfigV2 OH_Rdb_ConfigV2; + +/** + * @brief Define Rdb_DBType type. + * + * @since 13 + */ +typedef enum Rdb_DBType { + /** + * @brief Means using SQLITE as the db kernal + */ + RDB_SQLITE = 1, + /** + * @brief Means using CARLEY_DB as the db kernal + */ + RDB_CAYLEY = 2, + /** + * @brief Means largest value for Rdb_DBType + */ + DBTYPE_BUTT = 64, +} Rdb_DBType; + +/** + * @brief Create OH_Rdb_ConfigV2 which is used to open store + * + * @return Returns the newly created OH_Rdb_ConfigV2 object. If NULL is returned, the creation fails. + * The possible cause is that the address space of the application is full, As a result, the space + * cannot be allocated. + * @see OH_Rdb_ConfigV2 + * @since 13 + */ +OH_Rdb_ConfigV2 *OH_Rdb_CreateConfig(); + +/** + * @brief Destroy OH_Rdb_ConfigV2 which is created by OH_Rdb_CreateConfig + * + * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. + * Indicates the configuration of the database related to this RDB store. + * @return Returns the status code of the execution. Successful execution returns RDB_OK, + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * @since 13 + */ +int OH_Rdb_DestroyConfig(OH_Rdb_ConfigV2 *config); + +/** + * @brief Set property databaseDir into config + * + * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. + * Indicates the configuration of the database related to this RDB store. + * @param dataBaseDir Indicates the directory of the database. + * @return Returns the status code of the execution. Successful execution returns RDB_OK, + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * @since 13 + */ +int OH_Rdb_SetDatabaseDir(OH_Rdb_ConfigV2 *config, const char *databaseDir); + +/** + * @brief Set property storeName into config + * + * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. + * Indicates the configuration of the database related to this RDB store. + * @param storeName Indicates the name of the database. + * @return Returns the status code of the execution. Successful execution returns RDB_OK, + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * @since 13 + */ +int OH_Rdb_SetStoreName(OH_Rdb_ConfigV2 *config, const char *storeName); + +/** + * @brief Set property bundleName into config + * + * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. + * Indicates the configuration of the database related to this RDB store. + * @param bundleName Indicates the bundle name of the application + * @return Returns the status code of the execution. Successful execution returns RDB_OK, + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * @since 13 + */ +int OH_Rdb_SetBundleName(OH_Rdb_ConfigV2 *config, const char *bundleName); + +/** + * @brief Set property moduleName into config + * + * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. + * Indicates the configuration of the database related to this RDB store. + * @param moduleName Indicates the module name of the application. + * @return Returns the status code of the execution. Successful execution returns RDB_OK, + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * @since 13 + */ +int OH_Rdb_SetModuleName(OH_Rdb_ConfigV2 *config, const char *moduleName); + +/** + * @brief Set property isEncrypted into config + * + * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. + * Indicates the configuration of the database related to this RDB store. + * @param isEncrypt Indicates whether the database is encrypted. + * @return Returns the status code of the execution. Successful execution returns RDB_OK, + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * @since 13 + */ +int OH_Rdb_SetEncrypted(OH_Rdb_ConfigV2 *config, bool isEncrypted); + +/** + * @brief Set property securityLevel into config + * + * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. + * Indicates the configuration of the database related to this RDB store. + * @param securityLevel Indicates the security level {@link OH_Rdb_SecurityLevel} of the database. + * @return Returns the status code of the execution. Successful execution returns RDB_OK, + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * @since 13 + */ +int OH_Rdb_SetSecurityLevel(OH_Rdb_ConfigV2 *config, int securityLevel); + +/** + * @brief Set property area into config + * + * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. + * Indicates the configuration of the database related to this RDB store + * @return Returns the status code of the execution. Successful execution returns RDB_OK, + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * @since 13 + */ +int OH_Rdb_SetArea(OH_Rdb_ConfigV2 *config, int area); + +/** + * @brief Set property dbType into config + * @param config Represents a pointer to {@link OH_Rdb_ConfigV2} instance. + * @param dbType Indicates the dbType {@link Rdb_DBType} of the database + * @return Returns the status code of the execution. Successful execution returns RDB_OK, + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * {@link RDB_E_NOT_SUPPORTED} - The error code for not support db types. + * @since 13 + */ +int OH_Rdb_SetDbType(OH_Rdb_ConfigV2 *config, int dbType); + +/** + * @brief Get support db type list + * @param numType The output parameter, which is used to recieve the length of the support db type array. + * @return Return Rdb_DBType array contains supported db type, array length is number of support type + * @since 13 + */ +const int *OH_Rdb_GetSupportedDbType(int *typeCount); + /** * @brief Creates an {@link OH_VObject} instance. * @@ -207,6 +366,24 @@ OH_Predicates *OH_Rdb_CreatePredicates(const char *table); */ OH_Rdb_Store *OH_Rdb_GetOrOpen(const OH_Rdb_Config *config, int *errCode); +/** + * @brief Obtains an RDB store with OH_Rdb_ConfigV2. + * + * You can set parameters of the RDB store as required. In general, + * this method is recommended to obtain a rdb store. + * + * @param config Represents a pointer to an {@link OH_Rdb_ConfigV2} instance. + * Indicates the configuration of the database related to this RDB store. + * @param errCode This parameter is the output parameter, + * and the execution status of a function is written to this variable. + * @return If the creation is successful, a pointer to the instance of the @link OH_Rdb_Store} structure is returned. + * If the Config is empty, config.size does not match, or errCode is empty. + * Get database path failed.Get RDB Store fail. Nullptr is returned. + * @see OH_Rdb_ConfigV2, OH_Rdb_Store. + * @since 13 + */ +OH_Rdb_Store *OH_Rdb_CreateOrOpen(const OH_Rdb_ConfigV2 *config, int *errCode); + /** * @brief Close the {@link OH_Rdb_Store} object and reclaim the memory occupied by the object. * @@ -234,6 +411,20 @@ int OH_Rdb_CloseStore(OH_Rdb_Store *store); */ int OH_Rdb_DeleteStore(const OH_Rdb_Config *config); +/** + * @brief Deletes the database with a specified path. + * + * @param config Represents a pointer to an {@link OH_Rdb_ConfigV2} instance. + * Indicates the configuration of the database related to this RDB store. + * @return Returns the status code of the execution. Successful execution returns RDB_OK, + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * while failure returns a specific error code. Specific error codes can be referenced {@link OH_Rdb_ErrCode}. + * @see OH_Rdb_ErrCode. + * @since 13 + */ +int OH_Rdb_DeleteStoreV2(const OH_Rdb_ConfigV2 *config); + /** * @brief Inserts a row of data into the target table. * @@ -308,6 +499,21 @@ OH_Cursor *OH_Rdb_Query(OH_Rdb_Store *store, OH_Predicates *predicates, const ch */ int OH_Rdb_Execute(OH_Rdb_Store *store, const char *sql); +/** + * @brief Write operations are performed using the specified transaction represented by the transaction ID + * + * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. + * @param sql Indicates the SQL statement to execute. + * @param trxId The transaction ID of the specified transaction, must be greater than 0 + * @return Returns the status code of the execution. + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * {@link RDB_E_NOT_SUPPORTED} - The error code for not supprt. + * @see OH_Rdb_Store. + * @since 13 + */ +int OH_Rdb_ExecuteByTrxId(OH_Rdb_Store *store, int64_t trxId, const char *sql); + /** * @brief Queries data in the database based on an SQL statement. * @@ -356,6 +562,48 @@ int OH_Rdb_RollBack(OH_Rdb_Store *store); */ int OH_Rdb_Commit(OH_Rdb_Store *store); +/** + * @brief Begin a transaction and the transaction ID corresponding to the transaction. + * + * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. + * @param trxId The output parameter, which is used to receive the transaction ID corresponding to the transaction + * @return Returns the status code of the execution. + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * {@link RDB_E_NOT_SUPPORTED} - The error code for not supprt. + * @see OH_Rdb_Store. + * @since 13 + */ +int OH_Rdb_BeginTransWithTrxId(OH_Rdb_Store *store, int64_t *trxId); + +/** + * @brief Roll back a transaction that is represented by a specified transaction ID + * + * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. + * @param trxId The transaction ID of the specified transaction, must be greater than 0 + * @return Returns the status code of the execution. + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * {@link RDB_E_NOT_SUPPORTED} - The error code for not supprt. + * @see OH_Rdb_Store. + * @since 13 + */ +int OH_Rdb_RollBackByTrxId(OH_Rdb_Store *store, int64_t trxId); + +/** + * @brief Commit a transaction that is represented by a specified transaction ID + * + * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. + * @param trxId The transaction ID of the specified transaction, must be greater than 0 + * @return Returns the status code of the execution. + * {@link RDB_OK} - success. + * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. + * {@link RDB_E_NOT_SUPPORTED} - The error code for not supprt. + * @see OH_Rdb_Store. + * @since 13 + */ +int OH_Rdb_CommitByTrxId(OH_Rdb_Store *store, int64_t trxId); + /** * @brief Backs up a database on specified path. * @@ -863,7 +1111,7 @@ typedef struct Rdb_ProgressDetails { * @param progress Represents a pointer to an {@link Rdb_ProgressDetails} instance. * @param version Indicates the version of current {@link Rdb_ProgressDetails}. * @return If the operation is successful, a pointer to the instance of the {@link Rdb_TableDetails} - * structure is returned.If get details is failed,nullptr is returned. + * structure is returned.If get details is failed, nullptr is returned. * @see Rdb_ProgressDetails * @see Rdb_TableDetails * @since 11 diff --git a/distributeddatamgr/relational_store/libnative_rdb.ndk.json b/distributeddatamgr/relational_store/libnative_rdb.ndk.json index 68882bc8a..4d72ebe84 100644 --- a/distributeddatamgr/relational_store/libnative_rdb.ndk.json +++ b/distributeddatamgr/relational_store/libnative_rdb.ndk.json @@ -2,18 +2,86 @@ {"name":"OH_Rdb_CreatePredicates" }, {"name":"OH_Rdb_CreateValueObject" }, {"name":"OH_Rdb_CreateValuesBucket" }, + { + "first_introduced":"13", + "name":"OH_Rdb_CreateConfig" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_SetDatabaseDir" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_SetStoreName" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_SetBundleName" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_SetModuleName" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_SetEncrypted" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_SetSecurityLevel" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_SetArea" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_SetDbType" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_GetSupportedDbType" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_DestroyConfig" + }, {"name":"OH_Rdb_GetOrOpen" }, + { + "first_introduced": "13", + "name":"OH_Rdb_CreateOrOpen" + }, {"name":"OH_Rdb_CloseStore" }, {"name":"OH_Rdb_DeleteStore" }, + { + "first_introduced": "13", + "name":"OH_Rdb_DeleteStoreV2" + }, {"name":"OH_Rdb_Insert" }, {"name":"OH_Rdb_Update" }, {"name":"OH_Rdb_Delete" }, {"name":"OH_Rdb_Query" }, {"name":"OH_Rdb_Execute" }, + { + "first_introduced": "13", + "name":"OH_Rdb_ExecuteByTrxId" + }, {"name":"OH_Rdb_ExecuteQuery" }, {"name":"OH_Rdb_BeginTransaction" }, {"name":"OH_Rdb_RollBack" }, {"name":"OH_Rdb_Commit" }, + { + "first_introduced": "13", + "name":"OH_Rdb_BeginTransWithTrxId" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_RollBackByTrxId" + }, + { + "first_introduced": "13", + "name":"OH_Rdb_CommitByTrxId" + }, {"name":"OH_Rdb_Backup" }, {"name":"OH_Rdb_Restore"}, {"name":"OH_Rdb_GetVersion"},