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$
$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>
* sql.php: Don't try to require sql.php with parameters, rather redirect
to it.

View File

@@ -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 . ' '

View File

@@ -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) {
@@ -168,6 +168,7 @@ function PMA_DBI_postConnect($link) {
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);
$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 :)

View File

@@ -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) {
?>
<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="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>
</tr>
<?php
@@ -349,10 +346,13 @@ else {
if (trim($where) != '') {
$sql_query .= ' WHERE ' . $where;
} else {
$w = array();
$w = $charsets = array();
$cnt_func = count($func);
reset($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) {
$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 = '';
}