Skip to content

Commit

Permalink
fix(spanner/spansql): Add tests for INSERT parsing (#6303)
Browse files Browse the repository at this point in the history
Fix bug where 'INSERT' statement was generated incorrectly
  • Loading branch information
jamesrom committed Jul 5, 2022
1 parent f72abfe commit 0d19fb5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions spanner/spansql/parser_test.go
Expand Up @@ -312,6 +312,13 @@ func TestParseDMLStmt(t *testing.T) {
Input: Values{{IntegerLiteral(1), StringLiteral("Marc"), StringLiteral("Richards")}},
},
},
{"INSERT INTO Singers (SingerId, FirstName, LastName) VALUES (1, 'Marc', 'Richards')",
&Insert{
Table: "Singers",
Columns: []ID{ID("SingerId"), ID("FirstName"), ID("LastName")},
Input: Values{{IntegerLiteral(1), StringLiteral("Marc"), StringLiteral("Richards")}},
},
},
{"INSERT Singers (SingerId, FirstName, LastName) SELECT * FROM UNNEST ([1, 2, 3]) AS data",
&Insert{
Table: "Singers",
Expand Down
3 changes: 2 additions & 1 deletion spanner/spansql/sql.go
Expand Up @@ -157,6 +157,7 @@ func (rrdp ReplaceRowDeletionPolicy) SQL() string {
func (drdp DropRowDeletionPolicy) SQL() string {
return "DROP ROW DELETION POLICY"
}

func (sct SetColumnType) SQL() string {
str := sct.Type.SQL()
if sct.NotNull {
Expand Down Expand Up @@ -261,7 +262,7 @@ func (u *Update) SQL() string {
}

func (i *Insert) SQL() string {
str := "INSERT " + i.Table.SQL() + " INTO ("
str := "INSERT INTO " + i.Table.SQL() + " ("
for i, column := range i.Columns {
if i > 0 {
str += ", "
Expand Down
9 changes: 9 additions & 0 deletions spanner/spansql/sql_test.go
Expand Up @@ -411,6 +411,15 @@ func TestSQL(t *testing.T) {
"ALTER DATABASE dbname SET OPTIONS (optimizer_version=null, version_retention_period=null, enable_key_visualizer=null)",
reparseDDL,
},
{
&Insert{
Table: "Singers",
Columns: []ID{ID("SingerId"), ID("FirstName"), ID("LastName")},
Input: Values{{IntegerLiteral(1), StringLiteral("Marc"), StringLiteral("Richards")}},
},
`INSERT INTO Singers (SingerId, FirstName, LastName) VALUES (1, "Marc", "Richards")`,
reparseDML,
},
{
&Delete{
Table: "Ta",
Expand Down

0 comments on commit 0d19fb5

Please sign in to comment.