Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 13 additions & 6 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ type (

// DBDDL represents a CREATE, DROP, or ALTER database statement.
DBDDL struct {
Action string
DBName string
IfExists bool
Collate string
Charset string
Action string
DBName string
IfExists bool
IfNotExists bool
Collate string
Charset string
}

// DDL represents a CREATE, ALTER, DROP, RENAME, TRUNCATE or ANALYZE statement.
Expand Down Expand Up @@ -991,7 +992,13 @@ func (node *SetTransaction) Format(buf *TrackedBuffer) {
// Format formats the node.
func (node *DBDDL) Format(buf *TrackedBuffer) {
switch node.Action {
case CreateStr, AlterStr:
case CreateStr:
notExists := ""
if node.IfNotExists {
notExists = " if not exists"
}
buf.WriteString(fmt.Sprintf("%s database%s %v", node.Action, notExists, node.DBName))
case AlterStr:
buf.WriteString(fmt.Sprintf("%s database %s", node.Action, node.DBName))
case DropStr:
exists := ""
Expand Down
9 changes: 5 additions & 4 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1610,16 +1610,17 @@ var (
input: "create schema test_db",
output: "create database test_db",
}, {
input: "create database if not exists test_db",
output: "create database test_db",
input: "create database if not exists test_db",
}, {
input: "create schema if not exists test_db",
output: "create database if not exists test_db",
}, {
input: "drop database test_db",
}, {
input: "drop schema test_db",
output: "drop database test_db",
}, {
input: "drop database if exists test_db",
output: "drop database test_db",
input: "drop database if exists test_db",
}, {
input: "delete a.*, b.* from tbl_a a, tbl_b b where a.id = b.id and b.name = 'test'",
output: "delete a, b from tbl_a as a, tbl_b as b where a.id = b.id and b.name = 'test'",
Expand Down
Loading