Skip to content

Commit 73d7aac

Browse files
committed
smarter type conversion (STMT_EXEC)
1 parent 5079f1c commit 73d7aac

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

packets.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -582,23 +582,23 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
582582
}
583583

584584
// cache types and values
585-
switch args[i].(type) {
585+
switch v := args[i].(type) {
586586
case int64:
587587
paramTypes[i<<1] = fieldTypeLongLong
588-
paramValues[i] = uint64ToBytes(uint64(args[i].(int64)))
588+
paramValues[i] = uint64ToBytes(uint64(v))
589589
pktLen += 8
590590
continue
591591

592592
case float64:
593593
paramTypes[i<<1] = fieldTypeDouble
594-
paramValues[i] = uint64ToBytes(math.Float64bits(args[i].(float64)))
594+
paramValues[i] = uint64ToBytes(math.Float64bits(v))
595595
pktLen += 8
596596
continue
597597

598598
case bool:
599599
paramTypes[i<<1] = fieldTypeTiny
600600
pktLen++
601-
if args[i].(bool) {
601+
if v {
602602
paramValues[i] = []byte{0x01}
603603
} else {
604604
paramValues[i] = []byte{0x00}
@@ -607,27 +607,25 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
607607

608608
case []byte:
609609
paramTypes[i<<1] = fieldTypeString
610-
val := args[i].([]byte)
611610
paramValues[i] = append(
612-
lengthEncodedIntegerToBytes(uint64(len(val))),
613-
val...,
611+
lengthEncodedIntegerToBytes(uint64(len(v))),
612+
v...,
614613
)
615614
pktLen += len(paramValues[i])
616615
continue
617616

618617
case string:
619618
paramTypes[i<<1] = fieldTypeString
620-
val := []byte(args[i].(string))
621619
paramValues[i] = append(
622-
lengthEncodedIntegerToBytes(uint64(len(val))),
623-
val...,
620+
lengthEncodedIntegerToBytes(uint64(len(v))),
621+
[]byte(v)...,
624622
)
625623
pktLen += len(paramValues[i])
626624
continue
627625

628626
case time.Time:
629627
paramTypes[i<<1] = fieldTypeString
630-
val := []byte(args[i].(time.Time).Format(timeFormat))
628+
val := []byte(v.Format(timeFormat))
631629
paramValues[i] = append(
632630
lengthEncodedIntegerToBytes(uint64(len(val))),
633631
val...,

0 commit comments

Comments
 (0)