From cc4e4d9aee0b3ebfb45bee01aec79edc9e144c78 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 15 Jan 2009 11:06:34 +0000 Subject: Fixed #3566 -- Added support for aggregation to the ORM. See the documentation for details on usage. Many thanks to: * Nicolas Lara, who worked on this feature during the 2008 Google Summer of Code. * Alex Gaynor for his help debugging and fixing a number of issues. * Justin Bronn for his help integrating with contrib.gis. * Karen Tracey for her help with cross-platform testing. * Ian Kelly for his help testing and fixing Oracle support. * Malcolm Tredinnick for his invaluable review notes. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9742 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/sqlite3/base.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'django/db/backends/sqlite3') diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 15b0e983ad..071d421b58 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -10,7 +10,7 @@ from django.db.backends import * from django.db.backends.sqlite3.client import DatabaseClient from django.db.backends.sqlite3.creation import DatabaseCreation from django.db.backends.sqlite3.introspection import DatabaseIntrospection -from django.utils.safestring import SafeString +from django.utils.safestring import SafeString try: try: @@ -102,6 +102,26 @@ class DatabaseOperations(BaseDatabaseOperations): second = '%s-12-31 23:59:59.999999' return [first % value, second % value] + def convert_values(self, value, field): + """SQLite returns floats when it should be returning decimals, + and gets dates and datetimes wrong. + For consistency with other backends, coerce when required. + """ + internal_type = field.get_internal_type() + if internal_type == 'DecimalField': + return util.typecast_decimal(field.format_number(value)) + elif internal_type and internal_type.endswith('IntegerField') or internal_type == 'AutoField': + return int(value) + elif internal_type == 'DateField': + return util.typecast_date(value) + elif internal_type == 'DateTimeField': + return util.typecast_timestamp(value) + elif internal_type == 'TimeField': + return util.typecast_time(value) + + # No field, or the field isn't known to be a decimal or integer + return value + class DatabaseWrapper(BaseDatabaseWrapper): # SQLite requires LIKE statements to include an ESCAPE clause if the value -- cgit v1.3