Skip to content

Commit e465d0b

Browse files
authored
fix(engine/sqlite): fix grammer to avoid missing join_constraint (#2732)
close #2729 ANTLR's API has difficulty handling the case where there is no join_constraint corresponding to join_operator in join_clause, so an empty join_constraint is accepted. It is defined as such in the sqlite documentation. https://www.sqlite.org/syntax/join-clause.html https://www.sqlite.org/syntax/join-constraint.html
1 parent 79cb8b5 commit e465d0b

File tree

13 files changed

+1328
-1141
lines changed

13 files changed

+1328
-1141
lines changed

internal/endtoend/testdata/join_where_clause/mysql/go/query.sql.go

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/join_where_clause/mysql/query.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ WHERE owner = ?;
1111
SELECT foo.*
1212
FROM foo
1313
JOIN bar ON bar.id = ?
14-
WHERE owner = ?;
14+
WHERE owner = ?;
15+
16+
-- name: JoinNoConstraints :many
17+
SELECT foo.*
18+
FROM foo
19+
CROSS JOIN bar
20+
WHERE bar.id = ? AND owner = ?;

internal/endtoend/testdata/join_where_clause/postgresql/pgx/v4/go/query.sql.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/join_where_clause/postgresql/pgx/v4/query.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ WHERE owner = $1;
1111
SELECT foo.*
1212
FROM foo
1313
JOIN bar ON bar.id = $2
14-
WHERE owner = $1;
14+
WHERE owner = $1;
15+
16+
-- name: JoinNoConstraints :many
17+
SELECT foo.*
18+
FROM foo
19+
CROSS JOIN bar
20+
WHERE bar.id = $2 AND owner = $1;

internal/endtoend/testdata/join_where_clause/postgresql/pgx/v5/go/query.sql.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/join_where_clause/postgresql/pgx/v5/query.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ WHERE owner = $1;
1111
SELECT foo.*
1212
FROM foo
1313
JOIN bar ON bar.id = $2
14-
WHERE owner = $1;
14+
WHERE owner = $1;
15+
16+
-- name: JoinNoConstraints :many
17+
SELECT foo.*
18+
FROM foo
19+
CROSS JOIN bar
20+
WHERE bar.id = $2 AND owner = $1;

internal/endtoend/testdata/join_where_clause/postgresql/stdlib/go/query.sql.go

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/join_where_clause/postgresql/stdlib/query.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ WHERE owner = $1;
1111
SELECT foo.*
1212
FROM foo
1313
JOIN bar ON bar.id = $2
14-
WHERE owner = $1;
14+
WHERE owner = $1;
15+
16+
-- name: JoinNoConstraints :many
17+
SELECT foo.*
18+
FROM foo
19+
CROSS JOIN bar
20+
WHERE bar.id = $2 AND owner = $1;

internal/endtoend/testdata/join_where_clause/sqlite/go/query.sql.go

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/join_where_clause/sqlite/query.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ WHERE owner = ?;
1111
SELECT foo.*
1212
FROM foo
1313
JOIN bar ON bar.id = ?
14-
WHERE owner = ?;
14+
WHERE owner = ?;
15+
16+
-- name: JoinNoConstraints :many
17+
SELECT foo.*
18+
FROM foo
19+
CROSS JOIN bar
20+
WHERE bar.id = ? AND owner = ?;

internal/engine/sqlite/parser/SQLiteParser.g4

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ select_stmt:
398398
;
399399

400400
join_clause:
401-
table_or_subquery (join_operator table_or_subquery join_constraint?)*
401+
table_or_subquery (join_operator table_or_subquery join_constraint)*
402402
;
403403

404404
select_core:
@@ -454,8 +454,8 @@ join_operator:
454454
;
455455

456456
join_constraint:
457-
ON_ expr
458-
| USING_ OPEN_PAR column_name ( COMMA column_name)* CLOSE_PAR
457+
(ON_ expr
458+
| USING_ OPEN_PAR column_name ( COMMA column_name)* CLOSE_PAR)?
459459
;
460460

461461
compound_operator:

internal/engine/sqlite/parser/SQLiteParser.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)