From 837639360f16ec225c7013296e3e282bf76791c5 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 25 Jul 2004 20:17:53 +0000 Subject: [PATCH] bug 997682 Illegal mix of collations --- libraries/common.lib.php | 28 ++++++++++++++++++++++++++++ main.php | 7 +++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/libraries/common.lib.php b/libraries/common.lib.php index c0d599f0f..0b3c850ee 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -671,6 +671,34 @@ if ($is_minimum_common == FALSE) { return ($i < $max) ? $i : -1; } // end of the 'PMA_isInto()' function + + + /** + * Returns a string formatted with proper charset introducer + * and collate information, if MySQL supports it + * + * @param string the string itself + * @param string the charset introducer we want + * @param string the collation we want + * + * @return the formatted string + * + * @access private + */ + function PMA_charsetIntroducerCollate($original_string, $charset_introducer, $collation) + { + $result = ''; + if (PMA_MYSQL_INT_VERSION >= 40100) { + $result .= $charset_introducer; + } + $result .= '\'' . $original_string . '\''; + if (PMA_MYSQL_INT_VERSION >= 40100) { + $result .= ' COLLATE ' . $collation; + } + return $result; + + } // end of the 'PMA_charsetIntroducerCollate()' function + } /** diff --git a/main.php b/main.php index e00ba187c..526859eb8 100644 --- a/main.php +++ b/main.php @@ -167,6 +167,7 @@ include('./libraries/select_server.lib.php'); * Displays the mysql server related links */ $is_superuser = FALSE; + if ($server > 0) { // Get user's global privileges ($dbh and $userlink are links to MySQL // defined in the "common.lib.php" library) @@ -181,7 +182,8 @@ if ($server > 0) { // (even if they cannot see the tables) $is_superuser = PMA_DBI_try_query('SELECT COUNT(*) FROM mysql.user', $userlink, PMA_DBI_QUERY_STORE); if ($dbh) { - $local_query = 'SELECT Create_priv, Reload_priv FROM mysql.user WHERE User = \'' . PMA_sqlAddslashes($mysql_cur_user) . '\''; + // TODO: do we need to check the charset and collation of mysql.user? + $local_query = 'SELECT Create_priv, Reload_priv FROM mysql.user WHERE User = ' . PMA_charsetIntroducerCollate(PMA_sqlAddslashes($mysql_cur_user),'_latin1', 'latin1_swedish_ci') . ';'; $rs_usr = PMA_DBI_try_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE); if ($rs_usr) { while ($result_usr = PMA_DBI_fetch_assoc($rs_usr)) { @@ -200,7 +202,8 @@ if ($server > 0) { // the first inexistant db name that we find, in most cases it's probably // the one he just dropped :) if (!$is_create_priv) { - $rs_usr = PMA_DBI_try_query('SELECT DISTINCT Db FROM mysql.db WHERE Create_priv = \'Y\' AND User = \'' . PMA_sqlAddslashes($mysql_cur_user) . '\';', $dbh, PMA_DBI_QUERY_STORE); + $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Create_priv = ' . PMA_charsetIntroducerCollate('Y','_latin1','latin1_swedish_ci') . ' AND User = ' . PMA_charsetIntroducerCollate(PMA_sqlAddslashes($mysql_cur_user),'_latin1','latin1_swedish_ci') . ';'; + $rs_usr = PMA_DBI_try_query($local_query, $dbh, PMA_DBI_QUERY_STORE); if ($rs_usr) { $re0 = '(^|(\\\\\\\\)+|[^\])'; // non-escaped wildcards $re1 = '(^|[^\])(\\\)+'; // escaped wildcards