Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add additional parameters argument to runshell as required by Django 3.1 #52

Merged
merged 1 commit into from
Jul 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions mssql/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@
class DatabaseClient(BaseDatabaseClient):
executable_name = 'sqlcmd'

def runshell(self):
settings_dict = self.connection.settings_dict
@classmethod
def settings_to_cmd_args(cls, settings_dict, parameters):
options = settings_dict['OPTIONS']
user = options.get('user', settings_dict['USER'])
password = options.get('passwd', settings_dict['PASSWORD'])

driver = options.get('driver', 'ODBC Driver 13 for SQL Server')
ms_drivers = re.compile('^ODBC Driver .* for SQL Server$|^SQL Server Native Client')
if not ms_drivers.match(driver):
self.executable_name = 'isql'
cls.executable_name = 'isql'

if self.executable_name == 'sqlcmd':
if cls.executable_name == 'sqlcmd':
db = options.get('db', settings_dict['NAME'])
server = options.get('host', settings_dict['HOST'])
port = options.get('port', settings_dict['PORT'])
defaults_file = options.get('read_default_file')

args = [self.executable_name]
args = [cls.executable_name]
if server:
if port:
server = ','.join((server, str(port)))
Expand All @@ -44,9 +44,11 @@ def runshell(self):
args += ["-i", defaults_file]
else:
dsn = options.get('dsn', '')
args = ['%s -v %s %s %s' % (self.executable_name, dsn, user, password)]
args = ['%s -v %s %s %s' % (cls.executable_name, dsn, user, password)]

try:
subprocess.check_call(args)
except KeyboardInterrupt:
pass
args.extend(parameters)
return args

def runshell(self, parameters=[]):
args = DatabaseClient.settings_to_cmd_args(self.connection.settings_dict, parameters)
subprocess.run(args, check=True)