Skip to content

Instantly share code, notes, and snippets.

@shelling
Created August 26, 2009 09:06
Show Gist options
  • Save shelling/175411 to your computer and use it in GitHub Desktop.
Save shelling/175411 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use 5.010;
use warnings;
use utf8;
use DBI;
use SQL::Abstract;
use Data::Dumper;
$dbh_d2 = DBI->connect();
$dbh_d2->do("set character set utf8");
$dbh_local = DBI->connect();
$dbh_local->do("set character set utf8");
$sth_table_list = $dbh_local->prepare(qq{show tables;});
$sth_table_list->execute();
$res = $sth_table_list->fetchall_arrayref();
my @table;
for (@{$res}) {
push @table, @{$_};
}
my $sql = SQL::Abstract->new;
for (@table) {
$sth_d2 = $dbh_d2->prepare("select * from $_");
$sth_d2->execute();
$dbh_local->prepare(qq{truncate $_})->execute();
while ( $res = $sth_d2->fetchrow_hashref() ) {
my ($statment, @bind) = $sql->insert($_, $res);
$dbh_local->prepare($statment)->execute(@bind);
}
}
$dbh_d2->disconnect;
$dbh_local->disconnect;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment