[mapserver-commits] r9782 - branches/branch-5-6/mapserver

svn at osgeo.org svn at osgeo.org
Mon Feb 8 22:05:11 EST 2010


Author: pramsey
Date: 2010-02-08 22:05:11 -0500 (Mon, 08 Feb 2010)
New Revision: 9782

Modified:
   branches/branch-5-6/mapserver/HISTORY.TXT
   branches/branch-5-6/mapserver/configure.in
   branches/branch-5-6/mapserver/mappostgis.c
Log:
Determine PgSQL version in a more backwards compatible way (#3291)



Modified: branches/branch-5-6/mapserver/HISTORY.TXT
===================================================================
--- branches/branch-5-6/mapserver/HISTORY.TXT	2010-02-09 03:04:26 UTC (rev 9781)
+++ branches/branch-5-6/mapserver/HISTORY.TXT	2010-02-09 03:05:11 UTC (rev 9782)
@@ -15,6 +15,8 @@
 Current Version (SVN branch-5-6):
 --------------------------------
 
+- Determine PgSQL version in a more backwards compatible way (#3291)
+
 - Implemented RFC 52 LayerResultsGetShape support for OGR connection type. (#3069)
 
 - Fixed problem with the oracle driver w/FUNCTION=NONE (#3260)

Modified: branches/branch-5-6/mapserver/configure.in
===================================================================
--- branches/branch-5-6/mapserver/configure.in	2010-02-09 03:04:26 UTC (rev 9781)
+++ branches/branch-5-6/mapserver/configure.in	2010-02-09 03:05:11 UTC (rev 9782)
@@ -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: branches/branch-5-6/mapserver/mappostgis.c
===================================================================
--- branches/branch-5-6/mapserver/mappostgis.c	2010-02-09 03:04:26 UTC (rev 9781)
+++ branches/branch-5-6/mapserver/mappostgis.c	2010-02-09 03:05:11 UTC (rev 9782)
@@ -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); 
+    } 
+
+    strVersion = (char *)PQparameterStatus(pgconn, "server_version");
+    if (strVersion == NULL)
+        return(MS_FAILURE); 
+ 
+    strVersion = strdup(strVersion); 
+    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