Activity 01
Pair Coding: Try-Except SQL Insert
Pairs write a Python script using sqlite3 to connect to a database and insert data inside a try-except block. Introduce invalid input like non-numeric values to trigger IntegrityError. Pairs log the exception, fix it, and test again, noting improvements.
Explain the importance of error handling in database interactions.
Facilitation TipDuring Pair Coding: Try-Except SQL Insert, circulate and ask pairs why they chose particular exceptions like sqlite3.IntegrityError over generic ones.
What to look forPresent students with a Python code snippet that performs two database updates (e.g., updating a student's marks and then their attendance status). Ask them to identify where a try-except block should be added and what should happen in the except block (e.g., rollback). Then, ask them to write the specific SQL commands for commit and rollback.