diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/Components/CreateDefinition.php | 4 | ||||
-rw-r--r-- | tests/Builder/CreateStatementTest.php | 17 |
3 files changed, 23 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6187bf3..0c15291 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/src/Components/CreateDefinition.php b/src/Components/CreateDefinition.php index 0b5c584..f85ad0f 100644 --- a/src/Components/CreateDefinition.php +++ b/src/Components/CreateDefinition.php @@ -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, diff --git a/tests/Builder/CreateStatementTest.php b/tests/Builder/CreateStatementTest.php index abe219a..9a9900b 100644 --- a/tests/Builder/CreateStatementTest.php +++ b/tests/Builder/CreateStatementTest.php @@ -57,6 +57,23 @@ class CreateStatementTest extends TestCase ); } + 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( |