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

svn at osgeo.org svn at osgeo.org
Tue Jul 12 16:05:04 EDT 2011


Author: assefa
Date: 2011-07-12 13:05:04 -0700 (Tue, 12 Jul 2011)
New Revision: 11914

Modified:
   branches/branch-5-6/mapserver/mappostgis.c
Log:
Add missing escape function (#3903)

Modified: branches/branch-5-6/mapserver/mappostgis.c
===================================================================
--- branches/branch-5-6/mapserver/mappostgis.c	2011-07-12 18:20:06 UTC (rev 11913)
+++ branches/branch-5-6/mapserver/mappostgis.c	2011-07-12 20:05:04 UTC (rev 11914)
@@ -2538,6 +2538,42 @@
     return MS_FALSE;
 }
 
+
+char *msPostGISEscapeSQLParam(layerObj *layer, const char *pszString)
+{
+#ifdef USE_POSTGIS
+    msPostGISLayerInfo *layerinfo = NULL;
+    int nError;
+    size_t nSrcLen;
+    char* pszEscapedStr =NULL;
+
+    if (layer && pszString && strlen(pszString) > 0)
+    {
+        if(!msPostGISLayerIsOpen(layer))
+          msPostGISLayerOpen(layer);
+    
+        assert(layer->layerinfo != NULL);
+
+        layerinfo = (msPostGISLayerInfo *) layer->layerinfo;
+        nSrcLen = strlen(pszString);
+        pszEscapedStr = (char*) malloc( 2 * nSrcLen + 1);
+        PQescapeStringConn (layerinfo->pgconn, pszEscapedStr, pszString, nSrcLen, &nError);
+        if (nError != 0)
+        {
+            free(pszEscapedStr);
+            pszEscapedStr = NULL;
+        }
+    }
+    return pszEscapedStr;
+#else
+    msSetError( MS_MISCERR,
+                "PostGIS support is not available.",
+                "msPostGISEscapeSQLParam()");
+    return NULL;
+#endif
+}
+
+
 int msPostGISLayerInitializeVirtualTable(layerObj *layer) {
     assert(layer != NULL);
     assert(layer->vtable != NULL);
@@ -2560,5 +2596,8 @@
     /* layer->vtable->LayerCreateItems, use default */
     /* layer->vtable->LayerGetNumFeatures, use default */
 
+#ifdef USE_POSTGIS
+    layer->vtable->LayerEscapeSQLParam = msPostGISEscapeSQLParam;
+#endif
     return MS_SUCCESS;
 }



More information about the mapserver-commits mailing list