Skip to content

Commit 91fab73

Browse files
authored
internal/parser: Error if last query is missing (#325)
If the last query in the file does not have a semicolon, return an error
1 parent 1160609 commit 91fab73

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

internal/dinosql/parser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ func parseQuery(c core.Catalog, stmt nodes.Node, source string) (*Query, error)
436436
if err != nil {
437437
return nil, err
438438
}
439+
if rawSQL == "" {
440+
return nil, errors.New("missing semicolon at end of file")
441+
}
439442
if err := validateFuncCall(&c, raw); err != nil {
440443
return nil, err
441444
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE foo (email text not null);
2+
3+
-- name: FirstQuery :many
4+
SELECT * FROM foo;
5+
6+
-- name: SecondQuery :many
7+
SELECT * FROM foo WHERE email = $1
8+
9+
-- stderr
10+
-- # package querytest
11+
-- query.sql:7:1: missing semicolon at end of file
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": "1",
3+
"packages": [{
4+
"path": "go",
5+
"name": "querytest",
6+
"schema": "query.sql",
7+
"queries": "query.sql"
8+
}]
9+
}

0 commit comments

Comments
 (0)