Skip to content

Commit 70864b8

Browse files
EliSauderCopilot
andcommitted
fix(mssql): leave sqlc.embed out of the @name check
sqlc.embed names a table, not a parameter, so sqlc.embed("order details") was rejected as an invalid @name. Only sqlc.arg, narg and slice are checked now. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 896a112 commit 70864b8

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

‎internal/sql/preprocess/scan.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ func (l *lexer) sqlcCall(start, afterSqlc int) (occurrence, int, bool) {
140140
return occ, occ.end, true
141141
}
142142
// A dialect that binds @name writes the name into the query, so it has
143-
// to read back as one parameter: @user-id would be a subtraction.
144-
if l.d.Style == StyleAt && !isParamName(name) {
143+
// to read back as one parameter: @user-id would be a subtraction. An
144+
// embed names a table, not a parameter.
145+
if l.d.Style == StyleAt && fn != "embed" && !isParamName(name) {
145146
occ.err = &sqlerr.Error{
146147
Message: fmt.Sprintf("parameter name %q passed to sqlc.%s is not a valid @name; use letters, digits and underscores", name, fn),
147148
Location: start,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT sqlc.embed("order details") FROM [order details] WHERE id = @id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT "order details".* FROM [order details] WHERE id = @id;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"start": 0,
4+
"end": 61,
5+
"dollar": true,
6+
"params": [
7+
{
8+
"number": 1,
9+
"location": 57,
10+
"origin": 67,
11+
"name": "id",
12+
"named": true
13+
}
14+
],
15+
"embeds": [
16+
{
17+
"table": "order details",
18+
"location": 7,
19+
"origin": 7,
20+
"orig": "sqlc.embed(\"order details\")"
21+
}
22+
]
23+
}
24+
]

0 commit comments

Comments
 (0)