From 5fffdca3aa196253c1d32102eda437dda2a73ee9 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Thu, 30 May 2013 07:54:05 -0400 Subject: [PATCH] Parser: remove the color (html) mode --- doc/config.rst | 8 +- libraries/Util.class.php | 3 - libraries/sqlparser.lib.php | 43 +-- test/libraries/common/PMA_formatSql_test.php | 268 ------------------- 4 files changed, 6 insertions(+), 316 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index 4d9dee50b3..755b4a0bc0 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -2609,14 +2609,14 @@ SQL parser settings :type: string :default: ``'html'`` - The main use of the new :term:`SQL` Parser - is to pretty-print :term:`SQL` queries. By - default we use HTML to format the query, but you can disable this by + The main use of the :term:`SQL` Parser + is to format and analyze :term:`SQL` queries. By + default we use text to format the query, but you can disable this by setting this variable to ``'none'``. Available options: - * ``'html'`` + * ``'text'`` * ``'none'`` .. _cfg_SQP: diff --git a/libraries/Util.class.php b/libraries/Util.class.php index 110b683d23..5d4dd7fb05 100644 --- a/libraries/Util.class.php +++ b/libraries/Util.class.php @@ -404,9 +404,6 @@ class PMA_Util $formatted_sql = PMA_SQP_formatNone($parsed_sql); } break; - case 'html': - $formatted_sql = PMA_SQP_format($parsed_sql, 'color'); - break; case 'text': $formatted_sql = PMA_SQP_format($parsed_sql, 'text'); break; diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 5bdc8d096a..6321856015 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -1233,7 +1233,6 @@ function PMA_SQP_analyze($arr) * present in the list of forbidden words, for example * "storage" which can be used as an identifier * - * @todo avoid the pretty printing in color in this case */ $identifier = $arr[$i]['data']; break; @@ -2146,33 +2145,6 @@ function PMA_SQP_analyze($arr) } // end of the "PMA_SQP_analyze()" function -/** - * Colorizes SQL queries html formatted - * - * @param array $arr The SQL queries html formatted - * - * @return array The colorized SQL queries - * - * @todo check why adding a "\n" after the would cause extra blanks - * to be displayed: SELECT p . person_name - * - * @access public - */ -function PMA_SQP_formatHtml_colorize($arr) -{ - $i = PMA_strpos($arr['type'], '_'); - $class = ''; - if ($i > 0) { - $class = 'syntax_' . PMA_substr($arr['type'], 0, $i) . ' '; - } - - $class .= 'syntax_' . $arr['type']; - - return '' - . htmlspecialchars($arr['data']) . ''; -} // end of the "PMA_SQP_formatHtml_colorize()" function - - /** * Formats SQL queries * @@ -2186,7 +2158,7 @@ function PMA_SQP_formatHtml_colorize($arr) * @access public */ function PMA_SQP_format( - $arr, $mode='color', $start_token=0, + $arr, $mode='text', $start_token=0, $number_of_tokens=-1 ) { global $PMA_SQPdata_operators_docs, $PMA_SQPdata_functions_docs; @@ -2202,11 +2174,6 @@ function PMA_SQP_format( } // else do it properly switch ($mode) { - case 'color': - $str = ''; - $html_line_break = '
'; - $docu = true; - break; case 'query_only': $str = ''; $html_line_break = "\n"; @@ -2887,9 +2854,7 @@ function PMA_SQP_format( $after .= "\n"; */ $str .= $before; - if ($mode=='color') { - $str .= PMA_SQP_formatHtml_colorize($arr[$i]); - } elseif ($mode == 'text') { + if ($mode == 'text') { $str .= htmlspecialchars($arr[$i]['data']); } else { $str .= $arr[$i]['data']; @@ -2910,10 +2875,6 @@ function PMA_SQP_format( // close inner_sql span $str .= '
'; } - if ($mode=='color') { - // close syntax span - $str .= ''; - } return $str; } // end of the "PMA_SQP_format()" function diff --git a/test/libraries/common/PMA_formatSql_test.php b/test/libraries/common/PMA_formatSql_test.php index 35d887f69f..93712bcfed 100644 --- a/test/libraries/common/PMA_formatSql_test.php +++ b/test/libraries/common/PMA_formatSql_test.php @@ -44,243 +44,6 @@ class PMA_FormatSql_Test extends PHPUnit_Framework_TestCase $cfg = $this->tmpCfg; } - function testFormatSQLNotArray() - { - global $cfg; - $cfg['SQP']['fmtType'] = 'html'; - $sql = "SELECT * FROM tTable;"; - $this->assertEquals( - "
\n$sql\n
", - PMA_Util::formatSql($sql) - ); - } - - function testFormatSQLfmTypeHtml_1() - { - global $cfg; - $cfg['SQP']['fmtType'] = 'html'; - $cfg['MySQLManualType'] = 'none'; - - $sql = array ( - 'raw' => 'SELECT 1;', - 0 => - array ( - 'type' => 'alpha_reservedWord', - 'data' => 'SELECT', - 'pos' => 6, - 'forbidden' => true, - ), - 1 => - array ( - 'type' => 'digit_integer', - 'data' => '1', - 'pos' => 8, - ), - 2 => - array ( - 'type' => 'punct_queryend', - 'data' => ';', - 'pos' => 0, - ), - 'len' => 3, - ); - $unparsed = "SELECT 1;"; - $expected = 'SELECT 1 ;

'; - - $this->assertEquals( - $expected, - PMA_Util::formatSql($sql, $unparsed) - ); - } - - function testFormatSQLfmTypeHtml_2() - { - global $cfg; - $cfg['SQP']['fmtType'] = 'html'; - $cfg['MySQLManualType'] = 'none'; - - $unparsed = "SELECT * from `tTable`;"; - $sql = array ( - 'raw' => $unparsed, - 0 => - array ( - 'type' => 'alpha_reservedWord', - 'data' => 'SELECT', - 'pos' => 6, - 'forbidden' => true, - ), - 1 => - array ( - 'type' => 'punct', - 'data' => '*', - 'pos' => 0, - ), - 2 => - array ( - 'type' => 'alpha_reservedWord', - 'data' => 'from', - 'pos' => 13, - 'forbidden' => true, - ), - 3 => - array ( - 'type' => 'quote_backtick', - 'data' => '`tTable`', - 'pos' => 0, - ), - 4 => - array ( - 'type' => 'punct_queryend', - 'data' => ';', - 'pos' => 0, - ), - 'len' => 5, - ); - $expected = 'SELECT *
FROM `tTable` ;

'; - - $this->assertEquals( - $expected, PMA_Util::formatSql($sql, $unparsed) - ); - } - - function testFormatSQLfmTypeHtml_3() - { - global $cfg; - $cfg['SQP']['fmtType'] = 'html'; - $cfg['MySQLManualType'] = 'none'; - - $unparsed = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;'; - $sql = array ( - 'raw' => $unparsed, - 0 => - array ( - 'type' => 'alpha_reservedWord', - 'data' => 'SELECT', - 'pos' => 6, - 'forbidden' => true, - ), - 1 => - array ( - 'type' => 'punct', - 'data' => '*', - 'pos' => 0, - ), - 2 => - array ( - 'type' => 'alpha_reservedWord', - 'data' => 'FROM', - 'pos' => 13, - 'forbidden' => true, - ), - 3 => - array ( - 'type' => 'quote_backtick', - 'data' => '`tTable_A`', - 'pos' => 0, - ), - 4 => - array ( - 'type' => 'alpha_identifier', - 'data' => 'A', - 'pos' => 26, - 'forbidden' => false, - ), - 5 => - array ( - 'type' => 'alpha_reservedWord', - 'data' => 'INNER', - 'pos' => 32, - 'forbidden' => true, - ), - 6 => - array ( - 'type' => 'alpha_reservedWord', - 'data' => 'JOIN', - 'pos' => 37, - 'forbidden' => true, - ), - 7 => - array ( - 'type' => 'quote_backtick', - 'data' => '`tTable_B`', - 'pos' => 0, - ), - 8 => - array ( - 'type' => 'alpha_identifier', - 'data' => 'B', - 'pos' => 50, - 'forbidden' => false, - ), - 9 => - array ( - 'type' => 'alpha_reservedWord', - 'data' => 'ON', - 'pos' => 53, - 'forbidden' => true, - ), - 10 => - array ( - 'type' => 'alpha_identifier', - 'data' => 'B', - 'pos' => 55, - 'forbidden' => false, - ), - 11 => - array ( - 'type' => 'punct_qualifier', - 'data' => '.', - 'pos' => 0, - ), - 12 => - array ( - 'type' => 'alpha_identifier', - 'data' => 'ID', - 'pos' => 58, - 'forbidden' => false, - ), - 13 => - array ( - 'type' => 'punct', - 'data' => '=', - 'pos' => 0, - ), - 14 => - array ( - 'type' => 'alpha_identifier', - 'data' => 'A', - 'pos' => 62, - 'forbidden' => false, - ), - 15 => - array ( - 'type' => 'punct_qualifier', - 'data' => '.', - 'pos' => 0, - ), - 16 => - array ( - 'type' => 'alpha_identifier', - 'data' => 'ID', - 'pos' => 65, - 'forbidden' => false, - ), - 17 => - array ( - 'type' => 'punct_queryend', - 'data' => ';', - 'pos' => 0, - ), - 'len' => 18, - ); - - $expected = 'SELECT *
FROM `tTable_A` A
INNER JOIN `tTable_B` B ON B.ID = A.ID;

'; - - $this->assertEquals( - $expected, PMA_Util::formatSql($sql, $unparsed) - ); - } - function testFormatSQLfmTypeText_1() { global $cfg; @@ -744,37 +507,6 @@ class PMA_FormatSql_Test extends PHPUnit_Framework_TestCase ); } - function testFormatSQLWithoutType() - { - global $cfg; - $cfg['SQP']['fmtType'] = ''; - $cfg['MySQLManualType'] = 'none'; - $sql = array ( - 'raw' => 'SELECT 1;', - 0 => - array ( - 'type' => 'alpha_reservedWord', - 'data' => 'SELECT', - 'pos' => 6, - 'forbidden' => true, - ), - 1 => - array ( - 'type' => 'digit_integer', - 'data' => '1', - 'pos' => 8, - ), - 2 => - array ( - 'type' => 'punct_queryend', - 'data' => ';', - 'pos' => 0, - ), - 'len' => 3, - ); - $this->assertEmpty(PMA_Util::formatSql($sql)); - } - function testFormatSQLError() { global $SQP_errorString;