PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at peppler dot org>
Subject: Re: Can transactions span databases?
Date: Nov 8 2001 10:07PM

Dave Aiello writes:
 > A project at one of my consulting clients has code written using Sybase::DBlib 
 > that attempts to operate on two separate databases through a single handle 
 > under explicit transaction conditions.  Some of the code I have seen is written 
 > as follows:
 > 
 > $dbh->dbuse("database1");
 > $dbh->dbcmd("begin transaction");
 > $dbh->dbsqlexec;
 > 
 > $dbh->dbuse("database2");
 > $dbh->dbcmd("begin transaction");
 > $dbh->dbsqlexec;

This doesn't make any sense. The current database is completely
irrelevant to the transaction state, as you can just as easily stay in
"master" and perform updates on any other database with the
db.owner.table syntax.

 > 1) Is the scope of an explicit transaction the data server or the database?

The data server (i.e. the *connection*).

 > 2) Does nesting transactions in this fashion have any benefit in a Sybperl 
 > application where all operations are taking place through a single database 
 > handle?  Or, is this more trouble than its worth?

No benefit, as far as I can see, but no real harm either, as long as
the number of commits and/or rollbacks match the number of begin tran
statements.

I *do* use nested transactions, but that's usually in stored
procedures when I want the operations for each proc to be atomic. 

Michael
-- 
Michael Peppler - Data Migrations Inc. - http://www.mbay.net/~mpeppler
mpeppler@peppler.org - mpeppler@mbay.net
International Sybase User Group - http://www.isug.com