diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Components/IntoKeyword.php | 35 | ||||
-rw-r--r-- | src/Components/JoinKeyword.php | 8 | ||||
-rw-r--r-- | src/Parser.php | 2 | ||||
-rw-r--r-- | src/Statements/InsertStatement.php | 6 | ||||
-rw-r--r-- | src/Statements/ReplaceStatement.php | 6 | ||||
-rw-r--r-- | src/Statements/SelectStatement.php | 2 |
6 files changed, 44 insertions, 15 deletions
diff --git a/src/Components/IntoKeyword.php b/src/Components/IntoKeyword.php index caa3702..d90963d 100644 --- a/src/Components/IntoKeyword.php +++ b/src/Components/IntoKeyword.php @@ -46,6 +46,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. * @param array $options Parameters for parsing. @@ -102,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 === '(')) { @@ -140,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/src/Components/JoinKeyword.php b/src/Components/JoinKeyword.php index 865246c..7062783 100644 --- a/src/Components/JoinKeyword.php +++ b/src/Components/JoinKeyword.php @@ -146,6 +146,9 @@ class JoinKeyword extends Component $state = 3; } elseif ($token->value === 'USING') { $state = 4; + } else { + /* Next clause is starting */ + break; } } } elseif ($state === 3) { @@ -182,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/src/Parser.php b/src/Parser.php index c9fe0f0..21e1b39 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -162,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/src/Statements/InsertStatement.php b/src/Statements/InsertStatement.php index f9fe3fe..2270f58 100644 --- a/src/Statements/InsertStatement.php +++ b/src/Statements/InsertStatement.php @@ -200,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/src/Statements/ReplaceStatement.php b/src/Statements/ReplaceStatement.php index 99a04f0..4142c88 100644 --- a/src/Statements/ReplaceStatement.php +++ b/src/Statements/ReplaceStatement.php @@ -166,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/src/Statements/SelectStatement.php b/src/Statements/SelectStatement.php index 5484f49..34a68c3 100644 --- a/src/Statements/SelectStatement.php +++ b/src/Statements/SelectStatement.php @@ -87,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), @@ -104,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), |