From a81a32e62e6160054ed20e1203d3c7c0653138f9 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Thu, 7 Jul 2022 16:08:00 +0300 Subject: [PATCH] fix(proto): fix DateTime overflow --- proto/datetime.go | 2 +- query_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/proto/datetime.go b/proto/datetime.go index 37bb389e..4917339e 100644 --- a/proto/datetime.go +++ b/proto/datetime.go @@ -3,7 +3,7 @@ package proto import "time" // DateTime represents DateTime type. -type DateTime int32 +type DateTime uint32 // ToDateTime converts time.Time to DateTime. func ToDateTime(t time.Time) DateTime { diff --git a/query_test.go b/query_test.go index 035dd4fc..6932fa84 100644 --- a/query_test.go +++ b/query_test.go @@ -26,6 +26,22 @@ func requireEqual[T any](t *testing.T, a, b proto.ColumnOf[T]) { } } +func TestDateTimeOverflow(t *testing.T) { + t.Parallel() + ctx := context.Background() + conn := Conn(t) + var data proto.ColDateTime + query := Query{ + Body: "SELECT toDateTime('2061-02-01 00:00:00') as v", + Result: proto.Results{ + {Name: "v", Data: &data}, + }, + } + require.NoError(t, conn.Do(ctx, query)) + require.Equal(t, 1, data.Rows()) + require.Equal(t, "2061-02-01 00:00:00", data.Row(0).Format("2006-01-02 15:04:05")) +} + func TestClient_Query(t *testing.T) { ctx := context.Background() t.Parallel()