Skip to content

Commit

Permalink
allow to pass commands to mssqlclient.py via command line (#1770)
Browse files Browse the repository at this point in the history
* allow to pass commands to mssqlclient.py via command line

* Changed parameter name and nargs value as suggested

Co-authored-by: Gabriel Gonzalez <[email protected]>

* Update examples/mssqlclient.py

---------

Co-authored-by: Gabriel Gonzalez <[email protected]>
  • Loading branch information
trietend and gabrielg5 authored Dec 6, 2024
1 parent 9ef36ac commit e9a47ff
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions examples/mssqlclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'Authentication (default False)')
parser.add_argument('-debug', action='store_true', help='Turn DEBUG output ON')
parser.add_argument('-show', action='store_true', help='show the queries')
parser.add_argument('-command', action='extend', nargs='*', help='Commands to execute in the SQL shell. Multiple commands can be passed.')
parser.add_argument('-file', type=argparse.FileType('r'), help='input file with commands to execute in the SQL shell')

group = parser.add_argument_group('authentication')
Expand Down Expand Up @@ -107,10 +108,14 @@
res = False
if res is True:
shell = SQLSHELL(ms_sql, options.show)
if options.file is None:
shell.cmdloop()
else:
if options.file:
for line in options.file.readlines():
print("SQL> %s" % line, end=' ')
shell.onecmd(line)
elif options.command:
for c in options.command:
print("SQL> %s" % c)
shell.onecmd(c)
else:
shell.cmdloop()
ms_sql.disconnect()

0 comments on commit e9a47ff

Please sign in to comment.