Skip to content

Commit 571f082

Browse files
committed
fields: make fieldType its own type
1 parent 1b786bd commit 571f082

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
@@ -703,7 +703,7 @@ func (mc *mysqlConn) readColumns(count int) ([]mysqlField, error) {
703703
pos += n + 1 + 2 + 4
704704

705705
// Field type [uint8]
706-
columns[i].fieldType = data[pos]
706+
columns[i].fieldType = fieldType(data[pos])
707707
pos++
708708

709709
// Flags [uint16]
@@ -980,15 +980,15 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
980980
// build NULL-bitmap
981981
if arg == nil {
982982
nullMask[i/8] |= 1 << (uint(i) & 7)
983-
paramTypes[i+i] = fieldTypeNULL
983+
paramTypes[i+i] = byte(fieldTypeNULL)
984984
paramTypes[i+i+1] = 0x00
985985
continue
986986
}
987987

988988
// cache types and values
989989
switch v := arg.(type) {
990990
case int64:
991-
paramTypes[i+i] = fieldTypeLongLong
991+
paramTypes[i+i] = byte(fieldTypeLongLong)
992992
paramTypes[i+i+1] = 0x00
993993

994994
if cap(paramValues)-len(paramValues)-8 >= 0 {
@@ -1004,7 +1004,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
10041004
}
10051005

10061006
case float64:
1007-
paramTypes[i+i] = fieldTypeDouble
1007+
paramTypes[i+i] = byte(fieldTypeDouble)
10081008
paramTypes[i+i+1] = 0x00
10091009

10101010
if cap(paramValues)-len(paramValues)-8 >= 0 {
@@ -1020,7 +1020,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
10201020
}
10211021

10221022
case bool:
1023-
paramTypes[i+i] = fieldTypeTiny
1023+
paramTypes[i+i] = byte(fieldTypeTiny)
10241024
paramTypes[i+i+1] = 0x00
10251025

10261026
if v {
@@ -1032,7 +1032,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
10321032
case []byte:
10331033
// Common case (non-nil value) first
10341034
if v != nil {
1035-
paramTypes[i+i] = fieldTypeString
1035+
paramTypes[i+i] = byte(fieldTypeString)
10361036
paramTypes[i+i+1] = 0x00
10371037

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

10511051
// Handle []byte(nil) as a NULL value
10521052
nullMask[i/8] |= 1 << (uint(i) & 7)
1053-
paramTypes[i+i] = fieldTypeNULL
1053+
paramTypes[i+i] = byte(fieldTypeNULL)
10541054
paramTypes[i+i+1] = 0x00
10551055

10561056
case string:
1057-
paramTypes[i+i] = fieldTypeString
1057+
paramTypes[i+i] = byte(fieldTypeString)
10581058
paramTypes[i+i+1] = 0x00
10591059

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

10711071
case time.Time:
1072-
paramTypes[i+i] = fieldTypeString
1072+
paramTypes[i+i] = byte(fieldTypeString)
10731073
paramTypes[i+i+1] = 0x00
10741074

10751075
var a [64]byte

0 commit comments

Comments
 (0)