For Programmers: Free Programming Magazines  


Home > Archive > AWK > October 2004 > Parsing PL/SQL Source Code









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Parsing PL/SQL Source Code
Gabriel Jenik

2004-10-02, 8:56 am

Hi Everybody!!

My name is Gabriel Jenik and I am in the need of analyzing a PL/SQL
source code in order to extract all the tables being used by any SQL
statemnt (INSERT, UPDATE, DELETE or SELECT)

The code is 7000 lines long so it is not usefull to do it by hand.
That's when I thought about awk and regex.

Does anybody has a clue, thought, experience or idea about from where
to start? Any startegy that I could follow?

I got stuck when having to deal with multiple tables in a "select ...
from ..." statement.

Thanks

Gabriel
Brian Inglis

2004-10-02, 8:56 am

On 1 Oct 2004 10:47:04 -0700 in comp.lang.awk, gabrieljenik@yahoo.es
(Gabriel Jenik) wrote:

>I am in the need of analyzing a PL/SQL
>source code in order to extract all the tables being used by any SQL
>statemnt (INSERT, UPDATE, DELETE or SELECT)
>
>The code is 7000 lines long so it is not usefull to do it by hand.
>That's when I thought about awk and regex.
>
>Does anybody has a clue, thought, experience or idea about from where
>to start? Any startegy that I could follow?
>
>I got stuck when having to deal with multiple tables in a "select ...
>from ..." statement.


Save yourself the trouble, it's not worth the hassle, due to the
non-line oriented nature of SQL, and additional clauses that may be
present.
Make a copy of the file (perhaps with line numbers), use an editor to
search for 'insert', 'update', 'delete', and 'from', delete all the
lines that don't contain tables, then clean up remaining junk.
You should be able to do it in about an hour for 7000 lines.

--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada

Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]a
b[dot]ca)
fake address use address above to reply
William Park

2004-10-02, 8:56 am

Brian Inglis <Brian.Inglis@systematicsw.invalid> wrote:
> On 1 Oct 2004 10:47:04 -0700 in comp.lang.awk, gabrieljenik@yahoo.es
> (Gabriel Jenik) wrote:
>
>
> Save yourself the trouble, it's not worth the hassle, due to the
> non-line oriented nature of SQL, and additional clauses that may be
> present.
> Make a copy of the file (perhaps with line numbers), use an editor to
> search for 'insert', 'update', 'delete', and 'from', delete all the
> lines that don't contain tables, then clean up remaining junk.
> You should be able to do it in about an hour for 7000 lines.


Good advice. However, if you're extracting only the names of tables,
then it's doable using regex, because you know the syntax of SQL and
where the table names appear. But, because SQL is free-form, you need
to slurp the file as long string, and apply regex on that, ignoring the
special meaning of \n. Perl, Python, and Bash can do this, but Awk,
Sed, and Grep will have hard time.

--
William Park <opengeometry@yahoo.ca>
Open Geometry Consulting, Toronto, Canada
Brian Inglis

2004-10-02, 8:56 am

On 2 Oct 2004 06:39:09 GMT in comp.lang.awk, William Park
<opengeometry@yahoo.ca> wrote:

>Brian Inglis <Brian.Inglis@systematicsw.invalid> wrote:
>
>Good advice. However, if you're extracting only the names of tables,
>then it's doable using regex, because you know the syntax of SQL and
>where the table names appear. But, because SQL is free-form, you need
>to slurp the file as long string, and apply regex on that, ignoring the
>special meaning of \n. Perl, Python, and Bash can do this, but Awk,
>Sed, and Grep will have hard time.


The problem is not finding where the table name(s) start, rather
deciding when they stop, as each SQL dialect has various different
clauses that can follow.

--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada

Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]a
b[dot]ca)
fake address use address above to reply
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com