summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2009-03-11 03:39:34 +0000
committerAdrian Holovaty <adrian@holovaty.com>2009-03-11 03:39:34 +0000
commit315145f7ca682f8361d956e985f533a7fb421cde (patch)
tree959f7bac4d8356e4b900227646eace9f7c05ab48 /django/db/backends/sqlite3
parent7daf0b94070ab29419825156ec68bca813e3c09f (diff)
Fixed #10459 -- Refactored the internals of database connection objects so that connections know their own settings and pass around settings as dictionaries instead of passing around the Django settings module itself. This will make it easier for multiple database support. Thanks to Alex Gaynor for the initial patch.
This is backwards-compatible but will likely break third-party database backends. Specific API changes are: * BaseDatabaseWrapper.__init__() now takes a settings_dict instead of a settings module. It's called settings_dict to disambiguate, and for easy grepability. This should be a dictionary containing DATABASE_NAME, etc. * BaseDatabaseWrapper has a settings_dict attribute instead of an options attribute. BaseDatabaseWrapper.options is now BaseDatabaseWrapper['DATABASE_OPTIONS'] * BaseDatabaseWrapper._cursor() no longer takes a settings argument. * BaseDatabaseClient.__init__() now takes a connection argument (a DatabaseWrapper instance) instead of no arguments. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10026 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/sqlite3')
-rw-r--r--django/db/backends/sqlite3/base.py14
-rw-r--r--django/db/backends/sqlite3/client.py3
2 files changed, 8 insertions, 9 deletions
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index ba0ef16b61..b0c087d1cd 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -149,21 +149,22 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.features = DatabaseFeatures()
self.ops = DatabaseOperations()
- self.client = DatabaseClient()
+ self.client = DatabaseClient(self)
self.creation = DatabaseCreation(self)
self.introspection = DatabaseIntrospection(self)
self.validation = BaseDatabaseValidation()
- def _cursor(self, settings):
+ def _cursor(self):
if self.connection is None:
- if not settings.DATABASE_NAME:
+ settings_dict = self.settings_dict
+ if not settings_dict['DATABASE_NAME']:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured, "Please fill out DATABASE_NAME in the settings module before using the database."
kwargs = {
- 'database': settings.DATABASE_NAME,
+ 'database': settings_dict['DATABASE_NAME'],
'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
}
- kwargs.update(self.options)
+ kwargs.update(settings_dict['DATABASE_OPTIONS'])
self.connection = Database.connect(**kwargs)
# Register extract, date_trunc, and regexp functions.
self.connection.create_function("django_extract", 2, _sqlite_extract)
@@ -172,11 +173,10 @@ class DatabaseWrapper(BaseDatabaseWrapper):
return self.connection.cursor(factory=SQLiteCursorWrapper)
def close(self):
- from django.conf import settings
# If database is in memory, closing the connection destroys the
# database. To prevent accidental data loss, ignore close requests on
# an in-memory db.
- if settings.DATABASE_NAME != ":memory:":
+ if self.settings_dict['DATABASE_NAME'] != ":memory:":
BaseDatabaseWrapper.close(self)
class SQLiteCursorWrapper(Database.Cursor):
diff --git a/django/db/backends/sqlite3/client.py b/django/db/backends/sqlite3/client.py
index 239e72f1e9..0b65444d74 100644
--- a/django/db/backends/sqlite3/client.py
+++ b/django/db/backends/sqlite3/client.py
@@ -1,10 +1,9 @@
from django.db.backends import BaseDatabaseClient
-from django.conf import settings
import os
class DatabaseClient(BaseDatabaseClient):
executable_name = 'sqlite3'
def runshell(self):
- args = ['', settings.DATABASE_NAME]
+ args = ['', self.connection.settings_dict['DATABASE_NAME']]
os.execvp(self.executable_name, args)