QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsTransaction Class Reference

This class allows to include a set of layers in a database-side transaction, provided the layer data providers support transactions and are compatible with each other. More...

#include <qgstransaction.h>

Public Member Functions

virtual ~QgsTransaction ()
bool addLayer (const QString &layerId)
 Add layer to the transaction.
bool begin (QString &errorMsg, int statementTimeout=20)
 Begin transaction The statement timeout, in seconds, specifies how long an sql statement is allowed to block QGIS before it is aborted.
bool commit (QString &errorMsg)
 Commit transaction.
virtual bool executeSql (const QString &sql, QString &error)=0
 Executes sql.
bool rollback (QString &errorMsg)
 Roll back transaction.

Static Public Member Functions

static QgsTransactioncreate (const QString &connString, const QString &providerKey)
 Creates a transaction for the specified connection string and provider.
static QgsTransactioncreate (const QStringList &layerIds)
 Creates a transaction which includes the specified layers.

Protected Member Functions

 QgsTransaction (const QString &connString)

Protected Attributes

QString mConnString

Detailed Description

This class allows to include a set of layers in a database-side transaction, provided the layer data providers support transactions and are compatible with each other.

Only layers which are not in edit mode can be included in a transaction, and all layers need to be in read-only mode for a transaction to be committed or rolled back.

Layers cannot only be included in one transaction at a time.

When editing layers which are part of a transaction group, all changes are sent directly to the data provider (bypassing the undo/redo stack), and the changes can either be committed or rolled back on the database side via the QgsTransaction::commit and QgsTransaction::rollback methods.

As long as the transaction is active, the state of all layer features reflects the current state in the transaction.

Edits on features can get rejected if another conflicting transaction is active.

Definition at line 47 of file qgstransaction.h.

Constructor & Destructor Documentation

QgsTransaction::~QgsTransaction ( )
virtual

Definition at line 89 of file qgstransaction.cpp.

QgsTransaction::QgsTransaction ( const QString &  connString)
protected

Definition at line 84 of file qgstransaction.cpp.

Member Function Documentation

bool QgsTransaction::addLayer ( const QString &  layerId)

Add layer to the transaction.

The layer must not be in edit mode. The transaction must not be active.

Definition at line 94 of file qgstransaction.cpp.

bool QgsTransaction::begin ( QString &  errorMsg,
int  statementTimeout = 20 
)

Begin transaction The statement timeout, in seconds, specifies how long an sql statement is allowed to block QGIS before it is aborted.

Statements can block, depending on the provider, if multiple transactions are active and a statement would produce a conflicting state. In these cases, the statements block until the conflicting transaction is committed or rolled back. Some providers might not honour the statement timeout.

Definition at line 133 of file qgstransaction.cpp.

bool QgsTransaction::commit ( QString &  errorMsg)

Commit transaction.

All layers need to be in read-only mode.

Definition at line 151 of file qgstransaction.cpp.

QgsTransaction * QgsTransaction::create ( const QString &  connString,
const QString &  providerKey 
)
static

Creates a transaction for the specified connection string and provider.

Definition at line 29 of file qgstransaction.cpp.

QgsTransaction * QgsTransaction::create ( const QStringList &  layerIds)
static

Creates a transaction which includes the specified layers.

Connection string and data provider are taken from the first layer

Definition at line 51 of file qgstransaction.cpp.

virtual bool QgsTransaction::executeSql ( const QString &  sql,
QString &  error 
)
pure virtual

Executes sql.

bool QgsTransaction::rollback ( QString &  errorMsg)

Roll back transaction.

All layers need to be in read-only mode.

Definition at line 177 of file qgstransaction.cpp.

Member Data Documentation

QString QgsTransaction::mConnString
protected

Definition at line 84 of file qgstransaction.h.


The documentation for this class was generated from the following files: