Ticket #12818: 12818.2.diff
File 12818.2.diff, 4.0 KB (added by , 15 years ago) |
---|
-
django/db/backends/sqlite3/base.py
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index a9b1aa3..8ddb736 100644
a b class DatabaseFeatures(BaseDatabaseFeatures): 63 63 class DatabaseOperations(BaseDatabaseOperations): 64 64 def date_extract_sql(self, lookup_type, field_name): 65 65 # sqlite doesn't support extract, so we fake it with the user-defined 66 # function django_extract that's registered in connect(). 67 return 'django_extract("%s", %s)' % (lookup_type.lower(), field_name) 66 # function django_extract that's registered in connect(). Note that 67 # single quotes are used because this is a string (and could otherwise 68 # cause a collision with a field name). 69 return "django_extract('%s', %s)" % (lookup_type.lower(), field_name) 68 70 69 71 def date_trunc_sql(self, lookup_type, field_name): 70 72 # sqlite doesn't support DATE_TRUNC, so we fake it with a user-defined 71 # function django_date_trunc that's registered in connect(). 72 return 'django_date_trunc("%s", %s)' % (lookup_type.lower(), field_name) 73 # function django_date_trunc that's registered in connect(). Note that 74 # single quotes are used because this is a string (and could otherwise 75 # cause a collision with a field name). 76 return "django_date_trunc('%s', %s)" % (lookup_type.lower(), field_name) 73 77 74 78 def drop_foreignkey_sql(self): 75 79 return "" -
tests/regressiontests/backends/models.py
diff --git a/tests/regressiontests/backends/models.py b/tests/regressiontests/backends/models.py index 61b7b1a..423bead 100644
a b class Person(models.Model): 15 15 def __unicode__(self): 16 16 return u'%s %s' % (self.first_name, self.last_name) 17 17 18 class SchoolClass(models.Model): 19 year = models.PositiveIntegerField() 20 day = models.CharField(max_length=9, blank=True) 21 last_updated = models.DateTimeField() 22 18 23 qn = connection.ops.quote_name 19 24 20 25 __test__ = {'API_TESTS': """ -
tests/regressiontests/backends/tests.py
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py index e4fa824..7c5856e 100644
a b 1 1 # -*- coding: utf-8 -*- 2 2 # Unit and doctests for specific database backends. 3 import datetime 4 import models 3 5 import unittest 4 6 from django.db import backend, connection, DEFAULT_DB_ALIAS 5 7 from django.db.backends.signals import connection_created 6 8 from django.conf import settings 9 from django.test import TestCase 7 10 8 11 class Callproc(unittest.TestCase): 9 12 … … class LongString(unittest.TestCase): 33 36 row = c.fetchone() 34 37 c.execute('DROP TABLE ltext') 35 38 self.assertEquals(long_str, row[0].read()) 39 40 class DateQuotingTest(TestCase): 41 42 def test_django_date_trunc(self): 43 """ 44 Test the custom ``django_date_trunc method``, in particular against 45 fields which clash with strings passed to it (e.g. 'year') - see 46 #12818__. 47 48 __: http://code.djangoproject.com/ticket/12818 49 50 """ 51 updated = datetime.datetime(2010, 2, 20) 52 models.SchoolClass.objects.create(year=2009, last_updated=updated) 53 years = models.SchoolClass.objects.dates('last_updated', 'year') 54 self.assertEqual(list(years), [datetime.datetime(2010, 1, 1, 0, 0)]) 55 56 def test_django_extract(self): 57 """ 58 Test the custom ``django_extract method``, in particular against fields 59 which clash with strings passed to it (e.g. 'day') - see #12818__. 60 61 __: http://code.djangoproject.com/ticket/12818 62 63 """ 64 updated = datetime.datetime(2010, 2, 20) 65 models.SchoolClass.objects.create(year=2009, last_updated=updated) 66 classes = models.SchoolClass.objects.filter(last_updated__day=20) 67 self.assertEqual(len(classes), 1) 36 68 37 69 def connection_created_test(sender, **kwargs): 38 70 print 'connection_created signal'