Skip to content

Commit

Permalink
server: fix type year has too many 0s in prepare/execute (#7525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingyu Song authored and coocood committed Aug 30, 2018
1 parent 55af7e1 commit 4a31302
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/driver_tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand Down
22 changes: 22 additions & 0 deletions server/driver_tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 4a31302

Please sign in to comment.