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-12-22 23:18:51 +08:00
|
|
|
db = settings_dict['OPTIONS'].get('db', settings_dict['NAME'])
|
|
|
|
user = settings_dict['OPTIONS'].get('user', settings_dict['USER'])
|
|
|
|
passwd = settings_dict['OPTIONS'].get('passwd', settings_dict['PASSWORD'])
|
|
|
|
host = settings_dict['OPTIONS'].get('host', settings_dict['HOST'])
|
|
|
|
port = settings_dict['OPTIONS'].get('port', settings_dict['PORT'])
|
|
|
|
defaults_file = settings_dict['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:
|
2010-08-28 21:17:50 +08:00
|
|
|
if '/' in host:
|
|
|
|
args += ["--socket=%s" % host]
|
|
|
|
else:
|
|
|
|
args += ["--host=%s" % host]
|
2008-08-11 20:11:25 +08:00
|
|
|
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)
|
|
|
|
|