Skip to content

Commit

Permalink
Merge pull request #199 from dolthub/daylon/db-collation
Browse files Browse the repository at this point in the history
Added ALTER DATABASE parsing
  • Loading branch information
Hydrocharged authored Oct 31, 2022
2 parents 3d1c547 + ab0143f commit 9aad77e
Show file tree
Hide file tree
Showing 4 changed files with 7,627 additions and 7,592 deletions.
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

0 comments on commit 9aad77e

Please sign in to comment.