Skip to content

Instantly share code, notes, and snippets.

@nihen
Created November 14, 2011 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nihen/1363909 to your computer and use it in GitHub Desktop.
Save nihen/1363909 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use DBI;
use Test::More;
my $CONNECT_INFO = {
dsn => 'dbi:mysql:database=dbibench;host=localhost;mysql_server_prepare=1',
username => 'guest',
password => 'guest',
connect_options => {
mysql_enable_utf8 => 1,
},
};
my $dbh = DBI->connect($CONNECT_INFO->{dsn}, $CONNECT_INFO->{username}, $CONNECT_INFO->{password}, $CONNECT_INFO->{connect_options});
if ( fork ) {
wait;
$dbh = $dbh->clone; # 子でdisconnectしちゃったのでclone
my $row = $dbh->selectrow_hashref('SELECT id, name FROM users where id = ? LIMIT 1', undef, 1);
is_deeply $row => {id => 1, name => 'Masahiro Chiba'};
done_testing;
}
else {
$dbh->{InactiveDestroy} = 1;
$dbh->disconnect;
my $new_dbh = $dbh->clone({InactiveDestroy => 0});
undef $dbh;
$new_dbh->do('DROP TABLE IF EXISTS users');
$new_dbh->do('CREATE TABLE users (id INT,name VARCHAR(255), PRIMARY KEY (id)) ENGINE=INNODB');
$new_dbh->do('INSERT INTO users (id, name) values(?, ?)', undef, 1, 'Masahiro Chiba');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment