Skip to content

Commit dd0f5c9

Browse files
author
jef
committed
handle broken postgis installations more traceful
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10578 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent fdc93dc commit dd0f5c9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/providers/postgres/qgspostgresprovider.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,17 @@ QgsPostgresProvider::Conn *QgsPostgresProvider::Conn::connectDb( const QString &
310310
QgsDebugMsg( "Connection to the database was successful" );
311311

312312
Conn *conn = new Conn( pd );
313+
314+
/* Check to see if we have working PostGIS support */
315+
if ( conn->postgisVersion().isNull() )
316+
{
317+
showMessageBox( tr( "No PostGIS Support!" ),
318+
tr( "Your database has no working PostGIS support.\n") );
319+
conn->PQfinish();
320+
delete conn;
321+
return NULL;
322+
}
323+
313324
connections.insert( conninfo, conn );
314325

315326
/* Check to see if we have GEOS support and if not, warn the user about
@@ -1732,6 +1743,12 @@ bool QgsPostgresProvider::Conn::hasGEOS()
17321743
QString QgsPostgresProvider::Conn::postgisVersion()
17331744
{
17341745
Result result = PQexec( "select postgis_version()" );
1746+
if( PQntuples( result ) != 1 )
1747+
{
1748+
QgsDebugMsg( "Retrieval of postgis version failed" );
1749+
return QString::null;
1750+
}
1751+
17351752
postgisVersionInfo = QString::fromUtf8( PQgetvalue( result, 0, 0 ) );
17361753

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

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

17441766
postgisVersionMajor = postgisVersionParts[0].toInt();
17451767
postgisVersionMinor = postgisVersionParts[1].toInt();

0 commit comments

Comments
 (0)