Skip to content

Commit

Permalink
Add QgsDataProvider::invalidateConnections() and implement in Spatial…
Browse files Browse the repository at this point in the history
…ite provider

This invalidates all cached connections to the given database name.
This will be used by the WFS provider to cleanup any cached connections before
removing its temporary Spatialite DB
  • Loading branch information
rouault committed Apr 5, 2016
1 parent c178aef commit 62bd406
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions python/core/qgsdataprovider.sip
Expand Up @@ -218,6 +218,11 @@ class QgsDataProvider : QObject
*/
virtual QgsError error() const;

/** Invalidate connections corresponding to specified name
* @note added in QGIS 2.16
*/
virtual void invalidateConnections( const QString& connection );

signals:

/**
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsdataprovider.h
Expand Up @@ -306,6 +306,11 @@ class CORE_EXPORT QgsDataProvider : public QObject
*/
virtual QgsError error() const { return mError; }

/** Invalidate connections corresponding to specified name
* @note added in QGIS 2.16
*/
virtual void invalidateConnections( const QString& connection ) { Q_UNUSED( connection ); }

signals:

/**
Expand Down
7 changes: 6 additions & 1 deletion src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -461,7 +461,9 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri )
char* errMsg = nullptr;
int ret = sqlite3_exec( sqliteHandle, ( "PRAGMA " + pragma ).toUtf8(), nullptr, nullptr, &errMsg );
if ( ret != SQLITE_OK )
{
QgsDebugMsg( QString( "PRAGMA " ) + pragma + QString( " failed : %1" ).arg( errMsg ? errMsg : "" ) );
}
sqlite3_free( errMsg );
}
}
Expand Down Expand Up @@ -5014,7 +5016,10 @@ const QgsField & QgsSpatiaLiteProvider::field( int index ) const
return attributeFields[index];
}


void QgsSpatiaLiteProvider::invalidateConnections( const QString& connection )
{
QgsSpatiaLiteConnPool::instance()->invalidateConnections( connection );
}

/**
* Class factory to return a pointer to a newly created
Expand Down
2 changes: 2 additions & 0 deletions src/providers/spatialite/qgsspatialiteprovider.h
Expand Up @@ -233,6 +233,8 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider
*/
QgsAttributeList pkAttributeIndexes() override;

void invalidateConnections( const QString& connection ) override;

signals:
/**
* This is emitted whenever the worker thread has fully calculated the
Expand Down

0 comments on commit 62bd406

Please sign in to comment.