Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
25816ff3ad
@ -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:
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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 </span> 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 '<span class="' . $class . '">'
|
||||
. htmlspecialchars($arr['data']) . '</span>';
|
||||
} // 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 = '<span class="syntax">';
|
||||
$html_line_break = '<br />';
|
||||
$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 .= '</span>';
|
||||
}
|
||||
if ($mode=='color') {
|
||||
// close syntax span
|
||||
$str .= '</span>';
|
||||
}
|
||||
|
||||
return $str;
|
||||
} // end of the "PMA_SQP_format()" function
|
||||
|
||||
@ -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(
|
||||
"<pre>\n$sql\n</pre>",
|
||||
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 = '<span class="syntax"><span class="inner_sql"><span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span></a> <span class="syntax_digit syntax_digit_integer">1</span> <span class="syntax_punct syntax_punct_queryend">;</span><br /><br /></span></span>';
|
||||
|
||||
$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 = '<span class="syntax"><span class="inner_sql"><span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span></a> <span class="syntax_punct">*</span> <br /><span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_quote syntax_quote_backtick">`tTable`</span> <span class="syntax_punct syntax_punct_queryend">;</span><br /><br /></span></span>';
|
||||
|
||||
$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 = '<span class="syntax"><span class="inner_sql"><span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span></a> <span class="syntax_punct">*</span> <br /><span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_quote syntax_quote_backtick">`tTable_A`</span> <span class="syntax_alpha syntax_alpha_identifier">A</span><br /><span class="syntax_alpha syntax_alpha_reservedWord">INNER</span> <span class="syntax_alpha syntax_alpha_reservedWord">JOIN</span> <span class="syntax_quote syntax_quote_backtick">`tTable_B`</span> <span class="syntax_alpha syntax_alpha_identifier">B</span> <span class="syntax_alpha syntax_alpha_reservedWord">ON</span> <span class="syntax_alpha syntax_alpha_identifier">B</span><span class="syntax_punct syntax_punct_qualifier">.</span><span class="syntax_alpha syntax_alpha_identifier">ID</span> <span class="syntax_punct">=</span></a> <span class="syntax_alpha syntax_alpha_identifier">A</span><span class="syntax_punct syntax_punct_qualifier">.</span><span class="syntax_alpha syntax_alpha_identifier">ID</span><span class="syntax_punct syntax_punct_queryend">;</span><br /><br /></span></span>';
|
||||
|
||||
$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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user