Skip to content

Commit 248770e

Browse files
author
xianganjie
committed
decimal data type(#313)
1 parent 3dd4588 commit 248770e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

pkg/mysql/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package mysql
22

33
import (
44
"database/sql"
5+
"github.com/shopspring/decimal"
56
"reflect"
67
"time"
78

@@ -106,6 +107,8 @@ func SQLDataPtrs2Val(dataPtrs []interface{}, columnTypes []*sql.ColumnType) map[
106107
} else {
107108
ret[columnName] = v.Time
108109
}
110+
case decimal.Decimal:
111+
ret[columnName] = v
109112
default:
110113
log.Fatalf("failed to catch columnName: %v, type: %v", columnName, reflect.TypeOf(columnData))
111114
}

pkg/utils/db.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package utils
33
import (
44
"database/sql"
55
"fmt"
6+
"github.com/shopspring/decimal"
67
"math"
78
"math/rand"
89
"net/url"
@@ -149,7 +150,7 @@ func GetScanType(columnType *sql.ColumnType) reflect.Type {
149150
if IsColumnString(columnType) {
150151
return reflect.TypeOf(sql.NullString{})
151152
} else if IsColumnFloat(columnType) {
152-
return reflect.TypeOf(sql.NullFloat64{})
153+
return reflect.TypeOf(decimal.Decimal{})
153154
} else {
154155
return columnType.ScanType()
155156
}
@@ -610,13 +611,14 @@ func SQLWithAnnotation(annotation string, sql string) string {
610611

611612
func NewBinlogSyncer(serverID uint32, dbConfig *config.DBConfig, heartbeatPeriod time.Duration) *replication.BinlogSyncer {
612613
syncerConfig := replication.BinlogSyncerConfig{
613-
ServerID: serverID,
614-
Flavor: "mysql",
615-
Host: dbConfig.Host,
616-
Port: uint16(dbConfig.Port),
617-
User: dbConfig.Username,
618-
Password: dbConfig.Password,
619-
ParseTime: true,
614+
ServerID: serverID,
615+
Flavor: "mysql",
616+
Host: dbConfig.Host,
617+
Port: uint16(dbConfig.Port),
618+
User: dbConfig.Username,
619+
Password: dbConfig.Password,
620+
ParseTime: true,
621+
UseDecimal: true,
620622
}
621623

622624
if heartbeatPeriod > 0 {

0 commit comments

Comments
 (0)