I need to write a program that accepts a basic SQL select statement and outputs an XML file which breaks down the statement into it’s component parts (the output columns, the input tables, the join, group by, aggregations, etc.). At a minimum I need to support 2 tables in the from statement, different join types, where clause, group by and having. If more complex sql can be supported (e.g. subqueries) that’s a bonus, but not necessary.
I checked out ANTLR and it looks like a steep learning curve. Given that I have the ability to require the SQL to be fairly simple, should I attempt to hand code or should I embark on the world of ANTLR?
I don’t think you need to reinvent such a sql parser with ANTLR. Here is a sample that decode select SQL statement into meta-data:
Meta info:
If this is what you need, then you can check this article that illustrate how to use a sql parser to achieve this.