[mapserver-dev] help! strange preserving invalid query in mapobject

BrainDrain paulborodaev at gmail.com
Sat Jun 7 09:24:11 EDT 2008


I have already found almost similar solution
            oldFilter = layer.getFilterString();
            try
            {
                queryResult = layer.queryByAttributes(map, "", filter,
mapscript.MS_MULTIPLE);
            }
            catch
            {                
                layer.setFilter("");//or need to recreate map from file
                queryResult = (int)MS_RETURN_VALUE.MS_FAILURE;
            }
            finally
            {
                if (oldFilter != "\"\"" && oldFilter != null)
                    layer.setFilter(oldFilter);
            }
but I was not sure that it is a correct way.
is there any difference between setFilter("") & setFilter(null)?
and is it really necesary to reset  filteritem to null?
>>you should raise an error
to do so I should parse sql expression!? (it could be complex)...
>>you should call mapObj.clone()
or save and read map file once again? (if I have separate mapping web
services outside main application, which could not use context - session
state object, because they have their own ones)


Tamas Szekeres wrote:
> 
> Hi,
> 
> Actually queryByAttributes doesn`t restore the filter to the previous
> value. I consider this as a bug so don`t hesitate to file a ticket
> with this issue.
> You can workaround the problem by restoring the filter to a default state,
> like:
> 
> layer.setFilter(null);
> layer.filteritem = null;
> 
> 
> Some further notes:
> 
> It`s the caller`s responsibitity to avoid the passing invalid
> parameters to the functions, therefore you should raise an error to
> the user instead of calling queryByAttributes in this case.
> 
> You should avoid using the same mapObj instance in the subsequent
> queries, mapscript objects cannot safely passed between multiple
> threads. But you could anyway store a prototype mapObj in a session
> object but you should call mapObj.clone() somewhere at the beginning
> of the handler and operate on the clone afterwards.
> 
> Best regards,
> 
> Tamas
> 
> 
> 
> 2008/6/6 BrainDrain <paulborodaev at gmail.com>:
>>
>> I use mapscript in c#, data from postgis, map file is correct. My web
>> service
>> produce map image with mapObj.draw() method, mapObj stored in session
>> state
>> object to prevent useless mapfile parsing every time calling web server.
>> My
>> web app has an attribute query widget, which can initiate invalid query
>> string (filter) - sql where expression (just misprint for ex.). For ex.
>> we
>> have empty (zero length) query string "" for table street_axis. that will
>> produce an an exception during layer.queryByAttributes(map, "", filter,
>> mapscript.MS_MULTIPLE). After! this error occurred I have an exception in
>> my
>> web service (when requested by openlayers rich client js lib (by
>> zoomming/panning map)). This is expected:
>>  Message="msDrawMap(): Image handling error. Failed to draw layer named
>> 'street_axis'.;prepare_database(): Query error. Error executing POSTGIS
>> DECLARE (the actual query) statement: 'DECLARE mycursor BINARY CURSOR FOR
>> SELECT
>> \"name\"::text,asbinary(force_collection(force_2d(geom)),'NDR'),id::text
>> from public.street_axis WHERE () and (geom && setSRID(
>> 'BOX3D(240.340106037016 704.038663225639,418.96195656596
>> 822.319350804203)'::BOX3D,find_srid('','public.street_axis','geom') ))'
>> \n\nPostgresql reports the error as 'ERROR:  syntax error at or near
>> \")\"\nLINE 1: ...)),'NDR'),id::text from public.street_axis WHERE () and
>> (geo...\ bla bla bla. But what can I do to reset this invalid query in my
>> map object??? remove it?
>> I tried many ways right before calling map.draw() method (with or without
>> catching query exception):
>> 1) map.freeQuery(-1);
>> 2) map.freeQuery for all layers;
>> 3) turning on/off map.querymap.status;
>> 4) map.drawQuery() instead of draw();
>> 5) map.loadQuery with empty query (previously saved by 'clean' map);
>> 6) PROCESSING "CLOSE_CONNECTION=DEFER" or without it (in map file);
>> 7) opening/closing layers;
>> 8) even !!! making new dummy valid query returning 0 records (something
>> like
>> "id<0") on catching exception
>>  ... but nothing helped me!!!
>> Only the way I can use now is parsing mapObj from scratch from my
>> temporary
>> saved map file? but i don't like it:).
>> --
>> View this message in context:
>> http://www.nabble.com/help%21-strange-preserving-invalid-query-in-mapobject-tp17667367p17667367.html
>> Sent from the Mapserver - Dev mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> mapserver-dev mailing list
>> mapserver-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapserver-dev
>>
> _______________________________________________
> mapserver-dev mailing list
> mapserver-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-dev
> 
> 

-- 
View this message in context: http://www.nabble.com/help%21-strange-preserving-invalid-query-in-mapobject-tp17667367p17708858.html
Sent from the Mapserver - Dev mailing list archive at Nabble.com.



More information about the mapserver-dev mailing list