Skip to content

Commit

Permalink
fix bool
Browse files Browse the repository at this point in the history
  • Loading branch information
hantmac committed Aug 3, 2024
1 parent 3810b32 commit 7dbfcc0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
46 changes: 46 additions & 0 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestWorkFlow(t *testing.T) {
fmt.Println(endTime)
fmt.Println(fmt.Sprintf("total time: %s", time.Since(startTime)))

checkTargetTable()
}

func prepareMysql() {
Expand Down Expand Up @@ -134,3 +135,48 @@ func prepareTestConfig() *cfg.Config {

return &config
}

func checkTargetTable() {
db, err := sql.Open("databend", "http://databend:databend@localhost:8000")
if err != nil {
log.Fatal(err)
}
defer db.Close()

rows, err := db.Query(`
SELECT * FROM default.test_table
`)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
count := 0

for rows.Next() {
var id int
var int_col int
var varchar_col string
var float_col float64
var bool_col bool
var de float64
var date_col string
var time_col string
var datetime_col string
var timestamp_col string
err = rows.Scan(&id, &int_col, &varchar_col, &float_col, &bool_col, &de, &date_col, &time_col, &datetime_col, &timestamp_col)
if err != nil {
log.Fatal(err)
}
count += 1
}

if err := rows.Err(); err != nil {
log.Fatal(err)
}
defer rows.Close()
defer db.Close()
fmt.Println("target table count: ", count)
if count != 10 {
panic("target table count not equal 10")
}
}
8 changes: 7 additions & 1 deletion source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (s *Source) QueryTableData(conditionSql string) ([][]interface{}, []string,
case "DATE", "TIME", "DATETIME", "TIMESTAMP":
scanArgs[i] = new(string) // or use time.Time
case "BOOL", "BOOLEAN":
scanArgs[i] = new(bool)
scanArgs[i] = new(sql.NullBool)
default:
scanArgs[i] = new(sql.RawBytes)
}
Expand Down Expand Up @@ -204,6 +204,12 @@ func (s *Source) QueryTableData(conditionSql string) ([][]interface{}, []string,
} else {
row[i] = nil
}
case *sql.NullBool:
if v.Valid {
row[i] = v.Bool
} else {
row[i] = nil
}
case *float64:
row[i] = *v
case *sql.RawBytes:
Expand Down

0 comments on commit 7dbfcc0

Please sign in to comment.