Created
October 30, 2013 11:03
-
-
Save ken39arg/7230802 to your computer and use it in GitHub Desktop.
This file contains 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
use common::sense; | |
use DBI; | |
use Test::mysqld; | |
use Data::Dumper; | |
my $mysqld = Test::mysqld->new( | |
my_cnf => { 'skip-networking' => '' } | |
); | |
my $dbh = DBI->connect( $mysqld->dsn ); | |
$dbh->do(q{ | |
create table hoge ( | |
id int not null, | |
name varchar(10) not null | |
) | |
}); | |
$dbh->do(q{ | |
insert into hoge values | |
( 1, 'a'), | |
( 2, 'b'), | |
( 3, 'c') | |
}); | |
my $sth = $dbh->prepare( 'select id, name from hoge' ); | |
$sth->execute; | |
say "fetchall_arrayref([])"; | |
say Dumper $sth->fetchall_arrayref([]); | |
$sth->execute; | |
say "fetchall_arrayref([0])"; | |
say Dumper $sth->fetchall_arrayref([0]); | |
$sth->execute; | |
say "fetchall_arrayref([1])"; | |
say Dumper $sth->fetchall_arrayref([1]); | |
$sth->execute; | |
say "fetchall_arrayref({})"; | |
say Dumper $sth->fetchall_arrayref({}); | |
$sth->execute; | |
say "fetchall_arrayref({id => 1, name => 0})"; | |
say Dumper $sth->fetchall_arrayref({ id => 1, name => 0}); | |
$sth->execute; | |
say "fetchall_hashref('id')"; | |
say Dumper $sth->fetchall_hashref('id'); | |
__END__ | |
fetchall_arrayref([]) | |
$VAR1 = [ | |
[ | |
'1', | |
'a' | |
], | |
[ | |
'2', | |
'b' | |
], | |
[ | |
'3', | |
'c' | |
] | |
]; | |
fetchall_arrayref([0]) | |
$VAR1 = [ | |
[ | |
'1' | |
], | |
[ | |
'2' | |
], | |
[ | |
'3' | |
] | |
]; | |
fetchall_arrayref([1]) | |
$VAR1 = [ | |
[ | |
'a' | |
], | |
[ | |
'b' | |
], | |
[ | |
'c' | |
] | |
]; | |
fetchall_arrayref({}) | |
$VAR1 = [ | |
{ | |
'name' => 'a', | |
'id' => '1' | |
}, | |
{ | |
'name' => 'b', | |
'id' => '2' | |
}, | |
{ | |
'name' => 'c', | |
'id' => '3' | |
} | |
]; | |
fetchall_arrayref({id => 1, name => 0}) | |
$VAR1 = [ | |
{ | |
'name' => 'a', | |
'id' => '1' | |
}, | |
{ | |
'name' => 'b', | |
'id' => '2' | |
}, | |
{ | |
'name' => 'c', | |
'id' => '3' | |
} | |
]; | |
fetchall_hashref('id') | |
$VAR1 = { | |
'1' => { | |
'name' => 'a', | |
'id' => '1' | |
}, | |
'3' => { | |
'name' => 'c', | |
'id' => '3' | |
}, | |
'2' => { | |
'name' => 'b', | |
'id' => '2' | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment