Fixed #2866: Added DATABASE_OPTIONS setting which gets passed as extra kwargs to the backend's connect method. Thanks, ymasuda.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4048 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
afb2366430
commit
fef89a01c5
|
@ -101,6 +101,7 @@ DATABASE_USER = '' # Not used with sqlite3.
|
|||
DATABASE_PASSWORD = '' # Not used with sqlite3.
|
||||
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
|
||||
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
|
||||
DATABASE_OPTIONS = {} # Set to empy dictionary for default.
|
||||
|
||||
# Host for sending e-mail.
|
||||
EMAIL_HOST = 'localhost'
|
||||
|
|
|
@ -6,6 +6,8 @@ __all__ = ('backend', 'connection', 'DatabaseError')
|
|||
|
||||
if not settings.DATABASE_ENGINE:
|
||||
settings.DATABASE_ENGINE = 'dummy'
|
||||
if not settings.DATABASE_OPTIONS:
|
||||
settings.DATABASE_OPTIONS = {}
|
||||
|
||||
try:
|
||||
backend = __import__('django.db.backends.%s.base' % settings.DATABASE_ENGINE, {}, {}, [''])
|
||||
|
@ -27,7 +29,7 @@ get_introspection_module = lambda: __import__('django.db.backends.%s.introspecti
|
|||
get_creation_module = lambda: __import__('django.db.backends.%s.creation' % settings.DATABASE_ENGINE, {}, {}, [''])
|
||||
runshell = lambda: __import__('django.db.backends.%s.client' % settings.DATABASE_ENGINE, {}, {}, ['']).runshell()
|
||||
|
||||
connection = backend.DatabaseWrapper()
|
||||
connection = backend.DatabaseWrapper(**settings.DATABASE_OPTIONS)
|
||||
DatabaseError = backend.DatabaseError
|
||||
|
||||
# Register an event that closes the database connection
|
||||
|
|
|
@ -55,7 +55,7 @@ except ImportError:
|
|||
from django.utils._threading_local import local
|
||||
|
||||
class DatabaseWrapper(local):
|
||||
def __init__(self):
|
||||
def __init__(self, **kwargs):
|
||||
self.connection = None
|
||||
self.queries = []
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ class DatabaseWrapper:
|
|||
_commit = complain
|
||||
_rollback = complain
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
pass
|
||||
|
||||
def close(self):
|
||||
pass # close()
|
||||
|
||||
|
|
|
@ -65,10 +65,11 @@ except ImportError:
|
|||
from django.utils._threading_local import local
|
||||
|
||||
class DatabaseWrapper(local):
|
||||
def __init__(self):
|
||||
def __init__(self, **kwargs):
|
||||
self.connection = None
|
||||
self.queries = []
|
||||
self.server_version = None
|
||||
self.options = kwargs
|
||||
|
||||
def _valid_connection(self):
|
||||
if self.connection is not None:
|
||||
|
@ -95,6 +96,7 @@ class DatabaseWrapper(local):
|
|||
kwargs['host'] = settings.DATABASE_HOST
|
||||
if settings.DATABASE_PORT:
|
||||
kwargs['port'] = int(settings.DATABASE_PORT)
|
||||
kwargs.update(self.options)
|
||||
self.connection = Database.connect(**kwargs)
|
||||
cursor = self.connection.cursor()
|
||||
if self.connection.get_server_info() >= '4.1':
|
||||
|
|
|
@ -21,9 +21,10 @@ except ImportError:
|
|||
from django.utils._threading_local import local
|
||||
|
||||
class DatabaseWrapper(local):
|
||||
def __init__(self):
|
||||
def __init__(self, **kwargs):
|
||||
self.connection = None
|
||||
self.queries = []
|
||||
self.options = kwargs
|
||||
|
||||
def _valid_connection(self):
|
||||
return self.connection is not None
|
||||
|
@ -35,10 +36,10 @@ class DatabaseWrapper(local):
|
|||
settings.DATABASE_HOST = 'localhost'
|
||||
if len(settings.DATABASE_PORT.strip()) != 0:
|
||||
dsn = Database.makedsn(settings.DATABASE_HOST, int(settings.DATABASE_PORT), settings.DATABASE_NAME)
|
||||
self.connection = Database.connect(settings.DATABASE_USER, settings.DATABASE_PASSWORD, dsn)
|
||||
self.connection = Database.connect(settings.DATABASE_USER, settings.DATABASE_PASSWORD, dsn, **self.options)
|
||||
else:
|
||||
conn_string = "%s/%s@%s" % (settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME)
|
||||
self.connection = Database.connect(conn_string)
|
||||
self.connection = Database.connect(conn_string, **self.options)
|
||||
return FormatStylePlaceholderCursor(self.connection)
|
||||
|
||||
def _commit(self):
|
||||
|
|
|
@ -21,9 +21,10 @@ except ImportError:
|
|||
from django.utils._threading_local import local
|
||||
|
||||
class DatabaseWrapper(local):
|
||||
def __init__(self):
|
||||
def __init__(self, **kwargs):
|
||||
self.connection = None
|
||||
self.queries = []
|
||||
self.options = kwargs
|
||||
|
||||
def cursor(self):
|
||||
from django.conf import settings
|
||||
|
@ -40,7 +41,7 @@ class DatabaseWrapper(local):
|
|||
conn_string += " host=%s" % settings.DATABASE_HOST
|
||||
if settings.DATABASE_PORT:
|
||||
conn_string += " port=%s" % settings.DATABASE_PORT
|
||||
self.connection = Database.connect(conn_string)
|
||||
self.connection = Database.connect(conn_string, **self.options)
|
||||
self.connection.set_isolation_level(1) # make transactions transparent to all cursors
|
||||
cursor = self.connection.cursor()
|
||||
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
|
||||
|
|
|
@ -21,9 +21,10 @@ except ImportError:
|
|||
from django.utils._threading_local import local
|
||||
|
||||
class DatabaseWrapper(local):
|
||||
def __init__(self):
|
||||
def __init__(self, **kwargs):
|
||||
self.connection = None
|
||||
self.queries = []
|
||||
self.options = kwargs
|
||||
|
||||
def cursor(self):
|
||||
from django.conf import settings
|
||||
|
@ -40,7 +41,7 @@ class DatabaseWrapper(local):
|
|||
conn_string += " host=%s" % settings.DATABASE_HOST
|
||||
if settings.DATABASE_PORT:
|
||||
conn_string += " port=%s" % settings.DATABASE_PORT
|
||||
self.connection = Database.connect(conn_string)
|
||||
self.connection = Database.connect(conn_string, **self.options)
|
||||
self.connection.set_isolation_level(1) # make transactions transparent to all cursors
|
||||
cursor = self.connection.cursor()
|
||||
cursor.tzinfo_factory = None
|
||||
|
|
|
@ -42,16 +42,20 @@ except ImportError:
|
|||
from django.utils._threading_local import local
|
||||
|
||||
class DatabaseWrapper(local):
|
||||
def __init__(self):
|
||||
def __init__(self, **kwargs):
|
||||
self.connection = None
|
||||
self.queries = []
|
||||
self.options = kwargs
|
||||
|
||||
def cursor(self):
|
||||
from django.conf import settings
|
||||
if self.connection is None:
|
||||
self.connection = Database.connect(settings.DATABASE_NAME,
|
||||
detect_types=Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES)
|
||||
|
||||
kwargs = {
|
||||
'database': settings.DATABASE_NAME,
|
||||
'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
|
||||
}
|
||||
kwargs.update(self.options)
|
||||
self.connection = Database.connect(**kwargs)
|
||||
# Register extract and date_trunc functions.
|
||||
self.connection.create_function("django_extract", 2, _sqlite_extract)
|
||||
self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
|
||||
|
|
|
@ -265,6 +265,14 @@ Default: ``''`` (Empty string)
|
|||
The name of the database to use. For SQLite, it's the full path to the database
|
||||
file.
|
||||
|
||||
DATABASE_OPTIONS
|
||||
----------------
|
||||
|
||||
Default: ``{}`` (Empty dictionary)
|
||||
|
||||
Extra parameters to use when connecting to the database. Consult backend
|
||||
module's document for available keywords.
|
||||
|
||||
DATABASE_PASSWORD
|
||||
-----------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue