Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 71ff5e8bd0 | |||
| 61b783e447 | |||
| 8dfdd8a26d |
@@ -292,6 +292,9 @@ class SQLQuery(object):
|
|||||||
clone._group_by = args
|
clone._group_by = args
|
||||||
return clone
|
return clone
|
||||||
|
|
||||||
|
def first(self):
|
||||||
|
return self[:1]
|
||||||
|
|
||||||
def join(self, table, on="", how="inner join"):
|
def join(self, table, on="", how="inner join"):
|
||||||
clone = self._clone()
|
clone = self._clone()
|
||||||
if on:
|
if on:
|
||||||
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user