openharmony 鸿蒙 capi-relational-store-h

2026-08-25 浏览 (1)

relational_store.h

Overview

Provides APIs for managing data in an 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

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Since: 10

Related module: RDB

Summary

Structs

Nametypedef KeywordDescription
OH_Rdb_ConfigOH_Rdb_ConfigDefines the configuration of an RDB store.
OH_Rdb_StoreOH_Rdb_StoreDefines the RDB store type.
Rdb_DistributedConfigRdb_DistributedConfigDefines a struct for distributed configuration of a table.
Rdb_KeyInfoRdb_KeyInfoDefines a struct for the primary key or number of the row that changes.
Rdb_KeyData-Stores the changed data.
Rdb_ChangeInfoRdb_ChangeInfoDefines a struct for the details about the device-cloud sync process.
Rdb_SubscribeCallbackRdb_SubscribeCallbackDefines a callback used to return the subscribed event.
Rdb_DataObserverRdb_DataObserverDefines a struct for the data observer.
Rdb_StatisticRdb_StatisticDefines a struct for the device-cloud sync statistics of a database table.
Rdb_TableDetailsRdb_TableDetailsDefines a struct for statistics of device-cloud upload and download tasks of a database table.
Rdb_ProgressDetailsRdb_ProgressDetailsDefines a struct for statistics of the overall device-cloud sync (upload and download) tasks of an RDB store.
Rdb_ProgressObserverRdb_ProgressObserverDefines the observer of the device-cloud sync progress.
OH_Rdb_ConfigV2OH_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.

Enums

Nametypedef KeywordDescription
OH_Rdb_SecurityLevelOH_Rdb_SecurityLevelEnumerates the RDB store security levels.
Rdb_SecurityAreaRdb_SecurityAreaEnumerates the encryption levels of database files.
Rdb_DBTypeRdb_DBTypeEnumerates the database kernel types.
Rdb_TokenizerRdb_TokenizerEnumerates the database tokenizer types.
Rdb_DistributedTypeRdb_DistributedTypeEnumerates the distributed types.
Rdb_ChangeTypeRdb_ChangeTypeEnumerates the data change types.
Rdb_SubscribeTypeRdb_SubscribeTypeEnumerates the subscription types.
Rdb_SyncModeRdb_SyncModeEnumerates the RDB sync modes.
Rdb_ProgressRdb_ProgressEnumerates the device-cloud sync progress states.
Rdb_ProgressCodeRdb_ProgressCodeEnumerates the device-cloud sync states.

Functions

Nametypedef KeywordDescription
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 created by OH_Rdb_CreateConfig.
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 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.
int OH_Rdb_SetCustomDir(OH_Rdb_ConfigV2 *config, const char *customDir)-Sets the custom directory of the database.
int OH_Rdb_SetReadOnly(OH_Rdb_ConfigV2 *config, bool readOnly)-Sets whether the RDB store is in read-only mode.
int OH_Rdb_SetPlugins(OH_Rdb_ConfigV2 *config, const char **plugins, int32_t length)-Sets the dynamic library with specific capabilities (such as full-text search).
int OH_Rdb_SetCryptoParam(OH_Rdb_ConfigV2 *config, const OH_Rdb_CryptoParam *cryptoParam)-Sets custom encryption parameters.
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 the tokenizer type.
int OH_Rdb_SetPersistent(OH_Rdb_ConfigV2 *config, bool isPersistent)-Sets whether to persist an RDB store.
const int *OH_Rdb_GetSupportedDbType(int *typeCount)-Obtains the supported database type (Rdb_DBType).
OH_VObject *OH_Rdb_CreateValueObject()-Creates an OH_VObject instance.
OH_VBucket *OH_Rdb_CreateValuesBucket()-Creates an OH_VBucket instance.
OH_Predicates *OH_Rdb_CreatePredicates(const char *table)-Creates an OH_Predicates instance.
OH_Rdb_Store *OH_Rdb_GetOrOpen(const OH_Rdb_Config *config, int *errCode)-Obtains a related OH_Rdb_Store instance to operate the RDB store.
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_CloseStore(OH_Rdb_Store *store)-Closes an OH_Rdb_Store object and reclaims the memory occupied by the object.
int OH_Rdb_DeleteStore(const OH_Rdb_Config *config)-Deletes an RDB store with the specified configuration.
int OH_Rdb_DeleteStoreV2(const OH_Rdb_ConfigV2 *config)-Deletes an RDB store based on the given OH_Rdb_ConfigV2.
Before calling DeleteStoreV2, ensure that the OH_Rdb_Store and OH_Cursor of the vector store have been closed.
int OH_Rdb_Insert(OH_Rdb_Store *store, const char *table, OH_VBucket *valuesBucket)-Inserts a row of data into a table.
int OH_Rdb_InsertWithConflictResolution(OH_Rdb_Store *store, const char *table, OH_VBucket *row,Rdb_ConflictResolution resolution, int64_t *rowId)-Inserts a row of data into the target table and supports conflict resolution.
int OH_Rdb_BatchInsert(OH_Rdb_Store *store, const char *table,const OH_Data_VBuckets *rows, Rdb_ConflictResolution resolution, int64_t *changes)-Inserts data into a table in batches.
int OH_Rdb_Update(OH_Rdb_Store *store, OH_VBucket *valuesBucket, OH_Predicates *predicates)-Updates data in an RDB store based on specified conditions.
int OH_Rdb_UpdateWithConflictResolution(OH_Rdb_Store *store, OH_VBucket *row, OH_Predicates *predicates,Rdb_ConflictResolution resolution, int64_t *changes)-Updates data in the database based on specified conditions and supports conflict resolution.
int OH_Rdb_Delete(OH_Rdb_Store *store, OH_Predicates *predicates)-Deletes data from an RDB store based on specified conditions.
OH_Cursor *OH_Rdb_Query(OH_Rdb_Store *store, OH_Predicates *predicates, const char *const *columnNames, int length)-Queries data in an RDB store based on specified conditions.
int OH_Rdb_Execute(OH_Rdb_Store *store, const char *sql)-Executes an SQL statement that returns no value.
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.
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 only vector stores.
OH_Cursor *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_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_BeginTransaction(OH_Rdb_Store *store)-Begins the transaction before executing SQL statements.
int OH_Rdb_RollBack(OH_Rdb_Store *store)-Rolls back the SQL statements executed.
int OH_Rdb_Commit(OH_Rdb_Store *store)-Commits the executed SQL statement.
int OH_Rdb_BeginTransWithTrxId(OH_Rdb_Store *store, int64_t *trxId)-Begins a transaction. This API returns a transaction ID API and supports only 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 only 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 only vector stores.
int 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.
int OH_Rdb_Restore(OH_Rdb_Store *store, const char *databasePath)-Restores a database from a specified database backup file. This API supports vector stores.
int OH_Rdb_GetVersion(OH_Rdb_Store *store, int *version)-Obtains the RDB store version.
int OH_Rdb_SetVersion(OH_Rdb_Store *store, int version)-Sets the RDB store version.
int 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_Cursor *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.
typedef void (*Rdb_BriefObserver)(void *context, const char *values[], uint32_t count)Rdb_BriefObserverDefines a callback used to return the device-cloud data change event.
typedef void (*Rdb_DetailsObserver)(void *context, const Rdb_ChangeInfo **changeInfo, uint32_t count)Rdb_DetailsObserverDefines a callback used to return the details about the device-cloud data change.
int OH_Rdb_Subscribe(OH_Rdb_Store *store, Rdb_SubscribeType type, const Rdb_DataObserver *observer)-Registers an observer for an RDB store. The registered callback will be invoked when data in a distributed or local RDB store changes.
int OH_Rdb_Unsubscribe(OH_Rdb_Store *store, Rdb_SubscribeType type, const Rdb_DataObserver *observer)-Unregisters the observer of the specified type.
Rdb_TableDetails *OH_Rdb_GetTableDetails(Rdb_ProgressDetails *progress, int32_t version)-Obtains the device-cloud sync statistics of a table.
typedef void (*Rdb_ProgressCallback)(void *context, Rdb_ProgressDetails *progressDetails)Rdb_ProgressCallbackDefines a callback used to return the device-cloud sync progress.
typedef void (*Rdb_SyncCallback)(Rdb_ProgressDetails *progressDetails)Rdb_SyncCallbackDefines a callback for device-cloud sync.
int OH_Rdb_CloudSync(OH_Rdb_Store *store, Rdb_SyncMode mode, const char *tables[], uint32_t count,const Rdb_ProgressObserver *observer)-Performs device-cloud sync.
int OH_Rdb_SubscribeAutoSyncProgress(OH_Rdb_Store *store, const Rdb_ProgressObserver *observer)-Subscribes to the auto sync progress of an RDB store.
The registered callback will be invoked to return the auto sync progress.
int OH_Rdb_UnsubscribeAutoSyncProgress(OH_Rdb_Store *store, const Rdb_ProgressObserver *observer)-Unsubscribes from the auto 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 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.
int OH_Rdb_CreateTransaction(OH_Rdb_Store *store, const OH_RDB_TransOptions *options, OH_Rdb_Transaction **trans)-Creates a transaction object.
int OH_Rdb_Attach(OH_Rdb_Store *store, const OH_Rdb_ConfigV2 *config, const char *attachName, int64_t waitTime,size_t *attachedNumber)-Attaches a database file to the database that is currently connected.
int OH_Rdb_Detach(OH_Rdb_Store *store, const char *attachName, int64_t waitTime, size_t *attachedNumber)-Detaches a specified store from the current database.
int OH_Rdb_SetLocale(OH_Rdb_Store *store, const char *locale)-Sets locale.
int OH_Rdb_SetSemanticIndex(OH_Rdb_ConfigV2 *config, bool enableSemanticIndex)-Sets whether to enable knowledge processing based on semantic indexes.
int OH_Rdb_RekeyEx(OH_Rdb_Store *store, OH_Rdb_CryptoParam *param)-Changes the key used to encrypt the database.
Key update is not supported for databases in non-WAL mode.
Manual update requires exclusive access to the database. If any result set, transaction, or database opened by another process is not released, the update will fail.
Parameter update for an encrypted database and conversion between an encrypted database and a non-encrypted database are supported.
The larger the database, the longer the update takes.
Exercise caution when changing the encryption parameters. The correct encryption parameters must be passed when OH_Rdb_CreateOrOpen is called. Otherwise, the database may fail to be opened.
typedef void (*Rdb_CorruptedHandler)(void *context, OH_Rdb_ConfigV2 *config, OH_Rdb_Store *store)Rdb_CorruptedHandlerDefines a handler for processing database exceptions.
int OH_Rdb_RegisterCorruptedHandler(const OH_Rdb_ConfigV2 *config, void *context, const Rdb_CorruptedHandler handler)-Registers a handler for processing database exceptions. When a database exception occurs, this handler is called.
The exception handling logic is user-defined. You should ensure the service quality each time the callback is triggered.
Only one handler can be registered for each path.
int OH_Rdb_UnregisterCorruptedHandler(const OH_Rdb_ConfigV2 *config, void *context, const Rdb_CorruptedHandler handler)-Unregisters the handler for processing database exceptions.
The handler and context must be the same as those during subscription. Otherwise, the operation fails.
OH_Cursor *OH_Rdb_QueryWithoutRowCount(OH_Rdb_Store *store, OH_Predicates *predicates, const char * const columns[], int length)-Queries data from the database based on specified conditions without calculating the row count.
OH_Cursor *OH_Rdb_QuerySqlWithoutRowCount(OH_Rdb_Store *store, const char *sql, const OH_Data_Values *args)-Executes an SQL statement with a return value. This function does not calculate the row count, and supports vector stores.
int OH_Rdb_BatchInsertWithReturning(OH_Rdb_Store *store, const char *table, const OH_Data_VBuckets *rows, Rdb_ConflictResolution resolution, OH_RDB_ReturningContext *context)-Inserts batch data into the target table and outputs the change information to the context.
int OH_Rdb_UpdateWithReturning(OH_Rdb_Store *store, OH_VBucket *row, OH_Predicates *predicates, Rdb_ConflictResolution resolution, OH_RDB_ReturningContext *context)-Updates data in the database based on specified conditions and outputs the change information to the context.
int OH_Rdb_DeleteWithReturning(OH_Rdb_Store *store, OH_Predicates *predicates, OH_RDB_ReturningContext *context)-Deletes data from the database based on specified conditions and outputs the change information to the context.

Macros

NameDescription
DISTRIBUTED_CONFIG_VERSION 1Describes the version of Rdb_DistributedConfig.
Since: 11
DISTRIBUTED_CHANGE_INFO_VERSION 1Describes the version of Rdb_ChangeInfo.
Since: 11
DISTRIBUTED_PROGRESS_DETAIL_VERSION 1Describes the version of Rdb_ProgressDetails.
Since: 11

Enum Description

OH_Rdb_SecurityLevel

enum OH_Rdb_SecurityLevel

Description

Enumerates the RDB store security levels.

Since: 10

Enum ItemDescription
S1 = 1Low security level. If data leakage occurs, minor impact will be caused.
S2Medium security level. If data leakage occurs, moderate impact will be caused.
S3High security level. If data leakage occurs, major impact will be caused.
S4Critical security level. If data leakage occurs, critical impact will be caused.

Rdb_SecurityArea

enum Rdb_SecurityArea

Description

Enumerates the encryption levels of database files.

Since: 11

Enum ItemDescription
RDB_SECURITY_AREA_EL1 = 1Encryption level 1.
RDB_SECURITY_AREA_EL2Encryption level 2.
RDB_SECURITY_AREA_EL3Encryption level 3.
RDB_SECURITY_AREA_EL4Encryption level 4.
RDB_SECURITY_AREA_EL5Encryption level 5.
Since: 12

Rdb_DBType

enum Rdb_DBType

Description

Enumerates the database kernel types.

Since: 14

Enum ItemDescription
RDB_SQLITE = 1SQLite is used as the database kernel.
RDB_CAYLEY = 2Cayley is used as the database kernel.
DBTYPE_BUTT = 64Maximum value of the database kernel type, which is an invalid value.

Rdb_Tokenizer

enum Rdb_Tokenizer

Description

Enumerates the database tokenizer types.

Since: 17

Enum ItemDescription
RDB_NONE_TOKENIZER = 1No tokenizer is used.
RDB_ICU_TOKENIZER = 2ICU tokenizer.
RDB_CUSTOM_TOKENIZER = 3Custom tokenizer.
Since: 18

Rdb_DistributedType

enum Rdb_DistributedType

Description

Enumerates the distributed types.

Since: 11

Enum ItemDescription
RDB_DISTRIBUTED_CLOUDDistributed database tables for device-cloud sync.

Rdb_ChangeType

enum Rdb_ChangeType

Description

Enumerates the data change types.

Since: 11

Enum ItemDescription
RDB_DATA_CHANGEData change.
RDB_ASSET_CHANGEAsset change.

Rdb_SubscribeType

enum Rdb_SubscribeType

Description

Enumerates the subscription types.

Since: 11

Enum ItemDescription
RDB_SUBSCRIBE_TYPE_CLOUDSubscribe to cloud data changes.
RDB_SUBSCRIBE_TYPE_CLOUD_DETAILSSubscribe to detailed information about cloud data changes.
RDB_SUBSCRIBE_TYPE_LOCAL_DETAILSSubscribe to detailed information about local data changes.
Since: 12

Rdb_SyncMode

enum Rdb_SyncMode

Description

Sync mode of the database.

Since: 11

Enum ItemDescription
RDB_SYNC_MODE_TIME_FIRSTSynchronize with the data with the latest modification time.
RDB_SYNC_MODE_NATIVE_FIRSTSynchronize data from a local device to the cloud.
RDB_SYNC_MODE_CLOUD_FIRSTSynchronize data from the cloud to a local device.

Rdb_Progress

enum Rdb_Progress

Description

Enumerates the device-cloud sync progress states.

Since: 11

Enum ItemDescription
RDB_SYNC_BEGINThe device-cloud sync starts.
RDB_SYNC_IN_PROGRESSThe device-cloud sync is in progress.
RDB_SYNC_FINISHThe device-cloud sync is finished.

Rdb_ProgressCode

enum Rdb_ProgressCode

Description

Enumerates the device-cloud sync states.

Since: 11

Enum ItemDescription
RDB_SUCCESSThe device-cloud sync is successful.
RDB_UNKNOWN_ERRORAn unknown error occurs during the device-cloud sync.
RDB_NETWORK_ERRORA network error occurs during the device-cloud sync.
RDB_CLOUD_DISABLEDThe cloud is unavailable.
RDB_LOCKED_BY_OTHERSThe device-cloud sync of another device is being performed.
RDB_RECORD_LIMIT_EXCEEDEDThe number of records or size of the data to be synced exceeds the maximum. The maximum value is configured on the cloud.
RDB_NO_SPACE_FOR_ASSETThe remaining cloud space is less than the size of the data to be synced.

Function Description

OH_Rdb_SetSemanticIndex()

int OH_Rdb_SetSemanticIndex(OH_Rdb_ConfigV2 *config, bool enableSemanticIndex)

Description

Sets whether to enable knowledge processing based on semantic indexes.

Since: 20

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance.
bool enableSemanticIndexWhether to enable knowledge processing based on semantic indexes.
The value true indicates that the function is enabled; the value false indicates the opposite.

Returns

TypeDescription
intReturns an error code. For details about the error codes, see OH_Rdb_ErrCode.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_CreateConfig()

OH_Rdb_ConfigV2 *OH_Rdb_CreateConfig()

Description

Creates an OH_Rdb_ConfigV2 instance.

Since: 14

Returns

TypeDescription
OH_Rdb_ConfigV2Pointer to the OH_Rdb_ConfigV2 instance.
After use, release the memory by calling the OH_Rdb_DestroyConfig API.

See

OH_Rdb_ConfigV2

OH_Rdb_DestroyConfig()

int OH_Rdb_DestroyConfig(OH_Rdb_ConfigV2 *config)

Description

Destroys an OH_Rdb_ConfigV2 instance created by OH_Rdb_CreateConfig.

Since: 14

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetDatabaseDir()

int OH_Rdb_SetDatabaseDir(OH_Rdb_ConfigV2 *config, const char *databaseDir)

Description

Sets the database file path for an OH_Rdb_ConfigV2 instance.

Since: 14

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.
const char *dataBaseDirPointer to the database file path to set. The full path, including the RDB store name, cannot exceed a maximum of 1024 characters.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetStoreName()

int OH_Rdb_SetStoreName(OH_Rdb_ConfigV2 *config, const char *storeName)

Description

Sets the database name for an OH_Rdb_ConfigV2 instance.

Since: 14

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.
const char *storeNamePointer to the RDB store name to set.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetBundleName()

int OH_Rdb_SetBundleName(OH_Rdb_ConfigV2 *config, const char *bundleName)

Description

Sets the bundle name for an OH_Rdb_ConfigV2 instance.

Since: 14

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.
const char *bundleNamePointer to the application bundle name to set.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetModuleName()

int OH_Rdb_SetModuleName(OH_Rdb_ConfigV2 *config, const char *moduleName)

Description

Sets the module name for an OH_Rdb_ConfigV2 instance.

Since: 14

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.
const char *moduleNamePointer to the module name to set.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetEncrypted()

int OH_Rdb_SetEncrypted(OH_Rdb_ConfigV2 *config, bool isEncrypted)

Description

Sets whether to encrypt the database for an OH_Rdb_ConfigV2 instance.

Since: 14

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.
bool isEncryptedWhether to encrypt the RDB store. The value true means to encrypt the database; the value false means the opposite. After the database is created, this parameter cannot be modified directly. To change the database encryption status, call the OH_Rdb_RekeyEx API.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetSecurityLevel()

int OH_Rdb_SetSecurityLevel(OH_Rdb_ConfigV2 *config, int securityLevel)

Description

Sets the database security level (OH_Rdb_SecurityLevel) for an OH_Rdb_ConfigV2 instance.

This method must be called during database creation. Otherwise, the database file cannot be created, and the error code RDB_E_INVALID_ARGS is returned when the OH_Rdb_CreateOrOpen API is called.

Since: 14

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.
int securityLevelDatabase security level (OH_Rdb_SecurityLevel).

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetArea()

int OH_Rdb_SetArea(OH_Rdb_ConfigV2 *config, int area)

Description

Sets the security area level (Rdb_SecurityArea) for an OH_Rdb_ConfigV2 instance.

This method must be called during database creation. Otherwise, the database file cannot be created, and the error code RDB_E_INVALID_ARGS is returned when the OH_Rdb_CreateOrOpen API is called.

Since: 14

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.
int areaDatabase security area level (Rdb_SecurityArea).

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetDbType()

int OH_Rdb_SetDbType(OH_Rdb_ConfigV2 *config, int dbType)

Description

Sets the database type (Rdb_DBType) for an OH_Rdb_ConfigV2 instance.

Since: 14

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.
int dbTypeDatabase type (Rdb_DBType).

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_NOT_SUPPORTED indicates that the current operation is not supported.

OH_Rdb_SetCustomDir()

int OH_Rdb_SetCustomDir(OH_Rdb_ConfigV2 *config, const char *customDir)

Description

Sets the custom directory of the database.

Since: 20

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance.
const char *customDirCustom directory of the database, with a maximum length of 128 bytes.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetReadOnly()

int OH_Rdb_SetReadOnly(OH_Rdb_ConfigV2 *config, bool readOnly)

Description

Sets whether the RDB store is in read-only mode.

Since: 20

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance.
bool readOnlyWhether the RDB store is in read-only mode. The value true indicates that the RDB store is in read-only mode; the value false indicates that the RDB store is in read/write mode.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetPlugins()

int OH_Rdb_SetPlugins(OH_Rdb_ConfigV2 *config, const char **plugins, int32_t length)

Description

Sets the dynamic library with specific capabilities (such as full-text search).

Since: 20

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance.
const char **pluginsName array of the dynamic library.
int32_t lengthSize of the plugin array. The maximum value is 16.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetCryptoParam()

int OH_Rdb_SetCryptoParam(OH_Rdb_ConfigV2 *config, const OH_Rdb_CryptoParam *cryptoParam)

Description

Sets custom encryption parameters.

Since: 20

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance.
const OH_Rdb_CryptoParam *cryptoParamCustom encryption parameters.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_IsTokenizerSupported()

int OH_Rdb_IsTokenizerSupported(Rdb_Tokenizer tokenizer, bool *isSupported)

Description

Checks whether the specified tokenizer is supported.

Since: 18

Parameters

ParameterDescription
Rdb_Tokenizer tokenizerTokenizer to check.
bool *isSupportedPointer to the check result. The value true means the tokenizer is supported; the value false means the opposite.

Returns

TypeDescription
intReturns operation status code.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetTokenizer()

int OH_Rdb_SetTokenizer(OH_Rdb_ConfigV2 *config, Rdb_Tokenizer tokenizer)

Description

Sets the tokenizer type.

Since: 17

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the database configuration related to the RDB storage.
Rdb_Tokenizer tokenizerTokenizer type to set.

Returns

TypeDescription
intReturns operation status code.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_NOT_SUPPORTED indicates that the current operation is not supported.

OH_Rdb_SetPersistent()

int OH_Rdb_SetPersistent(OH_Rdb_ConfigV2 *config, bool isPersistent)

Description

Sets whether to persist an RDB store.

Since: 18

Parameters

ParameterDescription
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance,
which specifies the database configuration.
bool isPersistentWhether to persist the database data.

Returns

TypeDescription
intReturns operation status code.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_GetSupportedDbType()

const int *OH_Rdb_GetSupportedDbType(int *typeCount)

Description

Obtains the supported database type (Rdb_DBType).

Since: 14

Parameters

ParameterDescription
int *typeCountPointer to the length of the array of the supported database types obtained.

Returns

TypeDescription
const int *Returns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_CreateValueObject()

OH_VObject *OH_Rdb_CreateValueObject()

Description

Creates an OH_VObject instance.

Since: 10

Returns

TypeDescription
OH_VObjectReturns the pointer to the OH_VObject instance created if the operation is successful; returns NULL otherwise.

See

OH_VObject

OH_Rdb_CreateValuesBucket()

OH_VBucket *OH_Rdb_CreateValuesBucket()

Description

Creates an OH_VBucket instance.

Since: 10

Returns

TypeDescription
OH_VBucketReturns the pointer to the OH_VBucket instance created if the operation is successful; returns NULL otherwise.

See

OH_VBucket

OH_Rdb_CreatePredicates()

OH_Predicates *OH_Rdb_CreatePredicates(const char *table)

Description

Creates an OH_Predicates instance.

Since: 10

Parameters

ParameterDescription
const char *tablePointer to the name of the database table.

Returns

TypeDescription
OH_PredicatesReturns the pointer to the OH_Predicates instance created if the operation is successful; returns NULL otherwise.

See

OH_Predicates

OH_Rdb_GetOrOpen()

OH_Rdb_Store *OH_Rdb_GetOrOpen(const OH_Rdb_Config *config, int *errCode)

Description

Obtains a related OH_Rdb_Store instance to operate the RDB store.

Since: 10

Parameters

ParameterDescription
const OH_Rdb_Config *configPointer to the OH_Rdb_Config instance, which is the configuration of the RDB store.
int *errCodePointer to the execution result of this API.

Returns

TypeDescription
OH_Rdb_StoreReturns the pointer to the OH_Rdb_Store instance created if the operation is successful; returns NULL otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_CreateOrOpen()

OH_Rdb_Store *OH_Rdb_CreateOrOpen(const OH_Rdb_ConfigV2 *config, int *errCode)

Description

Creates or opens an OH_Rdb_Store instance based on the given OH_Rdb_ConfigV2.

Since: 14

Parameters

ParameterDescription
const OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.
int *errCodePointer to the execution result of this API.

Returns

TypeDescription
OH_Rdb_StoreReturns the pointer to the OH_Rdb_Store instance created if the operation is successful; returns NULL otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_CloseStore()

int OH_Rdb_CloseStore(OH_Rdb_Store *store)

Description

Closes an OH_Rdb_Store object and reclaims the memory occupied by the object.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_DeleteStore()

int OH_Rdb_DeleteStore(const OH_Rdb_Config *config)

Description

Deletes an RDB store with the specified configuration.

Since: 10

Parameters

ParameterDescription
const OH_Rdb_Config *configPointer to the database configuration.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_DeleteStoreV2()

int OH_Rdb_DeleteStoreV2(const OH_Rdb_ConfigV2 *config)

Description

Deletes an RDB store based on the given OH_Rdb_ConfigV2.
Before calling DeleteStoreV2, ensure that the OH_Rdb_Store and OH_Cursor of the vector store have been closed.

Since: 14

Parameters

ParameterDescription
const OH_Rdb_ConfigV2 *configPointer to the database configuration.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_Insert()

int OH_Rdb_Insert(OH_Rdb_Store *store, const char *table, OH_VBucket *valuesBucket)

Description

Inserts a row of data into a table.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *tablePointer to the target table.
OH_VBucket *valuesBucketPointer to the data OH_VBucket to insert.

Returns

TypeDescription
intReturns rowID if the operation is successful; returns a number less than 0 otherwise.
RDB_ERR indicates that the operation fails.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_InsertWithConflictResolution()

int OH_Rdb_InsertWithConflictResolution(OH_Rdb_Store *store, const char *table, OH_VBucket *row,Rdb_ConflictResolution resolution, int64_t *rowId)

Description

Inserts a row of data into the target table and supports conflict resolution.

Since: 20

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *tableName of the target table.
OH_VBucket *rowPointer to the row of data to insert.
Rdb_ConflictResolution resolutionPolicy used to resolve file conflicts.
int64_t *rowIdPointer to the row number returned.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_ERROR indicates a common database error.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_ALREADY_CLOSED indicates that the database is already closed.
RDB_E_WAL_SIZE_OVER_LIMIT indicates that the size of the WAL log file exceeds the default value.
RDB_E_SQLITE_FULL indicates an SQLite error: the database is full.
RDB_E_SQLITE_CORRUPT indicates that the database is corrupted.
RDB_E_SQLITE_PERM indicates an SQLite error: access denied.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_LOCKED indicates an SQLite error: database table locked.
RDB_E_SQLITE_NOMEM indicates an SQLite: insufficient database memory.
RDB_E_SQLITE_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite: disk I/O error.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.
RDB_E_SQLITE_CONSTRAINT indicates an SQLite error code: SQLite constraint.

OH_Rdb_BatchInsert()

int OH_Rdb_BatchInsert(OH_Rdb_Store *store, const char *table,const OH_Data_VBuckets *rows, Rdb_ConflictResolution resolution, int64_t *changes)

Description

Inserts data into a table in batches.

A maximum of 32,766 parameters can be inserted at a time. If the number of parameters exceeds this limit, the error code RDB_E_INVALID_ARGS is returned. The number of inserted data records multiplied by the size of the union set of all fields in the inserted data equals the number of parameters.

For example, if the size of the union set is 10, a maximum of 3,276 data records can be inserted (3276 × 10 = 32760).

Ensure that you comply with this constraint when calling this API to avoid errors caused by excessive parameters.

Since: 18

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *tablesPointer to the names of the distributed tables to set.
const OH_Data_VBuckets *rowsAn array of data to insert.
Rdb_ConflictResolution resolutionPolicy used to resolve file conflicts.
int64_t *changesPointer to the number of successful insertions.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_ERROR indicates a common database error.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_ALREADY_CLOSED indicates that the database is already closed.
RDB_E_WAL_SIZE_OVER_LIMIT indicates that the size of the WAL log file exceeds the default value.
RDB_E_SQLITE_FULL indicates an SQLite error: the database is full.
RDB_E_SQLITE_CORRUPT indicates that the database is corrupted.
RDB_E_SQLITE_PERM indicates an SQLite error: access denied.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_LOCKED indicates an SQLite error: database table locked.
RDB_E_SQLITE_NOMEM indicates an SQLite: insufficient database memory.
RDB_E_SQLITE_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite: disk I/O error.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.
RDB_E_SQLITE_CONSTRAINT indicates an SQLite error code: SQLite constraint.

OH_Rdb_Update()

int OH_Rdb_Update(OH_Rdb_Store *store, OH_VBucket *valuesBucket, OH_Predicates *predicates)

Description

Updates data in an RDB store based on specified conditions.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
OH_VBucket *valuesBucketPointer to the data OH_VBucket to update.
OH_Predicates *predicatesPointer to the OH_Predicates instance, specifying the update conditions.

Returns

TypeDescription
intReturns the number of updated rows if the operation is successful; returns a number less than 0 otherwise.
RDB_ERR indicates that the operation fails.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_UpdateWithConflictResolution()

int OH_Rdb_UpdateWithConflictResolution(OH_Rdb_Store *store, OH_VBucket *row, OH_Predicates *predicates,Rdb_ConflictResolution resolution, int64_t *changes)

Description

Updates data in the database based on specified conditions and supports conflict resolution.

Since: 20

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
OH_VBucket *rowPointer to the row of data to update.
OH_Predicates *predicatesPointer to the OH_Predicates instance, specifying the update conditions.
Rdb_ConflictResolution resolutionPolicy used to resolve file conflicts.
int64_t *changesPointer to the number of rows that are successfully updated.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_ERROR indicates a common database error.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_ALREADY_CLOSED indicates that the database is already closed.
RDB_E_WAL_SIZE_OVER_LIMIT indicates that the size of the WAL log file exceeds the default value.
RDB_E_SQLITE_FULL indicates an SQLite error: the database is full.
RDB_E_SQLITE_CORRUPT indicates that the database is corrupted.
RDB_E_SQLITE_PERM indicates an SQLite error: access denied.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_LOCKED indicates an SQLite error: database table locked.
RDB_E_SQLITE_NOMEM indicates an SQLite: insufficient database memory.
RDB_E_SQLITE_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite: disk I/O error.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.
RDB_E_SQLITE_CONSTRAINT indicates an SQLite error code: SQLite constraint.

OH_Rdb_Delete()

int OH_Rdb_Delete(OH_Rdb_Store *store, OH_Predicates *predicates)

Description

Deletes data from an RDB store based on specified conditions.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
OH_Predicates *predicatesPointer to the OH_Predicates instance, specifying the deletion conditions.

Returns

TypeDescription
intReturns the number of deleted rows if the operation is successful; returns a number less than 0 otherwise.
RDB_ERR indicates that the operation fails.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_Query()

OH_Cursor *OH_Rdb_Query(OH_Rdb_Store *store, OH_Predicates *predicates, const char *const *columnNames, int length)

Description

Queries data in an RDB store based on specified conditions.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
OH_Predicates *predicatesPointer to the OH_Predicates instance, specifying the query conditions.
const char *const *columnNamesColumns to query. If null is passed in, all columns are queried.
int lengthLength of columnNames. If the length is greater than the length of columnNames array, an out-of-bounds access will occur.

Returns

TypeDescription
OH_Cursor *Returns the pointer to the OH_Cursor instance if the operation is successful; returns NULL otherwise.

OH_Rdb_Execute()

int OH_Rdb_Execute(OH_Rdb_Store *store, const char *sql)

Description

Executes an SQL statement that returns no value.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *sqlSQL statement to execute.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

See

OH_Rdb_Store

OH_Rdb_ExecuteV2()

int OH_Rdb_ExecuteV2(OH_Rdb_Store *store, const char *sql, const OH_Data_Values *args, OH_Data_Value **result)

Description

Executes an SQL statement with a return value. This API supports vector stores.

Statements starting with comments are not supported.

Since: 18

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *sqlSQL statement to execute.
const OH_Data_Values *args(Optional) Pointer to the OH_Data_Values instance.
OH_Data_Value **resultPointer to the OH_Data_Value instance when the execution is successful. Use OH_Value_Destroy to release the memory in time.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_ERROR indicates a common database error.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_ALREADY_CLOSED indicates that the database is already closed.
RDB_E_WAL_SIZE_OVER_LIMIT indicates that the size of the WAL log file exceeds the default value.
RDB_E_SQLITE_FULL indicates an SQLite error: the database is full.
RDB_E_SQLITE_CORRUPT indicates that the database is corrupted.
RDB_E_SQLITE_PERM indicates an SQLite error: access denied.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_LOCKED indicates an SQLite error: database table locked.
RDB_E_SQLITE_NOMEM indicates an SQLite: insufficient database memory.
RDB_E_SQLITE_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite: disk I/O error.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.

See

OH_Value_Destroy

OH_Rdb_ExecuteByTrxId()

int OH_Rdb_ExecuteByTrxId(OH_Rdb_Store *store, int64_t trxId, const char *sql)

Description

Executes an SQL statement that returns no value based on the specified transaction ID. This API supports only vector stores.

Statements starting with comments are not supported.

Since: 14

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
int64_t trxIdTransaction ID returned by OH_Rdb_BeginTransWithTrxId. The value 0 indicates that no transaction is enabled.
const char *sqlSQL statement to execute.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates invalid parameters. The possible causes are as follows:
The input parameter is a null pointer.
The current transaction ID is not obtained by calling OH_Rdb_BeginTransWithTrxId.
The current transaction ID has been submitted by calling OH_Rdb_CommitByTrxId.
The current transaction ID has been rolled back by calling OH_Rdb_RollBackByTrxId.
store or sql is NULL.
RDB_E_NOT_SUPPORTED indicates that the current operation is not supported.

See

OH_Rdb_Store

OH_Rdb_ExecuteQuery()

OH_Cursor *OH_Rdb_ExecuteQuery(OH_Rdb_Store *store, const char *sql)

Description

Queries data in the database using the specified SQL statement. This API supports vector stores.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *sqlSQL statement to execute.

Returns

TypeDescription
OH_CursorReturns the pointer to the OH_Cursor instance if the operation is successful; returns NULL otherwise.

See

OH_Rdb_Store

OH_Rdb_ExecuteQueryV2()

OH_Cursor *OH_Rdb_ExecuteQueryV2(OH_Rdb_Store *store, const char *sql, const OH_Data_Values *args)

Description

Queries data in the database using the specified SQL statement. This API supports vector stores.

Since: 18

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *sqlSQL statement to execute.
const OH_Data_Values *args(Optional) Pointer to the OH_Data_Values instance.

Returns

TypeDescription
OH_Cursor *Returns a pointer to the OH_Cursor instance if the operation is successful. The OH_Cursor instance is released if it is no longer required in time.
Returns NULL if the SQL statement is invalid or the memory allocation fails.

See

OH_Rdb_Store

OH_Rdb_BeginTransaction()

int OH_Rdb_BeginTransaction(OH_Rdb_Store *store)

Description

Begins the transaction before executing SQL statements.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_RollBack()

int OH_Rdb_RollBack(OH_Rdb_Store *store)

Description

Rolls back the SQL statements executed.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_Commit()

int OH_Rdb_Commit(OH_Rdb_Store *store)

Description

Commits the executed SQL statement.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_BeginTransWithTrxId()

int OH_Rdb_BeginTransWithTrxId(OH_Rdb_Store *store, int64_t *trxId)

Description

Begins a transaction. This API returns a transaction ID and supports only vector stores.

Since: 14

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
int64_t *trxIdPointer to the transaction ID returned.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_NOT_SUPPORTED indicates that the current operation is not supported.

OH_Rdb_RollBackByTrxId()

int OH_Rdb_RollBackByTrxId(OH_Rdb_Store *store, int64_t trxId)

Description

Rolls back the executed SQL statements based on the specified transaction ID. This API supports only vector stores.

Since: 14

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
int64_t trxIdID of the transaction to be rolled back.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates invalid parameters. The possible causes are as follows:
The input parameter is a null pointer.
The current transaction ID is not obtained by calling OH_Rdb_BeginTransWithTrxId.
The current transaction ID has been submitted by calling OH_Rdb_CommitByTrxId.
The current transaction ID has been rolled back by calling OH_Rdb_RollBackByTrxId.
RDB_E_NOT_SUPPORTED indicates that the current operation is not supported.

OH_Rdb_CommitByTrxId()

int OH_Rdb_CommitByTrxId(OH_Rdb_Store *store, int64_t trxId)

Description

Commits the executed SQL statements based on the specified transaction ID. This API supports only vector stores.

Since: 14

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
int64_t trxIdTransaction ID.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates invalid parameters. The possible causes are as follows:
The input parameter is a null pointer.
The current transaction ID is not obtained by calling OH_Rdb_BeginTransWithTrxId.
The current transaction ID has been submitted by calling OH_Rdb_CommitByTrxId.
The current transaction ID has been rolled back by calling OH_Rdb_RollBackByTrxId.
RDB_E_NOT_SUPPORTED indicates that the current operation is not supported.

See

OH_Rdb_Store

OH_Rdb_Backup()

int OH_Rdb_Backup(OH_Rdb_Store *store, const char *databasePath)

Description

Backs up an RDB store using the backup file of the specified path. This API supports vector stores.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *databasePathPointer to the destination directory in which the RDB store is backed up.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

See

OH_Rdb_Store

OH_Rdb_Restore()

int OH_Rdb_Restore(OH_Rdb_Store *store, const char *databasePath)

Description

Restores a database from a specified database backup file. This API supports vector stores.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *databasePathPointer to the destination directory in which the RDB store is backed up.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_GetVersion()

int OH_Rdb_GetVersion(OH_Rdb_Store *store, int *version)

Description

Obtains the RDB store version.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
int *versionPointer to the version number.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SetVersion()

int OH_Rdb_SetVersion(OH_Rdb_Store *store, int version)

Description

Sets the RDB store version.

Since: 10

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
int versionVersion to set.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

See

OH_Rdb_Store

OH_Rdb_SetDistributedTables()

int OH_Rdb_SetDistributedTables(OH_Rdb_Store *store, const char *tables[], uint32_t count, Rdb_DistributedType type,const Rdb_DistributedConfig *config)

Description

Sets distributed database tables.

Since: 11

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *tables[]Pointer to the names of the distributed tables to set.
uint32_t countNumber of distributed database tables to be set.
Rdb_DistributedType typeRdb_DistributedType of the table.
const Rdb_DistributedConfig *configPointer to the distributed configuration of a table (Rdb_DistributedConfig).

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

See

OH_Rdb_Store

OH_Rdb_FindModifyTime()

OH_Cursor *OH_Rdb_FindModifyTime(OH_Rdb_Store *store, const char *tableName, const char *columnName,OH_VObject *values)

Description

Obtains the last modification time of a table in an RDB store.

Since: 11

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *tableNamePointer to the target distributed database table name.
const char *columnNamePointer to the column name of the database table to query.
OH_VObject *valuesPointer to the primary keys of the rows to query. If the database table has no primary key, rowid must be passed in through columnName. In this case, values specifies the row number of the database table to query.

Returns

TypeDescription
OH_CursorReturns the pointer to the OH_Rdb_Store instance created if the operation is successful; returns NULL otherwise.

Rdb_BriefObserver()

typedef void (*Rdb_BriefObserver)(void *context, const char *values[], uint32_t count)

Description

Callback used to return the device-cloud data change event.

Since: 11

Parameters

ParameterDescription
void *contextPointer to the context of the data observer.
const char *values[]Pointer to the accounts whose device-cloud data is changed.
uint32_t countNumber of accounts whose device-cloud data is changed.

Rdb_DetailsObserver()

typedef void (*Rdb_DetailsObserver)(void *context, const Rdb_ChangeInfo **changeInfo, uint32_t count)

Description

Callback used to return the details about the device-cloud data change.

Since: 11

Parameters

ParameterDescription
void *contextPointer to the context of the data observer.
const Rdb_ChangeInfo **changeInfoInformation about the changed table (Rdb_ChangeInfo).
uint32_t countNumber of changed tables.

OH_Rdb_Subscribe()

int OH_Rdb_Subscribe(OH_Rdb_Store *store, Rdb_SubscribeType type, const Rdb_DataObserver *observer)

Description

Registers an observer for an RDB store. The registered callback will be invoked when data in a distributed or local RDB store changes.

Since: 11

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
Rdb_SubscribeType typeSubscription type (Rdb_SubscribeType). If the value is RDB_SUBSCRIBE_TYPE_LOCAL_DETAILS, the callback is called when the data in the local RDB store changes.
const Rdb_DataObserver *observerPointer to the Rdb_DataObserver instance.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_Unsubscribe()

int OH_Rdb_Unsubscribe(OH_Rdb_Store *store, Rdb_SubscribeType type, const Rdb_DataObserver *observer)

Description

Unregisters the observer of the specified type.

Since: 11

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
Rdb_SubscribeType typeSubscription type (Rdb_SubscribeType).
const Rdb_DataObserver *observerPointer to the Rdb_DataObserver instance. If this parameter is nullptr, all observers of this type will be unregistered.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_GetTableDetails()

Rdb_TableDetails *OH_Rdb_GetTableDetails(Rdb_ProgressDetails *progress, int32_t version)

Description

Obtains the device-cloud sync statistics of a table.

Since: 11

Parameters

ParameterDescription
Rdb_ProgressDetails *progressPointer to the Rdb_ProgressDetails instance.
int32_t versionVersion of the current Rdb_ProgressDetails.

Returns

TypeDescription
Rdb_TableDetailsReturns a pointer to Rdb_TableDetails if the operation is successful; returns NULL otherwise.

See

Rdb_TableDetails

Rdb_ProgressCallback()

typedef void (*Rdb_ProgressCallback)(void *context, Rdb_ProgressDetails *progressDetails)

Description

Defines a callback used to return the device-cloud sync progress.

Since: 11

Parameters

ParameterDescription
void *contextPointer to the context of the callback data.
Rdb_ProgressDetails *progressDetailsDetails about the device-cloud sync progress.

Rdb_SyncCallback()

typedef void (*Rdb_SyncCallback)(Rdb_ProgressDetails *progressDetails)

Description

Defines a callback for device-cloud sync.

Since: 11

Parameters

ParameterDescription
Rdb_ProgressDetails *progressDetailsStatistics of device-cloud sync.

OH_Rdb_CloudSync()

int OH_Rdb_CloudSync(OH_Rdb_Store *store, Rdb_SyncMode mode, const char *tables[], uint32_t count,const Rdb_ProgressObserver *observer)

Description

Performs device-cloud sync.

Since: 11

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
Rdb_SyncMode modeType of the sync process (Rdb_SyncMode).
const char *tables[]Pointer to the names of the tables to be synced.
uint32_t countNumber of tables to sync. If the value is 0, all tables in the RDB store are synced.
const Rdb_ProgressObserver *observerPointer to the Rdb_ProgressObserver instance.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_SubscribeAutoSyncProgress()

int OH_Rdb_SubscribeAutoSyncProgress(OH_Rdb_Store *store, const Rdb_ProgressObserver *observer)

Description

Subscribes to the auto sync progress of an RDB store.
The registered callback will be invoked to return the auto sync progress.

Since: 11

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the target OH_Rdb_Store instance.
const Rdb_ProgressObserver *observerPointer to the Rdb_ProgressObserver instance, which invokes the callback to return the automatic sync progress.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_UnsubscribeAutoSyncProgress()

int OH_Rdb_UnsubscribeAutoSyncProgress(OH_Rdb_Store *store, const Rdb_ProgressObserver *observer)

Description

Unsubscribes from the auto sync process of an RDB store.

Since: 11

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the target OH_Rdb_Store instance.
const Rdb_ProgressObserver *observerPointer to the Rdb_ProgressObserver instance. If the pointer is null, all callbacks for the auto sync process will be unregistered.

Returns

TypeDescription
intReturns RDB_OK if the operation is successful; returns an error code otherwise.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_LockRow()

int OH_Rdb_LockRow(OH_Rdb_Store *store, OH_Predicates *predicates)

Description

Locks data in an RDB store based on specified conditions. The locked data will be blocked from the device-cloud sync.

Since: 12

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
OH_Predicates *predicatesPointer to the OH_Predicates instance, specifying the lock conditions.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_UnlockRow()

int OH_Rdb_UnlockRow(OH_Rdb_Store *store, OH_Predicates *predicates)

Description

Unlocks data in an RDB store based on specified conditions.

Since: 12

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
OH_Predicates *predicatesPointer to the OH_Predicates instance, specifying the unlock conditions.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_QueryLockedRow()

OH_Cursor *OH_Rdb_QueryLockedRow(OH_Rdb_Store *store, OH_Predicates *predicates, const char *const *columnNames, int length)

Description

Queries the locked data in an RDB store.

Since: 12

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
OH_Predicates *predicatesPointer to the OH_Predicates instance, specifying the query conditions.
const char *const *columnNamesColumns to query. If null is passed in, all columns are queried.
int lengthLength of columnNames. If the length is greater than the length of columnNames array, an out-of-bounds access will occur.

Returns

TypeDescription
OH_CursorReturns the pointer to the OH_Cursor instance if the operation is successful; returns NULL otherwise.

OH_Rdb_CreateTransaction()

int OH_Rdb_CreateTransaction(OH_Rdb_Store *store, const OH_RDB_TransOptions *options, OH_Rdb_Transaction **trans)

Description

Creates a transaction object.

Since: 18

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const OH_RDB_TransOptions *optionsPointer to the OH_RDB_TransOptions instance.
OH_Rdb_Transaction **transDouble pointer to the OH_Rdb_Transaction instance if the operation is successful; otherwise, nullptr is returned.
Release the memory using OH_RdbTrans_Destroy if the created transaction is used.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_ERROR indicates a common database error.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_ALREADY_CLOSED indicates that the database is already closed.
RDB_E_DATABASE_BUSY indicates that the database does not respond.
RDB_E_SQLITE_FULL indicates an SQLite error: the database is full.
RDB_E_SQLITE_CORRUPT indicates that the database is corrupted.
RDB_E_SQLITE_PERM indicates an SQLite error: access denied.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_NOMEM indicates an SQLite: insufficient database memory.
RDB_E_SQLITE_IOERR indicates an SQLite: disk I/O error.
RDB_E_SQLITE_CANT_OPEN indicates an SQLite error: unable to open the database file.

OH_Rdb_Attach()

int OH_Rdb_Attach(OH_Rdb_Store *store, const OH_Rdb_ConfigV2 *config, const char *attachName, int64_t waitTime,size_t *attachedNumber)

Description

Attaches a database file to the database that is currently connected.

Since: 20

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance.
const char *attachNamePointer to the alias of the database.
int64_t waitTimeMaximum duration for attaching a database, in seconds. The value ranges from 1 to 300.
size_t *attachedNumberPointer to the number of attached databases.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_ERROR indicates a common database error.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_ALREADY_CLOSED indicates that the database is already closed.
RDB_E_NOT_SUPPORTED indicates that the operation is not supported.
RDB_E_DATABASE_BUSY indicates that the database does not respond.
RDB_E_SQLITE_FULL indicates an SQLite error: the database is full.
RDB_E_SQLITE_CORRUPT indicates that the database is corrupted.
RDB_E_SQLITE_PERM indicates an SQLite error: access denied.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_LOCKED indicates an SQLite error: database table locked.
RDB_E_SQLITE_NOMEM indicates an SQLite: insufficient database memory.
RDB_E_SQLITE_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite: disk I/O error.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.
RDB_E_SQLITE_CONSTRAINT indicates an SQLite error code: SQLite constraint.

OH_Rdb_Detach()

int OH_Rdb_Detach(OH_Rdb_Store *store, const char *attachName, int64_t waitTime, size_t *attachedNumber)

Description

Detaches a specified store from the current database.

Since: 20

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *attachNamePointer to the alias of the database.
int64_t waitTimeMaximum duration for detaching a database, in seconds. The value ranges from 1 to 300.
size_t *attachedNumberPointer to the number of attached databases.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_ERROR indicates a common database error.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_ALREADY_CLOSED indicates that the database is already closed.
RDB_E_NOT_SUPPORTED indicates that the operation is not supported.
RDB_E_DATABASE_BUSY indicates that the database does not respond.
RDB_E_SQLITE_FULL indicates an SQLite error: the database is full.
RDB_E_SQLITE_CORRUPT indicates that the database is corrupted.
RDB_E_SQLITE_PERM indicates an SQLite error: access denied.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_LOCKED indicates an SQLite error: database table locked.
RDB_E_SQLITE_NOMEM indicates an SQLite: insufficient database memory.
RDB_E_SQLITE_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite: disk I/O error.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.
RDB_E_SQLITE_CONSTRAINT indicates an SQLite error code: SQLite constraint.

OH_Rdb_SetLocale()

int OH_Rdb_SetLocale(OH_Rdb_Store *store, const char *locale)

Description

Sets locale.

Since: 20

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *localePointer to the locale to set, for example, zh. The value must comply with the ISO 639 standard.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_ERR indicates that the operation fails.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_ALREADY_CLOSED indicates that the database is already closed.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_NOMEM indicates an SQLite: insufficient database memory.

OH_Rdb_RekeyEx()

int OH_Rdb_RekeyEx(OH_Rdb_Store *store, OH_Rdb_CryptoParam *param)

Description

Changes the key used to encrypt the database.

Key update is not supported for databases in non-WAL mode.

Manual update requires exclusive access to the database. If any result set, transaction, or database opened by another process is not released, the update will fail.

Parameter update for an encrypted database and conversion between an encrypted database and a non-encrypted database are supported.

The larger the database, the longer the update takes.

Exercise caution when changing the encryption parameters. The correct encryption parameters must be passed when OH_Rdb_CreateOrOpen is called. Otherwise, the database may fail to be opened.

Since: 22

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
OH_Rdb_CryptoParam *paramPointer to the OH_Rdb_CryptoParam instance.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_ERROR indicates a common database error.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_ALREADY_CLOSED indicates that the database is already closed.
RDB_E_SQLITE_CORRUPT indicates that the database is corrupted.
RDB_E_SQLITE_PERM indicates an SQLite error: access denied.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_NOMEM indicates an SQLite: insufficient database memory.
RDB_E_SQLITE_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite: disk I/O error.
RDB_E_SQLITE_FULL indicates an SQLite error: the database is full.

Rdb_CorruptedHandler()

typedef void (*Rdb_CorruptedHandler)(void *context, OH_Rdb_ConfigV2 *config, OH_Rdb_Store *store)

Description

Defines a handler for processing database exceptions.

Since: 22

Parameters

ParameterDescription
void *contextPointer to the context of the handler. The lifecycle is managed by the service.
OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 object, that is, the database configuration related to the RDB storage. This parameter cannot be used outside the callback function.
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance, which is generated by the system and is released immediately after the callback function ends. This parameter cannot be used outside the callback function.

OH_Rdb_RegisterCorruptedHandler()

int OH_Rdb_RegisterCorruptedHandler(const OH_Rdb_ConfigV2 *config, void *context, const Rdb_CorruptedHandler handler)

Description

Registers a handler for processing database exceptions. When a database exception occurs, this handler is called.

The exception handling logic is user-defined. You should ensure the service quality each time the callback is triggered.

Only one handler can be registered for each path.

Since: 22

Parameters

ParameterDescription
const OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.
void *contextPointer to the context of the handler.
const Rdb_CorruptedHandler handlerHandler for processing database exceptions.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_SUB_LIMIT_REACHED indicates that the number of registration exceeds the upper limit.

OH_Rdb_UnregisterCorruptedHandler()

int OH_Rdb_UnregisterCorruptedHandler(const OH_Rdb_ConfigV2 *config, void *context, const Rdb_CorruptedHandler handler)

Description

Unregisters the handler for processing database exceptions.

The handler and context must be the same as those during subscription. Otherwise, the operation fails.

Since: 22

Parameters

ParameterDescription
const OH_Rdb_ConfigV2 *configPointer to the OH_Rdb_ConfigV2 instance, which is the configuration of the RDB store.
void *contextPointer to the context of the handler.
const Rdb_CorruptedHandler handlerHandler for processing database exceptions.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.

OH_Rdb_QueryWithoutRowCount()

OH_Cursor *OH_Rdb_QueryWithoutRowCount(OH_Rdb_Store *store, OH_Predicates *predicates, const char * const columns[], int length)

Description

Queries data from the database based on specified conditions without calculating the row count.

Since: 23

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
OH_Predicates *predicatesPointer to the OH_Predicates instance, specifying the query conditions.
const char * const columns[]Columns to query. If null is passed in, all columns are queried.
int lengthLength of columns. If the length is greater than the actual length of the columns array, an out-of-bounds access will occur.

Returns

TypeDescription
OH_Cursor *Returns a pointer to the OH_Cursor instance if the operation is successful; returns nullptr if the store acquisition fails or the result set is empty.

OH_Rdb_QuerySqlWithoutRowCount()

OH_Cursor *OH_Rdb_QuerySqlWithoutRowCount(OH_Rdb_Store *store, const char *sql, const OH_Data_Values *args)

Description

Executes an SQL statement with a return value. This function does not calculate the row count, and supports vector stores.

Since: 23

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *sqlSQL statement to execute.
const OH_Data_Values *argsPointer to the OH_Data_Values instance. If the SQL statement is complete, args can be set to nullptr.

Returns

TypeDescription
OH_Cursor *Returns a pointer to the OH_Cursor instance if the operation is successful; returns nullptr if the SQL statement is invalid or the memory allocation fails.

OH_Rdb_BatchInsertWithReturning()

int OH_Rdb_BatchInsertWithReturning(OH_Rdb_Store *store, const char *table, const OH_Data_VBuckets *rows, Rdb_ConflictResolution resolution, OH_RDB_ReturningContext *context)

Description

Inserts batch data into the target table and outputs the change information to the context.

A maximum of 32,766 parameters can be inserted at a time. If the number of parameters exceeds this limit, the error code RDB_E_INVALID_ARGS is returned.

The number of inserted data records multiplied by the size of the union set of all fields in the inserted data equals the number of parameters.

For example, if the size of the union set is 10, a maximum of 3,276 data records can be inserted (3276 × 10 = 32760).

Ensure that you comply with this constraint when calling this API to avoid errors caused by excessive parameters.

Since: 23

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
const char *tableName of the target table for data insertion.
const OH_Data_VBuckets *rowsRow of data to insert.
Rdb_ConflictResolution resolutionRdb_ConflictResolution policy used to resolve file conflicts. RDB_CONFLICT_FAIL is not recommended, as an exception will be thrown upon failure
and the actual change data cannot be obtained properly.
OH_RDB_ReturningContext *contextPointer to the OH_RDB_ReturningContext instance.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_WAL_SIZE_OVER_LIMIT indicates that the size of the WAL log file exceeds the default value.
RDB_E_NOT_SUPPORTED indicates that the operation is not supported.
RDB_E_DATABASE_BUSY indicates that the database is busy.
RDB_E_SQLITE_FULL indicates an SQLite error: the database is full.
RDB_E_SQLITE_CORRUPT indicates that the database is corrupted.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_LOCKED indicates an SQLite error: database table locked.
RDB_E_SQLITE_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite error: disk I/O error occurs.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.
RDB_E_SQLITE_CONSTRAINT indicates an SQLite error: aborted due to constraint violation.
RDB_E_SQLITE_ERROR indicates an SQLite error. Possible causes include syntax errors. For example, the specified table or column does not exist.
For details about the error codes, see OH_Rdb_ErrCode.

OH_Rdb_UpdateWithReturning()

int OH_Rdb_UpdateWithReturning(OH_Rdb_Store *store, OH_VBucket *row, OH_Predicates *predicates, Rdb_ConflictResolution resolution, OH_RDB_ReturningContext *context)

Description

Updates data in the database based on specified conditions and outputs the change information to the context.

Since: 23

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
OH_VBucket *rowRow of data to update.
OH_Predicates *predicatesPointer to the OH_Predicates instance.
Rdb_ConflictResolution resolutionRdb_ConflictResolution policy used to resolve file conflicts. RDB_CONFLICT_FAIL is not recommended, as an exception will be thrown upon failure
and the actual change data cannot be obtained properly.
OH_RDB_ReturningContext *contextPointer to the OH_RDB_ReturningContext instance.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_WAL_SIZE_OVER_LIMIT indicates that the size of the WAL log file exceeds the default value.
RDB_E_NOT_SUPPORTED indicates that the operation is not supported.
RDB_E_EMPTY_VALUES_BUCKET indicates that the value bucket is empty.
RDB_E_DATABASE_BUSY indicates that the database is busy.
RDB_E_SQLITE_FULL indicates an SQLite error: the database is full.
RDB_E_SQLITE_CORRUPT indicates that the database is corrupted.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_LOCKED indicates an SQLite error: database table locked.
RDB_E_SQLITE_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite error: disk I/O error occurs.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.
RDB_E_SQLITE_CONSTRAINT indicates an SQLite error: aborted due to constraint violation.
RDB_E_SQLITE_ERROR indicates an SQLite error. Possible causes include syntax errors. For example, the specified table or column does not exist.
For details about the error codes, see OH_Rdb_ErrCode.

OH_Rdb_DeleteWithReturning()

int OH_Rdb_DeleteWithReturning(OH_Rdb_Store *store, OH_Predicates *predicates, OH_RDB_ReturningContext *context)

Description

Deletes data from the database based on specified conditions and outputs the change information to the context.

Since: 23

Parameters

ParameterDescription
OH_Rdb_Store *storePointer to the OH_Rdb_Store instance.
OH_Predicates *predicatesPointer to the OH_Predicates instance.
OH_RDB_ReturningContext *contextPointer to the OH_RDB_ReturningContext instance.

Returns

TypeDescription
intReturns the operation result.
RDB_OK indicates that the operation is successful.
RDB_E_INVALID_ARGS indicates that invalid parameters are specified.
RDB_E_WAL_SIZE_OVER_LIMIT indicates that the size of the WAL log file exceeds the default value.
RDB_E_NOT_SUPPORTED indicates that the operation is not supported.
RDB_E_DATABASE_BUSY indicates that the database is busy.
RDB_E_SQLITE_FULL indicates an SQLite error: the database is full.
RDB_E_SQLITE_CORRUPT indicates that the database is corrupted.
RDB_E_SQLITE_BUSY indicates an SQLite error: database file locked.
RDB_E_SQLITE_LOCKED indicates an SQLite error: database table locked.
RDB_E_SQLITE_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite error: disk I/O error occurs.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.
RDB_E_SQLITE_ERROR indicates an SQLite error. Possible causes include syntax errors. For example, the specified table or column does not exist.
For details about the error codes, see OH_Rdb_ErrCode.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 js-apis-distributedKVStore-sys

openharmony 鸿蒙 capi-oh-preferences-h

openharmony 鸿蒙 capi-udmf-oh-udshyperlink

openharmony 鸿蒙 js-apis-data-dataSharePredicates

openharmony 鸿蒙 capi-udmf-oh-udsappitem

openharmony 鸿蒙 capi-rdb-oh-data-vbuckets

openharmony 鸿蒙 capi-rdb-oh-predicates

openharmony 鸿蒙 capi-rdb-oh-data-value

openharmony 鸿蒙 capi-preferences-oh-preferencespair

openharmony 鸿蒙 errorcode-datashare

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