perl - Using DBIx::Class, how can I check if a table exists? -


my goal create function create mysql db table (using schema defined via dbix::class already) if hasn't been created yet. otherwise creates reference $schema.

currently understand how create table if doesn't exist following code:

my $schema = myapp::schema->connect(    $dsn,    $user,    $password,  );  $schema->deploy( { add_drop_table => 1 } ); 

i need add more logic not attempt add table if exists.

you can use "drop table if exists" in create table statement if want create every time. if don't want mess data can "show tables" , parse results, like

my $tables = $dbh->selectall_arrayref(qq|show tables|) or die "can't show tables " . $dbh->errstr(); if (@$tables) {     foreach $table (@$tables) {          if ($table->[0] eq 'sometablename') {          # table sometablename exists       }    } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -