fix multiple use of name param in sqlite#267
Merged
Conversation
SockworkOrange
approved these changes
Aug 12, 2025
Collaborator
SockworkOrange
left a comment
There was a problem hiding this comment.
Looks good:) Had one comment, but no critical. Can take in a differnt PR
| { | ||
| var areArgumentsNumbered = new Regex($@"\?\d\b*").IsMatch(query.Text); | ||
| // Regex to detect numbered parameters like ?1, ?2 | ||
| var areArgumentsNumbered = new Regex(@"\?\d+\b").IsMatch(query.Text); |
Collaborator
There was a problem hiding this comment.
you can extract the regex to a partial static class, like in one of the other drivers. See here for example. We can fix in another PR though
Collaborator
Author
There was a problem hiding this comment.
cool, let's improve on the next PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors the
TransformQueryTextmethod inSqliteDriver.cs. The method is responsible for converting sqlc's parameter syntax (?or?1,?2, etc.) to the named parameter format (@paramName) used byMicrosoft.Data.Sqlite.Key Changes:
The core of this change is an optimization of how both numbered and positional parameters are handled:
Numbered Parameter Handling (
?1,?2):Regexobject on each iteration to replace all instances of a specific numbered placeholder (e.g.,?1). This was inefficient due to repeated regex compilation inside a loop.Regex.Replacecall with aMatchEvaluator. This allows for all numbered placeholders to be replaced in a single pass over the query string.Positional Parameter Handling (
?):Regex.Replaceinside a loop, replacing one placeholder at a time.MatchEvaluatorwith a parameter enumerator, providing a cleaner and more efficient way to handle sequential replacements.