diff --git a/ChangeLog b/ChangeLog index 475b5d068..a46611d5c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ phpMyAdmin - Changelog $Id$ $Source$ +2002-11-08 Robin Johnson + * config.inc.php3 sql.php3 tbl_move_copy.php3 libraries/common.lib.php3 + libraries/sqlparser.lib.php3: Committed Marc's patches to the SQL parser + and pretty printer from bugs #605030 and #631421. + 2002-11-07 Alexander M. Turek * libraries/config_import.lib.php3: Fixed a small inconsistance. * config.inc.php3: Added a note about bug #634931. diff --git a/config.inc.php3 b/config.inc.php3 index 3b6080a0d..108101d46 100755 --- a/config.inc.php3 +++ b/config.inc.php3 @@ -375,7 +375,7 @@ $cfg['UploadDir'] = ''; // for example, './upload/'; you mus * SQL Parser Settings */ $cfg['SQP']['enable'] = TRUE; // Totally turn off the SQL Parser (not recommended) -$cfg['SQP']['fmtType'] = 'html'; // Pretty-printing style to use on queries (html, none) +$cfg['SQP']['fmtType'] = 'html'; // Pretty-printing style to use on queries (html, text, none) $cfg['SQP']['fmtInd'] = '1'; // Amount to indent each level (floats ok) $cfg['SQP']['fmtIndUnit'] = 'em'; // Units for indenting each level (CSS Types - {em,px,pt}) $cfg['SQP']['fmtColor'] = array( // Syntax colouring data diff --git a/libraries/common.lib.php3 b/libraries/common.lib.php3 index 5fb0e8df8..0d24f4037 100644 --- a/libraries/common.lib.php3 +++ b/libraries/common.lib.php3 @@ -280,10 +280,11 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold} $formatted_sql = PMA_SQP_formatNone($parsed_sql); break; case 'html': - $formatted_sql = PMA_SQP_formatHtml($parsed_sql); + $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'color'); break; case 'text': - $formatted_sql = PMA_SQP_formatText($parsed_sql); + //$formatted_sql = PMA_SQP_formatText($parsed_sql); + $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'text'); break; default: break; diff --git a/libraries/sqlparser.lib.php3 b/libraries/sqlparser.lib.php3 index 0d65da413..8ae7d76ab 100644 --- a/libraries/sqlparser.lib.php3 +++ b/libraries/sqlparser.lib.php3 @@ -970,7 +970,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $class .= 'syntax_' . $arr['type']; - return '' . htmlspecialchars($arr['data']) . ''; + return '' . htmlspecialchars($arr['data']) . '' . "\n"; } // end of the "PMA_SQP_formatHtml_colorize()" function @@ -983,9 +983,22 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { * * @access public */ - function PMA_SQP_formatHtml($arr) + function PMA_SQP_formatHtml($arr, $mode='color') { - $str = ''; + switch ($mode) { + case 'color': + $str = ''; + $html_line_break = '
'; + break; + case 'query_only': + $str = ''; + $html_line_break = ' '; + break; + case 'text': + $str = ''; + $html_line_break = '
'; + break; + } // end switch $indent = 0; $bracketlevel = 0; $functionlevel = 0; @@ -1084,7 +1097,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $after .= ' '; } else { $indent++; - $after .= '
'; + $after .= ($mode != 'query_only' ? '
' : ' '); } break; case 'alpha_identifier': @@ -1109,8 +1122,8 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { break; case 'punct_queryend': if (($typearr[3] != 'comment_mysql') && ($typearr[3] != 'comment_ansi')) { - $after .= '
'; - $after .= '
'; + $after .= $html_line_break; + $after .= $html_line_break; } $space_punct_listsep = ' '; $space_punct_listsep_function_name = ' '; @@ -1118,7 +1131,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { break; case 'comment_mysql': case 'comment_ansi': - $after .= '
'; + $after .= $html_line_break; break; case 'punct': $after .= ' '; @@ -1132,7 +1145,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { $before .= ' '; } else { $indent--; - $before .= '
'; + $before .= ($mode != 'query_only' ? '
' : ' '); } $infunction = ($functionlevel > 0) ? TRUE : FALSE; break; @@ -1163,7 +1176,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { switch ($upper) { case 'CREATE': - $space_punct_listsep = '
'; + $space_punct_listsep = $html_line_break; $space_alpha_reserved_word = ' '; break; case 'EXPLAIN': @@ -1177,21 +1190,21 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { case 'TRUNCATE': case 'ANALYZE': case 'ANALYSE': - $space_punct_listsep = '
'; + $space_punct_listsep = $html_line_break; $space_alpha_reserved_word = ' '; break; case 'INSERT': case 'REPLACE': - $space_punct_listsep = '
'; - $space_alpha_reserved_word = '
'; + $space_punct_listsep = $html_line_break; + $space_alpha_reserved_word = $html_line_break; break; case 'VALUES': $space_punct_listsep = ' '; - $space_alpha_reserved_word = '
'; + $space_alpha_reserved_word = $html_line_break; break; case 'SELECT': $space_punct_listsep = ' '; - $space_alpha_reserved_word = '
'; + $space_alpha_reserved_word = $html_line_break; break; default: break; @@ -1231,9 +1244,11 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) { } $after .= "\n"; */ - $str .= $before . PMA_SQP_formatHTML_colorize($arr[$i]) . $after; + $str .= $before . ($mode=='color' ? PMA_SQP_formatHTML_colorize($arr[$i]) : $arr[$i]['data']). $after; } // end for - $str .= '
'; + if ($mode=='color') { + $str .= '
'; + } return $str; } // end of the "PMA_SQP_formatHtml()" function diff --git a/sql.php3 b/sql.php3 index 159edba67..eab67f9bf 100755 --- a/sql.php3 +++ b/sql.php3 @@ -37,6 +37,7 @@ if (!isset($err_url)) { /** + * dead function, to be removed: * SK -- Patch * * Does some preliminary formatting of the $sql_query to avoid problems with @@ -65,7 +66,7 @@ function PMA_sqlFormat($sql_str) { $replace = ' ' . $w . ' (\\1) \\2'; $sql_str = substr(eregi_replace($pattern, $replace, ' ' . $sql_str), 1); - // Converts reservered words to upper case if not yet done + // Converts reserved words to upper case if not yet done $sql_str = substr(eregi_replace('[[:space:]]' . $w . '[[:space:]]', ' ' . $w . ' ', ' ' . $sql_str), 1); } // end while @@ -125,8 +126,11 @@ if (isset($btnDrop) || isset($navig)) { // SK -- Patch : Reformats query - adds spaces when omitted and removes extra // spaces; converts reserved words to uppercase -$sql_query = PMA_sqlFormat($sql_query); +//$sql_query = PMA_sqlFormat($sql_query); +$parsed_sql = PMA_SQP_parse((get_magic_quotes_gpc() ? stripslashes($sql_query) : $sql_query)); +$analyzed_sql = PMA_SQP_analyze($parsed_sql); +$sql_query = PMA_SQP_formatHtml($parsed_sql, 'query_only'); // If the query is a Select, extract the db and table names and modify // $db and $table, to have correct page headers, links and left frame. @@ -516,8 +520,8 @@ else { $dontlimitchars = 0; } - $parsed_sql = PMA_SQP_parse($sql_query); - $analyzed_sql = PMA_SQP_analyze($parsed_sql); + //$parsed_sql = PMA_SQP_parse($sql_query); + //$analyzed_sql = PMA_SQP_analyze($parsed_sql); PMA_displayTable($result, $disp_mode, $analyzed_sql); mysql_free_result($result); diff --git a/tbl_move_copy.php3 b/tbl_move_copy.php3 index 6a7173029..1175881ae 100644 --- a/tbl_move_copy.php3 +++ b/tbl_move_copy.php3 @@ -2,7 +2,6 @@ /* $Id$ */ // vim: expandtab sw=4 ts=4 sts=4: - /** * Insert datas from one table to another one * @@ -81,7 +80,13 @@ if (isset($new_name) && trim($new_name) != '') { include('./libraries/build_dump.lib.php3'); $sql_structure = PMA_getTableDef($db, $table, "\n", $err_url); - $sql_structure = eregi_replace('^CREATE TABLE (`?)' . $table . '(`?)', 'CREATE TABLE ' . $target, $sql_structure); + $parsed_sql = PMA_SQP_parse($sql_structure); + // no need to PMA_backquote() + $parsed_sql[2]['data'] = $target; + $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only'); + +// $sql_structure = eregi_replace('^CREATE TABLE (`?)' . $table . '(`?)', 'CREATE TABLE ' . $target, $sql_structure); + $result = @PMA_mysql_query($sql_structure); if (PMA_mysql_error()) { include('./header.inc.php3');