Skip to content
Permalink
Browse files

postgres provider: cancel running geometry type query

  • Loading branch information
jef-n committed Aug 21, 2012
1 parent a205034 commit b6760ce1d4f1227a3a9825102ac0458d95fd6eb2
@@ -34,6 +34,7 @@ void QgsGeomColumnTypeThread::addGeometryColumn( QgsPostgresLayerProperty layerP

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

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

if ( mStopped )
{
layerProperty.type = "";
layerProperty.srid = "";
@@ -361,6 +361,7 @@ QgsPgSourceSelect::~QgsPgSourceSelect()
{
mColumnTypeThread->stop();
mColumnTypeThread->wait();
finishList();
}

QSettings settings;
@@ -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;
}
@@ -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 );

0 comments on commit b6760ce

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