@@ -310,6 +310,17 @@ QgsPostgresProvider::Conn *QgsPostgresProvider::Conn::connectDb( const QString &
310
310
QgsDebugMsg ( " Connection to the database was successful" );
311
311
312
312
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
+
313
324
connections.insert ( conninfo, conn );
314
325
315
326
/* Check to see if we have GEOS support and if not, warn the user about
@@ -1732,6 +1743,12 @@ bool QgsPostgresProvider::Conn::hasGEOS()
1732
1743
QString QgsPostgresProvider::Conn::postgisVersion ()
1733
1744
{
1734
1745
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
+
1735
1752
postgisVersionInfo = QString::fromUtf8 ( PQgetvalue ( result, 0 , 0 ) );
1736
1753
1737
1754
QgsDebugMsg ( " PostGIS version info: " + postgisVersionInfo );
@@ -1740,6 +1757,11 @@ QString QgsPostgresProvider::Conn::postgisVersion()
1740
1757
1741
1758
// Get major and minor version
1742
1759
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
+ }
1743
1765
1744
1766
postgisVersionMajor = postgisVersionParts[0 ].toInt ();
1745
1767
postgisVersionMinor = postgisVersionParts[1 ].toInt ();
0 commit comments