Permalink
Browse files

Fix postgres issue with LIKE conditions.

1. % needed to be scaled, because the condition string will
   be interpolated by the ORM backend.

2. Texts in double quotes crashes Postgresql.
  • Loading branch information...
henriquebastos committed Dec 29, 2012
1 parent 6dc0cd8 commit 4f27fe0c1836e0b46a8b6e1fe28ad68f073c1f08
Showing with 5 additions and 1 deletion.
  1. +5 −1 aggregate_if.py
View
@@ -43,7 +43,11 @@ def _condition_as_sql(self, qn, connection):
'''
def escape(value):
if isinstance(value, basestring):
- value = qn(value)
+ # Escape params used with LIKE
+ if '%' in value:
+ value = value.replace('%', '%%')
+ # Add single quote to text values
+ value = "'" + value + "'"
if isinstance(value, bool):
value = int(value)
return value

0 comments on commit 4f27fe0

Please sign in to comment.