Skip to content

Commit cde4f46

Browse files
committed
fields: make fieldType its own type
1 parent cf68e20 commit cde4f46

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

const.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ const (
8787
)
8888

8989
// https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-Protocol::ColumnType
90+
type fieldType byte
91+
9092
const (
91-
fieldTypeDecimal byte = iota
93+
fieldTypeDecimal fieldType = iota
9294
fieldTypeTiny
9395
fieldTypeShort
9496
fieldTypeLong
@@ -107,7 +109,7 @@ const (
107109
fieldTypeBit
108110
)
109111
const (
110-
fieldTypeJSON byte = iota + 0xf5
112+
fieldTypeJSON fieldType = iota + 0xf5
111113
fieldTypeNewDecimal
112114
fieldTypeEnum
113115
fieldTypeSet

fields.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type mysqlField struct {
4141
tableName string
4242
name string
4343
flags fieldFlag
44-
fieldType byte
44+
fieldType fieldType
4545
decimals byte
4646
}
4747

packets.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ func (mc *mysqlConn) readColumns(count int) ([]mysqlField, error) {
676676
pos += n + 1 + 2 + 4
677677

678678
// Field type [uint8]
679-
columns[i].fieldType = data[pos]
679+
columns[i].fieldType = fieldType(data[pos])
680680
pos++
681681

682682
// Flags [uint16]
@@ -960,15 +960,15 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
960960
// build NULL-bitmap
961961
if arg == nil {
962962
nullMask[i/8] |= 1 << (uint(i) & 7)
963-
paramTypes[i+i] = fieldTypeNULL
963+
paramTypes[i+i] = byte(fieldTypeNULL)
964964
paramTypes[i+i+1] = 0x00
965965
continue
966966
}
967967

968968
// cache types and values
969969
switch v := arg.(type) {
970970
case int64:
971-
paramTypes[i+i] = fieldTypeLongLong
971+
paramTypes[i+i] = byte(fieldTypeLongLong)
972972
paramTypes[i+i+1] = 0x00
973973

974974
if cap(paramValues)-len(paramValues)-8 >= 0 {
@@ -984,7 +984,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
984984
}
985985

986986
case float64:
987-
paramTypes[i+i] = fieldTypeDouble
987+
paramTypes[i+i] = byte(fieldTypeDouble)
988988
paramTypes[i+i+1] = 0x00
989989

990990
if cap(paramValues)-len(paramValues)-8 >= 0 {
@@ -1000,7 +1000,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
10001000
}
10011001

10021002
case bool:
1003-
paramTypes[i+i] = fieldTypeTiny
1003+
paramTypes[i+i] = byte(fieldTypeTiny)
10041004
paramTypes[i+i+1] = 0x00
10051005

10061006
if v {
@@ -1012,7 +1012,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
10121012
case []byte:
10131013
// Common case (non-nil value) first
10141014
if v != nil {
1015-
paramTypes[i+i] = fieldTypeString
1015+
paramTypes[i+i] = byte(fieldTypeString)
10161016
paramTypes[i+i+1] = 0x00
10171017

10181018
if len(v) < mc.maxAllowedPacket-pos-len(paramValues)-(len(args)-(i+1))*64 {
@@ -1030,11 +1030,11 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
10301030

10311031
// Handle []byte(nil) as a NULL value
10321032
nullMask[i/8] |= 1 << (uint(i) & 7)
1033-
paramTypes[i+i] = fieldTypeNULL
1033+
paramTypes[i+i] = byte(fieldTypeNULL)
10341034
paramTypes[i+i+1] = 0x00
10351035

10361036
case string:
1037-
paramTypes[i+i] = fieldTypeString
1037+
paramTypes[i+i] = byte(fieldTypeString)
10381038
paramTypes[i+i+1] = 0x00
10391039

10401040
if len(v) < mc.maxAllowedPacket-pos-len(paramValues)-(len(args)-(i+1))*64 {
@@ -1049,7 +1049,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
10491049
}
10501050

10511051
case time.Time:
1052-
paramTypes[i+i] = fieldTypeString
1052+
paramTypes[i+i] = byte(fieldTypeString)
10531053
paramTypes[i+i+1] = 0x00
10541054

10551055
var val []byte

0 commit comments

Comments
 (0)