Begins, commits or rolls back a transaction:
- on the files of a database opened by SQLConnect,
- on the files of a database opened by a connection (OLE DB or Native Access/Native Connector) described in the data model editor or by HOpenConnection.
Remark: This function is the only SQL function that can be used with the HFSQL functions (to perform transactions on an external database handled by the HFSQL functions for example).
Syntax
Transaction on the files of a database opened by SQLConnect Hide the details
<Result> = SQLTransaction(<Indicator>)
<Result>: Boolean
- True if the operation was performed,
- False otherwise.
<Indicator>: Integer constant
Type of transaction operation to perform: | |
sqlCommit | End the transaction. |
sqlRollBack | Cancels the transaction. |
sqlStart | Starts the transaction. |
Remark: This syntax is not available in Android.
Remarks
Syntax 2: Performing a transaction on a connection
To perform a transaction on a connection, you must:
- Start the connection (SQLTransaction(sqlStart)).
- Perform the operations on the data files with the relevant HFSQL functions.
- End the transaction:
- by validating the operations performed (SQLTransaction(sqlCommit)).
- by canceling the operations performed (SQLTransaction(sqlRollBack)).
Nesting transactions
Transactions can be nested.
Locks and transactions
SQLTransaction does not lock data files or records. SQLTransaction begins, commits or rolls back a transaction.
If a transaction is started:
- write operations in tables can cause deadlocks (e.g. in an HFSQL database, write operations lock records).
- read operations can cause deadlocks on some databases if the isolation level is "repeatable-read" or "serializable" (note that this is not the case in HFSQL databases).