Django

Code

Changeset 7147

Show
Ignore:
Timestamp:
02/22/08 19:34:49 (4 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Implemented slicing to end of querysets.

Refs #2150, #5012.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/django/db/backends/__init__.py

    r7087 r7147  
    184184        return None 
    185185 
     186    def no_limit_value(self): 
     187        """ 
     188        Returns the value to use for the LIMIT when we are wanting "LIMIT 
     189        infinity". Returns None if the limit clause can be omitted in this case. 
     190        """ 
     191        # FIXME: API may need to change once Oracle backend is repaired. 
     192        raise NotImplementedError() 
     193 
    186194    def pk_default_value(self): 
    187195        """ 
  • django/branches/queryset-refactor/django/db/backends/mysql/base.py

    r7136 r7147  
    9393            sql += "%s," % offset 
    9494        return sql + str(limit) 
     95 
     96    def no_limit_value(self): 
     97        # 2**64 - 1, as recommended by the MySQL documentation 
     98        return 18446744073709551615L 
    9599 
    96100    def quote_name(self, name): 
  • django/branches/queryset-refactor/django/db/backends/mysql_old/base.py

    r6690 r7147  
    9898            sql += "%s," % offset 
    9999        return sql + str(limit) 
     100 
     101    def no_limit_value(self): 
     102        # 2**64 - 1, as recommended by the MySQL documentation 
     103        return 18446744073709551615L 
    100104 
    101105    def quote_name(self, name): 
  • django/branches/queryset-refactor/django/db/backends/postgresql/operations.py

    r6597 r7147  
    3131        cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name)) 
    3232        return cursor.fetchone()[0] 
     33 
     34    def no_limit_value(self): 
     35        return None 
    3336 
    3437    def quote_name(self, name): 
  • django/branches/queryset-refactor/django/db/backends/sqlite3/base.py

    r6337 r7147  
    6363            return name # Quoting once is enough. 
    6464        return '"%s"' % name 
     65 
     66    def no_limit_value(self): 
     67        return -1 
    6568 
    6669    def sql_flush(self, style, tables, sequences): 
  • django/branches/queryset-refactor/django/db/models/sql/query.py

    r7146 r7147  
    263263            result.append('ORDER BY %s' % ', '.join(ordering)) 
    264264 
     265        # FIXME: Pull this out to make life easier for Oracle et al. 
    265266        if with_limits: 
    266267            if self.high_mark: 
    267268                result.append('LIMIT %d' % (self.high_mark - self.low_mark)) 
    268269            if self.low_mark: 
    269                 assert self.high_mark, "'offset' is not allowed without 'limit'" 
     270                if not self.high_mark: 
     271                    val = self.connection.ops.no_limit_value() 
     272                    if val: 
     273                        result.append('LIMIT %d' % val) 
    270274                result.append('OFFSET %d' % self.low_mark) 
    271275 
  • django/branches/queryset-refactor/docs/db-api.txt

    r7136 r7147  
    422422 
    423423    Entry.objects.all()[5:10] 
     424 
     425You can also slice from the item ''N'' to the end of the queryset. For 
     426example, to return everything from the fixth item onwards:: 
     427 
     428    Entry.objects.all()[5:] 
     429 
     430How this last example is implemented in SQL varies depending upon the database 
     431used, but it is supported in all cases. 
    424432 
    425433Generally, slicing a ``QuerySet`` returns a new ``QuerySet`` -- it doesn't 
  • django/branches/queryset-refactor/tests/modeltests/basic/models.py

    r7136 r7147  
    293293[<Article: Default headline>] 
    294294 
    295 # Note that you can't use 'offset' without 'limit' (on some dbs), so this doesn't work: 
    296 >>> Article.objects.all()[2:] 
    297 Traceback (most recent call last): 
    298     ... 
    299 AssertionError: 'offset' is not allowed without 'limit' 
     295# Using an offset without a limit is also possible. 
     296>>> Article.objects.all()[5:] 
     297[<Article: Fourth article>, <Article: Article 7>, <Article: Updated article 8>] 
    300298 
    301299# Also, once you have sliced you can't filter, re-order or combine