diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-13 03:11:44 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-13 03:11:44 +0000 |
| commit | a7d01ec9b4b7a41d5e61498993949b1285db4e45 (patch) | |
| tree | 9a4bb0350da3156796ab6deddf63cd355b75f58e /django/db/models/sql | |
| parent | cc9d51942492a161757cf2ad24c809921267dcf3 (diff) | |
Fixed limit/offset computations.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6118 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 13 |
1 files 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): """ |
