diff options
author | Michal Čihař <michal@cihar.com> | 2017-10-10 14:54:29 +0200 |
---|---|---|
committer | Michal Čihař <michal@cihar.com> | 2017-10-10 14:55:39 +0200 |
commit | c87678cf410ac2f9f399788a5dff59f8d65c531b (patch) | |
tree | df8b48948bc347736c3297dbc49af20d9b98a22e | |
parent | d5592264c2422cd4694d6d23f25faa5469cd1a0d (diff) | |
download | sql-parser-c87678cf410ac2f9f399788a5dff59f8d65c531b.zip sql-parser-c87678cf410ac2f9f399788a5dff59f8d65c531b.tar.gz sql-parser-c87678cf410ac2f9f399788a5dff59f8d65c531b.tar.bz2 |
Fixed build CREATE TABLE query with PARTITIONS having ENGINE but not VALUES.
Fixes #174
Signed-off-by: Michal Čihař <michal@cihar.com>
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/Components/PartitionDefinition.php | 2 | ||||
-rw-r--r-- | tests/Builder/CreateStatementTest.php | 34 |
3 files changed, 33 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c831fd..8d0fa55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] * Make mbstring extension optional (though Symfony polyfill). +* Fixed build CREATE TABLE query with PARTITIONS having ENGINE but not VALUES. ## [4.2.2] - 2017-09-28 diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php index 59b34cb..2fc769e 100644 --- a/src/Components/PartitionDefinition.php +++ b/src/Components/PartitionDefinition.php @@ -214,7 +214,7 @@ class PartitionDefinition extends Component return trim( 'PARTITION ' . $component->name . (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ') - . $component->options . $subpartitions + . ((!empty($component->options) && !empty($component->type)) ? '' : ' ') . $component->options . $subpartitions ); } } diff --git a/tests/Builder/CreateStatementTest.php b/tests/Builder/CreateStatementTest.php index 7b0b03c..abe219a 100644 --- a/tests/Builder/CreateStatementTest.php +++ b/tests/Builder/CreateStatementTest.php @@ -183,9 +183,11 @@ class CreateStatementTest extends TestCase $this->assertEquals($query, $parser->statements[0]->build()); } - public function testBuilderPartitionsEngine() + public function partitionQueries() { - $query = <<<EOT + return array( + array( + 'subparts' => <<<EOT CREATE TABLE `ts` ( `id` int(11) DEFAULT NULL, `purchased` date DEFAULT NULL @@ -206,7 +208,33 @@ SUBPARTITION s4 ENGINE=InnoDB, SUBPARTITION s5 ENGINE=InnoDB ) ) -EOT; +EOT + ), + array( + 'parts' => <<<EOT +CREATE TABLE ptest ( + `event_date` date NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC +PARTITION BY HASH (TO_DAYS(event_date)) +( +PARTITION p0 ENGINE=InnoDB, +PARTITION p1 ENGINE=InnoDB, +PARTITION p2 ENGINE=InnoDB, +PARTITION p3 ENGINE=InnoDB, +PARTITION p4 ENGINE=InnoDB +) +EOT + ), + ); + } + + /** + * @dataProvider partitionQueries + * + * @param string $query + */ + public function testBuilderPartitionsEngine($query) + { $parser = new Parser($query); $stmt = $parser->statements[0]; |