Skip to content

Commit 1f266d5

Browse files
author
Achille Roussel
committed
support versions of Go before 1.5
1 parent c184106 commit 1f266d5

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

packets.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
10841084
if v.IsZero() {
10851085
b = append(b, "0000-00-00"...)
10861086
} else {
1087-
b = v.In(mc.cfg.Loc).AppendFormat(b, timeFormat)
1087+
b = appendTimeFormat(b, v.In(mc.cfg.Loc), timeFormat)
10881088
}
10891089

10901090
paramValues = appendLengthEncodedInteger(paramValues,

time.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2+
//
3+
// Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
7+
// You can obtain one at http://mozilla.org/MPL/2.0/.
8+
9+
// +build go1.5
10+
11+
package mysql
12+
13+
import "time"
14+
15+
// appendTimeFormat is used as an optimization on Go 1.5+ to avoid the dynamic
16+
// memory allocation that happens for the string returned by time.Format.
17+
func appendTimeFormat(b []byte, t time.Time, format string) []byte {
18+
return t.AppendFormat(b, format)
19+
}

time_legacy.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2+
//
3+
// Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
7+
// You can obtain one at http://mozilla.org/MPL/2.0/.
8+
9+
// +build !go1.5
10+
11+
package mysql
12+
13+
import "time"
14+
15+
// appendTimeFormat is used as an optimization on Go 1.5+ to avoid the dynamic
16+
// memory allocation that happens for the string returned by time.Format.
17+
func appendTimeFormat(b []byte, t time.Time, format string) []byte {
18+
return append(b, time.Format(format)...)
19+
}

0 commit comments

Comments
 (0)