Skip to content

Commit d44a092

Browse files
EliSauderCopilot
andcommitted
test(mssql): clarify variable scanning
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d1d16c9 commit d44a092

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎internal/sql/preprocess/scan.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ func (l *lexer) scan(start, end int) []occurrence {
3333
}
3434
i = j
3535

36-
// @@name is a system function, such as SQL Server's @@ROWCOUNT.
36+
// A parameter starts with @ followed by an identifier. The second @
37+
// in a T-SQL system variable such as @@ROWCOUNT must not start one.
3738
case c == '@' && l.d.AtSign && isIdentStart(l.at(i+1)) && l.at(i-1) != '@':
3839
j := l.identEnd(i + 1)
39-
// A SQL Server name goes on through #, $ and @, so @a and @a#b
40-
// are two parameters.
40+
// T-SQL parameter names may also contain #, $, and @ after the
41+
// first identifier character.
4142
for l.d.Style == StyleAt && j < len(l.src) && (isIdentPart(l.src[j]) || strings.IndexByte("#$@", l.src[j]) >= 0) {
4243
j++
4344
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SELECT id FROM users WHERE id = @a AND parent = @a#b AND other = @a$c;
1+
SELECT id FROM users WHERE id = @a AND parent = @a#b AND other = @a$c AND related = @a@b;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SELECT id FROM users WHERE id = @a AND parent = @a#b AND other = @a$c;
1+
SELECT id FROM users WHERE id = @a AND parent = @a#b AND other = @a$c AND related = @a@b;

‎internal/sql/preprocess/testdata/mssql/names_with_hash/side_table.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"start": 0,
4-
"end": 70,
4+
"end": 89,
55
"dollar": true,
66
"params": [
77
{
@@ -24,6 +24,13 @@
2424
"origin": 65,
2525
"name": "a$c",
2626
"named": true
27+
},
28+
{
29+
"number": 4,
30+
"location": 84,
31+
"origin": 84,
32+
"name": "a@b",
33+
"named": true
2734
}
2835
]
2936
}

0 commit comments

Comments
 (0)