@@ -51,6 +51,9 @@ def __init__(self):
5151 # Styling
5252 self ._setup_styles ()
5353
54+ # BUG 4: Sauberes Schließen via WM_DELETE_WINDOW
55+ self .protocol ("WM_DELETE_WINDOW" , self ._on_close )
56+
5457 def _setup_styles (self ):
5558 """Konfiguriere ttk Styles."""
5659 style = ttk .Style ()
@@ -288,7 +291,7 @@ def open_db(self):
288291 self .close_db ()
289292
290293 try :
291- conn = sqlite3 .connect (path )
294+ conn = sqlite3 .connect (f"file: { path } ?mode=ro" , uri = True )
292295 conn .row_factory = sqlite3 .Row
293296 self .conn = conn
294297 self .db_path = path
@@ -341,7 +344,10 @@ def load_selected_table(self):
341344 if not table or not self .conn :
342345 return
343346
344- limit = max (1 , int (self .limit_var .get () or DEFAULT_LIMIT ))
347+ try :
348+ limit = max (1 , int (self .limit_var .get ()))
349+ except (ValueError , TypeError ):
350+ limit = DEFAULT_LIMIT
345351
346352 try :
347353 # Spalten bestimmen
@@ -501,16 +507,21 @@ def execute_sql(self):
501507 start_time = datetime .now ()
502508 cur = self .conn .execute (sql )
503509
504- # Prüfe ob SELECT-Statement
505- if sql .upper ().strip ().startswith ("SELECT" ):
510+ # Prüfe ob SELECT-artiges Statement (BUG 2: WITH/EXPLAIN/PRAGMA eingeschlossen)
511+ sql_upper = sql .upper ().strip ()
512+ if sql_upper .startswith (("SELECT" , "WITH" , "EXPLAIN" , "PRAGMA" )):
506513 rows = cur .fetchall ()
514+ # BUG 3: Spaltenheader auch bei leeren Ergebnissen auslesen
515+ cols = [desc [0 ] for desc in cur .description ] if cur .description else []
507516 if rows :
508- cols = [desc [0 ] for desc in cur .description ]
509517 self ._populate_sql_result (cols , rows )
510518 elapsed = (datetime .now () - start_time ).total_seconds ()
511519 self .sql_status .config (text = f"✓ { len (rows )} Zeilen in { elapsed :.3f} s" )
512520 else :
513- self ._clear_sql_result ()
521+ if cols :
522+ self ._populate_sql_result (cols , [])
523+ else :
524+ self ._clear_sql_result ()
514525 self .sql_status .config (text = "✓ Keine Ergebnisse" )
515526 else :
516527 self .conn .commit ()
@@ -728,6 +739,11 @@ def _ident(self, name: str) -> str:
728739 def _set_status (self , text : str ):
729740 self .status_var .set (text )
730741
742+ def _on_close (self ):
743+ """Sauberes Schließen: DB schließen, dann Fenster zerstören."""
744+ self .close_db ()
745+ self .destroy ()
746+
731747 def _show_about (self ):
732748 messagebox .showinfo (
733749 "Über SQLite Viewer" ,
0 commit comments