Skip to content

Commit

Permalink
Merge pull request #19 from databendcloud/fix/null-data-sync
Browse files Browse the repository at this point in the history
fix: nullable data sync
  • Loading branch information
hantmac committed Aug 5, 2024
2 parents 2fa1013 + 5e3808d commit 772a708
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ func (s *Source) QueryTableData(conditionSql string) ([][]interface{}, []string,
for i, columnType := range columnTypes {
switch columnType.DatabaseTypeName() {
case "INT", "SMALLINT", "TINYINT", "MEDIUMINT", "BIGINT":
scanArgs[i] = new(int)
scanArgs[i] = new(sql.NullInt64)
case "UNSIGNED INT", "UNSIGNED TINYINT", "UNSIGNED MEDIUMINT", "UNSIGNED BIGINT":
scanArgs[i] = new(sql.NullInt64)
case "FLOAT", "DOUBLE":
scanArgs[i] = new(float64)
scanArgs[i] = new(sql.NullFloat64)
case "DECIMAL":
scanArgs[i] = new(sql.NullFloat64)
case "CHAR", "VARCHAR", "TEXT", "TINYTEXT", "MEDIUMTEXT", "LONGTEXT":
scanArgs[i] = new(string)
scanArgs[i] = new(sql.NullString)
case "DATE", "TIME", "DATETIME", "TIMESTAMP":
scanArgs[i] = new(string) // or use time.Time
case "BOOL", "BOOLEAN":
Expand Down Expand Up @@ -190,6 +190,12 @@ func (s *Source) QueryTableData(conditionSql string) ([][]interface{}, []string,
row[i] = *v
case *string:
row[i] = *v
case *sql.NullString:
if v.Valid {
row[i] = v.String
} else {
row[i] = nil
}
case *bool:
row[i] = *v
case *sql.NullInt64:
Expand Down

0 comments on commit 772a708

Please sign in to comment.