Ticket #10459: diff.diff

File diff.diff, 18.8 KB (added by Alex Gaynor, 16 years ago)

Hits this in every place(I think) but doesn't resolve issues with the test database, that neesd thought

  • django/db/__init__.py

    diff --git a/django/db/__init__.py b/django/db/__init__.py
    index 8025721..250e0a0 100644
    a b except ImportError, e:  
    3737            raise # If there's some other error, this must be an error in Django itself.
    3838
    3939# Convenient aliases for backend bits.
    40 connection = backend.DatabaseWrapper(**settings.DATABASE_OPTIONS)
     40connection = backend.DatabaseWrapper({
     41    'DATABASE_HOST': settings.DATABASE_HOST,
     42    'DATABASE_NAME': settings.DATABASE_NAME,
     43    'DATABASE_OPTIONS': settings.DATABASE_OPTIONS,
     44    'DATABASE_PASSWORD': settings.DATABASE_PASSWORD,
     45    'DATABASE_PORT': settings.DATABASE_PORT,
     46    'DATABASE_USER': settings.DATABASE_USER,
     47})
    4148DatabaseError = backend.DatabaseError
    4249IntegrityError = backend.IntegrityError
    4350
  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index 187ff6c..1b5f265 100644
    a b class BaseDatabaseWrapper(local):  
    2424    Represents a database connection.
    2525    """
    2626    ops = None
    27     def __init__(self, **kwargs):
     27    def __init__(self, settings):
    2828        self.connection = None
    2929        self.queries = []
    30         self.options = kwargs
     30        self.settings = settings
    3131
    3232    def _commit(self):
    3333        if self.connection is not None:
    class BaseDatabaseWrapper(local):  
    5959
    6060    def cursor(self):
    6161        from django.conf import settings
    62         cursor = self._cursor(settings)
     62        cursor = self._cursor()
    6363        if settings.DEBUG:
    6464            return self.make_debug_cursor(cursor)
    6565        return cursor
    class BaseDatabaseClient(object):  
    497497    # This should be a string representing the name of the executable
    498498    # (e.g., "psql"). Subclasses must override this.
    499499    executable_name = None
     500   
     501    def __init__(self, connection):
     502        self.connection = connection
    500503
    501504    def runshell(self):
    502505        raise NotImplementedError()
  • django/db/backends/dummy/base.py

    diff --git a/django/db/backends/dummy/base.py b/django/db/backends/dummy/base.py
    index 530ea9c..a18c609 100644
    a b class DatabaseWrapper(object):  
    4646
    4747        self.features = BaseDatabaseFeatures()
    4848        self.ops = DatabaseOperations()
    49         self.client = DatabaseClient()
     49        self.client = DatabaseClient(self)
    5050        self.creation = BaseDatabaseCreation(self)
    5151        self.introspection = DatabaseIntrospection(self)
    5252        self.validation = BaseDatabaseValidation()
  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    index 00da726..eb6dad1 100644
    a b class DatabaseWrapper(BaseDatabaseWrapper):  
    238238
    239239        self.features = DatabaseFeatures()
    240240        self.ops = DatabaseOperations()
    241         self.client = DatabaseClient()
     241        self.client = DatabaseClient(self)
    242242        self.creation = DatabaseCreation(self)
    243243        self.introspection = DatabaseIntrospection(self)
    244244        self.validation = DatabaseValidation()
    class DatabaseWrapper(BaseDatabaseWrapper):  
    253253                self.connection = None
    254254        return False
    255255
    256     def _cursor(self, settings):
     256    def _cursor(self):
    257257        if not self._valid_connection():
    258258            kwargs = {
    259259                'conv': django_conversions,
    260260                'charset': 'utf8',
    261261                'use_unicode': True,
    262262            }
    263             if settings.DATABASE_USER:
    264                 kwargs['user'] = settings.DATABASE_USER
    265             if settings.DATABASE_NAME:
    266                 kwargs['db'] = settings.DATABASE_NAME
    267             if settings.DATABASE_PASSWORD:
    268                 kwargs['passwd'] = settings.DATABASE_PASSWORD
    269             if settings.DATABASE_HOST.startswith('/'):
    270                 kwargs['unix_socket'] = settings.DATABASE_HOST
    271             elif settings.DATABASE_HOST:
    272                 kwargs['host'] = settings.DATABASE_HOST
    273             if settings.DATABASE_PORT:
    274                 kwargs['port'] = int(settings.DATABASE_PORT)
    275             kwargs.update(self.options)
     263            if self.settings['DATABASE_USER']:
     264                kwargs['user'] = self.settings['DATABASE_USER']
     265            if self.settings['DATABASE_NAME']:
     266                kwargs['db'] = self.settings['DATABASE_NAME']
     267            if self.settings['DATABASE_PASSWORD']:
     268                kwargs['passwd'] = self.settings['DATABASE_PASSWORD']
     269            if self.settings['DATABASE_HOST'].startswith('/'):
     270                kwargs['unix_socket'] = self.settings['DATABASE_HOST']
     271            elif self.settings['DATABASE_HOST']:
     272                kwargs['host'] = self.settings['DATABASE_HOST']
     273            if self.settings['DATABASE_PORT']:
     274                kwargs['port'] = int(self.settings['DATABASE_PORT'])
     275            kwargs.update(self.settings['DATABASE_OPTIONS'])
    276276            self.connection = Database.connect(**kwargs)
    277277            self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode]
    278278            self.connection.encoders[SafeString] = self.connection.encoders[str]
  • django/db/backends/mysql/client.py

    diff --git a/django/db/backends/mysql/client.py b/django/db/backends/mysql/client.py
    index 17daca9..d8783e0 100644
    a b  
    11from django.db.backends import BaseDatabaseClient
    2 from django.conf import settings
    32import os
    43
    54class DatabaseClient(BaseDatabaseClient):
    class DatabaseClient(BaseDatabaseClient):  
    76
    87    def runshell(self):
    98        args = ['']
    10         db = settings.DATABASE_OPTIONS.get('db', settings.DATABASE_NAME)
    11         user = settings.DATABASE_OPTIONS.get('user', settings.DATABASE_USER)
    12         passwd = settings.DATABASE_OPTIONS.get('passwd', settings.DATABASE_PASSWORD)
    13         host = settings.DATABASE_OPTIONS.get('host', settings.DATABASE_HOST)
    14         port = settings.DATABASE_OPTIONS.get('port', settings.DATABASE_PORT)
    15         defaults_file = settings.DATABASE_OPTIONS.get('read_default_file')
     9        db = self.connection.settings['DATABASE_OPTIONS'].get('db', self.connection.settings['DATABASE_NAME'])
     10        user = self.connection.settings['DATABASE_OPTIONS'].get('user', self.connection.settings['DATABASE_USER'])
     11        passwd = self.connection.settings['DATABASE_OPTIONS'].get('passwd', self.connection.settings['DATABASE_PASSWORD'])
     12        host = self.connection.settings['DATABASE_OPTIONS'].get('host', self.connection.settings['DATABASE_HOST'])
     13        port = self.connection.settings['DATABASE_OPTIONS'].get('port', self.connection.settings['DATABASE_PORT'])
     14        defaults_file = self.connection.settings['DATABASE_OPTIONS'].get('read_default_file')
    1615        # Seems to be no good way to set sql_mode with CLI.
    1716   
    1817        if defaults_file:
  • django/db/backends/oracle/base.py

    diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
    index baa8486..d59804a 100644
    a b class DatabaseWrapper(BaseDatabaseWrapper):  
    262262
    263263        self.features = DatabaseFeatures()
    264264        self.ops = DatabaseOperations()
    265         self.client = DatabaseClient()
     265        self.client = DatabaseClient(self)
    266266        self.creation = DatabaseCreation(self)
    267267        self.introspection = DatabaseIntrospection(self)
    268268        self.validation = BaseDatabaseValidation()
    class DatabaseWrapper(BaseDatabaseWrapper):  
    270270    def _valid_connection(self):
    271271        return self.connection is not None
    272272
    273     def _connect_string(self, settings):
    274         if len(settings.DATABASE_HOST.strip()) == 0:
    275             settings.DATABASE_HOST = 'localhost'
    276         if len(settings.DATABASE_PORT.strip()) != 0:
    277             dsn = Database.makedsn(settings.DATABASE_HOST,
    278                                    int(settings.DATABASE_PORT),
    279                                    settings.DATABASE_NAME)
     273    def _connect_string(self):
     274        if len(self.settings['DATABASE_HOST'].strip()) == 0:
     275            self.settings['DATABASE_HOST'] = 'localhost'
     276        if len(self.settings['DATABASE_PORT'].strip()) != 0:
     277            dsn = Database.makedsn(self.settings['DATABASE_HOST'],
     278                                   int(self.settings['DATABASE_PORT']),
     279                                   self.settings['DATABASE_NAME'])
    280280        else:
    281             dsn = settings.DATABASE_NAME
    282         return "%s/%s@%s" % (settings.DATABASE_USER,
    283                              settings.DATABASE_PASSWORD, dsn)
     281            dsn = self.settings['DATABASE_NAME']
     282        return "%s/%s@%s" % (self.settings['DATABASE_USER'],
     283                             self.settings['DATABASE_PASSWORD'], dsn)
    284284
    285     def _cursor(self, settings):
     285    def _cursor(self):
    286286        cursor = None
    287287        if not self._valid_connection():
    288             conn_string = self._connect_string(settings)
    289             self.connection = Database.connect(conn_string, **self.options)
     288            conn_string = self._connect_string()
     289            self.connection = Database.connect(conn_string, **self.settings['DATABASE_OPTIONS'])
    290290            cursor = FormatStylePlaceholderCursor(self.connection)
    291291            # Set oracle date to ansi date format.  This only needs to execute
    292292            # once when we create a new connection. We also set the Territory
  • django/db/backends/oracle/client.py

    diff --git a/django/db/backends/oracle/client.py b/django/db/backends/oracle/client.py
    index c95b810..84193ea 100644
    a b  
    11from django.db.backends import BaseDatabaseClient
    2 from django.conf import settings
    32import os
    43
    54class DatabaseClient(BaseDatabaseClient):
    65    executable_name = 'sqlplus'
    76
    87    def runshell(self):
    9         from django.db import connection
    10         conn_string = connection._connect_string(settings)
     8        conn_string = self.connection._connect_string()
    119        args = [self.executable_name, "-L", conn_string]
    1210        os.execvp(self.executable_name, args)
  • django/db/backends/postgresql/base.py

    diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
    index ad271f2..d4fb01b 100644
    a b class DatabaseWrapper(BaseDatabaseWrapper):  
    9090
    9191        self.features = DatabaseFeatures()
    9292        self.ops = DatabaseOperations()
    93         self.client = DatabaseClient()
     93        self.client = DatabaseClient(self)
    9494        self.creation = DatabaseCreation(self)
    9595        self.introspection = DatabaseIntrospection(self)
    9696        self.validation = BaseDatabaseValidation()
    9797
    98     def _cursor(self, settings):
     98    def _cursor(self):
    9999        set_tz = False
    100100        if self.connection is None:
    101101            set_tz = True
    102             if settings.DATABASE_NAME == '':
     102            if self.settings['DATABASE_NAME'] == '':
    103103                from django.core.exceptions import ImproperlyConfigured
    104104                raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
    105             conn_string = "dbname=%s" % settings.DATABASE_NAME
    106             if settings.DATABASE_USER:
    107                 conn_string = "user=%s %s" % (settings.DATABASE_USER, conn_string)
    108             if settings.DATABASE_PASSWORD:
    109                 conn_string += " password='%s'" % settings.DATABASE_PASSWORD
    110             if settings.DATABASE_HOST:
    111                 conn_string += " host=%s" % settings.DATABASE_HOST
    112             if settings.DATABASE_PORT:
    113                 conn_string += " port=%s" % settings.DATABASE_PORT
    114             self.connection = Database.connect(conn_string, **self.options)
     105            conn_string = "dbname=%s" % self.settings['DATABASE_NAME']
     106            if self.settings['DATABASE_USER']:
     107                conn_string = "user=%s %s" % (self.settings['DATABASE_USER'], conn_string)
     108            if self.settings['DATABASE_PASSWORD']:
     109                conn_string += " password='%s'" % self.settings['DATABASE_PASSWORD']
     110            if self.settings['DATABASE_HOST']:
     111                conn_string += " host=%s" % self.settings['DATABASE_HOST']
     112            if self.settings['DATABASE_PORT']:
     113                conn_string += " port=%s" % self.settings['DATABASE_PORT']
     114            self.connection = Database.connect(conn_string, **self.settings['DATABASE_OPTIONS'])
    115115            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
    116116        cursor = self.connection.cursor()
    117117        if set_tz:
  • django/db/backends/postgresql/client.py

    diff --git a/django/db/backends/postgresql/client.py b/django/db/backends/postgresql/client.py
    index 63f28a7..3e51423 100644
    a b  
    11from django.db.backends import BaseDatabaseClient
    2 from django.conf import settings
    32import os
    43
    54class DatabaseClient(BaseDatabaseClient):
    class DatabaseClient(BaseDatabaseClient):  
    76
    87    def runshell(self):
    98        args = [self.executable_name]
    10         if settings.DATABASE_USER:
    11             args += ["-U", settings.DATABASE_USER]
    12         if settings.DATABASE_PASSWORD:
     9        if self.connection.settings['DATABASE_USER']:
     10            args += ["-U", self.connection.settings['DATABASE_USER']]
     11        if self.connection.settings['DATABASE_PASSWORD']:
    1312            args += ["-W"]
    14         if settings.DATABASE_HOST:
    15             args.extend(["-h", settings.DATABASE_HOST])
    16         if settings.DATABASE_PORT:
    17             args.extend(["-p", str(settings.DATABASE_PORT)])
    18         args += [settings.DATABASE_NAME]
     13        if self.connection.settings['DATABASE_HOST']:
     14            args.extend(["-h", self.connection.settings['DATABASE_HOST']])
     15        if self.connection.settings['DATABASE_PORT']:
     16            args.extend(["-p", str(self.connection.settings['DATABASE_PORT'])])
     17        args += [self.connection.settings['DATABASE_NAME']]
    1918        os.execvp(self.executable_name, args)
  • django/db/backends/postgresql_psycopg2/base.py

    diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
    index 27de942..76aaf96 100644
    a b class DatabaseWrapper(BaseDatabaseWrapper):  
    6060       
    6161        self.features = DatabaseFeatures()
    6262        self.ops = DatabaseOperations()
    63         self.client = DatabaseClient()
     63        self.client = DatabaseClient(self)
    6464        self.creation = DatabaseCreation(self)
    6565        self.introspection = DatabaseIntrospection(self)
    6666        self.validation = BaseDatabaseValidation()
    6767
    68     def _cursor(self, settings):
     68    def _cursor(self):
    6969        set_tz = False
    7070        if self.connection is None:
    7171            set_tz = True
    72             if settings.DATABASE_NAME == '':
     72            if self.settings['DATABASE_NAME'] == '':
    7373                from django.core.exceptions import ImproperlyConfigured
    7474                raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
    7575            conn_params = {
    76                 'database': settings.DATABASE_NAME,
     76                'database': self.settings['DATABASE_NAME'],
    7777            }
    78             conn_params.update(self.options)
    79             if settings.DATABASE_USER:
    80                 conn_params['user'] = settings.DATABASE_USER
    81             if settings.DATABASE_PASSWORD:
    82                 conn_params['password'] = settings.DATABASE_PASSWORD
    83             if settings.DATABASE_HOST:
    84                 conn_params['host'] = settings.DATABASE_HOST
    85             if settings.DATABASE_PORT:
    86                 conn_params['port'] = settings.DATABASE_PORT
     78            conn_params.update(self.settings['DATABASE_OPTIONS'])
     79            if self.settings['DATABASE_USER']:
     80                conn_params['user'] = self.settings['DATABASE_USER']
     81            if self.settings['DATABASE_PASSWORD']:
     82                conn_params['password'] = self.settings['DATABASE_PASSWORD']
     83            if self.settings['DATABASE_HOST']:
     84                conn_params['host'] = self.settings['DATABASE_HOST']
     85            if self.settings['DATABASE_PORT']:
     86                conn_params['port'] = self.settings['DATABASE_PORT']
    8787            self.connection = Database.connect(**conn_params)
    8888            self.connection.set_isolation_level(1) # make transactions transparent to all cursors
    8989            self.connection.set_client_encoding('UTF8')
  • django/db/backends/sqlite3/base.py

    diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
    index ba0ef16..e1f6732 100644
    a b class DatabaseWrapper(BaseDatabaseWrapper):  
    149149
    150150        self.features = DatabaseFeatures()
    151151        self.ops = DatabaseOperations()
    152         self.client = DatabaseClient()
     152        self.client = DatabaseClient(self)
    153153        self.creation = DatabaseCreation(self)
    154154        self.introspection = DatabaseIntrospection(self)
    155155        self.validation = BaseDatabaseValidation()
    156156
    157     def _cursor(self, settings):
     157    def _cursor(self):
    158158        if self.connection is None:
    159             if not settings.DATABASE_NAME:
     159            if not self.settings['DATABASE_NAME']:
    160160                from django.core.exceptions import ImproperlyConfigured
    161161                raise ImproperlyConfigured, "Please fill out DATABASE_NAME in the settings module before using the database."
    162162            kwargs = {
    163                 'database': settings.DATABASE_NAME,
     163                'database': self.settings['DATABASE_NAME'],
    164164                'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
    165165            }
    166             kwargs.update(self.options)
     166            kwargs.update(self.settings['DATABASE_OPTIONS'])
    167167            self.connection = Database.connect(**kwargs)
    168168            # Register extract, date_trunc, and regexp functions.
    169169            self.connection.create_function("django_extract", 2, _sqlite_extract)
    class DatabaseWrapper(BaseDatabaseWrapper):  
    172172        return self.connection.cursor(factory=SQLiteCursorWrapper)
    173173
    174174    def close(self):
    175         from django.conf import settings
    176175        # If database is in memory, closing the connection destroys the
    177176        # database. To prevent accidental data loss, ignore close requests on
    178177        # an in-memory db.
    179         if settings.DATABASE_NAME != ":memory:":
     178        if self.settings['DATABASE_NAME'] != ":memory:":
    180179            BaseDatabaseWrapper.close(self)
    181180
    182181class SQLiteCursorWrapper(Database.Cursor):
  • django/db/backends/sqlite3/client.py

    diff --git a/django/db/backends/sqlite3/client.py b/django/db/backends/sqlite3/client.py
    index 239e72f..5b40ffb 100644
    a b  
    11from django.db.backends import BaseDatabaseClient
    2 from django.conf import settings
    32import os
    43
    54class DatabaseClient(BaseDatabaseClient):
    65    executable_name = 'sqlite3'
    76
    87    def runshell(self):
    9         args = ['', settings.DATABASE_NAME]
     8        args = ['', self.connection.settings['DATABASE_NAME']]
    109        os.execvp(self.executable_name, args)
Back to Top