[mapserver-commits] r9785 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Mon Feb 8 22:25:48 EST 2010


Author: pramsey
Date: 2010-02-08 22:25:47 -0500 (Mon, 08 Feb 2010)
New Revision: 9785

Modified:
   trunk/mapserver/configure.in
   trunk/mapserver/mappostgis.c
Log:
Determine PgSQL version in a more backwards compatible way (#3291)



Modified: trunk/mapserver/configure.in
===================================================================
--- trunk/mapserver/configure.in	2010-02-09 03:12:31 UTC (rev 9784)
+++ trunk/mapserver/configure.in	2010-02-09 03:25:47 UTC (rev 9785)
@@ -1574,6 +1574,12 @@
       POSTGIS_LIB="-L`$PG_CONFIG --libdir` -lpq"
   fi
   POSTGIS_INC="-I`$PG_CONFIG --includedir`"
+
+  old_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS -L`$PG_CONFIG --libdir`"
+  AC_CHECK_LIB(pq, PQserverVersion, POSTGIS_ENABLED="$POSTGIS_ENABLED -DPOSTGIS_HAS_SERVER_VERSION")
+  LDFLAGS="$old_LDFLAGS"
+
 fi
 
 AC_SUBST(POSTGIS_ENABLED,$POSTGIS_ENABLED)

Modified: trunk/mapserver/mappostgis.c
===================================================================
--- trunk/mapserver/mappostgis.c	2010-02-09 03:12:31 UTC (rev 9784)
+++ trunk/mapserver/mappostgis.c	2010-02-09 03:25:47 UTC (rev 9785)
@@ -394,6 +394,63 @@
 /* TODO Review and clean above! */
 
 
+static int msPostGISRetrievePgVersion(PGconn *pgconn) { 
+#ifndef POSTGIS_HAS_SERVER_VERSION 
+    int pgVersion = 0; 
+    char *strVersion = NULL; 
+    char *strParts[3] = { NULL, NULL, NULL }; 
+    int i = 0, j = 0, len = 0; 
+    int factor = 10000; 
+ 
+    if (pgconn == NULL) { 
+        msSetError(MS_QUERYERR, "Layer does not have a postgis connection.", "msPostGISRetrievePgVersion()"); 
+        return(MS_FAILURE); 
+    } 
+
+    if (! PQparameterStatus(pgconn, "server_version") )
+        return(MS_FAILURE); 
+ 
+    strVersion = strdup(PQparameterStatus(pgconn, "server_version"));
+    if( ! strVersion ) 
+        return MS_FAILURE; 
+
+    strParts[j] = strVersion; 
+    j++; 
+    len = strlen(strVersion); 
+    for( i = 0; i < len; i++ ) { 
+        if( strVersion[i] == '.' ) { 
+            strVersion[i] = '\0'; 
+ 
+            if( j < 3 ) { 
+                strParts[j] = strVersion + i + 1; 
+                j++; 
+            } 
+            else { 
+                free(strVersion); 
+                msSetError(MS_QUERYERR, "Too many parts in version string.", "msPostGISRetrievePgVersion()"); 
+                return MS_FAILURE; 
+            } 
+        } 
+    } 
+     
+    for( j = 0; j < 3 && strParts[j]; j++ ) { 
+        if( atoi(strParts[j]) ) { 
+            pgVersion += factor * atoi(strParts[j]); 
+        } 
+        else { 
+            free(strVersion); 
+            msSetError(MS_QUERYERR, "Unable to parse version string.", "msPostGISRetrievePgVersion()"); 
+            return MS_FAILURE; 
+        } 
+        factor = factor / 100; 
+    } 
+    free(strVersion); 
+    return pgVersion; 
+#else 
+    return PQserverVersion(pgconn); 
+#endif 
+} 
+
 /*
 ** msPostGISRetrievePK()
 **
@@ -439,7 +496,7 @@
         msSetError(MS_QUERYERR, "Layer does not have a postgis connection.", "msPostGISRetrievePK()");
         return(MS_FAILURE);
     }
-    pgVersion = PQserverVersion(layerinfo->pgconn);
+    pgVersion = msPostGISRetrievePgVersion(layerinfo->pgconn);
 
     if (pgVersion < 70000) {
         if (layer->debug) {



More information about the mapserver-commits mailing list