Fix medium/low severity issues: script splitter, EXPLAIN, keyring, imports
execute_script() semicolon splitter (all drivers)
- Add BaseDriver._split_statements() that tracks single/double-quoted
strings and -- / /* */ comments so semicolons inside procedure bodies
are not treated as statement boundaries.
- Replace the naive sql.split(';') in all four drivers with this helper.
- MSSQL execute_script() also pre-splits on GO (case-insensitive, own
line) so scripts pasted from SSMS work correctly.
MSSQL EXPLAIN
- SET SHOWPLAN_TEXT ON/execute/SET SHOWPLAN_TEXT OFF must be separate
execute() calls; pyodbc rejects multiple statements in one call.
Hold self._lock for the entire sequence to keep session state atomic.
Keyring (connections.py)
- Log warnings (with traceback) on load/save failures instead of
silently returning "".
- save_password() now calls delete_password() when password is empty,
so clearing a saved password actually removes the old keyring entry
rather than leaving a stale one behind.
SQLite get_tables() O(N) lock acquisitions
- Run all COUNT(*) queries inside the same `with self._cur() as c:`
block, reducing N+1 lock acquisitions to 1.
Unused import: remove psycopg2.extras from postgres_driver.py.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,9 @@ from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from app.models.connection_model import ConnectionProfile
|
||||
from app.utils.logger import get_logger
|
||||
|
||||
_log = get_logger(__name__)
|
||||
|
||||
_CONN_FILE = Path.home() / ".dbclient" / "connections.json"
|
||||
|
||||
@@ -23,8 +26,15 @@ _SERVICE = "DBClient"
|
||||
# ── Keyring helpers ──────────────────────────────────────────────────────────
|
||||
|
||||
def save_password(profile_id: str, password: str) -> None:
|
||||
if _KEYRING_OK and password:
|
||||
keyring.set_password(_SERVICE, profile_id, password)
|
||||
if not _KEYRING_OK:
|
||||
return
|
||||
if password:
|
||||
try:
|
||||
keyring.set_password(_SERVICE, profile_id, password)
|
||||
except Exception:
|
||||
_log.warning("keyring: failed to save password for %s", profile_id, exc_info=True)
|
||||
else:
|
||||
delete_password(profile_id)
|
||||
|
||||
|
||||
def load_password(profile_id: str) -> str:
|
||||
@@ -32,6 +42,7 @@ def load_password(profile_id: str) -> str:
|
||||
try:
|
||||
return keyring.get_password(_SERVICE, profile_id) or ""
|
||||
except Exception:
|
||||
_log.warning("keyring: failed to load password for %s", profile_id, exc_info=True)
|
||||
return ""
|
||||
return ""
|
||||
|
||||
@@ -41,7 +52,7 @@ def delete_password(profile_id: str) -> None:
|
||||
try:
|
||||
keyring.delete_password(_SERVICE, profile_id)
|
||||
except Exception:
|
||||
pass
|
||||
pass # Already absent is fine
|
||||
|
||||
|
||||
# ── Profile CRUD ─────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user