[mapserver-commits] r11922 - branches/branch-5-0/mapserver

svn at osgeo.org svn at osgeo.org
Tue Jul 12 16:51:28 EDT 2011


Author: assefa
Date: 2011-07-12 13:51:28 -0700 (Tue, 12 Jul 2011)
New Revision: 11922

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

Modified: branches/branch-5-0/mapserver/mappostgis.c
===================================================================
--- branches/branch-5-0/mapserver/mappostgis.c	2011-07-12 20:46:16 UTC (rev 11921)
+++ branches/branch-5-0/mapserver/mappostgis.c	2011-07-12 20:51:28 UTC (rev 11922)
@@ -2397,6 +2397,41 @@
 }
 
 
+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->conn, 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)
 {
@@ -2425,6 +2460,7 @@
     /* layer->vtable->LayerCreateItems, use default */
     /* layer->vtable->LayerGetNumFeatures, use default */
 
+    layer->vtable->LayerEscapeSQLParam = msPOSTGISEscapeSQLParam;
 
     return MS_SUCCESS;
 }



More information about the mapserver-commits mailing list