Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: DBI: checking if a table exists in a cross-DB manner?

by radiantmatrix (Parson)
on Dec 02, 2004 at 22:29 UTC ( [id://411975]=note: print w/replies, xml ) Need Help??


in reply to Re: DBI: checking if a table exists in a cross-DB manner?
in thread DBI: checking if a table exists in a cross-DB manner?

On its face, your suggestion seems great (and it is much faster than DELETE FROM, which is useful to me for another project -- thanks). However, it still doesn't address the case of a table that doesn't already exist.

So again, I'm left with:

eval { $dbh->do("TRUNCATE TABLE $table_name") }

With no reliable way to determine if an error means the table didn't exist or if it means there was actually a problem. Any ideas on how to solve for that case?

radiantmatrix
require General::Disclaimer;
s//2fde04abe76c036c9074586c1/; while(m/(.)/g){print substr(' ,JPacehklnorstu',hex($1),1)}

Replies are listed 'Best First'.
Re^3: DBI: checking if a table exists in a cross-DB manner?
by thor (Priest) on Dec 02, 2004 at 22:38 UTC
    Let's see what we can do. What about "select * from $table_name where 9=0"? For most db drivers that I know, that will either fail in the prepare or the execute if the table doesn't exist. You should be able to trap that error and act accordingly. Moreover, it won't actually fetch any data, so it's good from a data throughput standpoint. :)

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://411975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found