Skip to content

Commit 41278dd

Browse files
committed
* remove explicit support for legacy client through the interface
* don't re-read config between multiple runs
1 parent f08ac02 commit 41278dd

File tree

6 files changed

+42
-69
lines changed

6 files changed

+42
-69
lines changed

README.adoc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Modern SQL shells like `mssql-cli`, `mycli`, `SQLcl` and `pgcli` are very conven
1212
* a standard interface to enter connection parameters so you don't have to remember command line options
1313
* pre-defined connection strings for connection without typing
1414
* automatic tunneling if your database is behind a firewall or listening only on localhost interface
15-
* legacy client support
1615

1716
== Requirements ==
1817
* SQL shell clients (https://github.com/dbcli/mssql-cli[`mssql-cli`], https://www.mycli.net[`mycli`], https://www.oracle.com/database/technologies/appdev/sqlcl.html[`SQLcl`], https://www.pgcli.com[`pgcli`], https://litecli.com[`litecli`]) or legacy clients (`sqlcmd`, `mysql`, `SQLPlus`, `psql`, `sqlite3`)
@@ -37,6 +36,3 @@ image:screenshots/DSN.png[width=65%]
3736

3837
=== tunnel
3938
image:screenshots/tunnel.png[width=65%]
40-
41-
=== legacy client
42-
image:screenshots/legacy-client.png[width=65%]

docs/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ SQL Shell makes using SQL clients even more convenient:
55
* a standard interface to enter connection parameters so you don't have to remember command line options
66
* pre-defined connection strings for connection without typing
77
* automatic tunneling if your database is behind a firewall or listening only on localhost interface
8-
* legacy client support
98

109
![SQL Shell interface](https://raw.githubusercontent.com/thorstenkampe/SQL-Shell/main/screenshots/standard-pgcli.png)

screenshots/legacy-client.png

-77.3 KB
Binary file not shown.

sql shell.exe

245 KB
Binary file not shown.

sql shell.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
;shell =
99
;startup_file =
1010
;help =
11+
;legacy = true
1112

1213
;[DSN]
1314
; <db_type>: <name> = <arguments>

sql shell.py

Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@
1111

1212
tunnel.logger.setLevel('DEBUG')
1313
os.environ['ESCDELAY'] = '0' # no delay on Linux for Escape key
14+
15+
# Read config file
1416
# specify delimiter because of DSNs ("MSSQL: name = ...")
1517
config = configparser.ConfigParser(delimiters='=')
1618

17-
def read_config():
18-
if tb.is_pyinstaller():
19-
# https://pyinstaller.readthedocs.io/en/stable/runtime-information.html#using-sys-executable-and-sys-argv-0
20-
script_dir = sys.executable
21-
else:
22-
script_dir = __file__
23-
# config file in same directory as this file
24-
config_file = pathlib.Path(script_dir).with_name('sql shell.ini')
25-
config.optionxform = str # don't lowercase DSNs
26-
config.read(config_file, encoding='utf-8')
27-
try:
28-
os.environ.update(config['Environment'])
29-
except KeyError:
30-
pass
19+
if tb.is_pyinstaller():
20+
# https://pyinstaller.readthedocs.io/en/stable/runtime-information.html#using-sys-executable-and-sys-argv-0
21+
script_dir = sys.executable
22+
else:
23+
script_dir = __file__
24+
# config file in same directory as this file
25+
config_file = pathlib.Path(script_dir).with_name('sql shell.ini')
26+
config.optionxform = str # don't lowercase DSNs
27+
config.read(config_file, encoding='utf-8')
28+
try:
29+
os.environ.update(config['Environment'])
30+
except KeyError:
31+
pass
3132

3233
class DbApp(NPSAppManaged):
3334
def onStart(self):
@@ -42,11 +43,6 @@ def create(self):
4243
self.dbtype = self.add(TitleCombo, name='* Database type:', value=0, values=['...']
4344
+ dbms_types, **widget_defaults)
4445

45-
self.legacy_client = self.add(TitleMultiSelect, name='- Legacy client:',
46-
value=None, values=[''], max_height=2, scroll_exit=True,
47-
**widget_defaults)
48-
49-
# DSNs changes in config file will not be updated in this widget
5046
try:
5147
dsns = ['...'] + [f'{index+1}. {item}' for index, item in enumerate(config['DSN'])]
5248
except KeyError:
@@ -109,12 +105,7 @@ def on_ok(self): # NOSONAR
109105
notify_confirm('User is mandatory!', title='ERROR', editw=True)
110106
return
111107

112-
read_config()
113108
dbtype = dbms_types[self.dbtype.value - 1]
114-
if self.legacy_client.value:
115-
shelltype = f'{dbtype}-2'
116-
else:
117-
shelltype = dbtype
118109
try:
119110
dsn = config['DSN'][list(config['DSN'])[self.dsn.value - 1]]
120111
except KeyError:
@@ -125,13 +116,14 @@ def on_ok(self): # NOSONAR
125116
db = self.db.value
126117

127118
try:
128-
section = config[shelltype]
119+
section = config[dbtype]
129120
except KeyError:
130121
section = {}
131122

132123
prompt = section.get('prompt', '')[1:-1]
133124
startup_file = section.get('startup_file', '')
134125
sqlhelp = section.get('help')
126+
legacy = section.get('legacy')
135127

136128
# CONNECTION PARAMETERS AND OPTIONS
137129
opts = []
@@ -141,20 +133,17 @@ def on_ok(self): # NOSONAR
141133
port = self.port.value or 1433
142134
conn_params = ['-U', user, '-P', passwd, '-S', '{host},{port}', '-d', db]
143135

144-
if self.legacy_client.value:
136+
if legacy:
145137
defshell = 'sqlcmd'
138+
opts = ['-N', '-C']
139+
env_vars = {'SQLCMDINI': startup_file}
146140
else:
147141
if pycompat.system.is_windows:
148142
defshell = 'mssql-cli.bat'
149143
else:
150144
defshell = 'mssql-cli'
151-
152-
# `-N -C` = "encrypt, trust server certificate" (NOSONAR)
153-
if shelltype == 'MSSQL':
154-
opts = ['-N', '-C', '--mssqlclirc', startup_file]
155-
else:
156-
opts = ['-N', '-C']
157-
env_vars = {'SQLCMDINI': startup_file}
145+
# `-N -C` = "encrypt, trust server certificate" (NOSONAR)
146+
opts = ['-N', '-C', '--mssqlclirc', startup_file]
158147

159148
# named pipe connection to LocalDB
160149
if tb.is_localdb(dsn) or tb.is_localdb(host):
@@ -165,34 +154,36 @@ def on_ok(self): # NOSONAR
165154
port = self.port.value or 3306
166155
conn_params = ['-u', user, '-h', '{host}', '-P', '{port}', '-D', db]
167156

168-
if self.legacy_client.value:
157+
if legacy:
169158
defshell = 'mysql'
159+
opts = ['--protocol=TCP']
160+
if startup_file:
161+
# `--defaults-file` must be first option
162+
opts = [f'--defaults-file={startup_file}'] + opts
163+
170164
else:
171165
defshell = 'mycli'
166+
if startup_file:
167+
opts = ['--myclirc', startup_file]
172168

173169
if passwd:
174170
conn_params += [f'-p{passwd}']
175171

176-
if shelltype == 'MySQL':
177-
if startup_file:
178-
opts = ['--myclirc', startup_file]
179-
else:
180-
opts = ['--protocol=TCP']
181-
if startup_file:
182-
# `--defaults-file` must be first option
183-
opts = [f'--defaults-file={startup_file}'] + opts
184-
185172
elif dbtype == 'Oracle':
186173
port = self.port.value or 1521
187174
conn_params = [f'{user}/{passwd}@//{{host}}:{{port}}']
188175

189-
if self.legacy_client.value:
176+
if legacy:
190177
defshell = 'sqlplus'
178+
opts = ['-l']
179+
env_vars = {'SQLPATH': ''}
191180
else:
192181
if pycompat.system.is_windows:
193182
defshell = 'sql.exe'
194183
else:
195184
defshell = 'sql'
185+
opts = ['-logon']
186+
env_vars = {'SQLPATH': startup_file}
196187

197188
if db:
198189
# SQLcl can't handle `user@host/` connection strings
@@ -201,28 +192,18 @@ def on_ok(self): # NOSONAR
201192
if user == 'sys':
202193
conn_params += ['as', 'sysdba']
203194

204-
if shelltype == 'Oracle':
205-
opts = ['-logon']
206-
env_vars = {'SQLPATH': startup_file}
207-
else:
208-
opts = ['-l']
209-
env_vars = {'SQLPATH': ''}
210-
211195
elif dbtype == 'PostgreSQL':
212196
port = self.port.value or 5432
213197
conn_params = [f'postgres://{user}:{passwd}@{{host}}:{{port}}/{db}']
214198

215-
if self.legacy_client.value:
199+
if legacy:
216200
defshell = 'psql'
201+
env_vars = {'PSQLRC': startup_file}
217202
else:
218203
defshell = 'pgcli'
219-
220-
if shelltype == 'PostgreSQL':
221-
opts = ['--pgclirc', startup_file]
204+
opts = ['--pgclirc', startup_file]
222205
if prompt:
223206
opts += ['--prompt', prompt]
224-
else:
225-
env_vars = {'PSQLRC': startup_file}
226207

227208
elif dbtype == 'SQLite':
228209
# don't start tunnel for SQLite
@@ -235,17 +216,14 @@ def on_ok(self): # NOSONAR
235216
else:
236217
conn_params = [db]
237218

238-
if self.legacy_client.value:
219+
if legacy:
239220
defshell = 'sqlite3'
221+
opts = ['-init', startup_file]
240222
else:
241223
defshell = 'litecli'
242-
243-
if shelltype == 'SQLite':
244-
opts = ['--liteclirc', startup_file]
224+
opts = ['--liteclirc', startup_file]
245225
if prompt:
246226
opts += ['--prompt', prompt]
247-
else:
248-
opts = ['-init', startup_file]
249227

250228
# noinspection PyUnboundLocalVariable
251229
sqlshell = section.get('shell', defshell)
@@ -286,6 +264,5 @@ def on_ok(self): # NOSONAR
286264
click.pause()
287265
click.clear()
288266

289-
read_config()
290267
click.clear()
291268
DbApp().run()

0 commit comments

Comments
 (0)