1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

[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
This commit is contained in:
Alex Gaynor 2010-06-07 17:53:14 +00:00
parent a61b34b048
commit 0813aa4614
9 changed files with 26 additions and 10 deletions

View File

@ -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).

View File

View File

@ -0,0 +1,5 @@
from django.db.backends import BaseDatabaseWrapper
class DatabaseWrapper(BaseDatabaseWrapper):
pass

View File

@ -10,13 +10,10 @@ class BaseDatabaseWrapper(local):
""" """
Represents a database connection. Represents a database connection.
""" """
ops = None
def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS): def __init__(self, settings_dict, alias=DEFAULT_DB_ALIAS):
# `settings_dict` should be a dictionary containing keys such as # `settings_dict` should be a dictionary containing keys such as
# NAME, USER, etc. It's called `settings_dict` instead of `settings` # NAME, USER, etc. It's called `settings_dict` instead of `settings`
# to disambiguate it from Django settings modules. # to disambiguate it from Django settings modules.
self.connection = None
self.queries = [] self.queries = []
self.settings_dict = settings_dict self.settings_dict = settings_dict
self.alias = alias self.alias = alias
@ -27,6 +24,14 @@ class BaseDatabaseWrapper(local):
def __ne__(self, other): def __ne__(self, other):
return not 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): def _commit(self):
if self.connection is not None: if self.connection is not None:
return self.connection.commit() return self.connection.commit()
@ -80,6 +85,7 @@ class BaseDatabaseWrapper(local):
def make_debug_cursor(self, cursor): def make_debug_cursor(self, cursor):
return util.CursorDebugWrapper(cursor, self) return util.CursorDebugWrapper(cursor, self)
class BaseDatabaseFeatures(object): class BaseDatabaseFeatures(object):
allows_group_by_pk = False allows_group_by_pk = False
# True if django.db.backend.utils.typecast_timestamp is used on values # True if django.db.backend.utils.typecast_timestamp is used on values

View File

@ -230,7 +230,7 @@ class DatabaseOperations(BaseDatabaseOperations):
def max_name_length(self): def max_name_length(self):
return 64 return 64
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseSQLDatabaseWrapper):
operators = { operators = {
'exact': '= %s', 'exact': '= %s',
@ -303,7 +303,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
def _rollback(self): def _rollback(self):
try: try:
BaseDatabaseWrapper._rollback(self) super(DatabaseWrapper, self)._rollback()
except Database.NotSupportedError: except Database.NotSupportedError:
pass pass

View File

@ -310,7 +310,7 @@ WHEN (new.%(col_name)s IS NULL)
return super(DatabaseOperations, self).combine_expression(connector, sub_expressions) return super(DatabaseOperations, self).combine_expression(connector, sub_expressions)
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseSQLDatabaseWrapper):
operators = { operators = {
'exact': '= %s', 'exact': '= %s',

View File

@ -81,7 +81,7 @@ class UnicodeCursorWrapper(object):
class DatabaseFeatures(BaseDatabaseFeatures): class DatabaseFeatures(BaseDatabaseFeatures):
uses_savepoints = True uses_savepoints = True
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseSQLDatabaseWrapper):
operators = { operators = {
'exact': '= %s', 'exact': '= %s',
'iexact': '= UPPER(%s)', 'iexact': '= UPPER(%s)',

View File

@ -78,7 +78,7 @@ class DatabaseOperations(PostgresqlDatabaseOperations):
def return_insert_id(self): def return_insert_id(self):
return "RETURNING %s", () return "RETURNING %s", ()
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseSQLDatabaseWrapper):
operators = { operators = {
'exact': '= %s', 'exact': '= %s',
'iexact': '= UPPER(%s)', 'iexact': '= UPPER(%s)',

View File

@ -128,7 +128,7 @@ class DatabaseOperations(BaseDatabaseOperations):
# No field, or the field isn't known to be a decimal or integer # No field, or the field isn't known to be a decimal or integer
return value return value
class DatabaseWrapper(BaseDatabaseWrapper): class DatabaseWrapper(BaseSQLDatabaseWrapper):
# SQLite requires LIKE statements to include an ESCAPE clause if the value # SQLite requires LIKE statements to include an ESCAPE clause if the value
# being escaped has a percent or underscore in it. # 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 # database. To prevent accidental data loss, ignore close requests on
# an in-memory db. # an in-memory db.
if self.settings_dict['NAME'] != ":memory:": if self.settings_dict['NAME'] != ":memory:":
BaseDatabaseWrapper.close(self) super(DatabaseWrapper, self).close()
FORMAT_QMARK_REGEX = re.compile(r'(?![^%])%s') FORMAT_QMARK_REGEX = re.compile(r'(?![^%])%s')