Skip to content

Commit

Permalink
decimal data type(moiot#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
xianganjie committed Apr 20, 2021
1 parent 3dd4588 commit 248770e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions pkg/mysql/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mysql

import (
"database/sql"
"github.com/shopspring/decimal"
"reflect"
"time"

Expand Down Expand Up @@ -106,6 +107,8 @@ func SQLDataPtrs2Val(dataPtrs []interface{}, columnTypes []*sql.ColumnType) map[
} else {
ret[columnName] = v.Time
}
case decimal.Decimal:
ret[columnName] = v
default:
log.Fatalf("failed to catch columnName: %v, type: %v", columnName, reflect.TypeOf(columnData))
}
Expand Down
18 changes: 10 additions & 8 deletions pkg/utils/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package utils
import (
"database/sql"
"fmt"
"github.com/shopspring/decimal"
"math"
"math/rand"
"net/url"
Expand Down Expand Up @@ -149,7 +150,7 @@ func GetScanType(columnType *sql.ColumnType) reflect.Type {
if IsColumnString(columnType) {
return reflect.TypeOf(sql.NullString{})
} else if IsColumnFloat(columnType) {
return reflect.TypeOf(sql.NullFloat64{})
return reflect.TypeOf(decimal.Decimal{})
} else {
return columnType.ScanType()
}
Expand Down Expand Up @@ -610,13 +611,14 @@ func SQLWithAnnotation(annotation string, sql string) string {

func NewBinlogSyncer(serverID uint32, dbConfig *config.DBConfig, heartbeatPeriod time.Duration) *replication.BinlogSyncer {
syncerConfig := replication.BinlogSyncerConfig{
ServerID: serverID,
Flavor: "mysql",
Host: dbConfig.Host,
Port: uint16(dbConfig.Port),
User: dbConfig.Username,
Password: dbConfig.Password,
ParseTime: true,
ServerID: serverID,
Flavor: "mysql",
Host: dbConfig.Host,
Port: uint16(dbConfig.Port),
User: dbConfig.Username,
Password: dbConfig.Password,
ParseTime: true,
UseDecimal: true,
}

if heartbeatPeriod > 0 {
Expand Down

0 comments on commit 248770e

Please sign in to comment.