Skip to content

Commit

Permalink
postgres provider: cancel running geometry type query
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Aug 21, 2012
1 parent a205034 commit b6760ce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/providers/postgres/qgscolumntypethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void QgsGeomColumnTypeThread::addGeometryColumn( QgsPostgresLayerProperty layerP

void QgsGeomColumnTypeThread::stop()
{
mConn->cancel();
mStopped = true;
}

Expand All @@ -50,7 +51,8 @@ void QgsGeomColumnTypeThread::run()
{
mConn->retrieveLayerTypes( layerProperty, mUseEstimatedMetadata );
}
else

if ( mStopped )
{
layerProperty.type = "";
layerProperty.srid = "";
Expand Down
1 change: 1 addition & 0 deletions src/providers/postgres/qgspgsourceselect.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ QgsPgSourceSelect::~QgsPgSourceSelect()
{
mColumnTypeThread->stop();
mColumnTypeThread->wait();
finishList();
}

QSettings settings;
Expand Down
20 changes: 20 additions & 0 deletions src/providers/postgres/qgspostgresconn.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1425,3 +1425,23 @@ void QgsPostgresConn::deleteConnection( QString theConnName )
settings.remove( key + "/save" );
settings.remove( key );
}

bool QgsPostgresConn::cancel()
{
PGcancel *c = ::PQgetCancel( mConn );
if ( !c )
{
QgsMessageLog::logMessage( tr( "Query could not be canceled [%1]" ).arg( tr( "PQgetCancel failed" ) ),
tr( "PostGIS" ) );
return false;
}

char errbuf[256];
int res = ::PQcancel( c, errbuf, sizeof errbuf );
::PQfreeCancel( c );

if ( !res )
QgsMessageLog::logMessage( tr( "Query could not be canceled [%1]" ).arg( errbuf ), tr( "PostGIS" ) );

return res == 0;
}
3 changes: 3 additions & 0 deletions src/providers/postgres/qgspostgresconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class QgsPostgresConn : public QObject
PGresult *PQprepare( QString stmtName, QString query, int nParams, const Oid *paramTypes );
PGresult *PQexecPrepared( QString stmtName, const QStringList &params );

// cancel running query
bool cancel();

/** Double quote a PostgreSQL identifier for placement in a SQL string.
*/
static QString quotedIdentifier( QString ident, bool isGeography = false );
Expand Down

0 comments on commit b6760ce

Please sign in to comment.