Remove warning from DSNParser if using UTF-8 and DBD::mysql < 3.0008 (r508). --version-check can catch this.

This commit is contained in:
Daniel Nichter
2013-02-18 12:44:02 -07:00
parent a07c0c0a6a
commit 97f963c7f7
3 changed files with 37 additions and 46 deletions

View File

@@ -212,7 +212,8 @@ sub get_cxn_params {
. join(';', map { "$opts{$_}->{dsn}=$info->{$_}" } . join(';', map { "$opts{$_}->{dsn}=$info->{$_}" }
grep { defined $info->{$_} } grep { defined $info->{$_} }
qw(F h P S A)) qw(F h P S A))
. ';mysql_read_default_group=client'; . ';mysql_read_default_group=client'
. ($info->{L} ? ';mysql_local_infile=1' : '');
} }
PTDEBUG && _d($dsn); PTDEBUG && _d($dsn);
return ($dsn, $info->{u}, $info->{p}); return ($dsn, $info->{u}, $info->{p});
@@ -241,6 +242,9 @@ sub get_dbh {
mysql_enable_utf8 => ($cxn_string =~ m/charset=utf8/i ? 1 : 0), mysql_enable_utf8 => ($cxn_string =~ m/charset=utf8/i ? 1 : 0),
}; };
@{$defaults}{ keys %$opts } = values %$opts; @{$defaults}{ keys %$opts } = values %$opts;
if (delete $defaults->{L}) { # L for LOAD DATA LOCAL INFILE, our own extension
$defaults->{mysql_local_infile} = 1;
}
if ( $opts->{mysql_use_result} ) { if ( $opts->{mysql_use_result} ) {
$defaults->{mysql_use_result} = 1; $defaults->{mysql_use_result} = 1;
@@ -294,18 +298,6 @@ sub get_dbh {
die "Error getting the current SQL_MODE: $EVAL_ERROR"; die "Error getting the current SQL_MODE: $EVAL_ERROR";
} }
$sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
. '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO'
. ($sql_mode ? ",$sql_mode" : '')
. '\'*/';
PTDEBUG && _d($dbh, $sql);
eval { $dbh->do($sql) };
if ( $EVAL_ERROR ) {
die "Error setting SQL_QUOTE_SHOW_CREATE, SQL_MODE"
. ($sql_mode ? " and $sql_mode" : '')
. ": $EVAL_ERROR";
}
if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
$sql = qq{/*!40101 SET NAMES "$charset"*/}; $sql = qq{/*!40101 SET NAMES "$charset"*/};
PTDEBUG && _d($dbh, ':', $sql); PTDEBUG && _d($dbh, ':', $sql);
@@ -331,6 +323,18 @@ sub get_dbh {
die "Error setting $var: $EVAL_ERROR"; die "Error setting $var: $EVAL_ERROR";
} }
} }
$sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
. '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO'
. ($sql_mode ? ",$sql_mode" : '')
. '\'*/';
PTDEBUG && _d($dbh, $sql);
eval { $dbh->do($sql) };
if ( $EVAL_ERROR ) {
die "Error setting SQL_QUOTE_SHOW_CREATE, SQL_MODE"
. ($sql_mode ? " and $sql_mode" : '')
. ": $EVAL_ERROR";
}
} }
PTDEBUG && _d('DBH info: ', PTDEBUG && _d('DBH info: ',

View File

@@ -1900,7 +1900,8 @@ sub get_cxn_params {
. join(';', map { "$opts{$_}->{dsn}=$info->{$_}" } . join(';', map { "$opts{$_}->{dsn}=$info->{$_}" }
grep { defined $info->{$_} } grep { defined $info->{$_} }
qw(F h P S A)) qw(F h P S A))
. ';mysql_read_default_group=client'; . ';mysql_read_default_group=client'
. ($info->{L} ? ';mysql_local_infile=1' : '');
} }
PTDEBUG && _d($dsn); PTDEBUG && _d($dsn);
return ($dsn, $info->{u}, $info->{p}); return ($dsn, $info->{u}, $info->{p});
@@ -1929,6 +1930,9 @@ sub get_dbh {
mysql_enable_utf8 => ($cxn_string =~ m/charset=utf8/i ? 1 : 0), mysql_enable_utf8 => ($cxn_string =~ m/charset=utf8/i ? 1 : 0),
}; };
@{$defaults}{ keys %$opts } = values %$opts; @{$defaults}{ keys %$opts } = values %$opts;
if (delete $defaults->{L}) { # L for LOAD DATA LOCAL INFILE, our own extension
$defaults->{mysql_local_infile} = 1;
}
if ( $opts->{mysql_use_result} ) { if ( $opts->{mysql_use_result} ) {
$defaults->{mysql_use_result} = 1; $defaults->{mysql_use_result} = 1;
@@ -1982,18 +1986,6 @@ sub get_dbh {
die "Error getting the current SQL_MODE: $EVAL_ERROR"; die "Error getting the current SQL_MODE: $EVAL_ERROR";
} }
$sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
. '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO'
. ($sql_mode ? ",$sql_mode" : '')
. '\'*/';
PTDEBUG && _d($dbh, $sql);
eval { $dbh->do($sql) };
if ( $EVAL_ERROR ) {
die "Error setting SQL_QUOTE_SHOW_CREATE, SQL_MODE"
. ($sql_mode ? " and $sql_mode" : '')
. ": $EVAL_ERROR";
}
if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
$sql = qq{/*!40101 SET NAMES "$charset"*/}; $sql = qq{/*!40101 SET NAMES "$charset"*/};
PTDEBUG && _d($dbh, ':', $sql); PTDEBUG && _d($dbh, ':', $sql);
@@ -2019,6 +2011,18 @@ sub get_dbh {
die "Error setting $var: $EVAL_ERROR"; die "Error setting $var: $EVAL_ERROR";
} }
} }
$sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
. '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO'
. ($sql_mode ? ",$sql_mode" : '')
. '\'*/';
PTDEBUG && _d($dbh, $sql);
eval { $dbh->do($sql) };
if ( $EVAL_ERROR ) {
die "Error setting SQL_QUOTE_SHOW_CREATE, SQL_MODE"
. ($sql_mode ? " and $sql_mode" : '')
. ": $EVAL_ERROR";
}
} }
PTDEBUG && _d('DBH info: ', PTDEBUG && _d('DBH info: ',

View File

@@ -1,5 +1,5 @@
# This program is copyright 2007-2011 Baron Schwartz, 2011 Percona Inc. # This program is copyright 2007-2011 Baron Schwartz,
# Feedback and improvements are welcome. # 2011-2013 Percona Ireland Ltd.
# #
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED # THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
@@ -58,8 +58,7 @@ sub new {
die "I need a $arg argument" unless $args{$arg}; die "I need a $arg argument" unless $args{$arg};
} }
my $self = { my $self = {
opts => {}, # h, P, u, etc. Should come from DSN OPTIONS section in POD. opts => {} # h, P, u, etc. Should come from DSN OPTIONS section in POD.
warn_broken_utf8 => 0,
}; };
foreach my $opt ( @{$args{opts}} ) { foreach my $opt ( @{$args{opts}} ) {
if ( !$opt->{key} || !$opt->{desc} ) { if ( !$opt->{key} || !$opt->{desc} ) {
@@ -283,22 +282,6 @@ sub get_dbh {
$defaults->{mysql_local_infile} = 1; $defaults->{mysql_local_infile} = 1;
} }
# Check for broken DBD::mysql UTF-8.
eval {
require DBD::mysql;
};
if ( !$EVAL_ERROR ) {
if ( $defaults->{mysql_enable_utf8}
&& $DBD::mysql::VERSION lt '3.0008'
&& !$self->{warn_broken_utf8}++ )
{
warn "WARNING: UTF-8 support is enabled but DBD::mysql "
. "v$DBD::mysql::VERSION is installed which does not work "
. "correctly with UTF-8. You should install a newer version "
. "of DBD::mysql, else data will be displayed incorrectly.\n";
}
}
# Only add this if explicitly set because we're not sure if # Only add this if explicitly set because we're not sure if
# mysql_use_result=0 would leave default mysql_store_result # mysql_use_result=0 would leave default mysql_store_result
# enabled. # enabled.