Re: Oracle and Two Phase commit with Perl?

Eirik Toft <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Organization http://groups.google.com
Message-ID <f8ccbc49-8a57-4761-a802-1c7c12735ad4@m37g2000yqc.googlegroups.com>
On Sep 13, 11:16 am, [email protected] ("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;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.