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$
$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>
* libraries/config_import.lib.php3: Fixed a small inconsistance.
* 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
*/
$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

View File

@@ -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;

View File

@@ -970,7 +970,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
$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
@@ -983,9 +983,22 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
*
* @access public
*/
function PMA_SQP_formatHtml($arr)
function PMA_SQP_formatHtml($arr, $mode='color')
{
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;
$bracketlevel = 0;
$functionlevel = 0;
@@ -1084,7 +1097,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
$after .= ' ';
} else {
$indent++;
$after .= '<div class="syntax_indent' . $indent . '">';
$after .= ($mode != 'query_only' ? '<div class="syntax_indent' . $indent . '">' : ' ');
}
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 .= '<br />';
$after .= '<br />';
$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 .= '<br />';
$after .= $html_line_break;
break;
case 'punct':
$after .= ' ';
@@ -1132,7 +1145,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
$before .= ' ';
} else {
$indent--;
$before .= '</div>';
$before .= ($mode != 'query_only' ? '</div>' : ' ');
}
$infunction = ($functionlevel > 0) ? TRUE : FALSE;
break;
@@ -1163,7 +1176,7 @@ if (!defined('PMA_SQP_LIB_INCLUDED')) {
switch ($upper) {
case 'CREATE':
$space_punct_listsep = '<br />';
$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 = '<br />';
$space_punct_listsep = $html_line_break;
$space_alpha_reserved_word = ' ';
break;
case 'INSERT':
case 'REPLACE':
$space_punct_listsep = '<br />';
$space_alpha_reserved_word = '<br />';
$space_punct_listsep = $html_line_break;
$space_alpha_reserved_word = $html_line_break;
break;
case 'VALUES':
$space_punct_listsep = ' ';
$space_alpha_reserved_word = '<br />';
$space_alpha_reserved_word = $html_line_break;
break;
case 'SELECT':
$space_punct_listsep = ' ';
$space_alpha_reserved_word = '<br />';
$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
if ($mode=='color') {
$str .= '</span>';
}
return $str;
} // end of the "PMA_SQP_formatHtml()" function

View File

@@ -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);

View File

@@ -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');