Skip to content

Commit 916869a

Browse files
EliSauderCopilot
andcommitted
fix(mssql): read a placeholder's name through #, $ and @
SQL Server's names go on through #, $ and @ after the first character, but the preprocessor stopped at them, so @A and @A#b were both read as @A and given one number, and generated code bound only one of them. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 70864b8 commit 916869a

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎internal/sql/preprocess/scan.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func (l *lexer) scan(start, end int) []occurrence {
3636
// @@name is a system function, such as SQL Server's @@ROWCOUNT.
3737
case c == '@' && l.d.AtSign && isIdentStart(l.at(i+1)) && l.at(i-1) != '@':
3838
j := l.identEnd(i + 1)
39+
// A SQL Server name goes on through #, $ and @, so @a and @a#b
40+
// are two parameters.
41+
for l.d.Style == StyleAt && j < len(l.src) && (isIdentPart(l.src[j]) || strings.IndexByte("#$@", l.src[j]) >= 0) {
42+
j++
43+
}
3944
out = append(out, occurrence{
4045
kind: kindArg,
4146
start: i,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT id FROM users WHERE id = @a AND parent = @a#b AND other = @a$c;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT id FROM users WHERE id = @a AND parent = @a#b AND other = @a$c;
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": 70,
5+
"dollar": true,
6+
"params": [
7+
{
8+
"number": 1,
9+
"location": 32,
10+
"origin": 32,
11+
"name": "a",
12+
"named": true
13+
},
14+
{
15+
"number": 2,
16+
"location": 48,
17+
"origin": 48,
18+
"name": "a#b",
19+
"named": true
20+
},
21+
{
22+
"number": 3,
23+
"location": 65,
24+
"origin": 65,
25+
"name": "a$c",
26+
"named": true
27+
}
28+
]
29+
}
30+
]

0 commit comments

Comments
 (0)