From a7d01ec9b4b7a41d5e61498993949b1285db4e45 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Thu, 13 Sep 2007 03:11:44 +0000 Subject: [PATCH] Fixed limit/offset computations. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6118 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/sql/query.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 089bd75774..21ce5282d4 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -208,7 +208,7 @@ class Query(object): if self.high_mark: result.append('LIMIT %d' % (self.high_mark - self.low_mark)) if self.low_mark: - assert self.high_mark, "OFFSET not allowed without LIMIT." + assert self.high_mark, "'offset' is not allowed without 'limit'" result.append('OFFSET %d' % self.low_mark) params.extend(self.extra_params) @@ -632,10 +632,15 @@ class Query(object): clamped to any existing high value. """ if high: - # None (high_mark's default) is less than any number, so this works. - self.high_mark = max(self.high_mark, high) + if self.high_mark: + self.high_mark = min(self.high_mark, self.low_mark + high) + else: + self.high_mark = self.low_mark + high if low: - self.low_mark = max(self.high_mark, self.low_mark + low) + if self.high_mark: + self.low_mark = min(self.high_mark, self.low_mark + low) + else: + self.low_mark = self.low_mark + low def clear_limits(self): """