Skip to content

Commit

Permalink
fix sqlserver named parameter tokenization (#40)
Browse files Browse the repository at this point in the history
* fix sqlserver named parameter

* fix test
  • Loading branch information
lu-zhengda authored Oct 24, 2024
1 parent 9117b42 commit 8c03f53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions obfuscate_and_normalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,20 @@ multiline comment */
Size: 11,
},
},
{
input: `DELETE FROM [discount] WHERE [description]=@1`,
expected: `DELETE FROM discount WHERE description = @1`,
statementMetadata: StatementMetadata{
Tables: []string{"discount"},
Comments: []string{},
Commands: []string{"DELETE"},
Procedures: []string{},
Size: 14,
},
lexerOpts: []lexerOption{
WithDBMS(DBMSSQLServer),
},
},
}

obfuscator := NewObfuscator(
Expand Down
2 changes: 1 addition & 1 deletion sqllexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (s *Lexer) scanWhitespace() Token {
func (s *Lexer) scanOperator(lastCh rune) Token {
s.start = s.cursor
ch := s.next()
for isOperator(ch) && !(lastCh == '=' && ch == '?') {
for isOperator(ch) && !(lastCh == '=' && (ch == '?' || ch == '@')) {
// hack: we don't want to treat "=?" as an single operator
lastCh = ch
ch = s.next()
Expand Down

0 comments on commit 8c03f53

Please sign in to comment.