Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#1829 closed enhancement (invalid)

Test if runtime variable is defined

Reported by: bugzilla@… 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:1 by bugzilla@…, 18 years ago

*** Bug 1830 has been marked as a duplicate of this bug. ***

comment:2 by sdlime, 18 years ago

Resolution: invalid
Status: newclosed
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 bugzilla@…, 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 sdlime, 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

comment:5 by sdlime, 18 years ago

FYI I did add an FAQ to the website. Feel free to add to it!

Steve
Note: See TracTickets for help on using tickets.