Samn has asked for the wisdom of the Perl Monks concerning the following question:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Looping with DBI
by dws (Chancellor) on Jun 30, 2002 at 04:39 UTC | |
Or, it might be because you're overwriting $sth when you prepare a new query inside the loop.
| [reply] [d/l] |
[reply] | |
Re: Looping with DBI
by gav^ (Curate) on Jun 30, 2002 at 05:09 UTC | |
You should look through the DBI docs for information on binding variables, it's bother faster and (in this case) more readable. gav^ | [reply] [d/l] |
by Kanji (Parson) on Jun 30, 2002 at 11:27 UTC | |
If you're going to go through the trouble of using bind variables, why not move the second prepare outside the while? That way you avoid needless re-prepareing of the same statement on every iteration of the loop...
--k. | [reply] [d/l] |
Re: Looping with DBI
by Aristotle (Chancellor) on Jun 30, 2002 at 10:54 UTC | |
(Or, if you're using a reasonably recent version of Perl, use warnings; rather than the -w.) In your case f.ex, the following code:while rather not recommendable as a casual reader might confuse the inner and outer $sth with one another, would at least have worked. Makeshifts last the longest. | [reply] [d/l] [select] |
Re: Looping with DBI
by Ryszard (Priest) on Jun 30, 2002 at 09:57 UTC | |
To the orig. question, I personally prefer to use fetchrow_arrayref() then push a copy of it onto a return array. It works out kind a like a 2D array of columns in the "inside" array and rows on the "outside" array. It makes it nice and easy to process. BTW, you have to make a copy of the container, as it is re-used for each row returned: should do it.. :-) HTH! | [reply] [d/l] [select] |
Re: Looping with DBI
by rdfield (Priest) on Jun 30, 2002 at 17:45 UTC | |
it'll work faster, and there's no bind params or overwriting the statement handle to worry about. note: the (+) is the outer join operator in Oracle, change it to whatever's required in the RDBMS you use rdfield | [reply] [d/l] |