db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Hillegas <Richard.Hille...@Sun.COM>
Subject Re: Extracting dependencies from SQL statements
Date Tue, 09 Mar 2010 16:22:50 GMT
Hi Pavel,

These programs should be run using the Derby debug jars. I have edited 
the introductory comment to try to make this clear. The debug logic must 
be compiled into Derby in order for compilation to stop after parsing. 
If you need a solution which runs against the production jars, take a 
look at the related issue DERBY-791.

Hope this helps,
-Rick

Pavel Bortnovskiy wrote:
>
> I was able to compile both files by disabling SanityManager method 
> invocation and replacing ContextId.LANG_CONNECTION with its string 
> "LanguageConnectionContext".
> No other changes to ASTParser and TreeWalker have been done, however, 
> when running them the following exception is thrown:
>
> Parsing:
> select a from t, s where t.a = s.a
> Exception in thread "main" java.sql.SQLSyntaxErrorException: 
> Table/View 'T' does not exist.
>         at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
> Source)
>         at 
> org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
>         at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>         at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>         at 
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>         at 
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>         at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
>         at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown 
> Source)
>         at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown 
> Source)
>         at 
> org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown 
> Source)
>         at 
> org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
>         at 
> org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown 
> Source)
>         at 
> org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown 
> Source)
>         at TreeWalker.execute(TreeWalker.java:95)
>         at TreeWalker.main(TreeWalker.java:79)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
>
>         at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

>
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at 
> com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)
>
>
>
>
>
> *Rick Hillegas <Richard.Hillegas@Sun.COM>*
> Sent by: Richard.Hillegas@Sun.COM
>
> 03/09/2010 08:35 AM
> Please respond to
> "Derby Discussion" <derby-user@db.apache.org>
>
>
> 	
> To
> 	Derby Discussion <derby-user@db.apache.org>
> cc
> 	
> Subject
> 	Re: Extracting dependencies from SQL statements
>
>
>
> 	
>
>
>
>
>
> Hi Pavel,
>
> I don't know of an easy way to do this. You could run the statement
> through the Derby parser to get the parsed representation, the Abstract
> Syntax Tree. Then you could write a Visitor to walk the AST, looking for
> the nodes which represent tables. See the following JIRAs for some
> pointers on how to produce and walk the AST: DERBY-3946 and DERBY-791.
>
> Unfortunately, there is no systematic primer on the AST nodes
> themselves. All we have is the javadoc for the package
> org.apache.derby.impl.sql.compile.
>
> Hope this helps,
> -Rick
>
> Pavel Bortnovskiy wrote:
> >
> > Hello:
> >
> > is it possible to use Derby's SQL parser to "extract" dependencies
> > from a given SQL statement?
> > (or access the parser once the statement has been parsed).
> >
> > Whether it's a simple SELECT or a JOIN, UNION or a more complex
> > statement, I would like to get a list of tables that this statement
> > would depend on.
> > Looking for FROM clauses and attempting to do the parsing myself seems
> > like a difficult, error prone and impractical way to approach this.
> >
> > Any suggestions, please?
> >
> > Thanks,
> > Pavel.
> >
> >
> >
> > Jefferies archives and monitors outgoing and incoming e-mail. The
> > contents of this email, including any attachments, are confidential to
> > the ordinary user of the email address to which it was addressed. If
> > you are not the addressee of this email you may not copy, forward,
> > disclose or otherwise use it or any part of it in any form whatsoever.
> > This email may be produced at the request of regulators or in
> > connection with civil litigation. Jefferies accepts no liability for
> > any errors or omissions arising as a result of transmission. Use by
> > other than intended recipients is prohibited.  In the United Kingdom,
> > Jefferies operates as Jefferies International Limited; registered in
> > England: no. 1978621; registered office: Vintners Place, 68 Upper
> > Thames Street, London EC4V 3BJ.  Jefferies International Limited is
> > authorised and regulated by the Financial Services Authority.
>
>
>
>
>
>
> Jefferies archives and monitors outgoing and incoming e-mail. The 
> contents of this email, including any attachments, are confidential to 
> the ordinary user of the email address to which it was addressed. If 
> you are not the addressee of this email you may not copy, forward, 
> disclose or otherwise use it or any part of it in any form whatsoever. 
> This email may be produced at the request of regulators or in 
> connection with civil litigation. Jefferies accepts no liability for 
> any errors or omissions arising as a result of transmission. Use by 
> other than intended recipients is prohibited.  In the United Kingdom, 
> Jefferies operates as Jefferies International Limited; registered in 
> England: no. 1978621; registered office: Vintners Place, 68 Upper 
> Thames Street, London EC4V 3BJ.  Jefferies International Limited is 
> authorised and regulated by the Financial Services Authority. 


Mime
View raw message