in reply to Update is not working properly with Perl DBI Module
I guess you've edited that code since dreadpiratepeter commented since I see $id defined in the foreach loop. I commented on your post to dbi-users (which coincidentally used foreach my $ids but I'll reproduce some of it here.
I don't think we can help you because we don't know what HandleIds() does. I note it may return -1 and causes all of the remaining ids in your batch to be skipped. Some further comments below:
You could prepare your update statement once outside of the loop and use placeholders:
my $update_ids = $dbh->prepare(q/update queue set processed = ? where +id = ?/); # later: $update_ids->execute('T', $ids);
foreach my $id (@ids2process){ $count++; my $ret = HandleIds($id); next if($ret == -1);
We don't know what HandleIds does and it causes all remaining ids to be ignored. This is probably where your problem is.
eval{ my $update_ids = $dbh->prepare("UPDATE queue set p +rocessed = \'T \' where id = $ids"); $updated = $update_ids->execute(); }; if($@) { $log->error("Unable to update record for - id: $i +d, updated: $updated");} else { $log->info("Updated record for - id: $id, updated: $updated");}
What if your code is wrong and you pass an id which does not exist in the table - you do not know the update changed nothing. Check $updated contains 1.
There is something wrong with the above logic due to HandleIds() again. If your select returns 10 rows but HandleIds returns -1 for the last id, next causes the loop to end and your commit did not get called. Much better to do:
Personally I don't like turning off AutoCommit like this I prefer to do:
$dbh->begin_work; #do my work; $dbh->commit;
i.e., put the commit outside the loop then you don't care how many ids were processed, you just commit all the updates.
Did you intend to sleep 5s or 10s when no ids were found - you are doing the latter.
|
---|