Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Dynamic DSN w/ Class::DBI Example

by perrin (Chancellor)
on Apr 23, 2004 at 21:27 UTC ( #347755=note: print w/replies, xml ) Need Help??


in reply to Dynamic DSN w/ Class::DBI Example

It looks to me like the only reason your code didn't work is that you are calling import the first time with no parameters. In general, import() is a lousy place to put anything. Why not just call Stuff->set_db() directly?

Replies are listed 'Best First'.
Re: Re: Dynamic DSN w/ Class::DBI Example
by gryphon (Abbot) on Apr 23, 2004 at 22:11 UTC

    Pardon my stupidity, but do you mean like this:

    package Stuff::DBI; use base 'Class::DBI::BaseDSN'; package Stuff::Item; use base 'Stuff::DBI'; __PACKAGE__->set_up_table('item'); __PACKAGE__->has_a(categoryId => 'Stuff::Category'); package Stuff::Category; use base 'Stuff::DBI'; __PACKAGE__->set_up_table('category'); __PACKAGE__->has_a(departmentId => 'Stuff::Department'); package Stuff::Department; use base 'Stuff::DBI'; __PACKAGE__->set_up_table('department'); package main; Stuff::DBI->set_db('Main', 'dbi:mysql:dbname', 'gryphon', 'password'); my $item = Stuff::Item->retrieve(1); print $item->name, "\n";

    When I run this, I get a "Can't locate object method 'set_up_table' via package 'Stuff::Item' blah blah" when I run this. What am I doing wrong?

    gryphon
    code('Perl') || die;

      Get rid of that BaseDSN stuff. You have to subclass Class::DBI::MySQL, like you were before, to get the set_up_table method.

        Switching to use base 'Class::DBI::mysql' results in an error of "Can't locate object method 'db_Main' via package 'Stuff::Item' at blah, blah". I think I'm not smart enough to use Class::DBI. Do you have any working example code you can share with me? Thanks.

        gryphon
        code('Perl') || die;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://347755]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-02-27 04:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?