diff --git a/ChangeLog b/ChangeLog index 4f0d5cd22..7455e1eeb 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,7 +5,12 @@ phpMyAdmin - Changelog $Id$ $Source$ -2004-08-16 Alexander M. Turek +2004-09-03 Marc Delisle + * main.php, server_privileges.php, libraries/common.lib.php: + phase 1 of replacing charset introducers by CONVERT USING, + to support the case where the mysql.* tables are not in latin1 + +2004-09-02 Alexander M. Turek * Documentation.html: Typos; added a note about the deprecated MySQL versions 4.1.0 and 4.1.1. diff --git a/libraries/common.lib.php b/libraries/common.lib.php index eee7881e6..c0982df1c 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -716,6 +716,18 @@ if ($is_minimum_common == FALSE) { } // end of the 'PMA_charsetIntroducerCollate()' function + + function PMA_convert_using($string, $mode='unquoted') { + + if (PMA_MYSQL_INT_VERSION >= 40100) { + list($conn_charset) = explode('_', $GLOBALS['collation_connection']); + $converted_string = "CONVERT(" . ($mode=='quoted'?"'":"") . $string . ($mode=='quoted'?"'":"") . " USING " . $conn_charset . ")"; + } else { + $converted_string = ($mode=='quoted'?"'":"") . $string . ($mode=='quoted'?"'":""); + } + return $converted_string; + } // end function + } /** diff --git a/main.php b/main.php index 98f73b04a..b240d6c6d 100644 --- a/main.php +++ b/main.php @@ -182,8 +182,7 @@ 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) { - // 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)) . ';'; + $local_query = 'SELECT Create_priv, Reload_priv FROM mysql.user WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($mysql_cur_user), 'quoted') . ';'; $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)) { @@ -202,7 +201,7 @@ 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) { - $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Create_priv = ' . PMA_charsetIntroducerCollate('Y') . ' AND User = ' . PMA_charsetIntroducerCollate(PMA_sqlAddslashes($mysql_cur_user)) . ';'; + $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE ' . PMA_convert_using('Create_priv') . ' = ' . PMA_convert_using('Y', 'quoted') . ' AND ' . PMA_convert_using('User') . ' = ' .PMA_convert_using(PMA_sqlAddslashes($mysql_cur_user), 'quoted') . ';'; $rs_usr = PMA_DBI_try_query($local_query, $dbh, PMA_DBI_QUERY_STORE); if ($rs_usr) { $re0 = '(^|(\\\\\\\\)+|[^\])'; // non-escaped wildcards diff --git a/server_privileges.php b/server_privileges.php index d82d81606..a5dec0f2d 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -1347,24 +1347,13 @@ if (empty($adduser) && empty($checkprivs)) { // Starting with MySQL 4.0.0, we may use UNION SELECTs and this makes // the job much easier here! - function PMA_convert_using($string, $mode='variable') { - - if (PMA_MYSQL_INT_VERSION >= 40100) { - list($conn_charset) = explode('_', $GLOBALS['collation_connection']); - $converted_string = "CONVERT(" . ($mode=='constant'?"'":"") . $string . ($mode=='constant'?"'":"") . " USING " . $conn_charset . ")"; - } else { - $converted_string = ($mode=='constant'?"'":"") . $string . ($mode=='constant'?"'":""); - } - return $converted_string; - } // end function - - $no = PMA_convert_using('N', 'constant'); + $no = PMA_convert_using('N', 'quoted'); $list_of_privileges = PMA_convert_using('Select_priv') . ' AS Select_priv, ' . PMA_convert_using('Insert_priv') . ' AS Insert_priv, ' . PMA_convert_using('Update_priv') . ' AS Update_priv, ' . PMA_convert_using('Delete_priv') . ' AS Delete_priv, ' . PMA_convert_using('Create_priv') . ' AS Create_priv, ' . PMA_convert_using('Drop_priv') . ' AS Drop_priv, ' . PMA_convert_using('Grant_priv') . ' AS Grant_priv, '. PMA_convert_using('References_priv') . ' AS References_priv'; $list_of_compared_privileges = PMA_convert_using('Select_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Insert_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Update_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Delete_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Create_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Drop_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('Grant_priv') . ' = ' . $no . ' AND ' . PMA_convert_using('References_priv') . ' = ' . $no; - $sql_query = '(SELECT ' . PMA_convert_using('User') . ' AS User,' . PMA_convert_using('Host') . ' AS Host,' . PMA_convert_using('Db') . ' AS Db,' . $list_of_privileges . ' FROM `db` WHERE ' . PMA_convert_using($checkprivs, 'constant') . ' LIKE ' . PMA_convert_using('Db') . ' AND NOT (' . $list_of_compared_privileges. ')) UNION (SELECT ' . PMA_convert_using('User') . ' AS User, ' . PMA_convert_using('Host') . ' AS Host, ' . PMA_convert_using('*', 'constant') . ' AS Db, ' . $list_of_privileges . ' FROM `user` WHERE NOT (' . $list_of_compared_privileges . ')) ORDER BY User ASC, Host ASC, Db ASC;'; + $sql_query = '(SELECT ' . PMA_convert_using('User') . ' AS User,' . PMA_convert_using('Host') . ' AS Host,' . PMA_convert_using('Db') . ' AS Db,' . $list_of_privileges . ' FROM `db` WHERE ' . PMA_convert_using($checkprivs, 'quoted') . ' LIKE ' . PMA_convert_using('Db') . ' AND NOT (' . $list_of_compared_privileges. ')) UNION (SELECT ' . PMA_convert_using('User') . ' AS User, ' . PMA_convert_using('Host') . ' AS Host, ' . PMA_convert_using('*', 'quoted') . ' AS Db, ' . $list_of_privileges . ' FROM `user` WHERE NOT (' . $list_of_compared_privileges . ')) ORDER BY User ASC, Host ASC, Db ASC;'; $res = PMA_DBI_query($sql_query); $row = PMA_DBI_fetch_assoc($res);