Created
November 14, 2011 13:02
-
-
Save nihen/1363909 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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