From 41a31fc048ad43fe27495d7f68198eb7c5736a2d Mon Sep 17 00:00:00 2001 From: Patrick O'brien Date: Sat, 12 Nov 2016 13:40:11 +1000 Subject: [PATCH] Fix byte scan --- byte.go | 13 ++++++++++--- byte_test.go | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/byte.go b/byte.go index 69339ff..edc8613 100644 --- a/byte.go +++ b/byte.go @@ -5,8 +5,6 @@ import ( "database/sql/driver" "encoding/json" "errors" - - "gopkg.in/nullbio/null.v6/convert" ) // Byte is an nullable int. @@ -115,8 +113,17 @@ func (b *Byte) Scan(value interface{}) error { b.Byte, b.Valid = 0, false return nil } + + val := value.(string) + if len(val) == 0 { + b.Valid = false + b.Byte = 0 + return nil + } + b.Valid = true - return convert.ConvertAssign(&b.Byte, value) + b.Byte = byte(val[0]) + return nil } // Value implements the driver Valuer interface. diff --git a/byte_test.go b/byte_test.go index a6076f4..19e547e 100644 --- a/byte_test.go +++ b/byte_test.go @@ -136,7 +136,7 @@ func TestByteSetValid(t *testing.T) { func TestByteScan(t *testing.T) { var i Byte - err := i.Scan('b') + err := i.Scan("b") maybePanic(err) assertByte(t, i, "scanned int")