Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decimal data type(#313) #314

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 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,12 @@ func SQLDataPtrs2Val(dataPtrs []interface{}, columnTypes []*sql.ColumnType) map[
} else {
ret[columnName] = v.Time
}
case decimal.NullDecimal:
if !v.Valid {
ret[columnName] = nil
} else {
ret[columnName] = v.Decimal
}
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.NullDecimal{})
} 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