This commit is contained in:
2018-10-09 10:25:56 +02:00
parent 562c75880b
commit 4b5dc8e71a

View File

@@ -241,6 +241,7 @@ class SQLQuery(object):
self._limits = None
self._sql = sql
self._nolock = False
self._distinct = False
def has_filters(self,):
return self._order_by or self._group_by or self._joins\
@@ -272,6 +273,11 @@ class SQLQuery(object):
clone._nolock = enabled
return clone
def distinct(self, enabled=True):
clone = self._clone()
clone._distinct = enabled
return clone
def filter(self, *args, **kwargs):
clone = self._clone()
clone._filters &= self._q(*args, **kwargs)
@@ -374,6 +380,11 @@ class SQLCompiler(object):
return " WITH (NOLOCK)"
return ""
def get_distinct(self,):
if self._distinct:
return " DISTINCT "
return ""
def get_limits(self,):
if self._limits and self.sql_mode != "SQL_SERVER":
offset = self._limits.start
@@ -397,7 +408,10 @@ class SQLCompiler(object):
else:
table = self.get_table()
sql = ["SELECT", self.get_top(), self.get_columns(),
sql = ["SELECT",
self.get_distinct(),
self.get_top(),
self.get_columns(),
"FROM", table,
self.get_nolock(),
self.get_joins(), self.get_where(),