Skip to main content

VTabTransaction

Trait VTabTransaction 

Source
pub trait VTabTransaction {
    // Required methods
    fn sync(&mut self) -> Result<()>;
    fn commit(self) -> Result<()>;
    fn rollback(self) -> Result<()>;
    fn savepoint(&mut self, n: i32) -> Result<()>;
    fn release(&mut self, n: i32) -> Result<()>;
    fn rollback_to(&mut self, n: i32) -> Result<()>;
}
Expand description

Implementation of the transaction type for a virtual table.

Virtual tables which modify resources outside of the database in which they are defined may require additional work in order to safely implement fallible transactions. If the virtual table only modifies data inside of the database in which it is defined, then SQLite’s built-in transaction support is sufficient and implementing TransactionVTab is not necessary. The most important methods of this trait are rollback and rollback_to. If it is not possible to correctly implement these methods for the virtual table, then there is no need to implement TransactionVTab at all.

Virtual table transactions do not nest, so there will never be more than one instance of this trait per virtual table. Instances are always dropped in a call to either commit or rollback, with one exception: eponymous tables implementing this trait automatically begin a transaction after VTab::connect, but this transaction will be later on dropped without any methods being called on it. This is harmless, because if an UPDATE occurs for such a table, a new transaction will be created, dropping the previous one first.

Note that the savepoint, release, and rollback_to methods require SQLite 3.7.7. On previous versions of SQLite, these methods will not be called, which may result in unsound behavior. In the following example, the virtual table will incorrectly commit changes which should have been rolled back.

BEGIN;
SAVEPOINT a;
UPDATE my_virtual_table SET foo = 'bar';
ROLLBACK TO a;
COMMIT;

Required Methods§

Source

fn sync(&mut self) -> Result<()>

Start a two-phase commit.

This method is only invoked prior to a commit or rollback. In order to implement two-phase commit, the sync method on all virtual tables is invoked prior to invoking the commit method on any virtual table. If any of the sync methods fail, the entire transaction is rolled back.

Source

fn commit(self) -> Result<()>

Finish a commit.

A call to this method always follows a prior call sync.

Source

fn rollback(self) -> Result<()>

Roll back a commit.

Source

fn savepoint(&mut self, n: i32) -> Result<()>

Save current state as a save point.

The current state of the virtual table should be saved as savepoint n. There is no guarantee that n starts at zero or increases by 1 in between calls.

This method will only be called on SQLite 3.7.7 or later.

Source

fn release(&mut self, n: i32) -> Result<()>

Invalidate previous save points.

All save points numbered >= n should be invalidated. This does not mean the changes are ready to be committed, just that there is no need to maintain a record of those saved states any more.

Note that there is no guarantee that n will be a value from a previous call to savepoint.

This method will only be called on SQLite 3.7.7 or later.

Source

fn rollback_to(&mut self, n: i32) -> Result<()>

Restore a save point.

The virtual table should revert to the state it had when savepoint was called the lowest number >= n. There is no guarantee that savepoint was ever called with n exactly.

This method will only be called on SQLite 3.7.7 or later.

Implementors§