diff --git a/bin/pt-archiver b/bin/pt-archiver index 84d508b1..4950e4f0 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -2143,7 +2143,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } diff --git a/bin/pt-config-diff b/bin/pt-config-diff index a08df2a8..bd524d86 100755 --- a/bin/pt-config-diff +++ b/bin/pt-config-diff @@ -1252,7 +1252,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -1291,7 +1291,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -1301,15 +1301,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -1321,12 +1323,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } @@ -1451,6 +1453,7 @@ sub new { dsn_name => $dp->as_string($dsn, [qw(h P S)]), hostname => '', set => $args{set}, + NAME_lc => defined($args{NAME_lc}) ? $args{NAME_lc} : 1, dbh_set => 0, OptionParser => $o, DSNParser => $dp, @@ -1488,7 +1491,10 @@ sub set_dbh { PTDEBUG && _d($dbh, 'Setting dbh'); - $dbh->{FetchHashKeyName} = 'NAME_lc'; + if ( !exists $self->{NAME_lc} + || (defined $self->{NAME_lc} && $self->{NAME_lc}) ) { + $dbh->{FetchHashKeyName} = 'NAME_lc'; + } my $sql = 'SELECT @@hostname, @@server_id'; PTDEBUG && _d($dbh, $sql); diff --git a/bin/pt-deadlock-logger b/bin/pt-deadlock-logger index 9ac04181..32942ec1 100755 --- a/bin/pt-deadlock-logger +++ b/bin/pt-deadlock-logger @@ -2014,7 +2014,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -2053,7 +2053,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -2063,15 +2063,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -2083,12 +2085,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/bin/pt-diskstats b/bin/pt-diskstats index e25634cb..a6f4eb5a 100755 --- a/bin/pt-diskstats +++ b/bin/pt-diskstats @@ -1514,7 +1514,8 @@ sub _GetTerminalSize { die "My::Term::ReadKey doesn't implement GetTerminalSize with arguments"; } - my ( $rows, $cols ); + my $cols = $ENV{COLUMNS} || 80; + my $rows = $ENV{LINES} || 24; if ( open( TTY, "+<", "/dev/tty" ) ) { # Got a tty my $winsize = ''; diff --git a/bin/pt-duplicate-key-checker b/bin/pt-duplicate-key-checker index c4e3f8e0..c43424e2 100755 --- a/bin/pt-duplicate-key-checker +++ b/bin/pt-duplicate-key-checker @@ -787,7 +787,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -826,7 +826,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -836,15 +836,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -856,12 +858,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/bin/pt-find b/bin/pt-find index 78b342e4..81b3b748 100755 --- a/bin/pt-find +++ b/bin/pt-find @@ -227,7 +227,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -266,7 +266,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -276,15 +276,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -296,12 +298,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/bin/pt-fk-error-logger b/bin/pt-fk-error-logger index 90ab61b6..c3e5f082 100755 --- a/bin/pt-fk-error-logger +++ b/bin/pt-fk-error-logger @@ -1371,7 +1371,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -1410,7 +1410,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -1420,15 +1420,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -1440,12 +1442,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/bin/pt-heartbeat b/bin/pt-heartbeat index dc14eff0..f67a3b7e 100755 --- a/bin/pt-heartbeat +++ b/bin/pt-heartbeat @@ -1986,7 +1986,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } diff --git a/bin/pt-index-usage b/bin/pt-index-usage index a2cd5262..cc4638d3 100755 --- a/bin/pt-index-usage +++ b/bin/pt-index-usage @@ -227,7 +227,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -266,7 +266,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -276,15 +276,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -296,12 +298,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/bin/pt-kill b/bin/pt-kill index 2a501bd6..41f2454c 100755 --- a/bin/pt-kill +++ b/bin/pt-kill @@ -1586,7 +1586,7 @@ sub parse { } foreach my $key ( keys %given_props ) { - die "DSN option '$key' in '$dsn'. For more details, " + die "Unknown DSN option '$key' in '$dsn'. For more details, " . "please use the --help option, or try 'perldoc $PROGRAM_NAME' " . "for complete documentation." unless exists $opts->{$key}; @@ -1702,7 +1702,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -1741,7 +1741,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -1751,15 +1751,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -1771,12 +1773,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } @@ -2476,9 +2478,11 @@ sub parse { my ( $self, $ddl, $opts ) = @_; return unless $ddl; - if ( $ddl !~ m/CREATE (?:TEMPORARY )?TABLE `/ ) { - die "Cannot parse table definition; is ANSI quoting " - . "enabled or SQL_QUOTE_SHOW_CREATE disabled?"; + if ( $ddl =~ m/CREATE (?:TEMPORARY )?TABLE "/ ) { + $ddl = $self->ansi_to_legacy($ddl); + } + elsif ( $ddl !~ m/CREATE (?:TEMPORARY )?TABLE `/ ) { + die "TableParser doesn't handle CREATE TABLE without quoting."; } my ($name) = $ddl =~ m/CREATE (?:TEMPORARY )?TABLE\s+(`.+?`)/; @@ -2687,19 +2691,13 @@ sub get_keys { my $key_ddl = $key; PTDEBUG && _d('Parsed key:', $key_ddl); - if ( $engine !~ m/MEMORY|HEAP/ ) { + if ( !$engine || $engine !~ m/MEMORY|HEAP/ ) { $key =~ s/USING HASH/USING BTREE/; } my ( $type, $cols ) = $key =~ m/(?:USING (\w+))? \((.+)\)/; my ( $special ) = $key =~ m/(FULLTEXT|SPATIAL)/; $type = $type || $special || 'BTREE'; - if ( $opts->{mysql_version} && $opts->{mysql_version} lt '004001000' - && $engine =~ m/HEAP|MEMORY/i ) - { - $type = 'HASH'; # MySQL pre-4.1 supports only HASH indexes on HEAP - } - my ($name) = $key =~ m/(PRIMARY|`[^`]*`)/; my $unique = $key =~ m/PRIMARY|UNIQUE/ ? 1 : 0; my @cols; @@ -2725,7 +2723,7 @@ sub get_keys { ddl => $key_ddl, }; - if ( $engine =~ m/InnoDB/i && !$clustered_key ) { + if ( ($engine || '') =~ m/InnoDB/i && !$clustered_key ) { my $this_key = $keys->{$name}; if ( $this_key->{name} eq 'PRIMARY' ) { $clustered_key = 'PRIMARY'; @@ -2808,6 +2806,21 @@ sub get_table_status { return @tables; } +my $ansi_quote_re = qr/" [^"]* (?: "" [^"]* )* (?<=.) "/ismx; +sub ansi_to_legacy { + my ($self, $ddl) = @_; + $ddl =~ s/($ansi_quote_re)/ansi_quote_replace($1)/ge; + return $ddl; +} + +sub ansi_quote_replace { + my ($val) = @_; + $val =~ s/^"|"$//g; + $val =~ s/`/``/g; + $val =~ s/""/"/g; + return "`$val`"; +} + sub _d { my ($package, undef, $line) = caller 0; @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } @@ -4698,7 +4711,7 @@ sub new { dsn_name => $dp->as_string($dsn, [qw(h P S)]), hostname => '', set => $args{set}, - NAME_lc => $args{NAME_lc}, + NAME_lc => defined($args{NAME_lc}) ? $args{NAME_lc} : 1, dbh_set => 0, OptionParser => $o, DSNParser => $dp, diff --git a/bin/pt-log-player b/bin/pt-log-player index c0b65f46..64b46cc9 100755 --- a/bin/pt-log-player +++ b/bin/pt-log-player @@ -2207,7 +2207,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -2246,7 +2246,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -2256,15 +2256,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -2276,12 +2278,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index d3310425..f76ac8b7 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -1896,7 +1896,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -7985,6 +7985,12 @@ The C clause cannot be used to rename the table. Columns cannot be renamed by dropping and re-adding with the new name. The tool will not copy the original column's data to the new column. +=item * + +If you add a column without a default value and make it NOT NULL, the tool +will fail, as it will not try to guess a default value for you; You must +specify the default. + =back =item --alter-foreign-keys-method diff --git a/bin/pt-query-advisor b/bin/pt-query-advisor index 1cc0682e..a1066a0d 100755 --- a/bin/pt-query-advisor +++ b/bin/pt-query-advisor @@ -227,7 +227,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -266,7 +266,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -276,15 +276,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -296,12 +298,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } @@ -6895,7 +6897,8 @@ severity: warn OUTER JOIN defeated. The reference to an outer table column in the WHERE clause prevents the OUTER JOIN from returning any non-matched rows, which implicitly converts the query to an INNER JOIN. This is probably a bug in the query or a -misunderstanding of how OUTER JOIN works. +misunderstanding of how OUTER JOIN works, as LEFT/RIGHT joins are a shortcut +for LEFT/RIGHT OUTER JOIN. =item JOI.004 diff --git a/bin/pt-query-digest b/bin/pt-query-digest index f2e66307..c531c6c4 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -227,7 +227,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -266,7 +266,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -276,15 +276,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -296,12 +298,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } @@ -2311,6 +2313,7 @@ sub new { last_poll => 0, active_cxn => {}, # keyed off ID event_cache => [], + _reasons_for_matching => {}, }; return bless $self, $class; } @@ -2521,7 +2524,9 @@ sub find { PTDEBUG && _d("Query isn't running long enough"); next QUERY; } - PTDEBUG && _d('Exceeds busy time'); + my $reason = 'Exceeds busy time'; + PTDEBUG && _d($reason); + push @{$self->{_reasons_for_matching}->{$query} ||= []}, $reason; $matched++; } @@ -2531,7 +2536,9 @@ sub find { PTDEBUG && _d("Query isn't idle long enough"); next QUERY; } - PTDEBUG && _d('Exceeds idle time'); + my $reason = 'Exceeds idle time'; + PTDEBUG && _d($reason); + push @{$self->{_reasons_for_matching}->{$query} ||= []}, $reason; $matched++; } @@ -2548,7 +2555,9 @@ sub find { PTDEBUG && _d('Query does not match', $property, 'spec'); next QUERY; } - PTDEBUG && _d('Query matches', $property, 'spec'); + my $reason = 'Query matches ' . $property . ' spec'; + PTDEBUG && _d($reason); + push @{$self->{_reasons_for_matching}->{$query} ||= []}, $reason; $matched++; } } diff --git a/bin/pt-show-grants b/bin/pt-show-grants index 914df862..a3ba6157 100755 --- a/bin/pt-show-grants +++ b/bin/pt-show-grants @@ -1252,7 +1252,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -1291,7 +1291,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -1301,15 +1301,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -1321,12 +1323,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/bin/pt-slave-delay b/bin/pt-slave-delay index eb364b6f..7d2f1acb 100755 --- a/bin/pt-slave-delay +++ b/bin/pt-slave-delay @@ -1702,7 +1702,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -1741,7 +1741,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -1751,15 +1751,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -1771,12 +1773,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/bin/pt-slave-find b/bin/pt-slave-find index b7ec1577..67950593 100755 --- a/bin/pt-slave-find +++ b/bin/pt-slave-find @@ -1702,7 +1702,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } diff --git a/bin/pt-slave-restart b/bin/pt-slave-restart index b0f78761..48ed8c61 100755 --- a/bin/pt-slave-restart +++ b/bin/pt-slave-restart @@ -2015,7 +2015,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 05c94962..3ecbc961 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -227,7 +227,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -4357,6 +4357,11 @@ sub next { return; } } + if ( !$self->{one_nibble} && !$self->{first_lower} ) { + PTDEBUG && _d('No first lower boundary, table must be empty'); + $self->{no_more_boundaries} = 1; + return; + } } NIBBLE: diff --git a/bin/pt-table-sync b/bin/pt-table-sync index fc67a6c4..a9d9d779 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -1821,7 +1821,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } diff --git a/bin/pt-table-usage b/bin/pt-table-usage index 9a327ba3..37ef863d 100755 --- a/bin/pt-table-usage +++ b/bin/pt-table-usage @@ -227,7 +227,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -266,7 +266,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -276,15 +276,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -296,12 +298,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/bin/pt-tcp-model b/bin/pt-tcp-model index d659effb..895d4ff2 100755 --- a/bin/pt-tcp-model +++ b/bin/pt-tcp-model @@ -2338,7 +2338,8 @@ number of iterations. type: float -The percentile for the last column when L<"--type"> is "requests" (default .99). +The percentile for the second to last last column when L<"--type"> is +"requests" (default .99). =item --run-time diff --git a/bin/pt-upgrade b/bin/pt-upgrade index acaaabee..a7b26804 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -227,7 +227,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -266,7 +266,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -276,15 +276,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -296,12 +298,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/bin/pt-variable-advisor b/bin/pt-variable-advisor index 4a767fc9..27bd8646 100755 --- a/bin/pt-variable-advisor +++ b/bin/pt-variable-advisor @@ -1702,7 +1702,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -1741,7 +1741,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -1751,15 +1751,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -1771,12 +1773,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/bin/pt-visual-explain b/bin/pt-visual-explain index adcf42d0..e22c7798 100755 --- a/bin/pt-visual-explain +++ b/bin/pt-visual-explain @@ -1924,7 +1924,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; } @@ -1963,7 +1963,7 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error getting the current SQL_MODE: $EVAL_ERROR"; } $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' @@ -1973,15 +1973,17 @@ sub get_dbh { PTDEBUG && _d($dbh, $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $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+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { + $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting NAMES to $charset: $EVAL_ERROR"; } PTDEBUG && _d('Enabling charset for STDOUT'); if ( $charset eq 'utf8' ) { @@ -1993,12 +1995,12 @@ sub get_dbh { } } - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); + if ( my $var = $self->prop('set-vars') ) { + $sql = "SET $var"; PTDEBUG && _d($dbh, ':', $sql); eval { $dbh->do($sql) }; if ( $EVAL_ERROR ) { - die $EVAL_ERROR; + die "Error setting $var: $EVAL_ERROR"; } } } diff --git a/lib/DSNParser.pm b/lib/DSNParser.pm index 4ba7e7c1..43625496 100644 --- a/lib/DSNParser.pm +++ b/lib/DSNParser.pm @@ -291,7 +291,7 @@ sub get_dbh { . "that Perl searches for DBI. If DBI is not installed, try:\n" . " Debian/Ubuntu apt-get install libdbi-perl\n" . " RHEL/CentOS yum install perl-DBI\n" - . " OpenSolaris pgk install pkg:/SUNWpmdbi\n"; + . " OpenSolaris pkg install pkg:/SUNWpmdbi\n"; }