3 Commits

View File

@@ -8,7 +8,7 @@ PYTHON3 = True
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
PYTHON3 = False PYTHON3 = False
VERSION = "0.0.14" VERSION = "0.0.15"
def is_map(obj): def is_map(obj):
@@ -105,8 +105,8 @@ class Q(QMixin):
_mode = "MYSQL" _mode = "MYSQL"
lookup_types = [ lookup_types = [
'icontains', 'istartswith', 'iendswith', 'icontains', 'istartswith', 'iendswith',
'contains', 'startswith', 'endswith', 'contains', 'startswith', 'endswith',
'year', 'month', 'day', 'week_day', 'hour', 'minute', 'second', 'year', 'month', 'day', 'week_day', 'hour', 'minute', 'second',
'isnull', 'in'] 'isnull', 'in']
@@ -311,6 +311,9 @@ class SQLQuery(object):
return clone return clone
def __getitem__(self, slice): def __getitem__(self, slice):
if isinstance(slice, str):
raise IndexError
clone = self._clone() clone = self._clone()
clone._limits = slice clone._limits = slice
return clone return clone
@@ -423,6 +426,31 @@ class SQLCompiler(object):
self.get_group_by(), self.get_group_by(),
self.get_limits(), ") as tbl_paginated WHERE ", conds] self.get_limits(), ") as tbl_paginated WHERE ", conds]
if self.sql_mode == "ACCESS" and self._limits and \
self._limits.start is not None and self._limits.stop is not None:
conds = []
if self._limits.start is not None:
conds.append("row_number > %s" % self._limits.start)
if self._limits.stop is not None:
conds.append("row_number <= %s" % self._limits.stop)
conds = " AND ".join(conds)
count = "(select count(*) FROM {table} as t2 WHERE t2.{id} <= {table}.{id}) as row_number".format(table=table,
id=self._order_by[0])
return ["SELECT * FROM (", "SELECT", self.get_columns(), ",",
count,
# "FROM",
# table,
self.get_joins(),
self.get_where(),
self.get_group_by(),
" FROM ",
table,
") WHERE ", conds]
return sql return sql
def _compile(self): def _compile(self):
@@ -433,7 +461,7 @@ class SQLCompiler(object):
__str__ = __repr__ __str__ = __repr__
@property @ property
def sql(self,): def sql(self,):
return self.__str__() return self.__str__()
@@ -447,6 +475,6 @@ class Queryset(SQLCompiler, SQLQuery):
class SQLModel(object): class SQLModel(object):
@classproperty @ classproperty
def objects(cls): def objects(cls):
return Queryset(cls.table, getattr(cls, 'sql_mode', None)) return Queryset(cls.table, getattr(cls, 'sql_mode', None))