#61 Using expressions in WHERE clause results in SQLException

closed
Mario Frasca
None
5
2012-11-18
2011-12-20
Simon Chenery
No

When I call Statement.executeQuery("select * from test where c+1=2")

I get the following SQLException:

org.relique.jdbc.csv.ParseException: Encountered " "+" "+ "" at line 1, column 3.
Was expecting one of:
"IS" ...
"LIKE" ...
"BETWEEN" ...
<RELOP> ...

at org.relique.jdbc.csv.ExpressionParser.generateParseException(Unknown Source)
at org.relique.jdbc.csv.ExpressionParser.jj_consume_token(Unknown Source)
at org.relique.jdbc.csv.ExpressionParser.relationalExpression(Unknown Source)
at org.relique.jdbc.csv.ExpressionParser.logicalUnaryExpression(Unknown Source)
at org.relique.jdbc.csv.ExpressionParser.logicalAndExpression(Unknown Source)
at org.relique.jdbc.csv.ExpressionParser.logicalOrExpression(Unknown Source)
at org.relique.jdbc.csv.ExpressionParser.logicalExpression(Unknown Source)
at org.relique.jdbc.csv.ExpressionParser.parseLogicalExpression(Unknown Source)
at org.relique.jdbc.csv.SqlParser.parse(SqlParser.java:188)
at org.relique.jdbc.csv.CsvStatement.executeQuery(CsvStatement.java:326)
at org.relique.jdbc.csv.Runner5.main(Runner5.java:41)
java.sql.SQLException: Syntax Error. Encountered " "+" "+ "" at line 1, column 3.

However, the simpler call Statement.executeQuery("select * from test where c=2") does work correctly.

Discussion

  • Mario Frasca
    Mario Frasca
    2012-06-08

    I guess the problem is using an expression on the left hand side of the '='.
    did not look at the code, but I faintly remember coding this: <column> <binary operator> <expression>
    you are doing <expression> <binary operator> <expression>
    going to check memory and assumption.

     
  • Mario Frasca
    Mario Frasca
    2012-06-08

    nope. for some reason, we programmed <simple expression> <relop> <simple expression>, where <simple expression> does not allow for any operations. I think we should change the grammar here. and being at it, I also see that <parentheses expression> will fail if you put parentheses around a simple expression, like 'c = (2)'. we should add a couple of failing test here I guess.

     
  • Simon Chenery
    Simon Chenery
    2012-06-09

    Added failing unit tests to TestSqlParser.testWhereMoreParsing, testing the following SQL statements:

    SELECT * FROM test WHERE B = (20)
    SELECT * FROM test WHERE B = 20 + 30
    SELECT * FROM test WHERE B + 20 = 30

    Files changed:
    src/java/test/org/relique/jdbc/csv/TestSqlParser.java

     
  • Mario Frasca
    Mario Frasca
    2012-09-02

    d3aab71 solves this. but I think that the grammar has to be cleaned up a bit.

     
  • Mario Frasca
    Mario Frasca
    2012-09-02

    • assigned_to: nobody --> mfrasca
    • status: open --> pending
     
  • Simon Chenery
    Simon Chenery
    2012-11-18

    Included in CsvJdbc version 1.0-11

     
  • Simon Chenery
    Simon Chenery
    2012-11-18

    • status: pending --> closed
     
  • Every once in a while we choose blogs that we read. Listed below are the latest sites that we choose ?
    <a href="http://www.lagbook.com/blogs/item/retain-the-services-of-freelance-article-freelance-writers-and-also-se" title="as well as">as well as</a>