summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Smeaton <josh.smeaton@gmail.com>2014-12-29 09:15:00 +1100
committerJosh Smeaton <josh.smeaton@gmail.com>2014-12-29 19:44:13 +1100
commit1cdfbde4db1ac6bbddb2cf8dd5192831bc0f9ce3 (patch)
tree3d3b46ddd2fc69c59b2e7beef557ff4d0e065a5a
parent932d449f001a94aa5065cda652a442e4b1dd5352 (diff)
Fixed #23753 -- Oracle failure with Coalesce
-rw-r--r--django/db/models/functions.py12
-rw-r--r--tests/db_functions/tests.py12
2 files changed, 24 insertions, 0 deletions
diff --git a/django/db/models/functions.py b/django/db/models/functions.py
index f2252000cd..f16cf10b15 100644
--- a/django/db/models/functions.py
+++ b/django/db/models/functions.py
@@ -16,6 +16,18 @@ class Coalesce(Func):
raise ValueError('Coalesce must take at least two expressions')
super(Coalesce, self).__init__(*expressions, **extra)
+ def as_oracle(self, compiler, connection):
+ # we can't mix TextField (NCLOB) and CharField (NVARCHAR), so convert
+ # all fields to NCLOB when we expect NCLOB
+ if self.output_field.get_internal_type() == 'TextField':
+ class ToNCLOB(Func):
+ function = 'TO_NCLOB'
+
+ expressions = [
+ ToNCLOB(expression) for expression in self.get_source_expressions()]
+ self.set_source_expressions(expressions)
+ return super(Coalesce, self).as_sql(compiler, connection)
+
class ConcatPair(Func):
"""
diff --git a/tests/db_functions/tests.py b/tests/db_functions/tests.py
index 089fd11a8a..2ab18b61e0 100644
--- a/tests/db_functions/tests.py
+++ b/tests/db_functions/tests.py
@@ -56,6 +56,18 @@ class FunctionTests(TestCase):
lambda a: a.headline
)
+ # mixed Text and Char wrapped
+ article = Article.objects.annotate(
+ headline=Coalesce(Lower('summary'), Lower('text'), output_field=TextField()),
+ )
+
+ self.assertQuerysetEqual(
+ article.order_by('title'), [
+ lorem_ipsum.lower(),
+ ],
+ lambda a: a.headline
+ )
+
def test_concat(self):
Author.objects.create(name='Jayden')
Author.objects.create(name='John Smith', alias='smithj', goes_by='John')