From cea7e0817e48b6e55ffe601b788fbbbbf271ae4f Mon Sep 17 00:00:00 2001 From: qiuyesuifeng Date: Wed, 23 Sep 2015 11:21:48 +0800 Subject: [PATCH] *: WIP-fix issue 234. --- parser/parser.y | 13 +++++++++++-- parser/parser_test.go | 14 ++++++++++++++ tidb_test.go | 13 +++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/parser/parser.y b/parser/parser.y index a5b208a41c..c190ef66ea 100644 --- a/parser/parser.y +++ b/parser/parser.y @@ -344,6 +344,7 @@ import ( DeleteFromStmt "DELETE FROM statement" DistinctOpt "Distinct option" DoStmt "Do statement" + DropDatabase "DROP {DATABASE | SCHEMA}" DropDatabaseStmt "DROP DATABASE statement" DropIndexStmt "DROP INDEX statement" DropTableStmt "DROP TABLE statement" @@ -1134,6 +1135,7 @@ DefaultOpt: DefaultKwdOpt: {} | "DEFAULT" + /****************************************************************** * Do statement * See: https://dev.mysql.com/doc/refman/5.7/en/do.html @@ -1218,11 +1220,18 @@ DeleteFromStmt: } } +DropDatabase: + "DROP" "DATABASE" + { + } +| "DROP" "SCHEMA" + { + } DropDatabaseStmt: - "DROP" "DATABASE" IfExists Identifier + DropDatabase IfExists DBName { - $$ = &stmts.DropDatabaseStmt{IfExists: $3.(bool), Name: $4.(string)} + $$ = &stmts.DropDatabaseStmt{IfExists: $2.(bool), Name: $3.(string)} if yylex.(*lexer).root { break } diff --git a/parser/parser_test.go b/parser/parser_test.go index b7b41bac7b..eda828ce7e 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -350,6 +350,20 @@ func (s *testParserSuite) TestParser0(c *C) { {"show collation", true}, {"show collation like 'utf8%'", true}, {"show collation where Charset = 'utf8' and Collation = 'utf8_bin'", true}, + + // For drop datbase/schema + {"create database xxx", true}, + {"create database if exists xxx", false}, + {"create database if not exists xxx", true}, + {"create schema xxx", true}, + {"create schema if exists xxx", false}, + {"create schema if not exists xxx", true}, + {"drop database xxx", true}, + {"drop database if exists xxx", true}, + {"drop database if not exists xxx", false}, + {"drop schema xxx", true}, + {"drop schema if exists xxx", true}, + {"drop schema if not exists xxx", false}, } for _, t := range table { diff --git a/tidb_test.go b/tidb_test.go index 14c915db20..989b149cbc 100644 --- a/tidb_test.go +++ b/tidb_test.go @@ -859,6 +859,19 @@ func (s *testSessionSuite) TestBootstrap(c *C) { mustExecSQL(c, se, "USE test;") } +func (s *testSessionSuite) TestDatabase(c *C) { + store := newStore(c, s.dbName) + se := newSession(c, store, s.dbName) + + mustExecSQL(c, se, "create database xxx") + mustExecSQL(c, se, "use xxx") + mustExecSQL(c, se, "drop database xxx") + + mustExecSQL(c, se, "create schema xxx") + mustExecSQL(c, se, "use xxx") + mustExecSQL(c, se, "drop schema xxx") +} + func newSession(c *C, store kv.Storage, dbName string) Session { se, err := CreateSession(store) c.Assert(err, IsNil)