mirror of https://github.com/django/django.git
Fixed #7411 -- worked around some possible transaction conflicts in SQLite.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7926 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e867c5a0cc
commit
3b37c8151a
|
@ -53,6 +53,7 @@ class BaseDatabaseFeatures(object):
|
||||||
time_field_needs_date = False
|
time_field_needs_date = False
|
||||||
interprets_empty_strings_as_nulls = False
|
interprets_empty_strings_as_nulls = False
|
||||||
date_field_supports_time_value = True
|
date_field_supports_time_value = True
|
||||||
|
can_use_chunked_reads = True
|
||||||
|
|
||||||
class BaseDatabaseOperations(object):
|
class BaseDatabaseOperations(object):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -40,6 +40,11 @@ Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal)
|
||||||
|
|
||||||
class DatabaseFeatures(BaseDatabaseFeatures):
|
class DatabaseFeatures(BaseDatabaseFeatures):
|
||||||
supports_constraints = False
|
supports_constraints = False
|
||||||
|
# SQLite cannot handle us only partially reading from a cursor's result set
|
||||||
|
# and then writing the same rows to the database in another cursor. This
|
||||||
|
# setting ensures we always read result sets fully into memory all in one
|
||||||
|
# go.
|
||||||
|
can_use_chunked_reads = False
|
||||||
|
|
||||||
class DatabaseOperations(BaseDatabaseOperations):
|
class DatabaseOperations(BaseDatabaseOperations):
|
||||||
def date_extract_sql(self, lookup_type, field_name):
|
def date_extract_sql(self, lookup_type, field_name):
|
||||||
|
|
|
@ -1616,10 +1616,16 @@ class Query(object):
|
||||||
|
|
||||||
# The MULTI case.
|
# The MULTI case.
|
||||||
if self.ordering_aliases:
|
if self.ordering_aliases:
|
||||||
return order_modified_iter(cursor, len(self.ordering_aliases),
|
result = order_modified_iter(cursor, len(self.ordering_aliases),
|
||||||
self.connection.features.empty_fetchmany_value)
|
self.connection.features.empty_fetchmany_value)
|
||||||
return iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
|
result = iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
|
||||||
self.connection.features.empty_fetchmany_value)
|
self.connection.features.empty_fetchmany_value)
|
||||||
|
if not self.connection.features.can_use_chunked_reads:
|
||||||
|
# If we are using non-chunked reads, we return the same data
|
||||||
|
# structure as normally, but ensure it is all read into memory
|
||||||
|
# before going any further.
|
||||||
|
return list(result)
|
||||||
|
return result
|
||||||
|
|
||||||
# Use the backend's custom Query class if it defines one. Otherwise, use the
|
# Use the backend's custom Query class if it defines one. Otherwise, use the
|
||||||
# default.
|
# default.
|
||||||
|
|
|
@ -6,14 +6,14 @@ import datetime
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.query import Q
|
from django.db.models.query import Q, ITER_CHUNK_SIZE
|
||||||
|
|
||||||
# Python 2.3 doesn't have sorted()
|
# Python 2.3 doesn't have sorted()
|
||||||
try:
|
try:
|
||||||
sorted
|
sorted
|
||||||
except NameError:
|
except NameError:
|
||||||
from django.utils.itercompat import sorted
|
from django.utils.itercompat import sorted
|
||||||
|
|
||||||
class Tag(models.Model):
|
class Tag(models.Model):
|
||||||
name = models.CharField(max_length=10)
|
name = models.CharField(max_length=10)
|
||||||
parent = models.ForeignKey('self', blank=True, null=True,
|
parent = models.ForeignKey('self', blank=True, null=True,
|
||||||
|
@ -820,5 +820,15 @@ Bug #7698 -- People like to slice with '0' as the high-water mark.
|
||||||
>>> Item.objects.all()[0:0]
|
>>> Item.objects.all()[0:0]
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
Bug #7411 - saving to db must work even with partially read result set in
|
||||||
|
another cursor.
|
||||||
|
|
||||||
|
>>> for num in range(2 * ITER_CHUNK_SIZE + 1):
|
||||||
|
... _ = Number.objects.create(num=num)
|
||||||
|
|
||||||
|
>>> for i, obj in enumerate(Number.objects.all()):
|
||||||
|
... obj.save()
|
||||||
|
... if i > 10: break
|
||||||
|
|
||||||
"""}
|
"""}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue