PgDB: Add format_param method

This commit is contained in:
Benjamin Renard 2021-11-18 19:21:27 +01:00
parent 0eda55f11c
commit 6c7f3e4871

View file

@ -180,6 +180,10 @@ class PgDB:
# SQL helpers # SQL helpers
# #
@staticmethod
def format_param(param):
return '%({0})s'.format(param)
@classmethod @classmethod
def _combine_params(cls, params, to_add=None, **kwargs): def _combine_params(cls, params, to_add=None, **kwargs):
if to_add: if to_add:
@ -241,7 +245,7 @@ class PgDB:
idx += 1 idx += 1
cls._combine_params(params, {param: value}) cls._combine_params(params, {param: value})
sql_where_clauses.append( sql_where_clauses.append(
'"{field}" = %({param})s'.format(field=field, param=param) '"{field}" = {param}'.format(field=field, param=cls.format_param(param))
) )
return ( return (
(" %s " % where_op).join(sql_where_clauses), (" %s " % where_op).join(sql_where_clauses),
@ -282,7 +286,7 @@ class PgDB:
self._quote_table_name(table), self._quote_table_name(table),
'", "'.join(values.keys()), '", "'.join(values.keys()),
", ".join([ ", ".join([
'%({0})s'.format(key) self.format_param(key)
for key in values for key in values
]) ])
) )
@ -302,7 +306,7 @@ class PgDB:
sql = 'UPDATE {0} SET {1}'.format( sql = 'UPDATE {0} SET {1}'.format(
self._quote_table_name(table), self._quote_table_name(table),
", ".join([ ", ".join([
'"{0}" = %({0})s'.format(key) '"{0}" = {1}'.format(key, self.format_param(key))
for key in values for key in values
]) ])
) )