-
Notifications
You must be signed in to change notification settings - Fork 7
Fetch row
Return value of execute
method or select
method is DBIx::Custom::Result object. DBIx::Custom::Result have many ways to fetch rows.
Fetch a row and put it into array reference.
my $row = $result->fetch;
You get the following data.
['Perl', 'Ken']
Generally, fetch
method is used with while loop. If there is no row to fetch, fetch
method return undef
.
while (my $row = $result->fetch) {
my $title = $row->[0];
my $author = $row->[1];
}
Fetch only one row and put it into array reference. Automatically, Statement handle is finished by finish
method of DBI's statement handle after one row is fetched.
my $row = $result->fetch_one;
You get the following data.
['Perl', 'Ken']
Fetch all rows and put it into array of array reference.
my $rows = $result->fetch_all;
You can get the following data.
[
['Perl', 'Ken'],
['Ruby', 'Mike']
]
Fetch a row and put it into hash refernece.
my $row = $result->fetch_hash;
You get the following data.
{title => 'Perl', author => 'Ken'}
Generally, fetch_hash
method is used with while loop. If there is no row to fetch, fetch_hash
method return undef
.
while (my $row = $result->fetch_hash) {
my $title = $row->{title};
my $author = $row->{author};
}
Fetch only one row and put it into hash reference. Automatically, Statement handle is finished by finish
method of DBI's statement handle after one row is fetched.
my $row = $result->fetch_hash_one;
You get the following data.
{title => 'Perl', author => 'Ken'}
one
is alias for fetch_hash_one
to write it shorter.
my $row = $result->one;
Fetch all rows and put it into array of hash reference.
my $rows = $result->fetch_hash_all;
You get the following data.
[
{title => 'Perl', author => 'Ken'},
{title => 'Ruby', author => 'Mike'}
]
all
is alias for fetch_hash_all
to write it shorter.
my $rows = $result->all;