QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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 <QSet>
22#include "qgis_sip.h"
23#include <QString>
24#include <QObject>
25#include <QStack>
26
27#include "qgis_core.h"
28#include "qgis_sip.h"
29
31class QgsVectorLayer;
32
56class CORE_EXPORT QgsTransaction : public QObject SIP_ABSTRACT
57{
58 Q_OBJECT
59
60 public:
61
66 static QgsTransaction *create( const QString &connString, const QString &providerKey ) SIP_FACTORY;
67
73 static QgsTransaction *create( const QSet<QgsVectorLayer *> &layers ) SIP_FACTORY;
74
75 ~QgsTransaction() override;
76
81 QString connectionString() const;
82
90 bool addLayer( QgsVectorLayer *layer, bool addLayersInEditMode = false );
91
102 bool begin( QString &errorMsg SIP_OUT, int statementTimeout = 20 );
103
107 bool commit( QString &errorMsg SIP_OUT );
108
112 bool rollback( QString &errorMsg SIP_OUT );
113
124 virtual bool executeSql( const QString &sql, QString &error SIP_OUT, bool isDirty = false, const QString &name = QString() ) = 0;
125
129 static bool supportsTransaction( const QgsVectorLayer *layer );
130
137 QString createSavepoint( QString &error SIP_OUT );
138
144 virtual QString createSavepoint( const QString &savePointId, QString &error SIP_OUT );
145
150 virtual bool rollbackToSavepoint( const QString &name, QString &error SIP_OUT );
151
156 void dirtyLastSavePoint();
157
162 QList< QString > savePoints() const { return QList< QString >::fromVector( mSavepoints ); }
163
168 bool lastSavePointIsDirty() const { return mLastSavePointIsDirty; }
169
171 // For internal use only, or by QgsTransactionGroup
172 static QString connectionString( const QString &layerUri ) SIP_SKIP;
174
175 signals:
176
181
185 void dirtied( const QString &sql, const QString &name );
186
187 protected:
188 QgsTransaction( const QString &connString ) SIP_SKIP;
189
190 QString mConnString;
192 QStack< QString > mSavepoints;
194
195 private slots:
196 void onLayerDeleted();
197
198 private:
199
200 QSet<QgsVectorLayer *> mLayers;
201
202 void setLayerTransactionIds( QgsTransaction *transaction );
203
204 static QString cleanupConnectionString( const QString &str );
205
206 virtual bool beginTransaction( QString &error, int statementTimeout ) = 0;
207 virtual bool commitTransaction( QString &error ) = 0;
208 virtual bool rollbackTransaction( QString &error ) = 0;
209};
210
211#endif // QGSTRANSACTION_H
This class allows including a set of layers in a database-side transaction, provided the layer data p...
QStack< QString > mSavepoints
bool mLastSavePointIsDirty
void afterRollback()
Emitted after a rollback.
QList< QString > savePoints() const
returns savepoints
virtual bool executeSql(const QString &sql, QString &error, bool isDirty=false, const QString &name=QString())=0
Execute the sql string.
bool lastSavePointIsDirty() const
returns the last created savepoint
void dirtied(const QString &sql, const QString &name)
Emitted if a sql query is executed and the underlying data is modified.
This is the base class for vector data providers.
Represents a vector layer which manages a vector based data sets.
#define str(x)
Definition: qgis.cpp:38
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_ABSTRACT
Definition: qgis_sip.h:208
#define SIP_FACTORY
Definition: qgis_sip.h:76