From 6b3067de4275d7fa195fe36eac7deed4b174338a Mon Sep 17 00:00:00 2001 From: siddontang Date: Mon, 28 Sep 2015 16:22:02 +0800 Subject: [PATCH] parser: blob and text support field length option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Manual doesn’t point this, but SQLAlchemy has this test and MySQL parser handles this too. --- parser/parser.y | 6 ++++-- parser/parser_test.go | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/parser/parser.y b/parser/parser.y index 9278eb7202..03a1848eb6 100644 --- a/parser/parser.y +++ b/parser/parser.y @@ -3700,9 +3700,10 @@ BlobType: x.Collate = charset.CharsetBin $$ = x } -| "BLOB" +| "BLOB" OptFieldLen { x := types.NewFieldType(mysql.TypeBlob) + x.Flen = $2.(int) x.Charset = charset.CharsetBin x.Collate = charset.CharsetBin $$ = x @@ -3729,9 +3730,10 @@ TextType: $$ = x } -| "TEXT" +| "TEXT" OptFieldLen { x := types.NewFieldType(mysql.TypeBlob) + x.Flen = $2.(int) $$ = x } | "MEDIUMTEXT" diff --git a/parser/parser_test.go b/parser/parser_test.go index 5a8984670a..49887a9a8a 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -423,6 +423,9 @@ func (s *testParserSuite) TestParser0(c *C) { // For national {"create table t (c1 national char(2), c2 national varchar(2))", true}, + + // For blob and text field length + {"create table t (c1 blob(1024), c2 text(1024))", true}, } for _, t := range table {