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 | |
|---|---|---|
| 1cur.execute("DELETE FROM students WHERE studentId = ?", (sid,)) | AThe WHERE clause with the ? placeholder is missing, so the statement is not limited to one record. DELETE with no WHERE would remove every student. | |
| 2if cur.rowcount == 0: | BThe value is joined onto the SQL text instead of using a ? placeholder, which is unsafe and allows SQL injection. | |
| 3An UPDATE run from code uses a ? placeholder in WHERE so only the chosen student's points change. | CDeletes only the student whose studentId matches the value in sid, because the ? placeholder is filled safely by the tuple. | |
| 4After a DELETE, print a 'student not found' message when no rows were affected. | Dif cur.rowcount == 0: print("Student not found") | |
| 5cur.execute("DELETE FROM students", (sid,)) | EChecks whether no record was changed, which means the record was not found. | |
| 6cur.execute("UPDATE students SET points = 90 WHERE studentId = " + sid) | Fcur.execute("UPDATE students SET points = ? WHERE studentId = ?", (150, 3)) |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
DELETE FROM students WHERE studentId = ? — A parameterised DELETE or UPDATE run from code: the ? in WHERE is filled by a value so only that record changes. cursor.rowcount of 0 means record not found.sql = "DELETE FROM orders WHERE orderId = ?"
cursor.execute(sql, (order_id,))sql = "UPDATE orders SET quantity = ? "
sql += "WHERE orderId = ?"
cursor.execute(sql, (qty, order_id))if cursor.rowcount == 0:
print("Record not found")if cursor.rowcount == 0:
print("Record not found")cursor.execute(sql, (qty, order_id))
conn.commit()