db: Gave each DatabaseClient class an 'executable_name' attribute (e.g., 'psql' or 'mysql'), so that we can use it to make a more helpful error message. Refs #8978
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8989 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
8f78d7f940
commit
42a878cfea
|
@ -439,9 +439,13 @@ class BaseDatabaseIntrospection(object):
|
||||||
|
|
||||||
class BaseDatabaseClient(object):
|
class BaseDatabaseClient(object):
|
||||||
"""
|
"""
|
||||||
This class encapsualtes all backend-specific methods for opening a
|
This class encapsulates all backend-specific methods for opening a
|
||||||
client shell
|
client shell.
|
||||||
"""
|
"""
|
||||||
|
# This should be a string representing the name of the executable
|
||||||
|
# (e.g., "psql"). Subclasses must override this.
|
||||||
|
executable_name = None
|
||||||
|
|
||||||
def runshell(self):
|
def runshell(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ from django.conf import settings
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class DatabaseClient(BaseDatabaseClient):
|
class DatabaseClient(BaseDatabaseClient):
|
||||||
|
executable_name = 'mysql'
|
||||||
|
|
||||||
def runshell(self):
|
def runshell(self):
|
||||||
args = ['']
|
args = ['']
|
||||||
db = settings.DATABASE_OPTIONS.get('db', settings.DATABASE_NAME)
|
db = settings.DATABASE_OPTIONS.get('db', settings.DATABASE_NAME)
|
||||||
|
@ -11,7 +13,7 @@ class DatabaseClient(BaseDatabaseClient):
|
||||||
host = settings.DATABASE_OPTIONS.get('host', settings.DATABASE_HOST)
|
host = settings.DATABASE_OPTIONS.get('host', settings.DATABASE_HOST)
|
||||||
port = settings.DATABASE_OPTIONS.get('port', settings.DATABASE_PORT)
|
port = settings.DATABASE_OPTIONS.get('port', settings.DATABASE_PORT)
|
||||||
defaults_file = settings.DATABASE_OPTIONS.get('read_default_file')
|
defaults_file = settings.DATABASE_OPTIONS.get('read_default_file')
|
||||||
# Seems to be no good way to set sql_mode with CLI
|
# Seems to be no good way to set sql_mode with CLI.
|
||||||
|
|
||||||
if defaults_file:
|
if defaults_file:
|
||||||
args += ["--defaults-file=%s" % defaults_file]
|
args += ["--defaults-file=%s" % defaults_file]
|
||||||
|
@ -26,4 +28,4 @@ class DatabaseClient(BaseDatabaseClient):
|
||||||
if db:
|
if db:
|
||||||
args += [db]
|
args += [db]
|
||||||
|
|
||||||
os.execvp('mysql', args)
|
os.execvp(self.executable_name, args)
|
||||||
|
|
|
@ -3,11 +3,13 @@ from django.conf import settings
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class DatabaseClient(BaseDatabaseClient):
|
class DatabaseClient(BaseDatabaseClient):
|
||||||
|
executable_name = 'sqlplus'
|
||||||
|
|
||||||
def runshell(self):
|
def runshell(self):
|
||||||
dsn = settings.DATABASE_USER
|
dsn = settings.DATABASE_USER
|
||||||
if settings.DATABASE_PASSWORD:
|
if settings.DATABASE_PASSWORD:
|
||||||
dsn += "/%s" % settings.DATABASE_PASSWORD
|
dsn += "/%s" % settings.DATABASE_PASSWORD
|
||||||
if settings.DATABASE_NAME:
|
if settings.DATABASE_NAME:
|
||||||
dsn += "@%s" % settings.DATABASE_NAME
|
dsn += "@%s" % settings.DATABASE_NAME
|
||||||
args = ["sqlplus", "-L", dsn]
|
args = [self.executable_name, "-L", dsn]
|
||||||
os.execvp("sqlplus", args)
|
os.execvp(self.executable_name, args)
|
||||||
|
|
|
@ -3,8 +3,10 @@ from django.conf import settings
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class DatabaseClient(BaseDatabaseClient):
|
class DatabaseClient(BaseDatabaseClient):
|
||||||
|
executable_name = 'psql'
|
||||||
|
|
||||||
def runshell(self):
|
def runshell(self):
|
||||||
args = ['psql']
|
args = [self.executable_name]
|
||||||
if settings.DATABASE_USER:
|
if settings.DATABASE_USER:
|
||||||
args += ["-U", settings.DATABASE_USER]
|
args += ["-U", settings.DATABASE_USER]
|
||||||
if settings.DATABASE_PASSWORD:
|
if settings.DATABASE_PASSWORD:
|
||||||
|
@ -14,4 +16,4 @@ class DatabaseClient(BaseDatabaseClient):
|
||||||
if settings.DATABASE_PORT:
|
if settings.DATABASE_PORT:
|
||||||
args.extend(["-p", str(settings.DATABASE_PORT)])
|
args.extend(["-p", str(settings.DATABASE_PORT)])
|
||||||
args += [settings.DATABASE_NAME]
|
args += [settings.DATABASE_NAME]
|
||||||
os.execvp('psql', args)
|
os.execvp(self.executable_name, args)
|
||||||
|
|
|
@ -3,6 +3,8 @@ from django.conf import settings
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class DatabaseClient(BaseDatabaseClient):
|
class DatabaseClient(BaseDatabaseClient):
|
||||||
|
executable_name = 'sqlite3'
|
||||||
|
|
||||||
def runshell(self):
|
def runshell(self):
|
||||||
args = ['', settings.DATABASE_NAME]
|
args = ['', settings.DATABASE_NAME]
|
||||||
os.execvp('sqlite3', args)
|
os.execvp(self.executable_name, args)
|
||||||
|
|
Loading…
Reference in New Issue