Skip to content

Commit 248fcf1

Browse files
committed
parse integers on text protocol
1 parent 564dee9 commit 248fcf1

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

packets.go

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"fmt"
1818
"io"
1919
"math"
20+
"strconv"
2021
"time"
2122
)
2223

@@ -834,7 +835,8 @@ func (rows *textRows) readRow(dest []driver.Value) error {
834835

835836
for i := range dest {
836837
// Read bytes and convert to string
837-
dest[i], isNull, n, err = readLengthEncodedString(data[pos:])
838+
var buf []byte
839+
buf, isNull, n, err = readLengthEncodedString(data[pos:])
838840
pos += n
839841

840842
if err != nil {
@@ -846,19 +848,40 @@ func (rows *textRows) readRow(dest []driver.Value) error {
846848
continue
847849
}
848850

849-
if !mc.parseTime {
850-
continue
851-
}
852-
853-
// Parse time field
854851
switch rows.rs.columns[i].fieldType {
855852
case fieldTypeTimestamp,
856853
fieldTypeDateTime,
857854
fieldTypeDate,
858855
fieldTypeNewDate:
859-
if dest[i], err = parseDateTime(dest[i].([]byte), mc.cfg.Loc); err != nil {
860-
return err
856+
if mc.parseTime {
857+
dest[i], err = parseDateTime(buf, mc.cfg.Loc)
858+
} else {
859+
dest[i] = buf
860+
}
861+
862+
case fieldTypeTiny, fieldTypeShort, fieldTypeInt24, fieldTypeYear, fieldTypeLong:
863+
dest[i], err = strconv.ParseInt(string(buf), 10, 32)
864+
865+
case fieldTypeLongLong:
866+
if rows.rs.columns[i].flags&flagUnsigned != 0 {
867+
dest[i], err = strconv.ParseUint(string(buf), 10, 64)
868+
} else {
869+
dest[i], err = strconv.ParseInt(string(buf), 10, 64)
861870
}
871+
872+
case fieldTypeFloat:
873+
var d float64
874+
d, err = strconv.ParseFloat(string(buf), 32)
875+
dest[i] = float32(d)
876+
877+
case fieldTypeDouble:
878+
dest[i], err = strconv.ParseFloat(string(buf), 64)
879+
880+
default:
881+
dest[i] = buf
882+
}
883+
if err != nil {
884+
return err
862885
}
863886
}
864887

0 commit comments

Comments
 (0)