[Dbix-class] Re: Determining if a ResultsSource/table exists
Rob Kinyon
rob.kinyon at gmail.com
Fri Mar 6 13:58:31 GMT 2009
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 <tom at eborcom.com> 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/dbix-class@lists.scsys.co.uk
>
--
Thanks,
Rob Kinyon
More information about the DBIx-Class
mailing list