From c598e4bc64d5711ff5ae2cf0382c1aba60de6e8b Mon Sep 17 00:00:00 2001 From: Tanner Date: Wed, 18 Dec 2019 21:58:30 +0800 Subject: [PATCH] planner/core: add bit column test about display width range (#11985) (#13737) --- ddl/db_integration_test.go | 213 +++++++++++++++---------------- ddl/db_partition_test.go | 102 +++++++-------- ddl/db_test.go | 136 +++++++++----------- ddl/serial_test.go | 2 +- planner/core/integration_test.go | 7 +- types/errors.go | 1 + 6 files changed, 223 insertions(+), 238 deletions(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 48090df027a37..fcb69d7251bcb 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -142,11 +142,11 @@ func (s *testIntegrationSuite6) TestNoZeroDateMode(c *C) { tk.MustExec("use test;") tk.MustExec("set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION';") - assertErrorCode(c, tk, "create table test_zero_date(agent_start_time date NOT NULL DEFAULT '0000-00-00')", mysql.ErrInvalidDefault) - assertErrorCode(c, tk, "create table test_zero_date(agent_start_time datetime NOT NULL DEFAULT '0000-00-00 00:00:00')", mysql.ErrInvalidDefault) - assertErrorCode(c, tk, "create table test_zero_date(agent_start_time timestamp NOT NULL DEFAULT '0000-00-00 00:00:00')", mysql.ErrInvalidDefault) - assertErrorCode(c, tk, "create table test_zero_date(a timestamp default '0000-00-00 00');", mysql.ErrInvalidDefault) - assertErrorCode(c, tk, "create table test_zero_date(a timestamp default 0);", mysql.ErrInvalidDefault) + tk.MustGetErrCode("create table test_zero_date(agent_start_time date NOT NULL DEFAULT '0000-00-00')", mysql.ErrInvalidDefault) + tk.MustGetErrCode("create table test_zero_date(agent_start_time datetime NOT NULL DEFAULT '0000-00-00 00:00:00')", mysql.ErrInvalidDefault) + tk.MustGetErrCode("create table test_zero_date(agent_start_time timestamp NOT NULL DEFAULT '0000-00-00 00:00:00')", mysql.ErrInvalidDefault) + tk.MustGetErrCode("create table test_zero_date(a timestamp default '0000-00-00 00');", mysql.ErrInvalidDefault) + tk.MustGetErrCode("create table test_zero_date(a timestamp default 0);", mysql.ErrInvalidDefault) } func (s *testIntegrationSuite7) TestInvalidDefault(c *C) { @@ -257,8 +257,7 @@ func (s *testIntegrationSuite9) TestIssue2293(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("create table t_issue_2293 (a int)") - sql := "alter table t_issue_2293 add b int not null default 'a'" - assertErrorCode(c, tk, sql, tmysql.ErrInvalidDefault) + tk.MustGetErrCode("alter table t_issue_2293 add b int not null default 'a'", tmysql.ErrInvalidDefault) tk.MustExec("insert into t_issue_2293 value(1)") tk.MustQuery("select * from t_issue_2293").Check(testkit.Rows("1")) } @@ -302,15 +301,15 @@ func (s *testIntegrationSuite4) TestIssue3833(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("create table issue3833 (b char(0), c binary(0), d varchar(0))") - assertErrorCode(c, tk, "create index idx on issue3833 (b)", tmysql.ErrWrongKeyColumn) - assertErrorCode(c, tk, "alter table issue3833 add index idx (b)", tmysql.ErrWrongKeyColumn) - assertErrorCode(c, tk, "create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(b))", tmysql.ErrWrongKeyColumn) - assertErrorCode(c, tk, "create index idx on issue3833 (c)", tmysql.ErrWrongKeyColumn) - assertErrorCode(c, tk, "alter table issue3833 add index idx (c)", tmysql.ErrWrongKeyColumn) - assertErrorCode(c, tk, "create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(c))", tmysql.ErrWrongKeyColumn) - assertErrorCode(c, tk, "create index idx on issue3833 (d)", tmysql.ErrWrongKeyColumn) - assertErrorCode(c, tk, "alter table issue3833 add index idx (d)", tmysql.ErrWrongKeyColumn) - assertErrorCode(c, tk, "create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(d))", tmysql.ErrWrongKeyColumn) + tk.MustGetErrCode("create index idx on issue3833 (b)", tmysql.ErrWrongKeyColumn) + tk.MustGetErrCode("alter table issue3833 add index idx (b)", tmysql.ErrWrongKeyColumn) + tk.MustGetErrCode("create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(b))", tmysql.ErrWrongKeyColumn) + tk.MustGetErrCode("create index idx on issue3833 (c)", tmysql.ErrWrongKeyColumn) + tk.MustGetErrCode("alter table issue3833 add index idx (c)", tmysql.ErrWrongKeyColumn) + tk.MustGetErrCode("create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(c))", tmysql.ErrWrongKeyColumn) + tk.MustGetErrCode("create index idx on issue3833 (d)", tmysql.ErrWrongKeyColumn) + tk.MustGetErrCode("alter table issue3833 add index idx (d)", tmysql.ErrWrongKeyColumn) + tk.MustGetErrCode("create table issue3833_2 (b char(0), c binary(0), d varchar(0), index(d))", tmysql.ErrWrongKeyColumn) } func (s *testIntegrationSuite10) TestIssue2858And2717(c *C) { @@ -361,139 +360,139 @@ func (s *testIntegrationSuite5) TestMySQLErrorCode(c *C) { // create database sql := "create database aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - assertErrorCode(c, tk, sql, tmysql.ErrTooLongIdent) + tk.MustGetErrCode(sql, tmysql.ErrTooLongIdent) sql = "create database test" - assertErrorCode(c, tk, sql, tmysql.ErrDBCreateExists) + tk.MustGetErrCode(sql, tmysql.ErrDBCreateExists) sql = "create database test1 character set uft8;" - assertErrorCode(c, tk, sql, tmysql.ErrUnknownCharacterSet) + tk.MustGetErrCode(sql, tmysql.ErrUnknownCharacterSet) sql = "create database test2 character set gkb;" - assertErrorCode(c, tk, sql, tmysql.ErrUnknownCharacterSet) + tk.MustGetErrCode(sql, tmysql.ErrUnknownCharacterSet) sql = "create database test3 character set laitn1;" - assertErrorCode(c, tk, sql, tmysql.ErrUnknownCharacterSet) + tk.MustGetErrCode(sql, tmysql.ErrUnknownCharacterSet) // drop database sql = "drop database db_not_exist" - assertErrorCode(c, tk, sql, tmysql.ErrDBDropExists) + tk.MustGetErrCode(sql, tmysql.ErrDBDropExists) // create table tk.MustExec("create table test_error_code_succ (c1 int, c2 int, c3 int, primary key(c3))") sql = "create table test_error_code_succ (c1 int, c2 int, c3 int)" - assertErrorCode(c, tk, sql, tmysql.ErrTableExists) + tk.MustGetErrCode(sql, tmysql.ErrTableExists) sql = "create table test_error_code1 (c1 int, c2 int, c2 int)" - assertErrorCode(c, tk, sql, tmysql.ErrDupFieldName) + tk.MustGetErrCode(sql, tmysql.ErrDupFieldName) sql = "create table test_error_code1 (c1 int, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int)" - assertErrorCode(c, tk, sql, tmysql.ErrTooLongIdent) + tk.MustGetErrCode(sql, tmysql.ErrTooLongIdent) sql = "create table aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(a int)" - assertErrorCode(c, tk, sql, tmysql.ErrTooLongIdent) + tk.MustGetErrCode(sql, tmysql.ErrTooLongIdent) sql = "create table test_error_code1 (c1 int, c2 int, key aa (c1, c2), key aa (c1))" - assertErrorCode(c, tk, sql, tmysql.ErrDupKeyName) + tk.MustGetErrCode(sql, tmysql.ErrDupKeyName) sql = "create table test_error_code1 (c1 int, c2 int, c3 int, key(c_not_exist))" - assertErrorCode(c, tk, sql, tmysql.ErrKeyColumnDoesNotExits) + tk.MustGetErrCode(sql, tmysql.ErrKeyColumnDoesNotExits) sql = "create table test_error_code1 (c1 int, c2 int, c3 int, primary key(c_not_exist))" - assertErrorCode(c, tk, sql, tmysql.ErrKeyColumnDoesNotExits) + tk.MustGetErrCode(sql, tmysql.ErrKeyColumnDoesNotExits) sql = "create table test_error_code1 (c1 int not null default '')" - assertErrorCode(c, tk, sql, tmysql.ErrInvalidDefault) + tk.MustGetErrCode(sql, tmysql.ErrInvalidDefault) sql = "CREATE TABLE `t` (`a` double DEFAULT 1.0 DEFAULT 2.0 DEFAULT now());" - assertErrorCode(c, tk, sql, tmysql.ErrInvalidDefault) + tk.MustGetErrCode(sql, tmysql.ErrInvalidDefault) sql = "CREATE TABLE `t` (`a` double DEFAULT now());" - assertErrorCode(c, tk, sql, tmysql.ErrInvalidDefault) + tk.MustGetErrCode(sql, tmysql.ErrInvalidDefault) sql = "create table t1(a int) character set uft8;" - assertErrorCode(c, tk, sql, tmysql.ErrUnknownCharacterSet) + tk.MustGetErrCode(sql, tmysql.ErrUnknownCharacterSet) sql = "create table t1(a int) character set gkb;" - assertErrorCode(c, tk, sql, tmysql.ErrUnknownCharacterSet) + tk.MustGetErrCode(sql, tmysql.ErrUnknownCharacterSet) sql = "create table t1(a int) character set laitn1;" - assertErrorCode(c, tk, sql, tmysql.ErrUnknownCharacterSet) + tk.MustGetErrCode(sql, tmysql.ErrUnknownCharacterSet) sql = "create table test_error_code (a int not null ,b int not null,c int not null, d int not null, foreign key (b, c) references product(id));" - assertErrorCode(c, tk, sql, tmysql.ErrWrongFkDef) + tk.MustGetErrCode(sql, tmysql.ErrWrongFkDef) sql = "create table test_error_code_2;" - assertErrorCode(c, tk, sql, tmysql.ErrTableMustHaveColumns) + tk.MustGetErrCode(sql, tmysql.ErrTableMustHaveColumns) sql = "create table test_error_code_2 (unique(c1));" - assertErrorCode(c, tk, sql, tmysql.ErrTableMustHaveColumns) + tk.MustGetErrCode(sql, tmysql.ErrTableMustHaveColumns) sql = "create table test_error_code_2(c1 int, c2 int, c3 int, primary key(c1), primary key(c2));" - assertErrorCode(c, tk, sql, tmysql.ErrMultiplePriKey) + tk.MustGetErrCode(sql, tmysql.ErrMultiplePriKey) sql = "create table test_error_code_3(pt blob ,primary key (pt));" - assertErrorCode(c, tk, sql, tmysql.ErrBlobKeyWithoutLength) + tk.MustGetErrCode(sql, tmysql.ErrBlobKeyWithoutLength) sql = "create table test_error_code_3(a text, unique (a(3073)));" - assertErrorCode(c, tk, sql, tmysql.ErrTooLongKey) + tk.MustGetErrCode(sql, tmysql.ErrTooLongKey) sql = "create table test_error_code_3(`id` int, key `primary`(`id`));" - assertErrorCode(c, tk, sql, tmysql.ErrWrongNameForIndex) + tk.MustGetErrCode(sql, tmysql.ErrWrongNameForIndex) sql = "create table t2(c1.c2 blob default null);" - assertErrorCode(c, tk, sql, tmysql.ErrWrongTableName) + tk.MustGetErrCode(sql, tmysql.ErrWrongTableName) sql = "create table t2 (id int default null primary key , age int);" - assertErrorCode(c, tk, sql, tmysql.ErrInvalidDefault) + tk.MustGetErrCode(sql, tmysql.ErrInvalidDefault) sql = "create table t2 (id int null primary key , age int);" - assertErrorCode(c, tk, sql, tmysql.ErrPrimaryCantHaveNull) + tk.MustGetErrCode(sql, tmysql.ErrPrimaryCantHaveNull) sql = "create table t2 (id int default null, age int, primary key(id));" - assertErrorCode(c, tk, sql, tmysql.ErrPrimaryCantHaveNull) + tk.MustGetErrCode(sql, tmysql.ErrPrimaryCantHaveNull) sql = "create table t2 (id int null, age int, primary key(id));" - assertErrorCode(c, tk, sql, tmysql.ErrPrimaryCantHaveNull) + tk.MustGetErrCode(sql, tmysql.ErrPrimaryCantHaveNull) sql = "create table t2 (id int auto_increment);" - assertErrorCode(c, tk, sql, tmysql.ErrWrongAutoKey) + tk.MustGetErrCode(sql, tmysql.ErrWrongAutoKey) sql = "create table t2 (a datetime(2) default current_timestamp(3))" - assertErrorCode(c, tk, sql, tmysql.ErrInvalidDefault) + tk.MustGetErrCode(sql, tmysql.ErrInvalidDefault) sql = "create table t2 (a datetime(2) default current_timestamp(2) on update current_timestamp)" - assertErrorCode(c, tk, sql, tmysql.ErrInvalidOnUpdate) + tk.MustGetErrCode(sql, tmysql.ErrInvalidOnUpdate) sql = "create table t2 (a datetime default current_timestamp on update current_timestamp(2))" - assertErrorCode(c, tk, sql, tmysql.ErrInvalidOnUpdate) + tk.MustGetErrCode(sql, tmysql.ErrInvalidOnUpdate) sql = "create table t2 (a datetime(2) default current_timestamp(2) on update current_timestamp(3))" - assertErrorCode(c, tk, sql, tmysql.ErrInvalidOnUpdate) + tk.MustGetErrCode(sql, tmysql.ErrInvalidOnUpdate) sql = "create table t2 (id int primary key , age int);" tk.MustExec(sql) // add column sql = "alter table test_error_code_succ add column c1 int" - assertErrorCode(c, tk, sql, tmysql.ErrDupFieldName) + tk.MustGetErrCode(sql, tmysql.ErrDupFieldName) sql = "alter table test_error_code_succ add column aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int" - assertErrorCode(c, tk, sql, tmysql.ErrTooLongIdent) + tk.MustGetErrCode(sql, tmysql.ErrTooLongIdent) sql = "alter table test_comment comment 'test comment'" - assertErrorCode(c, tk, sql, tmysql.ErrNoSuchTable) + tk.MustGetErrCode(sql, tmysql.ErrNoSuchTable) sql = "alter table test_error_code_succ add column `a ` int ;" - assertErrorCode(c, tk, sql, tmysql.ErrWrongColumnName) + tk.MustGetErrCode(sql, tmysql.ErrWrongColumnName) tk.MustExec("create table test_on_update (c1 int, c2 int);") sql = "alter table test_on_update add column c3 int on update current_timestamp;" - assertErrorCode(c, tk, sql, tmysql.ErrInvalidOnUpdate) + tk.MustGetErrCode(sql, tmysql.ErrInvalidOnUpdate) sql = "create table test_on_update_2(c int on update current_timestamp);" - assertErrorCode(c, tk, sql, tmysql.ErrInvalidOnUpdate) + tk.MustGetErrCode(sql, tmysql.ErrInvalidOnUpdate) // drop column sql = "alter table test_error_code_succ drop c_not_exist" - assertErrorCode(c, tk, sql, tmysql.ErrCantDropFieldOrKey) + tk.MustGetErrCode(sql, tmysql.ErrCantDropFieldOrKey) tk.MustExec("create table test_drop_column (c1 int );") sql = "alter table test_drop_column drop column c1;" - assertErrorCode(c, tk, sql, tmysql.ErrCantRemoveAllFields) + tk.MustGetErrCode(sql, tmysql.ErrCantRemoveAllFields) // add index sql = "alter table test_error_code_succ add index idx (c_not_exist)" - assertErrorCode(c, tk, sql, tmysql.ErrKeyColumnDoesNotExits) + tk.MustGetErrCode(sql, tmysql.ErrKeyColumnDoesNotExits) tk.MustExec("alter table test_error_code_succ add index idx (c1)") sql = "alter table test_error_code_succ add index idx (c1)" - assertErrorCode(c, tk, sql, tmysql.ErrDupKeyName) + tk.MustGetErrCode(sql, tmysql.ErrDupKeyName) // drop index sql = "alter table test_error_code_succ drop index idx_not_exist" - assertErrorCode(c, tk, sql, tmysql.ErrCantDropFieldOrKey) + tk.MustGetErrCode(sql, tmysql.ErrCantDropFieldOrKey) sql = "alter table test_error_code_succ drop column c3" - assertErrorCode(c, tk, sql, int(tmysql.ErrUnknown)) + tk.MustGetErrCode(sql, int(tmysql.ErrUnknown)) // modify column sql = "alter table test_error_code_succ modify testx.test_error_code_succ.c1 bigint" - assertErrorCode(c, tk, sql, tmysql.ErrWrongDBName) + tk.MustGetErrCode(sql, tmysql.ErrWrongDBName) sql = "alter table test_error_code_succ modify t.c1 bigint" - assertErrorCode(c, tk, sql, tmysql.ErrWrongTableName) + tk.MustGetErrCode(sql, tmysql.ErrWrongTableName) // insert value tk.MustExec("create table test_error_code_null(c1 char(100) not null);") sql = "insert into test_error_code_null (c1) values(null);" - assertErrorCode(c, tk, sql, tmysql.ErrBadNull) + tk.MustGetErrCode(sql, tmysql.ErrBadNull) } func (s *testIntegrationSuite9) TestTableDDLWithFloatType(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists t") - assertErrorCode(c, s.tk, "create table t (a decimal(1, 2))", tmysql.ErrMBiggerThanD) - assertErrorCode(c, s.tk, "create table t (a float(1, 2))", tmysql.ErrMBiggerThanD) - assertErrorCode(c, s.tk, "create table t (a double(1, 2))", tmysql.ErrMBiggerThanD) + s.tk.MustGetErrCode("create table t (a decimal(1, 2))", tmysql.ErrMBiggerThanD) + s.tk.MustGetErrCode("create table t (a float(1, 2))", tmysql.ErrMBiggerThanD) + s.tk.MustGetErrCode("create table t (a double(1, 2))", tmysql.ErrMBiggerThanD) s.tk.MustExec("create table t (a double(1, 1))") - assertErrorCode(c, s.tk, "alter table t add column b decimal(1, 2)", tmysql.ErrMBiggerThanD) + s.tk.MustGetErrCode("alter table t add column b decimal(1, 2)", tmysql.ErrMBiggerThanD) // add multi columns now not support, so no case. - assertErrorCode(c, s.tk, "alter table t modify column a float(1, 4)", tmysql.ErrMBiggerThanD) - assertErrorCode(c, s.tk, "alter table t change column a aa float(1, 4)", tmysql.ErrMBiggerThanD) + s.tk.MustGetErrCode("alter table t modify column a float(1, 4)", tmysql.ErrMBiggerThanD) + s.tk.MustGetErrCode("alter table t change column a aa float(1, 4)", tmysql.ErrMBiggerThanD) s.tk.MustExec("drop table t") } @@ -501,21 +500,21 @@ func (s *testIntegrationSuite10) TestTableDDLWithTimeType(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") s.tk.MustExec("drop table if exists t") - assertErrorCode(c, s.tk, "create table t (a time(7))", tmysql.ErrTooBigPrecision) - assertErrorCode(c, s.tk, "create table t (a datetime(7))", tmysql.ErrTooBigPrecision) - assertErrorCode(c, s.tk, "create table t (a timestamp(7))", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("create table t (a time(7))", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("create table t (a datetime(7))", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("create table t (a timestamp(7))", tmysql.ErrTooBigPrecision) _, err := s.tk.Exec("create table t (a time(-1))") c.Assert(err, NotNil) s.tk.MustExec("create table t (a datetime)") - assertErrorCode(c, s.tk, "alter table t add column b time(7)", tmysql.ErrTooBigPrecision) - assertErrorCode(c, s.tk, "alter table t add column b datetime(7)", tmysql.ErrTooBigPrecision) - assertErrorCode(c, s.tk, "alter table t add column b timestamp(7)", tmysql.ErrTooBigPrecision) - assertErrorCode(c, s.tk, "alter table t modify column a time(7)", tmysql.ErrTooBigPrecision) - assertErrorCode(c, s.tk, "alter table t modify column a datetime(7)", tmysql.ErrTooBigPrecision) - assertErrorCode(c, s.tk, "alter table t modify column a timestamp(7)", tmysql.ErrTooBigPrecision) - assertErrorCode(c, s.tk, "alter table t change column a aa time(7)", tmysql.ErrTooBigPrecision) - assertErrorCode(c, s.tk, "alter table t change column a aa datetime(7)", tmysql.ErrTooBigPrecision) - assertErrorCode(c, s.tk, "alter table t change column a aa timestamp(7)", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("alter table t add column b time(7)", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("alter table t add column b datetime(7)", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("alter table t add column b timestamp(7)", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("alter table t modify column a time(7)", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("alter table t modify column a datetime(7)", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("alter table t modify column a timestamp(7)", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("alter table t change column a aa time(7)", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("alter table t change column a aa datetime(7)", tmysql.ErrTooBigPrecision) + s.tk.MustGetErrCode("alter table t change column a aa timestamp(7)", tmysql.ErrTooBigPrecision) s.tk.MustExec("alter table t change column a aa datetime(0)") s.tk.MustExec("drop table t") } @@ -608,11 +607,11 @@ func (s *testIntegrationSuite7) TestDependedGeneratedColumnPrior2GeneratedColumn ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") // should check unknown column first, then the prior ones. sql := "alter table t add column d int as (c + f + 1) first" - assertErrorCode(c, tk, sql, mysql.ErrBadField) + tk.MustGetErrCode(sql, mysql.ErrBadField) // depended generated column should be prior to generated column self sql = "alter table t add column d int as (c+1) first" - assertErrorCode(c, tk, sql, mysql.ErrGeneratedColumnNonPrior) + tk.MustGetErrCode(sql, mysql.ErrGeneratedColumnNonPrior) // correct case tk.MustExec("alter table t add column d int as (c+1) after c") @@ -1204,7 +1203,7 @@ func (s *testIntegrationSuite1) TestCreateTableTooLarge(c *C) { } } sql += ");" - assertErrorCode(c, s.tk, sql, tmysql.ErrTooManyFields) + s.tk.MustGetErrCode(sql, tmysql.ErrTooManyFields) originLimit := atomic.LoadUint32(&ddl.TableColumnCountLimit) atomic.StoreUint32(&ddl.TableColumnCountLimit, uint32(cnt*4)) @@ -1234,7 +1233,7 @@ func (s *testIntegrationSuite8) TestChangeColumnPosition(c *C) { s.tk.MustQuery("select * from position1").Check(testkit.Rows("TiDB 2 3.14 1")) s.tk.MustExec("alter table position1 modify column c double first") s.tk.MustQuery("select * from position1").Check(testkit.Rows("3.14 TiDB 2 1")) - assertErrorCode(c, s.tk, "alter table position1 modify column b int after b", tmysql.ErrBadField) + s.tk.MustGetErrCode("alter table position1 modify column b int after b", tmysql.ErrBadField) s.tk.MustExec("create table position2 (a int, b int)") s.tk.MustExec("alter table position2 add index t(a, b)") @@ -1243,7 +1242,7 @@ func (s *testIntegrationSuite8) TestChangeColumnPosition(c *C) { s.tk.MustQuery("select a from position2 where a = 3").Check(testkit.Rows()) s.tk.MustExec("alter table position2 change column b c int first") s.tk.MustQuery("select * from position2 where c = 3").Check(testkit.Rows("3 5")) - assertErrorCode(c, s.tk, "alter table position2 change column c b int after c", tmysql.ErrBadField) + s.tk.MustGetErrCode("alter table position2 change column c b int after c", tmysql.ErrBadField) s.tk.MustExec("create table position3 (a int default 2)") s.tk.MustExec("alter table position3 modify column a int default 5 first") @@ -1272,9 +1271,9 @@ func (s *testIntegrationSuite2) TestAddIndexAfterAddColumn(c *C) { s.tk.MustExec("insert into test_add_index_after_add_col values(1, 2),(2,2)") s.tk.MustExec("alter table test_add_index_after_add_col add column c int not null default '0'") sql := "alter table test_add_index_after_add_col add unique index cc(c) " - assertErrorCode(c, s.tk, sql, tmysql.ErrDupEntry) + s.tk.MustGetErrCode(sql, tmysql.ErrDupEntry) sql = "alter table test_add_index_after_add_col add index idx_test(f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17);" - assertErrorCode(c, s.tk, sql, tmysql.ErrTooManyKeyParts) + s.tk.MustGetErrCode(sql, tmysql.ErrTooManyKeyParts) } func (s *testIntegrationSuite8) TestResolveCharset(c *C) { @@ -1369,7 +1368,7 @@ func (s *testIntegrationSuite1) TestAddColumnTooMany(c *C) { s.tk.MustExec(createSQL) s.tk.MustExec("alter table t_column_too_many add column a_512 int") alterSQL := "alter table t_column_too_many add column a_513 int" - assertErrorCode(c, s.tk, alterSQL, tmysql.ErrTooManyFields) + s.tk.MustGetErrCode(alterSQL, tmysql.ErrTooManyFields) } func (s *testIntegrationSuite4) TestAlterColumn(c *C) { @@ -1425,13 +1424,13 @@ func (s *testIntegrationSuite4) TestAlterColumn(c *C) { // for failing tests sql := "alter table db_not_exist.test_alter_column alter column b set default 'c'" - assertErrorCode(c, s.tk, sql, tmysql.ErrNoSuchTable) + s.tk.MustGetErrCode(sql, tmysql.ErrNoSuchTable) sql = "alter table test_not_exist alter column b set default 'c'" - assertErrorCode(c, s.tk, sql, tmysql.ErrNoSuchTable) + s.tk.MustGetErrCode(sql, tmysql.ErrNoSuchTable) sql = "alter table test_alter_column alter column col_not_exist set default 'c'" - assertErrorCode(c, s.tk, sql, tmysql.ErrBadField) + s.tk.MustGetErrCode(sql, tmysql.ErrBadField) sql = "alter table test_alter_column alter column c set default null" - assertErrorCode(c, s.tk, sql, tmysql.ErrInvalidDefault) + s.tk.MustGetErrCode(sql, tmysql.ErrInvalidDefault) // The followings tests whether adding constraints via change / modify column // is forbidden as expected. @@ -1506,7 +1505,7 @@ func (s *testIntegrationSuite) assertAlterWarnExec(c *C, sql string) { } func (s *testIntegrationSuite) assertAlterErrorExec(c *C, sql string) { - assertErrorCode(c, s.tk, sql, mysql.ErrAlterOperationNotSupportedReason) + s.tk.MustGetErrCode(sql, mysql.ErrAlterOperationNotSupportedReason) } func (s *testIntegrationSuite3) TestAlterAlgorithm(c *C) { @@ -1593,12 +1592,12 @@ func (s *testIntegrationSuite3) TestAlterTableAddUniqueOnPartionRangeColumn(c *C s.tk.MustExec("insert into t values (4, 'xxx', 4)") s.tk.MustExec("insert into t values (4, 'xxx', 9)") // Note the repeated 4 s.tk.MustExec("insert into t values (17, 'xxx', 12)") - assertErrorCode(c, s.tk, "alter table t add unique index idx_a(a)", mysql.ErrDupEntry) + s.tk.MustGetErrCode("alter table t add unique index idx_a(a)", mysql.ErrDupEntry) s.tk.MustExec("delete from t where a = 4") s.tk.MustExec("alter table t add unique index idx_a(a)") s.tk.MustExec("alter table t add unique index idx_ac(a, c)") - assertErrorCode(c, s.tk, "alter table t add unique index idx_b(b)", mysql.ErrUniqueKeyNeedAllFieldsInPf) + s.tk.MustGetErrCode("alter table t add unique index idx_b(b)", mysql.ErrUniqueKeyNeedAllFieldsInPf) } func (s *testIntegrationSuite5) TestFulltextIndexIgnore(c *C) { @@ -1627,7 +1626,7 @@ func (s *testIntegrationSuite1) TestTreatOldVersionUTF8AsUTF8MB4(c *C) { defer s.tk.MustExec("drop table if exists t") s.tk.MustExec("create table t (a varchar(10) character set utf8, b varchar(10) character set ascii) charset=utf8mb4;") - assertErrorCode(c, s.tk, "insert into t set a= x'f09f8c80';", mysql.ErrTruncatedWrongValueForField) + s.tk.MustGetErrCode("insert into t set a= x'f09f8c80';", mysql.ErrTruncatedWrongValueForField) s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" + " `a` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,\n" + " `b` varchar(10) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n" + @@ -1665,7 +1664,7 @@ func (s *testIntegrationSuite1) TestTreatOldVersionUTF8AsUTF8MB4(c *C) { config.GetGlobalConfig().TreatOldVersionUTF8AsUTF8MB4 = false s.tk.MustExec("alter table t drop column c;") // reload schema. - assertErrorCode(c, s.tk, "insert into t set a= x'f09f8c80'", mysql.ErrTruncatedWrongValueForField) + s.tk.MustGetErrCode("insert into t set a= x'f09f8c80'", mysql.ErrTruncatedWrongValueForField) s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" + " `a` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,\n" + " `b` varchar(10) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n" + @@ -1691,7 +1690,7 @@ func (s *testIntegrationSuite1) TestTreatOldVersionUTF8AsUTF8MB4(c *C) { config.GetGlobalConfig().TreatOldVersionUTF8AsUTF8MB4 = false s.tk.MustExec("alter table t drop column c;") // reload schema. - assertErrorCode(c, s.tk, "insert into t set a= x'f09f8c80'", mysql.ErrTruncatedWrongValueForField) + s.tk.MustGetErrCode("insert into t set a= x'f09f8c80'", mysql.ErrTruncatedWrongValueForField) s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" + " `a` varchar(10) DEFAULT NULL,\n" + " `b` varchar(10) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n" + @@ -1736,7 +1735,7 @@ func (s *testIntegrationSuite1) TestTreatOldVersionUTF8AsUTF8MB4(c *C) { config.GetGlobalConfig().TreatOldVersionUTF8AsUTF8MB4 = false s.tk.MustExec("alter table t change column b b varchar(30) character set ascii") // reload schema. - assertErrorCode(c, s.tk, "insert into t set a= x'f09f8c80'", mysql.ErrTruncatedWrongValueForField) + s.tk.MustGetErrCode("insert into t set a= x'f09f8c80'", mysql.ErrTruncatedWrongValueForField) s.tk.MustQuery("show create table t").Check(testkit.Rows("t CREATE TABLE `t` (\n" + " `a` varchar(20) DEFAULT NULL,\n" + " `b` varchar(30) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL\n" + @@ -1878,12 +1877,12 @@ func (s *testIntegrationSuite4) TestDropAutoIncrementIndex(c *C) { tk.MustExec("drop table if exists t1") tk.MustExec("create table t1 (a int auto_increment, unique key (a))") dropIndexSQL := "alter table t1 drop index a" - assertErrorCode(c, tk, dropIndexSQL, mysql.ErrWrongAutoKey) + tk.MustGetErrCode(dropIndexSQL, mysql.ErrWrongAutoKey) tk.MustExec("drop table if exists t1") tk.MustExec("create table t1 (a int(11) not null auto_increment, b int(11), c bigint, unique key (a, b, c))") dropIndexSQL = "alter table t1 drop index a" - assertErrorCode(c, tk, dropIndexSQL, mysql.ErrWrongAutoKey) + tk.MustGetErrCode(dropIndexSQL, mysql.ErrWrongAutoKey) } func (s *testIntegrationSuite3) TestInsertIntoGeneratedColumnWithDefaultExpr(c *C) { @@ -1939,7 +1938,7 @@ func (s *testIntegrationSuite3) TestInsertIntoGeneratedColumnWithDefaultExpr(c * // generated columns with default function is not allowed tk.MustExec("create table t5 (a int default 10, b int as (a+1))") - assertErrorCode(c, tk, "insert into t5 values (20, default(a))", mysql.ErrBadGeneratedColumn) + tk.MustGetErrCode("insert into t5 values (20, default(a))", mysql.ErrBadGeneratedColumn) tk.MustExec("drop table t1") tk.MustExec("drop table t2") diff --git a/ddl/db_partition_test.go b/ddl/db_partition_test.go index 1816f87b20150..3f58bd5ed05c0 100644 --- a/ddl/db_partition_test.go +++ b/ddl/db_partition_test.go @@ -81,7 +81,7 @@ func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { partition p2 values less than (1996), partition p2 values less than (2001) );` - assertErrorCode(c, tk, sql1, tmysql.ErrSameNamePartition) + tk.MustGetErrCode(sql1, tmysql.ErrSameNamePartition) sql2 := `create table employees ( id int not null, @@ -92,7 +92,7 @@ func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { partition p2 values less than (1996), partition p3 values less than (2001) );` - assertErrorCode(c, tk, sql2, tmysql.ErrRangeNotIncreasing) + tk.MustGetErrCode(sql2, tmysql.ErrRangeNotIncreasing) sql3 := `create table employees ( id int not null, @@ -103,7 +103,7 @@ func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { partition p2 values less than maxvalue, partition p3 values less than (2001) );` - assertErrorCode(c, tk, sql3, tmysql.ErrPartitionMaxvalue) + tk.MustGetErrCode(sql3, tmysql.ErrPartitionMaxvalue) sql4 := `create table t4 ( a int not null, @@ -114,7 +114,7 @@ func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { partition p2 values less than (1991), partition p3 values less than (1995) );` - assertErrorCode(c, tk, sql4, tmysql.ErrPartitionMaxvalue) + tk.MustGetErrCode(sql4, tmysql.ErrPartitionMaxvalue) _, err = tk.Exec(`CREATE TABLE rc ( a INT NOT NULL, @@ -136,7 +136,7 @@ func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { partition by range( hired ) ( partition p0 values less than (6 , 10) );` - assertErrorCode(c, tk, sql6, tmysql.ErrTooManyValues) + tk.MustGetErrCode(sql6, tmysql.ErrTooManyValues) sql7 := `create table t7 ( a int not null, @@ -149,7 +149,7 @@ func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { partition p4 values less than (1995), partition p5 values less than maxvalue );` - assertErrorCode(c, tk, sql7, tmysql.ErrPartitionMaxvalue) + tk.MustGetErrCode(sql7, tmysql.ErrPartitionMaxvalue) _, err = tk.Exec(`create table t8 ( a int not null, @@ -168,9 +168,9 @@ func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { partition p0 values less than (2), partition p1 values less than (6) );` - assertErrorCode(c, tk, sql9, tmysql.ErrPartitionFunctionIsNotAllowed) + tk.MustGetErrCode(sql9, tmysql.ErrPartitionFunctionIsNotAllowed) - assertErrorCode(c, tk, `create TABLE t10 (c1 int,c2 int) partition by range(c1 / c2 ) (partition p0 values less than (2));`, tmysql.ErrPartitionFunctionIsNotAllowed) + tk.MustGetErrCode(`create TABLE t10 (c1 int,c2 int) partition by range(c1 / c2 ) (partition p0 values less than (2));`, tmysql.ErrPartitionFunctionIsNotAllowed) _, err = tk.Exec(`CREATE TABLE t9 ( a INT NOT NULL, b INT NOT NULL, @@ -183,7 +183,7 @@ func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { );`) c.Assert(ddl.ErrRangeNotIncreasing.Equal(err), IsTrue) - assertErrorCode(c, tk, `create TABLE t10 (c1 int,c2 int) partition by range(c1 / c2 ) (partition p0 values less than (2));`, tmysql.ErrPartitionFunctionIsNotAllowed) + tk.MustGetErrCode(`create TABLE t10 (c1 int,c2 int) partition by range(c1 / c2 ) (partition p0 values less than (2));`, tmysql.ErrPartitionFunctionIsNotAllowed) tk.MustExec(`create TABLE t11 (c1 int,c2 int) partition by range(c1 div c2 ) (partition p0 values less than (2));`) tk.MustExec(`create TABLE t12 (c1 int,c2 int) partition by range(c1 + c2 ) (partition p0 values less than (2));`) @@ -192,17 +192,17 @@ func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { tk.MustExec(`create TABLE t15 (c1 int,c2 int) partition by range( abs(c1) ) (partition p0 values less than (2));`) tk.MustExec(`create TABLE t16 (c1 int) partition by range( c1) (partition p0 values less than (10));`) - assertErrorCode(c, tk, `create TABLE t17 (c1 int,c2 float) partition by range(c1 + c2 ) (partition p0 values less than (2));`, tmysql.ErrPartitionFuncNotAllowed) - assertErrorCode(c, tk, `create TABLE t18 (c1 int,c2 float) partition by range( floor(c2) ) (partition p0 values less than (2));`, tmysql.ErrPartitionFuncNotAllowed) + tk.MustGetErrCode(`create TABLE t17 (c1 int,c2 float) partition by range(c1 + c2 ) (partition p0 values less than (2));`, tmysql.ErrPartitionFuncNotAllowed) + tk.MustGetErrCode(`create TABLE t18 (c1 int,c2 float) partition by range( floor(c2) ) (partition p0 values less than (2));`, tmysql.ErrPartitionFuncNotAllowed) tk.MustExec(`create TABLE t19 (c1 int,c2 float) partition by range( floor(c1) ) (partition p0 values less than (2));`) tk.MustExec(`create TABLE t20 (c1 int,c2 bit(10)) partition by range(c2) (partition p0 values less than (10));`) tk.MustExec(`create TABLE t21 (c1 int,c2 year) partition by range( c2 ) (partition p0 values less than (2000));`) - assertErrorCode(c, tk, `create TABLE t24 (c1 float) partition by range( c1 ) (partition p0 values less than (2000));`, tmysql.ErrFieldTypeNotAllowedAsPartitionField) + tk.MustGetErrCode(`create TABLE t24 (c1 float) partition by range( c1 ) (partition p0 values less than (2000));`, tmysql.ErrFieldTypeNotAllowedAsPartitionField) // test check order. The sql below have 2 problem: 1. ErrFieldTypeNotAllowedAsPartitionField 2. ErrPartitionMaxvalue , mysql will return ErrPartitionMaxvalue. - assertErrorCode(c, tk, `create TABLE t25 (c1 float) partition by range( c1 ) (partition p1 values less than maxvalue,partition p0 values less than (2000));`, tmysql.ErrPartitionMaxvalue) + tk.MustGetErrCode(`create TABLE t25 (c1 float) partition by range( c1 ) (partition p1 values less than maxvalue,partition p0 values less than (2000));`, tmysql.ErrPartitionMaxvalue) // Fix issue 7362. tk.MustExec("create table test_partition(id bigint, name varchar(255), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 PARTITION BY RANGE COLUMNS(id) (PARTITION p1 VALUES LESS THAN (10) ENGINE = InnoDB);") @@ -241,15 +241,15 @@ func (s *testIntegrationSuite9) TestCreateTableWithPartition(c *C) { (partition p0 values less than (10, 10.0))`) c.Assert(ddl.ErrNotAllowedTypeInPartition.Equal(err), IsTrue) - assertErrorCode(c, tk, `create table t31 (a int not null) partition by range( a );`, tmysql.ErrPartitionsMustBeDefined) - assertErrorCode(c, tk, `create table t32 (a int not null) partition by range columns( a );`, tmysql.ErrPartitionsMustBeDefined) - assertErrorCode(c, tk, `create table t33 (a int, b int) partition by hash(a) partitions 0;`, tmysql.ErrNoParts) - assertErrorCode(c, tk, `create table t33 (a timestamp, b int) partition by hash(a) partitions 30;`, tmysql.ErrFieldTypeNotAllowedAsPartitionField) + tk.MustGetErrCode(`create table t31 (a int not null) partition by range( a );`, tmysql.ErrPartitionsMustBeDefined) + tk.MustGetErrCode(`create table t32 (a int not null) partition by range columns( a );`, tmysql.ErrPartitionsMustBeDefined) + tk.MustGetErrCode(`create table t33 (a int, b int) partition by hash(a) partitions 0;`, tmysql.ErrNoParts) + tk.MustGetErrCode(`create table t33 (a timestamp, b int) partition by hash(a) partitions 30;`, tmysql.ErrFieldTypeNotAllowedAsPartitionField) // TODO: fix this one - // assertErrorCode(c, tk, `create table t33 (a timestamp, b int) partition by hash(unix_timestamp(a)) partitions 30;`, tmysql.ErrPartitionFuncNotAllowed) + // tk.MustGetErrCode(`create table t33 (a timestamp, b int) partition by hash(unix_timestamp(a)) partitions 30;`, tmysql.ErrPartitionFuncNotAllowed) // Fix issue 8647 - assertErrorCode(c, tk, `CREATE TABLE trb8 ( + tk.MustGetErrCode(`CREATE TABLE trb8 ( id int(11) DEFAULT NULL, name varchar(50) DEFAULT NULL, purchased date DEFAULT NULL @@ -463,7 +463,7 @@ func (s *testIntegrationSuite5) TestAlterTableAddPartition(c *C) { partition p1 values less than (2010), partition p2 values less than maxvalue );` - assertErrorCode(c, tk, sql1, tmysql.ErrPartitionMgmtOnNonpartitioned) + tk.MustGetErrCode(sql1, tmysql.ErrPartitionMgmtOnNonpartitioned) tk.MustExec(`create table table_MustBeDefined ( id int not null, hired date not null @@ -474,7 +474,7 @@ func (s *testIntegrationSuite5) TestAlterTableAddPartition(c *C) { partition p3 values less than (2001) );`) sql2 := "alter table table_MustBeDefined add partition" - assertErrorCode(c, tk, sql2, tmysql.ErrPartitionsMustBeDefined) + tk.MustGetErrCode(sql2, tmysql.ErrPartitionsMustBeDefined) tk.MustExec("drop table if exists table2;") tk.MustExec(`create table table2 ( @@ -489,7 +489,7 @@ func (s *testIntegrationSuite5) TestAlterTableAddPartition(c *C) { sql3 := `alter table table2 add partition ( partition p3 values less than (2010) );` - assertErrorCode(c, tk, sql3, tmysql.ErrPartitionMaxvalue) + tk.MustGetErrCode(sql3, tmysql.ErrPartitionMaxvalue) tk.MustExec("drop table if exists table3;") tk.MustExec(`create table table3 ( @@ -504,34 +504,34 @@ func (s *testIntegrationSuite5) TestAlterTableAddPartition(c *C) { sql4 := `alter table table3 add partition ( partition p3 values less than (1993) );` - assertErrorCode(c, tk, sql4, tmysql.ErrRangeNotIncreasing) + tk.MustGetErrCode(sql4, tmysql.ErrRangeNotIncreasing) sql5 := `alter table table3 add partition ( partition p1 values less than (1993) );` - assertErrorCode(c, tk, sql5, tmysql.ErrSameNamePartition) + tk.MustGetErrCode(sql5, tmysql.ErrSameNamePartition) sql6 := `alter table table3 add partition ( partition p1 values less than (1993), partition p1 values less than (1995) );` - assertErrorCode(c, tk, sql6, tmysql.ErrSameNamePartition) + tk.MustGetErrCode(sql6, tmysql.ErrSameNamePartition) sql7 := `alter table table3 add partition ( partition p4 values less than (1993), partition p1 values less than (1995), partition p5 values less than maxvalue );` - assertErrorCode(c, tk, sql7, tmysql.ErrSameNamePartition) + tk.MustGetErrCode(sql7, tmysql.ErrSameNamePartition) sql8 := "alter table table3 add partition (partition p6);" - assertErrorCode(c, tk, sql8, tmysql.ErrPartitionRequiresValues) + tk.MustGetErrCode(sql8, tmysql.ErrPartitionRequiresValues) sql9 := "alter table table3 add partition (partition p7 values in (2018));" - assertErrorCode(c, tk, sql9, tmysql.ErrPartitionWrongValues) + tk.MustGetErrCode(sql9, tmysql.ErrPartitionWrongValues) sql10 := "alter table table3 add partition partitions 4;" - assertErrorCode(c, tk, sql10, tmysql.ErrPartitionsMustBeDefined) + tk.MustGetErrCode(sql10, tmysql.ErrPartitionsMustBeDefined) tk.MustExec("alter table table3 add partition (partition p3 values less than (2001 + 10))") @@ -550,7 +550,7 @@ func (s *testIntegrationSuite5) TestAlterTableAddPartition(c *C) { tk.MustExec("drop table if exists t;") tk.MustExec("create table t (a datetime) partition by range columns (a) (partition p1 values less than ('2019-06-01'), partition p2 values less than ('2019-07-01'));") sql := "alter table t add partition ( partition p3 values less than ('2019-07-01'));" - assertErrorCode(c, tk, sql, tmysql.ErrRangeNotIncreasing) + tk.MustGetErrCode(sql, tmysql.ErrRangeNotIncreasing) tk.MustExec("alter table t add partition ( partition p3 values less than ('2019-08-01'));") // Add partition value's type should be the same with the column's type. @@ -561,7 +561,7 @@ func (s *testIntegrationSuite5) TestAlterTableAddPartition(c *C) { PARTITION p0 VALUES LESS THAN ('20190905'), PARTITION p1 VALUES LESS THAN ('20190906'));`) sql = "alter table t add partition (partition p2 values less than (20190907));" - assertErrorCode(c, tk, sql, tmysql.ErrWrongTypeColumnValue) + tk.MustGetErrCode(sql, tmysql.ErrWrongTypeColumnValue) } func (s *testIntegrationSuite6) TestAlterTableDropPartition(c *C) { @@ -596,7 +596,7 @@ func (s *testIntegrationSuite6) TestAlterTableDropPartition(c *C) { tk.MustExec("drop table if exists table1;") tk.MustExec("create table table1 (a int);") sql1 := "alter table table1 drop partition p10;" - assertErrorCode(c, tk, sql1, tmysql.ErrPartitionMgmtOnNonpartitioned) + tk.MustGetErrCode(sql1, tmysql.ErrPartitionMgmtOnNonpartitioned) tk.MustExec("drop table if exists table2;") tk.MustExec(`create table table2 ( @@ -609,7 +609,7 @@ func (s *testIntegrationSuite6) TestAlterTableDropPartition(c *C) { partition p3 values less than (2001) );`) sql2 := "alter table table2 drop partition p10;" - assertErrorCode(c, tk, sql2, tmysql.ErrDropPartitionNonExistent) + tk.MustGetErrCode(sql2, tmysql.ErrDropPartitionNonExistent) tk.MustExec("drop table if exists table3;") tk.MustExec(`create table table3 ( @@ -619,7 +619,7 @@ func (s *testIntegrationSuite6) TestAlterTableDropPartition(c *C) { partition p1 values less than (1991) );`) sql3 := "alter table table3 drop partition p1;" - assertErrorCode(c, tk, sql3, tmysql.ErrDropLastPartition) + tk.MustGetErrCode(sql3, tmysql.ErrDropLastPartition) tk.MustExec("drop table if exists table4;") tk.MustExec(`create table table4 ( @@ -698,10 +698,10 @@ func (s *testIntegrationSuite6) TestAlterTableDropPartition(c *C) { tk.MustExec("alter table table4 drop partition Par2;") tk.MustExec("alter table table4 drop partition PAR5;") sql4 := "alter table table4 drop partition PAR0;" - assertErrorCode(c, tk, sql4, tmysql.ErrDropPartitionNonExistent) + tk.MustGetErrCode(sql4, tmysql.ErrDropPartitionNonExistent) tk.MustExec("CREATE TABLE t1 (a int(11), b varchar(64)) PARTITION BY HASH(a) PARTITIONS 3") - assertErrorCode(c, tk, "alter table t1 drop partition p2", tmysql.ErrOnlyOnRangeListPartition) + tk.MustGetErrCode("alter table t1 drop partition p2", tmysql.ErrOnlyOnRangeListPartition) } func (s *testIntegrationSuite11) TestAddPartitionTooManyPartitions(c *C) { @@ -717,7 +717,7 @@ func (s *testIntegrationSuite11) TestAddPartitionTooManyPartitions(c *C) { sql1 += fmt.Sprintf("partition p%d values less than (%d),", i, i) } sql1 += "partition p1025 values less than (1025) );" - assertErrorCode(c, tk, sql1, tmysql.ErrTooManyPartitions) + tk.MustGetErrCode(sql1, tmysql.ErrTooManyPartitions) tk.MustExec("drop table if exists p2;") sql2 := `create table p2 ( @@ -733,7 +733,7 @@ func (s *testIntegrationSuite11) TestAddPartitionTooManyPartitions(c *C) { sql3 := `alter table p2 add partition ( partition p1025 values less than (1025) );` - assertErrorCode(c, tk, sql3, tmysql.ErrTooManyPartitions) + tk.MustGetErrCode(sql3, tmysql.ErrTooManyPartitions) } func checkPartitionDelRangeDone(c *C, s *testIntegrationSuite, partitionPrefix kv.Key) bool { @@ -785,7 +785,7 @@ func (s *testIntegrationSuite6) TestTruncatePartitionAndDropTable(c *C) { result = tk.MustQuery("select count(*) from t2;") result.Check(testkit.Rows("100")) tk.MustExec("drop table t2;") - assertErrorCode(c, tk, "select * from t2;", tmysql.ErrNoSuchTable) + tk.MustGetErrCode("select * from t2;", tmysql.ErrNoSuchTable) // Test truncate table partition. tk.MustExec("drop table if exists t3;") @@ -861,7 +861,7 @@ func (s *testIntegrationSuite6) TestTruncatePartitionAndDropTable(c *C) { partitionPrefix = tablecodec.EncodeTablePrefix(oldPID) hasOldPartitionData = checkPartitionDelRangeDone(c, s.testIntegrationSuite, partitionPrefix) c.Assert(hasOldPartitionData, IsFalse) - assertErrorCode(c, tk, "select * from t4;", tmysql.ErrNoSuchTable) + tk.MustGetErrCode("select * from t4;", tmysql.ErrNoSuchTable) // Test truncate table partition reassigns new partitionIDs. tk.MustExec("drop table if exists t5;") @@ -999,7 +999,7 @@ func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { partition p1 values less than (11), partition p2 values less than (15) );` - assertErrorCode(c, tk, sql1, tmysql.ErrUniqueKeyNeedAllFieldsInPf) + tk.MustGetErrCode(sql1, tmysql.ErrUniqueKeyNeedAllFieldsInPf) tk.MustExec("drop table if exists Part1;") sql2 := `create table Part1 ( @@ -1014,7 +1014,7 @@ func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { partition p1 values less than (11), partition p2 values less than (15) );` - assertErrorCode(c, tk, sql2, tmysql.ErrUniqueKeyNeedAllFieldsInPf) + tk.MustGetErrCode(sql2, tmysql.ErrUniqueKeyNeedAllFieldsInPf) tk.MustExec("drop table if exists Part1;") sql3 := `create table Part1 ( @@ -1029,7 +1029,7 @@ func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { partition p1 values less than (11), partition p2 values less than (15) );` - assertErrorCode(c, tk, sql3, tmysql.ErrUniqueKeyNeedAllFieldsInPf) + tk.MustGetErrCode(sql3, tmysql.ErrUniqueKeyNeedAllFieldsInPf) tk.MustExec("drop table if exists Part1;") sql4 := `create table Part1 ( @@ -1044,7 +1044,7 @@ func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { partition p1 values less than (11), partition p2 values less than (15) );` - assertErrorCode(c, tk, sql4, tmysql.ErrUniqueKeyNeedAllFieldsInPf) + tk.MustGetErrCode(sql4, tmysql.ErrUniqueKeyNeedAllFieldsInPf) tk.MustExec("drop table if exists Part1;") sql5 := `create table Part1 ( @@ -1058,7 +1058,7 @@ func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { partition p1 values less than (11), partition p2 values less than (15) );` - assertErrorCode(c, tk, sql5, tmysql.ErrUniqueKeyNeedAllFieldsInPf) + tk.MustGetErrCode(sql5, tmysql.ErrUniqueKeyNeedAllFieldsInPf) tk.MustExec("drop table if exists Part1;") sql6 := `create table Part1 ( @@ -1073,7 +1073,7 @@ func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { partition p1 values less than (11), partition p2 values less than (15) );` - assertErrorCode(c, tk, sql6, tmysql.ErrUniqueKeyNeedAllFieldsInPf) + tk.MustGetErrCode(sql6, tmysql.ErrUniqueKeyNeedAllFieldsInPf) tk.MustExec("drop table if exists Part1;") sql7 := `create table Part1 ( @@ -1088,7 +1088,7 @@ func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { partition p1 values less than (11), partition p2 values less than (15) );` - assertErrorCode(c, tk, sql7, tmysql.ErrUniqueKeyNeedAllFieldsInPf) + tk.MustGetErrCode(sql7, tmysql.ErrUniqueKeyNeedAllFieldsInPf) tk.MustExec("drop table if exists part6;") sql8 := `create table part6 ( @@ -1104,7 +1104,7 @@ func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { partition p1 values less than (11), partition p2 values less than (15) );` - assertErrorCode(c, tk, sql8, tmysql.ErrUniqueKeyNeedAllFieldsInPf) + tk.MustGetErrCode(sql8, tmysql.ErrUniqueKeyNeedAllFieldsInPf) sql9 := `create table part7 ( col1 int not null, @@ -1116,7 +1116,7 @@ func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { partition p1 values less than (11), partition p2 values less than (15) )` - assertErrorCode(c, tk, sql9, tmysql.ErrUniqueKeyNeedAllFieldsInPf) + tk.MustGetErrCode(sql9, tmysql.ErrUniqueKeyNeedAllFieldsInPf) sql10 := `create table part8 ( a int not null, @@ -1132,7 +1132,7 @@ func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { partition p1 values less than (7), partition p2 values less than (11) )` - assertErrorCode(c, tk, sql10, tmysql.ErrUniqueKeyNeedAllFieldsInPf) + tk.MustGetErrCode(sql10, tmysql.ErrUniqueKeyNeedAllFieldsInPf) sql11 := `create table part9 ( a int not null, @@ -1148,7 +1148,7 @@ func (s *testIntegrationSuite5) TestPartitionUniqueKeyNeedAllFieldsInPf(c *C) { partition p1 values less than (7, 9), partition p2 values less than (11, 22) )` - assertErrorCode(c, tk, sql11, tmysql.ErrUniqueKeyNeedAllFieldsInPf) + tk.MustGetErrCode(sql11, tmysql.ErrUniqueKeyNeedAllFieldsInPf) } func (s *testIntegrationSuite2) TestPartitionDropPrimaryKey(c *C) { diff --git a/ddl/db_test.go b/ddl/db_test.go index 9dbf1809de9f4..ab1e793928b8b 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -136,15 +136,6 @@ type testDBSuite6 struct{ *testDBSuite } type testDBSuite7 struct{ *testDBSuite } type testDBSuite8 struct{ *testDBSuite } -func assertErrorCode(c *C, tk *testkit.TestKit, sql string, errCode int) { - _, err := tk.Exec(sql) - c.Assert(err, NotNil) - originErr := errors.Cause(err) - tErr, ok := originErr.(*terror.Error) - c.Assert(ok, IsTrue, Commentf("err: %T", originErr)) - c.Assert(tErr.ToSQLError().Code, DeepEquals, uint16(errCode), Commentf("MySQL code:%v", tErr.ToSQLError())) -} - func (s *testDBSuite6) TestAddIndexWithPK(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use " + s.schemaName) @@ -182,13 +173,13 @@ func (s *testDBSuite1) TestRenameIndex(c *C) { s.tk.MustExec("admin check index t k3") // Test rename on non-exists keys - assertErrorCode(c, s.tk, "alter table t rename index x to x", mysql.ErrKeyDoesNotExist) + s.tk.MustGetErrCode("alter table t rename index x to x", mysql.ErrKeyDoesNotExist) // Test rename on already-exists keys - assertErrorCode(c, s.tk, "alter table t rename index k3 to k2", mysql.ErrDupKeyName) + s.tk.MustGetErrCode("alter table t rename index k3 to k2", mysql.ErrDupKeyName) s.tk.MustExec("alter table t rename index k2 to K2") - assertErrorCode(c, s.tk, "alter table t rename key k3 to K2", mysql.ErrDupKeyName) + s.tk.MustGetErrCode("alter table t rename key k3 to K2", mysql.ErrDupKeyName) } func testGetTableByName(c *C, ctx sessionctx.Context, db, table string) table.Table { @@ -1542,7 +1533,7 @@ func (s *testDBSuite1) TestAddColumnTooMany(c *C) { s.tk.MustExec(createSQL) s.tk.MustExec("alter table t_column_too_many add column a_512 int") alterSQL := "alter table t_column_too_many add column a_513 int" - assertErrorCode(c, s.tk, alterSQL, tmysql.ErrTooManyFields) + s.tk.MustGetErrCode(alterSQL, tmysql.ErrTooManyFields) } func sessionExec(c *C, s kv.Storage, sql string) { @@ -1828,23 +1819,23 @@ func (s *testDBSuite4) TestChangeColumn(c *C) { // for failing tests sql := "alter table t3 change aa a bigint default ''" - assertErrorCode(c, s.tk, sql, tmysql.ErrInvalidDefault) + s.tk.MustGetErrCode(sql, tmysql.ErrInvalidDefault) sql = "alter table t3 change a testx.t3.aa bigint" - assertErrorCode(c, s.tk, sql, tmysql.ErrWrongDBName) + s.tk.MustGetErrCode(sql, tmysql.ErrWrongDBName) sql = "alter table t3 change t.a aa bigint" - assertErrorCode(c, s.tk, sql, tmysql.ErrWrongTableName) + s.tk.MustGetErrCode(sql, tmysql.ErrWrongTableName) s.mustExec(c, "create table t4 (c1 int, c2 int, c3 int default 1, index (c1));") s.tk.MustExec("insert into t4(c2) values (null);") sql = "alter table t4 change c1 a1 int not null;" - assertErrorCode(c, s.tk, sql, tmysql.ErrInvalidUseOfNull) + s.tk.MustGetErrCode(sql, tmysql.ErrInvalidUseOfNull) sql = "alter table t4 change c2 a bigint not null;" - assertErrorCode(c, s.tk, sql, tmysql.WarnDataTruncated) + s.tk.MustGetErrCode(sql, tmysql.WarnDataTruncated) sql = "alter table t3 modify en enum('a', 'z', 'b', 'c') not null default 'a'" - assertErrorCode(c, s.tk, sql, tmysql.ErrUnknown) + s.tk.MustGetErrCode(sql, tmysql.ErrUnknown) // Rename to an existing column. s.mustExec(c, "alter table t3 add column a bigint") sql = "alter table t3 change aa a bigint" - assertErrorCode(c, s.tk, sql, tmysql.ErrDupFieldName) + s.tk.MustGetErrCode(sql, tmysql.ErrDupFieldName) s.tk.MustExec("drop table t3") } @@ -1987,18 +1978,18 @@ func (s *testDBSuite1) TestCreateTable(c *C) { // test for enum column s.tk.MustExec("use test") failSQL := "create table t_enum (a enum('e','e'));" - assertErrorCode(c, s.tk, failSQL, tmysql.ErrDuplicatedValueInType) + s.tk.MustGetErrCode(failSQL, tmysql.ErrDuplicatedValueInType) failSQL = "create table t_enum (a enum('e','E'));" - assertErrorCode(c, s.tk, failSQL, tmysql.ErrDuplicatedValueInType) + s.tk.MustGetErrCode(failSQL, tmysql.ErrDuplicatedValueInType) failSQL = "create table t_enum (a enum('abc','Abc'));" - assertErrorCode(c, s.tk, failSQL, tmysql.ErrDuplicatedValueInType) + s.tk.MustGetErrCode(failSQL, tmysql.ErrDuplicatedValueInType) // test for set column failSQL = "create table t_enum (a set('e','e'));" - assertErrorCode(c, s.tk, failSQL, tmysql.ErrDuplicatedValueInType) + s.tk.MustGetErrCode(failSQL, tmysql.ErrDuplicatedValueInType) failSQL = "create table t_enum (a set('e','E'));" - assertErrorCode(c, s.tk, failSQL, tmysql.ErrDuplicatedValueInType) + s.tk.MustGetErrCode(failSQL, tmysql.ErrDuplicatedValueInType) failSQL = "create table t_enum (a set('abc','Abc'));" - assertErrorCode(c, s.tk, failSQL, tmysql.ErrDuplicatedValueInType) + s.tk.MustGetErrCode(failSQL, tmysql.ErrDuplicatedValueInType) _, err = s.tk.Exec("create table t_enum (a enum('B','b'));") c.Assert(err.Error(), Equals, "[types:1291]Column 'a' has duplicated value 'B' in ENUM") } @@ -2019,17 +2010,12 @@ func (s *testDBSuite2) TestCreateTableWithSetCol(c *C) { // It's for failure cases. // The type of default value is string. s.tk.MustExec("drop table t_set") - failedSQL := "create table t_set (a set('1', '4', '10') default '3');" - assertErrorCode(c, s.tk, failedSQL, tmysql.ErrInvalidDefault) - failedSQL = "create table t_set (a set('1', '4', '10') default '1,4,11');" - assertErrorCode(c, s.tk, failedSQL, tmysql.ErrInvalidDefault) - failedSQL = "create table t_set (a set('1', '4', '10') default '1 ,4');" - assertErrorCode(c, s.tk, failedSQL, tmysql.ErrInvalidDefault) + s.tk.MustGetErrCode("create table t_set (a set('1', '4', '10') default '3');", tmysql.ErrInvalidDefault) + s.tk.MustGetErrCode("create table t_set (a set('1', '4', '10') default '1,4,11');", tmysql.ErrInvalidDefault) + s.tk.MustGetErrCode("create table t_set (a set('1', '4', '10') default '1 ,4');", tmysql.ErrInvalidDefault) // The type of default value is int. - failedSQL = "create table t_set (a set('1', '4', '10') default 0);" - assertErrorCode(c, s.tk, failedSQL, tmysql.ErrInvalidDefault) - failedSQL = "create table t_set (a set('1', '4', '10') default 8);" - assertErrorCode(c, s.tk, failedSQL, tmysql.ErrInvalidDefault) + s.tk.MustGetErrCode("create table t_set (a set('1', '4', '10') default 0);", tmysql.ErrInvalidDefault) + s.tk.MustGetErrCode("create table t_set (a set('1', '4', '10') default 8);", tmysql.ErrInvalidDefault) // The type of default value is int. // It's for successful cases @@ -2062,11 +2048,11 @@ func (s *testDBSuite2) TestTableForeignKey(c *C) { s.tk.MustExec("create table t1 (a int, b int);") // test create table with foreign key. failSQL := "create table t2 (c int, foreign key (a) references t1(a));" - assertErrorCode(c, s.tk, failSQL, tmysql.ErrKeyColumnDoesNotExits) + s.tk.MustGetErrCode(failSQL, tmysql.ErrKeyColumnDoesNotExits) // test add foreign key. s.tk.MustExec("create table t3 (a int, b int);") failSQL = "alter table t1 add foreign key (c) REFERENCES t3(a);" - assertErrorCode(c, s.tk, failSQL, tmysql.ErrKeyColumnDoesNotExits) + s.tk.MustGetErrCode(failSQL, tmysql.ErrKeyColumnDoesNotExits) s.tk.MustExec("drop table if exists t1,t2,t3;") } @@ -2167,46 +2153,46 @@ func (s *testDBSuite) testRenameTable(c *C, sql string, isAlterTable bool) { // for failure case failSQL := fmt.Sprintf(sql, "test_not_exist.t", "test_not_exist.t") if isAlterTable { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrNoSuchTable) + s.tk.MustGetErrCode(failSQL, tmysql.ErrNoSuchTable) } else { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrFileNotFound) + s.tk.MustGetErrCode(failSQL, tmysql.ErrFileNotFound) } failSQL = fmt.Sprintf(sql, "test.test_not_exist", "test.test_not_exist") if isAlterTable { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrNoSuchTable) + s.tk.MustGetErrCode(failSQL, tmysql.ErrNoSuchTable) } else { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrFileNotFound) + s.tk.MustGetErrCode(failSQL, tmysql.ErrFileNotFound) } failSQL = fmt.Sprintf(sql, "test.t_not_exist", "test_not_exist.t") if isAlterTable { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrNoSuchTable) + s.tk.MustGetErrCode(failSQL, tmysql.ErrNoSuchTable) } else { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrFileNotFound) + s.tk.MustGetErrCode(failSQL, tmysql.ErrFileNotFound) } failSQL = fmt.Sprintf(sql, "test1.t2", "test_not_exist.t") - assertErrorCode(c, s.tk, failSQL, tmysql.ErrErrorOnRename) + s.tk.MustGetErrCode(failSQL, tmysql.ErrErrorOnRename) s.tk.MustExec("use test1") s.tk.MustExec("create table if not exists t_exist (c1 int, c2 int)") failSQL = fmt.Sprintf(sql, "test1.t2", "test1.t_exist") - assertErrorCode(c, s.tk, failSQL, tmysql.ErrTableExists) + s.tk.MustGetErrCode(failSQL, tmysql.ErrTableExists) failSQL = fmt.Sprintf(sql, "test.t_not_exist", "test1.t_exist") if isAlterTable { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrNoSuchTable) + s.tk.MustGetErrCode(failSQL, tmysql.ErrNoSuchTable) } else { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrTableExists) + s.tk.MustGetErrCode(failSQL, tmysql.ErrTableExists) } failSQL = fmt.Sprintf(sql, "test_not_exist.t", "test1.t_exist") if isAlterTable { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrNoSuchTable) + s.tk.MustGetErrCode(failSQL, tmysql.ErrNoSuchTable) } else { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrTableExists) + s.tk.MustGetErrCode(failSQL, tmysql.ErrTableExists) } failSQL = fmt.Sprintf(sql, "test_not_exist.t", "test1.t_not_exist") if isAlterTable { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrNoSuchTable) + s.tk.MustGetErrCode(failSQL, tmysql.ErrNoSuchTable) } else { - assertErrorCode(c, s.tk, failSQL, tmysql.ErrFileNotFound) + s.tk.MustGetErrCode(failSQL, tmysql.ErrFileNotFound) } // for the same table name @@ -2217,13 +2203,13 @@ func (s *testDBSuite) testRenameTable(c *C, sql string, isAlterTable bool) { s.tk.MustExec(fmt.Sprintf(sql, "test1.t", "t")) s.tk.MustExec(fmt.Sprintf(sql, "test1.t1", "test1.T1")) } else { - assertErrorCode(c, s.tk, fmt.Sprintf(sql, "test1.t", "t"), tmysql.ErrTableExists) - assertErrorCode(c, s.tk, fmt.Sprintf(sql, "test1.t1", "test1.T1"), tmysql.ErrTableExists) + s.tk.MustGetErrCode(fmt.Sprintf(sql, "test1.t", "t"), tmysql.ErrTableExists) + s.tk.MustGetErrCode(fmt.Sprintf(sql, "test1.t1", "test1.T1"), tmysql.ErrTableExists) } // Test rename table name too long. - assertErrorCode(c, s.tk, "rename table test1.t1 to test1.txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", tmysql.ErrTooLongIdent) - assertErrorCode(c, s.tk, "alter table test1.t1 rename to test1.txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", tmysql.ErrTooLongIdent) + s.tk.MustGetErrCode("rename table test1.t1 to test1.txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", tmysql.ErrTooLongIdent) + s.tk.MustGetErrCode("alter table test1.t1 rename to test1.txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", tmysql.ErrTooLongIdent) s.tk.MustExec("drop database test1") } @@ -2353,7 +2339,7 @@ func (s *testDBSuite3) TestGeneratedColumnDDL(c *C) { {`alter table test_gv_ddl modify column b int as (a + 8) stored`, mysql.ErrUnsupportedOnGeneratedColumn}, } for _, tt := range genExprTests { - assertErrorCode(c, s.tk, tt.stmt, tt.err) + s.tk.MustGetErrCode(tt.stmt, tt.err) } // Check alter table modify/change generated column. @@ -2386,9 +2372,9 @@ func (s *testDBSuite4) TestComment(c *C) { s.tk.MustExec("create index i on ct (d) comment '" + validComment + "'") s.tk.MustExec("alter table ct add key (e) comment '" + validComment + "'") - assertErrorCode(c, s.tk, "create table ct1 (c int, key (c) comment '"+invalidComment+"')", tmysql.ErrTooLongIndexComment) - assertErrorCode(c, s.tk, "create index i1 on ct (d) comment '"+invalidComment+"b"+"'", tmysql.ErrTooLongIndexComment) - assertErrorCode(c, s.tk, "alter table ct add key (e) comment '"+invalidComment+"'", tmysql.ErrTooLongIndexComment) + s.tk.MustGetErrCode("create table ct1 (c int, key (c) comment '"+invalidComment+"')", tmysql.ErrTooLongIndexComment) + s.tk.MustGetErrCode("create index i1 on ct (d) comment '"+invalidComment+"b"+"'", tmysql.ErrTooLongIndexComment) + s.tk.MustGetErrCode("alter table ct add key (e) comment '"+invalidComment+"'", tmysql.ErrTooLongIndexComment) s.tk.MustExec("set @@sql_mode=''") s.tk.MustExec("create table ct1 (c int, d int, e int, key (c) comment '" + invalidComment + "')") @@ -2433,23 +2419,23 @@ func (s *testDBSuite4) TestRebaseAutoID(c *C) { s.tk.MustQuery("select * from tidb.test").Check(testkit.Rows("1 1", "6000 1", "11000 1", "16000 1")) s.tk.MustExec("create table tidb.test2 (a int);") - assertErrorCode(c, s.tk, "alter table tidb.test2 add column b int auto_increment key, auto_increment=10;", tmysql.ErrUnknown) + s.tk.MustGetErrCode("alter table tidb.test2 add column b int auto_increment key, auto_increment=10;", tmysql.ErrUnknown) } func (s *testDBSuite7) TestCheckColumnDefaultValue(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test;") s.tk.MustExec("drop table if exists text_default_text;") - assertErrorCode(c, s.tk, "create table text_default_text(c1 text not null default '');", tmysql.ErrBlobCantHaveDefault) - assertErrorCode(c, s.tk, "create table text_default_text(c1 text not null default 'scds');", tmysql.ErrBlobCantHaveDefault) + s.tk.MustGetErrCode("create table text_default_text(c1 text not null default '');", tmysql.ErrBlobCantHaveDefault) + s.tk.MustGetErrCode("create table text_default_text(c1 text not null default 'scds');", tmysql.ErrBlobCantHaveDefault) s.tk.MustExec("drop table if exists text_default_json;") - assertErrorCode(c, s.tk, "create table text_default_json(c1 json not null default '');", tmysql.ErrBlobCantHaveDefault) - assertErrorCode(c, s.tk, "create table text_default_json(c1 json not null default 'dfew555');", tmysql.ErrBlobCantHaveDefault) + s.tk.MustGetErrCode("create table text_default_json(c1 json not null default '');", tmysql.ErrBlobCantHaveDefault) + s.tk.MustGetErrCode("create table text_default_json(c1 json not null default 'dfew555');", tmysql.ErrBlobCantHaveDefault) s.tk.MustExec("drop table if exists text_default_blob;") - assertErrorCode(c, s.tk, "create table text_default_blob(c1 blob not null default '');", tmysql.ErrBlobCantHaveDefault) - assertErrorCode(c, s.tk, "create table text_default_blob(c1 blob not null default 'scds54');", tmysql.ErrBlobCantHaveDefault) + s.tk.MustGetErrCode("create table text_default_blob(c1 blob not null default '');", tmysql.ErrBlobCantHaveDefault) + s.tk.MustGetErrCode("create table text_default_blob(c1 blob not null default 'scds54');", tmysql.ErrBlobCantHaveDefault) s.tk.MustExec("set sql_mode='';") s.tk.MustExec("create table text_default_text(c1 text not null default '');") @@ -2562,8 +2548,8 @@ func (s *testDBSuite3) TestColumnModifyingDefinition(c *C) { s.tk.MustExec("drop table if exists test2;") s.tk.MustExec("create table test2 (c1 int, c2 int, c3 int default 1, index (c1));") s.tk.MustExec("insert into test2(c2) values (null);") - assertErrorCode(c, s.tk, "alter table test2 change c2 a int not null", tmysql.ErrInvalidUseOfNull) - assertErrorCode(c, s.tk, "alter table test2 change c1 a1 bigint not null;", tmysql.WarnDataTruncated) + s.tk.MustGetErrCode("alter table test2 change c2 a int not null", tmysql.ErrInvalidUseOfNull) + s.tk.MustGetErrCode("alter table test2 change c1 a1 bigint not null;", tmysql.WarnDataTruncated) } func (s *testDBSuite4) TestCheckTooBigFieldLength(c *C) { @@ -2580,11 +2566,11 @@ func (s *testDBSuite4) TestCheckTooBigFieldLength(c *C) { s.tk.MustExec("drop table if exists tr_04;") s.tk.MustExec("create table tr_04 (a varchar(20000) ) default charset utf8;") - assertErrorCode(c, s.tk, "alter table tr_04 add column b varchar(20000) charset utf8mb4;", tmysql.ErrTooBigFieldlength) - assertErrorCode(c, s.tk, "alter table tr_04 convert to character set utf8mb4;", tmysql.ErrTooBigFieldlength) - assertErrorCode(c, s.tk, "create table tr (id int, name varchar(30000), purchased date ) default charset=utf8 collate=utf8_bin;", tmysql.ErrTooBigFieldlength) - assertErrorCode(c, s.tk, "create table tr (id int, name varchar(20000) charset utf8mb4, purchased date ) default charset=utf8 collate=utf8_bin;", tmysql.ErrTooBigFieldlength) - assertErrorCode(c, s.tk, "create table tr (id int, name varchar(65536), purchased date ) default charset=latin1;", tmysql.ErrTooBigFieldlength) + s.tk.MustGetErrCode("alter table tr_04 add column b varchar(20000) charset utf8mb4;", tmysql.ErrTooBigFieldlength) + s.tk.MustGetErrCode("alter table tr_04 convert to character set utf8mb4;", tmysql.ErrTooBigFieldlength) + s.tk.MustGetErrCode("create table tr (id int, name varchar(30000), purchased date ) default charset=utf8 collate=utf8_bin;", tmysql.ErrTooBigFieldlength) + s.tk.MustGetErrCode("create table tr (id int, name varchar(20000) charset utf8mb4, purchased date ) default charset=utf8 collate=utf8_bin;", tmysql.ErrTooBigFieldlength) + s.tk.MustGetErrCode("create table tr (id int, name varchar(65536), purchased date ) default charset=latin1;", tmysql.ErrTooBigFieldlength) s.tk.MustExec("drop table if exists tr_05;") s.tk.MustExec("create table tr_05 (a varchar(16000) charset utf8);") @@ -2635,7 +2621,7 @@ func (s *testDBSuite7) TestModifyColumnRollBack(c *C) { } } if mysql.HasPreventNullInsertFlag(c2.Flag) { - assertErrorCode(c, s.tk, "insert into t1(c2) values (null);", tmysql.ErrBadNull) + s.tk.MustGetErrCode("insert into t1(c2) values (null);", tmysql.ErrBadNull) } hookCtx := mock.NewContext() diff --git a/ddl/serial_test.go b/ddl/serial_test.go index e37da92f5f5fc..6b6d73d2d86fd 100644 --- a/ddl/serial_test.go +++ b/ddl/serial_test.go @@ -739,7 +739,7 @@ func (s *testSerialSuite) TestCanceledJobTakeTime(c *C) { ddl.WaitTimeWhenErrorOccured = 1 * time.Second defer func() { ddl.WaitTimeWhenErrorOccured = originalWT }() startTime := time.Now() - assertErrorCode(c, tk, "alter table t_cjtt add column b int", mysql.ErrNoSuchTable) + tk.MustGetErrCode("alter table t_cjtt add column b int", mysql.ErrNoSuchTable) sub := time.Since(startTime) c.Assert(sub, Less, ddl.WaitTimeWhenErrorOccured) } diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 2beb39b4b5bd3..a7d611a81d0e4 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -16,6 +16,7 @@ package core_test import ( . "github.com/pingcap/check" "github.com/pingcap/errors" + "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/planner/core" @@ -226,10 +227,8 @@ func (s *testIntegrationSuite) TestBitColErrorMessage(c *C) { tk.MustExec("drop table bit_col_t") tk.MustExec("create table bit_col_t (a bit(1))") tk.MustExec("drop table bit_col_t") - _, err = tk.Exec("create table bit_col_t (a bit(0))") - c.Assert(err, NotNil) - _, err = tk.Exec("create table bit_col_t (a bit(65))") - c.Assert(err, NotNil) + tk.MustGetErrCode("create table bit_col_t (a bit(0))", mysql.ErrInvalidFieldSize) + tk.MustGetErrCode("create table bit_col_t (a bit(65))", mysql.ErrTooBigDisplaywidth) } func (s *testIntegrationSuite) TestPartitionTableStats(c *C) { diff --git a/types/errors.go b/types/errors.go index 2881595eb828b..7e7f39ecf2f92 100644 --- a/types/errors.go +++ b/types/errors.go @@ -125,6 +125,7 @@ func init() { codeTruncatedWrongValue: mysql.ErrTruncatedWrongValue, codeUnknown: mysql.ErrUnknown, codeInvalidDefault: mysql.ErrInvalidDefault, + codeInvalidFieldSize: mysql.ErrInvalidFieldSize, codeMBiggerThanD: mysql.ErrMBiggerThanD, codeDataOutOfRange: mysql.ErrWarnDataOutOfRange, codeDuplicatedValueInType: mysql.ErrDuplicatedValueInType,