Re: [CDBI] Re: Class::DBI with multiple db connections

"Sk8board Kid" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Message-ID <[email protected]>
On 11/01/07, Perrin Harkins <[email protected]> wrote:
> On Thu, 2007-01-11 at 13:58 -0500, Edward J. Sabol wrote:
> > > [Am] I missing something here?
> >
> > Class::DBI forces the Ima::DBI database connection name to be "Main". This
> > was an intentional design decision to simplify the API.
>
> Yes.  To get multiple database support for my project, I set them all up
> with set_db() calls (to the Ima::DBI::set_db, not the Class::DBI version
> that forces the db_name) and override db_Main() in my base class to call
> the correct database handle method for the database I want.  The method
> is called 'db_' . $db_name.
>
> > If you do override this design decision to enable multiple database
> > connections, I think you will need to turn off the object index
>
> Yes, you will.
>
> - Perrin
>
>
>

Thanks to both you guys help on this.

i'm having problems overriding Class::DBI's set_db method as follows:

package mysubclass;
use base qw(Class::DBI);
$Class::DBI::Weaken_Is_Available = 0;   #disable the object index for
the multiple db connections

{
    my $new_set_db = sub {
        my ($class, $db_name, $data_source, $user, $password, $attr) = @_;
        # 'dbi:Pg:dbname=foo' we want 'Pg'. I think this is enough.
        my ($driver) = $data_source =~ /^dbi:(\w+)/i;
        $class->__driver($driver);
        #$class->SUPER::set_db('Main', $data_source, $user, $password, $attr);
        print STDERR "using new set_db with: $class, $db_name\n";
        $class->SUPER::set_db($db_name, $data_source, $user, $password, $attr);
    };
    *Class::DBI::set_db = $new_set_db;
}

but this is method is called in the context of "mysubclass", which
means when you use the "SUPER" method this will give you
Class::DBI::set_db not Ima::DBI::set_db

I thought in the code above i was altering the Class::DBI::set_db method with:

*Class::DBI::set_db = $new_set_db;

so when $class->SUPER::set_db is used inside it it would call
effectively call Ima::DBI::set_db.

I suppose i want to do something like $class->SUPER->SUPER::set_db but
i'm not sure how to do that in perl

Can anyone help here?
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.