0

I am writing a SQL query evaluator and I am using JSQLParser for parsing the query. Now it seems (and also suggested by this link http://sourceforge.net/p/jsqlparser/feature-requests/2/ ) that JSQLParser does not allow multiple items in the FROM Clause of SQL.

When I do

statement.getFromItem().toString();

where statement is an object of type PlainSelect, I get only the first tablename from the FROM Clause. There is no toArray() method in the FromItem Class.

Is there any workaround for this ?

yakout
  • 782
  • 3
  • 9
  • 24
ping localhost
  • 479
  • 3
  • 22

1 Answers1

2

In fact JSQLParser is able to parse your statement or your mentioned example:

select t1.a, t2.b from t1, t2 where t1.id = t2.id

The second table is not recognized as a second FromItem but as a simple Join. To get your tables you need to look into getJoins as well.

Here is my test code, which is written using the fork of JSqlParser at github https://github.com/JSQLParser/JSqlParser.

public class MultiFromItems {
    public static void main(String args[]) throws JSQLParserException {
        String sql = "select t1.a, t2.b from t1, t2 where t1.id = t2.id";
        Statement parse = CCJSqlParserUtil.parse(sql);
        Select select = (Select)parse;
        PlainSelect ps = (PlainSelect)select.getSelectBody();
        System.out.println(ps);
        System.out.println(ps.getFromItem());
        System.out.println(ps.getJoins().get(0));
    }
}
wumpz
  • 8,257
  • 3
  • 30
  • 25