Skip to content

Commit

Permalink
Avoid conversion of MySQL error messages
Browse files Browse the repository at this point in the history
The messages are properly encoded based on connection collation. This
seems to be the case since introduction of the collations, but the code
has stayed in phpMyAdmin since the times before it.

Fixes #11788

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Dec 28, 2015
1 parent 985bdd1 commit e405586
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 73 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -10,6 +10,7 @@ phpMyAdmin - ChangeLog
- issue #11785 Set PHP's internal encoding to UTF-8
- issue #11786 Fixed Kanji encoding in some specific cases
- issue #11787 Check whether iconv works before using it
- issue #11788 Avoid conversion of MySQL error messages

4.5.3.1 (2015-12-25)
- issue #11774 Undefined offset 2
Expand Down
73 changes: 0 additions & 73 deletions libraries/DatabaseInterface.class.php
Expand Up @@ -279,75 +279,6 @@ public function tryMultiQuery($multi_query = '', $link = null)
return $this->_extension->realMultiQuery($link, $multi_query);
}

/**
* converts charset of a mysql message, usually coming from mysql_error(),
* into PMA charset, usually UTF-8
* uses language to charset mapping from mysql/share/errmsg.txt
* and charset names to ISO charset from information_schema.CHARACTER_SETS
*
* @param string $message the message
*
* @return string $message
*/
public function convertMessage($message)
{
// latin always last!
// @todo some values are missing,
// see https://mariadb.com/kb/en/mariadb/server-locale/

$encodings = array(
'ja' => 'EUC-JP', //'ujis',
'ko' => 'EUC-KR', //'euckr',
'ru' => 'KOI8-R', //'koi8r',
'uk' => 'KOI8-U', //'koi8u',
'sr' => 'CP1250', //'cp1250',
'et' => 'ISO-8859-13', //'latin7',
'sk' => 'ISO-8859-2', //'latin2',
'cz' => 'ISO-8859-2', //'latin2',
'hu' => 'ISO-8859-2', //'latin2',
'pl' => 'ISO-8859-2', //'latin2',
'ro' => 'ISO-8859-2', //'latin2',
'es' => 'CP1252', //'latin1',
'sv' => 'CP1252', //'latin1',
'it' => 'CP1252', //'latin1',
'no' => 'CP1252', //'latin1',
'pt' => 'CP1252', //'latin1',
'da' => 'CP1252', //'latin1',
'nl' => 'CP1252', //'latin1',
'en' => 'CP1252', //'latin1',
'fr' => 'CP1252', //'latin1',
'de' => 'CP1252', //'latin1',
);

$server_language = PMA_Util::cacheGet(
'server_language',
function () {
return $GLOBALS['dbi']->fetchValue("SELECT @@lc_messages;");
}
);

if ($server_language) {
$found = array();
$match = preg_match(
'&([a-z][a-z])_&i',
$server_language,
$found
);
if ($match) {
$server_language = $found[1];
}
}

if (! empty($server_language) && isset($encodings[$server_language])) {
$encoding = $encodings[$server_language];
} else {
/* Fallback to CP1252 if we can not detect */
$encoding = 'CP1252';
}

return PMA_convertString($encoding, 'utf-8', $message);
}

/**
* returns array with table names for given db
*
Expand Down Expand Up @@ -2508,10 +2439,6 @@ public function getTriggers($db, $table = '', $delimiter = '//')
*/
public function formatError($error_number, $error_message)
{
if (! empty($error_message)) {
$error_message = $this->convertMessage($error_message);
}

$error_message = htmlspecialchars($error_message);

$error = '#' . ((string) $error_number);
Expand Down

0 comments on commit e405586

Please sign in to comment.