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

server: fix resultType/flag of enum&set column #7417

Merged
merged 3 commits into from
Aug 17, 2018
Merged
Changes from all 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
28 changes: 26 additions & 2 deletions server/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

package server

import (
"github.com/pingcap/tidb/mysql"
)

// ColumnInfo contains information of a column
type ColumnInfo struct {
Schema string
Expand Down Expand Up @@ -42,8 +46,8 @@ func (column *ColumnInfo) Dump(buffer []byte) []byte {

buffer = dumpUint16(buffer, column.Charset)
buffer = dumpUint32(buffer, column.ColumnLength)
buffer = append(buffer, column.Type)
buffer = dumpUint16(buffer, column.Flag)
buffer = append(buffer, dumpType(column.Type))
buffer = dumpUint16(buffer, dumpFlag(column.Type, column.Flag))
buffer = append(buffer, column.Decimal)
buffer = append(buffer, 0, 0)

Expand All @@ -54,3 +58,23 @@ func (column *ColumnInfo) Dump(buffer []byte) []byte {

return buffer
}

func dumpFlag(tp byte, flag uint16) uint16 {
switch tp {
case mysql.TypeSet:
return flag | uint16(mysql.SetFlag)
case mysql.TypeEnum:
return flag | uint16(mysql.TypeEnum)
default:
return flag
}
}

func dumpType(tp byte) byte {
switch tp {
case mysql.TypeSet, mysql.TypeEnum:
return mysql.TypeString
default:
return tp
}
}