RE: Checking if a table exist
- From: Peter.Loo@xxxxxxxxxxxxxxxxxxxxxxxx (Peter # PHX Loo)
- Date: Thu, 27 Apr 2006 17:29:47 -0700
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.
- Prev by Date: Re: Checking if a table exist
- Next by Date: Re: Re: DBD::Oracle ppd
- Previous by thread: Re: Checking if a table exist
- Next by thread: RE: Checking if a table exist
- Index(es):
Relevant Pages
|