Ticket #2866: ticket2866.diff

File ticket2866.diff, 8.4 KB (added by ymasuda <ymasuda@…>, 18 years ago)

Diff to add settings.DATABASE_OPTIONS and kwargs on DatabaseWrapper

  • django/conf/global_settings.py

     
    100100DATABASE_PASSWORD = ''         # Not used with sqlite3.
    101101DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
    102102DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
     103DATABASE_OPTIONS = {}          # Set to empy dictionary for default.
    103104
    104105# Host for sending e-mail.
    105106EMAIL_HOST = 'localhost'
  • django/db/__init__.py

     
    66
    77if not settings.DATABASE_ENGINE:
    88    settings.DATABASE_ENGINE = 'dummy'
     9if not settings.DATABASE_OPTIONS:
     10    settings.DATABASE_OPTIONS = {}
    911
    1012try:
    1113    backend = __import__('django.db.backends.%s.base' % settings.DATABASE_ENGINE, '', '', [''])
     
    2729get_creation_module = lambda: __import__('django.db.backends.%s.creation' % settings.DATABASE_ENGINE, '', '', [''])
    2830runshell = lambda: __import__('django.db.backends.%s.client' % settings.DATABASE_ENGINE, '', '', ['']).runshell()
    2931
    30 connection = backend.DatabaseWrapper()
     32connection = backend.DatabaseWrapper(**settings.DATABASE_OPTIONS)
    3133DatabaseError = backend.DatabaseError
    3234
    3335# Register an event that closes the database connection
  • django/db/backends/ado_mssql/base.py

     
    5555    from django.utils._threading_local import local
    5656
    5757class DatabaseWrapper(local):
    58     def __init__(self):
     58    def __init__(self, **kwargs):
    5959        self.connection = None
    6060        self.queries = []
    6161
  • django/db/backends/postgresql/base.py

     
    2121    from django.utils._threading_local import local
    2222
    2323class DatabaseWrapper(local):
    24     def __init__(self):
     24    def __init__(self, **kwargs):
    2525        self.connection = None
    2626        self.queries = []
     27        self.options = kwargs
    2728
    2829    def cursor(self):
    2930        from django.conf import settings
     
    4041                conn_string += " host=%s" % settings.DATABASE_HOST
    4142            if settings.DATABASE_PORT:
    4243                conn_string += " port=%s" % settings.DATABASE_PORT
    43             self.connection = Database.connect(conn_string)
     44            self.connection = Database.connect(conn_string, **self.options)
    4445            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
    4546        cursor = self.connection.cursor()
    4647        cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
  • django/db/backends/sqlite3/base.py

     
    4242    from django.utils._threading_local import local
    4343
    4444class DatabaseWrapper(local):
    45     def __init__(self):
     45    def __init__(self, **kwargs):
    4646        self.connection = None
    4747        self.queries = []
     48        self.options = kwargs
    4849
    4950    def cursor(self):
    5051        from django.conf import settings
    5152        if self.connection is None:
    52             self.connection = Database.connect(settings.DATABASE_NAME,
    53                 detect_types=Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES)
    54 
     53            kwargs = {
     54                'database': settings.DATABASE_NAME,
     55                'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
     56            }
     57            kwargs.update(self.options)
     58            self.connection = Database.connect(**kwargs)
    5559            # Register extract and date_trunc functions.
    5660            self.connection.create_function("django_extract", 2, _sqlite_extract)
    5761            self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
  • django/db/backends/mysql/base.py

     
    6565    from django.utils._threading_local import local
    6666
    6767class DatabaseWrapper(local):
    68     def __init__(self):
     68    def __init__(self, **kwargs):
    6969        self.connection = None
    7070        self.queries = []
    7171        self.server_version = None
     72        self.options = kwargs
    7273
    7374    def _valid_connection(self):
    7475        if self.connection is not None:
     
    9596                kwargs['host'] = settings.DATABASE_HOST
    9697            if settings.DATABASE_PORT:
    9798                kwargs['port'] = int(settings.DATABASE_PORT)
     99            kwargs.update(self.options)
    98100            self.connection = Database.connect(**kwargs)
    99101        cursor = self.connection.cursor()
    100102        if self.connection.get_server_info() >= '4.1':
  • django/db/backends/oracle/base.py

     
    2121    from django.utils._threading_local import local
    2222
    2323class DatabaseWrapper(local):
    24     def __init__(self):
     24    def __init__(self, **kwargs):
    2525        self.connection = None
    2626        self.queries = []
     27        self.options = kwargs
    2728
    2829    def _valid_connection(self):
    2930        return self.connection is not None
     
    3536                settings.DATABASE_HOST = 'localhost'
    3637            if len(settings.DATABASE_PORT.strip()) != 0:
    3738                dsn = Database.makedsn(settings.DATABASE_HOST, int(settings.DATABASE_PORT), settings.DATABASE_NAME)
    38                 self.connection = Database.connect(settings.DATABASE_USER, settings.DATABASE_PASSWORD, dsn)
     39                self.connection = Database.connect(settings.DATABASE_USER, settings.DATABASE_PASSWORD, dsn, **self.options)
    3940            else:
    4041                conn_string = "%s/%s@%s" % (settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME)
    41                 self.connection = Database.connect(conn_string)
     42                self.connection = Database.connect(conn_string, **self.options)
    4243        return FormatStylePlaceholderCursor(self.connection)
    4344
    4445    def _commit(self):
  • django/db/backends/postgresql_psycopg2/base.py

     
    2121    from django.utils._threading_local import local
    2222
    2323class DatabaseWrapper(local):
    24     def __init__(self):
     24    def __init__(self, **kwargs):
    2525        self.connection = None
    2626        self.queries = []
     27        self.options = kwargs
    2728
    2829    def cursor(self):
    2930        from django.conf import settings
     
    4041                conn_string += " host=%s" % settings.DATABASE_HOST
    4142            if settings.DATABASE_PORT:
    4243                conn_string += " port=%s" % settings.DATABASE_PORT
    43             self.connection = Database.connect(conn_string)
     44            self.connection = Database.connect(conn_string, **self.options)
    4445            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
    4546        cursor = self.connection.cursor()
    4647        cursor.tzinfo_factory = None
  • django/db/backends/dummy/base.py

     
    2020    _commit = complain
    2121    _rollback = complain
    2222
     23    def __init__(self, **kwargs):
     24        pass
     25
    2326    def close(self):
    2427        pass # close()
    2528
  • docs/settings.txt

     
    265265The name of the database to use. For SQLite, it's the full path to the database
    266266file.
    267267
     268DATABASE_OPTIONS
     269----------------
     270
     271Default: ``{}`` (Empty dictionary)
     272
     273Extra parameters to use when connecting to the database. Consult backend
     274module's document for available keywords.
     275
    268276DATABASE_PASSWORD
    269277-----------------
    270278
Back to Top