Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ALTER DATABASE parsing #199

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1488,11 +1488,15 @@ type DBDDL struct {
// Format formats the node.
func (node *DBDDL) Format(buf *TrackedBuffer) {
switch node.Action {
case CreateStr:
case CreateStr, AlterStr:
exists := ""
if node.IfNotExists {
exists = " if not exists"
}
dbname := ""
if len(node.DBName) > 0 {
dbname = fmt.Sprintf(" %s", node.DBName)
}
charsetCollateStr := ""
for _, obj := range node.CharsetCollate {
typeStr := strings.ToLower(obj.Type)
Expand All @@ -1503,7 +1507,7 @@ func (node *DBDDL) Format(buf *TrackedBuffer) {
charsetCollateStr += fmt.Sprintf("%s %s %s", charsetDef, typeStr, obj.Value)
}

buf.WriteString(fmt.Sprintf("%s database%s %s%s", node.Action, exists, node.DBName, charsetCollateStr))
buf.WriteString(fmt.Sprintf("%s database%s%s%s", node.Action, exists, dbname, charsetCollateStr))
case DropStr:
exists := ""
if node.IfExists {
Expand Down
12 changes: 12 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2098,6 +2098,18 @@ var (
}, {
input: "create database if not exists test_db",
output: "create database if not exists test_db",
}, {
input: "alter database test_db character set utf8mb3",
}, {
input: "alter database test_db collate utf8mb3_bin",
}, {
input: "alter database test_db character set utf8mb3 collate utf8mb3_bin",
}, {
input: "alter database character set utf8mb3",
}, {
input: "alter database collate utf8mb3_bin",
}, {
input: "alter database character set utf8mb3 collate utf8mb3_bin",
}, {
input: "drop database test_db",
}, {
Expand Down
Loading