Errto has asked for the wisdom of the Perl Monks concerning the following question:
I have a module where I would like to take a given $dbh in DBI, and a given SQL statement, and programatically obtain the list of database objects (tables and views) that this query accesses. I could use SQL::Statement but I worry that I will need to support SQL syntax features that it doesn't (for example, subselects in the FROM clause). So I would like to somehow pass the statement to the database itself and get the information that way. For example, I would feed it
and it would give me back a list like ('foo','bar','baz','quux') My database is Oracle, so if no generic solution exists, I could happily live with an Oracle-specific one.SELECT * FROM foo JOIN bar ON foo.a = bar.a JOIN (SELECT * FROM baz where something_or_other) as mysub1 ON foo.z = + mysub1.z WHERE foo.b in (SELECT y+1 FROM quux)
As an addendum, I should add that I also looked at using EXPLAIN PLAN and just querying the object names from the plan table, but I discovered that if my query uses views it would give me the underlying table names, whereas what I need are the view names.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: DBI: Identify schema objects for a statement
by jZed (Prior) on Aug 29, 2007 at 00:04 UTC | |
by CountZero (Bishop) on Aug 29, 2007 at 13:26 UTC | |
by jZed (Prior) on Aug 29, 2007 at 15:44 UTC | |
by rdfield (Priest) on Aug 30, 2007 at 11:13 UTC | |
by jZed (Prior) on Aug 30, 2007 at 15:36 UTC | |
| |
Re: DBI: Identify schema objects for a statement
by rdfield (Priest) on Aug 29, 2007 at 13:13 UTC | |
by Errto (Vicar) on Aug 29, 2007 at 14:49 UTC | |
Re: DBI: Identify schema objects for a statement
by rdfield (Priest) on Aug 29, 2007 at 11:09 UTC |