Tim Falony Tim Falony - 2 years ago 206
Java Question

jsqlparser to evaluate a condition

The following String:

x=92 and y=29

Produces a valid output:
x=92 AND y=29
and it works fine with
but shouldn't it throw an exception for the following?

x=92 lasd y=29

But the output is just:

Furthermore which Expression I should use to implement my own visitor? i.e,

CCJSqlParser c= new CCJSqlParser(new StringReader(str));
Expression e = c.Expression(); // or SimpleExpression, etc..

So that when 'lasd' (anything other than not,or,and) is encountered I can throw an exception and not silently ignore the rest of the expression?

Answer Source

Recently a patch of JSqlParser (1.2-SNAPSHOT) was published to provide the needed behaviour:

CCJSqlParserUtil.parseExpression(String expression, boolean allowPartialParse)


CCJSqlParserUtil.parseCondExpression(String expression, boolean allowPartialParse)

Setting allowPartialParse to false will result in the mentioned Exception.

For on the fly interpreted stuff the already existing behaviour is still needed, e.g. to provide expressions from within an text. (Syntax coloring, Context help, ...)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download