Refs #25759 -- Fixed some Funcs to work if different database backends are used.

This commit is contained in:
Kai Feldhoff 2016-03-16 11:05:24 -04:00 committed by Tim Graham
parent 4b510c3889
commit baa8b0ec39
1 changed files with 14 additions and 15 deletions

View File

@ -26,8 +26,10 @@ class Coalesce(Func):
expressions = [ expressions = [
ToNCLOB(expression) for expression in self.get_source_expressions()] ToNCLOB(expression) for expression in self.get_source_expressions()]
self.set_source_expressions(expressions) clone = self.copy()
return super(Coalesce, self).as_sql(compiler, connection) clone.set_source_expressions(expressions)
return super(Coalesce, clone).as_sql(compiler, connection)
return self.as_sql(compiler, connection)
class ConcatPair(Func): class ConcatPair(Func):
@ -44,14 +46,15 @@ class ConcatPair(Func):
def as_sqlite(self, compiler, connection): def as_sqlite(self, compiler, connection):
coalesced = self.coalesce() coalesced = self.coalesce()
coalesced.arg_joiner = ' || ' coalesced.arg_joiner = ' || '
coalesced.template = '%(expressions)s' return super(ConcatPair, coalesced).as_sql(
return super(ConcatPair, coalesced).as_sql(compiler, connection) compiler, connection, template='%(expressions)s',
)
def as_mysql(self, compiler, connection): def as_mysql(self, compiler, connection):
# Use CONCAT_WS with an empty separator so that NULLs are ignored. # Use CONCAT_WS with an empty separator so that NULLs are ignored.
self.function = 'CONCAT_WS' return super(ConcatPair, self).as_sql(
self.template = "%(function)s('', %(expressions)s)" compiler, connection, function='CONCAT_WS', template="%(function)s('', %(expressions)s)"
return super(ConcatPair, self).as_sql(compiler, connection) )
def coalesce(self): def coalesce(self):
# null on either side results in null for expression, wrap with coalesce # null on either side results in null for expression, wrap with coalesce
@ -137,8 +140,7 @@ class Length(Transform):
super(Length, self).__init__(expression, output_field=output_field, **extra) super(Length, self).__init__(expression, output_field=output_field, **extra)
def as_mysql(self, compiler, connection): def as_mysql(self, compiler, connection):
self.function = 'CHAR_LENGTH' return super(Length, self).as_sql(compiler, connection, function='CHAR_LENGTH')
return super(Length, self).as_sql(compiler, connection)
class Lower(Transform): class Lower(Transform):
@ -158,8 +160,7 @@ class Now(Func):
# Postgres' CURRENT_TIMESTAMP means "the time at the start of the # Postgres' CURRENT_TIMESTAMP means "the time at the start of the
# transaction". We use STATEMENT_TIMESTAMP to be cross-compatible with # transaction". We use STATEMENT_TIMESTAMP to be cross-compatible with
# other databases. # other databases.
self.template = 'STATEMENT_TIMESTAMP()' return self.as_sql(compiler, connection, template='STATEMENT_TIMESTAMP()')
return self.as_sql(compiler, connection)
class Substr(Func): class Substr(Func):
@ -183,12 +184,10 @@ class Substr(Func):
super(Substr, self).__init__(*expressions, **extra) super(Substr, self).__init__(*expressions, **extra)
def as_sqlite(self, compiler, connection): def as_sqlite(self, compiler, connection):
self.function = 'SUBSTR' return super(Substr, self).as_sql(compiler, connection, function='SUBSTR')
return super(Substr, self).as_sql(compiler, connection)
def as_oracle(self, compiler, connection): def as_oracle(self, compiler, connection):
self.function = 'SUBSTR' return super(Substr, self).as_sql(compiler, connection, function='SUBSTR')
return super(Substr, self).as_sql(compiler, connection)
class Upper(Transform): class Upper(Transform):