Re: Stupid newbie question?
- From: martin.evans@xxxxxxxxxxxx (Martin J. Evans)
- Date: Fri, 23 Jun 2006 21:02:29 +0100
Ben wrote:
Hey guys, I'm very green at DBI stuff, so maybe this is a stupid question. But after going through the DBI man page and searching the web for a couple hours, I can't find the answer. All I'm looking to do is to walk the result set from a select statement more than once. Every example I can find follows the form:So long as you are not bothered about the result-set changing between
prepare, execute, fetch, fetch, fetch, ..., finish
What I would *like* to be able to do is walk the entire result set, and then, once I get to the end, reset the statement handle to point the fetch calls back to the top, and then walk them again. That seems so simple. Is there really no "reset" command? Do I actually have to execute the select again?
the first and second pass do:
$rs = $dbh->selectall_arrayref($sql, undef, $p1, $p2 ...)
or (selectall_hashref).
then:
while (my $row = @{$rs}) {
print $row->[0]; # first column, n'th row
}
Make sure RaiseError is on or check for $dbh->err;
If you are bothered about a change run selectall_arrayref twice.
However, I'd question why you need to process the result-set
twice IF you are not bothered about it changing. If the result-set
can change then you are talking cursors that pick up changes
and that is very db specific.
Martin
.
- References:
- Stupid newbie question?
- From: Ben
- Stupid newbie question?
- Prev by Date: RE: Stupid newbie question?
- Next by Date: Re: DBI/DBD::DB2
- Previous by thread: Stupid newbie question?
- Next by thread: Re: Stupid newbie question?
- Index(es):
Relevant Pages
|
|