Fixed #3501 -- Fixed date filtering in querysets for nullable date fields. Only
affects SQLite. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9466 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
98ec741a03
commit
9d0bacebd2
|
@ -101,7 +101,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
return [first % value, second % value]
|
return [first % value, second % value]
|
||||||
|
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
|
|
||||||
# SQLite requires LIKE statements to include an ESCAPE clause if the value
|
# SQLite requires LIKE statements to include an ESCAPE clause if the value
|
||||||
# being escaped has a percent or underscore in it.
|
# being escaped has a percent or underscore in it.
|
||||||
# See http://www.sqlite.org/lang_expr.html for an explanation.
|
# See http://www.sqlite.org/lang_expr.html for an explanation.
|
||||||
|
@ -124,7 +124,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
super(DatabaseWrapper, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.features = DatabaseFeatures()
|
self.features = DatabaseFeatures()
|
||||||
self.ops = DatabaseOperations()
|
self.ops = DatabaseOperations()
|
||||||
self.client = DatabaseClient()
|
self.client = DatabaseClient()
|
||||||
|
@ -179,6 +179,8 @@ class SQLiteCursorWrapper(Database.Cursor):
|
||||||
return query % tuple("?" * num_params)
|
return query % tuple("?" * num_params)
|
||||||
|
|
||||||
def _sqlite_extract(lookup_type, dt):
|
def _sqlite_extract(lookup_type, dt):
|
||||||
|
if dt is None:
|
||||||
|
return None
|
||||||
try:
|
try:
|
||||||
dt = util.typecast_timestamp(dt)
|
dt = util.typecast_timestamp(dt)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Movie(models.Model):
|
||||||
name = models.CharField(max_length=60)
|
name = models.CharField(max_length=60)
|
||||||
|
|
||||||
class Party(models.Model):
|
class Party(models.Model):
|
||||||
when = models.DateField()
|
when = models.DateField(null=True)
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
when = models.DateTimeField()
|
when = models.DateTimeField()
|
||||||
|
@ -93,6 +93,16 @@ u''
|
||||||
>>> [p.when for p in Party.objects.filter(when__year='1998')]
|
>>> [p.when for p in Party.objects.filter(when__year='1998')]
|
||||||
[datetime.date(1998, 12, 31)]
|
[datetime.date(1998, 12, 31)]
|
||||||
|
|
||||||
|
# Date filtering was failing with NULL date values in SQLite (regression test
|
||||||
|
# for #3501, amongst other things).
|
||||||
|
>>> _ = Party.objects.create()
|
||||||
|
>>> p = Party.objects.filter(when__month=1)[0]
|
||||||
|
>>> p.when
|
||||||
|
datetime.date(1999, 1, 1)
|
||||||
|
>>> l = Party.objects.filter(pk=p.pk).dates("when", "month")
|
||||||
|
>>> l[0].month == 1
|
||||||
|
True
|
||||||
|
|
||||||
# Check that get_next_by_FIELD and get_previous_by_FIELD don't crash when we
|
# Check that get_next_by_FIELD and get_previous_by_FIELD don't crash when we
|
||||||
# have usecs values stored on the database
|
# have usecs values stored on the database
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue