2010-04-01 23:10:53 +08:00
|
|
|
from django.db.models.sql import compiler
|
2013-09-02 18:10:03 +08:00
|
|
|
from django.utils.six.moves import zip_longest
|
2010-04-01 23:10:53 +08:00
|
|
|
|
2012-08-20 16:46:21 +08:00
|
|
|
|
2010-04-01 23:10:53 +08:00
|
|
|
class SQLCompiler(compiler.SQLCompiler):
|
|
|
|
def resolve_columns(self, row, fields=()):
|
|
|
|
values = []
|
2012-08-14 20:09:23 +08:00
|
|
|
index_extra_select = len(self.query.extra_select)
|
2012-08-20 16:46:21 +08:00
|
|
|
for value, field in zip_longest(row[index_extra_select:], fields):
|
2012-03-01 01:46:23 +08:00
|
|
|
if (field and field.get_internal_type() in ("BooleanField", "NullBooleanField") and
|
2013-11-26 17:43:46 +08:00
|
|
|
value in (0, 1)):
|
2012-03-01 01:46:23 +08:00
|
|
|
value = bool(value)
|
|
|
|
values.append(value)
|
2010-04-09 20:39:08 +08:00
|
|
|
return row[:index_extra_select] + tuple(values)
|
2010-04-01 23:10:53 +08:00
|
|
|
|
2013-05-27 19:59:16 +08:00
|
|
|
def as_subquery_condition(self, alias, columns, qn):
|
2013-03-25 00:40:40 +08:00
|
|
|
qn2 = self.connection.ops.quote_name
|
|
|
|
sql, params = self.as_sql()
|
2013-08-30 07:20:00 +08:00
|
|
|
return '(%s) IN (%s)' % (', '.join('%s.%s' % (qn(alias), qn2(column)) for column in columns), sql), params
|
2013-03-25 00:40:40 +08:00
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2010-04-01 23:10:53 +08:00
|
|
|
class SQLInsertCompiler(compiler.SQLInsertCompiler, SQLCompiler):
|
|
|
|
pass
|
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2010-04-01 23:10:53 +08:00
|
|
|
class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler):
|
|
|
|
pass
|
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2010-04-01 23:10:53 +08:00
|
|
|
class SQLUpdateCompiler(compiler.SQLUpdateCompiler, SQLCompiler):
|
|
|
|
pass
|
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2010-04-01 23:10:53 +08:00
|
|
|
class SQLAggregateCompiler(compiler.SQLAggregateCompiler, SQLCompiler):
|
|
|
|
pass
|
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2010-04-01 23:10:53 +08:00
|
|
|
class SQLDateCompiler(compiler.SQLDateCompiler, SQLCompiler):
|
|
|
|
pass
|
2013-02-10 23:15:49 +08:00
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2013-02-10 23:15:49 +08:00
|
|
|
class SQLDateTimeCompiler(compiler.SQLDateTimeCompiler, SQLCompiler):
|
|
|
|
pass
|