Skip to content

Commit d03ad5b

Browse files
authored
Fix panic with the invalid SQL (#130)
1 parent b083fa0 commit d03ad5b

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
fetch-depth: '0'
3030

3131
- name: Restore Go Module Cache
32-
uses: actions/cache@v2
32+
uses: actions/cache@v4
3333
with:
3434
path: ~/go/internal/mod
3535
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

parser/parser_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (p *Parser) parseLiteral(pos Pos) (Literal, error) {
274274
// accept the NULL keyword
275275
return &NullLiteral{NullPos: pos}, nil
276276
default:
277-
return nil, fmt.Errorf("expected <int>, <string> or keyword <NULL>, but got %q", p.last().Kind)
277+
return nil, fmt.Errorf("expected <int>, <string> or keyword <NULL>, but got %q", p.lastTokenKind())
278278
}
279279
}
280280

parser/parser_query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (p *Parser) parseJoinTableExpr(_ Pos) (Expr, error) {
214214
StatementEnd: statementEnd,
215215
}, nil
216216
default:
217-
return nil, fmt.Errorf("expected table name or subquery, got %s", p.last().Kind)
217+
return nil, fmt.Errorf("expected table name or subquery, got %s", fmt.Sprintf("%v", p.lastTokenKind()))
218218
}
219219
}
220220

parser/parser_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,14 @@ func validFormatSQL(t *testing.T, sql string) {
127127
}
128128
require.Equal(t, sql, builder.String())
129129
}
130+
131+
func TestParser_InvalidSyntax(t *testing.T) {
132+
invalidSQLs := []string{
133+
"SELECT * FROM",
134+
}
135+
for _, sql := range invalidSQLs {
136+
parser := NewParser(sql)
137+
_, err := parser.ParseStmts()
138+
require.Error(t, err)
139+
}
140+
}

0 commit comments

Comments
 (0)