-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset.py
More file actions
74 lines (56 loc) · 1.9 KB
/
reset.py
File metadata and controls
74 lines (56 loc) · 1.9 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Database Reset Utility
WARNING: This script will DELETE all data from the Attendance database.
Use only for testing or when you need to completely reset the system.
Usage:
python reset.py
"""
import sqlite3
import sys
def reset_database(db_path='Attendance.db'):
"""
Drop all tables from the database.
Args:
db_path: Path to the SQLite database file
Returns:
True if successful, False otherwise
"""
try:
conn = sqlite3.connect(db_path)
cur = conn.cursor()
print(f"Connecting to database: {db_path}")
# Get list of all tables
cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cur.fetchall()
if not tables:
print("Database is already empty")
return True
print(f"Found {len(tables)} table(s) to drop:")
for table in tables:
print(f" - {table[0]}")
# Confirm before deleting
response = input("\nAre you sure you want to delete ALL data? (yes/no): ").strip().lower()
if response != 'yes':
print("Reset cancelled")
return False
# Drop all tables
for table in tables:
table_name = table[0]
try:
cur.execute(f"DROP TABLE {table_name}")
print(f"✓ Dropped table: {table_name}")
except sqlite3.Error as e:
print(f"✗ Error dropping table {table_name}: {e}")
conn.commit()
conn.close()
print("\n✓ Database reset complete!")
return True
except sqlite3.Error as e:
print(f"Database error: {e}")
return False
except Exception as e:
print(f"Error: {e}")
return False
if __name__ == "__main__":
success = reset_database()
sys.exit(0 if success else 1)