even if you know beyond reasonable doubt that there isn't any more
Do you know for sure that will always be the case? It would seem easier to plan for it now and using an array than wait for a year, or five, only to realize that something changed in the design or usage of your code and now more rows are required. If it always returns one row, then looping over it with one row shouldn't cause any problems.
"Invalid cursor state" leads me to believe that there is a problem with performing two executes on a database in quick succession. Have you done any debugging between the two executes to rule out the obvious? For example, closing the connection and re-opening, or adding a sleep, or anything like that? I'm not an expert of using DBD, but I have done similiar things to what you're showing here and haven't run into this issue.
my $sth = $dbh->prepare("INSERT INTO tblserverattributes(hostname,attr
+name,attrvalue) VALUES (?,?,?)");
foreach $attr( keys %{$info{'DATA'}}) {
$sth->execute($hostname,$attr,$info{'DATA'}->{$attr});
}
The code above shows multiple executes on a single prepare, although it's set up a bit differently than what you've got.
I hope that helps.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.