QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgstransaction.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstransaction.h
3 ----------------
4 begin : May 5, 2014
5 copyright : (C) 2014 by Marco Hugentobler
6 email : marco dot hugentobler at sourcepole dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSTRANSACTION_H
19#define QGSTRANSACTION_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23
24#include <QObject>
25#include <QSet>
26#include <QStack>
27#include <QString>
28
30class QgsVectorLayer;
31
56
57class CORE_EXPORT QgsTransaction : public QObject SIP_ABSTRACT
58{
59 Q_OBJECT
60
61 public:
62
67 static QgsTransaction *create( const QString &connString, const QString &providerKey ) SIP_FACTORY;
68
74 static QgsTransaction *create( const QSet<QgsVectorLayer *> &layers ) SIP_FACTORY;
75
76 ~QgsTransaction() override;
77
82 QString connectionString() const;
83
91 bool addLayer( QgsVectorLayer *layer, bool addLayersInEditMode = false );
92
103 bool begin( QString &errorMsg SIP_OUT, int statementTimeout = 20 );
104
108 bool commit( QString &errorMsg SIP_OUT );
109
113 bool rollback( QString &errorMsg SIP_OUT );
114
125 virtual bool executeSql( const QString &sql, QString &error SIP_OUT, bool isDirty = false, const QString &name = QString() ) = 0;
126
130 static bool supportsTransaction( const QgsVectorLayer *layer );
131
137 QString createSavepoint( QString &error SIP_OUT );
138
143 virtual QString createSavepoint( const QString &savePointId, QString &error SIP_OUT );
144
148 virtual bool rollbackToSavepoint( const QString &name, QString &error SIP_OUT );
149
153 void dirtyLastSavePoint();
154
158 QList< QString > savePoints() const { return QList< QString >::fromVector( mSavepoints ); }
159
164
166 // For internal use only, or by QgsTransactionGroup
167 static QString connectionString( const QString &layerUri ) SIP_SKIP;
169
170 signals:
171
176
181 void afterRollbackToSavepoint( const QString &savepointName );
182
186 void dirtied( const QString &sql, const QString &name );
187
188 protected:
189 QgsTransaction( const QString &connString ) SIP_SKIP;
190
191 QString mConnString;
192 bool mTransactionActive = false;
193 QStack< QString > mSavepoints;
195
196 private slots:
197 void onLayerDeleted();
198
199 private:
200
201 QSet<QgsVectorLayer *> mLayers;
202
203 void setLayerTransactionIds( QgsTransaction *transaction );
204
205 static QString cleanupConnectionString( const QString &str );
206
207 virtual bool beginTransaction( QString &error, int statementTimeout ) = 0;
208 virtual bool commitTransaction( QString &error ) = 0;
209 virtual bool rollbackTransaction( QString &error ) = 0;
210};
211
212#endif // QGSTRANSACTION_H
QStack< QString > mSavepoints
void afterRollbackToSavepoint(const QString &savepointName)
Emitted after a rollback to savepoint.
void afterRollback()
Emitted after a rollback.
bool rollback(QString &errorMsg)
Roll back transaction.
bool addLayer(QgsVectorLayer *layer, bool addLayersInEditMode=false)
Add the layer to the transaction.
QList< QString > savePoints() const
returns savepoints
bool begin(QString &errorMsg, int statementTimeout=20)
Begin transaction The statementTimeout (in seconds) specifies how long an sql statement is allowed to...
static bool supportsTransaction(const QgsVectorLayer *layer)
Checks if the provider of a given layer supports transactions.
virtual bool rollbackToSavepoint(const QString &name, QString &error)
rollback to save point, the save point is maintained and is "undertied"
virtual bool executeSql(const QString &sql, QString &error, bool isDirty=false, const QString &name=QString())=0
Execute the sql string.
QgsTransaction(const QString &connString)
QString connectionString() const
Returns the connection string of the transaction.
bool commit(QString &errorMsg)
Commit transaction.
static QgsTransaction * create(const QString &connString, const QString &providerKey)
Create a transaction for the specified connection string connString and provider with providerKey.
bool lastSavePointIsDirty() const
returns the last created savepoint
QString createSavepoint(QString &error)
creates a save point returns empty string on error returns the last created savepoint if it's not dir...
void dirtyLastSavePoint()
dirty save point such that next call to createSavepoint will create a new one
void dirtied(const QString &sql, const QString &name)
Emitted if a sql query is executed and the underlying data is modified.
Base class for vector data providers.
Represents a vector layer which manages a vector based dataset.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_ABSTRACT
Definition qgis_sip.h:221
#define SIP_FACTORY
Definition qgis_sip.h:84