Per http://www.perlmonks.org/?node_id=412089, the table_info solution should work on nearly every DBD.
Rob On Fri, Mar 6, 2009 at 04:33, Tom Hukins <[email protected]> wrote: > On Fri, Mar 06, 2009 at 03:09:59PM +1100, Doug Scoular wrote: >> Just wondering if there is a recommended way to test whether a table >> exists in a DBIx::Class database independent way ? > > That dosen't sound like a DBIx::Class problem: DBIx::Class deals with > result sources, not tables. You can see whether a result source > exists by checking you receive a defined value when trying to retrieve > one. > > However, at the lower DBI level you might want to see whether a table exists. > I have some old code that I recall working the MySQL, SQLite and SQL Server > 2000: > > sub table_exists { > my $self = shift; > my %arg = @_; > > my $sth = $self->table_info( > '%', > '%', > $arg{table}, > ); > while ( my $row = $sth->fetchrow_hashref() ) { > return $arg{table} if $row->{TABLE_NAME} eq $arg{table}; > } > return; > } > > This code lived in a DBI::db subclass, so I could do: > > $dbh->table_exists(table => 'TABLE_NAME'); > > Tom > > _______________________________________________ > 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] > -- Thanks, Rob Kinyon _______________________________________________ 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]
