If autocommit is not on by default or turned on when you first connect and get your $dbh you will need to commit as in:
$dbh->commit() unless $dbh->{AutoCommit};
my @a=qw(random brilliant braindead); print $a[rand(@a)]; | [reply] [d/l] |
Thanks! That was what I needed...
| [reply] |
You don't mention whether you have AutoCommit set, but this is a common error when it's not. You might want to try something like this, assuming the data you want to update are arrayrefs in @data:
$dbh->{RaiseError} = 1; # if not already
my $sql = "UPDATE $table SET X = ? WHERE Y = ?";
my $sth = $dbh->prepare( $sql );
eval {
foreach my $d ( @data ) {
$sth->execute( $d->[0], $d->[1] );
}
};
if ( $@ ) {
print "Caught error: $@\nRolling back.\n";
$dbh->rollback;
}
else {
$dbh->commit;
}
Chris
M-x auto-bs-mode | [reply] [d/l] |
You've got the answer of "if AutoCommit is turned off...". So here's how to turn AutoCommit on (which will automatically commit all inserts/updates/deletes).
$dbh = DBI->connect($data_source, $user, $pass, { AutoCommit => 1 } );
1 is on, 0 is off.
This is from Programming the Perl DBI from O'Reilly. It can also be found in perldoc DBI, or here.
UPDATE: I forgot to mention, this is considered a bad thing to do these days. But, given caution, it can be a nice feature to use on purpose. Unfortunately, the system I'm on has AutoCommit turned on by default, and that's bitten me a couple of times... :-(
MungeMeister | [reply] [d/l] [select] |
| [reply] |
You either must set autocommit on, or do a $dbh->commit(); | [reply] |