From 92d3afb64f2a985eb93bb35f42107d3e519ed1ef Mon Sep 17 00:00:00 2001 From: imtbkcat Date: Wed, 29 Aug 2018 11:41:36 +0800 Subject: [PATCH 1/2] fix too many 0s --- server/driver_tidb.go | 2 +- server/driver_tidb_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/server/driver_tidb.go b/server/driver_tidb.go index 739e253e7422e..e9e5387967087 100644 --- a/server/driver_tidb.go +++ b/server/driver_tidb.go @@ -391,7 +391,7 @@ func convertColumnInfo(fld *ast.ResultField) (ci *ColumnInfo) { // Consider the decimal point. ci.ColumnLength++ } - } else if fld.Column.Tp != mysql.TypeBit && fld.Column.Tp != mysql.TypeTiny { + } else if fld.Column.Tp != mysql.TypeBit && fld.Column.Tp != mysql.TypeTiny && types.IsString(fld.Column.Tp) { // Fix issue #4540. // The flen is a hint, not a precise value, so most client will not use the value. // But we found in rare MySQL client, like Navicat for MySQL(version before 12) will truncate diff --git a/server/driver_tidb_test.go b/server/driver_tidb_test.go index f1298e083db70..97e7b87b05040 100644 --- a/server/driver_tidb_test.go +++ b/server/driver_tidb_test.go @@ -88,4 +88,26 @@ func (ts tidbResultSetTestSuite) TestConvertColumnInfo(c *C) { } colInfo = convertColumnInfo(&resultField) c.Assert(colInfo, DeepEquals, createColumnByTypeAndLen(mysql.TypeTiny, 1)) + + resultField = ast.ResultField{ + Column: &model.ColumnInfo{ + Name: model.NewCIStr("a"), + ID: 0, + Offset: 0, + FieldType: types.FieldType{ + Tp: mysql.TypeYear, + Flag: mysql.ZerofillFlag, + Flen: 4, + Decimal: 0, + Charset: charset.CharsetBin, + Collate: charset.CollationBin, + }, + Comment: "column a is the first column in table dual", + }, + ColumnAsName: model.NewCIStr("a"), + TableAsName: model.NewCIStr("dual"), + DBName: model.NewCIStr("test"), + } + colInfo = convertColumnInfo(&resultField) + c.Assert(colInfo.ColumnLength, Equals, uint32(4)) } From 0ca894713075780e1f362d37289272764bc4ce76 Mon Sep 17 00:00:00 2001 From: imtbkcat Date: Wed, 29 Aug 2018 17:52:23 +0800 Subject: [PATCH 2/2] remove extra condition --- server/driver_tidb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/driver_tidb.go b/server/driver_tidb.go index e9e5387967087..630f311a091fa 100644 --- a/server/driver_tidb.go +++ b/server/driver_tidb.go @@ -391,7 +391,7 @@ func convertColumnInfo(fld *ast.ResultField) (ci *ColumnInfo) { // Consider the decimal point. ci.ColumnLength++ } - } else if fld.Column.Tp != mysql.TypeBit && fld.Column.Tp != mysql.TypeTiny && types.IsString(fld.Column.Tp) { + } else if types.IsString(fld.Column.Tp) { // Fix issue #4540. // The flen is a hint, not a precise value, so most client will not use the value. // But we found in rare MySQL client, like Navicat for MySQL(version before 12) will truncate