Skip to content

Commit e9a47ff

Browse files
trietendgabrielg5
andauthored
allow to pass commands to mssqlclient.py via command line (#1770)
* allow to pass commands to mssqlclient.py via command line * Changed parameter name and nargs value as suggested Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com> * Update examples/mssqlclient.py --------- Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com>
1 parent 9ef36ac commit e9a47ff

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

examples/mssqlclient.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
'Authentication (default False)')
4343
parser.add_argument('-debug', action='store_true', help='Turn DEBUG output ON')
4444
parser.add_argument('-show', action='store_true', help='show the queries')
45+
parser.add_argument('-command', action='extend', nargs='*', help='Commands to execute in the SQL shell. Multiple commands can be passed.')
4546
parser.add_argument('-file', type=argparse.FileType('r'), help='input file with commands to execute in the SQL shell')
4647

4748
group = parser.add_argument_group('authentication')
@@ -107,10 +108,14 @@
107108
res = False
108109
if res is True:
109110
shell = SQLSHELL(ms_sql, options.show)
110-
if options.file is None:
111-
shell.cmdloop()
112-
else:
111+
if options.file:
113112
for line in options.file.readlines():
114113
print("SQL> %s" % line, end=' ')
115114
shell.onecmd(line)
115+
elif options.command:
116+
for c in options.command:
117+
print("SQL> %s" % c)
118+
shell.onecmd(c)
119+
else:
120+
shell.cmdloop()
116121
ms_sql.disconnect()

0 commit comments

Comments
 (0)