Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7411 -- worked around some possible transaction conflicts in S…

…QLite.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7926 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3b37c8151a06a2bebd51007db30ad436811b82c8 1 parent e867c5a
Malcolm Tredinnick authored July 15, 2008
1  django/db/backends/__init__.py
@@ -53,6 +53,7 @@ class BaseDatabaseFeatures(object):
53 53
     time_field_needs_date = False
54 54
     interprets_empty_strings_as_nulls = False
55 55
     date_field_supports_time_value = True
  56
+    can_use_chunked_reads = True
56 57
 
57 58
 class BaseDatabaseOperations(object):
58 59
     """
5  django/db/backends/sqlite3/base.py
@@ -40,6 +40,11 @@
40 40
 
41 41
 class DatabaseFeatures(BaseDatabaseFeatures):
42 42
     supports_constraints = False
  43
+    # SQLite cannot handle us only partially reading from a cursor's result set
  44
+    # and then writing the same rows to the database in another cursor. This
  45
+    # setting ensures we always read result sets fully into memory all in one
  46
+    # go.
  47
+    can_use_chunked_reads = False
43 48
 
44 49
 class DatabaseOperations(BaseDatabaseOperations):
45 50
     def date_extract_sql(self, lookup_type, field_name):
10  django/db/models/sql/query.py
@@ -1616,10 +1616,16 @@ def execute_sql(self, result_type=MULTI):
1616 1616
 
1617 1617
         # The MULTI case.
1618 1618
         if self.ordering_aliases:
1619  
-            return order_modified_iter(cursor, len(self.ordering_aliases),
  1619
+            result = order_modified_iter(cursor, len(self.ordering_aliases),
1620 1620
                     self.connection.features.empty_fetchmany_value)
1621  
-        return iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
  1621
+        result = iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
1622 1622
                 self.connection.features.empty_fetchmany_value)
  1623
+        if not self.connection.features.can_use_chunked_reads:
  1624
+            # If we are using non-chunked reads, we return the same data
  1625
+            # structure as normally, but ensure it is all read into memory
  1626
+            # before going any further.
  1627
+            return list(result)
  1628
+        return result
1623 1629
 
1624 1630
 # Use the backend's custom Query class if it defines one. Otherwise, use the
1625 1631
 # default.
14  tests/regressiontests/queries/models.py
@@ -6,14 +6,14 @@
6 6
 import pickle
7 7
 
8 8
 from django.db import models
9  
-from django.db.models.query import Q
  9
+from django.db.models.query import Q, ITER_CHUNK_SIZE
10 10
 
11 11
 # Python 2.3 doesn't have sorted()
12 12
 try:
13 13
     sorted
14 14
 except NameError:
15 15
     from django.utils.itercompat import sorted
16  
-                
  16
+
17 17
 class Tag(models.Model):
18 18
     name = models.CharField(max_length=10)
19 19
     parent = models.ForeignKey('self', blank=True, null=True,
@@ -820,5 +820,15 @@ class Related(models.Model):
820 820
 >>> Item.objects.all()[0:0]
821 821
 []
822 822
 
  823
+Bug #7411 - saving to db must work even with partially read result set in
  824
+another cursor.
  825
+
  826
+>>> for num in range(2 * ITER_CHUNK_SIZE + 1):
  827
+...     _ = Number.objects.create(num=num)
  828
+
  829
+>>> for i, obj in enumerate(Number.objects.all()):
  830
+...     obj.save()
  831
+...     if i > 10: break
  832
+
823 833
 """}
824 834
 

0 notes on commit 3b37c81

Please sign in to comment.
Something went wrong with that request. Please try again.