Skip to content

Commit

Permalink
ddl:fix type bit could have null as its default value (#7604)
Browse files Browse the repository at this point in the history
* ddl:fix type bit could have null as its default value
  • Loading branch information
ciscoxll committed Sep 5, 2018
1 parent 92e6a5a commit b6072de
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
41 changes: 41 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,47 @@ func (s *testDBSuite) TestBitDefaultValue(c *C) {
tk.MustExec("insert into t_bit set c2=1;")
tk.MustQuery("select bin(c1),c2 from t_bit").Check(testkit.Rows("11111010 1"))
tk.MustExec("drop table t_bit")
tk.MustExec(`create table testalltypes1 (
field_1 bit default 1,
field_2 tinyint null default null
);`)
tk.MustExec(`create table testalltypes2 (
field_1 bit null default null,
field_2 tinyint null default null,
field_3 tinyint unsigned null default null,
field_4 bigint null default null,
field_5 bigint unsigned null default null,
field_6 mediumblob null default null,
field_7 longblob null default null,
field_8 blob null default null,
field_9 tinyblob null default null,
field_10 varbinary(255) null default null,
field_11 binary(255) null default null,
field_12 mediumtext null default null,
field_13 longtext null default null,
field_14 text null default null,
field_15 tinytext null default null,
field_16 char(255) null default null,
field_17 numeric null default null,
field_18 decimal null default null,
field_19 integer null default null,
field_20 integer unsigned null default null,
field_21 int null default null,
field_22 int unsigned null default null,
field_23 mediumint null default null,
field_24 mediumint unsigned null default null,
field_25 smallint null default null,
field_26 smallint unsigned null default null,
field_27 float null default null,
field_28 double null default null,
field_29 double precision null default null,
field_30 real null default null,
field_31 varchar(255) null default null,
field_32 date null default null,
field_33 time null default null,
field_34 datetime null default null,
field_35 timestamp null default null
);`)
}

func (s *testDBSuite) TestCreateTableWithPartition(c *C) {
Expand Down
4 changes: 4 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func (c *ColumnInfo) SetDefaultValue(value interface{}) error {
if c.Tp == mysql.TypeBit {
// For mysql.TypeBit type, the default value storage format must be a string.
// Other value such as int must convert to string format first.
// The mysql.TypeBit type supports the null default value.
if value == nil {
return nil
}
if v, ok := value.(string); ok {
c.DefaultValueBit = []byte(v)
return nil
Expand Down

0 comments on commit b6072de

Please sign in to comment.