$dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; my $id = 737; my $rows; if (!eval { my $sql = "UPDATE stockhistory SET invoiced = 1 WHERE id = ?"; my $sth = $dbh->prepare($sql); $rows = $sth->execute($id); $dbh->commit(); 1 }) { print "Transaction aborted because $@"; $dbh->rollback(); } die("Record $id not found") if $rows < 1;
Note: Can't check if $rows is true since "0E0" (equal to zero but true) is returned when no rows are affected.
In reply to Re^3: Eval not working
by ikegami
in thread Eval not working
by DooDah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |