Skip to content

Commit

Permalink
allow to pass commands to mssqlclient.py via command line
Browse files Browse the repository at this point in the history
  • Loading branch information
trietend authored Jul 2, 2024
1 parent f827c8c commit 92933d0
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 @@ -40,6 +40,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('-cmd', 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 @@ -105,10 +106,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.cmd:
for c in options.cmd:
print("SQL> %s" % c)
shell.onecmd(c)
else:
shell.cmdloop()
ms_sql.disconnect()

0 comments on commit 92933d0

Please sign in to comment.