Skip Menu |

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 49484
Status: resolved
Priority: 0/
Queue: DBD-mysql

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 4.013



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.
MYSQL_INIT_COMMAND was introduced in MySQL 3.22.10.
Peter, I'd be glad to add this. Thank you for submitting the patch! --Patrick On Mon Sep 07 08:17:32 2009, cpan@pjedwards.co.uk wrote: Show quoted text
> 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
> > 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();
> > Just noticed I didn't update the MANIFEST with the new test.
Thanks for the patch! Going in 4.013 this week release!
On Wed Sep 16 10:33:02 2009, CAPTTOFU wrote: Show quoted text
> Thanks for the patch! Going in 4.013 this week release!
Thank you very much. I just noticed a copy-and-paste error in the patch, and in 4.013's lib/DBD/mysql.pm This line: If your DSN contains the option "mysql_init_command_timeout=##", Should be: If your DSN contains the option "mysql_init_command=##", Sorry about that, my fault. I changed the status of this ticket to open, hope that is OK.
Applied patch, is now in git and will be released with 4.013