Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i have the following code
my $teamposition; my $thisteam; my $thisscore; for $_ ( 1..13){ $thisteam = $teams{"team$_"}; $thisscore = $scores{"score$_"}; $teamposition = $_; my $sth1 = $dbh->do("UPDATE trees SET department = \'$thisteam\' WHERE + sport = \'$sport\' AND round = \'$teamposition\'")|| die "Can't exec +ute SQl update 1"; my $sth2 = $dbh->do("UPDATE trees SET score = \'$thisscore\' WHERE spo +rt = \'$sport\' AND round = \'$teamposition\'")|| die "Can't execute +SQl update 2"; my $sth3 = $dbh->do("UPDATE results SET score =\'$thisscore\' WHERE ye +ar = \'$thisyear\' AND sport =\'$sport\' AND department = \'$thisteam +\'")|| die "Can't execute SQl update 3"; }
when i run it with warnings it gives no errors but does not update the database i have printed out the database statements as print statements and it seems to be getting all the correct values in the loop so the hashes it is using seem to be set up right but when i check the database nothing has changed any ideas?? i tried it with and without the "my" statements on the dbh commands.

Replies are listed 'Best First'.
Re: more and more dbi issues
by thabenksta (Pilgrim) on Apr 04, 2001 at 23:29 UTC

    Try using print $dbh->errstr; that might give you some more info

    my $name = 'Ben Kittrell'; $name=~s/^(.+)\s(.).+$/\L$1$2/g; my $nick = 'tha' . $name . 'sta';
Re: more and more dbi issues
by sutch (Curate) on Apr 04, 2001 at 23:09 UTC
    One idea: could autocommit possibly be off? If so, you will need $dbh->commit to commit the changes to the database.

    Update: fixed a typo.

      am i allowed to have these statements in a loop or is this against dbase rules. does it compromise dbi standards to have 3 updates running 13 times in a loop??? is there protection against this. if this message doesn't make sense i've been coding 4 10hrs flat and am slowly shutting down. i hope u get the gist.

        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