Skip to content

Commit 50de69f

Browse files
committed
Fix parsing of CREATE TABLE with per field COLLATE
Fixes #182 Signed-off-by: Michal Čihař <michal@cihar.com>
1 parent 82fe464 commit 50de69f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased]
44

5+
* Fix parsing of CREATE TABLE with per field COLLATE.
6+
57
## [4.2.3] - 2017-10-10
68

79
* Make mbstring extension optional (though Symfony polyfill).

src/Components/CreateDefinition.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class CreateDefinition extends Component
3838
'NOT NULL' => 1,
3939
'NULL' => 1,
4040
'DEFAULT' => array(2, 'expr', array('breakOnAlias' => true)),
41+
/* Following are not according to grammar, but MySQL happily accepts
42+
* these at any location */
43+
'CHARSET' => array(2, 'var'),
44+
'COLLATE' => array(3, 'var'),
4145
'AUTO_INCREMENT' => 3,
4246
'PRIMARY' => 4,
4347
'PRIMARY KEY' => 4,

tests/Builder/CreateStatementTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ public function testBuilderDefaultInt()
5757
);
5858
}
5959

60+
public function testBuilderCollate()
61+
{
62+
$parser = new Parser(
63+
'CREATE TABLE IF NOT EXISTS t1 (' .
64+
" c1 varchar(11) NOT NULL DEFAULT '0' COLLATE 'utf8_czech_ci' COMMENT 'xxx'" .
65+
') ENGINE=MyISAM'
66+
);
67+
$stmt = $parser->statements[0];
68+
69+
$this->assertEquals(
70+
"CREATE TABLE IF NOT EXISTS t1 (\n" .
71+
" `c1` varchar(11) NOT NULL DEFAULT '0' COLLATE 'utf8_czech_ci' COMMENT 'xxx'\n" .
72+
') ENGINE=MyISAM',
73+
$stmt->build()
74+
);
75+
}
76+
6077
public function testBuilderDefaultComment()
6178
{
6279
$parser = new Parser(

0 commit comments

Comments
 (0)