39 if ( !createTransaction )
49 if ( layers.isEmpty() )
61 if ( !transaction->addLayer( layer ) )
68 return transaction.release();
74 , mTransactionActive( false )
75 , mLastSavePointIsDirty( true )
81 setLayerTransactionIds(
nullptr );
102 QgsDebugMsg( QString(
"Couldn't start transaction because connection string for layer %1 : '%2' does not match '%3'" ).arg(
108 connect( layer, &QgsVectorLayer::destroyed,
this, &QgsTransaction::onLayerDeleted );
109 mLayers.insert( layer );
111 if ( mTransactionActive )
119 if ( mTransactionActive )
123 if ( !beginTransaction( errorMsg, statementTimeout ) )
126 setLayerTransactionIds(
this );
127 mTransactionActive =
true;
134 if ( !mTransactionActive )
137 if ( !commitTransaction( errorMsg ) )
140 setLayerTransactionIds(
nullptr );
141 mTransactionActive =
false;
148 if ( !mTransactionActive )
151 if ( !rollbackTransaction( errorMsg ) )
154 setLayerTransactionIds(
nullptr );
155 mTransactionActive =
false;
169 return lib->resolve(
"createTransaction" );
172 void QgsTransaction::onLayerDeleted()
174 mLayers.remove( static_cast<QgsVectorLayer *>( sender() ) );
177 void QgsTransaction::setLayerTransactionIds(
QgsTransaction *transaction )
190 if ( !mTransactionActive )
193 if ( !mLastSavePointIsDirty && !mSavepoints.isEmpty() )
194 return mSavepoints.top();
196 const QString name( QUuid::createUuid().toString() );
204 mSavepoints.push( name );
205 mLastSavePointIsDirty =
false;
211 if ( !mTransactionActive )
220 mSavepoints.push( savePointId );
221 mLastSavePointIsDirty =
false;
227 if ( !mTransactionActive )
230 const int idx = mSavepoints.indexOf( name );
235 mSavepoints.resize( idx );
236 mLastSavePointIsDirty =
false;
242 mLastSavePointIsDirty =
true;
static QgsTransaction * create(const QString &connString, const QString &providerKey)
Create a transaction for the specified connection string connString and provider with providerKey...
virtual QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
QgsTransaction * createTransaction_t(const QString &connString)
bool rollbackToSavepoint(const QString &name, QString &error)
rollback to save point, the save point is maintained and is "undertied"
bool isEditable() const override
Returns true if the provider is in editing mode.
bool commit(QString &errorMsg)
Commit transaction.
virtual bool executeSql(const QString &sql, QString &error, bool isDirty=false, const QString &name=QString())=0
Execute the sql string.
virtual QString name() const =0
Returns a provider name.
void dataChanged()
This is emitted whenever an asynchronous operation has finished and the data should be redrawn...
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
~QgsTransaction() override
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
static bool supportsTransaction(const QgsVectorLayer *layer)
Checks if the provider of a given layer supports transactions.
void afterRollback()
Emitted after a rollback.
QgsTransaction(const QString &connString)
QString source() const
Returns the source for the layer.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
bool addLayer(QgsVectorLayer *layer)
Add the layer to the transaction.
QgsVectorDataProvider * dataProvider() override
Returns the layer's data provider.
bool rollback(QString &errorMsg)
Roll back transaction.
QString providerType() const
Returns the provider type for this layer.
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
QString createSavepoint(QString &error)
creates a save point returns empty string on error returns the last created savepoint if it's not dir...
Represents a vector layer which manages a vector based data sets.
void dirtyLastSavePoint()
dirty save point such that next call to createSavepoint will create a new one
bool begin(QString &errorMsg, int statementTimeout=20)
Begin transaction The statementTimeout (in seconds) specifies how long an sql statement is allowed to...