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
This commit is contained in:
Ian Kelly 2009-01-08 05:12:14 +00:00
parent 300752bd6c
commit c20019a91d
2 changed files with 17 additions and 20 deletions

View File

@ -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.

View File

@ -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)