From 50a49b24dc2a85a7fed50f29aba353482cdbe858 Mon Sep 17 00:00:00 2001 From: ciscoxll Date: Tue, 4 Sep 2018 16:17:48 +0800 Subject: [PATCH 1/5] ddl:fix type bit could have null as its default value --- ddl/db_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ model/model.go | 3 +++ 2 files changed, 44 insertions(+) diff --git a/ddl/db_test.go b/ddl/db_test.go index e577ca8dbf5bc..8f35ab1ab08e1 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -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) { diff --git a/model/model.go b/model/model.go index 2fe3c7b6ebb00..c5ddfdd0296de 100644 --- a/model/model.go +++ b/model/model.go @@ -96,6 +96,9 @@ 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. + if value == nil { + return nil + } if v, ok := value.(string); ok { c.DefaultValueBit = []byte(v) return nil From 96c9f8a60fdee90a8d7e865a7069cb004e362af5 Mon Sep 17 00:00:00 2001 From: ciscoxll Date: Tue, 4 Sep 2018 17:38:30 +0800 Subject: [PATCH 2/5] address comment --- model/model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/model.go b/model/model.go index c5ddfdd0296de..9f514e68db7c1 100644 --- a/model/model.go +++ b/model/model.go @@ -94,7 +94,7 @@ func (c *ColumnInfo) IsGenerated() bool { func (c *ColumnInfo) SetDefaultValue(value interface{}) error { c.DefaultValue = value if c.Tp == mysql.TypeBit { - // For mysql.TypeBit type, the default value storage format must be a string. + // For mysql.TypeBit type, the default value storage format must be a string, default value is null supported. // Other value such as int must convert to string format first. if value == nil { return nil From f5b9713a8e6cecd41b5bb5383d7b66e475a4f0c3 Mon Sep 17 00:00:00 2001 From: ciscoxll Date: Wed, 5 Sep 2018 14:38:31 +0800 Subject: [PATCH 3/5] update function comment --- model/model.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/model/model.go b/model/model.go index 9f514e68db7c1..83dff84a0575c 100644 --- a/model/model.go +++ b/model/model.go @@ -94,8 +94,9 @@ func (c *ColumnInfo) IsGenerated() bool { func (c *ColumnInfo) SetDefaultValue(value interface{}) error { c.DefaultValue = value if c.Tp == mysql.TypeBit { - // For mysql.TypeBit type, the default value storage format must be a string, default value is null supported. + // For mysql.TypeBit type, the default value storage format must be a string. // Other value such as int must convert to string format first. + // For mysql.TypeBit type, default value is null is supported. if value == nil { return nil } From 9ac506b5ec86c362c9f381d6cf94f371f7677aa8 Mon Sep 17 00:00:00 2001 From: ciscoxll Date: Wed, 5 Sep 2018 14:45:22 +0800 Subject: [PATCH 4/5] update function comment --- model/model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/model.go b/model/model.go index 83dff84a0575c..2be9f33584123 100644 --- a/model/model.go +++ b/model/model.go @@ -96,7 +96,7 @@ 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. - // For mysql.TypeBit type, default value is null is supported. + // For mysql.TypeBit type, the default value is null is supported. if value == nil { return nil } From 29e9f7fd53f7a637f749782ce607a9bb02494e91 Mon Sep 17 00:00:00 2001 From: ciscoxll Date: Wed, 5 Sep 2018 15:40:20 +0800 Subject: [PATCH 5/5] update function comment --- model/model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/model.go b/model/model.go index 2be9f33584123..74545f8d4f47b 100644 --- a/model/model.go +++ b/model/model.go @@ -96,7 +96,7 @@ 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. - // For mysql.TypeBit type, the default value is null is supported. + // The mysql.TypeBit type supports the null default value. if value == nil { return nil }