Skip to content
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
13 changes: 13 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"strings"
Expand Down Expand Up @@ -58,6 +59,9 @@ func Parse(sql string) (Statement, error) {
}
return nil, vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, tokenizer.LastError.Error())
}
if tokenizer.ParseTree == nil {
return nil, ErrEmpty
}
return tokenizer.ParseTree, nil
}

Expand All @@ -68,6 +72,9 @@ func ParseStrictDDL(sql string) (Statement, error) {
if yyParse(tokenizer) != 0 {
return nil, tokenizer.LastError
}
if tokenizer.ParseTree == nil {
return nil, ErrEmpty
}
return tokenizer.ParseTree, nil
}

Expand All @@ -94,9 +101,15 @@ func ParseNext(tokenizer *Tokenizer) (Statement, error) {
}
return nil, tokenizer.LastError
}
if tokenizer.ParseTree == nil {
return ParseNext(tokenizer)
}
return tokenizer.ParseTree, nil
}

// ErrEmpty is a sentinel error returned when parsing empty statements.
var ErrEmpty = errors.New("empty statement")

// SplitStatement returns the first sql statement up to either a ; or EOF
// and the remainder from the given buffer
func SplitStatement(blob string) (string, string, error) {
Expand Down
3 changes: 3 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,9 @@ func TestConvert(t *testing.T) {
}, {
input: "select convert('abc', decimal(4+9)) from t",
output: "syntax error at position 33",
}, {
input: "/* a comment */",
output: "empty statement",
}}

for _, tcase := range invalidSQL {
Expand Down
Loading