-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathispeziona_database.py
More file actions
36 lines (29 loc) · 1.04 KB
/
Copy pathispeziona_database.py
File metadata and controls
36 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sqlite3
def ispeziona_database():
# Connetti al database
conn = sqlite3.connect('ristorante1.db')
cursor = conn.cursor()
# Recupera l'elenco delle tabelle
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
print("Tabelle nel database:")
for table in tables:
print(f"- {table[0]}")
# Recupera la struttura della tabella
print(f" Struttura della tabella {table[0]}:")
cursor.execute(f"PRAGMA table_info({table[0]});")
columns = cursor.fetchall()
for column in columns:
print(f" {column[1]} ({column[2]})")
# Recupera i dati della tabella
print(f" Dati della tabella {table[0]}:")
cursor.execute(f"SELECT * FROM {table[0]};")
rows = cursor.fetchall()
if rows:
for row in rows:
print(f" {row}")
else:
print(" Nessun dato presente.")
print()
conn.close()
ispeziona_database()