diff --git a/jinjasql/core.py b/jinjasql/core.py index dcf1ef1..f7ecec1 100644 --- a/jinjasql/core.py +++ b/jinjasql/core.py @@ -122,8 +122,8 @@ def bind_in_clause(value): return clause def _bind_param(already_bound, key, value): - new_key = key - new_key = "%s#%s" % (key, random.getrandbits(128)) + _thread_local.param_index += 1 + new_key = "%s_%s" % (key, _thread_local.param_index) already_bound[new_key] = value param_style = _thread_local.param_style @@ -132,14 +132,12 @@ def _bind_param(already_bound, key, value): elif param_style == 'format': return "%s" elif param_style == 'numeric': - _thread_local.param_index += 1 return ":%s" % _thread_local.param_index elif param_style == 'named': return ":%s" % new_key elif param_style == 'pyformat': return "%%(%s)s" % new_key elif param_style == 'asyncpg': - _thread_local.param_index += 1 return "$%s" % _thread_local.param_index else: raise AssertionError("Invalid param_style - %s" % param_style) diff --git a/tests/yaml/macros.yaml b/tests/yaml/macros.yaml index 4c469a6..b840ec1 100644 --- a/tests/yaml/macros.yaml +++ b/tests/yaml/macros.yaml @@ -70,12 +70,12 @@ expected_sql: numeric: > select * from timesheet where day in (:1,:2,:3,:4,:5) - numeric: > + named: > select * from timesheet - where day in (:1,:2,:3,:4,:5) - numeric: > + where day in (:inclause_1,:inclause_2,:inclause_3,:inclause_4,:inclause_5) + pyformat: > select * from timesheet - where day in (:1,:2,:3,:4,:5) + where day in (%(inclause_1)s,%(inclause_2)s,%(inclause_3)s,%(inclause_4)s,%(inclause_5)s) --- name: test_macros template: >