Skip to content

Commit 1385d4e

Browse files
committed
- no default database user anymore; it was confusing in connection with password entry
- disable editing host, port, user, and password field if SQLite selected
1 parent 2516298 commit 1385d4e

4 files changed

Lines changed: 16 additions & 24 deletions

File tree

sql shell.exe

5.19 MB
Binary file not shown.

sql shell.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
}
1313

1414
dbms_defaults = {
15-
'MSSQL': {'shell': 'mssql-cli', 'shell-windows': 'mssql-cli.bat', 'legacy': 'sqlcmd'},
16-
'MySQL': {'shell': 'mycli', 'legacy': 'mysql'},
17-
'Oracle': {'shell': 'sql', 'shell-windows': 'sql.exe', 'legacy': 'sqlplus'},
18-
'PostgreSQL': {'shell': 'pgcli', 'legacy': 'psql'},
15+
'MSSQL': {'shell': 'mssql-cli', 'shell-windows': 'mssql-cli.bat', 'legacy': 'sqlcmd', 'port': 1433},
16+
'MySQL': {'shell': 'mycli', 'legacy': 'mysql', 'port': 3306},
17+
'Oracle': {'shell': 'sql', 'shell-windows': 'sql.exe', 'legacy': 'sqlplus', 'port': 1521},
18+
'PostgreSQL': {'shell': 'pgcli', 'legacy': 'psql', 'port': 5432},
1919
'SQLite': {'shell': 'litecli', 'legacy': 'sqlite3'}
2020
}
2121

@@ -75,7 +75,7 @@ def create(self):
7575
self.passwd = self.add(TitlePassword, name='- Password:', value=None, **widget_defaults)
7676

7777
def adjust_widgets(self):
78-
# hide all fields except legacy client and database type if DSN selected
78+
# hide host, port, database, user, and password field if DSN selected
7979
for field in self.host, self.port, self.db, self.user, self.passwd:
8080
field.hidden = self.dsn.value
8181

@@ -93,6 +93,10 @@ def adjust_widgets(self):
9393
# field
9494
self.dbtype.editable = False
9595

96+
# disable editing host, port, user, and password field if SQLite selected
97+
for field in self.host, self.port, self.user, self.passwd:
98+
field.editable = self.dbtype.value != 5 # `5` is SQLite
99+
96100
self.display()
97101

98102
def on_cancel(self):
@@ -104,6 +108,10 @@ def on_ok(self): # NOSONAR
104108
notify_confirm('Database type is mandatory!', title='ERROR', editw=True)
105109
return
106110

111+
if not (self.user.value or self.dbtype.value == 5): # `5` is SQLite
112+
notify_confirm('User is mandatory!', title='ERROR', editw=True)
113+
return
114+
107115
read_config()
108116
dbtype = list(dbms_defaults)[self.dbtype.value - 1]
109117
db_defaults = dbms_defaults[dbtype]
@@ -113,8 +121,8 @@ def on_ok(self): # NOSONAR
113121
except KeyError:
114122
dsn = ''
115123
host = self.host.value or 'localhost'
116-
port = self.port.value or tb.defaults['port'].get(dbtype.lower())
117-
user = self.user.value or tb.defaults['db_user'].get(dbtype.lower())
124+
port = self.port.value or db_defaults.get('port')
125+
user = self.user.value
118126
passwd = self.passwd.value
119127
db = self.db.value
120128

toolbox.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
import sys, urllib
22

3-
defaults = {
4-
'port': {
5-
'mssql': 1433,
6-
'mysql': 3306,
7-
'oracle': 1521,
8-
'postgresql': 5432
9-
},
10-
11-
'db_user': {
12-
'mssql': 'sa',
13-
'mysql': 'root',
14-
'oracle': 'sys',
15-
'postgresql': 'postgres'
16-
}
17-
}
18-
193
def is_localdb(dsn):
204
localdb = r'(localdb)\mssqllocaldb'
215
parsed_url = urllib.parse.urlsplit(dsn)

tunnel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def tunnel(remote_host, remote_port, local_port=0): # `0` means random port
4040
try:
4141
section = config[remote_host]
4242
except KeyError:
43-
# remote host is not in ini file so we don't need a real tunnel
43+
# remote host is not in ini file, so we don't need a real tunnel
4444
tunnel = MockTunnel(
4545
local_bind_host = remote_host,
4646
local_bind_port = remote_port

0 commit comments

Comments
 (0)