Transaction handling with Oracle DBD
- From: caissark@xxxxxxxxx (RKris)
- Date: Sat, 23 Apr 2005 08:30:56 -0700 (PDT)
Hi, I am getting data corruption when I attempt to run
several processes in parallel when making changes to
two tables.
DBD version 1.16, DBI version 1.48, Linux 2.6, Oracle
9i.
I am trying to select a counter value from table 1,
insert it into table 2 and update table 1 counter
value. This comprises a transaction. I do this 1000
times in a 'for' loop. Even after I clear out the
counter value in table 1 and run the test with two
processes, I am getting a value of 3000 in the
counter!
I included the code below. I moved the connect into
the 'for' loop as I read connect automatically starts
a transaction. Please let me know if I am doing
something wrong! Thanks a lot.
#!/usr/bin/perl
use DBI;
# DB name used by Perl Script
$PS_DBNAME = "DBI:Oracle:xyz";
$DB_USERID="abc";
$DB_PASS="def";
$counterval = 0;
$i = 0;
for($i=0; $i<100; $i++)
{
my $dbh = DBI->connect(PS_DBNAME, $DB_USERID,
$DB_PASS)
or die "Couldn't connect to database: " .
DBI->errstr;
$dbh->begin_work;
eval
{
my $sth = $dbh->prepare('SELECT counter FROM
count_tab')
or die "Couldn't prepare statement: " .
$dbh->errstr;
$sth->execute()
or die "Couldn't execute statement: " .
$sth->errstr;
# there should be only one row
while (@data = $sth->fetchrow_array())
{
$counterval = $data[0];
}
$dbh->do("INSERT INTO data_tab (counter)
VALUES($counterval)")
or die "Couldn't prepare statement: " .
$dbh->errstr;
$counterval = $counterval + 1;
$dbh->do("UPDATE count_tab SET counter =
$counterval")
or die "Couldn't prepare statement: " .
$dbh->errstr;
$sth->finish;
};
if ($@)
{
$dbh->rollback;
}
else
{
$dbh->commit;
}
$dbh->disconnect;
}
exit 0;
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
.
- Follow-Ups:
- Re: Transaction handling with Oracle DBD
- From: chuckfox2
- Re: Transaction handling with Oracle DBD
- From: Michael A Chase
- Re: Transaction handling with Oracle DBD
- Prev by Date: ANNOUNCE: SQL-Routine 0.59 (and Rosetta 0.44)
- Next by Date: Problems building DBI on Windows
- Previous by thread: ANNOUNCE: SQL-Routine 0.59 (and Rosetta 0.44)
- Next by thread: Re: Transaction handling with Oracle DBD
- Index(es):
Relevant Pages
|