Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #2866: Added DATABASE_OPTIONS setting which gets passed as extr…

…a 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
  • Loading branch information...
commit fef89a01c542701d73072ed22651f3be29ef1507 1 parent afb2366
@jacobian jacobian authored
View
1  django/conf/global_settings.py
@@ -101,6 +101,7 @@
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'
View
4 django/db/__init__.py
@@ -6,6 +6,8 @@
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_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
View
2  django/db/backends/ado_mssql/base.py
@@ -55,7 +55,7 @@ def variantToPython(variant, adType):
from django.utils._threading_local import local
class DatabaseWrapper(local):
- def __init__(self):
+ def __init__(self, **kwargs):
self.connection = None
self.queries = []
View
3  django/db/backends/dummy/base.py
@@ -20,6 +20,9 @@ class DatabaseWrapper:
_commit = complain
_rollback = complain
+ def __init__(self, **kwargs):
+ pass
+
def close(self):
pass # close()
View
4 django/db/backends/mysql/base.py
@@ -65,10 +65,11 @@ def __getattr__(self, attr):
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 @@ def cursor(self):
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':
View
7 django/db/backends/oracle/base.py
@@ -21,9 +21,10 @@
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 @@ def cursor(self):
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):
View
5 django/db/backends/postgresql/base.py
@@ -21,9 +21,10 @@
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 @@ def cursor(self):
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])
View
5 django/db/backends/postgresql_psycopg2/base.py
@@ -21,9 +21,10 @@
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 @@ def cursor(self):
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
View
12 django/db/backends/sqlite3/base.py
@@ -42,16 +42,20 @@ def utf8(s):
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)
View
8 docs/settings.txt
@@ -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
-----------------
Please sign in to comment.
Something went wrong with that request. Please try again.