Skip to content

Commit

Permalink
[Spatialite] Handle connection invalidation
Browse files Browse the repository at this point in the history
This will be used by the WFS provider, so it can properly invalidates
(=close) all connections to the temporary Spatialite database it uses
for caching. Closing those connections is needed to be able to remove
the file.
  • Loading branch information
rouault committed Apr 5, 2016
1 parent e792576 commit c3760ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/providers/spatialite/qgsspatialiteconnection.h
Expand Up @@ -131,7 +131,7 @@ class QgsSqliteHandle
//
public:
QgsSqliteHandle( sqlite3 * handle, const QString& dbPath, bool shared )
: ref( shared ? 1 : -1 ), sqlite_handle( handle ), mDbPath( dbPath )
: ref( shared ? 1 : -1 ), sqlite_handle( handle ), mDbPath( dbPath ), mIsValid( true )
{
}

Expand All @@ -145,6 +145,16 @@ class QgsSqliteHandle
return mDbPath;
}

bool isValid() const
{
return mIsValid;
}

void invalidate()
{
mIsValid = false;
}

//
// libsqlite3 wrapper
//
Expand All @@ -165,6 +175,7 @@ class QgsSqliteHandle
int ref;
sqlite3 *sqlite_handle;
QString mDbPath;
bool mIsValid;

static QMap < QString, QgsSqliteHandle * > handles;
};
Expand Down
8 changes: 5 additions & 3 deletions src/providers/spatialite/qgsspatialiteconnpool.h
Expand Up @@ -36,13 +36,15 @@ inline void qgsConnectionPool_ConnectionDestroy( QgsSqliteHandle* c )

inline void qgsConnectionPool_InvalidateConnection( QgsSqliteHandle* c )
{
Q_UNUSED( c );
/* Invalidation is used in particular by the WFS provider that uses a */
/* temporary spatialite DB and want to delete it at some point. For that */
/* it must invalidate all handles pointing to it */
c->invalidate();
}

inline bool qgsConnectionPool_ConnectionIsValid( QgsSqliteHandle* c )
{
Q_UNUSED( c );
return true;
return c->isValid();
}


Expand Down

0 comments on commit c3760ec

Please sign in to comment.