瀏覽代碼

null string

ls 5 年之前
父節點
當前提交
616fcb21c3
共有 1 個文件被更改,包括 9 次插入3 次删除
  1. 9 3
      types/string.go

+ 9 - 3
types/string.go

@@ -22,11 +22,17 @@ func (s TextNull) Value() (driver.Value, error) {
 // Scan implements the sql.Scanner interface,
 // and turns the bytes incoming from MySQL into a string
 func (s *TextNull) Scan(src interface{}) error {
-	if src == nil {
-		*s = TextNull("")
+	if src != nil {
+		v, ok := src.([]byte)
+		if !ok {
+			return errors.New("bad []byte type assertion")
+		}
+
+		*s = TextNull(v)
+		return nil
 	}
 
-	convertAssign(&s, src)
+	*s = TextNull("")
 
 	return nil
 }