diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-12-22 15:18:51 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-12-22 15:18:51 +0000 |
| commit | ff60c5f9de3e8690d1e86f3e9e3f7248a15397c8 (patch) | |
| tree | a4cb0ebdd55fcaf8c8855231b6ad3e1a7bf45bee /django/db/backends/__init__.py | |
| parent | 7ef212af149540aa2da577a960d0d87029fd1514 (diff) | |
Fixed #1142 -- Added multiple database support.
This monster of a patch is the result of Alex Gaynor's 2009 Google Summer of Code project.
Congratulations to Alex for a job well done.
Big thanks also go to:
* Justin Bronn for keeping GIS in line with the changes,
* Karen Tracey and Jani Tiainen for their help testing Oracle support
* Brett Hoerner, Jon Loyens, and Craig Kimmerer for their feedback.
* Malcolm Treddinick for his guidance during the GSoC submission process.
* Simon Willison for driving the original design process
* Cal Henderson for complaining about ponies he wanted.
... and everyone else too numerous to mention that helped to bring this feature into fruition.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11952 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/__init__.py')
| -rw-r--r-- | django/db/backends/__init__.py | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 9a1fe30925..bf3e9db15a 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -1,37 +1,31 @@ -try: - # Only exists in Python 2.4+ - from threading import local -except ImportError: - # Import copy of _thread_local.py from Python 2.4 - from django.utils._threading_local import local -try: - set -except NameError: - # Python 2.3 compat - from sets import Set as set - -try: - import decimal -except ImportError: - # Python 2.3 fallback - from django.utils import _decimal as decimal +import decimal +from threading import local +from django.db import DEFAULT_DB_ALIAS from django.db.backends import util from django.utils import datetime_safe +from django.utils.importlib import import_module class BaseDatabaseWrapper(local): """ Represents a database connection. """ ops = None - def __init__(self, settings_dict): + + def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS): # `settings_dict` should be a dictionary containing keys such as - # DATABASE_NAME, DATABASE_USER, etc. It's called `settings_dict` - # instead of `settings` to disambiguate it from Django settings - # modules. + # NAME, USER, etc. It's called `settings_dict` instead of `settings` + # to disambiguate it from Django settings modules. self.connection = None self.queries = [] self.settings_dict = settings_dict + self.alias = alias + + def __eq__(self, other): + return self.settings_dict == other.settings_dict + + def __ne__(self, other): + return not self == other def _commit(self): if self.connection is not None: @@ -91,7 +85,6 @@ class BaseDatabaseFeatures(object): # True if django.db.backend.utils.typecast_timestamp is used on values # returned from dates() calls. needs_datetime_string_cast = True - uses_custom_query_class = False empty_fetchmany_value = [] update_can_self_select = True interprets_empty_strings_as_nulls = False @@ -109,6 +102,11 @@ class BaseDatabaseOperations(object): a backend performs ordering or calculates the ID of a recently-inserted row. """ + compiler_module = "django.db.models.sql.compiler" + + def __init__(self): + self._cache = {} + def autoinc_sql(self, table, column): """ Returns any SQL needed to support auto-incrementing primary keys, or @@ -271,14 +269,17 @@ class BaseDatabaseOperations(object): """ pass - def query_class(self, DefaultQueryClass): + def compiler(self, compiler_name): """ - Given the default Query class, returns a custom Query class - to use for this backend. Returns None if a custom Query isn't used. - See also BaseDatabaseFeatures.uses_custom_query_class, which regulates - whether this method is called at all. + Returns the SQLCompiler class corresponding to the given name, + in the namespace corresponding to the `compiler_module` attribute + on this backend. """ - return None + if compiler_name not in self._cache: + self._cache[compiler_name] = getattr( + import_module(self.compiler_module), compiler_name + ) + return self._cache[compiler_name] def quote_name(self, name): """ @@ -565,6 +566,9 @@ class BaseDatabaseValidation(object): """ This class encapsualtes all backend-specific model validation. """ + def __init__(self, connection): + self.connection = connection + def validate_field(self, errors, opts, f): "By default, there is no backend-specific validation" pass |
