Memory engine does not support PREWHERE

This commit is contained in:
Itai Shirav 2019-02-27 08:41:16 +02:00
parent 64920a96c7
commit ad81a811fc

View File

@ -344,10 +344,10 @@ class QuerySet(object):
params = (distinct, self.select_fields_as_sql(), self._model_cls.table_name(), final) params = (distinct, self.select_fields_as_sql(), self._model_cls.table_name(), final)
sql = u'SELECT %s%s\nFROM `%s`%s' % params sql = u'SELECT %s%s\nFROM `%s`%s' % params
if self._prewhere_q: if self._prewhere_q and not self._prewhere_q.is_empty:
sql += '\nPREWHERE ' + self.conditions_as_sql(prewhere=True) sql += '\nPREWHERE ' + self.conditions_as_sql(prewhere=True)
if self._where_q: if self._where_q and not self._where_q.is_empty:
sql += '\nWHERE ' + self.conditions_as_sql(prewhere=False) sql += '\nWHERE ' + self.conditions_as_sql(prewhere=False)
if self._grouping_fields: if self._grouping_fields:
@ -410,7 +410,7 @@ class QuerySet(object):
return qs return qs
def _filter_or_exclude(self, *q, **kwargs): def _filter_or_exclude(self, *q, **kwargs):
reverse = kwargs.pop('reverse', False) inverse = kwargs.pop('_inverse', False)
prewhere = kwargs.pop('prewhere', False) prewhere = kwargs.pop('prewhere', False)
qs = copy(self) qs = copy(self)
@ -422,7 +422,7 @@ class QuerySet(object):
if kwargs: if kwargs:
condition &= Q(**kwargs) condition &= Q(**kwargs)
if reverse: if inverse:
condition = ~condition condition = ~condition
condition = copy(self._prewhere_q if prewhere else self._where_q) & condition condition = copy(self._prewhere_q if prewhere else self._where_q) & condition
@ -436,15 +436,16 @@ class QuerySet(object):
def filter(self, *q, **kwargs): def filter(self, *q, **kwargs):
""" """
Returns a copy of this queryset that includes only rows matching the conditions. Returns a copy of this queryset that includes only rows matching the conditions.
Add q object to query if it specified. Pass `prewhere=True` to apply the conditions as PREWHERE instead of WHERE.
""" """
return self._filter_or_exclude(*q, **kwargs) return self._filter_or_exclude(*q, **kwargs)
def exclude(self, *q, **kwargs): def exclude(self, *q, **kwargs):
""" """
Returns a copy of this queryset that excludes all rows matching the conditions. Returns a copy of this queryset that excludes all rows matching the conditions.
Pass `prewhere=True` to apply the conditions as PREWHERE instead of WHERE.
""" """
return self._filter_or_exclude(*q, reverse=True, **kwargs) return self._filter_or_exclude(*q, _inverse=True, **kwargs)
def paginate(self, page_num=1, page_size=100): def paginate(self, page_num=1, page_size=100):
""" """