From e44c56b46ffd4e4b5556c3086fe658e97ab434dc Mon Sep 17 00:00:00 2001 From: "Dolf Schimmel (Freeaqingme)" Date: Fri, 5 Jun 2015 02:04:28 +0200 Subject: [PATCH 1/3] Set a nil date to NULL rather than 0000-00-00 --- packets.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packets.go b/packets.go index 290a3887a..0532d0185 100644 --- a/packets.go +++ b/packets.go @@ -930,15 +930,18 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error { } case time.Time: + if v.IsZero() { + nullMask[i/8] |= 1 << (uint(i) & 7) + paramTypes[i+i] = fieldTypeNULL + paramTypes[i+i+1] = 0x00 + continue + } + paramTypes[i+i] = fieldTypeString paramTypes[i+i+1] = 0x00 var val []byte - if v.IsZero() { - val = []byte("0000-00-00") - } else { - val = []byte(v.In(mc.cfg.loc).Format(timeFormat)) - } + val = []byte(v.In(mc.cfg.loc).Format(timeFormat)) paramValues = appendLengthEncodedInteger(paramValues, uint64(len(val)), From 4f50868972038ecd1246e3e4cd654059c3e73b5d Mon Sep 17 00:00:00 2001 From: "Dolf Schimmel (Freeaqingme)" Date: Fri, 5 Jun 2015 02:21:27 +0200 Subject: [PATCH 2/3] Set a nil date to NULL rather than 0000-00-00, but only in strict mode --- packets.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packets.go b/packets.go index 310605c22..8742a5870 100644 --- a/packets.go +++ b/packets.go @@ -971,7 +971,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error { } case time.Time: - if v.IsZero() { + if stmt.mc.strict && v.IsZero() { nullMask[i/8] |= 1 << (uint(i) & 7) paramTypes[i+i] = fieldTypeNULL paramTypes[i+i+1] = 0x00 From 299afd763b181066345683ec363345f050ee8653 Mon Sep 17 00:00:00 2001 From: "Dolf Schimmel (Freeaqingme)" Date: Fri, 5 Jun 2015 02:24:31 +0200 Subject: [PATCH 3/3] Restore old behavior for NULL time.Time when strict mode is not enabled --- packets.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packets.go b/packets.go index 8742a5870..8982eac91 100644 --- a/packets.go +++ b/packets.go @@ -982,7 +982,11 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error { paramTypes[i+i+1] = 0x00 var val []byte - val = []byte(v.In(mc.cfg.loc).Format(timeFormat)) + if v.IsZero() { + val = []byte("0000-00-00") + } else { + val = []byte(v.In(mc.cfg.loc).Format(timeFormat)) + } paramValues = appendLengthEncodedInteger(paramValues, uint64(len(val)),