SQL parser now correctly works with multibyte strings (bug #936161).

This commit is contained in:
Michal Čihař
2004-04-29 09:28:04 +00:00
parent 51fc2da513
commit cfbdb563d0
5 changed files with 27 additions and 23 deletions

View File

@@ -5,6 +5,11 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2004-04-29 Michal Cihar <michal@cihar.com>
* libraries/display_tbl.lib.php, libraries/sqlparser.lib.php,
libraries/string.lib.php, libraries/dbi/mysql.dbi.lib.php: SQL parser
now correctly works with multibyte strings (bug #936161).
2004-04-28 Michal Cihar <michal@cihar.com> 2004-04-28 Michal Cihar <michal@cihar.com>
* css/phpmyadmin.css.php: Force <button> to be displayed inline. * css/phpmyadmin.css.php: Force <button> to be displayed inline.
* libraries/common.lib.php: When only_db matches no database, do not show * libraries/common.lib.php: When only_db matches no database, do not show

View File

@@ -245,7 +245,7 @@ function PMA_DBI_get_fields_meta($result) {
$fields = array(); $fields = array();
$num_fields = mysql_num_fields($result); $num_fields = mysql_num_fields($result);
for ($i = 0; $i < $num_fields; $i++) { for ($i = 0; $i < $num_fields; $i++) {
$fields[] = mysql_fetch_field($result, $i); $fields[] = PMA_convert_display_charset(mysql_fetch_field($result, $i));
} }
return $fields; return $fields;
} }

View File

@@ -817,7 +817,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $
// 2.1.5 Displays the sorting url // 2.1.5 Displays the sorting url
$order_link_pre = '<a href="sql.php?' . $url_query . '" ' . (($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') ? 'style="direction: ltr; writing-mode: tb-rl;"' : '') . ' title="' . $GLOBALS['strSort'] . '"' . '>'; $order_link_pre = '<a href="sql.php?' . $url_query . '" ' . (($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') ? 'style="direction: ltr; writing-mode: tb-rl;"' : '') . ' title="' . $GLOBALS['strSort'] . '"' . '>';
$order_link_post = '</a>'; $order_link_post = '</a>';
$order_link_content = ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars(PMA_convert_display_charset($fields_meta[$i]->name)), "<br />\n") : htmlspecialchars(PMA_convert_display_charset($fields_meta[$i]->name))); $order_link_content = ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
$order_link_words = explode(' ', $order_link_content); $order_link_words = explode(' ', $order_link_content);
if (isset($order_link_words[1])) { if (isset($order_link_words[1])) {
$order_last_word_index = count($order_link_words)-1; $order_last_word_index = count($order_link_words)-1;
@@ -853,7 +853,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $
?> ?>
<th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?> <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ? 'style="direction: ltr; writing-mode: tb-rl;"' : ''); ?>> <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?> <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ? 'style="direction: ltr; writing-mode: tb-rl;"' : ''); ?>>
<?php echo $comments_table_wrap_pre; ?> <?php echo $comments_table_wrap_pre; ?>
<?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(PMA_convert_display_charset(htmlspecialchars($fields_meta[$i]->name)), "<br />\n") : htmlspecialchars(PMA_convert_display_charset($fields_meta[$i]->name))) . "\n"; ?> <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?>
<?php echo $comments_table_wrap_post; ?> <?php echo $comments_table_wrap_post; ?>
</th> </th>
<?php <?php

View File

@@ -246,7 +246,7 @@ if ($is_minimum_common == FALSE) {
$arraysize = 0; $arraysize = 0;
while ($count2 < $len) { while ($count2 < $len) {
$c = $sql[$count2]; $c = PMA_substr($sql, $count2, 1);
$count1 = $count2; $count1 = $count2;
if (($c == "\n")) { if (($c == "\n")) {
@@ -266,9 +266,9 @@ if ($is_minimum_common == FALSE) {
// C style /* */ // C style /* */
// ANSI style -- // ANSI style --
if (($c == '#') if (($c == '#')
|| (($count2 + 1 < $len) && ($c == '/') && ($sql[$count2 + 1] == '*')) || (($count2 + 1 < $len) && ($c == '/') && (PMA_substr($sql, $count2 + 1, 1) == '*'))
|| (($count2 + 2 == $len) && ($c == '-') && ($sql[$count2 + 1] == '-')) || (($count2 + 2 == $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-'))
|| (($count2 + 2 < $len) && ($c == '-') && ($sql[$count2 + 1] == '-') && (($sql[$count2 + 2] == ' ') || ($sql[$count2 + 2] == "\n")))) { || (($count2 + 2 < $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-') && ((PMA_substr($sql, $count2 + 2, 1) == ' ') || (PMA_substr($sql, $count2 + 2, 1) == "\n")))) {
$count2++; $count2++;
$pos = 0; $pos = 0;
$type = 'bad'; $type = 'bad';
@@ -324,7 +324,7 @@ if ($is_minimum_common == FALSE) {
if (($pos < $len) && PMA_STR_charIsEscaped($sql, $pos)) { if (($pos < $len) && PMA_STR_charIsEscaped($sql, $pos)) {
$pos ++; $pos ++;
continue; continue;
} else if (($pos + 1 < $len) && ($sql[$pos] == $quotetype) && ($sql[$pos + 1] == $quotetype)) { } else if (($pos + 1 < $len) && (PMA_substr($sql, $pos, 1) == $quotetype) && (PMA_substr($sql, $pos + 1, 1) == $quotetype)) {
$pos = $pos + 2; $pos = $pos + 2;
continue; continue;
} else { } else {
@@ -380,7 +380,7 @@ if ($is_minimum_common == FALSE) {
// Checks for punct // Checks for punct
if (PMA_STR_strInStr($c, $allpunct_list)) { if (PMA_STR_strInStr($c, $allpunct_list)) {
while (($count2 < $len) && PMA_STR_strInStr($sql[$count2], $allpunct_list)) { while (($count2 < $len) && PMA_STR_strInStr(PMA_substr($sql, $count2, 1), $allpunct_list)) {
$count2++; $count2++;
} }
$l = $count2 - $count1; $l = $count2 - $count1;
@@ -455,7 +455,7 @@ if ($is_minimum_common == FALSE) {
$is_sql_variable = ($c == '@'); $is_sql_variable = ($c == '@');
$is_digit = (!$is_sql_variable) && PMA_STR_isDigit($c); $is_digit = (!$is_sql_variable) && PMA_STR_isDigit($c);
$is_hex_digit = ($is_digit) && ($c == '0') && ($count2 < $len) && ($sql[$count2] == 'x'); $is_hex_digit = ($is_digit) && ($c == '0') && ($count2 < $len) && (PMA_substr($sql, $count2, 1) == 'x');
$is_float_digit = FALSE; $is_float_digit = FALSE;
$is_float_digit_exponent = FALSE; $is_float_digit_exponent = FALSE;
@@ -463,8 +463,8 @@ if ($is_minimum_common == FALSE) {
$count2++; $count2++;
} }
while (($count2 < $len) && PMA_STR_isSqlIdentifier($sql[$count2], ($is_sql_variable || $is_digit))) { while (($count2 < $len) && PMA_STR_isSqlIdentifier(PMA_substr($sql, $count2, 1), ($is_sql_variable || $is_digit))) {
$c2 = $sql[$count2]; $c2 = PMA_substr($sql, $count2, 1);
if ($is_sql_variable && ($c2 == '.')) { if ($is_sql_variable && ($c2 == '.')) {
$count2++; $count2++;
continue; continue;

View File

@@ -14,9 +14,14 @@
* *
* The SQL Parser code relies heavily on these functions. * The SQL Parser code relies heavily on these functions.
*/ */
$GLOBALS['PMA_allow_mbstr'] = @function_exists('mb_strlen') && substr($GLOBALS['charset'], 0, 8) != 'windows-';
if ($GLOBALS['PMA_allow_mbstr']) {
mb_internal_encoding($GLOBALS['charset']);
}
// This is for handling input better // This is for handling input better
if (defined('PMA_MULTIBYTE_ENCODING')) { if (defined('PMA_MULTIBYTE_ENCODING') || $GLOBALS['PMA_allow_mbstr']) {
$GLOBALS['PMA_strpos'] = 'mb_strpos'; $GLOBALS['PMA_strpos'] = 'mb_strpos';
$GLOBALS['PMA_strrpos'] = 'mb_strrpos'; $GLOBALS['PMA_strrpos'] = 'mb_strrpos';
} else { } else {
@@ -24,8 +29,6 @@ if (defined('PMA_MULTIBYTE_ENCODING')) {
$GLOBALS['PMA_strrpos'] = 'strrpos'; $GLOBALS['PMA_strrpos'] = 'strrpos';
} }
$GLOBALS['PMA_has_mbstr'] = @function_exists('mb_strlen');
/** /**
* Returns length of string depending on current charset. * Returns length of string depending on current charset.
* *
@@ -39,11 +42,9 @@ $GLOBALS['PMA_has_mbstr'] = @function_exists('mb_strlen');
*/ */
function PMA_strlen($string) function PMA_strlen($string)
{ {
if (defined('PMA_MULTIBYTE_ENCODING')) {
return mb_strlen($string);
// windows-* charsets are not multibyte and not supported by mb_* // windows-* charsets are not multibyte and not supported by mb_*
} elseif($GLOBALS['PMA_has_mbstr'] && substr($GLOBALS['charset'],0,8) != 'windows-') { if (defined('PMA_MULTIBYTE_ENCODING') || $GLOBALS['PMA_allow_mbstr']) {
return mb_strlen($string, $GLOBALS['charset']); return mb_strlen($string);
} else { } else {
return strlen($string); return strlen($string);
} }
@@ -56,7 +57,7 @@ function PMA_strlen($string)
* @param int start of substring * @param int start of substring
* @param int length of substring * @param int length of substring
* *
* @return int string length * @return int substring
* *
* @access public * @access public
* *
@@ -64,10 +65,8 @@ function PMA_strlen($string)
*/ */
function PMA_substr($string, $start, $length = 2147483647) function PMA_substr($string, $start, $length = 2147483647)
{ {
if (defined('PMA_MULTIBYTE_ENCODING')) { if (defined('PMA_MULTIBYTE_ENCODING') || $GLOBALS['PMA_allow_mbstr']) {
return mb_substr($string, $start, $length); return mb_substr($string, $start, $length);
} elseif($GLOBALS['PMA_has_mbstr'] && substr($GLOBALS['charset'],0,8) != 'windows-') {
return mb_substr($string, $start, $length, $GLOBALS['charset']);
} else { } else {
return substr($string, $start, $length); return substr($string, $start, $length);
} }