[QGIS Commit] r10578 - trunk/qgis/src/providers/postgres

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Apr 16 15:58:26 EDT 2009


Author: jef
Date: 2009-04-16 15:58:26 -0400 (Thu, 16 Apr 2009)
New Revision: 10578

Modified:
   trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
Log:
handle broken postgis installations more traceful

Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2009-04-16 15:18:15 UTC (rev 10577)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2009-04-16 19:58:26 UTC (rev 10578)
@@ -310,6 +310,17 @@
   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
@@ -1732,6 +1743,12 @@
 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 );
@@ -1740,6 +1757,11 @@
 
   // 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();



More information about the QGIS-commit mailing list