Ticket #10803: db_executable_name.2.diff
File db_executable_name.2.diff, 5.7 KB (added by , 16 years ago) |
---|
-
django/db/backends/postgresql/client.py
1 import os2 import sys3 4 1 from django.db.backends import BaseDatabaseClient 5 2 6 3 class DatabaseClient(BaseDatabaseClient): 7 executable_name = 'psql'4 executable_names = ('psql',) 8 5 9 6 def runshell(self): 10 7 settings_dict = self.connection.settings_dict 11 args = [ self.executable_name]8 args = [] 12 9 if settings_dict['DATABASE_USER']: 13 10 args += ["-U", settings_dict['DATABASE_USER']] 14 11 if settings_dict['DATABASE_HOST']: … … 16 13 if settings_dict['DATABASE_PORT']: 17 14 args.extend(["-p", str(settings_dict['DATABASE_PORT'])]) 18 15 args += [settings_dict['DATABASE_NAME']] 19 if os.name == 'nt': 20 sys.exit(os.system(" ".join(args))) 21 else: 22 os.execvp(self.executable_name, args) 16 self.run_executable(args) 23 17 -
django/db/backends/sqlite3/client.py
1 import os2 import sys3 4 1 from django.db.backends import BaseDatabaseClient 5 2 6 3 class DatabaseClient(BaseDatabaseClient): 7 executable_name = 'sqlite3'4 executable_names = ('sqlite3',) 8 5 9 6 def runshell(self): 10 args = [self.executable_name, 11 self.connection.settings_dict['DATABASE_NAME']] 12 if os.name == 'nt': 13 sys.exit(os.system(" ".join(args))) 14 else: 15 os.execvp(self.executable_name, args) 7 args = [self.connection.settings_dict['DATABASE_NAME']] 8 self.run_executable(args) 16 9 -
django/db/backends/mysql/client.py
1 import os2 import sys3 4 1 from django.db.backends import BaseDatabaseClient 5 2 6 3 class DatabaseClient(BaseDatabaseClient): 7 executable_name = 'mysql'4 executable_names = ('mysql', 'mysql5') 8 5 9 6 def runshell(self): 10 7 settings_dict = self.connection.settings_dict 11 args = [self.executable_name]12 8 db = settings_dict['DATABASE_OPTIONS'].get('db', settings_dict['DATABASE_NAME']) 13 9 user = settings_dict['DATABASE_OPTIONS'].get('user', settings_dict['DATABASE_USER']) 14 10 passwd = settings_dict['DATABASE_OPTIONS'].get('passwd', settings_dict['DATABASE_PASSWORD']) … … 17 13 defaults_file = settings_dict['DATABASE_OPTIONS'].get('read_default_file') 18 14 # Seems to be no good way to set sql_mode with CLI. 19 15 16 args = [] 20 17 if defaults_file: 21 18 args += ["--defaults-file=%s" % defaults_file] 22 19 if user: … … 30 27 if db: 31 28 args += [db] 32 29 33 if os.name == 'nt': 34 sys.exit(os.system(" ".join(args))) 35 else: 36 os.execvp(self.executable_name, args) 30 self.run_executable(args) 37 31 -
django/db/backends/oracle/client.py
1 import os2 import sys3 4 1 from django.db.backends import BaseDatabaseClient 5 2 6 3 class DatabaseClient(BaseDatabaseClient): 7 executable_name = 'sqlplus'4 executable_names = ('sqlplus',) 8 5 9 6 def runshell(self): 10 7 conn_string = self.connection._connect_string() 11 args = [self.executable_name, "-L", conn_string] 12 if os.name == 'nt': 13 sys.exit(os.system(" ".join(args))) 14 else: 15 os.execvp(self.executable_name, args) 16 8 args = ["-L", conn_string] 9 self.run_executable(args) -
django/db/backends/__init__.py
16 16 # Python 2.3 fallback 17 17 from django.utils import _decimal as decimal 18 18 19 import os 20 import sys 21 19 22 from django.db.backends import util 20 23 from django.utils import datetime_safe 21 24 … … 539 542 This class encapsulates all backend-specific methods for opening a 540 543 client shell. 541 544 """ 542 # This should be a string representing the nameof the executable543 # (e.g., "psql"). Subclasses must override this.544 executable_name = None545 # This should be a tuple with strings representing the name (or names) of the executable 546 # names to try (e.g., ("mysql", "mysql5")). Subclasses must override this. 547 executable_names = None 545 548 546 549 def __init__(self, connection): 547 550 # connection is an instance of BaseDatabaseWrapper. … … 549 552 550 553 def runshell(self): 551 554 raise NotImplementedError() 555 556 def run_executable(self, args): 557 """ 558 Will try to run the first executable it finds in the 559 executable_names tuple. 560 """ 561 for executable_name in self.executable_names: 562 try: 563 cmd = (executable_name,) + tuple(args) 564 if os.name == 'nt': 565 sys.exit(os.system(" ".join(cmd))) 566 else: 567 os.execvp(executable_name, cmd) 568 except OSError: 569 # The executable was not found; try the next 570 # one in the tuple. 571 continue 572 break 552 573 553 574 class BaseDatabaseValidation(object): 554 575 """