diff options
-rw-r--r-- | src/Components/IntoKeyword.php | 33 | ||||
-rw-r--r-- | src/Statements/InsertStatement.php | 6 | ||||
-rw-r--r-- | src/Statements/ReplaceStatement.php | 6 | ||||
-rw-r--r-- | tests/Components/IntoKeywordTest.php | 6 |
4 files changed, 41 insertions, 10 deletions
diff --git a/src/Components/IntoKeyword.php b/src/Components/IntoKeyword.php index db29529..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,6 +155,8 @@ 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 . '"'; } 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/tests/Components/IntoKeywordTest.php b/tests/Components/IntoKeywordTest.php index c18938a..388368c 100644 --- a/tests/Components/IntoKeywordTest.php +++ b/tests/Components/IntoKeywordTest.php @@ -23,6 +23,12 @@ class IntoKeywordTest extends TestCase $this->assertEquals('tbl(`col1`, `col2`)', IntoKeyword::build($component)); } + public function testBuildValues() + { + $component = IntoKeyword::parse(new Parser(), $this->getTokensList('@a1, @a2, @a3')); + $this->assertEquals('@a1, @a2, @a3', IntoKeyword::build($component)); + } + public function testBuildOutfile() { $component = IntoKeyword::parse(new Parser(), $this->getTokensList('OUTFILE "/tmp/outfile.txt"')); |