From 5e8e47072ec3d88c0e77f41764679efd8862544c Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Sat, 10 Oct 2015 15:53:23 +0300 Subject: [PATCH 1/2] Partial fix for #11558. Updated sql-parser library to udan11/sql-parser@42c34ddd1fee261da43331e855c80bc432d66247 (v3.0.3). Signed-off-by: Dan Ungureanu --- .../sql-parser/src/Components/Condition.php | 1 + .../src/Components/PartitionDefinition.php | 1 - libraries/sql-parser/src/Context.php | 2 +- libraries/sql-parser/src/Lexer.php | 2 +- libraries/sql-parser/src/Statement.php | 23 +++++++++++++++++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/libraries/sql-parser/src/Components/Condition.php b/libraries/sql-parser/src/Components/Condition.php index b33b0c3b4a..d7262c5978 100644 --- a/libraries/sql-parser/src/Components/Condition.php +++ b/libraries/sql-parser/src/Components/Condition.php @@ -40,6 +40,7 @@ class Condition extends Component public static $OPERATORS = array( 'AND' => 1, 'BETWEEN' => 1, + 'EXISTS' => 1, 'IN' => 1, 'IS' => 1, 'LIKE' => 1, diff --git a/libraries/sql-parser/src/Components/PartitionDefinition.php b/libraries/sql-parser/src/Components/PartitionDefinition.php index bc30f61f02..8c54e22f83 100644 --- a/libraries/sql-parser/src/Components/PartitionDefinition.php +++ b/libraries/sql-parser/src/Components/PartitionDefinition.php @@ -10,7 +10,6 @@ */ namespace SqlParser\Components; -use SqlParser\Context; use SqlParser\Component; use SqlParser\Parser; use SqlParser\Token; diff --git a/libraries/sql-parser/src/Context.php b/libraries/sql-parser/src/Context.php index 5cbf6a1abb..40cd93470b 100644 --- a/libraries/sql-parser/src/Context.php +++ b/libraries/sql-parser/src/Context.php @@ -524,5 +524,5 @@ abstract class Context } } -// Initialing the default context. +// Initializing the default context. Context::load(); diff --git a/libraries/sql-parser/src/Lexer.php b/libraries/sql-parser/src/Lexer.php index 9e99b60c86..8c609db08f 100644 --- a/libraries/sql-parser/src/Lexer.php +++ b/libraries/sql-parser/src/Lexer.php @@ -171,7 +171,7 @@ class Lexer */ public static function getTokens($str, $strict = false, $delimiter = null) { - $lexer = new Lexer($str); + $lexer = new Lexer($str, $strict, $delimiter); return $lexer->list; } diff --git a/libraries/sql-parser/src/Statement.php b/libraries/sql-parser/src/Statement.php index 3fe3f42c1d..b15dc3dac9 100644 --- a/libraries/sql-parser/src/Statement.php +++ b/libraries/sql-parser/src/Statement.php @@ -108,6 +108,20 @@ abstract class Statement */ $query = ''; + /** + * Clauses which were built already. + * + * It is required to keep track of built clauses because some fields, + * for example `join` is used by multiple clauses (`JOIN`, `LEFT JOIN`, + * `LEFT OUTER JOIN`, etc.). The same happens for `VALUE` and `VALUES`. + * + * A clause is considered built just after fields' value + * (`$this->field`) was used in building. + * + * @var array + */ + $built = array(); + foreach (static::$CLAUSES as $clause) { /** * The name of the clause. @@ -144,6 +158,15 @@ abstract class Statement continue; } + // Checking if this field was already built. + if ($type & 1) { + if (!empty($built[$field])) { + continue; + } + + $built[$field] = true; + } + // Checking if the name of the clause should be added. if ($type & 2) { $query .= $name . ' '; From 2b315a413f59c9eeb76c2212c00ec78f69473931 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sat, 10 Oct 2015 09:52:31 -0400 Subject: [PATCH 2/2] ChangeLog entry Signed-off-by: Marc Delisle --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 5dd6453194..ba9be8311c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,7 @@ phpMyAdmin - ChangeLog - issue #11546 "Visualize GIS data" seems to be broken - issue #11548 Confirm box on "Reset slave" option - issue Fix cookies clearing on version change +- issue #11558 Cannot execute SQL with subquery (fix for part 1) 4.5.0.2 (2015-09-25) - issue #11497 Incorrect indexes when exporting