[CDBI] Using Class::DBI across multiple databases on one server (Sybase)

Matt S Trout dbix-class at trout.me.uk
Thu Aug 25 06:47:13 BST 2005

On Tue, Aug 23, 2005 at 06:54:59AM -0400, IvorW wrote:
> I have an issue where I am needing a transaction to update across multiple databases. I can do this in SQL using the database..table notation. 
> I have an existing CDBI suite of classes that use a separate database connection for each database. But this doesn't work with transactions on both connections owing to the way Sybase handles chained transactions. If they were sharing one channel, this would give me what I want.
> I have no choice over the fact that the tables are in two different databases. Here is an illustration of what I want to do.
> package DB::Connect;
> use base qw(Class::DBI);
> __PACKAGE__->set_db("dbi:Sybase:server=SYB_PROD;database=SALESDB",$user,$passwd);
> package DB::Order;
> use base qw(DB::Connect);
> __PACKAGE__->set_up_table("ORDER");
> __PACKAGE__->has_a( account => 'DB::Account');
> package DB::Account;
> use base qw(DB::Connect);
> __PACKAGE__->set_up_table("REFERENCEDB..ACCOUNT");
> ...
> It seems that table and set_up_table don't support "database.schema.table" syntax unless I am missing something.

set_up_table isn't a part of Class::DBI; it's something provided by a number
of the db-specific subclasses but is no part of Class::DBI itself and it's
probably what's breaking here.

I suspect if you just used ->table and called ->columns yourself, it
would work. Try it, and use DBI->trace(1) (or a higher value) to see what
SQL Class::DBI is generating if it doesn't work. If that doesn't help,
reply with the explicit classes and the trace and I'm sure somebody on
here can have a go.

     Matt S Trout        Specialists in OSS web application development and
  Technical Director    UNIX/Linux systems architecture and automation. Mail
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +

More information about the ClassDBI mailing list