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.

This commit is contained in:
Robin Johnson
2002-11-08 22:20:23 +00:00
parent 466579cce1
commit 703be1753e
6 changed files with 55 additions and 25 deletions

View File

@@ -5,6 +5,11 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2002-11-08 Robin Johnson <robbat2@users.sourceforge.net>
* 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 <rabus@users.sourceforge.net> 2002-11-07 Alexander M. Turek <rabus@users.sourceforge.net>
* libraries/config_import.lib.php3: Fixed a small inconsistance. * libraries/config_import.lib.php3: Fixed a small inconsistance.
* config.inc.php3: Added a note about bug #634931. * config.inc.php3: Added a note about bug #634931.

View File

@@ -375,7 +375,7 @@ $cfg['UploadDir'] = ''; // for example, './upload/'; you mus
* SQL Parser Settings * SQL Parser Settings
*/ */
$cfg['SQP']['enable'] = TRUE; // Totally turn off the SQL Parser (not recommended) $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']['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']['fmtIndUnit'] = 'em'; // Units for indenting each level (CSS Types - {em,px,pt})
$cfg['SQP']['fmtColor'] = array( // Syntax colouring data $cfg['SQP']['fmtColor'] = array( // Syntax colouring data

View File

@@ -280,10 +280,11 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold}
$formatted_sql = PMA_SQP_formatNone($parsed_sql); $formatted_sql = PMA_SQP_formatNone($parsed_sql);
break; break;
case 'html': case 'html':
$formatted_sql = PMA_SQP_formatHtml($parsed_sql); $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'color');
break; break;
case 'text': 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; break;
default: default:
break; break;

View File

@@ -970,7 +970,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
$class .= 'syntax_' . $arr['type']; $class .= 'syntax_' . $arr['type'];
return '<span class="' . $class . '">' . htmlspecialchars($arr['data']) . '</span>'; return '<span class="' . $class . '">' . htmlspecialchars($arr['data']) . '</span>' . "\n";
} // end of the "PMA_SQP_formatHtml_colorize()" function } // end of the "PMA_SQP_formatHtml_colorize()" function
@@ -983,9 +983,22 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
* *
* @access public * @access public
*/ */
function PMA_SQP_formatHtml($arr) function PMA_SQP_formatHtml($arr, $mode='color')
{ {
$str = '<span class="syntax">'; switch ($mode) {
case 'color':
$str = '<span class="syntax">';
$html_line_break = '<br />';
break;
case 'query_only':
$str = '';
$html_line_break = ' ';
break;
case 'text':
$str = '';
$html_line_break = '<br />';
break;
} // end switch
$indent = 0; $indent = 0;
$bracketlevel = 0; $bracketlevel = 0;
$functionlevel = 0; $functionlevel = 0;
@@ -1084,7 +1097,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
$after .= ' '; $after .= ' ';
} else { } else {
$indent++; $indent++;
$after .= '<div class="syntax_indent' . $indent . '">'; $after .= ($mode != 'query_only' ? '<div class="syntax_indent' . $indent . '">' : ' ');
} }
break; break;
case 'alpha_identifier': case 'alpha_identifier':
@@ -1109,8 +1122,8 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
break; break;
case 'punct_queryend': case 'punct_queryend':
if (($typearr[3] != 'comment_mysql') && ($typearr[3] != 'comment_ansi')) { if (($typearr[3] != 'comment_mysql') && ($typearr[3] != 'comment_ansi')) {
$after .= '<br />'; $after .= $html_line_break;
$after .= '<br />'; $after .= $html_line_break;
} }
$space_punct_listsep = ' '; $space_punct_listsep = ' ';
$space_punct_listsep_function_name = ' '; $space_punct_listsep_function_name = ' ';
@@ -1118,7 +1131,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
break; break;
case 'comment_mysql': case 'comment_mysql':
case 'comment_ansi': case 'comment_ansi':
$after .= '<br />'; $after .= $html_line_break;
break; break;
case 'punct': case 'punct':
$after .= ' '; $after .= ' ';
@@ -1132,7 +1145,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
$before .= ' '; $before .= ' ';
} else { } else {
$indent--; $indent--;
$before .= '</div>'; $before .= ($mode != 'query_only' ? '</div>' : ' ');
} }
$infunction = ($functionlevel > 0) ? TRUE : FALSE; $infunction = ($functionlevel > 0) ? TRUE : FALSE;
break; break;
@@ -1163,7 +1176,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
switch ($upper) { switch ($upper) {
case 'CREATE': case 'CREATE':
$space_punct_listsep = '<br />'; $space_punct_listsep = $html_line_break;
$space_alpha_reserved_word = ' '; $space_alpha_reserved_word = ' ';
break; break;
case 'EXPLAIN': case 'EXPLAIN':
@@ -1177,21 +1190,21 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
case 'TRUNCATE': case 'TRUNCATE':
case 'ANALYZE': case 'ANALYZE':
case 'ANALYSE': case 'ANALYSE':
$space_punct_listsep = '<br />'; $space_punct_listsep = $html_line_break;
$space_alpha_reserved_word = ' '; $space_alpha_reserved_word = ' ';
break; break;
case 'INSERT': case 'INSERT':
case 'REPLACE': case 'REPLACE':
$space_punct_listsep = '<br />'; $space_punct_listsep = $html_line_break;
$space_alpha_reserved_word = '<br />'; $space_alpha_reserved_word = $html_line_break;
break; break;
case 'VALUES': case 'VALUES':
$space_punct_listsep = ' '; $space_punct_listsep = ' ';
$space_alpha_reserved_word = '<br />'; $space_alpha_reserved_word = $html_line_break;
break; break;
case 'SELECT': case 'SELECT':
$space_punct_listsep = ' '; $space_punct_listsep = ' ';
$space_alpha_reserved_word = '<br />'; $space_alpha_reserved_word = $html_line_break;
break; break;
default: default:
break; break;
@@ -1231,9 +1244,11 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
} }
$after .= "\n"; $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 } // end for
$str .= '</span>'; if ($mode=='color') {
$str .= '</span>';
}
return $str; return $str;
} // end of the "PMA_SQP_formatHtml()" function } // end of the "PMA_SQP_formatHtml()" function

View File

@@ -37,6 +37,7 @@ if (!isset($err_url)) {
/** /**
* dead function, to be removed:
* SK -- Patch * SK -- Patch
* *
* Does some preliminary formatting of the $sql_query to avoid problems with * 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'; $replace = ' ' . $w . ' (\\1) \\2';
$sql_str = substr(eregi_replace($pattern, $replace, ' ' . $sql_str), 1); $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); $sql_str = substr(eregi_replace('[[:space:]]' . $w . '[[:space:]]', ' ' . $w . ' ', ' ' . $sql_str), 1);
} // end while } // end while
@@ -125,8 +126,11 @@ if (isset($btnDrop) || isset($navig)) {
// SK -- Patch : Reformats query - adds spaces when omitted and removes extra // SK -- Patch : Reformats query - adds spaces when omitted and removes extra
// spaces; converts reserved words to uppercase // 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 // 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. // $db and $table, to have correct page headers, links and left frame.
@@ -516,8 +520,8 @@ else {
$dontlimitchars = 0; $dontlimitchars = 0;
} }
$parsed_sql = PMA_SQP_parse($sql_query); //$parsed_sql = PMA_SQP_parse($sql_query);
$analyzed_sql = PMA_SQP_analyze($parsed_sql); //$analyzed_sql = PMA_SQP_analyze($parsed_sql);
PMA_displayTable($result, $disp_mode, $analyzed_sql); PMA_displayTable($result, $disp_mode, $analyzed_sql);
mysql_free_result($result); mysql_free_result($result);

View File

@@ -2,7 +2,6 @@
/* $Id$ */ /* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4: // vim: expandtab sw=4 ts=4 sts=4:
/** /**
* Insert datas from one table to another one * 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'); include('./libraries/build_dump.lib.php3');
$sql_structure = PMA_getTableDef($db, $table, "\n", $err_url); $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); $result = @PMA_mysql_query($sql_structure);
if (PMA_mysql_error()) { if (PMA_mysql_error()) {
include('./header.inc.php3'); include('./header.inc.php3');