From ab6e795560e8c0d4cd4e2a3737b297121a941ad5 Mon Sep 17 00:00:00 2001 From: Ben Harper Date: Thu, 10 Nov 2022 09:43:43 +0200 Subject: [PATCH 1/2] Fix buffer overwrite when emitting TIME(0) datatype --- types.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types.go b/types.go index 87803416..2627c18e 100644 --- a/types.go +++ b/types.go @@ -915,8 +915,10 @@ func decodeTime(scale uint8, buf []byte) time.Time { func encodeTime(hour, minute, second, ns, scale int) (buf []byte) { seconds := hour*3600 + minute*60 + second - buf = make([]byte, calcTimeSize(scale)) + timeSize := calcTimeSize(scale) + buf = make([]byte, timeSize+2) encodeTimeInt(seconds, ns, scale, buf) + buf = buf[:timeSize] return } From 01f253b53602d39ba255a50027ef633dea1b640b Mon Sep 17 00:00:00 2001 From: Ben Harper Date: Fri, 11 Nov 2022 10:22:31 +0200 Subject: [PATCH 2/2] Add test for bulk copy into time(0) This test currently fails. I can't figure out what the server wants. --- bulkcopy_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bulkcopy_test.go b/bulkcopy_test.go index 5de35154..a241ce13 100644 --- a/bulkcopy_test.go +++ b/bulkcopy_test.go @@ -58,6 +58,7 @@ func TestBulkcopy(t *testing.T) { {"test_date_2", "2015-06-07", time.Date(2015, 6, 7, 0, 0, 0, 0, time.UTC)}, {"test_time", time.Date(2010, 11, 12, 13, 14, 15, 123000000, time.UTC), time.Date(1, 1, 1, 13, 14, 15, 123000000, time.UTC)}, {"test_time_2", "13:14:15.1230000", time.Date(1, 1, 1, 13, 14, 15, 123000000, time.UTC)}, + {"test_time_0", "13:14:15", time.Date(1, 1, 1, 13, 14, 15, 0, time.UTC)}, {"test_tinyint", 255, nil}, {"test_smallint", 32767, nil}, {"test_smallintn", nil, nil}, @@ -256,6 +257,7 @@ func setupTable(ctx context.Context, t *testing.T, conn *sql.Conn, tableName str [test_date_2] [date] NULL, [test_time] [time](7) NULL, [test_time_2] [time](7) NULL, + [test_time_0] [time](0) NULL, [test_smallmoney] [smallmoney] NULL, [test_money] [money] NULL, [test_tinyint] [tinyint] NULL,