diff options
author | Dan Ungureanu <udan1107@gmail.com> | 2015-08-16 02:48:03 +0300 |
---|---|---|
committer | Dan Ungureanu <udan1107@gmail.com> | 2015-08-16 02:48:03 +0300 |
commit | 2c1124c25a74191f4c3bf095238a0a732bfd8a9e (patch) | |
tree | 30ca07e0d1b37a0a567d6be5fabe9bffe2d8a594 /src | |
parent | 3cbebbe741f4bab1ce4790daa34d4cdd8bf36a25 (diff) | |
download | sql-parser-2c1124c25a74191f4c3bf095238a0a732bfd8a9e.zip sql-parser-2c1124c25a74191f4c3bf095238a0a732bfd8a9e.tar.gz sql-parser-2c1124c25a74191f4c3bf095238a0a732bfd8a9e.tar.bz2 |
Fixed a couple of minor bugs in partition parsing.
'MAXVALUE' can be used for partitions.
The correct class is used for parsing.
Options may be specified for the class that is used for parsing.
Wrote tests.
Diffstat (limited to 'src')
-rw-r--r-- | src/Components/ArrayObj.php | 6 | ||||
-rw-r--r-- | src/Components/PartitionDefinition.php | 26 | ||||
-rw-r--r-- | src/Statements/CreateStatement.php | 6 |
3 files changed, 28 insertions, 10 deletions
diff --git a/src/Components/ArrayObj.php b/src/Components/ArrayObj.php index 431ed6d..0e0b183 100644 --- a/src/Components/ArrayObj.php +++ b/src/Components/ArrayObj.php @@ -115,7 +115,11 @@ class ArrayObj extends Component $ret->values[] = $token->value; $ret->raw[] = $token->token; } else { - $ret[] = $options['type']::parse($parser, $list); + $ret[] = $options['type']::parse( + $parser, + $list, + empty($options['typeOptions']) ? array() : $options['typeOptions'] + ); } $state = 2; } elseif ($state === 2) { diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php index c7546b0..c46252d 100644 --- a/src/Components/PartitionDefinition.php +++ b/src/Components/PartitionDefinition.php @@ -155,7 +155,18 @@ class PartitionDefinition extends Component $ret->type = $token->value; $state = 4; } elseif ($state === 4) { - $ret->expr = Expression::parse($parser, $list, array('noAlias' => true, 'bracketsDelimited' => true)); + if ($token->value === 'MAXVALUE') { + $ret->expr = $token->value; + } else { + $ret->expr = Expression::parse( + $parser, + $list, + array( + 'bracketsDelimited' => true, + 'noAlias' => true, + ) + ); + } $state = 5; } elseif ($state === 5) { $ret->options = OptionsArray::parse($parser, $list, static::$OPTIONS); @@ -166,12 +177,12 @@ class PartitionDefinition extends Component $parser, $list, array( - 'type' => 'SqlParser\Components\PartitionDefinition' + 'type' => 'SqlParser\\Components\\PartitionDefinition' ) ); - } else { - break; + ++$list->idx; } + break; } } @@ -196,11 +207,10 @@ class PartitionDefinition extends Component if ($component->isSubpartition) { return 'SUBPARTITION ' . $component->name; } else { - if (!empty($component->subpartitions)) { - $subpartitions = ' ' . PartitionDefinition::build($component->subpartitions); - } + $subpartitions = empty($component->subpartitions) + ? '' : ' ' . PartitionDefinition::build($component->subpartitions); return 'PARTITION ' . $component->name - . ' VALUES ' . $component->type . $component->expr + . ' VALUES ' . $component->type . ' ' . $component->expr . $subpartitions; } diff --git a/src/Statements/CreateStatement.php b/src/Statements/CreateStatement.php index 0f2e565..bc7cf73 100644 --- a/src/Statements/CreateStatement.php +++ b/src/Statements/CreateStatement.php @@ -421,9 +421,11 @@ class CreateStatement extends Statement $brackets = false; } elseif (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'PARTITIONS')) { $token = $list->getNextOfType(Token::TYPE_NUMBER); + --$list->idx; // `getNextOfType` also advances one position. $this->partitionsNum = $token->value; } elseif (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'SUBPARTITIONS')) { $token = $list->getNextOfType(Token::TYPE_NUMBER); + --$list->idx; // `getNextOfType` also advances one position. $this->subpartitionsNum = $token->value; } elseif (!empty($field)) { @@ -457,7 +459,9 @@ class CreateStatement extends Statement $this->partitions = ArrayObj::parse( $parser, $list, - array('type' => 'SqlParser\Components\PartitionDefinition') + array( + 'type' => 'SqlParser\\Components\\PartitionDefinition' + ) ); } break; |