Closed Perlover closed 11 years ago
You want to use DBI callbacks for that. The one you want is connect
. An example from the DBI docs:
my $dbh = DBI->connect($dsn, $username, $auth, {
Callbacks => {
connected => sub {
shift->do(q{
SET SESSION sql_mode='ansi,strict_trans_tables,no_auto_value_on_zero';
});
return;
},
}
});
I don't think that this will work Callbacks are properties of dbh But if i will loose connect your module will create new dbh handler without my callbacks How can i execute my own initialization for MySQL if i loose connect and your dbh method will do reconnect with new dbh handler? Your opinion?
Sorry, i think i should pass Callbacks options to DBIx::Connector new constructor ;-)
Yes, that is correct. Any options you can pass to DBI->connect
you can also pass to DBIx::Connector->new
.
Hello,
Your _connect method does a reconnect if connection is lost But sometimes there is a need to resend some commands after reconnect For example: SET NAMES 'utf8' Without these commands my programs will have big problems - after reconnect Mysql will decide that i send latin1 coding if i will send utf-8 encoded strings.
The DBD::mysql has 'mysql_init_command' command if 'mysql_auto_reconnect' is true But your module uses own reconnect way. I think your module should have some way to send own commands after reconnect.
If you agree to have this feature and don't have a free time for this now i can patch and send to you pull request.
Please let me know your opinion about this feature
Thanks!