Commits

Michael Manfre  committed 07396e8

Issue 103 - Use NEWID() for random order_by queries so multiple, identical queries return different randomly ordered resultsets.

  • Participants
  • Parent commits 44f7ce1

Comments (0)

Files changed (2)

File sqlserver_ado/operations.py

         return '[%s]' % name
 
     def random_function_sql(self):
-        return 'RAND()'
+        return 'NEWID()'
 
     def regex_lookup(self, lookup_type):
         # Case sensitivity

File tests/test_main/regressiontests/tests.py

 
         dates = Bug93Table.objects.filter(dt__year='2010')
         self.assertTrue(dates.count() == 2)
+
+class RandomOrderTestCase(TestCase):
+    def testRandomOrder(self):
+        """
+        Check that multiple results with order_by('?') return
+        different orders.
+        """
+        for x in xrange(1,20):
+            Bug69Table1.objects.create(id=x)
+
+        a = list(Bug69Table1.objects.all().order_by('?'))
+        b = list(Bug69Table1.objects.all().order_by('?'))
+        
+        self.assertNotEquals(a, b)