Skip to content
Merged
Changes from 1 commit
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
18 changes: 13 additions & 5 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ var (
scanTypeUint16 = reflect.TypeOf(uint16(0))
scanTypeUint32 = reflect.TypeOf(uint32(0))
scanTypeUint64 = reflect.TypeOf(uint64(0))
scanTypeString = reflect.TypeOf(string(""))
scanTypeRawBytes = reflect.TypeOf(sql.RawBytes{})
scanTypeUnknown = reflect.TypeOf(new(interface{}))
)
Expand Down Expand Up @@ -175,11 +176,18 @@ func (mf *mysqlField) scanType() reflect.Type {
}
return scanTypeNullFloat

case fieldTypeDecimal, fieldTypeNewDecimal, fieldTypeVarChar,
fieldTypeBit, fieldTypeEnum, fieldTypeSet, fieldTypeTinyBLOB,
fieldTypeMediumBLOB, fieldTypeLongBLOB, fieldTypeBLOB,
fieldTypeVarString, fieldTypeString, fieldTypeGeometry, fieldTypeJSON,
fieldTypeTime:
case fieldTypeVarChar, fieldTypeString, fieldTypeVarString:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of VARBINARY and VARCHAR uses VARCHAR field type.
This case statement should be merged in the next case.

return scanTypeString

case fieldTypeTinyBLOB, fieldTypeMediumBLOB, fieldTypeLongBLOB, fieldTypeBLOB:
if mf.charSet == collations[defaultCollation] {
return scanTypeString
}
fallthrough
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://dev.mysql.com/doc/refman/8.0/en/c-api-data-structures.html

To distinguish between binary and nonbinary data for string data types, check whether the charsetnr value is 63.

So correct code is this:

// charsetnr == 63 means this column is binary.
// https://dev.mysql.com/doc/refman/8.0/en/c-api-data-structures.html
if mf.charSet == 63 {
    return scanTypeRawBytes
}
return scanTypeString


case fieldTypeDecimal, fieldTypeNewDecimal, fieldTypeBit,
fieldTypeEnum, fieldTypeSet,
fieldTypeGeometry, fieldTypeJSON, fieldTypeTime:
return scanTypeRawBytes

case fieldTypeDate, fieldTypeNewDate,
Expand Down