Why does the old photo remain in my blog after being replaced by a new one?
Fw: How to Retrieve Table Name from Statement Handle
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > Perl web-programming > Fw: How to Retrieve Table Name from Statement Handle 8 May 2008 23:26:34

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

Fw: How to Retrieve Table Name from Statement Handle

Lamb Joseph 8 May 2008 23:26:34
 To answer you question, for an Oracle environment I would like $sth->{TABLENAME} to contain a list.

my $tablename = $sth->{TABLENAME} ->[0] = First table
$tablename $sth->{TABLENAME} ->[1] = Second table

The $tablename value will be schema.tablename format.
For example:
schema.narf
schema.zord

Joseph Lamb


----- Forwarded Message ----
From: Alexander Foken <alexander@foken.de­>
To: Lamb Joseph <joseph_lamb@yahoo.­com>
Cc: dbi-users@perl.org
Sent: Wednesday, May 7, 2008 11:18:53 AM
Subject: Re: How to Retrieve Table Name from Statement Handle

Hmmm, and what do you think $sth->{TABLENAME} should contain after
executing the following SQL?

SELECT t1.foo,t2.bar FROM narf t1, zord t2 WHERE t1.ikes=t2.blurb

Alexander

On 07.05.2008 19:51, Lamb Joseph wrote:
I am creating a simple tool that will query one table and retrieve the data. Then this tool will turn the data into insert statements.
I was wondering if there was a way to retrieve the table name from the statement handle?
Similar to print "SQL statement contains $sth->{NUM_OF_FIELD­S} columns\n";
but like this
print "SQL statement table name is $sth->{TABLENAME} \n";
Joseph Lamb
___________________­____________________­____________________­____________________­_____
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo­.com/;_ylt=Ahu06i62s­R8HDtDypao8Wcj9tAcJ


--
Alexander Foken
mailto:alexander@fo­ken.de http://www.foken.de­/alexander/


___________________­____________________­____________________­____________________­_____
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo­.com/;_ylt=Ahu06i62s­R8HDtDypao8Wcj9tAcJ

OptionsAdd comment
Lamb Joseph 7 May 2008 23:41:01 permanent link ]
 I will have to break apart the SQL statement with a regex and store it that way.

Thanks for the input.

Joseph Lamb


----- Forwarded Message ----
From: Jonathan Leffler <jonathan.leffler@g­mail.com>
To: Lamb Joseph <joseph_lamb@yahoo.­com>
Cc: dbi-users@perl.org
Sent: Wednesday, May 7, 2008 12:22:06 PM
Subject: Re: How to Retrieve Table Name from Statement Handle

On Wed, May 7, 2008 at 10:51 AM, Lamb Joseph <joseph_lamb@yahoo.­com> wrote:

I am creating a simple tool that will query one table and retrieve the
data. Then this tool will turn the data into insert statements.
I was wondering if there was a way to retrieve the table name from the
statement handle?
Similar to print "SQL statement contains $sth->{NUM_OF_FIELD­S} columns\n";
but like this
print "SQL statement table name is $sth->{TABLENAME} \n";


Over and above Alexander's cogent (but gentle - the SQL could have been a
lot more complex than that) rebuttal, there's another question for you:

How did you decide which table to build the 'SELECT * FROM $table' query
from?
Can't you keep tabs on the table name from that?

(Succinctly - no, you can't tell the table name from the statement handle
because, in general, there isn't a single table name to report.)

--
Jonathan Leffler <jonathan.leffler@g­mail.com> #include <disclaimer.h>
Guardian of DBD::Informix - v2008.0229 - http://dbi.perl.org­
"Blessed are we who can laugh at ourselves, for we shall never cease to be
amused."



___________________­____________________­____________________­____________________­_____
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo­.com/;_ylt=Ahu06i62s­R8HDtDypao8Wcj9tAcJ

Add comment
Jonathan Leffler 7 May 2008 23:48:56 permanent link ]
 On Wed, May 7, 2008 at 12:37 PM, Lamb Joseph <joseph_lamb@yahoo.­com> wrote:

To answer you question, for an Oracle environment I would like
$sth->{TABLENAME} to contain a list.
my $tablename = $sth->{TABLENAME} ->[0] = First table
$tablename $sth->{TABLENAME} ->[1] = Second table
The $tablename value will be schema.tablename format.
For example:
schema.narf
schema.zord


So, what do you expect from a more complex statement, such as one which
includes multiply nested sub-queries in the FROM clause, with renaming
operations?

SELECT * FROM table1, (SELECT * FROM (SELECT * FROM ...) AS renaming) AS
renaming2 OUTER JOIN (...) ...

And who do you expect to do the parsing of your SQL? On average, the DBD
driver shouldn't have to, and the average database server won't tell you,
so... Also, don't forget that any of the names could be a reference to an
arbitrarily complex view -- what should be returned then?

I'm sorry, but I don't think you are going to get the information, unless
some DB server is willing to give that information to the driver.

I've seen your response to my other post:
I will have to break apart the SQL statement with a regex and store it
that way.
Question: how do you know that it is query using a single table - as your
original question posited?


I won't lambast this any further. Suffice to say, what you are asking for
is incredibly non-trivial in the general case, and the general case has to
work as well as the trivial.



----- Forwarded Message ----
From: Alexander Foken <alexander@foken.de­>
To: Lamb Joseph <joseph_lamb@yahoo.­com>
Cc: dbi-users@perl.org
Sent: Wednesday, May 7, 2008 11:18:53 AM
Subject: Re: How to Retrieve Table Name from Statement Handle
Hmmm, and what do you think $sth->{TABLENAME} should contain after
executing the following SQL?
SELECT t1.foo,t2.bar FROM narf t1, zord t2 WHERE t1.ikes=t2.blurb
Alexander
On 07.05.2008 19:51, Lamb Joseph wrote:
I am creating a simple tool that will query one table and retrieve the
data. Then this tool will turn the data into insert statements.
I was wondering if there was a way to retrieve the table name from the
statement handle?
Similar to print "SQL statement contains $sth->{NUM_OF_FIELD­S}
columns\n";
but like this
print "SQL statement table name is $sth->{TABLENAME} \n";
Joseph Lamb
___________________­____________________­____________________­____________________­_____
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
--
Alexander Foken
mailto:alexander@fo­ken.de http://www.foken.de­/alexander/
___________________­____________________­____________________­____________________­_____
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.



--
Jonathan Leffler <jonathan.leffler@g­mail.com> #include <disclaimer.h>
Guardian of DBD::Informix - v2008.0229 - http://dbi.perl.org­
"Blessed are we who can laugh at ourselves, for we shall never cease to be
amused."
Add comment
Steve Baldwin 8 May 2008 00:11:23 permanent link ]
 You may be able to use the explain plan functionality in Oracle to
obtain the tables participating in a SELECT statement.

Steve

On Wed, 2008-05-07 at 12:48 -0700, Jonathan Leffler wrote:
On Wed, May 7, 2008 at 12:37 PM, Lamb Joseph <joseph_lamb@yahoo.­com> wrote:
To answer you question, for an Oracle environment I would like
$sth->{TABLENAME} to contain a list.
my $tablename = $sth->{TABLENAME} ->[0] = First table
$tablename $sth->{TABLENAME} ->[1] = Second table
The $tablename value will be schema.tablename format.
For example:
schema.narf
schema.zord
So, what do you expect from a more complex statement, such as one which
includes multiply nested sub-queries in the FROM clause, with renaming
operations?
SELECT * FROM table1, (SELECT * FROM (SELECT * FROM ...) AS renaming) AS
renaming2 OUTER JOIN (...) ...
And who do you expect to do the parsing of your SQL? On average, the DBD
driver shouldn't have to, and the average database server won't tell you,
so... Also, don't forget that any of the names could be a reference to an
arbitrarily complex view -- what should be returned then?
I'm sorry, but I don't think you are going to get the information, unless
some DB server is willing to give that information to the driver.
I've seen your response to my other post:
I will have to break apart the SQL statement with a regex and store it
that way.
Question: how do you know that it is query using a single table - as your
original question posited?
I won't lambast this any further. Suffice to say, what you are asking for
is incredibly non-trivial in the general case, and the general case has to
work as well as the trivial.
----- Forwarded Message ----
From: Alexander Foken <alexander@foken.de­>
To: Lamb Joseph <joseph_lamb@yahoo.­com>
Cc: dbi-users@perl.org
Sent: Wednesday, May 7, 2008 11:18:53 AM
Subject: Re: How to Retrieve Table Name from Statement Handle
Hmmm, and what do you think $sth->{TABLENAME} should contain after
executing the following SQL?
SELECT t1.foo,t2.bar FROM narf t1, zord t2 WHERE t1.ikes=t2.blurb
Alexander
On 07.05.2008 19:51, Lamb Joseph wrote:
I am creating a simple tool that will query one table and retrieve the
data. Then this tool will turn the data into insert statements.
I was wondering if there was a way to retrieve the table name from the
statement handle?
Similar to print "SQL statement contains $sth->{NUM_OF_FIELD­S}
columns\n";
but like this
print "SQL statement table name is $sth->{TABLENAME} \n";
Joseph Lamb
___________________­____________________­____________________­____________________­_____
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
--
Alexander Foken
mailto:alexander@fo­ken.de http://www.foken.de­/alexander/
___________________­____________________­____________________­____________________­_____
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.



*******************­********************­********************­*******
This email is intended solely for the use of the addressee and may
contain information that is confidential, proprietary, or both.

If you receive this email in error please immediately notify the
sender and delete the email.
*******************­********************­********************­*******


Add comment
Bart Lateur 8 May 2008 23:26:34 permanent link ]
 On Wed, 7 May 2008 12:41:01 -0700 (PDT), Lamb Joseph wrote:

I will have to break apart the SQL statement with a regex and store it that way.
Thanks for the input.

More input: take a look at Ovid's article "Lexing Your Data" on
perl.com, at

http://www.perl.com­/pub/a/2006/01/05/pa­rsing.html

which discusses using a tokenizer (lexer) to pull tokens, such as table
names, out of SQL statements.

--
Bart.

Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > Perl web-programming > Fw: How to Retrieve Table Name from Statement Handle 8 May 2008 23:26:34

see also:
Mod_rewrite help
Apache behaviour for bad HTTP headers
Exact behaviour of KeepAliveTimeout
see also:
Bizarre 404 errors
Limiting space.
Limiting User on a Virtual Site
see also:
Authentication and Redirect...
odd log entry
2.x and mod_ssl

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
You can find the help and FAQ in the Admin's blog.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .