1

I am migrating an existing application from Mapserver 6.2.1 to Mapserver 7.0. How did the expression-Querying change there?

When doing an itemnquery or itemquery it always fails in querying my postgis-Layers. This is my query:

mapserv.exe "QUERY_STRING=mode=itemnquery&schluesselgesamt='0335502400092'&qstring=hausnummer='5'&qlayer=alkisadresssuche&mapsize=1129+646&map=E:\tmp\tmp_alkis.map&"

I didn't use any FILTER in my layer but it seems that it therefore includes an empty filter which can be found in the Postgres-log:

syntax error at or near ")"

here is the sent query from Postgres-Log

select "schluesselgesamt","id","hausnummer",encode(ST_AsBinary(ST_Force2D("geom"),'NDR'),'hex') as geom,"id" 
from (SELECT schluesselgesamt, id, geom geom FROM alkis.adresssuche ) as ergebnis where geom 
&& ST_GeomFromText('POLYGON((593025 5891783,593025 5893724,595424 5893724,595424 5891783,593025 5891783))',25832) 
and () and (schluesselgesamt='0335502400092')

It works with ONE query parameter but not with multiple parameters. I tried several different calls to mapserver and it works without EXPRESSION or FILTER or PROCESSING=NATIVE_FILTER.

This was the important part in the original query: :&qstring=schluesselgesamt='0335502400092'+AND+hausnummer='5'&

The Mapserver homepage just told me, that the FILTER has changed but not that it is now needed. Also is there no hint on the Mapserver EXPRESSION page on possible changes. The Mapserver7 changelog only gives some tickets about changes in query but they didn't help much (http://mapserver.org/development/changelog/changelog-7-0.html#changelog-7-0-0-beta2)

Does somebody has any hints for me in this case? Any not so well documented changes in Mapserver7?

By the way: here is my layer:

LAYER
    CONNECTIONTYPE postgis
    NAME "alkisadresssuche"    
    CONNECTION "user=***** dbname=local_database host=localhost password=****"
    DATA "geom from (SELECT schluesselgesamt, id, hausnummer, geom FROM alkis.adresssuche 
            ) as ergebnis using unique id USING srid=25832"
    STATUS On
    TYPE POLYGON
    DEBUG On
    HEADER   "../templates/utf8/search_h.html"
    TEMPLATE "../templates/utf8/search_q.html"
    CLASS
       NAME "Alkis-Adresssuche"
       STYLE
          WIDTH 5
          OUTLINECOLOR 0 0 255 
       END
    END
    VALIDATION
        "schluesselgesamt" "."
        "hausnummer" "."
        "qstring"  "."
    END
END
1

Result

The problem that I had was, that the QSTRING parameter tries to be reworked into an SQL-Syntax. If this is not possible, then it will be deleted which results in an empty SQL: "and ()" in the Postgres/Postgis-Layer-Query.

If the QSTRING is encapsulated in rounded parenthesis "()" then it will be evaluated as Mapserver-Expression. Therefore i then need to also add the quare brackets "[]". The final working QSTRING is:

...&qstring=([schluesselgesamt]='0335502400092')+AND+([hausnummer]='4')&...

This results in the following Postgres-Query:

...("schluesselgesamt" = '0335502400092') and ("hausnummer" = '5')

Developing-Details

Following is the text from the research in progress; i leave it here for details that might help somebody.

I am still not quite sure about the changes in mapserver 7 (or 6) and what happened. But to me it looks like that it is not possible (since Mapserver7) to have multiple parameters in the qstring any more.

The following query works:

mapserv.exe "QUERY_STRING=mode=itemnquery&qitem=schluesselgesamt&qstring='0335502400092'&hausnummer='5'&qlayer=alkisadresssuche&mapsize=1129+646&map=E:\tmp\tmp_alkis.map&"

Therefore I now have only ONE qitem and one parameter in the qstring and the second parameter is given separately

&qitem=schluesselgesamt&qstring='0335502400092'&hausnummer='5'&qlayer=alkisadresssuche&

My mapfile now needs to have the second parameter directly as it isn't given any more the parameter as well:

DATA "geom from (SELECT schluesselgesamt, id, hausnummer, geom 
        FROM alkis.adresssuche 
        WHERE hausnummer=%hausnummer%
        ) as ergebnis using unique id USING srid=25832"
STATUS On

That helps for the itemnquery and afterwards for the highlighting in the map I use the same expression as before (the second half of the parameter is not needed any more):

EXPRESSION (('[schluesselgesamt]'=%schluesselgesamt%) && ('[hausnummer]'=%hausnummer%))

Edit: Regarding the anove mentioned error:

syntax error at or near ")"

It seems that errors in the QSTRING parameter or unknown parameters results in an empty qstring and this is added at the end of the mapserver-postgis-query and therefore the error by mapserver-addition of and () to the SQL.

an helpful link were the following from the Mapserver-mailinglist:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.