9

General SQL Parser (GSP) is a quite feature rich SQL parser (to the extent that I have played with it) that allows for modifying SQL statements in a robust way by altering the parse tree itself. Furthermore, it supports SQL flavors for most popular databases. However, a big minus with GSP is that it is horribly, simply horribly, documented: the javadoc's consist mostly of the raw method and property names (with almost no comments), there are really no documentation that outlines the core functionality and the meaning of most important properties and methods; and it seems like they have just exposed everything as public members, making the API very hard to grasp by looking at it. The only documentation is a bunch of practical examples from which you have to reverse-engineer the meaning of the API calls yourself.

I do not like producing production critical software with a library like that. So due to the above, I would prefer using another parser, but have unfortunately failed to find any alternatives (for java) with similar functionality and support for multiple SQL flavors.

Are there any comparable (!) alternatives to GSP for java out there?

someName
  • 1,275
  • 2
  • 14
  • 33

3 Answers3

8

I'm James from gudu software(company that developed General SQL Parser). Due to the complexity of SQL language of various databases such as Oracle, SQL Server, DB2, MySQL, Teradata, PostgreSQL, the SQL Parser we created to support those databases was a little bit complicated as well.

I have to admit that the document of General SQL Parser is really poor, Maybe we should put more effort on the document rather than SQL library itself.

Fortunately, we have created a rich set of demos to help people getting started quickly.

If are still interested in using General SQL Parser, please kindly let me know(I can be reached via info@sqlparser.com). We are happy to help.

James Wang
  • 453
  • 4
  • 5
  • I really like GSP so far and the demos you have for C\C++ are easy to understand and great. How easy is it to expand the parser to add more operators .. it seems that the lib files are the ones responsible for that, no? – Saher Ahwal Feb 17 '14 at 03:50
2

Have you had a look at JsqlParser? I don't know how it compares feature wise, but I've seen it used in production code and it works extremely well.

laz
  • 28,320
  • 5
  • 53
  • 50
  • 1
    Apparently it does not support multiple SQL variants, and it looks quite immature (and only maintained by one person). Last, the documentation seems exactly as poor as GSP's. – someName Nov 14 '11 at 09:29
  • That's too bad. I guess there aren't many players in the field of Java SQL parsers. – laz Nov 17 '11 at 16:09
  • Are there any parsers for other languages? I have failed finding any relevant parsers in non-java languages too. – someName Nov 19 '11 at 21:19
  • Doesn't cover a huge range of SQL dialects, but does cover some. See our http://www.semanticdesigns.com/Products/FrontEnds – Ira Baxter Nov 22 '11 at 07:44
0

jOOQ's parser is an alternative. While jOOQ is historically perceived as an internal DSL that allows for writing type safe, embedded SQL queries in Java, you can also parse all sorts of SQL, procedural code, etc, from and to 30+ RDBMS dialects. and access / transform the resulting expression tree. You can execute it, or just re-generate the SQL.

There are different ways to interact with the parser:

Its documentation is vast, both in terms of the manual and Javadoc. Obviously, the documentation's main purpose is to document the DSL use case, not the parser use case, although for most parser usages this doesn't really matter.

Disclaimer: I work for the company behind jOOQ

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509