diff --git a/ChangeLog b/ChangeLog index fea51b932..f5f3ffec7 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ phpMyAdmin - Changelog $Id$ $Source$ +2002-10-13 Robin Johnson + * libraries/sqlparser.lib.php3: bug #621357 + 2002-10-11 Marc Delisle * libraries/common.lib.php3: bug 620624 diff --git a/libraries/sqlparser.lib.php3 b/libraries/sqlparser.lib.php3 index f2644e423..90e8e9e50 100644 --- a/libraries/sqlparser.lib.php3 +++ b/libraries/sqlparser.lib.php3 @@ -32,6 +32,18 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { define('PMA_SQP_LIB_INCLUDED', 1); + if(defined('PMA_MULTIBYTE_ENCODING')) { + $GLOBALS['PMA_SQP_strlen'] = 'mb_strlen'; + $GLOBALS['PMA_SQP_strpos'] = 'mb_strpos'; + $GLOBALS['PMA_SQP_strrpos'] = 'mb_strrpos'; + $GLOBALS['PMA_SQP_substr'] = 'mb_substr'; + } else { + $GLOBALS['PMA_SQP_strlen'] = 'strlen'; + $GLOBALS['PMA_SQP_strpos'] = 'strpos'; + $GLOBALS['PMA_SQP_strrpos'] = 'strrpos'; + $GLOBALS['PMA_SQP_substr'] = 'substr'; + } + /** * Include the string library as we use it heavily */ @@ -169,7 +181,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { return $sql; } - $len = strlen($sql); + $len = $GLOBALS['PMA_SQP_strlen']($sql); if ($len == 0) { return array(); } @@ -234,18 +246,18 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $type = 'mysql'; case '-': $type = 'ansi'; - $pos = strpos($sql, "\n", $count2); + $pos = $GLOBALS['PMA_SQP_strpos']($sql, "\n", $count2); break; case '/': $type = 'c'; - $pos = strpos($sql, '*/', $count2); + $pos = $GLOBALS['PMA_SQP_strpos']($sql, '*/', $count2); $pos += 2; break; default: break; } // end switch $count2 = ($pos < $count2) ? $len : $pos; - $str = substr($sql, $count1, $count2 - $count1); + $str = $GLOBALS['PMA_SQP_substr']($sql, $count1, $count2 - $count1); PMA_SQP_arrayAdd($sql_array, 'comment_' . $type, $str, $arraysize); continue; } // end if @@ -261,7 +273,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $oldpos = 0; do { $oldpos = $pos; - $pos = strpos(' ' . $sql, $quotetype, $oldpos + 1) - 1; + $pos = $GLOBALS['PMA_SQP_strpos'](' ' . $sql, $quotetype, $oldpos + 1) - 1; // ($pos === FALSE) if ($pos < 0) { $debugstr = $GLOBALS['strSQPBugUnclosedQuote'] . ' @ ' . $startquotepos. "\n" @@ -305,7 +317,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { default: break; } // end switch - $data = substr($sql, $count1, $count2 - $count1); + $data = $GLOBALS['PMA_SQP_substr']($sql, $count1, $count2 - $count1); PMA_SQP_arrayAdd($sql_array, $type, $data, $arraysize); continue; } @@ -344,7 +356,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { if ($l == 1) { $punct_data = $c; } else { - $punct_data = substr($sql, $count1, $l); + $punct_data = $GLOBALS['PMA_SQP_substr']($sql, $count1, $l); } // Special case, sometimes, althought two characters are @@ -381,10 +393,10 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $punct_data = $first; } else if (($last2 == '/*') || ($last2 == '--')) { $count2 -= 2; - $punct_data = substr($sql, $count1, $count2 - $count1); + $punct_data = $GLOBALS['PMA_SQP_substr']($sql, $count1, $count2 - $count1); } else if (($last == '-') || ($last == '+') || ($last == '!')) { $count2--; - $punct_data = substr($sql, $count1, $count2 - $count1); + $punct_data = $GLOBALS['PMA_SQP_substr']($sql, $count1, $count2 - $count1); } else { $debugstr = $GLOBALS['strSQPBugUnknownPunctuation'] . ' @ ' . ($count1+1) . "\n" . 'STR: ' . $punct_data; @@ -423,7 +435,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { continue; } else { $debugstr = $GLOBALS['strSQPBugInvalidIdentifer'] . ' @ ' . ($count1+1) . "\n" - . 'STR: ' . substr($sql, $count1, $count2 - $count1); + . 'STR: ' . $GLOBALS['PMA_SQP_substr']($sql, $count1, $count2 - $count1); PMA_SQP_throwError($debugstr, $sql); return $sql; } @@ -451,7 +463,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { } // end while $l = $count2 - $count1; - $str = substr($sql, $count1, $l); + $str = $GLOBALS['PMA_SQP_substr']($sql, $count1, $l); $type = ''; if ($is_digit) { @@ -480,7 +492,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $count2++; $debugstr = 'C1 C2 LEN: ' . $count1 . ' ' . $count2 . ' ' . $len . "\n" - . 'STR: ' . substr($sql, $count1, $count2 - $count1) . "\n"; + . 'STR: ' . $GLOBALS['PMA_SQP_substr']($sql, $count1, $count2 - $count1) . "\n"; PMA_SQP_bug($debugstr, $sql); return $sql; @@ -488,38 +500,49 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { if ($arraysize > 0) { - $t_next = $sql_array[0]['type']; - $t_prev = ''; - $t_cur = ''; + $t_next = $sql_array[0]['type']; + $t_prev = ''; + $t_cur = ''; } for ($i = 0; $i < $arraysize; $i++) { - $t_prev = $t_cur; - $t_cur = $t_next; - if (($i + 1) < $arraysize) { - $t_next = $sql_array[$i + 1]['type']; + $t_prev = $t_cur; + $t_cur = $t_next; + if (($i + 1) < $arraysize) { + $t_next = $sql_array[$i + 1]['type']; + } else { + $t_next = ''; + } + if ($t_cur == 'alpha') { + $t_suffix = '_identifier'; + $d_cur_upper = strtoupper($sql_array[$i]['data']); + + if($d_cur_upper == 'SET') { + echo "T: $t_next\n"; + } + + if (($t_next == 'punct_qualifier') || ($t_prev == 'punct_qualifier')) { + $t_suffix = '_identifier'; + } else if (($t_next == 'punct_bracket_open_round') + && PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_function_name, $PMA_SQPdata_function_name_cnt)) { + $t_suffix = '_functionName'; + } else if (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_column_type, $PMA_SQPdata_column_type_cnt)) { + $t_suffix = '_columnType'; + //temporary fix for BUG #621357 + //TODO FIX PROPERLY NEEDS OVERHAUL OF SQL TOKENIZER + if($d_cur_upper == 'SET' && $t_next != 'punct_bracket_open_round') { + $t_suffix = '_reservedWord'; + } + //END OF TEMPORARY FIX + } else if (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_reserved_word, $PMA_SQPdata_reserved_word_cnt)) { + $t_suffix = '_reservedWord'; + } else if (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_column_attrib, $PMA_SQPdata_column_attrib_cnt)) { + $t_suffix = '_columnAttrib'; } else { - $t_next = ''; - } - if ($t_cur == 'alpha') { - $t_suffix = '_identifier'; - $d_cur_upper = strtoupper($sql_array[$i]['data']); - if (($t_next == 'punct_qualifier') || ($t_prev == 'punct_qualifier')) { - $t_suffix = '_identifier'; - } else if (($t_next == 'punct_bracket_open_round') - && PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_function_name, $PMA_SQPdata_function_name_cnt)) { - $t_suffix = '_functionName'; - } else if (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_reserved_word, $PMA_SQPdata_reserved_word_cnt)) { - $t_suffix = '_reservedWord'; - } else if (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_column_type, $PMA_SQPdata_column_type_cnt)) { - $t_suffix = '_columnType'; - } else if (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_column_attrib, $PMA_SQPdata_column_attrib_cnt)) { - $t_suffix = '_columnAttrib'; - } else { - // Do nothing - } - $sql_array[$i]['type'] .= $t_suffix; + // Do nothing } + $sql_array[$i]['type'] .= $t_suffix; + } } // Stores the size of the array inside the array, as count() is a slow @@ -634,10 +657,10 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { */ function PMA_SQP_formatHtml_colorize($arr) { - $i = strpos($arr['type'], '_'); + $i = $GLOBALS['PMA_SQP_strpos']($arr['type'], '_'); $class = ''; if ($i > 0) { - $class = 'syntax_' . substr($arr['type'], 0, $i) . ' '; + $class = 'syntax_' . $GLOBALS['PMA_SQP_substr']($arr['type'], 0, $i) . ' '; } $class .= 'syntax_' . $arr['type'];