From 06311c36f2acff7b99aa945385b948c94a4b20d3 Mon Sep 17 00:00:00 2001 From: davidshi Date: Wed, 22 May 2024 15:25:29 -0500 Subject: [PATCH] handle sql.NullTime parameters --- alwaysencrypted_test.go | 2 ++ mssql.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/alwaysencrypted_test.go b/alwaysencrypted_test.go index 9dd08b59..f9a74bf3 100644 --- a/alwaysencrypted_test.go +++ b/alwaysencrypted_test.go @@ -70,6 +70,8 @@ func TestAlwaysEncryptedE2E(t *testing.T) { {"bigint", "BIGINT", ColumnEncryptionDeterministic, sql.NullInt64{Int64: 128, Valid: true}}, {"uniqueidentifier", "UNIQUEIDENTIFIER", ColumnEncryptionRandomized, UniqueIdentifier{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}}, {"uniqueidentifier", "UNIQUEIDENTIFIER", ColumnEncryptionRandomized, NullUniqueIdentifier{Valid: false}}, + {"datetimeoffset(7)", "DATETIMEOFFSET", ColumnEncryptionDeterministic, sql.NullTime{Valid: false}}, + {"datetimeoffset(7)", "DATETIMEOFFSET", ColumnEncryptionDeterministic, sql.NullTime{Valid: true, Time: time.Now()}}, } for _, test := range providerTests { // turn off key caching diff --git a/mssql.go b/mssql.go index f86d5361..fd8ca10a 100644 --- a/mssql.go +++ b/mssql.go @@ -1110,6 +1110,15 @@ func (s *Stmt) makeParam(val driver.Value) (res param, err error) { res.buffer = encodeDateTime(val) res.ti.Size = len(res.buffer) } + case sql.NullTime: // only null values reach here + res.buffer = []byte{} + res.ti.Size = 8 + if s.c.sess.loginAck.TDSVersion >= verTDS73 { + res.ti.TypeId = typeDateTimeOffsetN + res.ti.Scale = 7 + } else { + res.ti.TypeId = typeDateTimeN + } default: return s.makeParamExtra(val) }