Bug #47172 PATCH add support for MYSQL_INIT_COMMAND to DBD::mysql
Submitted: 7 Sep 2009 12:10 Modified: 17 Sep 2009 0:26
Reporter: Peter Edwards Email Updates:
Status: Closed Impact on me:
None 
Category:Connectors: DBD::mysql ( Perl ) Severity:S4 (Feature request)
Version:NA OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution, MYSQL_INIT_COMMAND

[7 Sep 2009 12:10] Peter Edwards
Description:
Could support for option MYSQL_INIT_COMMAND be added to DBD::mysql?
I've got a patch against 4.010, I'll paste it in the suggested fix section below.  I'll also post this feature request to:
  http://rt.cpan.org/Public/Dist/Display.html?Name=DBD-mysql
Many thanks,
Peter (Stig) Edwards

How to repeat:
Feature request, the test case included in the suggested fix section below will fail if the feature is not implemented (and the wait_timeout is not set to 7).

Suggested fix:
==== DBD-mysql-4.010/ChangeLog#1 - DBD-mysql-4.010/ChangeLog ====
0a1,3
> 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
>
>
>       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
> =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
> #!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' });};
> 
> 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'"));
> 
> ok($sth->execute());
> 
> ok(my @fetchrow = $sth->fetchrow_array());
> 
> is($fetchrow[1],'7','session variable is 7');
> 
> $sth->finish();
> 
> $dbh->disconnect();
[7 Sep 2009 12:47] Peter Edwards
MYSQL_INIT_COMMAND was introduced in MySQL 3.22.10.
[8 Sep 2009 6:12] Susanne Ebrecht
Many thanks for providing a patch. We will check it and our development will contact you after checking.
[15 Sep 2009 15:46] Liz Drachnik
Hello Peter

In order for us to continue the process of reviewing your contribution to MySQL - We need
you to review and sign the Sun|MySQL contributor agreement (the "SCA")

The process is explained here: 
http://forge.mysql.com/wiki/Sun_Contributor_Agreement

Getting a signed/approved SCA on file will help us facilitate your contribution-- this
one, and others in the future.

Thank you !
[17 Sep 2009 0:26] Jim Winstead
This was applied by Patrick Galbraith (the DBD::mysql maintainer).

Sorry, but there was no need for an SCA, since this is a community-led project.