diff options
author | Marko Kreen | 2008-04-25 14:45:53 +0000 |
---|---|---|
committer | Marko Kreen | 2008-04-25 14:45:53 +0000 |
commit | a6bc0ffa2c37b9e43a5bca7b4003313ce1875ad3 (patch) | |
tree | b4f7abc09a1e22d468a93c273e0dcaf35bb656dd /python/skytools/quoting.py | |
parent | 20af213cd1a177fa3b46733759b0a07a326d5c24 (diff) |
skytools.quote_statement(): support list/tuple args too
Diffstat (limited to 'python/skytools/quoting.py')
-rw-r--r-- | python/skytools/quoting.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/python/skytools/quoting.py b/python/skytools/quoting.py index 8225c7b0..a0c2c0d8 100644 --- a/python/skytools/quoting.py +++ b/python/skytools/quoting.py @@ -34,15 +34,19 @@ def quote_bytea_copy(s): return quote_copy(quote_bytea_raw(s)) -def quote_statement(sql, dict): +def quote_statement(sql, dict_or_list): """Quote whole statement. - Data values are taken from dict. + Data values are taken from dict or list or tuple. """ - xdict = {} - for k, v in dict.items(): - xdict[k] = quote_literal(v) - return sql % xdict + if hasattr(dict_or_list, 'items'): + qvals = {} + for k, v in dict_or_list.items(): + qvals[k] = quote_literal(v) + else: + qvals = [quote_literal(v) for v in dict_or_list] + qvals = tuple(qvals) + return sql % qvals # reserved keywords _ident_kwmap = { |