Skip to content

Commit c87678c

Browse files
committed
Fixed build CREATE TABLE query with PARTITIONS having ENGINE but not VALUES.
Fixes #174 Signed-off-by: Michal Čihař <[email protected]>
1 parent d559226 commit c87678c

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
* Make mbstring extension optional (though Symfony polyfill).
6+
* Fixed build CREATE TABLE query with PARTITIONS having ENGINE but not VALUES.
67

78
## [4.2.2] - 2017-09-28
89

src/Components/PartitionDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public static function build($component, array $options = array())
214214
return trim(
215215
'PARTITION ' . $component->name
216216
. (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ')
217-
. $component->options . $subpartitions
217+
. ((!empty($component->options) && !empty($component->type)) ? '' : ' ') . $component->options . $subpartitions
218218
);
219219
}
220220
}

tests/Builder/CreateStatementTest.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,11 @@ public function testBuilderPartitions()
183183
$this->assertEquals($query, $parser->statements[0]->build());
184184
}
185185

186-
public function testBuilderPartitionsEngine()
186+
public function partitionQueries()
187187
{
188-
$query = <<<EOT
188+
return array(
189+
array(
190+
'subparts' => <<<EOT
189191
CREATE TABLE `ts` (
190192
`id` int(11) DEFAULT NULL,
191193
`purchased` date DEFAULT NULL
@@ -206,7 +208,33 @@ public function testBuilderPartitionsEngine()
206208
SUBPARTITION s5 ENGINE=InnoDB
207209
)
208210
)
209-
EOT;
211+
EOT
212+
),
213+
array(
214+
'parts' => <<<EOT
215+
CREATE TABLE ptest (
216+
`event_date` date NOT NULL
217+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC
218+
PARTITION BY HASH (TO_DAYS(event_date))
219+
(
220+
PARTITION p0 ENGINE=InnoDB,
221+
PARTITION p1 ENGINE=InnoDB,
222+
PARTITION p2 ENGINE=InnoDB,
223+
PARTITION p3 ENGINE=InnoDB,
224+
PARTITION p4 ENGINE=InnoDB
225+
)
226+
EOT
227+
),
228+
);
229+
}
230+
231+
/**
232+
* @dataProvider partitionQueries
233+
*
234+
* @param string $query
235+
*/
236+
public function testBuilderPartitionsEngine($query)
237+
{
210238
$parser = new Parser($query);
211239
$stmt = $parser->statements[0];
212240

0 commit comments

Comments
 (0)