From 03da070f5cfda592a174f8c19349638656a521b2 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Wed, 4 Oct 2017 20:24:38 +0200 Subject: Refs #28670 -- Moved LIMIT/OFFSET SQL to DatabaseOperations.limit_offset_sql(). Thanks Tim Graham for the review. --- django/db/backends/base/operations.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'django/db/backends/base') diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index 7bf0210bc6..3517300b50 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -204,6 +204,22 @@ class BaseDatabaseOperations: ' 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): """ Return a string of the query last executed by the given cursor, with -- cgit v1.3