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

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
okJiang authored and okJiang committed Jul 20, 2021
1 parent dcbd125 commit d49933a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions loader/loader.go
Expand Up @@ -532,12 +532,12 @@ func (l *Loader) Init(ctx context.Context) (err error) {
if !hasSQLMode {
sqlModes, err3 := utils.AdjustSQLModeCompatible(l.cfg.LoaderConfig.SQLMode)
if err3 != nil {
l.logger.Warn("cannot adjust sql_mode compatible, the sql_mode will be assigned \"\"", log.ShortError(err3))
l.logger.Warn("cannot adjust sql_mode compatible, the sql_mode will stay the same", log.ShortError(err3))
}
lcfg.To.Session["sql_mode"] = sqlModes
}

l.logger.Info("loader's sql_mode is ", zap.String("sqlmode", lcfg.To.Session["sql_mode"]))
l.logger.Info("loader's sql_mode is", zap.String("sqlmode", lcfg.To.Session["sql_mode"]))

l.toDB, l.toDBConns, err = createConns(tctx, lcfg, l.cfg.PoolSize)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/utils/db.go
Expand Up @@ -526,7 +526,7 @@ func AddGSetWithPurged(ctx context.Context, gset gtid.Set, conn *sql.Conn) (gtid
}

// AdjustSQLModeCompatible adjust downstream sql mode to compatible.
// When upstream's datatime is 2020-00-00, 2020-00-01, 2020-06-00
// TODO: When upstream's datatime is 2020-00-00, 2020-00-01, 2020-06-00
// and so on, downstream will be 2019-11-30, 2019-12-01, 2020-05-31,
// as if set the 'NO_ZERO_IN_DATE', 'NO_ZERO_DATE'.
// This is because the implementation of go-mysql, that you can see
Expand All @@ -550,15 +550,15 @@ func AdjustSQLModeCompatible(sqlModes string) (string, error) {

mode, err := tmysql.GetSQLMode(sqlModes)
if err != nil {
return "", err
return sqlModes, err
}
disableMode, err2 := tmysql.GetSQLMode(disable)
if err2 != nil {
return "", err2
return sqlModes, err2
}
enableMode, err3 := tmysql.GetSQLMode(enable)
if err3 != nil {
return "", err3
return sqlModes, err3
}
// About this bit manipulation, details can be seen
// https://github.com/pingcap/dm/pull/1869#discussion_r669771966
Expand Down
4 changes: 2 additions & 2 deletions syncer/syncer.go
Expand Up @@ -2860,11 +2860,11 @@ func (s *Syncer) createDBs(ctx context.Context) error {
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, the sql_mode will be assigned \"\"", log.ShortError(err2))
s.tctx.L().Warn("cannot get sql_mode from upstream database, the sql_mode will be assigned \"IGNORE_SPACE, NO_AUTO_VALUE_ON_ZERO, ALLOW_INVALID_DATES\"", log.ShortError(err2))
}
sqlModes, err3 := utils.AdjustSQLModeCompatible(sqlMode)
if err3 != nil {
s.tctx.L().Warn("cannot adjust sql_mode compatible, the sql_mode will be assigned \"\"", log.ShortError(err3))
s.tctx.L().Warn("cannot adjust sql_mode compatible, the sql_mode will be assigned stay the same", log.ShortError(err3))
}
s.cfg.To.Session["sql_mode"] = sqlModes
}
Expand Down
2 changes: 1 addition & 1 deletion tests/sql_mode/data/db2.increment.sql
Expand Up @@ -17,7 +17,7 @@ insert into t_2(name) values(concat ('ignore', 'space'));
-- test sql_mode NO_AUTO_VALUE_ON_ZERO
set @@session.sql_mode=concat(@@session.sql_mode, ',NO_AUTO_VALUE_ON_ZERO');
insert into t_2(id, name) values (20, 'a');
replace into t_2(id, name) values (0, 'b');
replace into t_2(id, name) values (0, 'c');

-- test sql_mode NO_BACKSLASH_ESCAPES
set @@session.sql_mode=concat(@@session.sql_mode, ',NO_BACKSLASH_ESCAPES');
Expand Down

0 comments on commit d49933a

Please sign in to comment.