According to House Bill 17289, in preparation, programming loops will no longer be able to nest beyond two levels deep. It looks like this sucker's going to become law, so you'd better hope that your code gets grandfathered in.
In other news ... DBI won't prevent you from shooting yourself in the foot -- if you issue updates upon updates of the same row, it won't complain. Your DBMS might, on the other hand. It's up to you to ensure that your code's correct, here as nearly everywhere else.
Philosophy can be made out of anything. Or less -- Jerry A. Fodor
| [reply] |
i took it out of the loop i removed the and statements and it works
is there anything wrong with the and statements
it works in sql manually
i cant get it to work if there's even 1 and statement.
i know someone who got it to work on the same system here with one and statement
any ideas??
| [reply] |
I see nothing wrong with your SQL as written, though I will say this again:
Use placeholders. They will prevent certain nasty kinds of errors from cropping up; one thing that might cause problems with your code as written is that IF there any quotes or other zany things in your data, that will result in the SQL string not being well-formed; if you use placeholders, these issues will be dealt with automatically. All this adds up to : use placeholders
OK, with that out of the way ... check to see whether you've issued a commit to the database (this will have no effect if you're using a DB without commit and rollback, like vanilla MySQL), as sutch recommended. If the statements execute without error but nothing happens in the database, that's one place to look. Also, as thabenskta mentioned, you should always return the value of $dbh->errstr when a call to the database fails. So put those in, they'll help with debugging!
Now, as to the method: whatdo is good for one-off things, but it forces you to prepare each statement each time through the loop. That's inefficient: prepare once, execute many times! So go with the normal prepare, bind, execute cycle:
my $sth1 = $db->prepare(q{
UPDATE trees
SET
department = ?
WHERE
sport = ?
AND
round = ?
})
or die "Can't prepare first statement: ". $dbh->errstr() .
+ "\n";
# and so with $sth2 and $sth3
# execution time
for my $i (1..13) {
# I'd suggest reworking this data structure too, but
# I'll work with what you have
# smaller sermon : initialize the variables that are
# expected to change on each step through the loop
# with my *** inside the loop ***
# that way, you get a fresh copy of the variable each time
# through without potentially having old values intrude
my $team = $teams{"team$i"};
my $score = $scores{"score$i'};
$sth1->execute ($team, $sport, $i)
or die "Execution of first update failed: ". $dbh->errstr() ."
+\n";
$sth2->execute( #blah blah...
}
HTH.
Philosophy can be made out of anything. Or less -- Jerry A. Fodor | [reply] [d/l] [select] |