Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: DBIx::Class connection

by Your Mother (Archbishop)
on Jan 02, 2011 at 23:46 UTC ( [id://880105]=note: print w/replies, xml ) Need Help??


in reply to DBIx::Class connection

You could pass a sub instead of plain connection variable and do whatever you want there.

$schema= My::Schema->connect(sub{ # Prep/config load. my $dbh = DBI->connect... # Do your logging. return $dbh; }

I'm not sure it's the easiest/sanest way. It feels like the wrong place to do it to me. Perhaps you want some permutation of DBI->trace instead.

Replies are listed 'Best First'.
Re^2: DBIx::Class connection
by tinita (Parson) on Jan 03, 2011 at 01:11 UTC
    yes, as far as I remember it's not recommended to do the DBI connect yourself since DBIC cares about reconnecting itself when the connection has gone away, so tracing in DBI is probably the best way.
Re^2: DBIx::Class connection
by morgon (Priest) on Jan 03, 2011 at 01:22 UTC
    As always many thanks for sharing your knowledge, mother.

    And to log the SQL that is generated I could simply subclass DBIx::Class::Storage::Statistics and set it as debugobj I guess?

    And while I am at it (and don't want to experiment when I can simply ask mother):

    I don't quite understand what happens when the database-connection is lost (I am using mysql).

    I understand DBIx::Class will try to reconnect automatically - does that mean it will try once and give up if it fails to reconnect or what exactly happens?

    How could I trace (assumed I cared) when a connection is lost and re-established?

    Many thanks.

      Look at DBIx::Class::QueryLog and Log::Log4perl::Appender::DBIx::Class and the trace section of DBI. I think you can do pretty deep logging but I've never tried and when I've needed a log I've generally used DBI->trace to a tmp file.

      I also am not sure how the reconnection stuff is is handled. I've been lucky enough that it's always "just worked" for everything I've done. You could dive the guts of the relevant Storage/Engine modules though I suspect the reconnect stuff is (at least partly) handled in the relevant DBD modules.

Re^2: DBIx::Class connection
by ribasushi (Pilgrim) on Mar 25, 2013 at 12:05 UTC
    It feels like the wrong place to do it to me.

    This is very much the case yes. See my answer to the OP.

    Cheers

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-20 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found