-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite_debugging.py
More file actions
43 lines (31 loc) Β· 1.58 KB
/
Copy pathsqlite_debugging.py
File metadata and controls
43 lines (31 loc) Β· 1.58 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
import sqlite3
def debug_and_update_database():
print("π Starting Sudhir's Advanced DB Debugging Script...\n")
db_name = "sudhir_projects.db"
conn = sqlite3.connect(db_name)
cursor = conn.cursor()
try:
# 1.UPDATE TRICK: Increasing the budget for Job ID 2 (Glossary Project) from $55 to $75.
print("π§ Step 1: Updating budget for Job ID 2...")
cursor.execute("UPDATE upwork_jobs SET budget = 75.0 WHERE job_id = 2")
# 2.DELETE TRICK: Removing all duplicate records with an ID greater than 4 to clean up the database.
print("π§ Step 2: Removing duplicate records with ID > 3...")
cursor.execute("DELETE FROM upwork_jobs WHERE job_id > 3")
# Permanently saving (committing) changes to the repository.
conn.commit()
print("β
Success: Database cleaning and optimization completed.")
# 3. Viewing fresh, filtered data on the screen.
print("\nπ Reading Fresh Optimized Data from 'sudhir_projects.db':")
print("-" * 60)
cursor.execute("SELECT * FROM upwork_jobs")
rows = cursor.fetchall()
for row in rows:
print(f"π Job ID: {row[0]} | πΌ Title: {row[1]} | π° Budget: ${row[2]} | π Status: {row[3]}")
print("-" * 60)
print("\nπ Advanced SQL Debugging executed with 100% data integrity!")
except Exception as e:
print(f"β Debugging Error: {e}")
finally:
conn.close()
if __name__ == "__main__":
debug_and_update_database()