1
0
mirror of https://github.com/google/uuid.git synced 2024-11-24 08:32:23 +02:00

sql: Support nil values

This commit is contained in:
Andrew Stone 2017-03-03 14:59:38 -08:00
parent c96242ef50
commit 3694829644
2 changed files with 14 additions and 0 deletions

3
sql.go
View File

@ -14,6 +14,9 @@ import (
// consult database-specific driver documentation for matching types.
func (uuid *UUID) Scan(src interface{}) error {
switch src := src.(type) {
case nil:
return nil
case string:
// if an empty UUID comes from a table, we return a null UUID
if src == "" {

View File

@ -90,6 +90,17 @@ func TestScan(t *testing.T) {
t.Error("UUID was not nil after scanning empty byte slice")
}
}
uuid = UUID{}
err = (&uuid).Scan(nil)
if err != nil {
t.Fatal(err)
}
for _, v := range uuid {
if v != 0 {
t.Error("UUID was not nil after scanning nil")
}
}
}
func TestValue(t *testing.T) {