Skip to content

Commit 1007c8e

Browse files
committed
sqlite: validate qualified refs in subqueries
Signed-off-by: Amirhossein Akhlaghpour <[email protected]>
1 parent 09775dc commit 1007c8e

File tree

9 files changed

+44
-1
lines changed

9 files changed

+44
-1
lines changed

internal/endtoend/testdata/sqlite_invalid_correlated_ref/sqlite/query.sql renamed to internal/endtoend/testdata/base/sqlite_invalid_correlated_ref/sqlite/query.sql

File renamed without changes.

internal/endtoend/testdata/sqlite_invalid_correlated_ref/sqlite/schema.sql renamed to internal/endtoend/testdata/base/sqlite_invalid_correlated_ref/sqlite/schema.sql

File renamed without changes.

internal/endtoend/testdata/sqlite_invalid_correlated_ref/sqlite/sqlc.yaml renamed to internal/endtoend/testdata/base/sqlite_invalid_correlated_ref/sqlite/sqlc.yaml

File renamed without changes.

internal/endtoend/testdata/sqlite_invalid_correlated_ref/sqlite/stderr.txt renamed to internal/endtoend/testdata/base/sqlite_invalid_correlated_ref/sqlite/stderr.txt

File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# package querytest
2-
query.sql:1:1: sqlite3: SQL logic error: no such column: p.id
2+
query.sql:4:9: table alias "p" does not exist
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- name: GetByPublicID :one
2+
SELECT *
3+
FROM locations l
4+
WHERE l.public_id = ?
5+
AND EXISTS (
6+
SELECT 1
7+
FROM projects p
8+
WHERE p.id = location.project_id
9+
);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CREATE TABLE organizations (
2+
id INTEGER PRIMARY KEY
3+
);
4+
5+
CREATE TABLE organization_members (
6+
id INTEGER PRIMARY KEY,
7+
organization_id INTEGER NOT NULL,
8+
account_id INTEGER NOT NULL
9+
);
10+
11+
CREATE TABLE projects (
12+
id INTEGER PRIMARY KEY,
13+
organization_id INTEGER NOT NULL
14+
);
15+
16+
CREATE TABLE locations (
17+
id INTEGER PRIMARY KEY,
18+
public_id TEXT UNIQUE NOT NULL,
19+
project_id INTEGER NOT NULL
20+
) STRICT;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: "2"
2+
3+
sql:
4+
- engine: "sqlite"
5+
schema: "schema.sql"
6+
queries: "query.sql"
7+
rules:
8+
- sqlc/db-prepare
9+
gen:
10+
go:
11+
package: "db"
12+
out: "generated"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# package db
2+
query.sql:8:18: table alias "location" does not exist

0 commit comments

Comments
 (0)