Perl日記

日々の知ったことのメモなどです。Perlは最近やってないです。

$sth->fetch は $sth->fetchrow_arrayref のエイリアス

素のDBIメモ。よく忘れてしまうので。
SELECT文をステートメントハンドル使って取得する一番短いメソッド名の fetch() は、fetchrow_arrayref()のエイリアスである。

my $sth = $dbh->prepare($sql);
$sth->execute(@bind_params);
#while (my $array_ref = $sth->fetchrow_arrayref) {
# alias is
while (my $array_ref = $sth->fetch) {
  ...
}


そしてこの最も短いフェッチメソッド名のメソッドが、フェッチ系最速らしい。

$ perldoc DBI
...
"fetchrow_arrayref"

...This is the fastest way to fetch data, particularly if used with "$sth->bind_columns".
これはデータを取得する最速の方法であり、"$sth->bind_columns"との併用で特に効く。


でもたとえタイプ多くなっても「fetch()」より「fetchrow_array()」って書くほうが親切だよね。