FAQ
I find a common operation is to execute a statement that you expect to return
at most one row and then fetch that row. I've found it convenient to combine
these two calls into one:

$res = $sth->executerow_foo(@bind);

equivalent to:

$sth->execute(@bind);
$res = $sth->fetchrow_foo();
$sth->finish;

Ideally, after getting the first row, it could additionally check if there are
more rows to fetch and complain if there are. It could also return a
different value to indicate error condition, or just raise an error.

I've found such a function useful and often define it myself. I realize it's
similar to $dbh->selectrow_foo($sth, undef, @bind), but with better-looking
syntax, more checking, and also finishes the current execution. If other
people would find it useful, it might be a nice addition to DBI.

Thanks,
:-Dylan

Search Discussions

  • Paul Boutros at Nov 16, 2003 at 3:26 pm
    It sounds like you are describing two existing methods:
    selectrow_arrayref
    selectrow_hashref

    which are in the perldocs under handle-methods. See:

    http://search.cpan.org/~timb/DBI-1.38/DBI.pm#Database_Handle_Methods

    Paul
    -----Original Message-----
    From: Dylan Alex Simon
    Sent: Sunday, November 16, 2003 4:00 AM
    To: dbi-users@perl.org
    Subject: new function suggestion: $sth->execute + fetch single row


    I find a common operation is to execute a statement that you
    expect to return
    at most one row and then fetch that row. I've found it
    convenient to combine
    these two calls into one:

    $res = $sth->executerow_foo(@bind);

    equivalent to:

    $sth->execute(@bind);
    $res = $sth->fetchrow_foo();
    $sth->finish;

    Ideally, after getting the first row, it could additionally check
    if there are
    more rows to fetch and complain if there are. It could also return a
    different value to indicate error condition, or just raise an error.

    I've found such a function useful and often define it myself. I
    realize it's
    similar to $dbh->selectrow_foo($sth, undef, @bind), but with
    better-looking
    syntax, more checking, and also finishes the current execution. If other
    people would find it useful, it might be a nice addition to DBI.

    Thanks,
    :-Dylan

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbi-users @
categoriesperl
postedNov 16, '03 at 9:00a
activeNov 16, '03 at 3:26p
posts2
users2
websitedbi.perl.org

2 users in discussion

Paul Boutros: 1 post Dylan Alex Simon: 1 post

People

Translate

site design / logo © 2022 Grokbase