1
0
mirror of https://github.com/google/uuid.git synced 2025-11-06 08:59:16 +02:00

altered uuid.Scan() so that it allows for empty UUIDs to be read properly (returning a null UUID value)

This commit is contained in:
Daniel Souza
2016-01-21 23:52:00 -05:00
parent dee7705ef7
commit 6a70b0ec98

10
sql.go
View File

@@ -15,6 +15,11 @@ import (
func (uuid *UUID) Scan(src interface{}) error {
switch src.(type) {
case string:
// if an empty UUID comes from a table, we return a null UUID
if src.(string) == "" {
return nil
}
// see uuid.Parse for required string format
parsed := Parse(src.(string))
@@ -26,6 +31,11 @@ func (uuid *UUID) Scan(src interface{}) error {
case []byte:
b := src.([]byte)
// if an empty UUID comes from a table, we return a null UUID
if len(b) == 0 {
return nil
}
// assumes a simple slice of bytes if 16 bytes
// otherwise attempts to parse
if len(b) == 16 {