Home: Perl Programming Help: DBI:
update table in oracle db



ms10380
Novice

Feb 15, 2010, 7:53 AM


Views: 8615
update table in oracle db

I have the function below that is supposed to update an existing table. I do not get any errors when I execute the script, however when I go back and try to verify that the update was successful, the entry is not in the table. I am connecting to an oracle database using the DBI module.

Thanks



sub update_cmds {

my $name = shift;

my $value = shift;

my $sth = undef;

my $sql_statement = "UPDATE SET_CMDS SET SET_VALUES=\'$value\', LAST_ACK_TIME=NULL WHERE SET_NAME=\'$name\' ";

unless ($sth=$dbh->prepare($sql_statement)) {

$dbh->rollback;

log_off_oracle($dbh);

exit;

}

unless ($sth->execute()) {

$dbh->rollback;

log_off_oracle($dbh);

exit;

}

}


Nila
User


Mar 8, 2010, 1:42 AM


Views: 8137
Re: [ms10380] update table in oracle db

Try to check your AutoCommit property in your code.


Code
my $dbh = DBI->connect( "dbi:Oracle:$db", $username, $passwd ) ||           die( $DBI::errstr . "\n" ); 
$dbh->{AutoCommit} = 0;


AutoCommit: when set to 1, DBI issues a commit after each successful SQL statement. This is very dangerous and on by default. Setting it to 0 is a good idea.
If you set it to '0' then you need to commit every successful SQL statement.


(This post was edited by Nila on Mar 9, 2010, 5:18 AM)