Fixed #23753 -- Oracle failure with Coalesce
This commit is contained in:
parent
932d449f00
commit
1cdfbde4db
|
@ -16,6 +16,18 @@ class Coalesce(Func):
|
||||||
raise ValueError('Coalesce must take at least two expressions')
|
raise ValueError('Coalesce must take at least two expressions')
|
||||||
super(Coalesce, self).__init__(*expressions, **extra)
|
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):
|
class ConcatPair(Func):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -56,6 +56,18 @@ class FunctionTests(TestCase):
|
||||||
lambda a: a.headline
|
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):
|
def test_concat(self):
|
||||||
Author.objects.create(name='Jayden')
|
Author.objects.create(name='Jayden')
|
||||||
Author.objects.create(name='John Smith', alias='smithj', goes_by='John')
|
Author.objects.create(name='John Smith', alias='smithj', goes_by='John')
|
||||||
|
|
Loading…
Reference in New Issue