RE: Checking if a table exist



Thanks Jonathan. I was thinking about doing something like this:

@tables = $dbh->tables();

if ((grep/$tableName/, @tables) <= 0) {
...


________________________________

From: Jonathan Leffler [mailto:jonathan.leffler@xxxxxxxxx]
Sent: Thursday, April 27, 2006 5:17 PM
To: Loo, Peter # PHX
Cc: DBI users
Subject: Re: Checking if a table exist




On 4/27/06, Loo, Peter # PHX <Peter.Loo@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:


Does anyone know of a good way to check if a table exist
disregarding
whether the table has data or not?



Simplest is:

my $sth = $dbh->prepare("SELECT * FROM $tablename");
if ($sth) { ...table exists...probably; you might need to do
$sth->execute to be sure as different DBMS differ... }
else { ...table probably doesn't exist, or it exists but you don't
have select permission on it... }

Or you can play with table_info, etc.

--
Jonathan Leffler <jonathan.leffler@xxxxxxxxx> #include <disclaimer.h>
Guardian of DBD::Informix - v2005.02 - http://dbi.perl.org
"I don't suffer from insanity - I enjoy every minute of it."


This E-mail message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply E-mail, and destroy all copies of the original message.


Relevant Pages

  • Re: Back from the southern regions ....
    ... Jonathan;o} wrote: ... Anyway and getting to point here -- many stops along the way to friends we know in different states and in one stop, our friends were talking about how Granny made it to age 94 and how she used to just love the piano. ... And finally -- in Florida -- we get asked to another friend's house and little 'Elizabeth', age 12, is asked by her mother to play. ...
    (rec.music.makers.piano)
  • try not to kick a button
    ... It can happily irritate within Jonathan when the distant coconuts ... play it. ... If you will hate Frederick's camp beneath games, ... seeks farmers in Geoffrey's open dust. ...
    (uk.rec.gardening)
  • Re: An experiment in Attitude
    ... Jonathan should have asked the guy why he was ... laughing or simply gone quiet on the phone until the guy asked him what ... There'a nothing childish about laughing. ... to play, considering the circumstances. ...
    (alt.guitar.bass)
  • Re: national championship tomorrow
    ... On Dec 4 2009 11:20 PM, jonathan wrote: ... i hate the way you play your hands ... and you wear your gun all wrong ...
    (rec.gambling.poker)
  • Re: An experiment in Attitude
    ... That's just childish. ... Jonathan should have asked the guy why he was laughing ... I think it's great the Jonathan is standing up for himself, ... A professional tells the bandleader on what songs he wants to play ...
    (alt.guitar.bass)