[mapserver-commits] r9052 - branches/branch-5-4/mapserver

svn at osgeo.org svn at osgeo.org
Thu May 28 14:56:59 EDT 2009


Author: pramsey
Date: 2009-05-28 14:56:59 -0400 (Thu, 28 May 2009)
New Revision: 9052

Modified:
   branches/branch-5-4/mapserver/HISTORY.TXT
   branches/branch-5-4/mapserver/mappostgis.c
Log:
Test database connections before using them (#2932)



Modified: branches/branch-5-4/mapserver/HISTORY.TXT
===================================================================
--- branches/branch-5-4/mapserver/HISTORY.TXT	2009-05-28 18:56:51 UTC (rev 9051)
+++ branches/branch-5-4/mapserver/HISTORY.TXT	2009-05-28 18:56:59 UTC (rev 9052)
@@ -14,6 +14,8 @@
 Current Version:
 ----------------
 
+- Test database connections before using them (#2932)
+
 - Support non-numeric join criteria (#2006)
 
 - Ensure there's enough room in the SQL to hold a long (#1284)

Modified: branches/branch-5-4/mapserver/mappostgis.c
===================================================================
--- branches/branch-5-4/mapserver/mappostgis.c	2009-05-28 18:56:51 UTC (rev 9051)
+++ branches/branch-5-4/mapserver/mappostgis.c	2009-05-28 18:56:59 UTC (rev 9052)
@@ -1521,7 +1521,21 @@
         /* Save this connection in the pool for later. */
         msConnPoolRegister(layer, layerinfo->pgconn, msPostGISCloseConnection);
     }
+    else {
+        /* Connection in the pool should be tested to see if backend is alive. */
+        if( PQstatus(layerinfo->pgconn) != CONNECTION_OK ) {
+            /* Uh oh, bad connection. Can we reset it? */
+            PQreset(layerinfo->pgconn);
+            if( PQstatus(layerinfo->pgconn) != CONNECTION_OK ) {
+                /* Nope, time to bail out. */
+                msSetError(MS_QUERYERR, "PostgreSQL database connection gone bad (%s)", "msPostGISLayerOpen()", PQerrorMessage(layerinfo->pgconn));
+                return MS_FAILURE;
+            }
+            
+        }
+    }
 
+
     /* Save the layerinfo in the layerObj. */
     layer->layerinfo = (void*)layerinfo;
 



More information about the mapserver-commits mailing list