summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-07-01 22:49:38 +0300
committerAnssi Kääriäinen <akaariai@gmail.com>2012-07-01 22:52:35 +0300
commite74787391e8fdf87d9a92138028911746809bd7c (patch)
tree55d069782efb40088a9bcf9c34b4d486a9733ed6 /django/db/models/sql
parentf572ee0c65ec5eac9edb0cb3e35c96ec86d89ffb (diff)
Fixed a regression introduced in where.as_sql() refactor
At least Oracle needs parentheses in negated where conditions, even if there is only single condition negated. Fixed this by reverting to old logic in that part of as_sql() and adding a comment about this. I did not investigate why the parentheses are needed. The original offending commit was bd283aa844b04651b7c8b4e85f48c6dced1678f0.
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/where.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py
index 70ff5310f7..827046553d 100644
--- a/django/db/models/sql/where.py
+++ b/django/db/models/sql/where.py
@@ -135,10 +135,13 @@ class WhereNode(tree.Node):
conn = ' %s ' % self.connector
sql_string = conn.join(result)
if sql_string:
- if len(result) > 1:
- sql_string = '(%s)' % sql_string
if self.negated:
- sql_string = 'NOT %s' % sql_string
+ # Note that some backends (Oracle at least) need the
+ # parentheses even around single experssion in the
+ # negated case.
+ sql_string = 'NOT (%s)' % sql_string
+ elif len(result) > 1:
+ sql_string = '(%s)' % sql_string
return sql_string, result_params
def make_atom(self, child, qn, connection):