Opened 20 years ago
Closed 20 years ago
#514 closed defect (fixed)
setExpression with a variable
Reported by: | Owned by: | sdlime | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | MapScript | Version: | 4.1 |
Severity: | normal | Keywords: | |
Cc: |
Description
I'm trying to set a class expression in mapscript using a variable. I can copy the value if my variable into the setExpression() method and it works fine but I get nothing when substituting the variable. I tried all sorts of delimiter combinations with no sucess. Also, is thier a better way to define this statement nore like an SQL statement? (ie "[nodeid] in(595.0,436.1,...) My mapscript code is as follows: +++++++++++++++++++++++++++++++ $expstr="'([nodeid] eq 436.4 OR [nodeid] eq 436.2 OR [nodeid] eq 436.1 OR [nodeid] eq 434.0 OR [nodeid] eq 595.0 OR [nodeid] eq 553.0 OR [nodeid] eq 435.4 OR [nodeid] eq 452.0 OR [nodeid] eq 426.0 OR [nodeid] eq 435.2)'"; print "**ExpStr:$_,$minctr, $maxctr, $expstr <br>\n"; $class=$layer->getClass(0); ## This DOES NOT work!! $rv = $class->setExpression( $expstr ); ## Either of these statements work fine and produce the results expected # #$rv = $class->setExpression('([nodeid] eq 436.1 OR [nodeid] eq 436.2)'); #$rv = $class->setExpression('([nodeid] eq 436.4 OR [nodeid] eq 436.2 OR [nodeid] eq 436.1 OR [nodeid] eq 434.0 OR [nodeid] eq 595.0 OR [nodeid] eq 553.0 OR [nodeid] eq 435.4 OR [nodeid] eq 452.0 OR [nodeid] eq 426.0 OR [nodeid] eq 435.2)'); $rv == $mapscript::MS_SUCCESS or &Error('can not setExpression in class index $classindx layer nodes_oldnew',"error"); +++++++++++++++++++++++++++++++++++++++++++++++++++
Change History (9)
comment:2 by , 20 years ago
Yes, I'm using perl, I tried the following with no help. $rv = $class->setExpression('([nodeid] in "436.1,436.2")'); $rv = $class->setExpression('([nodeid] in (436.1,436.2))'); $rv = $class->setExpression('([nodeid] in "436.1"'); $rv = $class->setExpression('([nodeid] in (436.1)'); but the following work. $rv = $class->setExpression('([nodeid] eq 436.1'); $rv = $class->setExpression('([nodeid] eq 436.1 OR [nodeid] eq 436.2)'); My primary concern is that can't get: $rv = $class->setExpression( $expstr ); to work as stated earlier. Am I missing some simple syntax or something?
comment:3 by , 20 years ago
IN only works works with strings, otherwise you'll get a parse error. Steve
comment:4 by , 20 years ago
Can you provide me the proper syntax on these 2 setExpression statements? I'm at a loss. I thought I was passing a string value in these examples? $rv = $class->setExpression('([nodeid] in "436.1,436.2")'); and $rv = $class->setExpression( $expstr ); Thanks.
comment:5 by , 20 years ago
I'm only using POSTGIS for all of my data. I have no shapefiles, if this would make a difference in parsing the data in the setExpression method.
comment:6 by , 20 years ago
I finally figured it out! Here is the syntax that works with Postgis. $rv = $class->setExpression('(\'[nodeid]\' in "436.1,436.2")'); and $expstr = qq( (\'[nodeid]\' in "436.1,436.2") ); $rv = $class->setExpression( $expstr ); Thanks
comment:8 by , 20 years ago
Cc: | added |
---|
Steve, Tom, is there any action required here? Can this be closed as invalid?
comment:9 by , 20 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Yes, I've marked as fixed. The original problems were in the expressions themselves, not MapScript (unless you think not quoting strings is a flaw). I did fix that too. You can use numbers with the IN operator, so Tom's original expressions should work. Sorry for not cleaning this up earlier... Steve
Note:
See TracTickets
for help on using tickets.