Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Help with fetchall_arrayref

by mwp (Hermit)
on May 16, 2001 at 05:46 UTC ( [id://80785]=note: print w/replies, xml ) Need Help??


in reply to Help with fetchall_arrayref

First question: You're close, but it looks like you're trying to loop through the recordset twice. You can keep your current semantics by doing something like this:

while (my $row = $sth->fetchrow_arrayref) { print @$row, "\n"; }

You don't need to verify that $row is a reference; fetchrow_arrayref will always return one. If you want to validate the data in each row, you'll have to do something like this:

OUTER: while (my $row = $sth->fetchrow_arrayref) { INNER: foreach my $column (@$row) { next OUTER if($column eq undef); } print @$row, "\n"; }

Which will skip any row with a blank column. (Not all blank columns, ANY blank column.)

Second question: fetchrow and fetchall only affect how you layout your program, not how the database is called. In both circumstances, the entire recordset is loaded into memory. fetchrow retrieves one row at a time (from memory), and fetchall retrieves them all. I think! You'll have to check up on that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://80785]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-18 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found