diff --git a/go/vt/sqlparser/ast.go b/go/vt/sqlparser/ast.go index 235142c77b4..cc512c7096e 100644 --- a/go/vt/sqlparser/ast.go +++ b/go/vt/sqlparser/ast.go @@ -2674,7 +2674,7 @@ func (ct *ColumnType) merge(other ColumnType) error { if other.KeyOpt != colKeyNone { keyOptions := []ColumnKeyOption{ct.KeyOpt, other.KeyOpt} - sort.Slice(keyOptions, func(i, j int) bool {return keyOptions[i] < keyOptions[j]}) + sort.Slice(keyOptions, func(i, j int) bool { return keyOptions[i] < keyOptions[j] }) if other.KeyOpt == ct.KeyOpt { // MySQL will deduplicate key options when they are repeated. } else if keyOptions[0] == colKeyPrimary && (keyOptions[1] == colKeyUnique || keyOptions[1] == colKeyUniqueKey) { @@ -4789,7 +4789,7 @@ func (*ConvertExpr) iExpr() {} func (*SubstrExpr) iExpr() {} func (*TrimExpr) iExpr() {} func (*ConvertUsingExpr) iExpr() {} -func (*CharExpr) iExpr() {} +func (*CharExpr) iExpr() {} func (*MatchExpr) iExpr() {} func (*GroupConcatExpr) iExpr() {} func (*Default) iExpr() {} @@ -6895,6 +6895,15 @@ func (node *TableFuncExpr) UnmarshalJSON(b []byte) error { return nil } +func (node *TableFuncExpr) walkSubtree(visit Visit) error { + if node == nil { + return nil + } + return Walk( + visit, + node.Exprs) +} + // TableIdent is a case sensitive SQL identifier. It will be escaped with // backquotes if necessary. type TableIdent struct { diff --git a/go/vt/sqlparser/sql_test.go b/go/vt/sqlparser/sql_test.go index c5163b9153d..1437807e293 100644 --- a/go/vt/sqlparser/sql_test.go +++ b/go/vt/sqlparser/sql_test.go @@ -323,22 +323,39 @@ func TestDropIndex(t *testing.T) { testIndex(t, tests) } -// TestShowTablePrepared tests that Vitess can correctly walk all the SQLVal instances -// in a parsed SHOW TABLES statement to identify the bound variables. -func TestShowTablePrepared(t *testing.T) { - statement, err := Parse("SHOW TABLES FROM `mydb` WHERE `Tables_in_mydb` = ?") - require.NoError(t, err) - paramsCount := uint16(0) - _ = Walk(func(node SQLNode) (bool, error) { - switch node := node.(type) { - case *SQLVal: - if strings.HasPrefix(string(node.Val), ":v") { - paramsCount++ - } - } - return true, nil - }, statement) - assert.Equal(t, uint16(1), paramsCount) +// TestWalkPrepared tests that Vitess can correctly walk all the SQLVal instances +// in a parsed statement to identify the bound variables. +func TestWalkPrepared(t *testing.T) { + tests := []struct { + q string + paramCnt int + }{ + { + q: "SHOW TABLES FROM `mydb` WHERE `Tables_in_mydb` = ?", + paramCnt: 1, + }, + { + q: "select * from table_function(?,?)", + paramCnt: 2, + }, + } + for _, tt := range tests { + t.Run(fmt.Sprintf("prepare param count: %s", tt.q), func(t *testing.T) { + statement, err := Parse(tt.q) + require.NoError(t, err) + paramsCount := uint16(0) + _ = Walk(func(node SQLNode) (bool, error) { + switch node := node.(type) { + case *SQLVal: + if strings.HasPrefix(string(node.Val), ":v") { + paramsCount++ + } + } + return true, nil + }, statement) + assert.Equal(t, uint16(tt.paramCnt), paramsCount) + }) + } } func TestShowIndex(t *testing.T) {