#1829 closed enhancement (invalid)
Test if runtime variable is defined
Reported by: | Owned by: | sdlime | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | MapServer CGI | Version: | unspecified |
Severity: | minor | Keywords: | |
Cc: |
Description
I wish it were possible to have an EXPRESSION to test if a variable is defined. I would like to be able to test this: EXPRESSION (defined '%key%') or EXPRESSION ('%key%' != NULL) The problem is that %key% is not replaced in case no 'key' is passed through query_string, and you get a literal '%key%' string in your expression instead of a null value. I found a workaround for this: EXPRESSION (('%key%' lt '%key$' or '%key%' gt '%key&') and '[FIELD]' ne '%key%') You can't test if %key% is defined, but you can test if %key% is equal to literal '%key%'. This is my dirty way to test is a variable is defined. I think the best approach is to replace all %vars% on mapfile with empty strings in case they were not defined. This is the default behaviour of Perl's template module, for example. Could you please consider implementing a way to test if a variable is defined?
Change History (5)
comment:2 by , 18 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
This is impossible to do as you envision because MapServer doesn't know what runtime variables to expect. However, you do, so why wouldn't this work. Let's say you have a runtime variable called foo, then why not do something like: EXPRESSION (!('%foo%' =~ /foo/)) If the substitution doesn't take place, that is, foo isn't set then the regular expression ('%foo%' =~ /foo/) would evaluate to true. Assuming that works (and it should) then I see no reason to pursue a more elegant solution, so I'll mark this as INVALID for now and we can always re- open later. Steve
comment:3 by , 18 years ago
Hi Steve, your expression is more elegant (and slower) than mine. You are right. It works, so this is not a high priority enhancement. But this is not a nice solution, and not intuitive at all. Users must have a happy idea in order to imagine this kind of solution. There should be, at least, some referece to this trick on mapserver documentation.
comment:4 by , 18 years ago
The CGI variables never make it down to the expression engine so I'm afraid this is the best we'll do for the moment. An expanded set of string operators (e.g. a strstr wrapper for substrings) might help with the speed issue. As for documentation- the website will accept documentation from any and all users so here might be a good opportunity to create a short howto or snippet! Steve
Note:
See TracTickets
for help on using tickets.