mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
Refs #28670 -- Moved LIMIT/OFFSET SQL to DatabaseOperations.limit_offset_sql().
Thanks Tim Graham for the review.
This commit is contained in:
parent
39eba25f47
commit
03da070f5c
@ -204,6 +204,22 @@ class BaseDatabaseOperations:
|
|||||||
' SKIP LOCKED' if skip_locked else '',
|
' SKIP LOCKED' if skip_locked else '',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _get_limit_offset_params(self, low_mark, high_mark):
|
||||||
|
offset = low_mark or 0
|
||||||
|
if high_mark is not None:
|
||||||
|
return (high_mark - offset), offset
|
||||||
|
elif offset:
|
||||||
|
return self.connection.ops.no_limit_value(), offset
|
||||||
|
return None, offset
|
||||||
|
|
||||||
|
def limit_offset_sql(self, low_mark, high_mark):
|
||||||
|
"""Return LIMIT/OFFSET SQL clause."""
|
||||||
|
limit, offset = self._get_limit_offset_params(low_mark, high_mark)
|
||||||
|
return '%s%s' % (
|
||||||
|
(' LIMIT %d' % limit) if limit else '',
|
||||||
|
(' OFFSET %d' % offset) if offset else '',
|
||||||
|
)
|
||||||
|
|
||||||
def last_executed_query(self, cursor, sql, params):
|
def last_executed_query(self, cursor, sql, params):
|
||||||
"""
|
"""
|
||||||
Return a string of the query last executed by the given cursor, with
|
Return a string of the query last executed by the given cursor, with
|
||||||
|
@ -233,6 +233,9 @@ END;
|
|||||||
else:
|
else:
|
||||||
return "%s"
|
return "%s"
|
||||||
|
|
||||||
|
def limit_offset_sql(self, low_mark, high_mark):
|
||||||
|
return ''
|
||||||
|
|
||||||
def last_executed_query(self, cursor, sql, params):
|
def last_executed_query(self, cursor, sql, params):
|
||||||
# https://cx-oracle.readthedocs.io/en/latest/cursor.html#Cursor.statement
|
# https://cx-oracle.readthedocs.io/en/latest/cursor.html#Cursor.statement
|
||||||
# The DB API definition does not define this attribute.
|
# The DB API definition does not define this attribute.
|
||||||
|
@ -532,14 +532,9 @@ class SQLCompiler:
|
|||||||
result.append('ORDER BY %s' % ', '.join(ordering))
|
result.append('ORDER BY %s' % ', '.join(ordering))
|
||||||
|
|
||||||
if with_limits:
|
if with_limits:
|
||||||
if self.query.high_mark is not None:
|
limit_offset_sql = self.connection.ops.limit_offset_sql(self.query.low_mark, self.query.high_mark)
|
||||||
result.append('LIMIT %d' % (self.query.high_mark - self.query.low_mark))
|
if limit_offset_sql:
|
||||||
if self.query.low_mark:
|
result.append(limit_offset_sql)
|
||||||
if self.query.high_mark is None:
|
|
||||||
val = self.connection.ops.no_limit_value()
|
|
||||||
if val:
|
|
||||||
result.append('LIMIT %d' % val)
|
|
||||||
result.append('OFFSET %d' % self.query.low_mark)
|
|
||||||
|
|
||||||
if for_update_part and not self.connection.features.for_update_after_from:
|
if for_update_part and not self.connection.features.for_update_after_from:
|
||||||
result.append(for_update_part)
|
result.append(for_update_part)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user