From aa19ffde328eeca98e68aab940035cbed01e04dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 3 Oct 2016 16:05:44 +0200 Subject: [PATCH] Update SQL parser to 3.4.9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - issue #12316 Correct export of complex SELECT statements - issue #12080 Fixed parsing of subselect queries - issue #11740 Fixed handling DELETE ... USING queries - issue #12100 Fixed handling of CASE operator Signed-off-by: Michal Čihař --- ChangeLog | 4 + libraries/sql-parser/src/Component.php | 3 +- .../src/Components/AlterOperation.php | 3 +- .../sql-parser/src/Components/Array2d.php | 3 +- .../sql-parser/src/Components/ArrayObj.php | 3 +- .../src/Components/CaseExpression.php | 250 ++++++++++++++++ .../sql-parser/src/Components/Condition.php | 3 +- .../src/Components/CreateDefinition.php | 3 +- .../sql-parser/src/Components/DataType.php | 3 +- .../sql-parser/src/Components/Expression.php | 3 +- .../src/Components/ExpressionArray.php | 17 +- .../src/Components/FunctionCall.php | 3 +- .../sql-parser/src/Components/IntoKeyword.php | 38 ++- .../sql-parser/src/Components/JoinKeyword.php | 11 +- libraries/sql-parser/src/Components/Key.php | 3 +- libraries/sql-parser/src/Components/Limit.php | 9 +- .../src/Components/OptionsArray.php | 3 +- .../src/Components/OrderKeyword.php | 3 +- .../src/Components/ParameterDefinition.php | 3 +- .../src/Components/PartitionDefinition.php | 3 +- .../sql-parser/src/Components/Reference.php | 3 +- .../src/Components/RenameOperation.php | 3 +- .../src/Components/SetOperation.php | 3 +- .../src/Components/UnionKeyword.php | 3 +- libraries/sql-parser/src/Context.php | 3 +- .../src/Contexts/ContextMySql50000.php | 3 +- .../src/Contexts/ContextMySql50100.php | 3 +- .../src/Contexts/ContextMySql50500.php | 3 +- .../src/Contexts/ContextMySql50600.php | 3 +- .../src/Contexts/ContextMySql50700.php | 3 +- .../src/Exceptions/LexerException.php | 3 +- .../src/Exceptions/ParserException.php | 3 +- libraries/sql-parser/src/Lexer.php | 3 +- libraries/sql-parser/src/Parser.php | 5 +- libraries/sql-parser/src/Statement.php | 3 +- .../src/Statements/AlterStatement.php | 3 +- .../src/Statements/AnalyzeStatement.php | 3 +- .../src/Statements/BackupStatement.php | 3 +- .../src/Statements/CallStatement.php | 3 +- .../src/Statements/CheckStatement.php | 3 +- .../src/Statements/ChecksumStatement.php | 3 +- .../src/Statements/CreateStatement.php | 3 +- .../src/Statements/DeleteStatement.php | 273 ++++++++++++++++-- .../src/Statements/DropStatement.php | 3 +- .../src/Statements/ExplainStatement.php | 3 +- .../src/Statements/InsertStatement.php | 9 +- .../src/Statements/MaintenanceStatement.php | 3 +- .../Statements/NotImplementedStatement.php | 3 +- .../src/Statements/OptimizeStatement.php | 3 +- .../src/Statements/RenameStatement.php | 3 +- .../src/Statements/RepairStatement.php | 3 +- .../src/Statements/ReplaceStatement.php | 9 +- .../src/Statements/RestoreStatement.php | 3 +- .../src/Statements/SelectStatement.php | 5 +- .../src/Statements/SetStatement.php | 3 +- .../src/Statements/ShowStatement.php | 3 +- .../src/Statements/TransactionStatement.php | 3 +- .../src/Statements/TruncateStatement.php | 3 +- .../src/Statements/UpdateStatement.php | 3 +- libraries/sql-parser/src/Token.php | 3 +- libraries/sql-parser/src/TokensList.php | 3 +- libraries/sql-parser/src/UtfString.php | 3 +- .../sql-parser/src/Utils/BufferedQuery.php | 3 +- libraries/sql-parser/src/Utils/CLI.php | 3 +- libraries/sql-parser/src/Utils/Error.php | 3 +- libraries/sql-parser/src/Utils/Formatter.php | 3 +- libraries/sql-parser/src/Utils/Misc.php | 3 +- libraries/sql-parser/src/Utils/Query.php | 3 +- libraries/sql-parser/src/Utils/Routine.php | 3 +- libraries/sql-parser/src/Utils/Table.php | 3 +- libraries/sql-parser/src/Utils/Tokens.php | 3 +- 71 files changed, 630 insertions(+), 180 deletions(-) create mode 100644 libraries/sql-parser/src/Components/CaseExpression.php diff --git a/ChangeLog b/ChangeLog index 9fab505888..64eb7ae992 100644 --- a/ChangeLog +++ b/ChangeLog @@ -48,6 +48,10 @@ phpMyAdmin - ChangeLog - issue #12508 Remove duplicate code in SQL escaping - issue #12475 Cleanup code for getting table information - issue #12579 phpMyAdmin's export of a Select statment without a FROM clause generates Wrong SQL +- issue #12316 Correct export of complex SELECT statements +- issue #12080 Fixed parsing of subselect queries +- issue #11740 Fixed handling DELETE ... USING queries +- issue #12100 Fixed handling of CASE operator 4.6.4 (2016-08-16) - issue [security] Weaknesses with cookie encryption, see PMASA-2016-29 diff --git a/libraries/sql-parser/src/Component.php b/libraries/sql-parser/src/Component.php index 2e406c5c7b..08720cfa14 100644 --- a/libraries/sql-parser/src/Component.php +++ b/libraries/sql-parser/src/Component.php @@ -20,8 +20,7 @@ require_once 'common.php'; * * @category Components * @package SqlParser - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ abstract class Component { diff --git a/libraries/sql-parser/src/Components/AlterOperation.php b/libraries/sql-parser/src/Components/AlterOperation.php index 3481e985df..c2344c607f 100644 --- a/libraries/sql-parser/src/Components/AlterOperation.php +++ b/libraries/sql-parser/src/Components/AlterOperation.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Components * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class AlterOperation extends Component { diff --git a/libraries/sql-parser/src/Components/Array2d.php b/libraries/sql-parser/src/Components/Array2d.php index a46813b081..2199efe1d4 100644 --- a/libraries/sql-parser/src/Components/Array2d.php +++ b/libraries/sql-parser/src/Components/Array2d.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Keywords * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Array2d extends Component { diff --git a/libraries/sql-parser/src/Components/ArrayObj.php b/libraries/sql-parser/src/Components/ArrayObj.php index 627f8c750e..bed7fc7391 100644 --- a/libraries/sql-parser/src/Components/ArrayObj.php +++ b/libraries/sql-parser/src/Components/ArrayObj.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Components * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ArrayObj extends Component { diff --git a/libraries/sql-parser/src/Components/CaseExpression.php b/libraries/sql-parser/src/Components/CaseExpression.php new file mode 100644 index 0000000000..d33f532f58 --- /dev/null +++ b/libraries/sql-parser/src/Components/CaseExpression.php @@ -0,0 +1,250 @@ +idx; // Skip 'CASE' + + for (; $list->idx < $list->count; ++$list->idx) { + + /** + * Token parsed at this moment. + * + * @var Token $token + */ + $token = $list->tokens[$list->idx]; + + // Skipping whitespaces and comments. + if (($token->type === Token::TYPE_WHITESPACE) + || ($token->type === Token::TYPE_COMMENT) + ) { + continue; + } + + if ($state === 0) { + if ($token->type === Token::TYPE_KEYWORD + && $token->value === 'WHEN' + ) { + ++$list->idx; // Skip 'WHEN' + $new_condition = Condition::parse($parser, $list); + $type = 1; + $state = 1; + $ret->conditions[] = $new_condition; + } elseif ($token->type === Token::TYPE_KEYWORD + && $token->value === 'ELSE' + ) { + ++$list->idx; // Skip 'ELSE' + $ret->else_result = Expression::parse($parser, $list); + $state = 0; // last clause of CASE expression + } elseif ($token->type === Token::TYPE_KEYWORD + && ($token->value === 'END' + || $token->value === 'end') + ) { + $state = 3; // end of CASE expression + ++$list->idx; + break; + } elseif ($token->type === Token::TYPE_KEYWORD) { + $parser->error(__('Unexpected keyword.'), $token); + break; + } else { + $ret->value = Expression::parse($parser, $list); + $type = 0; + $state = 1; + } + } elseif ($state === 1) { + if ($type === 0) { + if ($token->type === Token::TYPE_KEYWORD + && $token->value === 'WHEN' + ) { + ++$list->idx; // Skip 'WHEN' + $new_value = Expression::parse($parser, $list); + $state = 2; + $ret->compare_values[] = $new_value; + } elseif ($token->type === Token::TYPE_KEYWORD + && $token->value === 'ELSE' + ) { + ++$list->idx; // Skip 'ELSE' + $ret->else_result = Expression::parse($parser, $list); + $state = 0; // last clause of CASE expression + } elseif ($token->type === Token::TYPE_KEYWORD + && ($token->value === 'END' + || $token->value === 'end') + ) { + $state = 3; // end of CASE expression + ++$list->idx; + break; + } elseif ($token->type === Token::TYPE_KEYWORD) { + $parser->error(__('Unexpected keyword.'), $token); + break; + } + } else { + if ($token->type === Token::TYPE_KEYWORD + && $token->value === 'THEN' + ) { + ++$list->idx; // Skip 'THEN' + $new_result = Expression::parse($parser, $list); + $state = 0; + $ret->results[] = $new_result; + } elseif ($token->type === Token::TYPE_KEYWORD) { + $parser->error(__('Unexpected keyword.'), $token); + break; + } + } + } elseif ($state === 2) { + if ($type === 0) { + if ($token->type === Token::TYPE_KEYWORD + && $token->value === 'THEN' + ) { + ++$list->idx; // Skip 'THEN' + $new_result = Expression::parse($parser, $list); + $ret->results[] = $new_result; + $state = 1; + } elseif ($token->type === Token::TYPE_KEYWORD) { + $parser->error(__('Unexpected keyword.'), $token); + break; + } + } + } + } + + if ($state !== 3) { + $parser->error( + __('Unexpected end of CASE expression'), + $list->tokens[$list->idx - 1] + ); + } + + --$list->idx; + return $ret; + } + + /** + * @param Expression $component The component to be built. + * @param array $options Parameters for building. + * + * @return string + */ + public static function build($component, array $options = array()) + { + $ret = 'CASE '; + if (isset($component->value)) { + // Syntax type 0 + $ret .= $component->value . ' '; + for ( + $i = 0; + $i < count($component->compare_values) && $i < count($component->results); + ++$i + ) { + $ret .= 'WHEN ' . $component->compare_values[$i] . ' '; + $ret .= 'THEN ' . $component->results[$i] . ' '; + } + } else { + // Syntax type 1 + for ( + $i = 0; + $i < count($component->conditions) && $i < count($component->results); + ++$i + ) { + $ret .= 'WHEN ' . Condition::build($component->conditions[$i]) . ' '; + $ret .= 'THEN ' . $component->results[$i] . ' '; + } + } + if (isset($component->else_result)) { + $ret .= 'ELSE ' . $component->else_result . ' '; + } + $ret .= 'END'; + + return $ret; + } +} diff --git a/libraries/sql-parser/src/Components/Condition.php b/libraries/sql-parser/src/Components/Condition.php index cb1a5f8af5..c69441aa35 100644 --- a/libraries/sql-parser/src/Components/Condition.php +++ b/libraries/sql-parser/src/Components/Condition.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Keywords * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Condition extends Component { diff --git a/libraries/sql-parser/src/Components/CreateDefinition.php b/libraries/sql-parser/src/Components/CreateDefinition.php index 6e302d08d1..0ef8a31160 100644 --- a/libraries/sql-parser/src/Components/CreateDefinition.php +++ b/libraries/sql-parser/src/Components/CreateDefinition.php @@ -24,8 +24,7 @@ use SqlParser\TokensList; * @category Components * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CreateDefinition extends Component { diff --git a/libraries/sql-parser/src/Components/DataType.php b/libraries/sql-parser/src/Components/DataType.php index aac40ee3fa..378ec9d88e 100644 --- a/libraries/sql-parser/src/Components/DataType.php +++ b/libraries/sql-parser/src/Components/DataType.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Components * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class DataType extends Component { diff --git a/libraries/sql-parser/src/Components/Expression.php b/libraries/sql-parser/src/Components/Expression.php index 592207bf24..1ca05968c8 100644 --- a/libraries/sql-parser/src/Components/Expression.php +++ b/libraries/sql-parser/src/Components/Expression.php @@ -22,8 +22,7 @@ use SqlParser\TokensList; * @category Components * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Expression extends Component { diff --git a/libraries/sql-parser/src/Components/ExpressionArray.php b/libraries/sql-parser/src/Components/ExpressionArray.php index f108ad8002..e2aa86eb1a 100644 --- a/libraries/sql-parser/src/Components/ExpressionArray.php +++ b/libraries/sql-parser/src/Components/ExpressionArray.php @@ -1,7 +1,7 @@ - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ExpressionArray extends Component { @@ -73,13 +72,21 @@ class ExpressionArray extends Component && ((~$token->flags & Token::FLAG_KEYWORD_FUNCTION)) && ($token->value !== 'DUAL') && ($token->value !== 'NULL') + && ($token->value !== 'CASE') ) { // No keyword is expected. break; } if ($state === 0) { - $expr = Expression::parse($parser, $list, $options); + if ($token->type === Token::TYPE_KEYWORD + && $token->value === 'CASE' + ) { + $expr = CaseExpression::parse($parser, $list, $options); + } else { + $expr = Expression::parse($parser, $list, $options); + } + if ($expr === null) { break; } diff --git a/libraries/sql-parser/src/Components/FunctionCall.php b/libraries/sql-parser/src/Components/FunctionCall.php index 9d2dfed5d8..e260532bb8 100644 --- a/libraries/sql-parser/src/Components/FunctionCall.php +++ b/libraries/sql-parser/src/Components/FunctionCall.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Keywords * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class FunctionCall extends Component { diff --git a/libraries/sql-parser/src/Components/IntoKeyword.php b/libraries/sql-parser/src/Components/IntoKeyword.php index 783ac3cdb3..d90963db76 100644 --- a/libraries/sql-parser/src/Components/IntoKeyword.php +++ b/libraries/sql-parser/src/Components/IntoKeyword.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Keywords * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class IntoKeyword extends Component { @@ -46,6 +45,13 @@ class IntoKeyword extends Component */ public $columns; + /** + * The values to be selected into (SELECT .. INTO @var1) + * + * @var ExpressionArray + */ + public $values; + /** * @param Parser $parser The parser that serves as context. * @param TokensList $list The list of tokens that are being parsed. @@ -103,14 +109,22 @@ class IntoKeyword extends Component } if ($state === 0) { - $ret->dest = Expression::parse( - $parser, - $list, - array( - 'parseField' => 'table', - 'breakOnAlias' => true, - ) - ); + if ((isset($options['fromInsert']) + && $options['fromInsert']) + || (isset($options['fromReplace']) + && $options['fromReplace']) + ) { + $ret->dest = Expression::parse( + $parser, + $list, + array( + 'parseField' => 'table', + 'breakOnAlias' => true, + ) + ); + } else { + $ret->values = ExpressionArray::parse($parser, $list); + } $state = 1; } elseif ($state === 1) { if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) { @@ -141,8 +155,10 @@ class IntoKeyword extends Component $columns = !empty($component->columns) ? '(`' . implode('`, `', $component->columns) . '`)' : ''; return $component->dest . $columns; + } elseif (isset($component->values)) { + return ExpressionArray::build($component->values); } else { return 'OUTFILE "' . $component->dest . '"'; } } -} +} \ No newline at end of file diff --git a/libraries/sql-parser/src/Components/JoinKeyword.php b/libraries/sql-parser/src/Components/JoinKeyword.php index e7f62a6ff8..7062783c30 100644 --- a/libraries/sql-parser/src/Components/JoinKeyword.php +++ b/libraries/sql-parser/src/Components/JoinKeyword.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Keywords * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class JoinKeyword extends Component { @@ -147,6 +146,9 @@ class JoinKeyword extends Component $state = 3; } elseif ($token->value === 'USING') { $state = 4; + } else { + /* Next clause is starting */ + break; } } } elseif ($state === 3) { @@ -183,8 +185,9 @@ class JoinKeyword extends Component foreach ($component as $c) { $ret[] = array_search($c->type, static::$JOINS) . ' ' . $c->expr . (!empty($c->on) - ? ' ON ' . Condition::build($c->on) - : ' USING ' . ArrayObj::build($c->using)); + ? ' ON ' . Condition::build($c->on) : '') + . (!empty($c->using) + ? ' USING ' . ArrayObj::build($c->using) : ''); } return implode(' ', $ret); } diff --git a/libraries/sql-parser/src/Components/Key.php b/libraries/sql-parser/src/Components/Key.php index ef066dd179..24cc363290 100644 --- a/libraries/sql-parser/src/Components/Key.php +++ b/libraries/sql-parser/src/Components/Key.php @@ -22,8 +22,7 @@ use SqlParser\TokensList; * @category Components * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Key extends Component { diff --git a/libraries/sql-parser/src/Components/Limit.php b/libraries/sql-parser/src/Components/Limit.php index 30881dcbef..13a11277fb 100644 --- a/libraries/sql-parser/src/Components/Limit.php +++ b/libraries/sql-parser/src/Components/Limit.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Keywords * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Limit extends Component { @@ -127,10 +126,6 @@ class Limit extends Component */ public static function build($component, array $options = array()) { - if (empty($component->offset)) { - return (string) $component->rowCount; - } else { - return $component->offset . ', ' . $component->rowCount; - } + return $component->offset . ', ' . $component->rowCount; } } diff --git a/libraries/sql-parser/src/Components/OptionsArray.php b/libraries/sql-parser/src/Components/OptionsArray.php index 684e5cc12d..0c80e0d742 100644 --- a/libraries/sql-parser/src/Components/OptionsArray.php +++ b/libraries/sql-parser/src/Components/OptionsArray.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Components * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class OptionsArray extends Component { diff --git a/libraries/sql-parser/src/Components/OrderKeyword.php b/libraries/sql-parser/src/Components/OrderKeyword.php index 7d23013836..ba773a8496 100644 --- a/libraries/sql-parser/src/Components/OrderKeyword.php +++ b/libraries/sql-parser/src/Components/OrderKeyword.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Keywords * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class OrderKeyword extends Component { diff --git a/libraries/sql-parser/src/Components/ParameterDefinition.php b/libraries/sql-parser/src/Components/ParameterDefinition.php index aea8f9c199..274555e938 100644 --- a/libraries/sql-parser/src/Components/ParameterDefinition.php +++ b/libraries/sql-parser/src/Components/ParameterDefinition.php @@ -20,8 +20,7 @@ use SqlParser\TokensList; * @category Components * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ParameterDefinition extends Component { diff --git a/libraries/sql-parser/src/Components/PartitionDefinition.php b/libraries/sql-parser/src/Components/PartitionDefinition.php index 85342d7050..33c369287a 100644 --- a/libraries/sql-parser/src/Components/PartitionDefinition.php +++ b/libraries/sql-parser/src/Components/PartitionDefinition.php @@ -23,8 +23,7 @@ use SqlParser\TokensList; * @category Components * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class PartitionDefinition extends Component { diff --git a/libraries/sql-parser/src/Components/Reference.php b/libraries/sql-parser/src/Components/Reference.php index 7acd92e042..24d633ca90 100644 --- a/libraries/sql-parser/src/Components/Reference.php +++ b/libraries/sql-parser/src/Components/Reference.php @@ -20,8 +20,7 @@ use SqlParser\TokensList; * @category Keywords * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Reference extends Component { diff --git a/libraries/sql-parser/src/Components/RenameOperation.php b/libraries/sql-parser/src/Components/RenameOperation.php index c0ecf6c01b..291bd43011 100644 --- a/libraries/sql-parser/src/Components/RenameOperation.php +++ b/libraries/sql-parser/src/Components/RenameOperation.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Keywords * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class RenameOperation extends Component { diff --git a/libraries/sql-parser/src/Components/SetOperation.php b/libraries/sql-parser/src/Components/SetOperation.php index ffe754aef5..0a1a54ca9a 100644 --- a/libraries/sql-parser/src/Components/SetOperation.php +++ b/libraries/sql-parser/src/Components/SetOperation.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Keywords * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class SetOperation extends Component { diff --git a/libraries/sql-parser/src/Components/UnionKeyword.php b/libraries/sql-parser/src/Components/UnionKeyword.php index 6286cd0542..138a79e51a 100644 --- a/libraries/sql-parser/src/Components/UnionKeyword.php +++ b/libraries/sql-parser/src/Components/UnionKeyword.php @@ -17,8 +17,7 @@ use SqlParser\Statements\SelectStatement; * @category Keywords * @package SqlParser * @subpackage Components - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class UnionKeyword extends Component { diff --git a/libraries/sql-parser/src/Context.php b/libraries/sql-parser/src/Context.php index a62fa16b9e..0bdc6960db 100644 --- a/libraries/sql-parser/src/Context.php +++ b/libraries/sql-parser/src/Context.php @@ -15,8 +15,7 @@ namespace SqlParser; * * @category Contexts * @package SqlParser - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ abstract class Context { diff --git a/libraries/sql-parser/src/Contexts/ContextMySql50000.php b/libraries/sql-parser/src/Contexts/ContextMySql50000.php index d9a254479b..4931faa1ff 100644 --- a/libraries/sql-parser/src/Contexts/ContextMySql50000.php +++ b/libraries/sql-parser/src/Contexts/ContextMySql50000.php @@ -19,8 +19,7 @@ use SqlParser\Context; * @category Contexts * @package SqlParser * @subpackage Contexts - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMySql50000 extends Context { diff --git a/libraries/sql-parser/src/Contexts/ContextMySql50100.php b/libraries/sql-parser/src/Contexts/ContextMySql50100.php index ffa8ad8cc9..a547e6405d 100644 --- a/libraries/sql-parser/src/Contexts/ContextMySql50100.php +++ b/libraries/sql-parser/src/Contexts/ContextMySql50100.php @@ -19,8 +19,7 @@ use SqlParser\Context; * @category Contexts * @package SqlParser * @subpackage Contexts - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMySql50100 extends Context { diff --git a/libraries/sql-parser/src/Contexts/ContextMySql50500.php b/libraries/sql-parser/src/Contexts/ContextMySql50500.php index ed64233200..a15744a8b0 100644 --- a/libraries/sql-parser/src/Contexts/ContextMySql50500.php +++ b/libraries/sql-parser/src/Contexts/ContextMySql50500.php @@ -19,8 +19,7 @@ use SqlParser\Context; * @category Contexts * @package SqlParser * @subpackage Contexts - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMySql50500 extends Context { diff --git a/libraries/sql-parser/src/Contexts/ContextMySql50600.php b/libraries/sql-parser/src/Contexts/ContextMySql50600.php index 4a2c132528..7a0cf56234 100644 --- a/libraries/sql-parser/src/Contexts/ContextMySql50600.php +++ b/libraries/sql-parser/src/Contexts/ContextMySql50600.php @@ -19,8 +19,7 @@ use SqlParser\Context; * @category Contexts * @package SqlParser * @subpackage Contexts - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMySql50600 extends Context { diff --git a/libraries/sql-parser/src/Contexts/ContextMySql50700.php b/libraries/sql-parser/src/Contexts/ContextMySql50700.php index 1b6eb9c18c..8682032dc3 100644 --- a/libraries/sql-parser/src/Contexts/ContextMySql50700.php +++ b/libraries/sql-parser/src/Contexts/ContextMySql50700.php @@ -19,8 +19,7 @@ use SqlParser\Context; * @category Contexts * @package SqlParser * @subpackage Contexts - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMySql50700 extends Context { diff --git a/libraries/sql-parser/src/Exceptions/LexerException.php b/libraries/sql-parser/src/Exceptions/LexerException.php index 3bbc0c72cd..2dd30412e6 100644 --- a/libraries/sql-parser/src/Exceptions/LexerException.php +++ b/libraries/sql-parser/src/Exceptions/LexerException.php @@ -14,8 +14,7 @@ namespace SqlParser\Exceptions; * @category Exceptions * @package SqlParser * @subpackage Exceptions - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class LexerException extends \Exception { diff --git a/libraries/sql-parser/src/Exceptions/ParserException.php b/libraries/sql-parser/src/Exceptions/ParserException.php index 5a9fac0442..81f6259304 100644 --- a/libraries/sql-parser/src/Exceptions/ParserException.php +++ b/libraries/sql-parser/src/Exceptions/ParserException.php @@ -16,8 +16,7 @@ use SqlParser\Token; * @category Exceptions * @package SqlParser * @subpackage Exceptions - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ParserException extends \Exception { diff --git a/libraries/sql-parser/src/Lexer.php b/libraries/sql-parser/src/Lexer.php index 8c609db08f..7fb2356d76 100644 --- a/libraries/sql-parser/src/Lexer.php +++ b/libraries/sql-parser/src/Lexer.php @@ -38,8 +38,7 @@ if (!defined('USE_UTF_STRINGS')) { * * @category Lexer * @package SqlParser - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ * @see Context */ class Lexer diff --git a/libraries/sql-parser/src/Parser.php b/libraries/sql-parser/src/Parser.php index e37b36374b..21e1b395f9 100644 --- a/libraries/sql-parser/src/Parser.php +++ b/libraries/sql-parser/src/Parser.php @@ -21,8 +21,7 @@ use SqlParser\Statements\TransactionStatement; * * @category Parser * @package SqlParser - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Parser { @@ -163,7 +162,7 @@ class Parser 'FROM' => array( 'class' => 'SqlParser\\Components\\ExpressionArray', 'field' => 'from', - 'options' => array('parseField' => 'table'), + 'options' => array('field' => 'table'), ), 'GROUP BY' => array( 'class' => 'SqlParser\\Components\\OrderKeyword', diff --git a/libraries/sql-parser/src/Statement.php b/libraries/sql-parser/src/Statement.php index 9f3341ea25..c23db67bb5 100644 --- a/libraries/sql-parser/src/Statement.php +++ b/libraries/sql-parser/src/Statement.php @@ -17,8 +17,7 @@ use SqlParser\Components\OptionsArray; * * @category Statements * @package SqlParser - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ abstract class Statement { diff --git a/libraries/sql-parser/src/Statements/AlterStatement.php b/libraries/sql-parser/src/Statements/AlterStatement.php index e76599958d..abad5dadb1 100644 --- a/libraries/sql-parser/src/Statements/AlterStatement.php +++ b/libraries/sql-parser/src/Statements/AlterStatement.php @@ -22,8 +22,7 @@ use SqlParser\Components\OptionsArray; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class AlterStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/AnalyzeStatement.php b/libraries/sql-parser/src/Statements/AnalyzeStatement.php index b6ae99e8c0..f7e8f816e5 100644 --- a/libraries/sql-parser/src/Statements/AnalyzeStatement.php +++ b/libraries/sql-parser/src/Statements/AnalyzeStatement.php @@ -20,8 +20,7 @@ use SqlParser\Components\Expression; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class AnalyzeStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/BackupStatement.php b/libraries/sql-parser/src/Statements/BackupStatement.php index 5a58a2acb4..df759398f9 100644 --- a/libraries/sql-parser/src/Statements/BackupStatement.php +++ b/libraries/sql-parser/src/Statements/BackupStatement.php @@ -16,8 +16,7 @@ namespace SqlParser\Statements; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class BackupStatement extends MaintenanceStatement { diff --git a/libraries/sql-parser/src/Statements/CallStatement.php b/libraries/sql-parser/src/Statements/CallStatement.php index bac73ee530..42a21d753a 100644 --- a/libraries/sql-parser/src/Statements/CallStatement.php +++ b/libraries/sql-parser/src/Statements/CallStatement.php @@ -23,8 +23,7 @@ use SqlParser\Components\FunctionCall; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CallStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/CheckStatement.php b/libraries/sql-parser/src/Statements/CheckStatement.php index 8ffa9460f5..ef99ed3154 100644 --- a/libraries/sql-parser/src/Statements/CheckStatement.php +++ b/libraries/sql-parser/src/Statements/CheckStatement.php @@ -16,8 +16,7 @@ namespace SqlParser\Statements; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CheckStatement extends MaintenanceStatement { diff --git a/libraries/sql-parser/src/Statements/ChecksumStatement.php b/libraries/sql-parser/src/Statements/ChecksumStatement.php index 7c66bed786..8b623353bc 100644 --- a/libraries/sql-parser/src/Statements/ChecksumStatement.php +++ b/libraries/sql-parser/src/Statements/ChecksumStatement.php @@ -16,8 +16,7 @@ namespace SqlParser\Statements; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ChecksumStatement extends MaintenanceStatement { diff --git a/libraries/sql-parser/src/Statements/CreateStatement.php b/libraries/sql-parser/src/Statements/CreateStatement.php index 1c768cbbf1..ed13952364 100644 --- a/libraries/sql-parser/src/Statements/CreateStatement.php +++ b/libraries/sql-parser/src/Statements/CreateStatement.php @@ -27,8 +27,7 @@ use SqlParser\Statements\SelectStatement; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CreateStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/DeleteStatement.php b/libraries/sql-parser/src/Statements/DeleteStatement.php index 0e13881926..394c0f40bc 100644 --- a/libraries/sql-parser/src/Statements/DeleteStatement.php +++ b/libraries/sql-parser/src/Statements/DeleteStatement.php @@ -9,11 +9,16 @@ namespace SqlParser\Statements; use SqlParser\Statement; +use SqlParser\Parser; +use SqlParser\Token; +use SqlParser\TokensList; use SqlParser\Components\ArrayObj; use SqlParser\Components\Expression; +use SqlParser\Components\ExpressionArray; use SqlParser\Components\Limit; use SqlParser\Components\OrderKeyword; use SqlParser\Components\Condition; +use SqlParser\Components\OptionsArray; /** * `DELETE` statement. @@ -24,11 +29,25 @@ use SqlParser\Components\Condition; * [ORDER BY ...] * [LIMIT row_count] * + * Multi-table syntax + * + * DELETE [LOW_PRIORITY] [QUICK] [IGNORE] + * tbl_name[.*] [, tbl_name[.*]] ... + * FROM table_references + * [WHERE where_condition] + * + * OR + * + * DELETE [LOW_PRIORITY] [QUICK] [IGNORE] + * FROM tbl_name[.*] [, tbl_name[.*]] ... + * USING table_references + * [WHERE where_condition] + * + * * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class DeleteStatement extends Statement { @@ -45,30 +64,26 @@ class DeleteStatement extends Statement ); /** - * The clauses of this statement, in order. - * - * @see Statement::$CLAUSES - * - * @var array - */ - public static $CLAUSES = array( - 'DELETE' => array('DELETE', 2), - // Used for options. - '_OPTIONS' => array('_OPTIONS', 1), - 'FROM' => array('FROM', 3), - 'PARTITION' => array('PARTITION', 3), - 'WHERE' => array('WHERE', 3), - 'ORDER BY' => array('ORDER BY', 3), - 'LIMIT' => array('LIMIT', 3), - ); - - /** - * Tables used as sources for this statement. + * Table(s) used as sources for this statement. * * @var Expression[] */ public $from; + /** + * Tables used as sources for this statement + * + * @var Expression[] + */ + public $using; + + /** + * Columns used in this statement + * + * @var Expression[] + */ + public $columns; + /** * Partitions used as source for this statement. * @@ -96,4 +111,220 @@ class DeleteStatement extends Statement * @var Limit */ public $limit; + + + /** + * @return string + */ + public function build() + { + $ret = 'DELETE ' . OptionsArray::build($this->options); + + if ($this->columns != NULL && count($this->columns) > 0) { + $ret .= ' ' . ExpressionArray::build($this->columns); + } + if ($this->from != NULL && count($this->from) > 0) { + $ret .= ' FROM ' . ExpressionArray::build($this->from); + } + if ($this->using != NULL && count($this->using) > 0) { + $ret .= ' USING ' . ExpressionArray::build($this->using); + } + if ($this->where != NULL && count($this->where) > 0) { + $ret .= ' WHERE ' . Condition::build($this->where); + } + if ($this->order != NULL && count($this->order) > 0) { + $ret .= ' ORDER BY ' . ExpressionArray::build($this->order); + } + if ($this->limit != NULL && count($this->limit) > 0) { + $ret .= ' LIMIT ' . Limit::build($this->limit); + } + + return $ret; + + } + + + /** + * @param Parser $parser The instance that requests parsing. + * @param TokensList $list The list of tokens to be parsed. + * + * @return void + */ + public function parse(Parser $parser, TokensList $list) + { + ++$list->idx; // Skipping `DELETE`. + + // parse any options if provided + $this->options = OptionsArray::parse( + $parser, + $list, + static::$OPTIONS + ); + ++$list->idx; + + /** + * The state of the parser. + * + * Below are the states of the parser. + * + * 0 ---------------------------------[ FROM ]----------------------------------> 2 + * 0 ------------------------------[ table[.*] ]--------------------------------> 1 + * 1 ---------------------------------[ FROM ]----------------------------------> 2 + * 2 --------------------------------[ USING ]----------------------------------> 3 + * 2 --------------------------------[ WHERE ]----------------------------------> 4 + * 2 --------------------------------[ ORDER ]----------------------------------> 5 + * 2 --------------------------------[ LIMIT ]----------------------------------> 6 + * + * @var int $state + */ + $state = 0; + + /** + * If the query is multi-table or not + * + * @var bool $multiTable + */ + $multiTable = false; + + for (; $list->idx < $list->count; ++$list->idx) { + /** + * Token parsed at this moment. + * + * @var Token $token + */ + $token = $list->tokens[$list->idx]; + + // End of statement. + if ($token->type === Token::TYPE_DELIMITER) { + break; + } + + if ($state === 0) { + if ($token->type === Token::TYPE_KEYWORD + && $token->value !== 'FROM' + ) { + $parser->error(__('Unexpected keyword.'), $token); + break; + } elseif ($token->type === Token::TYPE_KEYWORD + && $token->value === 'FROM' + ) { + ++$list->idx; // Skip 'FROM' + $this->from = ExpressionArray::parse($parser, $list); + $state = 2; + } else { + $this->columns = ExpressionArray::parse($parser, $list); + $state = 1; + } + } elseif ($state === 1) { + if ($token->type === Token::TYPE_KEYWORD + && $token->value !== 'FROM' + ) { + $parser->error(__('Unexpected keyword.'), $token); + break; + } elseif ($token->type === Token::TYPE_KEYWORD + && $token->value === 'FROM' + ) { + ++$list->idx; // Skip 'FROM' + $this->from = ExpressionArray::parse($parser, $list); + $state = 2; + } else { + $parser->error(__('Unexpected token.'), $token); + break; + } + } elseif ($state === 2) { + if ($token->type === Token::TYPE_KEYWORD + && $token->value === 'USING' + ) { + ++$list->idx; // Skip 'USING' + $this->using = ExpressionArray::parse($parser, $list); + $state = 3; + + $multiTable = true; + } elseif ($token->type === Token::TYPE_KEYWORD + && $token->value === 'WHERE' + ) { + ++$list->idx; // Skip 'WHERE' + $this->where = Condition::parse($parser, $list); + $state = 4; + } elseif ($token->type === Token::TYPE_KEYWORD + && $token->value === 'ORDER BY' + ) { + ++$list->idx; // Skip 'ORDER BY' + $this->order = OrderKeyword::parse($parser, $list); + $state = 5; + } elseif ($token->type === Token::TYPE_KEYWORD + && $token->value === 'LIMIT' + ) { + ++$list->idx; // Skip 'LIMIT' + $this->limit = Limit::parse($parser, $list); + $state = 6; + } elseif ($token->type === Token::TYPE_KEYWORD) { + $parser->error(__('Unexpected keyword.'), $token); + break; + } + } elseif ($state === 3) { + if ($token->type === Token::TYPE_KEYWORD + && $token->value === 'WHERE' + ) { + ++$list->idx; // Skip 'WHERE' + $this->where = Condition::parse($parser, $list); + $state = 4; + } elseif ($token->type === Token::TYPE_KEYWORD) { + $parser->error(__('Unexpected keyword.'), $token); + break; + } else { + $parser->error(__('Unexpected token.'), $token); + break; + } + } elseif ($state === 4) { + if ($multiTable === true + && $token->type === Token::TYPE_KEYWORD + ) { + $parser->error( + __('This type of clause is not valid in Multi-table queries.'), + $token + ); + break; + } + + if ($token->type === Token::TYPE_KEYWORD + && $token->value === 'ORDER BY' + ) { + ++$list->idx; // Skip 'ORDER BY' + $this->order = OrderKeyword::parse($parser, $list); + $state = 5; + } elseif ($token->type === Token::TYPE_KEYWORD + && $token->value === 'LIMIT' + ) { + ++$list->idx; // Skip 'LIMIT' + $this->limit = Limit::parse($parser, $list); + $state = 6; + } elseif ($token->type === Token::TYPE_KEYWORD) { + $parser->error(__('Unexpected keyword.'), $token); + break; + } + } elseif ($state === 5) { + if ($token->type === Token::TYPE_KEYWORD + && $token->value === 'LIMIT' + ) { + ++$list->idx; // Skip 'LIMIT' + $this->limit = Limit::parse($parser, $list); + $state = 6; + } elseif ($token->type === Token::TYPE_KEYWORD) { + $parser->error(__('Unexpected keyword.'), $token); + break; + } + } + } + + if ($state >= 2) { + foreach ($this->from as $from_expr) { + $from_expr->database = $from_expr->table; + $from_expr->table = $from_expr->column; + $from_expr->column = null; + } + } + + --$list->idx; + } } diff --git a/libraries/sql-parser/src/Statements/DropStatement.php b/libraries/sql-parser/src/Statements/DropStatement.php index 063146e1f5..b75ab0e555 100644 --- a/libraries/sql-parser/src/Statements/DropStatement.php +++ b/libraries/sql-parser/src/Statements/DropStatement.php @@ -17,8 +17,7 @@ use SqlParser\Components\Expression; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class DropStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/ExplainStatement.php b/libraries/sql-parser/src/Statements/ExplainStatement.php index eb869643cb..78c7acd219 100644 --- a/libraries/sql-parser/src/Statements/ExplainStatement.php +++ b/libraries/sql-parser/src/Statements/ExplainStatement.php @@ -14,8 +14,7 @@ namespace SqlParser\Statements; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ExplainStatement extends NotImplementedStatement { diff --git a/libraries/sql-parser/src/Statements/InsertStatement.php b/libraries/sql-parser/src/Statements/InsertStatement.php index 164b52c967..2270f5897e 100644 --- a/libraries/sql-parser/src/Statements/InsertStatement.php +++ b/libraries/sql-parser/src/Statements/InsertStatement.php @@ -54,8 +54,7 @@ use SqlParser\Components\SetOperation; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class InsertStatement extends Statement { @@ -201,7 +200,11 @@ class InsertStatement extends Statement break; } else { ++$list->idx; - $this->into = IntoKeyword::parse($parser, $list); + $this->into = IntoKeyword::parse( + $parser, + $list, + array('fromInsert' => true) + ); } $state = 1; diff --git a/libraries/sql-parser/src/Statements/MaintenanceStatement.php b/libraries/sql-parser/src/Statements/MaintenanceStatement.php index 952314e8f2..9097527c54 100644 --- a/libraries/sql-parser/src/Statements/MaintenanceStatement.php +++ b/libraries/sql-parser/src/Statements/MaintenanceStatement.php @@ -24,8 +24,7 @@ use SqlParser\Components\OptionsArray; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class MaintenanceStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/NotImplementedStatement.php b/libraries/sql-parser/src/Statements/NotImplementedStatement.php index 0a1dc338eb..8bdff2d776 100644 --- a/libraries/sql-parser/src/Statements/NotImplementedStatement.php +++ b/libraries/sql-parser/src/Statements/NotImplementedStatement.php @@ -21,8 +21,7 @@ use SqlParser\TokensList; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class NotImplementedStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/OptimizeStatement.php b/libraries/sql-parser/src/Statements/OptimizeStatement.php index 07150150da..f688333e4f 100644 --- a/libraries/sql-parser/src/Statements/OptimizeStatement.php +++ b/libraries/sql-parser/src/Statements/OptimizeStatement.php @@ -20,8 +20,7 @@ use SqlParser\Components\Expression; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class OptimizeStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/RenameStatement.php b/libraries/sql-parser/src/Statements/RenameStatement.php index 6b4f1888e0..0205f84633 100644 --- a/libraries/sql-parser/src/Statements/RenameStatement.php +++ b/libraries/sql-parser/src/Statements/RenameStatement.php @@ -23,8 +23,7 @@ use SqlParser\Components\RenameOperation; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class RenameStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/RepairStatement.php b/libraries/sql-parser/src/Statements/RepairStatement.php index b1d840b624..f98fcc62b8 100644 --- a/libraries/sql-parser/src/Statements/RepairStatement.php +++ b/libraries/sql-parser/src/Statements/RepairStatement.php @@ -18,8 +18,7 @@ namespace SqlParser\Statements; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class RepairStatement extends MaintenanceStatement { diff --git a/libraries/sql-parser/src/Statements/ReplaceStatement.php b/libraries/sql-parser/src/Statements/ReplaceStatement.php index df00272657..4142c886c8 100644 --- a/libraries/sql-parser/src/Statements/ReplaceStatement.php +++ b/libraries/sql-parser/src/Statements/ReplaceStatement.php @@ -42,8 +42,7 @@ use SqlParser\Components\SetOperation; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ReplaceStatement extends Statement { @@ -167,7 +166,11 @@ class ReplaceStatement extends Statement break; } else { ++$list->idx; - $this->into = IntoKeyword::parse($parser, $list); + $this->into = IntoKeyword::parse( + $parser, + $list, + array('fromReplace' => true) + ); } $state = 1; diff --git a/libraries/sql-parser/src/Statements/RestoreStatement.php b/libraries/sql-parser/src/Statements/RestoreStatement.php index be83dd64e1..8500479bbd 100644 --- a/libraries/sql-parser/src/Statements/RestoreStatement.php +++ b/libraries/sql-parser/src/Statements/RestoreStatement.php @@ -16,8 +16,7 @@ namespace SqlParser\Statements; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class RestoreStatement extends MaintenanceStatement { diff --git a/libraries/sql-parser/src/Statements/SelectStatement.php b/libraries/sql-parser/src/Statements/SelectStatement.php index 5d306f0662..34a68c3e45 100644 --- a/libraries/sql-parser/src/Statements/SelectStatement.php +++ b/libraries/sql-parser/src/Statements/SelectStatement.php @@ -49,8 +49,7 @@ use SqlParser\Components\Condition; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class SelectStatement extends Statement { @@ -88,6 +87,7 @@ class SelectStatement extends Statement '_OPTIONS' => array('_OPTIONS', 1), // Used for selected expressions. '_SELECT' => array('SELECT', 1), + 'INTO' => array('INTO', 3), 'FROM' => array('FROM', 3), 'PARTITION' => array('PARTITION', 3), @@ -105,7 +105,6 @@ class SelectStatement extends Statement 'ORDER BY' => array('ORDER BY', 3), 'LIMIT' => array('LIMIT', 3), 'PROCEDURE' => array('PROCEDURE', 3), - 'INTO' => array('INTO', 3), 'UNION' => array('UNION', 1), // These are available only when `UNION` is present. // 'ORDER BY' => array('ORDER BY', 3), diff --git a/libraries/sql-parser/src/Statements/SetStatement.php b/libraries/sql-parser/src/Statements/SetStatement.php index a5cffa2609..a9ff498315 100644 --- a/libraries/sql-parser/src/Statements/SetStatement.php +++ b/libraries/sql-parser/src/Statements/SetStatement.php @@ -18,8 +18,7 @@ use SqlParser\Components\OptionsArray; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class SetStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/ShowStatement.php b/libraries/sql-parser/src/Statements/ShowStatement.php index ae8cb3f55c..ecca348960 100644 --- a/libraries/sql-parser/src/Statements/ShowStatement.php +++ b/libraries/sql-parser/src/Statements/ShowStatement.php @@ -14,8 +14,7 @@ namespace SqlParser\Statements; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ShowStatement extends NotImplementedStatement { diff --git a/libraries/sql-parser/src/Statements/TransactionStatement.php b/libraries/sql-parser/src/Statements/TransactionStatement.php index 0ae83fec3f..2d355eab99 100644 --- a/libraries/sql-parser/src/Statements/TransactionStatement.php +++ b/libraries/sql-parser/src/Statements/TransactionStatement.php @@ -19,8 +19,7 @@ use SqlParser\Components\OptionsArray; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class TransactionStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/TruncateStatement.php b/libraries/sql-parser/src/Statements/TruncateStatement.php index c0cb5fd2c1..6f9d303a9c 100644 --- a/libraries/sql-parser/src/Statements/TruncateStatement.php +++ b/libraries/sql-parser/src/Statements/TruncateStatement.php @@ -17,8 +17,7 @@ use SqlParser\Components\Expression; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class TruncateStatement extends Statement { diff --git a/libraries/sql-parser/src/Statements/UpdateStatement.php b/libraries/sql-parser/src/Statements/UpdateStatement.php index 59b2ff72a3..011b955520 100644 --- a/libraries/sql-parser/src/Statements/UpdateStatement.php +++ b/libraries/sql-parser/src/Statements/UpdateStatement.php @@ -33,8 +33,7 @@ use SqlParser\Components\Condition; * @category Statements * @package SqlParser * @subpackage Statements - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class UpdateStatement extends Statement { diff --git a/libraries/sql-parser/src/Token.php b/libraries/sql-parser/src/Token.php index 18ffec76a7..3181a446ab 100644 --- a/libraries/sql-parser/src/Token.php +++ b/libraries/sql-parser/src/Token.php @@ -15,8 +15,7 @@ namespace SqlParser; * * @category Tokens * @package SqlParser - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Token { diff --git a/libraries/sql-parser/src/TokensList.php b/libraries/sql-parser/src/TokensList.php index 10ff56e717..c0c2c89e71 100644 --- a/libraries/sql-parser/src/TokensList.php +++ b/libraries/sql-parser/src/TokensList.php @@ -12,8 +12,7 @@ namespace SqlParser; * * @category Tokens * @package SqlParser - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class TokensList implements \ArrayAccess { diff --git a/libraries/sql-parser/src/UtfString.php b/libraries/sql-parser/src/UtfString.php index 5f4ba12f9d..c7b08d8e18 100644 --- a/libraries/sql-parser/src/UtfString.php +++ b/libraries/sql-parser/src/UtfString.php @@ -21,8 +21,7 @@ namespace SqlParser; * * @category Misc * @package SqlParser - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class UtfString implements \ArrayAccess { diff --git a/libraries/sql-parser/src/Utils/BufferedQuery.php b/libraries/sql-parser/src/Utils/BufferedQuery.php index 8aad59f543..b1ef46d4a1 100644 --- a/libraries/sql-parser/src/Utils/BufferedQuery.php +++ b/libraries/sql-parser/src/Utils/BufferedQuery.php @@ -22,8 +22,7 @@ use SqlParser\Context; * @category Lexer * @package SqlParser * @subpackage Utils - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class BufferedQuery { diff --git a/libraries/sql-parser/src/Utils/CLI.php b/libraries/sql-parser/src/Utils/CLI.php index b6ce35e687..9ec7b85357 100644 --- a/libraries/sql-parser/src/Utils/CLI.php +++ b/libraries/sql-parser/src/Utils/CLI.php @@ -17,8 +17,7 @@ use SqlParser\Lexer; * @category Exceptions * @package SqlParser * @subpackage Utils - * @author Michal Čihař - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CLI { diff --git a/libraries/sql-parser/src/Utils/Error.php b/libraries/sql-parser/src/Utils/Error.php index f0ad5afbb2..2e942c4434 100644 --- a/libraries/sql-parser/src/Utils/Error.php +++ b/libraries/sql-parser/src/Utils/Error.php @@ -17,8 +17,7 @@ use SqlParser\Parser; * @category Exceptions * @package SqlParser * @subpackage Utils - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Error { diff --git a/libraries/sql-parser/src/Utils/Formatter.php b/libraries/sql-parser/src/Utils/Formatter.php index 41b50945b5..bcf5486263 100644 --- a/libraries/sql-parser/src/Utils/Formatter.php +++ b/libraries/sql-parser/src/Utils/Formatter.php @@ -19,8 +19,7 @@ use SqlParser\TokensList; * @category Misc * @package SqlParser * @subpackage Utils - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Formatter { diff --git a/libraries/sql-parser/src/Utils/Misc.php b/libraries/sql-parser/src/Utils/Misc.php index cec5653688..8166c458d2 100644 --- a/libraries/sql-parser/src/Utils/Misc.php +++ b/libraries/sql-parser/src/Utils/Misc.php @@ -17,8 +17,7 @@ use SqlParser\Statements\SelectStatement; * @category Misc * @package SqlParser * @subpackage Utils - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Misc { diff --git a/libraries/sql-parser/src/Utils/Query.php b/libraries/sql-parser/src/Utils/Query.php index 239cd6f41b..2e0982a018 100644 --- a/libraries/sql-parser/src/Utils/Query.php +++ b/libraries/sql-parser/src/Utils/Query.php @@ -39,8 +39,7 @@ use SqlParser\Statements\UpdateStatement; * @category Statement * @package SqlParser * @subpackage Utils - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Query { diff --git a/libraries/sql-parser/src/Utils/Routine.php b/libraries/sql-parser/src/Utils/Routine.php index 5450cac178..d5a7891d17 100644 --- a/libraries/sql-parser/src/Utils/Routine.php +++ b/libraries/sql-parser/src/Utils/Routine.php @@ -20,8 +20,7 @@ use SqlParser\Statements\CreateStatement; * @category Routines * @package SqlParser * @subpackage Utils - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Routine { diff --git a/libraries/sql-parser/src/Utils/Table.php b/libraries/sql-parser/src/Utils/Table.php index b88f2345d1..a31ddf2703 100644 --- a/libraries/sql-parser/src/Utils/Table.php +++ b/libraries/sql-parser/src/Utils/Table.php @@ -16,8 +16,7 @@ use SqlParser\Statements\CreateStatement; * @category Statement * @package SqlParser * @subpackage Utils - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Table { diff --git a/libraries/sql-parser/src/Utils/Tokens.php b/libraries/sql-parser/src/Utils/Tokens.php index eb76df2a73..acec369c40 100644 --- a/libraries/sql-parser/src/Utils/Tokens.php +++ b/libraries/sql-parser/src/Utils/Tokens.php @@ -18,8 +18,7 @@ use SqlParser\TokensList; * @category Token * @package SqlParser * @subpackage Utils - * @author Dan Ungureanu - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Tokens {