Re: SQL query parser



Boris Stumm <stumm@xxxxxxxxxxxxxxxxxxxx> writes:

Hello all,

I am currently looking for an SQL parser written in Java, preferably
with source code. What I want to do is to infer (as far as possible)
the schema from an SQL DML statement. The parser should give me some
nice, traversable Java object tree/abstract syntax tree.

So far I only found sql4j and Zql, which both are very old and do not
parse my statements.

Anyone can give me some pointers? Here is a list of things that the
parser should be able to parse:

* CASE statements in the SELECT as well as in the WHERE clause
* subselects, exists, not exists, ...
* column and table aliasing
* grouping and aggregate functions

Derby uses javacc with an SQL grammar file which you could look at.

See http://db.apache.org/derby/dev/derby_source.html

You'll probably have to do quite a bit of tweaking to make it suit
your needs, though...

--
dt

.



Relevant Pages

  • Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
    ... Perl was to relate it to uninitialized values in Java or C++. ... The fact that nulls in SQL have special ... Both Java and C++ have containers that support set theoretic ...
    (comp.lang.perl.misc)
  • Re: SQL
    ... Persistence access is the abstraction, ... However, UML is just one of many OOA/D notations proposed, so it is an implementation of an OOA/D notation. ... Note that I was careful to say that SQL is a solution to persistence /access/ when the data is represented in RDB form. ... Sounds a little bit like Java and the JVM.... ...
    (comp.object)
  • Re: Regex questions suggestions.
    ... C comments closely resemble Java comments. ... Then there are parser generators. ... own code to a custom generated parser. ... I am usually dealing with imperfect syntax. ...
    (comp.lang.java.help)
  • Re: object databases
    ... Calling SQL from say java code is one of the easiest tasks in mordern ... The major problem is that SQL statements are written as strings in ... the strings are not compiled until runtime. ...
    (comp.object)
  • Re: Is perl better? :(((
    ... draw from variable "table" and execute a slightly modified SQL just once. ... > public void openCon(String url, ... > String user, String password) { ... > Total Java expenses 4.5 minutes. ...
    (comp.lang.java.databases)