jamf / go-mysqldump

Create SQL dumps in Go without external dependencies
MIT License
18 stars 24 forks source link

fix: use native ScanType from driver and enhance RowBuffer to understand more types #18

Open mechinn opened 1 year ago

mechinn commented 1 year ago

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.

mechinn commented 1 year ago

added a workaround for https://github.com/go-sql-driver/mysql/pull/1424 not being in a released version yet by adding reflectColumnType() back just to handle string/binary types correctly