Skip to content

Commit 5cec01c

Browse files
committed
Sort params named_matches by len
This searches for larger (more specific) matches first so that for example matchid and match get matched independently. Added _ to regex to match for params specified as match_id
1 parent b7f53d1 commit 5cec01c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/pyrqlite/cursors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _substitute_params(self, operation, parameters):
9797
param_matches = 0
9898

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

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

0 commit comments

Comments
 (0)