Merge branch 'master' of ssh://phpmyadmin.git.sourceforge.net/gitroot/phpmyadmin/phpmyadmin
This commit is contained in:
@@ -1039,6 +1039,9 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', $is_view
|
|||||||
} else {
|
} else {
|
||||||
// Parse SQL if needed
|
// Parse SQL if needed
|
||||||
$parsed_sql = PMA_SQP_parse($query_base);
|
$parsed_sql = PMA_SQP_parse($query_base);
|
||||||
|
if (PMA_SQP_isError()) {
|
||||||
|
unset($parsed_sql);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Analyze it
|
// Analyze it
|
||||||
|
@@ -717,10 +717,6 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $
|
|||||||
$GLOBALS['mime_map'] = PMA_getMIME($db, $table);
|
$GLOBALS['mime_map'] = PMA_getMIME($db, $table);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($is_display['sort_lnk'] == '1') {
|
|
||||||
$select_expr = $analyzed_sql[0]['select_expr_clause'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// See if we have to highlight any header fields of a WHERE query.
|
// See if we have to highlight any header fields of a WHERE query.
|
||||||
// Uses SQL-Parser results.
|
// Uses SQL-Parser results.
|
||||||
$highlight_columns = array();
|
$highlight_columns = array();
|
||||||
@@ -2094,7 +2090,7 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
|
|||||||
'submit_mult_change', __('Change'), 'b_edit.png');
|
'submit_mult_change', __('Change'), 'b_edit.png');
|
||||||
PMA_buttonOrImage('submit_mult', 'mult_submit',
|
PMA_buttonOrImage('submit_mult', 'mult_submit',
|
||||||
'submit_mult_delete', $delete_text, 'b_drop.png');
|
'submit_mult_delete', $delete_text, 'b_drop.png');
|
||||||
if ($analyzed_sql[0]['querytype'] == 'SELECT') {
|
if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
|
||||||
PMA_buttonOrImage('submit_mult', 'mult_submit',
|
PMA_buttonOrImage('submit_mult', 'mult_submit',
|
||||||
'submit_mult_export', __('Export'),
|
'submit_mult_export', __('Export'),
|
||||||
'b_tblexport.png');
|
'b_tblexport.png');
|
||||||
|
@@ -43,7 +43,9 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
|||||||
* Include data for the SQL Parser
|
* Include data for the SQL Parser
|
||||||
*/
|
*/
|
||||||
require_once './libraries/sqlparser.data.php';
|
require_once './libraries/sqlparser.data.php';
|
||||||
require_once './libraries/mysql_charsets.lib.php';
|
if (!defined('TESTSUITE')) {
|
||||||
|
require_once './libraries/mysql_charsets.lib.php';
|
||||||
|
}
|
||||||
if (!isset($mysql_charsets)) {
|
if (!isset($mysql_charsets)) {
|
||||||
$mysql_charsets = array();
|
$mysql_charsets = array();
|
||||||
$mysql_charsets_count = 0;
|
$mysql_charsets_count = 0;
|
||||||
|
181
test/PMA_SQL_parser_test.php
Normal file
181
test/PMA_SQL_parser_test.php
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
<?php
|
||||||
|
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||||
|
/**
|
||||||
|
* tests for correctness of SQL parser
|
||||||
|
*
|
||||||
|
* @package phpMyAdmin-test
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests core.
|
||||||
|
*/
|
||||||
|
require_once 'PHPUnit/Framework.php';
|
||||||
|
|
||||||
|
define('PHPMYADMIN', 1);
|
||||||
|
define('TESTSUITE', 1);
|
||||||
|
$GLOBALS['charset'] = 'utf-8';
|
||||||
|
|
||||||
|
function __($s) {
|
||||||
|
return $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Include to test.
|
||||||
|
*/
|
||||||
|
require_once './libraries/sqlparser.lib.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for SQL parser
|
||||||
|
*
|
||||||
|
* @package phpMyAdmin-test
|
||||||
|
*/
|
||||||
|
class PMA_SQL_parser_test extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
private function assertParser($sql, $expected, $error = '')
|
||||||
|
{
|
||||||
|
$parsed_sql = PMA_SQP_parse($sql);
|
||||||
|
$this->assertEquals(PMA_SQP_getErrorString(), $error);
|
||||||
|
$this->assertEquals($parsed_sql, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testParse_1()
|
||||||
|
{
|
||||||
|
$this->assertParser('SELECT 1;', 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,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testParse_2()
|
||||||
|
{
|
||||||
|
$this->assertParser('SELECT * from aaa;', array (
|
||||||
|
'raw' => 'SELECT * from aaa;',
|
||||||
|
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' => 'alpha_identifier',
|
||||||
|
'data' => 'aaa',
|
||||||
|
'pos' => 17,
|
||||||
|
'forbidden' => false,
|
||||||
|
),
|
||||||
|
4 =>
|
||||||
|
array (
|
||||||
|
'type' => 'punct_queryend',
|
||||||
|
'data' => ';',
|
||||||
|
'pos' => 0,
|
||||||
|
),
|
||||||
|
'len' => 5,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testParse_3()
|
||||||
|
{
|
||||||
|
$this->assertParser('SELECT * from `aaa`;', array (
|
||||||
|
'raw' => 'SELECT * from `aaa`;',
|
||||||
|
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' => '`aaa`',
|
||||||
|
'pos' => 0,
|
||||||
|
),
|
||||||
|
4 =>
|
||||||
|
array (
|
||||||
|
'type' => 'punct_queryend',
|
||||||
|
'data' => ';',
|
||||||
|
'pos' => 0,
|
||||||
|
),
|
||||||
|
'len' => 5,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testParse_4()
|
||||||
|
{
|
||||||
|
$this->assertParser('SELECT * from `aaa;', array (
|
||||||
|
'raw' => 'SELECT * from `aaa;',
|
||||||
|
0 =>
|
||||||
|
array (
|
||||||
|
'type' => 'alpha',
|
||||||
|
'data' => 'SELECT',
|
||||||
|
'pos' => 6,
|
||||||
|
),
|
||||||
|
1 =>
|
||||||
|
array (
|
||||||
|
'type' => 'punct',
|
||||||
|
'data' => '*',
|
||||||
|
'pos' => 0,
|
||||||
|
),
|
||||||
|
2 =>
|
||||||
|
array (
|
||||||
|
'type' => 'alpha',
|
||||||
|
'data' => 'from',
|
||||||
|
'pos' => 13,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'<p>There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem</p>
|
||||||
|
<pre>
|
||||||
|
ERROR: Unclosed quote @ 14
|
||||||
|
STR: `
|
||||||
|
SQL: SELECT * from `aaa;
|
||||||
|
</pre>
|
||||||
|
');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
Reference in New Issue
Block a user