harmony 鸿蒙relational_store.h

2025-06-12 浏览 (1)

relational_store.h

Overview

Provides APIs for managing data in a relational database (RDB) store. The APIs not marked as supporting vector stores are available only to RDB stores.

File to include: <database/rdb/relational_store.h>

Library: libnative_rdb_ndk.z.so

Since: 10

Related module: RDB

Summary

Structs

NameDescription
OH_Rdb_ConfigRepresents the RDB store configuration.
OH_Rdb_StoreRepresents the RDB store type.
Rdb_DistributedConfigRepresents the distributed configuration of a table.
Rdb_KeyInfoRepresents the primary key or row number of the row that changes.
Rdb_KeyInfo::Rdb_KeyDataRepresents the changed data.
Rdb_ChangeInfoRepresents the details about the device-cloud sync.
Rdb_SubscribeCallbackRepresents a callback used to listen for data changes.
Rdb_DataObserverRepresents the data observer.
Rdb_StatisticRepresents the device-cloud sync statistics of a table.
Rdb_TableDetailsRepresents the statistics of device-cloud upload and download tasks of a table.
Rdb_ProgressDetailsRepresents the statistics of the overall device-cloud upload and download tasks of a database.
Rdb_ProgressObserverRepresents the observer of the device-cloud sync progress.

Macros

NameDescription
DISTRIBUTED_CONFIG_VERSION   1Version of Rdb_DistributedConfig.
DISTRIBUTED_CHANGE_INFO_VERSION   1Version of Rdb_ChangeInfo.
DISTRIBUTED_PROGRESS_DETAIL_VERSION   1Version of Rdb_ProgressDetails.

Types

NameDescription
OH_Rdb_SecurityLevelDefines an enum for RDB store security levels.
Rdb_SecurityAreaDefines an enum for database directory encryption levels.
typedef struct OH_Rdb_ConfigV2 OH_Rdb_ConfigV2Defines a struct for the RDB store configuration. Different from OH_Rdb_Config, this struct does not expose its member variables externally. Methods are used to configure the properties of this struct. It supports vector stores.
typedef enum Rdb_DBType Rdb_DBTypeDefines an enum for the database kernel types.
Rdb_DistributedTypeDefines an enum for distributed types.
Rdb_DistributedConfigDefines a struct for the distributed configuration of a table.
Rdb_ChangeTypeDefines an enum for data change types.
Rdb_KeyInfoDefines a struct for the primary key or row number of the row that changes.
Rdb_ChangeInfoDefines a struct for details about the device-cloud sync process.
Rdb_SubscribeTypeDefines an enum for subscription types.
Rdb_BriefObserverDefines a callback used to return the device-cloud data change event.
Rdb_DetailsObserverDefines a callback used to return the details about the device-cloud data change.
Rdb_SubscribeCallbackDefines a callback used to return the subscribed event.
Rdb_DataObserverDefines a struct for the data observer.
Rdb_SyncModeDefines an enum for RDB store sync modes.
Rdb_StatisticDefines a struct for device-cloud sync statistics of a database table.
Rdb_TableDetailsDefines a struct for statistics of device-cloud upload and download tasks of a database table.
Rdb_ProgressDefines an enum for device-cloud sync progresses.
Rdb_ProgressCodeDefines an enum for states in the device-cloud sync process.
Rdb_ProgressDetailsDefines a struct for statistics of the overall device-cloud upload and download tasks of an RDB store.
Rdb_ProgressCallbackDefines a callback used to return the device-cloud sync progress.
Rdb_SyncCallbackDefines a callback to be invoked in device-cloud sync.
Rdb_ProgressObserverDefines a struct for the observer of the device-cloud sync progress.

Enums

NameDescription
OH_Rdb_SecurityLevel { S1 = 1, S2, S3, S4}Enumerates the RDB store security levels.
Rdb_SecurityArea { RDB_SECURITY_AREA_EL1 = 1, RDB_SECURITY_AREA_EL2, RDB_SECURITY_AREA_EL3, RDB_SECURITY_AREA_EL4 }Enumerates the database directory encryption levels.
Rdb_DBType { RDB_SQLITE = 1, RDB_CAYLEY = 2, DBTYPE_BUTT = 64 }Enumerates the database kernel types.
Rdb_DistributedType { RDB_DISTRIBUTED_CLOUD }Enumerates the distributed types.
Rdb_ChangeType { RDB_DATA_CHANGE, RDB_ASSET_CHANGE }Enumerates the data change types.
Rdb_SubscribeType { RDB_SUBSCRIBE_TYPE_CLOUD, RDB_SUBSCRIBE_TYPE_CLOUD_DETAILS, RDB_SUBSCRIBE_TYPE_LOCAL_DETAILS }Enumerates the subscription types.
Rdb_SyncMode { RDB_SYNC_MODE_TIME_FIRST, RDB_SYNC_MODE_NATIVE_FIRST, RDB_SYNC_MODE_CLOUD_FIRST }Enumerates the RDB store sync modes.
Rdb_Progress { RDB_SYNC_BEGIN, RDB_SYNC_IN_PROGRESS, RDB_SYNC_FINISH }Enumerates the device-cloud sync progresses.
Rdb_ProgressCode {
RDB_SUCCESS, RDB_UNKNOWN_ERROR, RDB_NETWORK_ERROR, RDB_CLOUD_DISABLED,
RDB_LOCKED_BY_OTHERS, RDB_RECORD_LIMIT_EXCEEDED, RDB_NO_SPACE_FOR_ASSET
}
Enumerates the states in the device-cloud sync process.

Functions

NameDescription
int OH_Rdb_SetPersistent (OH_Rdb_ConfigV2 *config, bool isPersistent)Sets whether to persist an RDB store.
int OH_Rdb_BatchInsert (OH_Rdb_Store *store, const char *table, const OH_Data_VBuckets *rows, Rdb_ConflictResolution resolution, int64_t *changes)Inserts a batch of data into a table.
int OH_Rdb_CreateTransaction (OH_Rdb_Store *store, const OH_RDB_TransOptions *options, OH_Rdb_Transaction **trans)Creates a transaction object.
int OH_Rdb_ExecuteV2 (OH_Rdb_Store *store, const char *sql, const OH_Data_Values *args, OH_Data_Value **result)Executes an SQL statement with a return value. This API supports vector stores.
OH_Cursor * OH_Rdb_ExecuteQueryV2 (OH_Rdb_Store *store, const char *sql, const OH_Data_Values *args)Queries data in the database using the specified SQL statement. This API supports vector stores.
int OH_Rdb_IsTokenizerSupported (Rdb_Tokenizer tokenizer, bool *isSupported)Checks whether the specified tokenizer is supported.
int OH_Rdb_SetTokenizer (OH_Rdb_ConfigV2 *config, Rdb_Tokenizer tokenizer)Sets a tokenizer for a database file.
OH_Rdb_ConfigV2 * OH_Rdb_CreateConfig ()Creates an OH_Rdb_ConfigV2 instance.
int OH_Rdb_DestroyConfig (OH_Rdb_ConfigV2 *config)Destroys an OH_Rdb_ConfigV2 instance.
int OH_Rdb_SetDatabaseDir (OH_Rdb_ConfigV2 *config, const char *databaseDir)Sets the database file path for an OH_Rdb_ConfigV2 instance.
int OH_Rdb_SetStoreName (OH_Rdb_ConfigV2 *config, const char *storeName)Sets the database name for an OH_Rdb_ConfigV2 instance.
int OH_Rdb_SetBundleName (OH_Rdb_ConfigV2 *config, const char *bundleName)Sets the application bundle name for an OH_Rdb_ConfigV2 instance.
int OH_Rdb_SetModuleName (OH_Rdb_ConfigV2 *config, const char *moduleName)Sets the module name for an OH_Rdb_ConfigV2 instance.
int OH_Rdb_SetEncrypted (OH_Rdb_ConfigV2 *config, bool isEncrypted)Sets whether to encrypt the database for an OH_Rdb_ConfigV2 instance.
int OH_Rdb_SetSecurityLevel (OH_Rdb_ConfigV2 *config, int securityLevel)Sets the database security level (OH_Rdb_SecurityLevel) for an OH_Rdb_ConfigV2 instance.
int OH_Rdb_SetArea (OH_Rdb_ConfigV2 *config, int area)Sets the security area level (Rdb_SecurityArea) for an OH_Rdb_ConfigV2 instance.
int OH_Rdb_SetDbType (OH_Rdb_ConfigV2 *config, int dbType)Sets the database type (Rdb_DBType) for an OH_Rdb_ConfigV2 instance.
const int * OH_Rdb_GetSupportedDbType (int *typeCount)Obtains the supported database type Rdb_DBType.
OH_Rdb_Store * OH_Rdb_CreateOrOpen (const OH_Rdb_ConfigV2 *config, int *errCode)Creates or opens an OH_Rdb_Store instance based on the given OH_Rdb_ConfigV2.
int OH_Rdb_ExecuteByTrxId (OH_Rdb_Store *store, int64_t trxId, const char *sql)Executes an SQL statement that returns no value based on the specified transaction ID. This API supports vector stores.
int OH_Rdb_BeginTransWithTrxId (OH_Rdb_Store *store, int64_t *trxId)Begins a transaction. This API returns a transaction ID. This API supports vector stores.
int OH_Rdb_RollBackByTrxId (OH_Rdb_Store *store, int64_t trxId)Rolls back the executed SQL statements based on the specified transaction ID. This API supports vector stores.
int OH_Rdb_CommitByTrxId (OH_Rdb_Store *store, int64_t trxId)Commits the executed SQL statements based on the specified transaction ID. This API supports vector stores.
OH_Rdb_CreateValueObject (void)Creates an OH_VObject instance.
OH_Rdb_CreateValuesBucket (void)Creates an OH_VBucket instance.
OH_Rdb_CreatePredicates (const char *table)Creates an OH_Predicates instance.
OH_Rdb_GetOrOpen (const OH_Rdb_Config *config, int *errCode)Obtains an OH_Rdb_Store instance for RDB store operations.
OH_Rdb_CloseStore (OH_Rdb_Store *store)Destroys an OH_Rdb_Store object and reclaims the memory occupied by the object.
OH_Rdb_DeleteStore (const OH_Rdb_Config *config)Deletes an RDB store with the specified database file configuration.
int OH_Rdb_DeleteStoreV2 (const OH_Rdb_ConfigV2 *config)Deletes an RDB store based on the given OH_Rdb_ConfigV2. If a vector store is used, ensure that the vector store has been correctly closed before calling the API.
OH_Rdb_Insert (OH_Rdb_Store *store, const char *table, OH_VBucket *valuesBucket)Inserts a row of data into a table.
OH_Rdb_Update (OH_Rdb_Store *store, OH_VBucket *valuesBucket, OH_Predicates *predicates)Updates data in an RDB store based on specified conditions.
OH_Rdb_Delete (OH_Rdb_Store *store, OH_Predicates *predicates)Deletes data from an RDB store based on specified conditions.
OH_Rdb_Query (OH_Rdb_Store *store, OH_Predicates *predicates, const char *const *columnNames, int length)Queries data in an RDB store.
OH_Rdb_Execute (OH_Rdb_Store *store, const char *sql)Executes the SQL statement that returns no value.
OH_Rdb_ExecuteQuery (OH_Rdb_Store *store, const char *sql)Queries data in the database using the specified SQL statement. This API supports vector stores.
OH_Rdb_BeginTransaction (OH_Rdb_Store *store)Begins the transaction before executing the SQL statements.
OH_Rdb_RollBack (OH_Rdb_Store *store)Rolls back the SQL statements that have been executed.
OH_Rdb_Commit (OH_Rdb_Store *store)Commits the executed SQL statements.
OH_Rdb_Backup (OH_Rdb_Store *store, const char *databasePath)Backs up an RDB store using the backup file of the specified path. This API supports vector stores.
OH_Rdb_Restore (OH_Rdb_Store *store, const char *databasePath)Restores a database from a specified database backup file. This API supports vector stores.
OH_Rdb_GetVersion (OH_Rdb_Store *store, int *version)Obtains the RDB store version.
OH_Rdb_SetVersion (OH_Rdb_Store *store, int version)Sets the RDB store version.
OH_Rdb_SetDistributedTables (OH_Rdb_Store *store, const char *tables[], uint32_t count, Rdb_DistributedType type, const Rdb_DistributedConfig *config)Sets distributed database tables.
OH_Rdb_FindModifyTime (OH_Rdb_Store *store, const char *tableName, const char *columnName, OH_VObject *values)Obtains the last modification time of a table in an RDB store.
OH_Rdb_Subscribe (OH_Rdb_Store *store, Rdb_SubscribeType type, const Rdb_DataObserver *observer)Registers an observer for an RDB store. When data in the RDB store changes, a callback will be invoked to return the data changes.
OH_Rdb_Unsubscribe (OH_Rdb_Store *store, Rdb_SubscribeType type, const Rdb_DataObserver *observer)Unregisters the observer of the specified type.
OH_Rdb_GetTableDetails (Rdb_ProgressDetails *progress, int32_t version)Obtains the device-cloud sync statistics of a table.
OH_Rdb_CloudSync (OH_Rdb_Store *store, Rdb_SyncMode mode, const char *tables, int count, const Rdb_ProgressObserver *observer)Performs device-cloud sync.
OH_Rdb_SubscribeAutoSyncProgress (OH_Rdb_Store *store, const Rdb_ProgressObserver *observer)Subscribes to the automatic sync progress of an RDB store. The registered callback will be invoked to return the automatic sync progress.
OH_Rdb_UnsubscribeAutoSyncProgress (OH_Rdb_Store *store, const Rdb_ProgressObserver *observer)Unsubscribes from the automatic sync process of an RDB store.
int OH_Rdb_LockRow (OH_Rdb_Store *store, OH_Predicates *predicates)Locks data in an RDB store based on specified conditions. The locked data will be blocked from the device-cloud sync.
int OH_Rdb_UnlockRow (OH_Rdb_Store *store, OH_Predicates *predicates)Unlocks data in an RDB store based on the specified conditions.
OH_Cursor * OH_Rdb_QueryLockedRow (OH_Rdb_Store *store, OH_Predicates *predicates, const char *const *columnNames, int length)Queries the locked data in an RDB store.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkData (ArkData Management)

harmony 鸿蒙Data

harmony 鸿蒙OH_Cursor

harmony 鸿蒙OH_Predicates

harmony 鸿蒙OH_Rdb_Config

harmony 鸿蒙OH_Rdb_Store

harmony 鸿蒙OH_VBucket

harmony 鸿蒙OH_VObject

harmony 鸿蒙Preferences

harmony 鸿蒙_r_d_b

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/jm4sqY