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 | |
|---|---|---|
| 1cursor.execute("SELECT name, price FROM products") | Afetchall() is called before execute(), so there is no query to fetch rows from. The query must be run first. | |
| 2rows = cursor.fetchall() | BThe brackets are missing after fetchall, so the method is never called. rows holds the method itself, not the data. | |
| 3fetchone() returns just the first row as a single tuple, so you can read one record without a list. | Cif rows == []: | |
| 4A SELECT that matches no rows gives an empty list, so you can check for it with an if statement. | DSends the SELECT query to the database to run it. The rows are not returned yet; they wait to be fetched. | |
| 5rows = cursor.fetchall print(rows) | ECollects every row from the SELECT as a list of tuples, or an empty list [] if nothing matched. | |
| 6rows = cursor.fetchall() 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.fetchall() — Returns every row from the SELECT that cursor.execute() ran, as a list of tuples. An empty result gives an empty list []. fetchone() returns just one row.cursor.execute("SELECT * FROM students")cursor.execute("SELECT name FROM subjects")
rows = cursor.fetchall()cursor.execute("SELECT * FROM students")
row = cursor.fetchone()rows = cursor.fetchall()
if len(rows) == 0:
print("No rows found")rows = cursor.fetchall()
for row in rows:
print(row[0])