diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 1fca002d0a..ce5e0f06f1 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -245,23 +245,23 @@ class DatabaseWrapper(BaseDatabaseWrapper): def _valid_connection(self): return self.connection is not None + def _connect_string(self, settings): + if len(settings.DATABASE_HOST.strip()) == 0: + settings.DATABASE_HOST = 'localhost' + if len(settings.DATABASE_PORT.strip()) != 0: + dsn = '%s:%s/%s' % (settings.DATABASE_HOST, + settings.DATABASE_PORT, + settings.DATABASE_NAME) + else: + dsn = settings.DATABASE_NAME + return "%s/%s@%s" % (settings.DATABASE_USER, + settings.DATABASE_PASSWORD, dsn) + def _cursor(self, settings): cursor = None if not self._valid_connection(): - if len(settings.DATABASE_HOST.strip()) == 0: - 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.options) - else: - conn_string = "%s/%s@%s" % (settings.DATABASE_USER, - settings.DATABASE_PASSWORD, - settings.DATABASE_NAME) - self.connection = Database.connect(conn_string, **self.options) + conn_string = self._connect_string(settings) + self.connection = Database.connect(conn_string, **self.options) cursor = FormatStylePlaceholderCursor(self.connection) # Set oracle date to ansi date format. This only needs to execute # once when we create a new connection. diff --git a/django/db/backends/oracle/client.py b/django/db/backends/oracle/client.py index 52c4880e0e..c95b8109ba 100644 --- a/django/db/backends/oracle/client.py +++ b/django/db/backends/oracle/client.py @@ -6,10 +6,7 @@ class DatabaseClient(BaseDatabaseClient): executable_name = 'sqlplus' def runshell(self): - dsn = settings.DATABASE_USER - if settings.DATABASE_PASSWORD: - dsn += "/%s" % settings.DATABASE_PASSWORD - if settings.DATABASE_NAME: - dsn += "@%s" % settings.DATABASE_NAME - args = [self.executable_name, "-L", dsn] + from django.db import connection + conn_string = connection._connect_string(settings) + args = [self.executable_name, "-L", conn_string] os.execvp(self.executable_name, args)