Skip to content

Commit

Permalink
fix spansql: CREATE PROTO BUNDLE SQL with 0 types
Browse files Browse the repository at this point in the history
Fix a bug in CreateProtoBundle.SQL() which unintentionally generated the
DDL when there were no types listed:
```
CREATE PROTO BUNDLE (``)
```
  • Loading branch information
dfinkel committed Dec 12, 2024
1 parent fcbf256 commit 8301123
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion spanner/spansql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ func (ci CreateIndex) SQL() string {
}

func (cp CreateProtoBundle) SQL() string {
typeList := ""
if len(cp.Types) > 0 {
typeList = "`" + strings.Join(cp.Types, "`, `") + "`"
}
// Backtick-quote all the types so we don't need to check for SQL keywords
return "CREATE PROTO BUNDLE (`" + strings.Join(cp.Types, "`, `") + "`)"
return "CREATE PROTO BUNDLE (" + typeList + ")"
}

func (cv CreateView) SQL() string {
Expand Down
8 changes: 8 additions & 0 deletions spanner/spansql/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,14 @@ func TestSQL(t *testing.T) {
"CREATE PROTO BUNDLE (`a.b.c`, `b.d.e`)",
reparseDDL,
},
{
&CreateProtoBundle{
Types: []string(nil),
Position: line(1),
},
"CREATE PROTO BUNDLE ()",
reparseDDL,
},
{
&CreateProtoBundle{
Types: []string{"a"},
Expand Down

0 comments on commit 8301123

Please sign in to comment.