Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ddl/sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func (s *testSequenceSuite) TestDropSequence(c *C) {
_, err = tk1.Exec("drop sequence my_seq")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[planner:1142]DROP command denied to user 'localhost'@'myuser' for table 'my_seq'")

// test for if exists.
Comment thread
0xPoe marked this conversation as resolved.
Outdated
s.tk.MustExec("drop sequence if exists seq_if_exists")
s.tk.MustQuery("show warnings;").Check(testkit.Rows("Note 4139 Unknown SEQUENCE: 'test.seq_if_exists'"))
}

func (s *testSequenceSuite) TestShowCreateSequence(c *C) {
Expand Down
10 changes: 10 additions & 0 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,16 @@ func (e *DDLExec) dropTableObject(objects []*ast.TableName, obt objectType, ifEx
}
return infoschema.ErrTableDropExists.GenWithStackByArgs(strings.Join(notExistTables, ","))
}
// We need add warning when use if exists.
if len(notExistTables) > 0 && ifExists {
for _, table := range notExistTables {
if obt == sequenceObject {
e.ctx.GetSessionVars().StmtCtx.AppendNote(infoschema.ErrSequenceDropExists.GenWithStackByArgs(table))
} else {
e.ctx.GetSessionVars().StmtCtx.AppendNote(infoschema.ErrTableDropExists.GenWithStackByArgs(table))
}
}
}
return nil
}

Expand Down
14 changes: 14 additions & 0 deletions executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ func (s *testSuite6) TestCreateTable(c *C) {
tk.MustExec("insert into create_auto_increment_test (name) values ('aa')")
r = tk.MustQuery("select * from create_auto_increment_test;")
r.Check(testkit.Rows("1000 aa"))

// test for drop if exists.
Comment thread
0xPoe marked this conversation as resolved.
Outdated
tk.MustExec("drop table if exists t_if_exists;")
tk.MustQuery("show warnings;").Check(testkit.Rows("Note 1051 Unknown table 'test.t_if_exists'"))
tk.MustExec("create table if not exists t1_if_exists(c int)")
tk.MustExec("drop table if exists t1_if_exists,t2_if_exists,t3_if_exists")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Note|1051|Unknown table 'test.t2_if_exists'", "Note|1051|Unknown table 'test.t3_if_exists'"))
}

func (s *testSuite6) TestCreateView(c *C) {
Expand Down Expand Up @@ -253,6 +260,13 @@ func (s *testSuite6) TestCreateView(c *C) {
tk.MustExec("drop view v")
tk.MustExec("create view v as (select * from t1 union select * from t2)")
tk.MustExec("drop view v")

// test for drop if exists.
Comment thread
0xPoe marked this conversation as resolved.
Outdated
tk.MustExec("drop view if exists v_if_exists;")
tk.MustQuery("show warnings;").Check(testkit.Rows("Note 1051 Unknown table 'test.v_if_exists'"))
tk.MustExec("create view v1_if_exists as (select * from t1)")
tk.MustExec("drop view if exists v1_if_exists,v2_if_exists,v3_if_exists")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Note|1051|Unknown table 'test.v2_if_exists'", "Note|1051|Unknown table 'test.v3_if_exists'"))
}

func (s *testSuite6) TestCreateDropDatabase(c *C) {
Expand Down
6 changes: 5 additions & 1 deletion server/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"sync/atomic"
"time"

dmysql "github.com/go-sql-driver/mysql"
. "github.com/pingcap/check"
"github.com/pingcap/failpoint"
zaplog "github.com/pingcap/log"
Expand Down Expand Up @@ -927,7 +928,10 @@ func (ts *HTTPHandlerTestSuite) TestPostSettings(c *C) {
c.Assert(atomic.LoadUint32(&variable.DDLSlowOprThreshold), Equals, uint32(200))

// test check_mb4_value_in_utf8
db, err := sql.Open("mysql", ts.getDSN())
overriders := []configOverrider{func(config *dmysql.Config) {
config.Strict = false
}}
db, err := sql.Open("mysql", ts.getDSN(overriders...))
c.Assert(err, IsNil, Commentf("Error connecting"))
defer db.Close()
dbt := &DBTest{c, db}
Expand Down
8 changes: 6 additions & 2 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,9 @@ func (cli *testServerClient) runTestLoadData(c *C, server *Server) {

func (cli *testServerClient) runTestConcurrentUpdate(c *C) {
dbName := "Concurrent"
cli.runTestsOnNewDB(c, nil, dbName, func(dbt *DBTest) {
cli.runTestsOnNewDB(c, func(config *mysql.Config) {
config.Strict = false
}, dbName, func(dbt *DBTest) {
dbt.mustExec("drop table if exists test2")
dbt.mustExec("create table test2 (a int, b int)")
dbt.mustExec("insert test2 values (1, 1)")
Expand Down Expand Up @@ -1014,7 +1016,9 @@ func (cli *testServerClient) runTestDBNameEscape(c *C) {
}

func (cli *testServerClient) runTestResultFieldTableIsNull(c *C) {
cli.runTestsOnNewDB(c, nil, "ResultFieldTableIsNull", func(dbt *DBTest) {
cli.runTestsOnNewDB(c, func(config *mysql.Config) {
config.Strict = false
}, "ResultFieldTableIsNull", func(dbt *DBTest) {
dbt.mustExec("drop table if exists test;")
dbt.mustExec("create table test (c int);")
dbt.mustExec("explain select * from test;")
Expand Down