diff --git a/config/config.go b/config/config.go index 798c216b8..955001737 100644 --- a/config/config.go +++ b/config/config.go @@ -324,8 +324,10 @@ type Inc struct { // 全量日志 GeneralLog bool `toml:"general_log" json:"general_log"` - - Lang string `toml:"lang" json:"lang"` + // 使用十六进制表示法转储二进制列 + // 受影响的数据类型为BINARY,VARBINARY,BLOB类型 + HexBlob bool `toml:"hex_blob" json:"hex_blob"` + Lang string `toml:"lang" json:"lang"` // 连接服务器允许的最大包大小,以字节为单位 默认值为4194304(即4MB) MaxAllowedPacket uint `toml:"max_allowed_packet" json:"max_allowed_packet"` MaxCharLength uint `toml:"max_char_length" json:"max_char_length"` diff --git a/session/parser.go b/session/parser.go index 0f5b56993..5ef5ddc6c 100644 --- a/session/parser.go +++ b/session/parser.go @@ -3,6 +3,7 @@ package session import ( "context" "database/sql/driver" + "encoding/hex" "fmt" "math" "reflect" @@ -10,6 +11,7 @@ import ( "strings" "sync" "time" + "unicode/utf8" mysqlDriver "github.com/go-sql-driver/mysql" "github.com/juju/errors" @@ -414,6 +416,8 @@ func (s *session) flush(table string, record *Record) { if myErr, ok := err.(*mysqlDriver.MySQLError); ok { record.StageStatus = StatusBackupFail record.AppendErrorMessage(myErr.Message) + // log.Error(fmt.Sprintf(sql, table, values)) + // log.Error(s.insertBuffer) log.Error(myErr) } } @@ -486,7 +490,7 @@ func (s *session) generateInsertSql(t *TableInfo, e *replication.RowsEvent, // } } - r, err := InterpolateParams(sql, vv) + r, err := InterpolateParams(sql, vv, s.Inc.HexBlob) s.checkError(err) s.write(r, binEvent) @@ -549,7 +553,7 @@ func (s *session) generateDeleteSql(t *TableInfo, e *replication.RowsEvent, } newSql := strings.Join([]string{sql, strings.Join(columnNames, " AND")}, "") - r, err := InterpolateParams(newSql, vv) + r, err := InterpolateParams(newSql, vv, s.Inc.HexBlob) s.checkError(err) s.write(r, binEvent) @@ -729,7 +733,7 @@ func (s *session) generateUpdateSql(t *TableInfo, e *replication.RowsEvent, } newSql = strings.Join([]string{sql, strings.Join(columnNames, " AND")}, "") newValues = append(newValues, oldValues...) - r, err := InterpolateParams(newSql, newValues) + r, err := InterpolateParams(newSql, newValues, s.Inc.HexBlob) s.checkError(err) s.write(r, binEvent) @@ -742,7 +746,7 @@ func (s *session) generateUpdateSql(t *TableInfo, e *replication.RowsEvent, return string(buf), nil } -func InterpolateParams(query string, args []driver.Value) ([]byte, error) { +func InterpolateParams(query string, args []driver.Value, hexBlob bool) ([]byte, error) { // Number of ? should be same to len(args) if strings.Count(query, "?") != len(args) { log.Error("sql", query, "需要参数", strings.Count(query, "?"), @@ -772,6 +776,9 @@ func InterpolateParams(query string, args []driver.Value) ([]byte, error) { continue } + // log.Info(arg) + // log.Infof("%T", arg) + switch v := arg.(type) { case int8: buf = strconv.AppendInt(buf, int64(v), 10) @@ -843,18 +850,41 @@ func InterpolateParams(query string, args []driver.Value) ([]byte, error) { buf = append(buf, '\'') } case string: - buf = append(buf, '\'') - buf = escapeBytesBackslash(buf, []byte(v)) + if hexBlob { + if utf8.ValidString(v) { + buf = append(buf, '\'') + buf = escapeBytesBackslash(buf, []byte(v)) + } else { + buf = append(buf, 'X') + buf = append(buf, '\'') + b := hex.EncodeToString([]byte(v)) + buf = append(buf, b...) + } + } else { + buf = append(buf, '\'') + buf = escapeBytesBackslash(buf, []byte(v)) + } + buf = append(buf, '\'') case []byte: if v == nil { buf = append(buf, "NULL"...) } else { // buf = append(buf, "_binary'"...) - buf = append(buf, '\'') - - buf = escapeBytesBackslash(buf, v) - + if hexBlob { + if utf8.Valid(v) { + buf = append(buf, '\'') + buf = escapeBytesBackslash(buf, v) + } else { + buf = append(buf, 'X') + buf = append(buf, '\'') + b := hex.EncodeToString(v) + buf = append(buf, b...) + } + } else { + buf = append(buf, '\'') + buf = escapeBytesBackslash(buf, v) + } buf = append(buf, '\'') } default: diff --git a/session/session_inception.go b/session/session_inception.go index 94e535b05..ba87e7011 100644 --- a/session/session_inception.go +++ b/session/session_inception.go @@ -6159,7 +6159,7 @@ func (s *session) executeInceptionShow(sql string) ([]sqlexec.RecordSet, error) vv = append(vv, *val) } - res, err := InterpolateParams(paramValues, vv) + res, err := InterpolateParams(paramValues, vv, s.Inc.HexBlob) if err != nil { s.AppendErrorMessage(err.Error()) return nil, nil diff --git a/session/session_inception_backup_test.go b/session/session_inception_backup_test.go index 5eefc92e5..e9bce7343 100644 --- a/session/session_inception_backup_test.go +++ b/session/session_inception_backup_test.go @@ -123,13 +123,13 @@ func (s *testSessionIncBackupSuite) TearDownTest(c *C) { } } -func (s *testSessionIncBackupSuite) makeSQL(c *C, tk *testkit.TestKit, sql string) *testkit.Result { +func (s *testSessionIncBackupSuite) makeSQL(c *C, sql string) *testkit.Result { a := `/*--user=test;--password=test;--host=127.0.0.1;--execute=1;--backup=1;--port=3306;--enable-ignore-warnings;real_row_count=%v;*/ inception_magic_start; use test_inc; %s; inception_magic_commit;` - res := tk.MustQueryInc(fmt.Sprintf(a, s.realRowCount, sql)) + res := s.tk.MustQueryInc(fmt.Sprintf(a, s.realRowCount, sql)) // 需要成功执行 for _, row := range res.Rows() { @@ -139,16 +139,13 @@ inception_magic_commit;` return res } -func (s *testSessionIncBackupSuite) makeExecSQL(tk *testkit.TestKit, sql string) *testkit.Result { - - session.CheckAuditSetting(config.GetGlobalConfig()) - - a := `/*--user=test;--password=test;--host=127.0.0.1;--execute=1;--backup=0;--port=3306;--enable-ignore-warnings;real_row_count=%v;*/ +func (s *testSessionIncBackupSuite) makeExecSQL(sql string) *testkit.Result { + a := `/*--user=test;--password=test;--host=127.0.0.1;--execute=1;--backup=1;--port=3306;--enable-ignore-warnings;real_row_count=%v;*/ inception_magic_start; use test_inc; %s; inception_magic_commit;` - return tk.MustQueryInc(fmt.Sprintf(a, s.realRowCount, sql)) + return s.tk.MustQueryInc(fmt.Sprintf(a, s.realRowCount, sql)) } func (s *testSessionIncBackupSuite) getDBVersion(c *C) int { @@ -165,7 +162,7 @@ func (s *testSessionIncBackupSuite) getDBVersion(c *C) int { } sql := "show variables like 'version'" - res := s.makeSQL(c, s.tk, sql) + res := s.makeSQL(c, sql) c.Assert(int(s.tk.Se.AffectedRows()), Equals, 2) row := res.Rows()[int(s.tk.Se.AffectedRows())-1] @@ -195,33 +192,31 @@ func (s *testSessionIncBackupSuite) getDBVersion(c *C) int { } func (s *testSessionIncBackupSuite) TestCreateTable(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved }() - res := s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int);") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + res := s.makeSQL(c, "drop table if exists t1;create table t1(id int);") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DROP TABLE `test_inc`.`t1`;", Commentf("%v", res.Rows())) } func (s *testSessionIncBackupSuite) TestDropTable(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved }() config.GetGlobalConfig().Inc.EnableDropTable = true - res := s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int);") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + res := s.makeSQL(c, "drop table if exists t1;create table t1(id int);") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DROP TABLE `test_inc`.`t1`;") - res = s.makeSQL(c, tk, "drop table t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "drop table t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) // mysql 8.0版本默认字符集改成了utf8mb4 if s.getDBVersion(c) < 80000 { @@ -230,18 +225,18 @@ func (s *testSessionIncBackupSuite) TestDropTable(c *C) { c.Assert(backup, Equals, "CREATE TABLE `t1` (\n `id` int(11) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;") } - s.makeSQL(c, tk, "create table t1(id int) default charset utf8mb4;") - res = s.makeSQL(c, tk, "drop table t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "create table t1(id int) default charset utf8mb4;") + res = s.makeSQL(c, "drop table t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) if s.getDBVersion(c) < 80000 { c.Assert(backup, Equals, "CREATE TABLE `t1` (\n `id` int(11) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;") } else { c.Assert(backup, Equals, "CREATE TABLE `t1` (\n `id` int(11) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;") } - s.makeSQL(c, tk, "create table t1(id int not null default 0);") - res = s.makeSQL(c, tk, "drop table t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "create table t1(id int not null default 0);") + res = s.makeSQL(c, "drop table t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) if s.getDBVersion(c) < 80000 { c.Assert(backup, Equals, "CREATE TABLE `t1` (\n `id` int(11) NOT NULL DEFAULT '0'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;") @@ -251,7 +246,6 @@ func (s *testSessionIncBackupSuite) TestDropTable(c *C) { } func (s *testSessionIncBackupSuite) TestAlterTableAddColumn(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved @@ -260,86 +254,84 @@ func (s *testSessionIncBackupSuite) TestAlterTableAddColumn(c *C) { config.GetGlobalConfig().Inc.CheckColumnComment = false config.GetGlobalConfig().Inc.CheckTableComment = false - res := s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int);") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + res := s.makeSQL(c, "drop table if exists t1;create table t1(id int);") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DROP TABLE `test_inc`.`t1`;", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, "alter table t1 add column c1 int;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 add column c1 int;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` DROP COLUMN `c1`;") - res = s.makeSQL(c, tk, "alter table t1 add column c2 bit first;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 add column c2 bit first;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` DROP COLUMN `c2`;") - res = s.makeSQL(c, tk, "alter table t1 add column (c3 int,c4 varchar(20));") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 add column (c3 int,c4 varchar(20));") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` DROP COLUMN `c4`,DROP COLUMN `c3`;") // 特殊字符 config.GetGlobalConfig().Inc.CheckIdentifier = false - res = s.makeSQL(c, tk, "drop table if exists `t3!@#$^&*()`;create table `t3!@#$^&*()`(id int primary key);alter table `t3!@#$^&*()` add column `c3!@#$^&*()2` int comment '123';") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "drop table if exists `t3!@#$^&*()`;create table `t3!@#$^&*()`(id int primary key);alter table `t3!@#$^&*()` add column `c3!@#$^&*()2` int comment '123';") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t3!@#$^&*()", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t3!@#$^&*()` DROP COLUMN `c3!@#$^&*()2`;", Commentf("%v", res.Rows())) // pt-osc config.GetGlobalConfig().Osc.OscOn = true - res = s.makeSQL(c, tk, "drop table if exists `t3!@#$^&*()`;create table `t3!@#$^&*()`(id int primary key);alter table `t3!@#$^&*()` add column `c3!@#$^&*()2` int comment '123';") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "drop table if exists `t3!@#$^&*()`;create table `t3!@#$^&*()`(id int primary key);alter table `t3!@#$^&*()` add column `c3!@#$^&*()2` int comment '123';") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t3!@#$^&*()", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t3!@#$^&*()` DROP COLUMN `c3!@#$^&*()2`;", Commentf("%v", res.Rows())) // gh-ost config.GetGlobalConfig().Osc.OscOn = false config.GetGlobalConfig().Ghost.GhostOn = true - res = s.makeSQL(c, tk, "drop table if exists `t3!@#$^&*()`;create table `t3!@#$^&*()`(id int primary key);alter table `t3!@#$^&*()` add column `c3!@#$^&*()2` int comment '123';") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "drop table if exists `t3!@#$^&*()`;create table `t3!@#$^&*()`(id int primary key);alter table `t3!@#$^&*()` add column `c3!@#$^&*()2` int comment '123';") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t3!@#$^&*()", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t3!@#$^&*()` DROP COLUMN `c3!@#$^&*()2`;", Commentf("%v", res.Rows())) } func (s *testSessionIncBackupSuite) TestAlterTableAlterColumn(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved }() // res := s.makeSQL(c,tk, "drop table if exists t1;create table t1(id int);alter table t1 alter column id set default '';") - // row := res.Rows()[int(tk.Se.AffectedRows())-1] + // row := res.Rows()[int(s.tk.Se.AffectedRows())-1] // c.Assert(row[2], Equals, "2") // c.Assert(row[4], Equals, "Invalid default value for column 'id'.") // res = s.makeSQL(c,tk, "drop table if exists t1;create table t1(id int);alter table t1 alter column id set default '1';") - // row = res.Rows()[int(tk.Se.AffectedRows())-1] + // row = res.Rows()[int(s.tk.Se.AffectedRows())-1] // c.Assert(row[2], Equals, "0") // res = s.makeSQL(c,tk, "drop table if exists t1;create table t1(id int);alter table t1 alter column id drop default ;alter table t1 alter column id set default '1';") - // row = res.Rows()[int(tk.Se.AffectedRows())-2] + // row = res.Rows()[int(s.tk.Se.AffectedRows())-2] // c.Assert(row[2], Equals, "0") - // row = res.Rows()[int(tk.Se.AffectedRows())-1] + // row = res.Rows()[int(s.tk.Se.AffectedRows())-1] // c.Assert(row[2], Equals, "0") - s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int,c1 int);") - res := s.makeSQL(c, tk, "alter table t1 alter column c1 set default '1';") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "drop table if exists t1;create table t1(id int,c1 int);") + res := s.makeSQL(c, "alter table t1 alter column c1 set default '1';") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` DROP DEFAULT;", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, "alter table t1 alter column c1 drop default;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 alter column c1 drop default;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` SET DEFAULT '1';") } func (s *testSessionIncBackupSuite) TestAlterTableModifyColumn(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved @@ -348,78 +340,76 @@ func (s *testSessionIncBackupSuite) TestAlterTableModifyColumn(c *C) { config.GetGlobalConfig().Inc.CheckColumnComment = false config.GetGlobalConfig().Inc.CheckTableComment = false - res := s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int,c1 int);") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + res := s.makeSQL(c, "drop table if exists t1;create table t1(id int,c1 int);") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DROP TABLE `test_inc`.`t1`;", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, "alter table t1 modify column c1 varchar(10);") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 modify column c1 varchar(10);") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` MODIFY COLUMN `c1` int(11);") - res = s.makeSQL(c, tk, "alter table t1 modify column c1 varchar(100) not null;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 modify column c1 varchar(100) not null;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` MODIFY COLUMN `c1` varchar(10);") - res = s.makeSQL(c, tk, "alter table t1 modify column c1 int null;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 modify column c1 int null;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` MODIFY COLUMN `c1` varchar(100) NOT NULL;") - res = s.makeSQL(c, tk, "alter table t1 modify column c1 int first;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 modify column c1 int first;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` MODIFY COLUMN `c1` int(11);") - res = s.makeSQL(c, tk, "alter table t1 modify column c1 varchar(200) not null comment '测试列';") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 modify column c1 varchar(200) not null comment '测试列';") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` MODIFY COLUMN `c1` int(11);") - res = s.makeSQL(c, tk, "alter table t1 modify column c1 int;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 modify column c1 int;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` MODIFY COLUMN `c1` varchar(200) NOT NULL COMMENT '测试列';") - res = s.makeSQL(c, tk, "alter table t1 modify column c1 varchar(20) character set utf8;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 modify column c1 varchar(20) character set utf8;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` MODIFY COLUMN `c1` int(11);") - res = s.makeSQL(c, tk, "alter table t1 modify column c1 varchar(20) COLLATE utf8_bin;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t1 modify column c1 varchar(20) COLLATE utf8_bin;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` MODIFY COLUMN `c1` varchar(20);") } func (s *testSessionIncBackupSuite) TestAlterTableDropColumn(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved }() - res := s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int,c1 int);") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + res := s.makeSQL(c, "drop table if exists t1;create table t1(id int,c1 int);") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DROP TABLE `test_inc`.`t1`;", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, "ALTER TABLE `test_inc`.`t1` DROP COLUMN `c1`;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "ALTER TABLE `test_inc`.`t1` DROP COLUMN `c1`;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` ADD COLUMN `c1` int(11);") - s.makeSQL(c, tk, "ALTER TABLE `test_inc`.`t1` ADD COLUMN `c1` int(11) not null default 0 comment '测试列';") - res = s.makeSQL(c, tk, "ALTER TABLE `test_inc`.`t1` DROP COLUMN `c1`;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "ALTER TABLE `test_inc`.`t1` ADD COLUMN `c1` int(11) not null default 0 comment '测试列';") + res = s.makeSQL(c, "ALTER TABLE `test_inc`.`t1` DROP COLUMN `c1`;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` ADD COLUMN `c1` int(11) NOT NULL DEFAULT '0' COMMENT '测试列';") } func (s *testSessionIncBackupSuite) TestInsert(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved @@ -427,18 +417,18 @@ func (s *testSessionIncBackupSuite) TestInsert(c *C) { config.GetGlobalConfig().Inc.CheckInsertField = false - res := s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int);") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + res := s.makeSQL(c, "drop table if exists t1;create table t1(id int);") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DROP TABLE `test_inc`.`t1`;", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, "insert into t1 values(1);") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "insert into t1 values(1);") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DELETE FROM `test_inc`.`t1` WHERE `id`=1;", Commentf("%v", res.Rows())) // 值溢出时的回滚解析 - res = s.makeSQL(c, tk, `drop table if exists t1; + res = s.makeSQL(c, `drop table if exists t1; create table t1(id int primary key, c1 tinyint unsigned, c2 smallint unsigned, @@ -446,12 +436,12 @@ func (s *testSessionIncBackupSuite) TestInsert(c *C) { c4 int unsigned, c5 bigint unsigned );`) - res = s.makeSQL(c, tk, "insert into t1 values(1,128,32768,8388608,2147483648,9223372036854775808);") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "insert into t1 values(1,128,32768,8388608,2147483648,9223372036854775808);") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DELETE FROM `test_inc`.`t1` WHERE `id`=1;", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, `drop table if exists t1; + res = s.makeSQL(c, `drop table if exists t1; create table t1(id int, c1 tinyint unsigned, c2 smallint unsigned, @@ -463,15 +453,15 @@ func (s *testSessionIncBackupSuite) TestInsert(c *C) { c8 float unsigned, c9 double unsigned );`) - res = s.makeSQL(c, tk, `insert into t1 values(1,128,32768,8388608,2147483648,9223372036854775808, + res = s.makeSQL(c, `insert into t1 values(1,128,32768,8388608,2147483648,9223372036854775808, 9999999999,99.99,3.402823466e+38,1.7976931348623157e+308);`) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DELETE FROM `test_inc`.`t1` WHERE `id`=1 AND `c1`=128 AND `c2`=32768 AND "+ "`c3`=8388608 AND `c4`=2147483648 AND `c5`=9223372036854775808 AND "+ "`c6`=9999999999 AND `c7`=99.99 AND `c8`=3.4028235e+38 AND `c9`=1.7976931348623157e+308;", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, `update t1 set c1 = 129, + res = s.makeSQL(c, `update t1 set c1 = 129, c2 = 32769, c3 = 8388609, c4 = 2147483649, @@ -481,7 +471,7 @@ func (s *testSessionIncBackupSuite) TestInsert(c *C) { c8 = 3e+38, c9 = 1e+308 where id = 1;`) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "UPDATE `test_inc`.`t1` SET `id`=1, `c1`=128, `c2`=32768, "+ "`c3`=8388608, `c4`=2147483648, `c5`=9223372036854775808, `c6`=9999999999, "+ @@ -490,39 +480,39 @@ func (s *testSessionIncBackupSuite) TestInsert(c *C) { "`c4`=2147483649 AND `c5`=9223372036854775809 AND `c6`=9999999990 "+ "AND `c7`=88.88 AND `c8`=3e+38 AND `c9`=1e+308;", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, `delete from t1 where id = 1;`) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, `delete from t1 where id = 1;`) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`,`c2`,`c3`,`c4`,`c5`,`c6`,`c7`,`c8`,`c9`)"+ " VALUES(1,129,32769,8388609,2147483649,9223372036854775809,9999999990,88.88,3e+38,1e+308);", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, `drop table if exists t1; + res = s.makeSQL(c, `drop table if exists t1; create table t1(c1 bigint unsigned);`) - res = s.makeSQL(c, tk, `insert into t1 values(9223372036854775808);`) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, `insert into t1 values(9223372036854775808);`) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DELETE FROM `test_inc`.`t1` WHERE `c1`=9223372036854775808;", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, `insert into t1 values(18446744073709551615);`) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, `insert into t1 values(18446744073709551615);`) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DELETE FROM `test_inc`.`t1` WHERE `c1`=18446744073709551615;", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, `drop table if exists t1; + res = s.makeSQL(c, `drop table if exists t1; create table t1(id int primary key,c1 varchar(100))default character set utf8mb4; insert into t1(id,c1)values(1,'😁😄🙂👩');`) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DELETE FROM `test_inc`.`t1` WHERE `id`=1;", Commentf("%v", res.Rows())) // // 受影响行数 // res = s.makeSQL(c,tk, "drop table if exists t1;create table t1(id int,c1 int);insert into t1 values(1,1),(2,2);") - // row = res.Rows()[int(tk.Se.AffectedRows())-1] + // row = res.Rows()[int(s.tk.Se.AffectedRows())-1] // c.Assert(row[2], Equals, "0") // c.Assert(row[6], Equals, "2") // res = s.makeSQL(c,tk, "drop table if exists t1;create table t1(id int,c1 int );insert into t1(id,c1) select 1,null;") - // row = res.Rows()[int(tk.Se.AffectedRows())-1] + // row = res.Rows()[int(s.tk.Se.AffectedRows())-1] // c.Assert(row[2], Equals, "0") // c.Assert(row[6], Equals, "1") @@ -532,25 +522,24 @@ insert into t1(id,c1)values(1,'😁😄🙂👩');`) } func (s *testSessionIncBackupSuite) TestUpdate(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved }() - s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int,c1 int);insert into t1 values(1,1),(2,2);") + s.makeSQL(c, "drop table if exists t1;create table t1(id int,c1 int);insert into t1 values(1,1),(2,2);") - res := s.makeSQL(c, tk, "update t1 set c1=10 where id = 1;") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + res := s.makeSQL(c, "update t1 set c1=10 where id = 1;") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "UPDATE `test_inc`.`t1` SET `id`=1, `c1`=1 WHERE `id`=1 AND `c1`=10;", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1; + s.makeSQL(c, `drop table if exists t1; create table t1(id int primary key,c1 int); insert into t1 values(1,1),(2,2);`) - res = s.makeSQL(c, tk, "update t1 set id=id+2 where id > 0;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "update t1 set id=id+2 where id > 0;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, strings.Join([]string{ @@ -558,25 +547,24 @@ func (s *testSessionIncBackupSuite) TestUpdate(c *C) { "UPDATE `test_inc`.`t1` SET `id`=2, `c1`=2 WHERE `id`=4;", }, "\n"), Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 decimal(18,4),c2 decimal(18,4)); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 decimal(18,4),c2 decimal(18,4)); insert into t1 values(1,123456789012.1234,123456789012.1235);`) - res = s.makeSQL(c, tk, "update t1 set c1 = 123456789012 where id>0;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "update t1 set c1 = 123456789012 where id>0;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "UPDATE `test_inc`.`t1` SET `id`=1, `c1`=123456789012.1234, `c2`=123456789012.1235 WHERE `id`=1;", Commentf("%v", res.Rows())) config.GetGlobalConfig().Inc.EnableMinimalRollback = true - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 decimal(18,4),c2 decimal(18,4)); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 decimal(18,4),c2 decimal(18,4)); insert into t1 values(1,123456789012.1234,123456789012.1235);`) - res = s.makeSQL(c, tk, "update t1 set c1 = 123456789012 where id>0;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "update t1 set c1 = 123456789012 where id>0;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "UPDATE `test_inc`.`t1` SET `c1`=123456789012.1234 WHERE `id`=1;", Commentf("%v", res.Rows())) } func (s *testSessionIncBackupSuite) TestMinimalUpdate(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved @@ -584,19 +572,19 @@ func (s *testSessionIncBackupSuite) TestMinimalUpdate(c *C) { config.GetGlobalConfig().Inc.EnableMinimalRollback = true - s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int,c1 int);insert into t1 values(1,1),(2,2);") + s.makeSQL(c, "drop table if exists t1;create table t1(id int,c1 int);insert into t1 values(1,1),(2,2);") - res := s.makeSQL(c, tk, "update t1 set c1=10 where id = 1;") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + res := s.makeSQL(c, "update t1 set c1=10 where id = 1;") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "UPDATE `test_inc`.`t1` SET `c1`=1 WHERE `id`=1 AND `c1`=10;", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1; + s.makeSQL(c, `drop table if exists t1; create table t1(id int primary key,c1 int); insert into t1 values(1,1),(2,2);`) - res = s.makeSQL(c, tk, "update t1 set c1=10 where id > 0;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "update t1 set c1=10 where id > 0;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, strings.Join([]string{ @@ -604,22 +592,22 @@ func (s *testSessionIncBackupSuite) TestMinimalUpdate(c *C) { "UPDATE `test_inc`.`t1` SET `c1`=2 WHERE `id`=2;", }, "\n"), Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1; + s.makeSQL(c, `drop table if exists t1; create table t1(id int primary key,c1 int); insert into t1 values(1,1),(2,2);`) - res = s.makeSQL(c, tk, "update t1 set c1=2 where id > 0;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "update t1 set c1=2 where id > 0;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "UPDATE `test_inc`.`t1` SET `c1`=1 WHERE `id`=1;", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1; + s.makeSQL(c, `drop table if exists t1; create table t1(id int primary key,c1 tinyint unsigned,c2 varchar(100)); insert into t1 values(1,127,'t1'),(2,130,'t2');`) - res = s.makeSQL(c, tk, "update t1 set c1=130,c2='aa' where id > 0;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "update t1 set c1=130,c2='aa' where id > 0;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, strings.Join([]string{ @@ -627,12 +615,12 @@ func (s *testSessionIncBackupSuite) TestMinimalUpdate(c *C) { "UPDATE `test_inc`.`t1` SET `c2`='t2' WHERE `id`=2;", }, "\n"), Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1; + s.makeSQL(c, `drop table if exists t1; create table t1(id int,c1 tinyint unsigned,c2 varchar(100)); insert into t1 values(1,127,'t1'),(2,130,'t2');`) - res = s.makeSQL(c, tk, "update t1 set c1=130,c2='aa' where id > 0;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "update t1 set c1=130,c2='aa' where id > 0;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, strings.Join([]string{ @@ -640,11 +628,11 @@ func (s *testSessionIncBackupSuite) TestMinimalUpdate(c *C) { "UPDATE `test_inc`.`t1` SET `c2`='t2' WHERE `id`=2 AND `c1`=130 AND `c2`='aa';", }, "\n"), Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1; + s.makeSQL(c, `drop table if exists t1; create table t1(id int primary key,c1 int); insert into t1 values(1,1),(2,2);`) - res = s.makeSQL(c, tk, "update t1 set id=id+2 where id > 0;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "update t1 set id=id+2 where id > 0;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, strings.Join([]string{ @@ -653,16 +641,15 @@ func (s *testSessionIncBackupSuite) TestMinimalUpdate(c *C) { }, "\n"), Commentf("%v", res.Rows())) } func (s *testSessionIncBackupSuite) TestDelete(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved }() - s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int,c1 int);insert into t1 values(1,1),(2,2);") + s.makeSQL(c, "drop table if exists t1;create table t1(id int,c1 int);insert into t1 values(1,1),(2,2);") - res := s.makeSQL(c, tk, "delete from t1 where id <= 2;") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + res := s.makeSQL(c, "delete from t1 where id <= 2;") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, strings.Join([]string{ @@ -670,86 +657,130 @@ func (s *testSessionIncBackupSuite) TestDelete(c *C) { "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(2,2);", }, "\n"), Commentf("%v", res.Rows())) - s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int primary key,c1 blob);insert into t1 values(1,X'010203');") - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + // ------------- 二进制类型: binary,varbinary,blob ---------------- + s.makeSQL(c, `drop table if exists t1; + create table t1(id int primary key,c1 blob); + insert into t1 values(1,X'010203');`) + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] + backup = s.query("t1", row[7].(string)) + c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,'\x01\x02\x03');", Commentf("%v", res.Rows())) + + s.makeSQL(c, `drop table if exists t1; + create table t1(id int primary key,c1 binary(100)); + insert into t1 values(1,X'010203');`) + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,'\x01\x02\x03');", Commentf("%v", res.Rows())) + s.makeSQL(c, `drop table if exists t1; + create table t1(id int primary key,c1 varbinary(100)); + insert into t1 values(1,X'010203');`) + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] + backup = s.query("t1", row[7].(string)) + c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,'\x01\x02\x03');", Commentf("%v", res.Rows())) + + // 二进制在解析时会误存为string,此时会报错 + s.makeExecSQL(`drop table if exists t1; + create table t1(id int primary key,c1 varbinary(100)); + insert into t1 values(1,X'71E6D5A383BB447C');`) + res = s.makeExecSQL("delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] + c.Assert(row[2], Equals, "2", Commentf("%v", row)) + + // 开启二进制自动转换为十六进制字符串 + config.GetGlobalConfig().Inc.HexBlob = true + s.makeSQL(c, `drop table if exists t1; + create table t1(id int primary key,c1 varbinary(100)); + insert into t1 values(1,X'71E6D5A383BB447C');`) + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] + backup = s.query("t1", row[7].(string)) + c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,X'71e6d5a383bb447c');", Commentf("%v", res.Rows())) + + s.makeSQL(c, `insert into t1 values(1,unhex('71E6D5A383BB447C'));`) + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] + backup = s.query("t1", row[7].(string)) + c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,X'71e6d5a383bb447c');", Commentf("%v", res.Rows())) + + // ------------- json类型 ---------------- if s.getDBVersion(c) >= 50708 { - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 json); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 json); insert into t1 values(1,'{"time":"2015-01-01 13:00:00","result":"fail"}');`) - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,'{\\\"result\\\":\\\"fail\\\",\\\"time\\\":\\\"2015-01-01 13:00:00\\\"}');", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,'{\\\"result\\\":\\\"fail\\\",\\\"time\\\":\\\"2015-01-01 13:00:00\\\"}');") - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,'{\\\"result\\\":\\\"fail\\\",\\\"time\\\":\\\"2015-01-01 13:00:00\\\"}');") + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,'{\\\"result\\\":\\\"fail\\\",\\\"time\\\":\\\"2015-01-01 13:00:00\\\"}');", Commentf("%v", res.Rows())) } - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 enum('type1','type2','type3','type4')); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 enum('type1','type2','type3','type4')); insert into t1 values(1,'type2');`) - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,2);", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,2);") - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,2);") + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,2);") - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 bit); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 bit); insert into t1 values(1,1);`) - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,1);", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 decimal(10,2)); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 decimal(10,2)); insert into t1 values(1,1.11);`) - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,1.11);", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 decimal(18,4)); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 decimal(18,4)); insert into t1 values(1,123456789012.1234);`) - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,123456789012.1234);", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 double); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 double); insert into t1 values(1,1.11e100);`) - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,1.11e+100);", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,1.11e+100);") - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,1.11e+100);") + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,1.11e+100);") - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 date); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 date); insert into t1 values(1,'2019-1-1');`) - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,'2019-01-01');", Commentf("%v", res.Rows())) if s.getDBVersion(c) >= 50700 { - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 timestamp); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 timestamp); insert into t1(id) values(1);`) - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) if s.getExplicitDefaultsForTimestamp(c) { c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,NULL);", Commentf("%v", res.Rows())) @@ -759,29 +790,29 @@ func (s *testSessionIncBackupSuite) TestDelete(c *C) { } } - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 time); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 time); insert into t1 values(1,'00:01:01');`) - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,'00:01:01');", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1;create table t1(id int primary key,c1 year); + s.makeSQL(c, `drop table if exists t1;create table t1(id int primary key,c1 year); insert into t1 values(1,2019);`) - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,2019);", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `drop table if exists t1; + s.makeSQL(c, `drop table if exists t1; create table t1(id int primary key,c1 varchar(100))default character set utf8mb4; insert into t1(id,c1)values(1,'😁😄🙂👩');`) - res = s.makeSQL(c, tk, "delete from t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`c1`) VALUES(1,'😁😄🙂👩');", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, `DROP TABLE IF EXISTS t1; + s.makeSQL(c, `DROP TABLE IF EXISTS t1; CREATE TABLE t1 ( id int(11) not null auto_increment, v4_2 decimal(4,2), @@ -818,8 +849,8 @@ func (s *testSessionIncBackupSuite) TestDelete(c *C) { (-99.99 , -3699 , -3699.010 , -3699.01 , -3699.010 , -3699.01 , -9.99999999999999 , -3699.0100000000 , -3699.01000 , -3699.01000000000000000000 , -3699.0100000000000000000000000 , 13 , 2 ), (-99.99 , -1948 , -1948.140 , -1948.14 , -1948.140 , -1948.14 , -9.99999999999999 , -1948.1400000000 , -1948.14000 , -1948.14000000000000000000 , -1948.1400000000000000000000000 , 13 , 2 )`) - res = s.makeSQL(c, tk, "delete from t1 where id>0;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "delete from t1 where id>0;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "INSERT INTO `test_inc`.`t1`(`id`,`v4_2`,`v5_0`,`v7_3`,`v10_2`,`v10_3`,`v13_2`,`v15_14`,`v20_10`,`v30_5`,`v30_20`,`v30_25`,`prec`,`scale`) VALUES(1,-10.55,-11,-10.55,-10.55,-10.55,-10.55,-9.99999999999999,-10.55,-10.55,-10.55,-10.55,4,2);\n"+ "INSERT INTO `test_inc`.`t1`(`id`,`v4_2`,`v5_0`,`v7_3`,`v10_2`,`v10_3`,`v13_2`,`v15_14`,`v20_10`,`v30_5`,`v30_20`,`v30_25`,`prec`,`scale`) VALUES(2,0.01,0,0.012,0.01,0.012,0.01,0.01234567890123,0.0123456789,0.01235,0.01234567890123456789,0.0123456789012345678912345,30,25);\n"+ @@ -842,7 +873,6 @@ func (s *testSessionIncBackupSuite) TestDelete(c *C) { } func (s *testSessionIncBackupSuite) TestCreateDataBase(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved @@ -850,75 +880,72 @@ func (s *testSessionIncBackupSuite) TestCreateDataBase(c *C) { config.GetGlobalConfig().Inc.EnableDropDatabase = true - s.makeSQL(c, tk, "drop database if exists test123456;") - res := s.makeSQL(c, tk, "create database test123456;") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "drop database if exists test123456;") + res := s.makeSQL(c, "create database test123456;") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, "drop database if exists test123456;") + s.makeSQL(c, "drop database if exists test123456;") } func (s *testSessionIncBackupSuite) TestRenameTable(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved }() - s.makeSQL(c, tk, "drop table if exists t1;drop table if exists t2;create table t1(id int primary key);") - res := s.makeSQL(c, tk, "rename table t1 to t2;") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "drop table if exists t1;drop table if exists t2;create table t1(id int primary key);") + res := s.makeSQL(c, "rename table t1 to t2;") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t2", row[7].(string)) c.Assert(backup, Equals, "RENAME TABLE `test_inc`.`t2` TO `test_inc`.`t1`;", Commentf("%v", res.Rows())) - res = s.makeSQL(c, tk, "alter table t2 rename to t1;") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, "alter table t2 rename to t1;") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` RENAME TO `test_inc`.`t2`;", Commentf("%v", res.Rows())) } func (s *testSessionIncBackupSuite) TestAlterTableCreateIndex(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved }() - s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int,c1 int);") - res := s.makeSQL(c, tk, "alter table t1 add index idx (c1);") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "drop table if exists t1;create table t1(id int,c1 int);") + res := s.makeSQL(c, "alter table t1 add index idx (c1);") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` DROP INDEX `idx`;", Commentf("%v", res.Rows())) - s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int,c1 int);") - res = s.makeSQL(c, tk, "create index idx on t1(c1);") - row = res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "drop table if exists t1;create table t1(id int,c1 int);") + res = s.makeSQL(c, "create index idx on t1(c1);") + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "DROP INDEX `idx` ON `test_inc`.`t1`;", Commentf("%v", res.Rows())) } func (s *testSessionIncBackupSuite) TestAlterTableDropIndex(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved }() sql := "" - s.makeSQL(c, tk, "drop table if exists t1;create table t1(id int,c1 int);alter table t1 add index idx (c1);") - res := s.makeSQL(c, tk, "alter table t1 drop index idx;") - row := res.Rows()[int(tk.Se.AffectedRows())-1] + s.makeSQL(c, "drop table if exists t1;create table t1(id int,c1 int);alter table t1 add index idx (c1);") + res := s.makeSQL(c, "alter table t1 drop index idx;") + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` ADD INDEX `idx`(`c1`);", Commentf("%v", res.Rows())) sql = `drop table if exists t1; create table t1(id int primary key,c1 int,unique index ix_1(c1)); alter table t1 drop index ix_1;` - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` ADD UNIQUE INDEX `ix_1`(`c1`);", Commentf("%v", res.Rows())) @@ -926,16 +953,16 @@ func (s *testSessionIncBackupSuite) TestAlterTableDropIndex(c *C) { create table t1(id int primary key,c1 int); alter table t1 add unique index ix_1(c1); alter table t1 drop index ix_1;` - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` ADD UNIQUE INDEX `ix_1`(`c1`);", Commentf("%v", res.Rows())) sql = `drop table if exists t1; create table t1(id int primary key,c1 GEOMETRY not null ,SPATIAL index ix_1(c1)); alter table t1 drop index ix_1;` - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` ADD SPATIAL INDEX `ix_1`(`c1`);", Commentf("%v", res.Rows())) @@ -943,25 +970,24 @@ func (s *testSessionIncBackupSuite) TestAlterTableDropIndex(c *C) { create table t1(id int primary key,c1 GEOMETRY not null); alter table t1 add SPATIAL index ix_1(c1); alter table t1 drop index ix_1;` - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` ADD SPATIAL INDEX `ix_1`(`c1`);", Commentf("%v", res.Rows())) sql = `drop table if exists t1; create table t1(id int primary key,c1 GEOMETRY not null); alter table t1 add SPATIAL index ix_1(c1);` - s.makeExecSQL(tk, sql) + s.makeExecSQL(sql) sql = "alter table t1 drop index ix_1;" - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` ADD SPATIAL INDEX `ix_1`(`c1`);", Commentf("%v", res.Rows())) } func (s *testSessionIncBackupSuite) TestAlterTable(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved @@ -975,43 +1001,43 @@ func (s *testSessionIncBackupSuite) TestAlterTable(c *C) { // 删除后添加列 sql = "drop table if exists t1;create table t1(id int,c1 int);alter table t1 drop column c1;alter table t1 add column c1 varchar(20);" - res := s.makeSQL(c, tk, sql) - row := res.Rows()[int(tk.Se.AffectedRows())-1] + res := s.makeSQL(c, sql) + row := res.Rows()[int(s.tk.Se.AffectedRows())-1] backup := s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` DROP COLUMN `c1`;", Commentf("%v", res.Rows())) sql = "drop table if exists t1;create table t1(id int,c1 int);alter table t1 drop column c1,add column c1 varchar(20);" - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` DROP COLUMN `c1`,ADD COLUMN `c1` int(11);", Commentf("%v", res.Rows())) // 删除后添加索引 sql = "drop table if exists t1;create table t1(id int ,c1 int,key ix(c1));alter table t1 drop index ix;alter table t1 add index ix(c1);" - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` DROP INDEX `ix`;", Commentf("%v", res.Rows())) sql = "drop table if exists t1;create table t1(id int,c1 int,c2 int,key ix(c2));alter table t1 drop index ix,add index ix(c1);" - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` DROP INDEX `ix`,ADD INDEX `ix`(`c2`);", Commentf("%v", res.Rows())) sql = `drop table if exists t1; create table t1(id int,c1 int,c2 datetime null default current_timestamp on update current_timestamp comment '123'); alter table t1 modify c2 datetime;` - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` MODIFY COLUMN `c2` datetime ON UPDATE CURRENT_TIMESTAMP COMMENT '123';", Commentf("%v", res.Rows())) sql = `drop table if exists t1; create table t1(id int,c1 int,c2 datetime null default current_timestamp on update current_timestamp comment '123'); alter table t1 modify c2 datetime;` - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` MODIFY COLUMN `c2` datetime ON UPDATE CURRENT_TIMESTAMP COMMENT '123';", Commentf("%v", res.Rows())) @@ -1023,8 +1049,8 @@ func (s *testSessionIncBackupSuite) TestAlterTable(c *C) { alter table t1 add column c3 linestring; alter table t1 add column c4 polygon; alter table t1 drop column c1,drop column c2,drop column c3,drop column c4;` - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` ADD COLUMN `c4` geometry,ADD COLUMN `c3` geometry,ADD COLUMN `c2` geometry,ADD COLUMN `c1` geometry;", Commentf("%v", res.Rows())) @@ -1034,11 +1060,11 @@ func (s *testSessionIncBackupSuite) TestAlterTable(c *C) { alter table t1 add column c2 point; alter table t1 add column c3 linestring; alter table t1 add column c4 polygon;` - s.makeExecSQL(tk, sql) + s.makeExecSQL(sql) sql = `alter table t1 drop column c1,drop column c2,drop column c3,drop column c4; ` - res = s.makeSQL(c, tk, sql) - row = res.Rows()[int(tk.Se.AffectedRows())-1] + res = s.makeSQL(c, sql) + row = res.Rows()[int(s.tk.Se.AffectedRows())-1] backup = s.query("t1", row[7].(string)) c.Assert(backup, Equals, "ALTER TABLE `test_inc`.`t1` ADD COLUMN `c4` polygon,ADD COLUMN `c3` linestring,ADD COLUMN `c2` point,ADD COLUMN `c1` geometry;", Commentf("%v", res.Rows())) @@ -1152,7 +1178,7 @@ func (s *testSessionIncBackupSuite) getSQLMode(c *C) string { sql := "show variables like 'sql_mode'" - res := s.makeSQL(c, s.tk, sql) + res := s.makeSQL(c, sql) c.Assert(int(s.tk.Se.AffectedRows()), Equals, 2, Commentf("%v", res.Rows())) row := res.Rows()[int(s.tk.Se.AffectedRows())-1] @@ -1181,7 +1207,7 @@ func (s *testSessionIncBackupSuite) getExplicitDefaultsForTimestamp(c *C) bool { sql := "show variables where Variable_name='explicit_defaults_for_timestamp';" - res := s.makeSQL(c, s.tk, sql) + res := s.makeSQL(c, sql) c.Assert(int(s.tk.Se.AffectedRows()), Equals, 2, Commentf("%v", res.Rows())) row := res.Rows()[int(s.tk.Se.AffectedRows())-1] @@ -1199,7 +1225,6 @@ func (s *testSessionIncBackupSuite) getExplicitDefaultsForTimestamp(c *C) bool { } func (s *testSessionIncBackupSuite) TestStatistics(c *C) { - tk := testkit.NewTestKitWithInit(c, s.store) saved := config.GetGlobalConfig().Inc defer func() { config.GetGlobalConfig().Inc = saved @@ -1210,7 +1235,7 @@ func (s *testSessionIncBackupSuite) TestStatistics(c *C) { sql := "" sql = "drop table if exists t1;create table t1(id int,c1 int);alter table t1 drop column c1;alter table t1 add column c1 varchar(20);" - res := s.makeSQL(c, tk, sql) + res := s.makeSQL(c, sql) statistics := s.queryStatistics() result := []int{ 1, // usedb, @@ -1252,7 +1277,7 @@ func (s *testSessionIncBackupSuite) TestStatistics(c *C) { truncate table t1; ` - res = s.makeSQL(c, tk, sql) + res = s.makeSQL(c, sql) statistics = s.queryStatistics() result = []int{ 1, // usedb,