|
3 | 3 | from copy import copy
|
4 | 4 |
|
5 | 5 | from django.core.exceptions import EmptyResultSet
|
6 |
| -from django.db.models.expressions import Exists, Func, RawSQL, Value |
7 |
| -from django.db.models.fields import DateTimeField, Field, IntegerField |
| 6 | +from django.db.models.expressions import Case, Exists, Func, Value, When |
| 7 | +from django.db.models.fields import ( |
| 8 | + BooleanField, DateTimeField, Field, IntegerField, |
| 9 | +) |
8 | 10 | from django.db.models.query_utils import RegisterLookupMixin
|
9 | 11 | from django.utils.datastructures import OrderedSet
|
10 | 12 | from django.utils.functional import cached_property
|
@@ -119,11 +121,7 @@ def as_oracle(self, compiler, connection):
|
119 | 121 | exprs = []
|
120 | 122 | for expr in (self.lhs, self.rhs):
|
121 | 123 | if isinstance(expr, Exists):
|
122 |
| - # XXX: Use Case(When(self.lhs)) once support for boolean |
123 |
| - # expressions is added to When. |
124 |
| - sql, params = compiler.compile(expr) |
125 |
| - sql = 'CASE WHEN %s THEN 1 ELSE 0 END' % sql |
126 |
| - expr = RawSQL(sql, params) |
| 124 | + expr = Case(When(expr, then=True), default=False, output_field=BooleanField()) |
127 | 125 | wrapped = True
|
128 | 126 | exprs.append(expr)
|
129 | 127 | lookup = type(self)(*exprs) if wrapped else self
|
|
0 commit comments