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,22 +245,22 @@ class DatabaseWrapper(BaseDatabaseWrapper):
def _valid_connection(self): def _valid_connection(self):
return self.connection is not None return self.connection is not None
def _cursor(self, settings): def _connect_string(self, settings):
cursor = None
if not self._valid_connection():
if len(settings.DATABASE_HOST.strip()) == 0: if len(settings.DATABASE_HOST.strip()) == 0:
settings.DATABASE_HOST = 'localhost' settings.DATABASE_HOST = 'localhost'
if len(settings.DATABASE_PORT.strip()) != 0: if len(settings.DATABASE_PORT.strip()) != 0:
dsn = Database.makedsn(settings.DATABASE_HOST, dsn = '%s:%s/%s' % (settings.DATABASE_HOST,
int(settings.DATABASE_PORT), settings.DATABASE_PORT,
settings.DATABASE_NAME) settings.DATABASE_NAME)
self.connection = Database.connect(settings.DATABASE_USER,
settings.DATABASE_PASSWORD,
dsn, **self.options)
else: else:
conn_string = "%s/%s@%s" % (settings.DATABASE_USER, dsn = settings.DATABASE_NAME
settings.DATABASE_PASSWORD, return "%s/%s@%s" % (settings.DATABASE_USER,
settings.DATABASE_NAME) settings.DATABASE_PASSWORD, dsn)
def _cursor(self, settings):
cursor = None
if not self._valid_connection():
conn_string = self._connect_string(settings)
self.connection = Database.connect(conn_string, **self.options) self.connection = Database.connect(conn_string, **self.options)
cursor = FormatStylePlaceholderCursor(self.connection) cursor = FormatStylePlaceholderCursor(self.connection)
# Set oracle date to ansi date format. This only needs to execute # Set oracle date to ansi date format. This only needs to execute

View File

@ -6,10 +6,7 @@ class DatabaseClient(BaseDatabaseClient):
executable_name = 'sqlplus' executable_name = 'sqlplus'
def runshell(self): def runshell(self):
dsn = settings.DATABASE_USER from django.db import connection
if settings.DATABASE_PASSWORD: conn_string = connection._connect_string(settings)
dsn += "/%s" % settings.DATABASE_PASSWORD args = [self.executable_name, "-L", conn_string]
if settings.DATABASE_NAME:
dsn += "@%s" % settings.DATABASE_NAME
args = [self.executable_name, "-L", dsn]
os.execvp(self.executable_name, args) os.execvp(self.executable_name, args)