Re: Several databases from the same script
[prev]
[thread]
[next]
[Date index for 2004/06/03]
I'm using Pg and another problem is with schemas.
I try to solve more db connections for same layout with dynamic class
generation.
package My::Class::DBI;
...
package My::Class::DBI::Employee;
...
package My::Class::DBI::Employee::Address;
...
package main;
$db_one = new DBConnection
(connection => [$dbdns, $dbusr, $dbpwd, { params }],
schema => $schema,
layout => 'My::Class::DBI',
);
It creates reference eq. HASH(0xFFEEDDCC) and new package
DBConnection_HASH_0xFFEEDDCC::My::Class::DBI, with @ISA sets
to ['DBConnection', 'My::Class::DBI'] and method db_Main
(I'm using Symbol::Table) and after successfull connection, it calls
db_Main->do ('set search_path = ' . $schema), if schema is defiend.
and usage:
$db_one->Employee->create (...);
... AUTOLOAD method, create package and method Employee
$db_one->Employee->Address->retrieve_all;
... same behaviour
It works nice, but I lost all Class::DBI functionality, where fixed
package name is used (has_a, has_many, ...)
Maybe more troubles should be found if this is used with more db drivers.
Brano.