Skip to content

Commit a825be0

Browse files
achille-rousseljulienschmidt
authored andcommitted
packets: use AppendFormat to format time values (#615)
* use AppendFormat to format time values * drop support for Go 1.4
1 parent 72e0ac3 commit a825be0

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
sudo: false
22
language: go
33
go:
4-
- 1.4
54
- 1.5
65
- 1.6
76
- 1.7

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>

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) pac
3939
* Optional placeholder interpolation
4040

4141
## Requirements
42-
* Go 1.4 or higher
42+
* Go 1.5 or higher
4343
* MySQL (4.1+), MariaDB, Percona Server, Google CloudSQL or Sphinx (2.2.3+)
4444

4545
---------------------------------------

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)