Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

sycner: automatically use upstream sql_mode (#1306) #1307

Merged
merged 1 commit into from
Nov 26, 2020
Merged
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
25 changes: 23 additions & 2 deletions syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (s *Syncer) Init(ctx context.Context) (err error) {
return err
}

err = s.createDBs()
err = s.createDBs(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -2342,7 +2342,7 @@ func (s *Syncer) printStatus(ctx context.Context) {
}
}

func (s *Syncer) createDBs() error {
func (s *Syncer) createDBs(ctx context.Context) error {
var err error
dbCfg := s.cfg.From
dbCfg.RawDBCfg = config.DefaultRawDBConfig().SetReadTimeout(maxDMLConnectionTimeout)
Expand All @@ -2351,6 +2351,27 @@ func (s *Syncer) createDBs() error {
return err
}

hasSQLMode := false
// get sql_mode from upstream db
if s.cfg.To.Session == nil {
s.cfg.To.Session = make(map[string]string)
} else {
for k := range s.cfg.To.Session {
if strings.ToLower(k) == "sql_mode" {
hasSQLMode = true
break
}
}
}
if !hasSQLMode {
sqlMode, err2 := utils.GetGlobalVariable(ctx, s.fromDB.BaseDB.DB, "sql_mode")
if err2 != nil {
s.tctx.L().Warn("cannot get sql_mode from upstream database", log.ShortError(err2))
} else {
s.cfg.To.Session["sql_mode"] = sqlMode
}
}

dbCfg = s.cfg.To
dbCfg.RawDBCfg = config.DefaultRawDBConfig().
SetReadTimeout(maxDMLConnectionTimeout).
Expand Down
4 changes: 4 additions & 0 deletions tests/all_mode/data/db2.increment.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
use all_mode;
delete from t2 where name = 'Sansa';


-- test sql_mode=NO_AUTO_VALUE_ON_ZERO
insert into t2 (id, name) values (0,'haha')