From 0813aa46142bf1ff77b4478d4d620a2117f70d81 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 7 Jun 2010 17:53:14 +0000 Subject: [PATCH] [soc2010/query-refactor] Altered the base database backend class to not have anything more than the bare minimum. Also add the bare beginnings for a mongodb backend. git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13330 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/mongodb/README | 5 +++++ django/contrib/mongodb/__init__.py | 0 django/contrib/mongodb/base.py | 5 +++++ django/db/backends/__init__.py | 12 +++++++++--- django/db/backends/mysql/base.py | 4 ++-- django/db/backends/oracle/base.py | 2 +- django/db/backends/postgresql/base.py | 2 +- django/db/backends/postgresql_psycopg2/base.py | 2 +- django/db/backends/sqlite3/base.py | 4 ++-- 9 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 django/contrib/mongodb/README create mode 100644 django/contrib/mongodb/__init__.py create mode 100644 django/contrib/mongodb/base.py diff --git a/django/contrib/mongodb/README b/django/contrib/mongodb/README new file mode 100644 index 0000000000..c1fbf2679e --- /dev/null +++ b/django/contrib/mongodb/README @@ -0,0 +1,5 @@ +NOTE +==== + +This backend lives here for conveinience purposes during the 2010 GSOC. This +is not it's permanent location (nor should you probably be using it all). diff --git a/django/contrib/mongodb/__init__.py b/django/contrib/mongodb/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/django/contrib/mongodb/base.py b/django/contrib/mongodb/base.py new file mode 100644 index 0000000000..6a65e96031 --- /dev/null +++ b/django/contrib/mongodb/base.py @@ -0,0 +1,5 @@ +from django.db.backends import BaseDatabaseWrapper + + +class DatabaseWrapper(BaseDatabaseWrapper): + pass diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index fe2c7c451b..cbd3307f04 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -10,13 +10,10 @@ class BaseDatabaseWrapper(local): """ Represents a database connection. """ - ops = None - def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS): # `settings_dict` should be a dictionary containing keys such as # 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 @@ -27,6 +24,14 @@ class BaseDatabaseWrapper(local): def __ne__(self, other): return not self == other + +class BaseSQLDatabaseWrapper(BaseDatabaseWrapper): + ops = None + + def __init__(self, *args, **kwargs): + self.connection = None + super(BaseSQLDatabaseWrapper, self).__init__(*args, **kwargs) + def _commit(self): if self.connection is not None: return self.connection.commit() @@ -80,6 +85,7 @@ class BaseDatabaseWrapper(local): def make_debug_cursor(self, cursor): return util.CursorDebugWrapper(cursor, self) + class BaseDatabaseFeatures(object): allows_group_by_pk = False # True if django.db.backend.utils.typecast_timestamp is used on values diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index e94e24bff9..09d5ca04a7 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -230,7 +230,7 @@ class DatabaseOperations(BaseDatabaseOperations): def max_name_length(self): return 64 -class DatabaseWrapper(BaseDatabaseWrapper): +class DatabaseWrapper(BaseSQLDatabaseWrapper): operators = { 'exact': '= %s', @@ -303,7 +303,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): def _rollback(self): try: - BaseDatabaseWrapper._rollback(self) + super(DatabaseWrapper, self)._rollback() except Database.NotSupportedError: pass diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 369e65baf7..b44681c8c8 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -310,7 +310,7 @@ WHEN (new.%(col_name)s IS NULL) return super(DatabaseOperations, self).combine_expression(connector, sub_expressions) -class DatabaseWrapper(BaseDatabaseWrapper): +class DatabaseWrapper(BaseSQLDatabaseWrapper): operators = { 'exact': '= %s', diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index a1c858bd8f..1494ae426a 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -81,7 +81,7 @@ class UnicodeCursorWrapper(object): class DatabaseFeatures(BaseDatabaseFeatures): uses_savepoints = True -class DatabaseWrapper(BaseDatabaseWrapper): +class DatabaseWrapper(BaseSQLDatabaseWrapper): operators = { 'exact': '= %s', 'iexact': '= UPPER(%s)', diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index 29b7e7ff1a..484c85056d 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -78,7 +78,7 @@ class DatabaseOperations(PostgresqlDatabaseOperations): def return_insert_id(self): return "RETURNING %s", () -class DatabaseWrapper(BaseDatabaseWrapper): +class DatabaseWrapper(BaseSQLDatabaseWrapper): operators = { 'exact': '= %s', 'iexact': '= UPPER(%s)', diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index bc97f5cfd8..3ef3fab72a 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -128,7 +128,7 @@ class DatabaseOperations(BaseDatabaseOperations): # No field, or the field isn't known to be a decimal or integer return value -class DatabaseWrapper(BaseDatabaseWrapper): +class DatabaseWrapper(BaseSQLDatabaseWrapper): # SQLite requires LIKE statements to include an ESCAPE clause if the value # being escaped has a percent or underscore in it. @@ -184,7 +184,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): # database. To prevent accidental data loss, ignore close requests on # an in-memory db. if self.settings_dict['NAME'] != ":memory:": - BaseDatabaseWrapper.close(self) + super(DatabaseWrapper, self).close() FORMAT_QMARK_REGEX = re.compile(r'(?![^%])%s')