Commits

adamv  committed 530504c

Fix for slicing offsets issue 32.

  • Participants
  • Parent commits 87bb820

Comments (0)

Files changed (3)

File source/sqlserver_ado/query.py

                 qn = self.connection.ops.quote_name
                 order = '%s.%s ASC' % (qn(meta.db_table), qn(meta.pk.attname))
             
-            where_row_num = "%s <= _row_num" % (self.low_mark)
+            where_row_num = "%s < _row_num" % (self.low_mark)
             if self.high_mark:
-                where_row_num += " and _row_num < %s" % (self.high_mark)
+                where_row_num += " and _row_num <= %s" % (self.high_mark)
                 
             outer_select, inner_select = self._alias_columns(inner_select)
             

File tests/test_main/myapp/models.py

 # Test slicing
 class Products(models.Model):
     """
-    >>> names=['Screws', 'Bolts', 'Nuts', 'S-Pipe', 'L-Pipe', 'Item', 'Zebra']
+    >>> names=['Screws', 'Bolts', 'Nuts', 'SPipe', 'LPipe', 'Item', 'Zebra']
     >>> for n in names: product = Products.objects.create(name=n)
     >>> p = Products.objects
     >>> len(list(p.all()))
     >>> len(list(p.all()[2:5]))
     3
     >>> len(list(p.all()[5:]))
-    3
-    >>> list(p.order_by('name'))
-    [Bolts, Item, L-Pipe, Nuts, Screws, S-Pipe, Zebra]
-    >>> list(p.order_by('name')[:3])
-    [Bolts, Item, L-Pipe]
-    >>> list(p.order_by('name')[2:5])
-    [Item, L-Pipe, Nuts]
-    >>> list(p.order_by('name')[5:])
-    [Screws, S-Pipe, Zebra]
+    2
+    >>> pn = p.order_by('name')
+    >>> list(pn)
+    [Bolts, Item, LPipe, Nuts, Screws, SPipe, Zebra]
+    >>> list(pn[:3])
+    [Bolts, Item, LPipe]
+    >>> list(pn[2:5])
+    [LPipe, Nuts, Screws]
+    >>> list(pn[5:])
+    [SPipe, Zebra]
     """
 
     productid = models.AutoField(primary_key=True)

File tests/test_main/paging/models.py

 from django.db import models
-from django.core.paginator import QuerySetPaginator
+from django.core.paginator import Paginator
 
 import unittest
 
     # * The string splitting on 'FROM' shouldn't break either
     c = models.CharField(default=u'test', max_length=10, db_column=u'FROM')
     
+    def __repr__(self):
+        return '<FirstTable %s: %s, %s>' % (self.pk, self.b, self.c)
+    
 class SecondTable(models.Model):
     a = models.ForeignKey(FirstTable)
     b = models.CharField(max_length=100)
+    
+    def __repr__(self):
+        return '<FirstTable %s: %s, %s>' % (self.pk, self.a_id, self.b)
 
 
 class PagingTestCase(unittest.TestCase):
         b3.save()
         
         return a1.pk
+        
+    def try_page(self, page_number, a1_pk):
+        # Select related data so we get two 'b' columns and two 'id' columns per row.
+        data = SecondTable.objects.filter(a=a1_pk).order_by('b').select_related(depth=1)
+        
+        # Use a single item per page, to get multiple pages.
+        pager = Paginator(data, 1)
+        self.assertEquals(pager.count, 3)
+
+        on_this_page = list(pager.page(page_number).object_list)
+        self.assertEquals(len(on_this_page), 1, 'Too many results on this page.')
+        self.assertEquals(on_this_page[0].b, 'B'+str(page_number))
     
     def testPagingWithDuplicateColumnNames(self):
         a1_pk = self.setupPagingData()
         
-        # Select related data so we get two 'b' columns per row
-        # (and two id columns, too)
-        data = SecondTable.objects.filter(a=a1_pk).order_by('b').select_related(depth=1)
-        
-        # Use a single item per page, to get multiple pages
-        paged_data = QuerySetPaginator(data, 1)
-
-        on_this_page = list(paged_data.page(1).object_list)
-        self.assertEquals(len(on_this_page), 1, 'Too many results on this page.')
-        self.assertEquals(on_this_page[0].b, 'B1')
-        
-        on_this_page = list(paged_data.page(2).object_list)
-        self.assertEquals(len(on_this_page), 1, 'Too many results on this page.')
-        self.assertEquals(on_this_page[0].b, 'B2')
-
-        on_this_page = list(paged_data.page(3).object_list)
-        self.assertEquals(len(on_this_page), 1, 'Too many results on this page.')
-        self.assertEquals(on_this_page[0].b, 'B3')
+        for i in (1,2,3):
+            self.try_page(i, a1_pk)