Skip to content

Commit

Permalink
workaround github.com/go-sql-driver/mysql/pull/1424 not released
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Chinn committed Aug 30, 2023
1 parent 31781fc commit 42dfede
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion dump.go
Expand Up @@ -383,11 +383,28 @@ func (table *table) Init() error {

table.values = make([]interface{}, len(tt))
for i, tp := range tt {
table.values[i] = reflect.New(tp.ScanType()).Interface()
table.values[i] = reflect.New(reflectColumnType(tp)).Interface()
}
return nil
}

func reflectColumnType(tp *sql.ColumnType) reflect.Type {
// workaround https://github.com/go-sql-driver/mysql/pull/1424 till it's released
nullable, _ := tp.Nullable()
switch tp.DatabaseTypeName() {
case "TINYBLOB", "MEDIUMBLOB", "LONGBLOB", "BLOB",
"VARBINARY", "BINARY", "BIT", "GEOMETRY":
return reflect.TypeOf([]byte{})
case "TINYTEXT", "MEDIUMTEXT", "LONGTEXT", "TEXT",
"VARCHAR", "CHAR", "DECIMAL", "ENUM", "SET", "JSON", "TIME":
if nullable {
return reflect.TypeOf(sql.NullString{})
}
return reflect.TypeOf("")
}
return tp.ScanType()
}

func (table *table) Next() bool {
if table.rows == nil {
if err := table.Init(); err != nil {
Expand Down

0 comments on commit 42dfede

Please sign in to comment.