Fix binding of explicitly numbered parameters#1032
Open
mvduin wants to merge 2 commits intoWiseLibs:masterfrom
Open
Fix binding of explicitly numbered parameters#1032mvduin wants to merge 2 commits intoWiseLibs:masterfrom
mvduin wants to merge 2 commits intoWiseLibs:masterfrom
Conversation
e.g. db.prepare('SELECT ?3, ?2, ?1').get(1, 2, 3)
|
What's preventing this from being merged? I'm working on improving parameter handling in a library I use that depends on better-sqlite3, and this bug has unfortunately become a blocker. |
s5bug
added a commit
to s5bug/porcupine
that referenced
this pull request
Mar 23, 2024
creates a binding dictionary explicitly on JS, zipping the arguments with their index and binding str(idx+1) to the argument
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.
Parameters of the form
?1,?2, etc aren't named parameters, you're explicitly specifying the parameter index, allowing indexed (i.e. unnamed) parameters to be explicitly ordered, reused, or skipped. Somewhat oddly however sqlite still reports their name* fromsqlite3_bind_parameter_name, causing better-sqlite3 to force it to be passed by name which is not what's expected or desired.(* or rather their first name, e.g.
SELECT ?01, ?1, ?001has a single parameter whose reported name is?01though I don't think sqlite documents which of the three names is returned in this case.)This patch-set fixes this and adds some tests for explicitly numbered parameters (there were none whatsoever).
The reason I care about explicitly numbered parameters is because I'm using tagged templates for queries, and using explicit numbering allows this to be much more robust against e.g. parts of the query being comments out. Here's a highly simplified minimalistic demo of this concept:
output: