Front page | perl.dbi.users |
Postings from October 2011
Re: Oracle and Two Phase commit with Perl?
Thread Previous
|
Thread Next
From:
Eirik Toft
Date:
October 7, 2011 01:50
Subject:
Re: Oracle and Two Phase commit with Perl?
Message ID:
f8ccbc49-8a57-4761-a802-1c7c12735ad4@m37g2000yqc.googlegroups.com
On Sep 13, 11:16 am, Mark.Bo...@proquest.com ("Bobak, Mark") wrote:
> Does anyone have any experience w/ doing two-phase commit across connections to two different databases from the same Perl program? (To guarantee that either both or neither transaction is committed, for consistency.)
>
> Any thoughts, ideas or suggestions would be appreciated.
>
> Thanks,
>
> -Mark
Well, assuming you have AutoCommit turned off, why not....
$dbh1 = DBI->connect("dbi:Oracle:$db1", $user, $passwd,AutoCommit=>0);
$dbh2 = DBI->connect("dbi:Oracle:$db2", $user, $passwd,AutoCommit=>0);
$sth1 = $dbh1->prepare("INSERT INTO foo (val1,val2) VALUES (?,?)");
$sth2 = $dbh2->prepare("INSERT INTO bar (val1,val2) VALUES (?,?)");
unless ($sth1->execute("this","that") && $sth2-
>execute("this","that")) {
$dbh1->rollback;
$dbh2->rollback;
} else {
$dbh1->commit;
$dbh2->commit;
}
Thread Previous
|
Thread Next