From 751404c4288608ceabfbc46d603127f82805a5e9 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 12 Oct 2004 21:08:49 +0000 Subject: [PATCH] bug #1033388 and optimizations --- ChangeLog | 5 +++++ db_search.php | 8 +++---- libraries/database_interface.lib.php | 5 +++-- tbl_select.php | 32 ++++++++++++++-------------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2aa543fe3..72d1025be 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ phpMyAdmin - Changelog $Id$ $Source$ +2004-10-12 Alexander M. Turek + * db_search.php, tbl_select.php, libraries/database_interface.lib.php: + - bug #1033388 (Illegal mix of collations for converted strings), + - don't convert if column charset and connection charset match. + 2004-10-12 Michal Čihař * sql.php: Don't try to require sql.php with parameters, rather redirect to it. diff --git a/db_search.php b/db_search.php index c95593d00..d93a16315 100644 --- a/db_search.php +++ b/db_search.php @@ -50,7 +50,7 @@ if (isset($submit_search)) { */ function PMA_getSearchSqls($table, $search_str, $search_option) { - global $err_url; + global $err_url, $charset_connection; // Statement types $sqlstr_select = 'SELECT'; @@ -85,11 +85,11 @@ if (isset($submit_search)) { // Eliminates empty values if (!empty($search_words[$i])) { for ($j = 0; $j < $tblfields_cnt; $j++) { - $prefix = PMA_MYSQL_INT_VERSION >= 40100 && $tblfields[$j]['Charset'] != 'NULL' + $prefix = PMA_MYSQL_INT_VERSION >= 40100 && $tblfields[$j]['Charset'] != $charset_connection && $tblfields[$j]['Charset'] != 'NULL' ? 'CONVERT(_utf8 ' : ''; - $suffix = PMA_MYSQL_INT_VERSION >= 40100 && $tblfields[$j]['Charset'] != 'NULL' - ? ' USING ' . $tblfields[$j]['Charset'] . ')' + $suffix = PMA_MYSQL_INT_VERSION >= 40100 && $tblfields[$j]['Charset'] != $charset_connection && $tblfields[$j]['Charset'] != 'NULL' + ? ' USING ' . $tblfields[$j]['Charset'] . ') COLLATE ' . $tblfields[$j]['Collation'] : ''; $thefieldlikevalue[] = $tblfields[$j]['Field'] . ' ' . $like_or_regex . ' ' diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index dba00f5c9..0b443fa0f 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -115,7 +115,7 @@ function PMA_DBI_get_variable($var, $type = PMA_DBI_GETVAR_SESSION, $link = NULL } function PMA_DBI_postConnect($link) { - global $collation_connection; + global $collation_connection, $charset_connection; if (!defined('PMA_MYSQL_INT_VERSION')) { $result = PMA_DBI_query('SELECT VERSION() AS version', $link, PMA_DBI_QUERY_STORE); if ($result != FALSE && @PMA_DBI_num_rows($result) > 0) { @@ -167,7 +167,8 @@ function PMA_DBI_postConnect($link) { if (!empty($collation_connection)) { PMA_DBI_query('SET collation_connection = \'' . $collation_connection . '\';', $link, PMA_DBI_QUERY_STORE); } - $collation_connection = PMA_DBI_get_variable('collation_connection', PMA_DBI_GETVAR_SESSION, $link); + $collation_connection = PMA_DBI_get_variable('collation_connection', PMA_DBI_GETVAR_SESSION, $link); + $charset_connection = PMA_DBI_get_variable('character_set_connection', PMA_DBI_GETVAR_SESSION, $link); // Add some field types to the list // (we pass twice here; feel free to code something better :) diff --git a/tbl_select.php b/tbl_select.php index 0822efb6c..b920e8544 100644 --- a/tbl_select.php +++ b/tbl_select.php @@ -49,6 +49,8 @@ if (!isset($param) || $param[0] == '') { // Gets the list and number of fields $result = PMA_DBI_query('SHOW' . (PMA_MYSQL_INT_VERSION >= 40100 ? ' FULL' : '') . ' FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ';', NULL, PMA_DBI_QUERY_STORE); $fields_cnt = PMA_DBI_num_rows($result); + // rabue: we'd better ensure, that all arrays are empty. + $fields_list = $fields_null = $fields_type = $fields_collation = array(); while ($row = PMA_DBI_fetch_assoc($result)) { $fields_list[] = $row['Field']; $type = $row['Type']; @@ -64,14 +66,9 @@ if (!isset($param) || $param[0] == '') { } $fields_null[] = $row['Null']; $fields_type[] = $type; - if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($row['Collation']) && $row['Collation'] != 'NULL') { - $fields_collation[] = $row['Collation']; - $tmp_charset = explode('_', $row['Collation']); - $fields_charset[] = $tmp_charset[0]; - unset($tmp_charset); - } else { - $fields_collation[] = $fields_charset[] = ''; - } + $fields_collation[] = PMA_MYSQL_INT_VERSION >= 40100 && !empty($row['Collation']) && $row['Collation'] != 'NULL' + ? $row['Collation'] + : ''; } // end while PMA_DBI_free_result($result); unset($result, $type); @@ -297,7 +294,7 @@ function PMA_tbl_select_operator(f, index, multiple) { ?> - + = 40100) { + list($charsets[$i]) = explode('_', $collations[$i]); + } if (@$GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) { $fields[$i] = ''; $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type; @@ -378,14 +378,14 @@ else { $parens_close = ''; } $enum_where = '\'' . PMA_sqlAddslashes($fields[$i][0]) . '\''; - if (PMA_MYSQL_INT_VERSION >= 40100) { - $enum_where = 'CONVERT(_utf8 ' . $enum_where . ' USING ' . $charsets[$i] . ')'; + if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) { + $enum_where = 'CONVERT(_utf8 ' . $enum_where . ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i]; } for ($e = 1; $e < $enum_selected_count; $e++) { $enum_where .= ', '; $tmp_literal = '\'' . PMA_sqlAddslashes($fields[$i][$e]) . '\''; - if (PMA_MYSQL_INT_VERSION >= 40100) { - $tmp_literal = 'CONVERT(_utf8 ' . $tmp_literal . ' USING ' . $charsets[$i] . ')'; + if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) { + $tmp_literal = 'CONVERT(_utf8 ' . $tmp_literal . ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i]; } $enum_where .= $tmp_literal; unset($tmp_literal); @@ -402,9 +402,9 @@ else { } // Make query independant from the selected connection charset. - if (PMA_MYSQL_INT_VERSION >= 40101 && preg_match('@char|binary|blob|text|set@i', $types[$i])) { + if (PMA_MYSQL_INT_VERSION >= 40101 && $charsets[$i] != $charset_connection && preg_match('@char|binary|blob|text|set@i', $types[$i])) { $prefix = 'CONVERT(_utf8 '; - $suffix = ' USING ' . $charsets[$i] . ')'; + $suffix = ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i]; } else { $prefix = $suffix = ''; }