Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort params named_matches by len #60

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pyrqlite/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _substitute_params(self, operation, parameters):
param_matches = 0

qmark_re = re.compile(r"(\?)")
named_re = re.compile(r"(:{1}[a-zA-Z]+?\b)")
named_re = re.compile(r"(:{1}[a-zA-Z_]+?\b)")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could also support $ since I found this:
https://github.com/sqlite/sqlite/blob/master/test/e_expr.test#L546

Identifiers in SQLite consist of alphanumeric, '_' and '$' characters

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we could possibly support @ instead of colon:
https://github.com/sqlite/sqlite/blob/master/test/e_expr.test#L559


qmark_matches = qmark_re.findall(operation)
named_matches = named_re.findall(operation)
Expand All @@ -123,7 +123,7 @@ def _substitute_params(self, operation, parameters):
raise ProgrammingError('Unamed binding used, but you supplied '
'a dictionary (which has only names): '
'%s %s' % (operation, parameters))
for op_key in named_matches:
for op_key in sorted(named_matches, key=len, reverse=True):
try:
operation = operation.replace(op_key,
_adapt_from_python(parameters[op_key[1:]]))
Expand Down