From: Peter Rabbitson Date: Thu, 20 Jan 2011 22:59:07 +0000 (+0100) Subject: Disable default mysql_auto_reconnect for MySQL X-Git-Tag: v0.08191~107 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f98120e4b249787a84b7d19819d9bda9e53d3711;hp=1db83fb9ce3e15d68e2384720ed06af6de5edbac;p=dbsrgits%2FDBIx-Class.git Disable default mysql_auto_reconnect for MySQL --- diff --git a/Changes b/Changes index 83098b8..622ce52 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for DBIx::Class + * Fixes + - Disable mysql_auto_reconnect for MySQL - depending on the ENV + it sometimes defaults to on and causes major borkage on older + DBD::mysql versions + 0.08127 2011-01-19 16:40 (UTC) * New Features / Changes - Schema/resultsource instances are now crossreferenced via a new diff --git a/lib/DBIx/Class/Storage/DBI/mysql.pm b/lib/DBIx/Class/Storage/DBI/mysql.pm index 2c49691..8dc49ad 100644 --- a/lib/DBIx/Class/Storage/DBI/mysql.pm +++ b/lib/DBIx/Class/Storage/DBI/mysql.pm @@ -33,6 +33,24 @@ sub _dbh_last_insert_id { $dbh->{mysql_insertid}; } +# here may seem like an odd place to override, but this is the first +# method called after we are connected *and* the driver is determined +# ($self is reblessed). See code flow in ::Storage::DBI::_populate_dbh +sub _run_connection_actions { + my $self = shift; + + # default mysql_auto_reconnect to off unless explicitly set + if ( + $self->_dbh->{mysql_auto_reconnect} + and + ! exists $self->_dbic_connect_attributes->{mysql_auto_reconnect} + ) { + $self->_dbh->{mysql_auto_reconnect} = 0; + } + + $self->next::method(@_); +} + # we need to figure out what mysql version we're running sub sql_maker { my $self = shift; diff --git a/t/71mysql.t b/t/71mysql.t index d75474e..18a44b0 100644 --- a/t/71mysql.t +++ b/t/71mysql.t @@ -344,13 +344,21 @@ ZEROINSEARCH: { ); } -## If find() is the first query after connect() -## DBI::Storage::sql_maker() will be called before -## _determine_driver() and so the ::SQLHacks class for MySQL -## will not be used - -my $schema2 = DBICTest::Schema->connect($dsn, $user, $pass); -$schema2->resultset("Artist")->find(4); -isa_ok($schema2->storage->sql_maker, 'DBIx::Class::SQLMaker::MySQL'); +# make sure find hooks determine driver +{ + my $schema = DBICTest::Schema->connect($dsn, $user, $pass); + $schema->resultset("Artist")->find(4); + isa_ok($schema->storage->sql_maker, 'DBIx::Class::SQLMaker::MySQL'); +} + +# make sure the mysql_auto_reconnect buggery is avoided +{ + local $ENV{MOD_PERL} = 'boogiewoogie'; + my $schema = DBICTest::Schema->connect($dsn, $user, $pass); + ok (! $schema->storage->_get_dbh->{mysql_auto_reconnect}, 'mysql_auto_reconnect unset regardless of ENV' ); + + my $schema2 = DBICTest::Schema->connect($dsn, $user, $pass, { mysql_auto_reconnect => 1 }); + ok ($schema2->storage->_get_dbh->{mysql_auto_reconnect}, 'but is properly set if explicitly requested mysql_auto_reconnect' ); +} done_testing;