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

sqlparser: fix canonical formatting for enums #10149

Merged
merged 2 commits into from
Apr 27, 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
9 changes: 8 additions & 1 deletion go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,14 @@ func (ct *ColumnType) Format(buf *TrackedBuffer) {
}

if ct.EnumValues != nil {
buf.astPrintf(ct, "(%s)", strings.Join(ct.EnumValues, ", "))
buf.WriteString("(")
for i, enum := range ct.EnumValues {
if i > 0 {
buf.WriteString(", ")
}
buf.astPrintf(ct, "%#s", enum)
}
buf.WriteString(")")
}

if ct.Unsigned {
Expand Down
11 changes: 8 additions & 3 deletions go/vt/sqlparser/ast_format_fast.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions go/vt/sqlparser/tracked_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ func TestCanonicalOutput(t *testing.T) {
"alter table t1 row_format=compressed, character set=utf8",
"ALTER TABLE `t1` ROW_FORMAT COMPRESSED, CHARSET utf8",
},
{
"create table a (e enum('red','green','blue','orange','yellow'))",
"CREATE TABLE `a` (\n\t`e` enum('red', 'green', 'blue', 'orange', 'yellow')\n)",
},
{
"create table a (e set('red','green','blue','orange','yellow'))",
"CREATE TABLE `a` (\n\t`e` set('red', 'green', 'blue', 'orange', 'yellow')\n)",
},
}

for _, tc := range testcases {
Expand Down