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 | |
|---|---|---|
| 1rows = cursor.fetchall() | AReturns every row from the last SELECT as a list of tuples, such as [(1, 'Ava'), (2, 'Liam')]. | |
| 2conn.commit() | BThe change is never saved because conn.commit() is missing before the connection is closed. | |
| 3Use a ? placeholder and pass the value in a tuple, so the value is not pasted into the SQL text. | Ccursor.execute("SELECT * FROM students WHERE house = ?", (house,)) | |
| 4fetchone() returns only the next single row as a tuple, which suits a query that finds one record. | DThe order is wrong: execute() must run the SELECT first, and fetchall() must be called afterwards to get the rows. | |
| 5cursor.execute("UPDATE students SET points = 150 WHERE studentId = 1") conn.close() | ESaves the changes made by INSERT, UPDATE or DELETE so they stay in the database file. | |
| 6cursor.fetchall() rows = cursor.execute("SELECT * FROM students") | Frow = cursor.fetchone() |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
cursor.execute() — Runs an SQL statement from Python. Then fetchall() returns the result rows as tuples, and conn.commit() saves INSERT or UPDATE changes. Use ? placeholders for values.cursor.execute("SELECT * FROM students")cursor.execute("SELECT * FROM subjects")
rows = cursor.fetchall()
print(rows)sql = "UPDATE students SET points = 0"
cursor.execute(sql)
conn.commit()cursor.execute(
"SELECT * FROM results WHERE mark > ?",
(50,))cursor.execute("SELECT COUNT(*) FROM orders")
row = cursor.fetchone()
print(row[0])