Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

custom $dbh with Rose::DB?

by mreece (Friar)
on Nov 05, 2006 at 02:14 UTC ( #582279=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Why did DBIC overtake CDBI?
in thread Why did DBIC overtake CDBI?

i'm commenting a bit late, so maybe i won't get an answer, but how does one "shove [an existing $dbh] into a Rose::DB object"?

i've been reading the docs and tutorial for Rose::DB but don't see how to stuff a $dbh into it, only how to get one out.


Comment on custom $dbh with Rose::DB?
Select or Download Code
Replies are listed 'Best First'.
Re: custom $dbh with Rose::DB?
by Anonymous Monk on Nov 05, 2006 at 09:32 UTC
      Right. Just make sure that the driver() of the $db is the same as the driver of the $dbh (i.e., don't try to put a Postgres $dbh into a Rose::DB object whose driver is "mysql")
        using $db->dbh as a setter isn't documented, but this approach sounds reasonable if i can get it to work.

        this is my test script so far, which is not working:

        use DBI; use Rose::DB; my $dbh = DBI->connect( 'DBI:mysql:database=mydb', 'user', 'pass' ); my $rdb = Rose::DB->new( driver => "mysql" ); $rdb->dbh( $dbh ); print "still here\n";
        produces:
        No database information found for domain 'default' and type 'default' at rdttest.pl line 6
        
        what do i do here instead if i don't want to do the register_db stuff(or can't, because in the non-simplified case i don't have the DSN, only a $dbh that was exported from elsewhere) ?

        update:

        it looks like this works, clunky as it seems:

        use base qw( Rose::DB ); __PACKAGE__->use_private_registry; __PACKAGE__->register_db( driver => 'mysql', database => 'fake', host => 'fake', username => 'fake', password => 'fake' ); package My::RDBO::User; use base qw( Rose::DB::Object ); use DBI; __PACKAGE__->meta->setup( table => 'user', columns => [qw( id username password email name )], pk_columns => 'id', unique_key => 'username', ); sub init_db { my $dbh = DBI->connect( 'DBI:mysql:database=mydb', 'user', 'pass' +); my $rdb = My::RDB->new; $rdb->dbh($dbh); return $rdb; } package main; my $u = My::RDBO::User->new(id => 1); $u->load; print("$_ => ", $u->$_, "\n") foreach $u->meta->columns;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (20)
As of 2015-07-29 16:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (265 votes), past polls