Skip to content
Permalink
Browse files

Add a name to transaction command

  • Loading branch information
pblottiere committed Nov 10, 2017
1 parent 066d677 commit 76c0a5ba828cfa8a69e46fd01aae5ca0ec09f89a
@@ -84,13 +84,14 @@ Commit transaction.
Roll back transaction.
%End

virtual bool executeSql( const QString &sql, QString &error /Out/, bool isDirty = false ) = 0;
virtual bool executeSql( const QString &sql, QString &error /Out/, bool isDirty = false, const QString &name = QString() ) = 0;
%Docstring
Execute the ``sql`` string.

:param sql: The sql query to execute
:param error: The error message
:param isDirty: Flag to indicate if the underlying data will be modified
:param name: Name of the transaction ( only used if `isDirty` is true)

:return: true if everything is OK, false otherwise
%End
@@ -152,7 +153,7 @@ returns the last created savepoint
Emitted after a rollback
%End

void dirtied( const QString &sql );
void dirtied( const QString &sql, const QString &name );
%Docstring
Emitted if a sql query is executed and the underlying data is modified
%End
@@ -41,12 +41,13 @@ class QgsVectorLayerEditPassthrough : QgsVectorLayerEditBuffer
virtual void rollBack();


bool update( QgsTransaction *transaction, const QString &sql );
bool update( QgsTransaction *transaction, const QString &sql, const QString &name );
%Docstring
Update underlying data with a SQL query embedded in a transaction.

:param transaction: Transaction in which the sql query has been run
:param sql: The SQL query updating data
:param name: The name of the undo/redo command

:return: true if the undo/redo command is well added to the stack, false otherwise

@@ -303,13 +303,14 @@ class QgsVectorLayerUndoPassthroughCommandUpdate : QgsVectorLayerUndoPassthrough
%End
public:

QgsVectorLayerUndoPassthroughCommandUpdate( QgsVectorLayerEditBuffer *buffer /Transfer/, QgsTransaction *transaction, const QString &sql );
QgsVectorLayerUndoPassthroughCommandUpdate( QgsVectorLayerEditBuffer *buffer /Transfer/, QgsTransaction *transaction, const QString &sql, const QString &name );
%Docstring
Constructor for :py:class:`QgsVectorLayerUndoCommandUpdate`

:param buffer: associated edit buffer
:param transaction: transaction running the sql query
:param sql: the query
:param name: The name of the command
%End

virtual void undo();
@@ -108,10 +108,11 @@ class CORE_EXPORT QgsTransaction : public QObject SIP_ABSTRACT
* \param sql The sql query to execute
* \param error The error message
* \param isDirty Flag to indicate if the underlying data will be modified
* \param name Name of the transaction ( only used if `isDirty` is true)
*
* \returns true if everything is OK, false otherwise
*/
virtual bool executeSql( const QString &sql, QString &error SIP_OUT, bool isDirty = false ) = 0;
virtual bool executeSql( const QString &sql, QString &error SIP_OUT, bool isDirty = false, const QString &name = QString() ) = 0;

/**
* Checks if the provider of a given \a layer supports transactions.
@@ -167,7 +168,7 @@ class CORE_EXPORT QgsTransaction : public QObject SIP_ABSTRACT
/**
* Emitted if a sql query is executed and the underlying data is modified
*/
void dirtied( const QString &sql );
void dirtied( const QString &sql, const QString &name );

protected:
QgsTransaction( const QString &connString ) SIP_SKIP;
@@ -4591,11 +4591,11 @@ bool QgsVectorLayer::readExtentFromXml() const
return mReadExtentFromXml;
}

void QgsVectorLayer::onDirtyTransaction( const QString &sql )
void QgsVectorLayer::onDirtyTransaction( const QString &sql, const QString &name )
{
QgsTransaction *tr = dataProvider()->transaction();
if ( tr && mEditBuffer )
{
qobject_cast<QgsVectorLayerEditPassthrough *>( mEditBuffer )->update( tr, sql );
qobject_cast<QgsVectorLayerEditPassthrough *>( mEditBuffer )->update( tr, sql, name );
}
}
@@ -2236,7 +2236,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
void onFeatureDeleted( QgsFeatureId fid );
void onRelationsLoaded();
void onSymbolsCounted();
void onDirtyTransaction( const QString &sql );
void onDirtyTransaction( const QString &sql, const QString &name );

protected:
//! Set the extent
@@ -112,7 +112,7 @@ void QgsVectorLayerEditPassthrough::rollBack()
mModified = false;
}

bool QgsVectorLayerEditPassthrough::update( QgsTransaction *tr, const QString &sql )
bool QgsVectorLayerEditPassthrough::update( QgsTransaction *tr, const QString &sql, const QString &name )
{
return modify( new QgsVectorLayerUndoPassthroughCommandUpdate( this, tr, sql ) );
return modify( new QgsVectorLayerUndoPassthroughCommandUpdate( this, tr, sql, name ) );
}
@@ -49,12 +49,13 @@ class CORE_EXPORT QgsVectorLayerEditPassthrough : public QgsVectorLayerEditBuffe
*
* \param transaction Transaction in which the sql query has been run
* \param sql The SQL query updating data
* \param name The name of the undo/redo command
*
* \returns true if the undo/redo command is well added to the stack, false otherwise
*
* \since QGIS 3.0
*/
bool update( QgsTransaction *transaction, const QString &sql );
bool update( QgsTransaction *transaction, const QString &sql, const QString &name );

private:
bool mModified;
@@ -352,8 +352,8 @@ void QgsVectorLayerUndoPassthroughCommandRenameAttribute::redo()
}
}

QgsVectorLayerUndoPassthroughCommandUpdate::QgsVectorLayerUndoPassthroughCommandUpdate( QgsVectorLayerEditBuffer *buffer, QgsTransaction *transaction, const QString &sql )
: QgsVectorLayerUndoPassthroughCommand( buffer, QObject::tr( "custom transaction" ), false )
QgsVectorLayerUndoPassthroughCommandUpdate::QgsVectorLayerUndoPassthroughCommandUpdate( QgsVectorLayerEditBuffer *buffer, QgsTransaction *transaction, const QString &sql, const QString &name )
: QgsVectorLayerUndoPassthroughCommand( buffer, name.isEmpty() ? QObject::tr( "custom transaction" ) : name, false )
, mTransaction( transaction )
, mSql( sql )
{
@@ -297,8 +297,9 @@ class CORE_EXPORT QgsVectorLayerUndoPassthroughCommandUpdate : public QgsVectorL
* \param buffer associated edit buffer
* \param transaction transaction running the sql query
* \param sql the query
* \param name The name of the command
*/
QgsVectorLayerUndoPassthroughCommandUpdate( QgsVectorLayerEditBuffer *buffer SIP_TRANSFER, QgsTransaction *transaction, const QString &sql );
QgsVectorLayerUndoPassthroughCommandUpdate( QgsVectorLayerEditBuffer *buffer SIP_TRANSFER, QgsTransaction *transaction, const QString &sql, const QString &name );

void undo() override;
void redo() override;
@@ -57,7 +57,7 @@ bool QgsPostgresTransaction::rollbackTransaction( QString &error )
return false;
}

bool QgsPostgresTransaction::executeSql( const QString &sql, QString &errorMsg, bool isDirty )
bool QgsPostgresTransaction::executeSql( const QString &sql, QString &errorMsg, bool isDirty, const QString &name )
{
if ( !mConn )
{
@@ -91,7 +91,7 @@ bool QgsPostgresTransaction::executeSql( const QString &sql, QString &errorMsg,
if ( isDirty )
{
dirtyLastSavePoint();
emit dirtied( sql );
emit dirtied( sql, name );
}

QgsDebugMsg( QString( "Status %1 (OK)" ).arg( r.PQresultStatus() ) );
@@ -29,7 +29,17 @@ class QgsPostgresTransaction : public QgsTransaction

public:
explicit QgsPostgresTransaction( const QString &connString );
bool executeSql( const QString &sql, QString &error, bool isDirty = false ) override;

/**
* Executes the SQL query in database.
*
* \param sql The SQL query to execute
* \param error The error or an empty string if none
* \param isDirty True to add an undo/redo command in the edition buffer, false otherwise
* \param name Name of the transaction ( only used if `isDirty` is true)
*/
bool executeSql( const QString &sql, QString &error, bool isDirty = false, const QString &name = QString() ) override;

QgsPostgresConn *connection() const { return mConn; }


0 comments on commit 76c0a5b

Please sign in to comment.
You can’t perform that action at this time.