Skip to content

Commit

Permalink
For default() - make sure to escape columns when necessary
Browse files Browse the repository at this point in the history
Fixes vitessio#6221

Signed-off-by: Andres Taylor <andres@planetscale.com>

Signed-off-by: deepthi <deepthi@planetscale.com>
  • Loading branch information
systay authored and deepthi committed Jun 16, 2020
1 parent 5245945 commit 77ce19f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,9 @@ func (node *CaseExpr) Format(buf *TrackedBuffer) {
func (node *Default) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "default")
if node.ColName != "" {
buf.astPrintf(node, "(%s)", node.ColName)
buf.WriteString("(")
formatID(buf, node.ColName, strings.ToLower(node.ColName), NoAt)
buf.WriteString(")")
}
}

Expand Down
7 changes: 7 additions & 0 deletions go/vt/sqlparser/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"
"unsafe"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -784,3 +785,9 @@ func TestSplitStatementToPieces(t *testing.T) {
}
}
}

func TestDefaultStatus(t *testing.T) {
assert.Equal(t,
String(&Default{ColName: "status"}),
"default(`status`)")
}
2 changes: 2 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ var (
input: "insert /* bool in on duplicate */ into a values (1, 2, 3) on duplicate key update b = values(a.b), c = d",
}, {
input: "insert /* bool expression on duplicate */ into a values (1, 2) on duplicate key update b = func(a), c = a > d",
}, {
input: "insert into user(username, `status`) values ('Chuck', default(`status`))",
}, {
input: "update /* simple */ a set b = 3",
}, {
Expand Down

0 comments on commit 77ce19f

Please sign in to comment.