1レコードづつ取得する
selectrow_array => 配列
my @ret = $dbh->selectrow_array(
'select user_id, reg_date, nickname from user_data');
is_deeply \@ret, [ 10001, 1297573789, 'はるく' ];
selectrow_arrayref => 配列リファレンス
my $ret = $dbh->selectrow_arrayref(
'select user_id, reg_date, nickname from user_data');
is_deeply $ret, [ 10001, 1297573789, 'はるく' ];
selectrow_arrayref => ハッシュリファレンス
my $ret = $dbh->selectrow_arrayref(
'select user_id, reg_date, nickname from user_data');
is_deeply $ret, +{ user_id => 10001, reg_date => 1297573789, nickname => 'はるく' };
複数レコード取得
selectall_arrayref => 配列リファレンス
my $ret = $dbh->selectall_arrayref('select user_id, reg_date, nickname from user_data');
is_deeply $ret, [[10001, 1234567, 'はるく'], [10002, 1234567, 'ひかり']];
selectall_arrayref (Slice[]) => 配列リファレンス
my $ret = $dbh->selectall_arrayref('select user_id, reg_date, nickname from user_data', +{ Slice => []});
is_deeply $ret, [[10001, 1234567, 'はるく'], [10002, 1234567, 'ひかり']];
selectall_arrayref (Slice+{}) => ハッシュリファレンス
my $ret = $dbh->selectall_arrayref('select user_id, reg_date, nickname from user_data', +{ Slice => +{}});
is_deeply $ret, [ +{ user_id => 10001, reg_date => 1234567, nickname => 'はるく'}, ... ];
selectall_arrayref (Columns) => ハッシュリファレンス
my $ret = $dbh->selectall_arrayref('select user_id, reg_date, nickname from user_data', +{ Columns +{}});
is_deeply $ret, [ +{ user_id => 10001, reg_date => 1234567, nickname => 'はるく'}, ... ];
selectall_hashref => ハッシュリファレンス
my $ret = $dbh->selectall_hashref($sql, 1); # user_idでも一緒
is_deeply $ret => +{
10001 => +{ user_id => 10001, reg_date => 12345, nickname="はるく"},
10002 => +{ user_id => 10002, reg_date => 12346, nickname="ひかり"},
}
my $ret = $dbh->selectall_hashref($sql, [1, 2]); # qw/user_id reg_date/でも一緒
is_deeply $ret => +{
10001 => +{ 12345 => +{ user_id => 10001, reg_date => 12345, nickname="はるく"} },
10002 => +{ 12346 => +{ user_id => 10002, reg_date => 12346, nickname="ひかり"} },
}
0 件のコメント:
コメントを投稿