openharmony 鸿蒙 capi-oh-rdb-transaction-h

2026-08-25 浏览 (1)

oh_rdb_transaction.h

Overview

Defines APIs and enums related to transactions.

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

Library: libnative_rdb_ndk.z.so

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Since: 18

Related module: RDB

Summary

Structs

Nametypedef KeywordDescription
OH_RDB_TransOptionsOH_RDB_TransOptionsDefines the OH_RDB_TransOptions struct.
OH_Rdb_TransactionOH_Rdb_TransactionDefines the OH_RDB_TransOptions struct.

Enums

Nametypedef KeywordDescription
OH_RDB_TransTypeOH_RDB_TransTypeEnumerates the transaction types of an RDB store.

Functions

NameDescription
OH_RDB_TransOptions *OH_RdbTrans_CreateOptions(void)Creates a TransOptions instance.
int OH_RdbTrans_DestroyOptions(OH_RDB_TransOptions *options)Destroys a TransOptions instance.
int OH_RdbTransOption_SetType(OH_RDB_TransOptions *options, OH_RDB_TransType type)Sets the transaction type of an RDB store.
int OH_RdbTrans_Commit(OH_Rdb_Transaction *trans)Commits a transaction.
int OH_RdbTrans_Rollback(OH_Rdb_Transaction *trans)Rolls back a transaction.
int OH_RdbTrans_Insert(OH_Rdb_Transaction *trans, const char *table, const OH_VBucket *row, int64_t *rowId)Inserts a row of data into a table.
int OH_RdbTrans_InsertWithConflictResolution(OH_Rdb_Transaction *trans, const char *table, const OH_VBucket *row,Rdb_ConflictResolution resolution, int64_t *rowId)Inserts a row of data into a table with conflict resolutions.
int OH_RdbTrans_BatchInsert(OH_Rdb_Transaction *trans, const char *table, const OH_Data_VBuckets *rows,Rdb_ConflictResolution resolution, int64_t *changes)Inserts data into a table in batches.
int OH_RdbTrans_Update(OH_Rdb_Transaction *trans, const OH_VBucket *row, const OH_Predicates *predicates,int64_t *changes)Updates data in an RDB store based on specified conditions.
int OH_RdbTrans_UpdateWithConflictResolution(OH_Rdb_Transaction *trans, const OH_VBucket *row,const OH_Predicates *predicates, Rdb_ConflictResolution resolution, int64_t *changes)Updates data in the database based on specified conditions and supports conflict resolution.
int OH_RdbTrans_Delete(OH_Rdb_Transaction *trans, const OH_Predicates *predicates, int64_t *changes)Deletes data from the database based on specified conditions.
OH_Cursor *OH_RdbTrans_Query(OH_Rdb_Transaction *trans, const OH_Predicates *predicates, const char *columns[],int len)Queries data from the database based on specified conditions.
OH_Cursor *OH_RdbTrans_QuerySql(OH_Rdb_Transaction *trans, const char *sql, const OH_Data_Values *args)Queries data from the database based on the SQL statement.
int OH_RdbTrans_Execute(OH_Rdb_Transaction *trans, const char *sql, const OH_Data_Values *args, OH_Data_Value **result)Executes an SQL statement that contains specified parameters.
int OH_RdbTrans_Destroy(OH_Rdb_Transaction *trans)Destroys a transaction object.
OH_Cursor *OH_RdbTrans_QueryWithoutRowCount(OH_Rdb_Transaction *trans, const OH_Predicates *predicates, const char * const columns[], int len)Queries data from the database based on specified conditions without calculating the row count.
OH_Cursor *OH_RdbTrans_QuerySqlWithoutRowCount(OH_Rdb_Transaction *trans, const char *sql, const OH_Data_Values *args)Queries data from the database based on the SQL statement without calculating the row count.
int OH_RdbTrans_BatchInsertWithReturning(OH_Rdb_Transaction *trans, 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_RdbTrans_UpdateWithReturning(OH_Rdb_Transaction *trans, 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_RdbTrans_DeleteWithReturning(OH_Rdb_Transaction *trans, OH_Predicates *predicates, OH_RDB_ReturningContext *context)Deletes data from the database based on specified conditions and outputs the change information to the context.

Enum Description

OH_RDB_TransType

enum OH_RDB_TransType

Description

Enumerates the transaction types of an RDB store.

Since: 18

Enum ItemDescription
RDB_TRANS_DEFERRED = 0Do not start any transaction before the database is accessed for the first time.
RDB_TRANS_IMMEDIATEStart new writes without waiting for the write statement once the database is connected.
RDB_TRANS_EXCLUSIVEStart the write transaction immediately, similar to RDB_TRANS_IMMEDIATE.
In WAL mode, RDB_TRANS_EXCLUSIVE is the same as RDB_TRANS_IMMEDIATE. In other log modes, RDB_TRANS_EXCLUSIVE prevents other database connections when the transaction is reading the database.
RDB_TRANS_BUTTMaximum value of the RDB transaction type.

Function Description

OH_RdbTrans_CreateOptions()

OH_RDB_TransOptions *OH_RdbTrans_CreateOptions(void)

Description

Creates a transaction configuration object.

Since: 18

Returns

TypeDescription
OH_RDB_TransOptionsReturns a pointer to the OH_RDB_TransOptions instance if the operation is successful; returns nullptr otherwise.
Use OH_RdbTrans_DestroyOptions to release the memory in time.

OH_RdbTrans_DestroyOptions()

int OH_RdbTrans_DestroyOptions(OH_RDB_TransOptions *options)

Description

Destroys a TransOptions instance.

Since: 18

Parameters

NameDescription
OH_RDB_TransOptions *optionsPointer to the OH_RDB_TransOptions instance.

Returns

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

OH_RdbTransOption_SetType()

int OH_RdbTransOption_SetType(OH_RDB_TransOptions *options, OH_RDB_TransType type)

Description

Sets the transaction type of an RDB store.

Since: 18

Parameters

NameDescription
OH_RDB_TransOptions *optionsPointer to the OH_RDB_TransOptions instance.
OH_RDB_TransType typeTransaction type to set.

Returns

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

OH_RdbTrans_Commit()

int OH_RdbTrans_Commit(OH_Rdb_Transaction *trans)

Description

Commits a transaction.

Since: 18

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.

Returns

TypeDescription
intReturns the execution result.
RDB_OK indicates 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_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_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite: disk I/O error.

OH_RdbTrans_Rollback()

int OH_RdbTrans_Rollback(OH_Rdb_Transaction *trans)

Description

Rolls back a transaction.

Since: 18

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.

Returns

TypeDescription
intReturns the execution result.
RDB_OK indicates 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_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_READONLY indicates an SQLite error: attempt to write a read-only database.
RDB_E_SQLITE_IOERR indicates an SQLite: disk I/O error.

OH_RdbTrans_Insert()

int OH_RdbTrans_Insert(OH_Rdb_Transaction *trans, const char *table, const OH_VBucket *row, int64_t *rowId)

Description

Inserts a row of data into a table.

Since: 18

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
const char *tableName of the target table for data insertion.
const OH_VBucket *rowRow of data to insert.
int64_t *rowIdPointer to the row number returned.

Returns

TypeDescription
intReturns the execution result.
RDB_OK indicates 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 limit.
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 size limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.

OH_RdbTrans_InsertWithConflictResolution()

int OH_RdbTrans_InsertWithConflictResolution(OH_Rdb_Transaction *trans, const char *table, const OH_VBucket *row,Rdb_ConflictResolution resolution, int64_t *rowId)

Description

Inserts a row of data into a table with conflict resolutions.

Since: 20

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
const char *tableName of the target table for data insertion.
const OH_VBucket *rowRow of data to insert.
Rdb_ConflictResolution resolutionPolicy used to resolve file conflicts.
int64_t *rowIdPointer to the row number returned.

Returns

TypeDescription
intReturns the execution result.
RDB_OK indicates 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 limit.
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 size limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.
RDB_E_SQLITE_CONSTRAINT indicates an SQLite error code: SQLite constraint.

OH_RdbTrans_BatchInsert()

int OH_RdbTrans_BatchInsert(OH_Rdb_Transaction *trans, 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

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
const char *tableName of the target table for data insertion.
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 execution result.
RDB_OK indicates 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 limit.
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 size limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.
RDB_E_SQLITE_CONSTRAINT indicates an SQLite error code: SQLite constraint.

OH_RdbTrans_Update()

int OH_RdbTrans_Update(OH_Rdb_Transaction *trans, const OH_VBucket *row, const OH_Predicates *predicates, int64_t *changes)

Description

Updates data in an RDB store based on specified conditions.

Since: 18

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
const OH_VBucket *rowRow of data to update.
const OH_Predicates *predicatesPointer to the OH_Predicates instance, specifying the update conditions.
int64_t *changesPointer to the number of successful updates.

Returns

TypeDescription
intReturns the execution result.
RDB_OK indicates 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 limit.
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 size limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.

OH_RdbTrans_UpdateWithConflictResolution()

int OH_RdbTrans_UpdateWithConflictResolution(OH_Rdb_Transaction *trans, const OH_VBucket *row,const 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

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
const OH_VBucket *rowRow of data to update.
const 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 successful updates.

Returns

TypeDescription
intReturns the execution result.
RDB_OK indicates 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 limit.
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 size limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.
RDB_E_SQLITE_CONSTRAINT indicates an SQLite error code: SQLite constraint.

OH_RdbTrans_Delete()

int OH_RdbTrans_Delete(OH_Rdb_Transaction *trans, const OH_Predicates *predicates, int64_t *changes)

Description

Deletes data from the database based on specified conditions.

Since: 18

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
const OH_Predicates *predicatesPointer to the OH_Predicates instance, specifying the deletion conditions.
int64_t *changesPointer to the number of successful deletions.

Returns

TypeDescription
intReturns the execution result.
RDB_OK indicates 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 limit.
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 size limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.

OH_RdbTrans_Query()

OH_Cursor *OH_RdbTrans_Query(OH_Rdb_Transaction *trans, const OH_Predicates *predicates, const char *columns[], int len)

Description

Queries data from the database based on specified conditions.

Since: 18

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
const OH_Predicates *predicatesPointer to the OH_Predicates instance, specifying the query conditions.
const char *columns[]Columns to query. If null is passed in, all columns are queried.
int lenNumber of elements in a column.

Returns

TypeDescription
OH_CursorReturns a pointer to the OH_Cursor instance if the operation is successful; returns null if the database is closed or does not respond.

OH_RdbTrans_QuerySql()

OH_Cursor *OH_RdbTrans_QuerySql(OH_Rdb_Transaction *trans, const char *sql, const OH_Data_Values *args)

Description

Queries data from the database based on the SQL statement.

Since: 18

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
const char *sqlPointer to the SQL statement to execute.
const OH_Data_Values *argsPointer to OH_Data_Values.

Returns

TypeDescription
OH_CursorReturns a pointer to the OH_Cursor instance if the operation is successful; returns null if the database is closed or does not respond.

OH_RdbTrans_Execute()

int OH_RdbTrans_Execute(OH_Rdb_Transaction *trans, const char *sql, const OH_Data_Values *args, OH_Data_Value **result)

Description

Executes an SQL statement that contains specified parameters.

Statements starting with comments are not supported.

Since: 18

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
const char *sqlPointer to the SQL statement to execute.
const OH_Data_Values *argsPointer to the parameters contained in the SQL statement.
OH_Data_Value **resultDouble pointer to the OH_Data_Value instance. After the execution is complete, you must release the memory by calling OH_Value_Destroy.

Returns

TypeDescription
intReturns the execution result.
RDB_OK indicates 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 limit.
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 size limit.
RDB_E_SQLITE_MISMATCH indicates an SQLite error: data types mismatch.

OH_RdbTrans_Destroy()

int OH_RdbTrans_Destroy(OH_Rdb_Transaction *trans)

Description

Destroys a transaction object.

Since: 18

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.

Returns

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

OH_RdbTrans_QueryWithoutRowCount()

OH_Cursor *OH_RdbTrans_QueryWithoutRowCount(OH_Rdb_Transaction *trans, const OH_Predicates *predicates, const char * const columns[], int len)

Description

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

Since: 23

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
const OH_Predicates *predicatesQuery conditions specified by OH_Predicates.
const char * const columns[]Columns to query. If null is passed in, all columns are queried.
int lenLength of the input columns array. If len 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 a null pointer if the database is closed or does not respond.

OH_RdbTrans_QuerySqlWithoutRowCount()

OH_Cursor *OH_RdbTrans_QuerySqlWithoutRowCount(OH_Rdb_Transaction *trans, const char *sql, const OH_Data_Values *args)

Description

Queries data from the database based on the SQL statement without calculating the row count.

Since: 23

Parameters

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
const char *sqlSQL statement to execute.
const OH_Data_Values *argsPointer to OH_Data_Values.

Returns

TypeDescription
OH_Cursor *Returns a pointer to the OH_Cursor instance if the operation is successful; returns a null pointer if the database is closed or does not respond.

OH_RdbTrans_BatchInsertWithReturning()

int OH_RdbTrans_BatchInsertWithReturning(OH_Rdb_Transaction *trans, 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

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction 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 execution result.
RDB_OK indicates 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 limit.
RDB_E_NOT_SUPPORTED indicates that the operation is not supported.
RDB_E_DATABASE_BUSY indicates that the database is busy.
RDB_E_ALREADY_CLOSED indicates that the database is already closed.
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_IOERR indicates an SQLite error: disk I/O error occurs.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the size 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_RdbTrans_UpdateWithReturning()

int OH_RdbTrans_UpdateWithReturning(OH_Rdb_Transaction *trans, 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

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction 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 execution result.
RDB_OK indicates 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 limit.
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_ALREADY_CLOSED indicates that the database is already closed.
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_IOERR indicates an SQLite error: disk I/O error occurs.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the size 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_RdbTrans_DeleteWithReturning()

int OH_RdbTrans_DeleteWithReturning(OH_Rdb_Transaction *trans, 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

NameDescription
OH_Rdb_Transaction *transPointer to the OH_Rdb_Transaction instance.
OH_Predicates *predicatesPointer to the OH_Predicates instance.
OH_RDB_ReturningContext *contextPointer to the OH_RDB_ReturningContext instance.

Returns

TypeDescription
intReturns the execution result.
RDB_OK indicates 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 limit.
RDB_E_NOT_SUPPORTED indicates that the operation is not supported.
RDB_E_DATABASE_BUSY indicates that the database is busy.
RDB_E_ALREADY_CLOSED indicates that the database is already closed.
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_IOERR indicates an SQLite error: disk I/O error occurs.
RDB_E_SQLITE_TOO_BIG indicates an SQLite error: TEXT or BLOB exceeds the size 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/Lpke5ITL