From c20019a91d7d553606f45d21c513f277fb98deb4 Mon Sep 17 00:00:00 2001 From: Ian Kelly Date: Thu, 8 Jan 2009 05:12:14 +0000 Subject: [PATCH] Fixed #9972: The dbshell command was ignoring the DATABASE_HOST and DATABASE_PORT settings in Oracle. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9713 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/oracle/base.py | 28 ++++++++++++++-------------- django/db/backends/oracle/client.py | 9 +++------ 2 files changed, 17 insertions(+), 20 deletions(-) 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)