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
This commit is contained in:
Adrian Holovaty 2009-03-11 03:39:34 +00:00
parent 7daf0b9407
commit 315145f7ca
12 changed files with 115 additions and 92 deletions

View file

@ -1,19 +1,19 @@
from django.db.backends import BaseDatabaseClient
from django.conf import settings
import os
class DatabaseClient(BaseDatabaseClient):
executable_name = 'psql'
def runshell(self):
settings_dict = self.connection.settings_dict
args = [self.executable_name]
if settings.DATABASE_USER:
args += ["-U", settings.DATABASE_USER]
if settings.DATABASE_PASSWORD:
if settings_dict['DATABASE_USER']:
args += ["-U", settings_dict['DATABASE_USER']]
if settings_dict['DATABASE_PASSWORD']:
args += ["-W"]
if settings.DATABASE_HOST:
args.extend(["-h", settings.DATABASE_HOST])
if settings.DATABASE_PORT:
args.extend(["-p", str(settings.DATABASE_PORT)])
args += [settings.DATABASE_NAME]
if settings_dict['DATABASE_HOST']:
args.extend(["-h", settings_dict['DATABASE_HOST']])
if settings_dict['DATABASE_PORT']:
args.extend(["-p", str(settings_dict['DATABASE_PORT'])])
args += [settings_dict['DATABASE_NAME']]
os.execvp(self.executable_name, args)