Refactored Rebind() so that it respects escaped ?'s #768
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 PR addresses a
FIXME
comment I found next to theRebind()
function.Summary of changes
Rebind()
to respect?
that are properly escaped as part of a string using single or double quotes.Rebind()
unit tests fromsqlx_test.go
tobind_test.go
Rebind()
unit tests to run along side the new unit tests.Rebind()
benchmarks tobind_test.go
and combined them into a single benchmark function with sub-benchmarks.Valid Escaped ?'s
Because of the cross DBMS nature of
Rebind()
there are some ways to escape a character or string in Postgres, SQL Server, etc. that don't make sense to implement because they are not supported by all DBMS's.This version of
Rebind()
respects two kinds of escaped question marks: string constants, and quoted identifiers. Double an single quotes that are inside a string constant or quoted identifier can be escaped by using a C style backslash e.g.\"
or by using a two quotation marks e.g.""
String Constants
A
?
that is part of a valid string constant i.e. surrounded by single quotes is not replaced with a parameter placeholder e.g.$1
.Examples of string constant escaped
?
:Quoted Identifiers
A
?
that is part of a valid quoted or delimited identifier i.e. surrounded by double quotes is not replaced with a parameter placeholder.Examples of quoted identifier escaped
?
:None of the question marks in the above examples will be replaced with a parameter placeholder.
Benchmarks
This new version of
Rebind()
is slower than the previousstrings.Index
version. However, it is faster than thebytes.Buffer
version.Issues
This should fix #487