QGIS API Documentation
3.6.0-Noosa (5873452)
|
This class allows including 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>
Signals | |
void | afterRollback () |
Emitted after a rollback. More... | |
void | dirtied (const QString &sql, const QString &name) |
Emitted if a sql query is executed and the underlying data is modified. More... | |
Public Member Functions | |
~QgsTransaction () override | |
bool | addLayer (QgsVectorLayer *layer) |
Add the layer to the transaction. More... | |
bool | begin (QString &errorMsg, int statementTimeout=20) |
Begin transaction The statementTimeout (in seconds) specifies how long an sql statement is allowed to block QGIS before it is aborted. More... | |
bool | commit (QString &errorMsg) |
Commit transaction. More... | |
QString | createSavepoint (QString &error) |
creates a save point returns empty string on error returns the last created savepoint if it's not dirty More... | |
QString | createSavepoint (const QString &savePointId, QString &error) |
creates a save point returns empty string on error More... | |
void | dirtyLastSavePoint () |
dirty save point such that next call to createSavepoint will create a new one More... | |
virtual bool | executeSql (const QString &sql, QString &error, bool isDirty=false, const QString &name=QString())=0 |
Execute the sql string. More... | |
bool | lastSavePointIsDirty () const |
returns the last created savepoint More... | |
bool | rollback (QString &errorMsg) |
Roll back transaction. More... | |
bool | rollbackToSavepoint (const QString &name, QString &error) |
rollback to save point, the save point is maintained and is "undertied" More... | |
QList< QString > | savePoints () const |
returns savepoints More... | |
Static Public Member Functions | |
static QgsTransaction * | create (const QString &connString, const QString &providerKey) |
Create a transaction for the specified connection string connString and provider with providerKey. More... | |
static QgsTransaction * | create (const QSet< QgsVectorLayer *> &layers) |
Create a transaction which includes the layers. More... | |
static bool | supportsTransaction (const QgsVectorLayer *layer) |
Checks if the provider of a given layer supports transactions. More... | |
Protected Member Functions | |
QgsTransaction (const QString &connString) | |
Protected Attributes | |
QString | mConnString |
This class allows including 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 can 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 56 of file qgstransaction.h.
|
override |
Definition at line 79 of file qgstransaction.cpp.
|
protected |
Definition at line 72 of file qgstransaction.cpp.
bool QgsTransaction::addLayer | ( | QgsVectorLayer * | layer | ) |
Add the layer to the transaction.
The layer must not be in edit mode and the connection string must match.
Definition at line 124 of file qgstransaction.cpp.
|
signal |
Emitted after a rollback.
bool QgsTransaction::begin | ( | QString & | errorMsg, |
int | statementTimeout = 20 |
||
) |
Begin transaction The statementTimeout (in seconds) specifies how long an sql statement is allowed to block QGIS before it is aborted.
Statements can block, 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 158 of file qgstransaction.cpp.
bool QgsTransaction::commit | ( | QString & | errorMsg | ) |
Commit transaction.
Definition at line 173 of file qgstransaction.cpp.
|
static |
Create a transaction for the specified connection string connString and provider with providerKey.
Definition at line 32 of file qgstransaction.cpp.
|
static |
Create a transaction which includes the layers.
All layers are expected to have the same connection string and data provider.
Definition at line 47 of file qgstransaction.cpp.
QString QgsTransaction::createSavepoint | ( | QString & | error | ) |
creates a save point returns empty string on error returns the last created savepoint if it's not dirty
Definition at line 229 of file qgstransaction.cpp.
QString QgsTransaction::createSavepoint | ( | const QString & | savePointId, |
QString & | error | ||
) |
creates a save point returns empty string on error
Definition at line 250 of file qgstransaction.cpp.
|
signal |
Emitted if a sql query is executed and the underlying data is modified.
void QgsTransaction::dirtyLastSavePoint | ( | ) |
dirty save point such that next call to createSavepoint will create a new one
Definition at line 281 of file qgstransaction.cpp.
|
pure virtual |
Execute the sql string.
sql | The sql query to execute |
error | The error message |
isDirty | Flag to indicate if the underlying data will be modified |
name | Name of the transaction ( only used if isDirty is true) |
|
inline |
bool QgsTransaction::rollback | ( | QString & | errorMsg | ) |
Roll back transaction.
Definition at line 187 of file qgstransaction.cpp.
bool QgsTransaction::rollbackToSavepoint | ( | const QString & | name, |
QString & | error | ||
) |
rollback to save point, the save point is maintained and is "undertied"
Definition at line 266 of file qgstransaction.cpp.
|
inline |
|
static |
Checks if the provider of a given layer supports transactions.
Definition at line 204 of file qgstransaction.cpp.
|
protected |
Definition at line 181 of file qgstransaction.h.