CC: | darren [...] darrenduncan.net |
Subject: | want DBIx::Connector post-connect hooks |
Date: | Sat, 06 Nov 2010 23:16:00 -0700 |
To: | "David E. Wheeler" <david [...] kineticode.com>, bug-dbix-connector [...] rt.cpan.org |
From: | Darren Duncan <darren [...] darrenduncan.net> |
Hello David,
I have been using DBIx::Connector for a few months now, and it occurs to me that
my usage may be vulnerable to breaking if DBIx::Connector ever has to reopen a
database connection.
For context, here is the setup code that I currently use to create my
DBIx::Connector object; it is within a wrapper class of my own:
my $dsn = sprintf( q{dbi:Pg:dbname=%s;host=%s;port=%s},
$process->db_name(), $process->db_host(), $process->db_port() );
my $dbc = DBIx::Connector->new( $dsn,
$process->db_user(), $process->db_pass(),
{ 'RaiseError' => 1, 'AutoCommit' => 1 },
);
my $dbh = $dbc->dbh();
$dbh->{pg_bool_tf} = 0; # 0 is default
$dbh->{pg_server_prepare} = 1; # 1 is default
$dbh->{pg_placeholder_dollaronly} = 1; # 0 is default
$dbh->{pg_enable_utf8} = 1; # 0 is default
$process->_sql_exec( $dbh, q{
SET extra_float_digits TO 3;
}, [] );
$process->_sql_exec( $dbh, q{
SET datestyle TO 'ISO, YMD';
}, [] );
$process->_sql_exec( $dbh, q{
SET intervalstyle TO 'postgres';
}, [] );
$process->_sql_exec( $dbh, q{
SET timezone TO 'UTC';
}, [] );
The problem concerns the extra DBMS client environment setup that is done at the
start of a connection, which the normal code expects to be in place.
If DBIx::Connector has to reconnect to a database, I assume the details provided
to new() will be reapplied, but I imagine that everything I did after isn't.
If that is true, then can you please either add, or tell me about existing,
post-connect-hooks on the DBIx::Connector object such that I can provide it a
Perl anonymous subroutine reference which DBIx::Connector would execute any time
it makes a connection (including the first time, so I assume it would be another
argument for "new") so that any client setup can be transparently done? This
subroutine would of course need to be given the DBIx::Connector object as an
argument and/or that be provided in $_, as you feel is appropriate.
Hopefully this is a quick and easy thing to do.
Thank you in advance.
-- Darren Duncan