From 58e34726dfc069b558038efbaa25555f182d1f7a Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 18 Feb 2018 09:00:03 +0800 Subject: [PATCH] Don't access scanner's fields if already defined data type --- dialect.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dialect.go b/dialect.go index b20bfd5b..5f6439c1 100644 --- a/dialect.go +++ b/dialect.go @@ -94,14 +94,16 @@ var ParseFieldStructForDialect = func(field *StructField, dialect Dialect) (fiel } // Get scanner's real value - var getScannerValue func(reflect.Value) - getScannerValue = func(value reflect.Value) { - fieldValue = value - if _, isScanner := reflect.New(fieldValue.Type()).Interface().(sql.Scanner); isScanner && fieldValue.Kind() == reflect.Struct { - getScannerValue(fieldValue.Field(0)) + if dataType == "" { + var getScannerValue func(reflect.Value) + getScannerValue = func(value reflect.Value) { + fieldValue = value + if _, isScanner := reflect.New(fieldValue.Type()).Interface().(sql.Scanner); isScanner && fieldValue.Kind() == reflect.Struct { + getScannerValue(fieldValue.Field(0)) + } } + getScannerValue(fieldValue) } - getScannerValue(fieldValue) // Default Size if num, ok := field.TagSettings["SIZE"]; ok {