the go mysql driver provides a very good mapping of database types to go types by doing reflect.New(tp.ScanType()).Interface() directly instead of manually mapping all integers to sql.NullInt64, strings to sql.NullString, etc. with reflectColumnType()
It seems the reason the ColumnType was being interpreted differently was to account for mocking VARCHAR columns that were expected to have rows with NULL values that could not be scanned to a simple string, the fix was to change the unit tests to have the sampleValue be a sql.NullString{} instead of a simple string.
This allows database connections that have ParseTime = true to correctly dump DATETIME columns.
Also wrapped SET NAMES and SET character_set_client with mysql version comments like mysqldump does.
the go mysql driver provides a very good mapping of database types to go types by doing
reflect.New(tp.ScanType()).Interface()
directly instead of manually mapping all integers tosql.NullInt64
, strings tosql.NullString
, etc. withreflectColumnType()
It seems the reason the
ColumnType
was being interpreted differently was to account for mocking VARCHAR columns that were expected to have rows with NULL values that could not be scanned to a simplestring
, the fix was to change the unit tests to have thesampleValue
be asql.NullString{}
instead of a simplestring
.This allows database connections that have
ParseTime = true
to correctly dumpDATETIME
columns.Also wrapped
SET NAMES
andSET character_set_client
with mysql version comments like mysqldump does.