From 09c941fd8cec4af5bafd4d0481c26babe755bdb0 Mon Sep 17 00:00:00 2001 From: tangwz Date: Wed, 4 Nov 2020 17:41:03 +0800 Subject: [PATCH] ddl: convert hexLit to stringLit in enum and set default value. (#20459) --- ddl/db_integration_test.go | 18 ++++++++++++++++++ ddl/ddl_api.go | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index c7a385778e..aedf79146b 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -2530,3 +2530,21 @@ func (s *testIntegrationSuite3) TestIssue20490(c *C) { tk.MustQuery("select b from issue20490 order by a;").Check(testkit.Rows("1", "1", "")) } + +// TestDefaultValueIsLatin1 for issue #18977 +func (s *testIntegrationSuite3) TestEnumAndSetDefaultValue(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + defer tk.MustExec("drop table if exists t") + tk.MustExec("create table t (a enum(0x61, 'b') not null default 0x61, b set(0x61, 'b') not null default 0x61) character set latin1") + tbl := testGetTableByName(c, s.ctx, "test", "t") + c.Assert(tbl.Meta().Columns[0].DefaultValue, Equals, "a") + c.Assert(tbl.Meta().Columns[1].DefaultValue, Equals, "a") + + tk.MustExec("drop table t") + tk.MustExec("create table t (a enum(0x61, 'b') not null default 0x61, b set(0x61, 'b') not null default 0x61) character set utf8mb4") + tbl = testGetTableByName(c, s.ctx, "test", "t") + c.Assert(tbl.Meta().Columns[0].DefaultValue, Equals, "a") + c.Assert(tbl.Meta().Columns[1].DefaultValue, Equals, "a") +} diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 20a508c8cf..4288b1b145 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -742,7 +742,7 @@ func getDefaultValue(ctx sessionctx.Context, col *table.Column, c *ast.ColumnOpt if tp == mysql.TypeBit || tp == mysql.TypeString || tp == mysql.TypeVarchar || tp == mysql.TypeVarString || tp == mysql.TypeBlob || tp == mysql.TypeLongBlob || tp == mysql.TypeMediumBlob || tp == mysql.TypeTinyBlob || - tp == mysql.TypeJSON { + tp == mysql.TypeJSON || tp == mysql.TypeEnum || tp == mysql.TypeSet { // For BinaryLiteral / string fields, when getting default value we cast the value into BinaryLiteral{}, thus we return // its raw string content here. return v.GetBinaryLiteral().ToString(), false, nil