bug #1033388 and optimizations

This commit is contained in:
Alexander M. Turek
2004-10-12 21:08:49 +00:00
parent 9ab1eb5a2d
commit 751404c428
4 changed files with 28 additions and 22 deletions

View File

@@ -5,6 +5,11 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2004-10-12 Alexander M. Turek <me@derrabus.de>
* 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ř <michal@cihar.com> 2004-10-12 Michal Čihař <michal@cihar.com>
* sql.php: Don't try to require sql.php with parameters, rather redirect * sql.php: Don't try to require sql.php with parameters, rather redirect
to it. to it.

View File

@@ -50,7 +50,7 @@ if (isset($submit_search)) {
*/ */
function PMA_getSearchSqls($table, $search_str, $search_option) function PMA_getSearchSqls($table, $search_str, $search_option)
{ {
global $err_url; global $err_url, $charset_connection;
// Statement types // Statement types
$sqlstr_select = 'SELECT'; $sqlstr_select = 'SELECT';
@@ -85,11 +85,11 @@ if (isset($submit_search)) {
// Eliminates empty values // Eliminates empty values
if (!empty($search_words[$i])) { if (!empty($search_words[$i])) {
for ($j = 0; $j < $tblfields_cnt; $j++) { 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 ' ? 'CONVERT(_utf8 '
: ''; : '';
$suffix = PMA_MYSQL_INT_VERSION >= 40100 && $tblfields[$j]['Charset'] != 'NULL' $suffix = PMA_MYSQL_INT_VERSION >= 40100 && $tblfields[$j]['Charset'] != $charset_connection && $tblfields[$j]['Charset'] != 'NULL'
? ' USING ' . $tblfields[$j]['Charset'] . ')' ? ' USING ' . $tblfields[$j]['Charset'] . ') COLLATE ' . $tblfields[$j]['Collation']
: ''; : '';
$thefieldlikevalue[] = $tblfields[$j]['Field'] $thefieldlikevalue[] = $tblfields[$j]['Field']
. ' ' . $like_or_regex . ' ' . ' ' . $like_or_regex . ' '

View File

@@ -115,7 +115,7 @@ function PMA_DBI_get_variable($var, $type = PMA_DBI_GETVAR_SESSION, $link = NULL
} }
function PMA_DBI_postConnect($link) { function PMA_DBI_postConnect($link) {
global $collation_connection; global $collation_connection, $charset_connection;
if (!defined('PMA_MYSQL_INT_VERSION')) { if (!defined('PMA_MYSQL_INT_VERSION')) {
$result = PMA_DBI_query('SELECT VERSION() AS version', $link, PMA_DBI_QUERY_STORE); $result = PMA_DBI_query('SELECT VERSION() AS version', $link, PMA_DBI_QUERY_STORE);
if ($result != FALSE && @PMA_DBI_num_rows($result) > 0) { if ($result != FALSE && @PMA_DBI_num_rows($result) > 0) {
@@ -167,7 +167,8 @@ function PMA_DBI_postConnect($link) {
if (!empty($collation_connection)) { if (!empty($collation_connection)) {
PMA_DBI_query('SET collation_connection = \'' . $collation_connection . '\';', $link, PMA_DBI_QUERY_STORE); 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 // Add some field types to the list
// (we pass twice here; feel free to code something better :) // (we pass twice here; feel free to code something better :)

View File

@@ -49,6 +49,8 @@ if (!isset($param) || $param[0] == '') {
// Gets the list and number of fields // 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); $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); $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)) { while ($row = PMA_DBI_fetch_assoc($result)) {
$fields_list[] = $row['Field']; $fields_list[] = $row['Field'];
$type = $row['Type']; $type = $row['Type'];
@@ -64,14 +66,9 @@ if (!isset($param) || $param[0] == '') {
} }
$fields_null[] = $row['Null']; $fields_null[] = $row['Null'];
$fields_type[] = $type; $fields_type[] = $type;
if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($row['Collation']) && $row['Collation'] != 'NULL') { $fields_collation[] = PMA_MYSQL_INT_VERSION >= 40100 && !empty($row['Collation']) && $row['Collation'] != 'NULL'
$fields_collation[] = $row['Collation']; ? $row['Collation']
$tmp_charset = explode('_', $row['Collation']); : '';
$fields_charset[] = $tmp_charset[0];
unset($tmp_charset);
} else {
$fields_collation[] = $fields_charset[] = '';
}
} // end while } // end while
PMA_DBI_free_result($result); PMA_DBI_free_result($result);
unset($result, $type); unset($result, $type);
@@ -297,7 +294,7 @@ function PMA_tbl_select_operator(f, index, multiple) {
?> ?>
<input type="hidden" name="names[<?php echo $i; ?>]" value="<?php echo htmlspecialchars($fields_list[$i]); ?>" /> <input type="hidden" name="names[<?php echo $i; ?>]" value="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
<input type="hidden" name="types[<?php echo $i; ?>]" value="<?php echo $fields_type[$i]; ?>" /> <input type="hidden" name="types[<?php echo $i; ?>]" value="<?php echo $fields_type[$i]; ?>" />
<input type="hidden" name="charsets[<?php echo $i; ?>]" value="<?php echo $fields_charset[$i]; ?>" /> <input type="hidden" name="collations[<?php echo $i; ?>]" value="<?php echo $fields_collation[$i]; ?>" />
</td> </td>
</tr> </tr>
<?php <?php
@@ -349,10 +346,13 @@ else {
if (trim($where) != '') { if (trim($where) != '') {
$sql_query .= ' WHERE ' . $where; $sql_query .= ' WHERE ' . $where;
} else { } else {
$w = array(); $w = $charsets = array();
$cnt_func = count($func); $cnt_func = count($func);
reset($func); reset($func);
while (list($i, $func_type) = each($func)) { while (list($i, $func_type) = each($func)) {
if (PMA_MYSQL_INT_VERSION >= 40100) {
list($charsets[$i]) = explode('_', $collations[$i]);
}
if (@$GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) { if (@$GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) {
$fields[$i] = ''; $fields[$i] = '';
$w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type; $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type;
@@ -378,14 +378,14 @@ else {
$parens_close = ''; $parens_close = '';
} }
$enum_where = '\'' . PMA_sqlAddslashes($fields[$i][0]) . '\''; $enum_where = '\'' . PMA_sqlAddslashes($fields[$i][0]) . '\'';
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) {
$enum_where = 'CONVERT(_utf8 ' . $enum_where . ' USING ' . $charsets[$i] . ')'; $enum_where = 'CONVERT(_utf8 ' . $enum_where . ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i];
} }
for ($e = 1; $e < $enum_selected_count; $e++) { for ($e = 1; $e < $enum_selected_count; $e++) {
$enum_where .= ', '; $enum_where .= ', ';
$tmp_literal = '\'' . PMA_sqlAddslashes($fields[$i][$e]) . '\''; $tmp_literal = '\'' . PMA_sqlAddslashes($fields[$i][$e]) . '\'';
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) {
$tmp_literal = 'CONVERT(_utf8 ' . $tmp_literal . ' USING ' . $charsets[$i] . ')'; $tmp_literal = 'CONVERT(_utf8 ' . $tmp_literal . ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i];
} }
$enum_where .= $tmp_literal; $enum_where .= $tmp_literal;
unset($tmp_literal); unset($tmp_literal);
@@ -402,9 +402,9 @@ else {
} }
// Make query independant from the selected connection charset. // 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 '; $prefix = 'CONVERT(_utf8 ';
$suffix = ' USING ' . $charsets[$i] . ')'; $suffix = ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i];
} else { } else {
$prefix = $suffix = ''; $prefix = $suffix = '';
} }