I'm always cautious of slurping (files or result sets) like that.
Depending on the size of your result set, that can wind up being a huge
array, which of course is then held in memory until it's discarded, or
until the program ends. If it's only a few thousand rows, go for it, but
if it's a few hundred thousand, I'd rethink it.
Also, if you are going to slurp the whole thing into an array, consider
$sth->fetchall_arrayref() as it allows more flexibility such as doing your
execute with bind parameters.
____________________________
Jeff Seger
Fairchild Semiconductor
[EMAIL PROTECTED]
____________________________
Tom Mornini <[EMAIL PROTECTED]>
02/25/2005 12:28 PM
To: Perl - DBI users <[email protected]>
cc:
Subject: Re: how to fetch all records
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Feb 25, 2005, at 9:22 AM, Tiffany Thang wrote:
> Is there another way of fetching all table records in one statement
> without going through a loop?
>
> What I have now is as follows:
> while (@eachrec=$sth->fetchrow_array) {
> do whatever;
> }
>
> I want to retrieve all the records into an array first and process it
> later on. What would be the best way of doing it?
from perldoc DBI...
$ary_ref = $dbh->selectall_arrayref($statement);
Looks like selectall_arrayref is your cup of tea.
- --
- -- Tom Mornini
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFCH2BYzaKkuvKwKvcRApIcAKCBpOPUl6erXlmwnB5irQ9lK3eTbgCfafSw
D62q6T95L+/udISb63eJo8s=
=bOUZ
-----END PGP SIGNATURE-----