Hi All,
Just wondering if there is a recommended way
to test whether a table exists in a DBIx::Class
database independent way ?
At the moment I'm doing it this ugly way:
sub tableExists {
my $self = shift;
my $name = shift;
my $schema = $self->_getSchema(); # Get our DBIx::Class schema.
my $table = $schema->source($name)->from(); # Get our actual table name.
my $dbh = $schema->storage->dbh; # Get our DBI handle.
# Try preparing a select on the table in question.
eval { $dbh->prepare("select count(*) from $table where 1=0") };
if ($dbh->err) {
# Table probably does not exist.
return 0;
}
else {
return 1;
}
}
But I'm not sure if it's very elegant. I got the prepare
code by googling. Is there a better way ?
Any thoughts much appreciated.
Cheers,
Doug
--
"The big print giveth and the small print taketh away"
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]