2006-05-02 09:31:56 +08:00
|
|
|
import os
|
2009-04-11 19:41:35 +08:00
|
|
|
import sys
|
|
|
|
|
|
|
|
from django.db.backends import BaseDatabaseClient
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
class DatabaseClient(BaseDatabaseClient):
|
2008-09-09 10:13:58 +08:00
|
|
|
executable_name = 'mysql'
|
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def runshell(self):
|
2009-03-11 11:39:34 +08:00
|
|
|
settings_dict = self.connection.settings_dict
|
2009-04-11 19:41:35 +08:00
|
|
|
args = [self.executable_name]
|
2009-03-11 11:39:34 +08:00
|
|
|
db = settings_dict['DATABASE_OPTIONS'].get('db', settings_dict['DATABASE_NAME'])
|
|
|
|
user = settings_dict['DATABASE_OPTIONS'].get('user', settings_dict['DATABASE_USER'])
|
|
|
|
passwd = settings_dict['DATABASE_OPTIONS'].get('passwd', settings_dict['DATABASE_PASSWORD'])
|
|
|
|
host = settings_dict['DATABASE_OPTIONS'].get('host', settings_dict['DATABASE_HOST'])
|
|
|
|
port = settings_dict['DATABASE_OPTIONS'].get('port', settings_dict['DATABASE_PORT'])
|
|
|
|
defaults_file = settings_dict['DATABASE_OPTIONS'].get('read_default_file')
|
2008-09-09 10:13:58 +08:00
|
|
|
# Seems to be no good way to set sql_mode with CLI.
|
2009-04-11 19:41:35 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
if defaults_file:
|
|
|
|
args += ["--defaults-file=%s" % defaults_file]
|
|
|
|
if user:
|
|
|
|
args += ["--user=%s" % user]
|
|
|
|
if passwd:
|
|
|
|
args += ["--password=%s" % passwd]
|
|
|
|
if host:
|
|
|
|
args += ["--host=%s" % host]
|
|
|
|
if port:
|
|
|
|
args += ["--port=%s" % port]
|
|
|
|
if db:
|
|
|
|
args += [db]
|
2007-03-14 20:08:19 +08:00
|
|
|
|
2009-04-11 19:41:35 +08:00
|
|
|
if os.name == 'nt':
|
|
|
|
sys.exit(os.system(" ".join(args)))
|
|
|
|
else:
|
|
|
|
os.execvp(self.executable_name, args)
|
|
|
|
|