[GRASS-SVN] r58237 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 16 09:19:04 PST 2013


Author: martinl
Date: 2013-11-16 09:19:04 -0800 (Sat, 16 Nov 2013)
New Revision: 58237

Modified:
   grass/trunk/lib/vector/Vlib/open_pg.c
Log:
vlib/pg: check if DB is spatial


Modified: grass/trunk/lib/vector/Vlib/open_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open_pg.c	2013-11-16 17:04:46 UTC (rev 58236)
+++ grass/trunk/lib/vector/Vlib/open_pg.c	2013-11-16 17:19:04 UTC (rev 58237)
@@ -491,16 +491,26 @@
 /*!
   \brief Establish PG connection (pg_info->conninfo)
 
+  Check if DB is spatial as defined by PostGIS.
+
   \param pg_info pointer to Format_info_pg
 */
 void connect_db(struct Format_info_pg *pg_info)
 {
+    char stmt[DB_SQL_MAX];
+
     pg_info->conn = PQconnectdb(pg_info->conninfo);
     G_debug(2, "   PQconnectdb(): %s", pg_info->conninfo);
     if (PQstatus(pg_info->conn) == CONNECTION_BAD)
         G_fatal_error("%s\n%s",
                       _("Connection to PostgreSQL database failed."),
                       PQerrorMessage(pg_info->conn));
+
+    sprintf(stmt, "SELECT COUNT(*) FROM pg_tables WHERE tablename = 'spatial_ref_sys'");
+    if (Vect__execute_get_value_pg(pg_info->conn, stmt) != 1) {
+        PQfinish(pg_info->conn);
+        G_fatal_error(_("Spatial-enabled PostGIS database is required"));
+    }
     
     /* print notice messages only on verbose level */
     PQsetNoticeProcessor(pg_info->conn, notice_processor, NULL);



More information about the grass-commit mailing list