Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: year type should not has unsigned flag #6745

Merged
merged 3 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func columnDefToCol(ctx sessionctx.Context, offset int, colDef *ast.ColumnDef) (
if col.Tp == mysql.TypeYear {
// For Year field, it's charset is binary but does not have binary flag.
col.Flag &= ^mysql.BinaryFlag
col.Flag |= mysql.UnsignedFlag | mysql.ZerofillFlag
col.Flag |= mysql.ZerofillFlag
}
err := checkDefaultValue(ctx, col, hasDefaultValue)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions ddl/ddl_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,26 @@ func (s *testDBSuite) TestRebaseAutoID(c *C) {
s.testErrorCode(c, "alter table tidb.test2 add column b int auto_increment key, auto_increment=10;", tmysql.ErrUnknown)
}

func (s *testDBSuite) TestYearTypeCreateTable(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use test")
s.tk.MustExec("drop table if exists abc;")
s.tk.MustExec("create table abc(y year, x int, primary key(y));")
is := s.dom.InfoSchema()
tbl, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("abc"))
c.Assert(err, IsNil)
var yearCol *model.ColumnInfo
for _, col := range tbl.Meta().Columns {
if col.Name.String() == "y" {
yearCol = col
break
}
}
c.Assert(yearCol, NotNil)
c.Assert(yearCol.Tp, Equals, mysql.TypeYear)
c.Assert(mysql.HasUnsignedFlag(yearCol.Flag), IsFalse)
}

func (s *testDBSuite) TestCharacterSetInColumns(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("drop database if exists varchar_test;")
Expand Down
10 changes: 10 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ func (s *testSuite) TestShow(c *C) {
" `d` int(11) DEFAULT NULL\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"+"\nPARTITION BY RANGE COLUMNS(a,d,c) (\n PARTITION p0 VALUES LESS THAN (5,10,\"ggg\"),\n PARTITION p1 VALUES LESS THAN (10,20,\"mmm\"),\n PARTITION p2 VALUES LESS THAN (15,30,\"sss\"),\n PARTITION p3 VALUES LESS THAN (50,MAXVALUE,MAXVALUE)\n)",
))

// Test show create table year type
tk.MustExec(`drop table if exists t`)
tk.MustExec(`create table t(y year, x int, primary key(y));`)
tk.MustQuery(`show create table t`).Check(testutil.RowsWithSep("|",
"t CREATE TABLE `t` (\n"+
" `y` year NOT NULL,\n"+
" `x` int(11) DEFAULT NULL,\n"+
" PRIMARY KEY (`y`)\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"))
}

func (s *testSuite) TestShowVisibility(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion expression/typeinfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (s *testInferTypeSuite) createTestCase4Cast() []typeInferTestCase {
func (s *testInferTypeSuite) createTestCase4Columns() []typeInferTestCase {
return []typeInferTestCase{
{"c_bit ", mysql.TypeBit, charset.CharsetBin, mysql.UnsignedFlag, 10, 0},
{"c_year ", mysql.TypeYear, charset.CharsetBin, mysql.UnsignedFlag | mysql.ZerofillFlag, 4, 0},
{"c_year ", mysql.TypeYear, charset.CharsetBin, mysql.ZerofillFlag, 4, 0},
{"c_int_d ", mysql.TypeLong, charset.CharsetBin, 0, 11, 0},
{"c_uint_d ", mysql.TypeLong, charset.CharsetBin, mysql.UnsignedFlag, 10, 0},
{"c_bigint_d ", mysql.TypeLonglong, charset.CharsetBin, 0, 20, 0},
Expand Down
2 changes: 1 addition & 1 deletion table/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const defaultPrivileges = "select,insert,update,references"
// GetTypeDesc gets the description for column type.
func (c *Column) GetTypeDesc() string {
desc := c.FieldType.CompactStr()
if mysql.HasUnsignedFlag(c.Flag) && c.Tp != mysql.TypeBit {
if mysql.HasUnsignedFlag(c.Flag) && c.Tp != mysql.TypeBit && c.Tp != mysql.TypeYear {
desc += " UNSIGNED"
}
return desc
Expand Down