Skip to content

Commit dc51324

Browse files
committed
preprocess: cover every sqlc syntax shape used in internal/endtoend
Audited every .sql file in internal/endtoend (and examples/), grouping each sqlc.* call by engine, function and argument shape, then diffed that inventory against the preprocessor's testdata. Seventeen shapes the corpus relies on had no golden. They all behaved correctly; they just were not pinned. The ones that exercise a distinct code path: - MySQL reads "x" as a string, so a double-quoted argument names the parameter and keeps its case, unlike a bare reference which is folded (coalesce_params/mysql, overrides_go_types/mysql) - $1 is not a placeholder in MySQL and is left alone (create_view/mysql) - "-- @sqlc-vet-disable" is a vet directive in a PostgreSQL query file, where @name *is* sqlc syntax; it survives only because the lexer never looks inside a comment (vet_disable) - PostgreSQL's @> operator next to a string holding a $-path, with a cast on the argument (table_function/postgresql) The rest fill in per-engine shapes: string-constant arguments for narg and slice on PostgreSQL and SQLite, narg against a bare reference on MySQL and SQLite, and the four invalid-call errors on MySQL and SQLite, where the reported text is dialect-specific ('got "?"' rather than 'got "$1"'). Also adds cases for the string-constant forms that had only one golden between them: case preservation against a folded bare reference, an escaped quote inside the name, and sqlc.embed('t'). 76 cases in total. Every sqlc syntax shape in the corpus now has a preprocessor test for its engine. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015BSM9xGoosq58r1Mz6B7YP
1 parent 7fcad42 commit dc51324

54 files changed

Lines changed: 457 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎internal/sql/preprocess/CLAUDE.md‎

Lines changed: 7 additions & 0 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT * FROM second_view WHERE val2 = $1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT * FROM second_view WHERE val2 = $1;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"start": 0,
4+
"end": 42,
5+
"dollar": true
6+
}
7+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT
2+
(CASE WHEN sqlc.arg("Timezone") = "calendar" THEN cal.Timezone ELSE sqlc.arg("Timezone") END),
3+
COALESCE(sqlc.narg("calName"), "")
4+
FROM Calendar cal;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT
2+
(CASE WHEN ? = "calendar" THEN cal.Timezone ELSE ? END),
3+
COALESCE(?, "")
4+
FROM Calendar cal;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[
2+
{
3+
"start": 0,
4+
"end": 106,
5+
"dollar": true,
6+
"params": [
7+
{
8+
"number": 1,
9+
"location": 22,
10+
"origin": 22,
11+
"name": "Timezone",
12+
"named": true
13+
},
14+
{
15+
"number": 2,
16+
"location": 60,
17+
"origin": 79,
18+
"name": "Timezone",
19+
"named": true
20+
},
21+
{
22+
"number": 3,
23+
"location": 81,
24+
"origin": 119,
25+
"name": "calName",
26+
"named": true,
27+
"nullable": true
28+
}
29+
]
30+
}
31+
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- name: WrongFunc :one
2+
SELECT id FROM users WHERE id = sqlc.argh(target_id);
3+
4+
-- name: TooManyArgs :one
5+
SELECT id FROM users WHERE id = sqlc.arg('foo', 'bar');
6+
7+
-- name: TooFewArgs :one
8+
SELECT id FROM users WHERE id = sqlc.arg();
9+
10+
-- name: InvalidArgPlaceholder :one
11+
SELECT id FROM users WHERE id = sqlc.arg(?);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- name: WrongFunc :one
2+
SELECT id FROM users WHERE id = sqlc.argh(target_id);
3+
4+
-- name: TooManyArgs :one
5+
SELECT id FROM users WHERE id = sqlc.arg('foo', 'bar');
6+
7+
-- name: TooFewArgs :one
8+
SELECT id FROM users WHERE id = sqlc.arg();
9+
10+
-- name: InvalidArgPlaceholder :one
11+
SELECT id FROM users WHERE id = sqlc.arg(?);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[
2+
{
3+
"start": 0,
4+
"end": 77,
5+
"dollar": true,
6+
"error": "function \"sqlc.argh\" does not exist",
7+
"error_at": 56
8+
},
9+
{
10+
"start": 77,
11+
"end": 160,
12+
"dollar": true,
13+
"error": "expected 1 parameter to sqlc.arg; got 2",
14+
"error_at": 137
15+
},
16+
{
17+
"start": 160,
18+
"end": 230,
19+
"dollar": true,
20+
"error": "expected 1 parameter to sqlc.arg; got 0",
21+
"error_at": 219
22+
},
23+
{
24+
"start": 230,
25+
"end": 312,
26+
"dollar": true,
27+
"error": "expected parameter to sqlc.arg to be string or reference; got \"?\"",
28+
"error_at": 300
29+
}
30+
]

0 commit comments

Comments
 (0)