"be consistent" | |
PerlMonks |
Re^2: Why does DBI prepare break my loop?by McA (Priest) |
on Jul 07, 2014 at 12:31 UTC ( [id://1092565]=note: print w/replies, xml ) | Need Help?? |
Hi perlfan, sorry, but I have to disagree with your general advice not to use prepare and execute. IMHO this use case is exactly the one to use prepared statement handles. It was just abused or misunderstood by aditya1977. I would rewrite the snippet to the following ona rush:
The two SQL statements are prepared and checked early. The statement for the update which is often used in the loop is prepared exactly once and used many times. This solution has another advantage: On a database which supports server side result set cursors you really iterate over the result set row by row. You don't pull the whole result set to the DB client. I also replaced the switch clause by a hash lookup which should be faster. More readable is it anyway, IMHO. Regards
In Section
Seekers of Perl Wisdom
|
|