Skip to content

Instantly share code, notes, and snippets.

@shibayu36
Created March 29, 2012 14:33
Show Gist options
  • Save shibayu36/2238013 to your computer and use it in GitHub Desktop.
Save shibayu36/2238013 to your computer and use it in GitHub Desktop.
#!perl
use strict;
use warnings;
use DBI;
sub copy_schema_from_test_db ($$$$) {
my ($orig_dsn, $user, $password, $new_dbh) = @_;
my $old_dbh = DBI->connect($orig_dsn, $user, $password)
or BAIL_OUT($DBI::errstr);
my $sth_tables = $old_dbh->prepare('SHOW TABLES');
$sth_tables->execute;
while (my $row_table = $sth_tables->fetch) {
my $table = $old_dbh->quote_identifier($row_table->[0]);
my $sth_create = $old_dbh->prepare("SHOW CREATE TABLE $table");
$sth_create->execute;
my $create_statement = $sth_create->fetch->[1];
$new_dbh->do($create_statement) or die $new_dbh->errstr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment