Subject: | PATCH add support for MYSQL_INIT_COMMAND to DBD::mysql |
Hello and thanks for DBD::mysql,
Could support for option MYSQL_INIT_COMMAND be added to DBD::mysql?
I've got a patch against 4.010, I'll paste it below
I have also filed this as an enhancement request on:
http://bugs.mysql.com/bug.php?id=47172
Many thanks,
Peter (Stig) Edwards
==== DBD-mysql-4.010/ChangeLog#1 - DBD-mysql-4.010/ChangeLog ====
0a1,3
Show quoted text
> 2009-??-?? Patrick Galbraith <patg@patg.net> (4.0??)
> * dbdimp.c (mysql_dr_connect): Added mysql_init_command option.
>
==== DBD-mysql-4.010/dbdimp.c#1 - DBD-mysql-4.010/dbdimp.c ====
1504a1505,1517
Show quoted text>
>
> if ((svp = hv_fetch(hv, "mysql_init_command", 18, FALSE)) &&
> *svp && SvTRUE(*svp))
> {
> char* df = SvPV(*svp, lna);
> if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
> PerlIO_printf(DBILOGFP,
> "imp_dbh->mysql_dr_connect: Setting" \
> " init command (%s).\n", df);
> mysql_options(sock, MYSQL_INIT_COMMAND, df);
> }
>
==== DBD-mysql-4.010/lib/DBD/mysql.pm#1 - DBD-mysql-
4.010/lib/DBD/mysql.pm ====
948a949,954
Show quoted text> =item mysql_init_command
>
> If your DSN contains the option "mysql_init_command_timeout=##", then
> this SQL statement is executed when conencting to the MySQL server.
> It is automatically re-executed if reconnection occurs.
>
==== DBD-mysql-4.010/t/85init_command.t
Show quoted text> #!perl -w
> # vim: ft=perl
>
> use Test::More;
> use DBI;
> use DBI::Const::GetInfoType;
> use strict;
> $|= 1;
>
> use vars qw($table $test_dsn $test_user $test_password);
> use lib 't', '.';
> require 'lib.pl';
>
> my $dbh;
> eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
> { RaiseError => 1, PrintError => 1, AutoCommit
=> 0,
mysql_init_command => 'SET SESSION wait_timeout=7' });};
Show quoted text>
> if ($@) {
> plan skip_all => "ERROR: $DBI::errstr. Can't continue test";
> }
> plan tests => 5;
>
> ok(defined $dbh, "Connected to database");
>
> ok(my $sth=$dbh->prepare("SHOW SESSION VARIABLES
like 'wait_timeout'"));
Show quoted text>
> ok($sth->execute());
>
> ok(my @fetchrow = $sth->fetchrow_array());
>
> is($fetchrow[1],'7','session variable is 7');
>
> $sth->finish();
>
> $dbh->disconnect();
Just noticed I didn't update the MANIFEST with the new test.