Skip to content

Commit a82205e

Browse files
Merge pull request #1 from achille-roussel/optimize-time-format
use AppendFormat to format time values
2 parents 5622634 + c184106 commit a82205e

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# Individual Persons
1313

1414
Aaron Hopkins <go-sql-driver at die.net>
15+
Achille Roussel <achille.roussel at gmail.com>
1516
Arne Hormann <arnehormann at gmail.com>
1617
Asta Xie <xiemengjun at gmail.com>
1718
Bulat Gaifullin <gaifullinbf at gmail.com>

packets.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -1078,17 +1078,19 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
10781078
paramTypes[i+i] = fieldTypeString
10791079
paramTypes[i+i+1] = 0x00
10801080

1081-
var val []byte
1081+
var a [64]byte
1082+
var b = a[:0]
1083+
10821084
if v.IsZero() {
1083-
val = []byte("0000-00-00")
1085+
b = append(b, "0000-00-00"...)
10841086
} else {
1085-
val = []byte(v.In(mc.cfg.Loc).Format(timeFormat))
1087+
b = v.In(mc.cfg.Loc).AppendFormat(b, timeFormat)
10861088
}
10871089

10881090
paramValues = appendLengthEncodedInteger(paramValues,
1089-
uint64(len(val)),
1091+
uint64(len(b)),
10901092
)
1091-
paramValues = append(paramValues, val...)
1093+
paramValues = append(paramValues, b...)
10921094

10931095
default:
10941096
return fmt.Errorf("can not convert type: %T", arg)

0 commit comments

Comments
 (0)