Skip to content

Commit 5560e21

Browse files
committed
remove legacy support
1 parent 41278dd commit 5560e21

File tree

4 files changed

+44
-65
lines changed

4 files changed

+44
-65
lines changed

Diff for: sql shell.exe

-3.35 MB
Binary file not shown.

Diff for: sql shell.ini

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
;; sample SQL Shell configuration file
22

3-
;[Environment]
3+
;[general]
4+
;legacy = false
5+
6+
;[environment]
47
;EDITOR =
58
;PAGER =
69

7-
;[MSSQL]
10+
;[mssql]
811
;shell =
912
;startup_file =
1013
;help =
11-
;legacy = true
1214

13-
;[DSN]
15+
;[mssql legacy]
16+
;shell =
17+
;help =
18+
19+
;[dsn]
1420
; <db_type>: <name> = <arguments>
1521
;MSSQL: Ubuntu = -S db -U sa -P password
1622
;MySQL: Ubuntu = -u root -ppassword -h db

Diff for: sql shell.py

+31-58
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
config.optionxform = str # don't lowercase DSNs
2727
config.read(config_file, encoding='utf-8')
2828
try:
29-
os.environ.update(config['Environment'])
29+
os.environ.update(config['environment'])
3030
except KeyError:
3131
pass
3232

@@ -44,7 +44,7 @@ def create(self):
4444
+ dbms_types, **widget_defaults)
4545

4646
try:
47-
dsns = ['...'] + [f'{index+1}. {item}' for index, item in enumerate(config['DSN'])]
47+
dsns = ['...'] + [f'{index+1}. {item}' for index, item in enumerate(config['dsn'])]
4848
except KeyError:
4949
dsns = ['...']
5050
self.dsn = self.add(TitleCombo, name='- DSN:', value=0, values=dsns,
@@ -105,9 +105,9 @@ def on_ok(self): # NOSONAR
105105
notify_confirm('User is mandatory!', title='ERROR', editw=True)
106106
return
107107

108-
dbtype = dbms_types[self.dbtype.value - 1]
108+
dbtype = dbms_types[self.dbtype.value - 1].lower()
109109
try:
110-
dsn = config['DSN'][list(config['DSN'])[self.dsn.value - 1]]
110+
dsn = config['dsn'][list(config['dsn'])[self.dsn.value - 1]]
111111
except KeyError:
112112
dsn = ''
113113
host = self.host.value or 'localhost'
@@ -123,67 +123,48 @@ def on_ok(self): # NOSONAR
123123
prompt = section.get('prompt', '')[1:-1]
124124
startup_file = section.get('startup_file', '')
125125
sqlhelp = section.get('help')
126-
legacy = section.get('legacy')
127126

128127
# CONNECTION PARAMETERS AND OPTIONS
129128
opts = []
130129
env_vars = {}
131130

132-
if dbtype == 'MSSQL':
131+
if dbtype == 'mssql':
133132
port = self.port.value or 1433
134133
conn_params = ['-U', user, '-P', passwd, '-S', '{host},{port}', '-d', db]
135134

136-
if legacy:
137-
defshell = 'sqlcmd'
138-
opts = ['-N', '-C']
139-
env_vars = {'SQLCMDINI': startup_file}
135+
if pycompat.system.is_windows:
136+
defshell = 'mssql-cli.bat'
140137
else:
141-
if pycompat.system.is_windows:
142-
defshell = 'mssql-cli.bat'
143-
else:
144-
defshell = 'mssql-cli'
145-
# `-N -C` = "encrypt, trust server certificate" (NOSONAR)
146-
opts = ['-N', '-C', '--mssqlclirc', startup_file]
138+
defshell = 'mssql-cli'
139+
# `-N -C` = "encrypt, trust server certificate" (NOSONAR)
140+
opts = ['-N', '-C', '--mssqlclirc', startup_file]
147141

148142
# named pipe connection to LocalDB
149143
if tb.is_localdb(dsn) or tb.is_localdb(host):
150144
conn_params[5] = '{host}' # host,port -> host
151145
opts.remove('-N') # `-N` = "encrypt" (NOSONAR)
152146

153-
elif dbtype == 'MySQL':
147+
elif dbtype == 'mysql':
154148
port = self.port.value or 3306
155149
conn_params = ['-u', user, '-h', '{host}', '-P', '{port}', '-D', db]
156150

157-
if legacy:
158-
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-
164-
else:
165-
defshell = 'mycli'
166-
if startup_file:
167-
opts = ['--myclirc', startup_file]
151+
defshell = 'mycli'
152+
if startup_file:
153+
opts = ['--myclirc', startup_file]
168154

169155
if passwd:
170156
conn_params += [f'-p{passwd}']
171157

172-
elif dbtype == 'Oracle':
158+
elif dbtype == 'oracle':
173159
port = self.port.value or 1521
174160
conn_params = [f'{user}/{passwd}@//{{host}}:{{port}}']
175161

176-
if legacy:
177-
defshell = 'sqlplus'
178-
opts = ['-l']
179-
env_vars = {'SQLPATH': ''}
162+
if pycompat.system.is_windows:
163+
defshell = 'sql.exe'
180164
else:
181-
if pycompat.system.is_windows:
182-
defshell = 'sql.exe'
183-
else:
184-
defshell = 'sql'
185-
opts = ['-logon']
186-
env_vars = {'SQLPATH': startup_file}
165+
defshell = 'sql'
166+
opts = ['-logon']
167+
env_vars = {'SQLPATH': startup_file}
187168

188169
if db:
189170
# SQLcl can't handle `user@host/` connection strings
@@ -192,20 +173,16 @@ def on_ok(self): # NOSONAR
192173
if user == 'sys':
193174
conn_params += ['as', 'sysdba']
194175

195-
elif dbtype == 'PostgreSQL':
176+
elif dbtype == 'postgresql':
196177
port = self.port.value or 5432
197178
conn_params = [f'postgres://{user}:{passwd}@{{host}}:{{port}}/{db}']
198179

199-
if legacy:
200-
defshell = 'psql'
201-
env_vars = {'PSQLRC': startup_file}
202-
else:
203-
defshell = 'pgcli'
204-
opts = ['--pgclirc', startup_file]
205-
if prompt:
206-
opts += ['--prompt', prompt]
180+
defshell = 'pgcli'
181+
opts = ['--pgclirc', startup_file]
182+
if prompt:
183+
opts += ['--prompt', prompt]
207184

208-
elif dbtype == 'SQLite':
185+
elif dbtype == 'sqlite':
209186
# don't start tunnel for SQLite
210187
host = None
211188
port = None
@@ -216,14 +193,10 @@ def on_ok(self): # NOSONAR
216193
else:
217194
conn_params = [db]
218195

219-
if legacy:
220-
defshell = 'sqlite3'
221-
opts = ['-init', startup_file]
222-
else:
223-
defshell = 'litecli'
224-
opts = ['--liteclirc', startup_file]
225-
if prompt:
226-
opts += ['--prompt', prompt]
196+
defshell = 'litecli'
197+
opts = ['--liteclirc', startup_file]
198+
if prompt:
199+
opts += ['--prompt', prompt]
227200

228201
# noinspection PyUnboundLocalVariable
229202
sqlshell = section.get('shell', defshell)
@@ -234,7 +207,7 @@ def on_ok(self): # NOSONAR
234207
port = None
235208

236209
# DSNs have precedence over manually entered connection parameters
237-
if dbtype == 'SQLite':
210+
if dbtype == 'sqlite':
238211
conn_params = [dsn]
239212
else:
240213
conn_params = dsn.split()

Diff for: toolbox.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import sys, urllib
2-
31
def is_localdb(dsn):
2+
import urllib
43
localdb = r'(localdb)\mssqllocaldb'
54
parsed_url = urllib.parse.urlsplit(dsn)
65

@@ -13,6 +12,7 @@ def is_localdb(dsn):
1312
else:
1413
return False
1514

16-
# https://pyinstaller.readthedocs.io/en/stable/runtime-information.html
1715
def is_pyinstaller():
16+
# https://pyinstaller.readthedocs.io/en/stable/runtime-information.html
17+
import sys
1818
return getattr(sys, 'frozen', False)

0 commit comments

Comments
 (0)