Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

SQLite Table Existence?

by Anonymous Monk
on Sep 17, 2010 at 14:41 UTC ( [id://860496]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there a better way of checking to see if a SQLite table exists? This is how I currently check but doesn't seem correct:
my $dbh = DBI->connect( "dbi:SQLite:$db" ) || warn "Cannot connect +: $DBI::errstr"; my $all = $dbh->selectall_arrayref( "SELECT * from table_X" ); if ( defined $all ) { # table exists } else { # table deosn't exist } $dbh->disconnect;

Replies are listed 'Best First'.
Re: SQLite Table Existence?
by jau (Hermit) on Sep 17, 2010 at 15:03 UTC
Re: SQLite Table Existence?
by Anonymous Monk on Sep 17, 2010 at 23:54 UTC
    Hi,

    SQLite has a table called sqlite_master
    which holds details of all the tables you have created.

    Try -

    select * from sqlite_master;

    to have a look at it.

    J.C.
      That worked...great to know!
      Thanks

        It is not, however, what you want to use. Use tables or table_info from DBI. They will continue to work if you move to Pg or MySQL or whatever DBD engine you like. Every bit of engine dependent code you add is a future impediment to change and further amounts to an interface fork you will have to maintain when you could get it for free.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-28 11:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found