cutelyst  4.5.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Cutelyst::Sql::Transaction Class Reference

This is a helper class to create scoped transactions. More...

#include <Cutelyst/Plugins/Utils/Sql>

Public Member Functions

 Transaction (const QSqlDatabase &database)
 
 Transaction (const QString &databaseName=QString())
 
 ~Transaction ()
 
bool commit ()
 
bool rollback ()
 
bool transaction () const
 

Detailed Description

This is a helper class to create scoped transactions, when you create a local Transaction object it will automatically open a transaction, you can check if the transaction was created successfully by calling transaction(),

Once this object goes out of scope it will automatically rollback the transaction if the transaction was open and commit() was not called. It helps you forgetting to rollback a transaction in case of an error.

Definition at line 31 of file sql.h.

Constructor & Destructor Documentation

◆ Transaction() [1/2]

Sql::Transaction::Transaction ( const QString databaseName = QString())
explicit

Creates a Transaction using the databaseName that you would pass to Sql::databaseNameThread().

Definition at line 273 of file sql.cpp.

References QSqlDatabase::transaction().

◆ Transaction() [2/2]

Sql::Transaction::Transaction ( const QSqlDatabase database)

Creates a Transaction using the database that you would get for example from Sql::databaseThread().

Definition at line 279 of file sql.cpp.

References QSqlDatabase::transaction().

◆ ~Transaction()

Sql::Transaction::~Transaction ( )

Destroys the Transaction object and rolls back the transaction is still open and commit() was not called.

Definition at line 285 of file sql.cpp.

Member Function Documentation

◆ commit()

bool Sql::Transaction::commit ( )

Tries to commit the database transaction and returns true on success.

Definition at line 297 of file sql.cpp.

◆ rollback()

bool Sql::Transaction::rollback ( )

Manually rolls back the database transaction and returns true on success.

Definition at line 304 of file sql.cpp.

◆ transaction()

bool Sql::Transaction::transaction ( ) const

Returns true if the database transaction is still running.

Definition at line 292 of file sql.cpp.