Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: [DBIx::Class] Can I extract $dbhandle from schema?

by LTjake (Prior)
on Aug 21, 2007 at 11:04 UTC ( [id://634053]=note: print w/replies, xml ) Need Help??


in reply to [DBIx::Class] Can I extract $dbhandle from schema?

I belive you can access the $dbh via the Storage class:

my $dbh = $self->schema->storage->dbh;

--
"Go up to the next female stranger you see and tell her that her "body is a wonderland."
My hypothesis is that she’ll be too busy laughing at you to even bother slapping you.
" (src)

Replies are listed 'Best First'.
Re^2: [DBIx::Class] Can I extract $dbhandle from schema?
by dreel (Sexton) on Aug 21, 2007 at 12:41 UTC
    Great! 10x! It's working! DBIx creates connection at every query? Or it uses sheared dbhandle? May be you read it before me )
      DBIx::Class re-uses existing connections. It checks if connections are still open: if so they are re-used otherwise it reconnects.

      Please note DBIx::Class is not sharing connections: every my $schema = My::DB->connect('dbi:mysql:DB', 'user', 'secret_password'); will remain separate from every other connection, but every query within an individual $schema will re-use the same connection as long as it is still open. Connections only get closed when the script finishes or when explicitly closed ($schema->disconnect;) or when timed-out server-side.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        Wow, threads can come around after a long rest. :P

        I was having a little trouble comparing two databases with a single DBIC schema today for exactly the reason you cite: cached connection. I figured I'd post the way around that particular hobgoblin. This might be considered a bug… New connection_info should reset the connection, I think.

        my @configuration_db_one = ...; my @configuration_db_two = ...; my $schema_one = MyDBIC::Schema->connect( @configuration_db_one ); my $schema_two = MyDBIC::Schema->connect( @configuration_db_two ); # ^^^ Wrong, connection from $schema_one is reused despite new config. my $schema_one = MyDBIC::Schema->connect( @configuration_db_one ); $schema_one->storage->disconnect; my $schema_two = MyDBIC::Schema->connect( @configuration_db_two ); # ^^^ Right, $schema_one will reconnect with its own info when used.
        Sorry, thought I was logged in. This applies to the post above. I also tried using Apache::DBI and it didn't seem to work and I have since read this is not recommended either. Is that not a good solution?
        I am using DBIx::Class and when I look at the processlist (mysql) all the connections are in state of sleep. I am using mod_perl so the scripts should be staying alive. Is it recommended to call disconnect each time or to try and re-use the existing connection?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (8)
As of 2024-04-19 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found