Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1if is_valid(points): | ARun the validation function first and only continue to the SQL statement when it returns True | |
| 2else: print("Invalid points") | BReject the bad data with a message so the SQL never runs and the database is not changed | |
| 3Rejecting bad data before SQL runs: only execute the INSERT when the validation function returns True | Cif student_exists(student_id): cur.execute(sql, values) | |
| 4Foreign key existence check: confirm the studentId exists in students before inserting an order | Dif is_valid(points): cur.execute(sql, (name, points)) | |
| 5cur.execute(sql, (name, points)) if is_valid(points): conn.commit() | EThe INSERT runs before the validation check, so bad data is already sent to SQL. The execute call must be moved inside the if block. | |
| 6if student_exists: cur.execute(sql, values) | FThe function is not called because the brackets and argument are missing, so the name is always truthy and the check never runs. It should be student_exists(student_id). |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
if is_valid(points): — Run the validation function first and only execute the INSERT or UPDATE when it returns True, so bad data is rejected before SQL runs and never reaches the database.if valid(points):
cur.execute(sql, (points,))if valid(points):
cur.execute(sql, (points,))if not valid(points):
print("Invalid points")
returnif exists(cur, sid):
cur.execute(sql, (sid, mark))if valid(points):
cur.execute(sql, (points,))
conn.commit()