Database.BeginTransaction

From Xojo Documentation

Revision as of 12:40, 29 March 2021 by PLefebvre (talk | contribs) (Sample Code: Removed incorrect quotes in SQL statement, capitalized data types per SQL standards)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Method

Database.BeginTransaction()

New in 2019r2

Supported for all project types and targets.

Creates a new transaction. Changes to the database made after this call can be saved with CommitTransaction or undone with RollbackTransaction.

Exceptions

Exception Reason
DatabaseException Raised if the transaction could not begin or another transaction is already in progress.

Sample Code

You typically want to Commit changes after ensuring there were no database errors:

// Prior DB code has run

Try
DB.BeginTransaction
DB.ExecuteSQL("CREATE TABLE AddressBook name VARCHAR, email VARCHAR")
DB.CommitTransaction
Catch error As DatabaseException
MsgBox("Error: " + error.Message)
DB.RollbackTransaction
End Try

See Also

Database.Close, Database.CommitTransaction, Database.RollbackTransaction