Database.BeginTransaction

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
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.

Notes

A DatabaseException will be 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
MessageBox("Error: " + error.Message)
DB.RollbackTransaction
End Try

See Also

Database.Close, Database.CommitTransaction, Database.RollbackTransaction