Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
handle broken postgis installations more traceful
git-svn-id: http://svn.osgeo.org/qgis/trunk@10578 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 16, 2009
1 parent bd3ced7 commit 4bd78a3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -310,6 +310,17 @@ QgsPostgresProvider::Conn *QgsPostgresProvider::Conn::connectDb( const QString &
QgsDebugMsg( "Connection to the database was successful" );

Conn *conn = new Conn( pd );

/* Check to see if we have working PostGIS support */
if ( conn->postgisVersion().isNull() )
{
showMessageBox( tr( "No PostGIS Support!" ),
tr( "Your database has no working PostGIS support.\n") );
conn->PQfinish();
delete conn;
return NULL;
}

connections.insert( conninfo, conn );

/* Check to see if we have GEOS support and if not, warn the user about
Expand Down Expand Up @@ -1732,6 +1743,12 @@ bool QgsPostgresProvider::Conn::hasGEOS()
QString QgsPostgresProvider::Conn::postgisVersion()
{
Result result = PQexec( "select postgis_version()" );
if( PQntuples( result ) != 1 )
{
QgsDebugMsg( "Retrieval of postgis version failed" );
return QString::null;
}

postgisVersionInfo = QString::fromUtf8( PQgetvalue( result, 0, 0 ) );

QgsDebugMsg( "PostGIS version info: " + postgisVersionInfo );
Expand All @@ -1740,6 +1757,11 @@ QString QgsPostgresProvider::Conn::postgisVersion()

// Get major and minor version
QStringList postgisVersionParts = postgisParts[0].split( ".", QString::SkipEmptyParts );
if( postgisVersionParts.size() < 2 )
{
QgsDebugMsg( "Could not parse postgis version" );
return QString::null;
}

postgisVersionMajor = postgisVersionParts[0].toInt();
postgisVersionMinor = postgisVersionParts[1].toInt();
Expand Down

0 comments on commit 4bd78a3

Please sign in to comment.