[mapserver-users] Filter query

Steven Bowden steveb@bundaberg.qld.gov.au
23 Jul 2002 16:47:27 +1000


--=-ubl+LBDyeWSaovgOU+eD
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hello all,
I am having trouble figuring out how to use filters in php/mapscript
3.6.1.
I have a layer where I want to dynamically change the filter string.
Here is the layer out of the map file
LAYER
  NAME selected_parcel
  GROUP cadaster
  CONNECTIONTYPE postgis
  CONNECTION "user=steveb dbname=blis host=blis"
  TYPE polygon
  STATUS off
  TEMPLATE ""
  #FILTER "tag = 'RP83015/1'"  # Option 1
  FILTER "tag = 'test_string'"      # Option 2
  TRANSPARENCY 50
  DATA "the_geom from bucc"
  CLASS
     Name "Selected Parcel"
     COLOR 255 220 220
  END
END

Here is the relevant mapscript stuff
$rp=RP83015/1;
$selected_layer = $map->getlayerbyname(selected_parcel);
$selected_layer->setfilter("tag = $rp");
$selected_layer->set(status,MS_ON);
$image=$map->draw();
$image_url=$image->saveWebImage(MS_PNG,1,1,0);

I keep getting the following error and no image when I try and run the
script:
Warning: MapServer Error in msPOSTGISLayerWhichShapes(): prep_DB:Error
executing POSTGIS DECLARE statement (0.6 failed - retried 0.5 and it
failed too). DECLARE mycursor BINARY CURSOR FOR SELECT
tag::text,asbinary(force_collection(force_2d(the_geom)),'NDR'),OID::text
from bucc WHERE (tag = RP83015/1) and (the_geom && setSRID(
'BOX3D(432838.932823529 7247483.128,432988.617176471
7247568.006)'::BOX3D,find_srid('','bucc','the_geom') )) in
/var/www/html/blis_dev/lis.phpm on line 86

I suspect it is due to the where clause in the sql, ie WHERE (tag =
RP83015/1).  I have tried placing the single quotes (') around $rp in
the setfilter line and it still fails.  The where clause in the error
message looks like this, WHERE (tag = ).  I have tried escaping the
single quotes with backslashes but still no go.
Is there another way to escape the single quotes so that they appear in
the where clause as 
WHERE (tag = 'RP83015/1')  ?
If not, am I going about this process in the correct way?
When I comment out the setfilter line in php and change the comment
around on Option 1 & 2 in the map file everything works how I want it
to.

Any advice would be greatly appreciated.
Thanks
Steve

--=-ubl+LBDyeWSaovgOU+eD
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/1.0.2">
</HEAD>
<BODY>
Hello all,
<BR>
I am having trouble figuring out how to use filters in php/mapscript 3.6.1.
<BR>
I have a layer where I want to dynamically change the filter string.
<BR>
Here is the layer out of the map file
<BR>
LAYER
<BR>
&nbsp; NAME selected_parcel
<BR>
&nbsp; GROUP cadaster
<BR>
&nbsp; CONNECTIONTYPE postgis
<BR>
&nbsp; CONNECTION &quot;user=steveb dbname=blis host=blis&quot;
<BR>
&nbsp; TYPE polygon
<BR>
&nbsp; STATUS off
<BR>
&nbsp; TEMPLATE &quot;&quot;
<BR>
&nbsp; #FILTER &quot;tag = 'RP83015/1'&quot;&nbsp; # Option 1
<BR>
&nbsp; FILTER &quot;tag = 'test_string'&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Option 2
<BR>
&nbsp; TRANSPARENCY 50
<BR>
&nbsp; DATA &quot;the_geom from bucc&quot;
<BR>
&nbsp; CLASS
<BR>
&nbsp;&nbsp;&nbsp;&nbsp; Name &quot;Selected Parcel&quot;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp; COLOR 255 220 220
<BR>
&nbsp; END
<BR>
END
<BR>

<BR>
Here is the relevant mapscript stuff
<BR>
$rp=RP83015/1;
<BR>
$selected_layer = $map-&gt;getlayerbyname(selected_parcel);
<BR>
$selected_layer-&gt;setfilter(&quot;tag = $rp&quot;);
<BR>
$selected_layer-&gt;set(status,MS_ON);
<BR>
$image=$map-&gt;draw();
<BR>
$image_url=$image-&gt;saveWebImage(MS_PNG,1,1,0);
<BR>

<BR>
I keep getting the following error and no image when I try and run the script:
<BR>
Warning: MapServer Error in msPOSTGISLayerWhichShapes(): prep_DB:Error executing POSTGIS DECLARE statement (0.6 failed - retried 0.5 and it failed too). DECLARE mycursor BINARY CURSOR FOR SELECT tag::text,asbinary(force_collection(force_2d(the_geom)),'NDR'),OID::text from bucc WHERE (tag = RP83015/1) and (the_geom &amp;&amp; setSRID( 'BOX3D(432838.932823529 7247483.128,432988.617176471 7247568.006)'::BOX3D,find_srid('','bucc','the_geom') )) in /var/www/html/blis_dev/lis.phpm on line 86
<BR>

<BR>
I suspect it is due to the where clause in the sql, ie WHERE (tag = RP83015/1).&nbsp; I have tried placing the single quotes (') around $rp in the setfilter line and it still fails.&nbsp; The where clause in the error message looks like this, WHERE (tag = ).&nbsp; I have tried escaping the single quotes with backslashes but still no go.
<BR>
Is there another way to escape the single quotes so that they appear in the where clause as 
<BR>
WHERE (tag = 'RP83015/1')&nbsp; ?
<BR>
If not, am I going about this process in the correct way?
<BR>
When I comment out the setfilter line in php and change the comment around on Option 1 &amp; 2 in the map file everything works how I want it to.
<BR>

<BR>
Any advice would be greatly appreciated.
<BR>
Thanks
<BR>
Steve
</BODY>
</HTML>

--=-ubl+LBDyeWSaovgOU+eD--