ddl: convert hexLit to stringLit in enum and set default value. (#20459)

This commit is contained in:
tangwz
2020-11-04 17:41:03 +08:00
committed by GitHub
parent feab4cb9b8
commit 09c941fd8c
2 changed files with 19 additions and 1 deletions

View File

@ -2530,3 +2530,21 @@ func (s *testIntegrationSuite3) TestIssue20490(c *C) {
tk.MustQuery("select b from issue20490 order by a;").Check(testkit.Rows("1", "1", "<nil>"))
}
// 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")
}

View File

@ -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