summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2017-11-08 15:19:56 +0100
committerMichal Čihař <michal@cihar.com>2017-11-08 15:29:52 +0100
commit50de69f424b843589fdc6e4328809a0da24250b0 (patch)
tree31adafbdc649cf25aff201b12aa4e80b0c5eb74a
parent82fe464d767ad87bfaf7b996d9365a1f69ec6bb7 (diff)
downloadsql-parser-50de69f424b843589fdc6e4328809a0da24250b0.zip
sql-parser-50de69f424b843589fdc6e4328809a0da24250b0.tar.gz
sql-parser-50de69f424b843589fdc6e4328809a0da24250b0.tar.bz2
Fix parsing of CREATE TABLE with per field COLLATE
Fixes #182 Signed-off-by: Michal Čihař <michal@cihar.com>
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/Components/CreateDefinition.php4
-rw-r--r--tests/Builder/CreateStatementTest.php17
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(