From 06315375ce5c6477b7498026177b7e715372a7d1 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 16 Jun 2008 03:15:04 +0000 Subject: [PATCH] Fixed #7420 -- Abstracted some more database options into DatabaseFeatures -- supports_usecs, time_field_needs_date, interprets_empty_strings_as_nulls and date_field_supports_time_value -- and changed various hard-coded 'if DATABASE_BACKEND == oracle' statements to use the new options. Thanks to ramiro for the patch git-svn-id: http://code.djangoproject.com/svn/django/trunk@7643 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/__init__.py | 9 ++++++++ django/db/backends/mysql/base.py | 1 + django/db/backends/mysql_old/base.py | 1 + django/db/backends/oracle/base.py | 3 +++ django/db/models/fields/__init__.py | 32 ++++++++++++++-------------- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index b076e290dd..63a6435bdb 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -52,6 +52,10 @@ class BaseDatabaseFeatures(object): uses_custom_query_class = False empty_fetchmany_value = [] update_can_self_select = True + supports_usecs = True + time_field_needs_date = False + interprets_empty_strings_as_nulls = False + date_field_supports_time_value = True class BaseDatabaseOperations(object): """ @@ -266,3 +270,8 @@ class BaseDatabaseOperations(object): tablespaces. """ return None + + def prep_for_like_query(self, x): + """Prepares a value for use in a LIKE query.""" + from django.utils.encoding import smart_unicode + return smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index da57ecbe47..23735a023b 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -64,6 +64,7 @@ class DatabaseFeatures(BaseDatabaseFeatures): inline_fk_references = False empty_fetchmany_value = () update_can_self_select = False + supports_usecs = False class DatabaseOperations(BaseDatabaseOperations): def date_extract_sql(self, lookup_type, field_name): diff --git a/django/db/backends/mysql_old/base.py b/django/db/backends/mysql_old/base.py index 0ae114d176..e57aee6a04 100644 --- a/django/db/backends/mysql_old/base.py +++ b/django/db/backends/mysql_old/base.py @@ -68,6 +68,7 @@ class DatabaseFeatures(BaseDatabaseFeatures): inline_fk_references = False empty_fetchmany_value = () update_can_self_select = False + supports_usecs = False class DatabaseOperations(BaseDatabaseOperations): def date_extract_sql(self, lookup_type, field_name): diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 3635acdf2a..a1a9fb1c73 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -31,6 +31,9 @@ class DatabaseFeatures(BaseDatabaseFeatures): supports_tablespaces = True uses_case_insensitive_names = True uses_custom_query_class = True + time_field_needs_date = True + interprets_empty_strings_as_nulls = True + date_field_supports_time_value = False class DatabaseOperations(BaseDatabaseOperations): def autoinc_sql(self, table, column): diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 88033756ee..96bb466c7b 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -7,7 +7,7 @@ try: except ImportError: from django.utils import _decimal as decimal # for Python 2.3 -from django.db import get_creation_module +from django.db import connection, get_creation_module from django.db.models import signals from django.db.models.query_utils import QueryWrapper from django.dispatch import dispatcher @@ -33,9 +33,6 @@ HORIZONTAL, VERTICAL = 1, 2 BLANK_CHOICE_DASH = [("", "---------")] BLANK_CHOICE_NONE = [("", "None")] -# prepares a value for use in a LIKE query -prep_for_like_query = lambda x: smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") - # returns the