QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
34 if ( layers.isEmpty() )
46 if ( !transaction->addLayer( layer,
false ) )
53 return transaction.release();
58 : mConnString( connString )
59 , mTransactionActive( false )
60 , mLastSavePointIsDirty( true )
66 setLayerTransactionIds(
nullptr );
76 QString QgsTransaction::removeLayerIdOrName(
const QString &
str )
80 for (
int i = 0; i < 2; i++ )
82 const int pos = res.indexOf( i == 0 ? QLatin1String(
"|layername=" ) : QLatin1String(
"|layerid=" ) );
85 const int end = res.indexOf(
'|', pos + 1 );
88 res = res.mid( 0, pos ) + res.mid( end );
92 res = res.mid( 0, pos );
106 if ( connString.isEmpty() )
108 connString = removeLayerIdOrName( layerUri );
119 if ( ! addLayersInEditMode
134 QgsDebugMsg( QStringLiteral(
"Couldn't start transaction because connection string for layer %1 : '%2' does not match '%3'" ).arg(
140 connect( layer, &QgsVectorLayer::destroyed,
this, &QgsTransaction::onLayerDeleted );
141 mLayers.insert( layer );
155 if ( !beginTransaction( errorMsg, statementTimeout ) )
158 setLayerTransactionIds(
this );
169 if ( !commitTransaction( errorMsg ) )
172 setLayerTransactionIds(
nullptr );
183 if ( !rollbackTransaction( errorMsg ) )
186 setLayerTransactionIds(
nullptr );
204 void QgsTransaction::onLayerDeleted()
209 void QgsTransaction::setLayerTransactionIds(
QgsTransaction *transaction )
211 const auto constMLayers = mLayers;
214 if ( vl->dataProvider() )
216 vl->dataProvider()->setTransaction( transaction );
231 const QString name( QStringLiteral(
"qgis" ) + ( QUuid::createUuid().toString().mid( 1, 24 ).replace(
'-', QString() ) ) );
bool mLastSavePointIsDirty
Class for storing the component parts of a RDBMS data source URI (e.g. a Postgres data source).
bool rollback(QString &errorMsg)
Roll back transaction.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
@ TransactionSupport
Supports transactions.
QStack< QString > mSavepoints
QgsTransaction * createTransaction(const QString &providerKey, const QString &connString)
Returns new instance of transaction.
virtual bool executeSql(const QString &sql, QString &error, bool isDirty=false, const QString &name=QString())=0
Execute the sql string.
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
bool begin(QString &errorMsg, int statementTimeout=20)
Begin transaction The statementTimeout (in seconds) specifies how long an sql statement is allowed to...
This class allows including a set of layers in a database-side transaction, provided the layer data p...
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
bool isEditable() const FINAL
Returns true if the provider is in editing mode.
QString providerType() const
Returns the provider type (provider key) for this layer.
virtual Q_INVOKABLE QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
virtual bool rollbackToSavepoint(const QString &name, QString &error)
rollback to save point, the save point is maintained and is "undertied"
static bool supportsTransaction(const QgsVectorLayer *layer)
Checks if the provider of a given layer supports transactions.
~QgsTransaction() override
bool commit(QString &errorMsg)
Commit transaction.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
bool addLayer(QgsVectorLayer *layer, bool addLayersInEditMode=false)
Add the layer to the transaction.
QString source() const
Returns the source for the layer.
QString connectionString() const
Returns the connection string of the transaction.
Represents a vector layer which manages a vector based data sets.
static QgsTransaction * create(const QString &connString, const QString &providerKey)
Create a transaction for the specified connection string connString and provider with providerKey.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
QString createSavepoint(QString &error)
creates a save point returns empty string on error returns the last created savepoint if it's not dir...
QgsTransaction(const QString &connString)
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
void dirtyLastSavePoint()
dirty save point such that next call to createSavepoint will create a new one
QString connectionInfo(bool expandAuthConfig=true) const
Returns the connection part of the URI.
void afterRollback()
Emitted after a rollback.