Django

Code

Changeset 7926

Show
Ignore:
Timestamp:
07/15/08 13:47:32 (4 months ago)
Author:
mtredinnick
Message:

Fixed #7411 -- worked around some possible transaction conflicts in SQLite.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/backends/__init__.py

    r7852 r7926  
    5454    interprets_empty_strings_as_nulls = False 
    5555    date_field_supports_time_value = True 
     56    can_use_chunked_reads = True 
    5657 
    5758class BaseDatabaseOperations(object): 
  • django/trunk/django/db/backends/sqlite3/base.py

    r7477 r7926  
    4141class DatabaseFeatures(BaseDatabaseFeatures): 
    4242    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 
    4348 
    4449class DatabaseOperations(BaseDatabaseOperations): 
  • django/trunk/django/db/models/sql/query.py

    r7901 r7926  
    16171617        # The MULTI case. 
    16181618        if self.ordering_aliases: 
    1619             return order_modified_iter(cursor, len(self.ordering_aliases), 
     1619            result = order_modified_iter(cursor, len(self.ordering_aliases), 
    16201620                    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)), 
    16221622                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 
    16231629 
    16241630# Use the backend's custom Query class if it defines one. Otherwise, use the 
  • django/trunk/tests/regressiontests/queries/models.py

    r7914 r7926  
    77 
    88from django.db import models 
    9 from django.db.models.query import Q 
     9from django.db.models.query import Q, ITER_CHUNK_SIZE 
    1010 
    1111# Python 2.3 doesn't have sorted() 
     
    1414except NameError: 
    1515    from django.utils.itercompat import sorted 
    16                  
     16 
    1717class Tag(models.Model): 
    1818    name = models.CharField(max_length=10) 
     
    821821[] 
    822822 
     823Bug #7411 - saving to db must work even with partially read result set in 
     824another 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 
    823833"""} 
    824834