Skip to content

Commit

Permalink
Fix parsing of CREATE TABLE with per field COLLATE
Browse files Browse the repository at this point in the history
Fixes #182

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Nov 8, 2017
1 parent 82fe464 commit 50de69f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

* Fix parsing of CREATE TABLE with per field COLLATE.

## [4.2.3] - 2017-10-10

* Make mbstring extension optional (though Symfony polyfill).
Expand Down
4 changes: 4 additions & 0 deletions src/Components/CreateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class CreateDefinition extends Component
'NOT NULL' => 1,
'NULL' => 1,
'DEFAULT' => array(2, 'expr', array('breakOnAlias' => true)),
/* Following are not according to grammar, but MySQL happily accepts
* these at any location */
'CHARSET' => array(2, 'var'),
'COLLATE' => array(3, 'var'),
'AUTO_INCREMENT' => 3,
'PRIMARY' => 4,
'PRIMARY KEY' => 4,
Expand Down
17 changes: 17 additions & 0 deletions tests/Builder/CreateStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ public function testBuilderDefaultInt()
);
}

public function testBuilderCollate()
{
$parser = new Parser(
'CREATE TABLE IF NOT EXISTS t1 (' .
" c1 varchar(11) NOT NULL DEFAULT '0' COLLATE 'utf8_czech_ci' COMMENT 'xxx'" .
') ENGINE=MyISAM'
);
$stmt = $parser->statements[0];

$this->assertEquals(
"CREATE TABLE IF NOT EXISTS t1 (\n" .
" `c1` varchar(11) NOT NULL DEFAULT '0' COLLATE 'utf8_czech_ci' COMMENT 'xxx'\n" .
') ENGINE=MyISAM',
$stmt->build()
);
}

public function testBuilderDefaultComment()
{
$parser = new Parser(
Expand Down

0 comments on commit 50de69f

Please sign in to comment.