Skip to content

Commit

Permalink
handle sql.NullTime parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
shueybubbles committed May 22, 2024
1 parent ada30cb commit 06311c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions alwaysencrypted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 06311c3

Please sign in to comment.