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("INSERT INTO products (name, price) VALUES (?, ?)", (n, p)) | Acursor.execute("INSERT INTO products (name, price) VALUES (?, ?)", ("Ruler", 2.5)) conn.commit() | |
| 2conn.commit() | Bcommit() was never called before closing the connection, so the new product is not saved. It needs conn.commit() before conn.close(). | |
| 3The number of ? placeholders must match the number of columns listed, and the tuple must hold the same number of values | CAdds a new product record, with the ? placeholders filled safely from the values in the tuple (n, p) | |
| 4After executing an INSERT, call commit() on the connection to make the new record permanent | DSaves the INSERT permanently to the database file | |
| 5cursor.execute("INSERT INTO products (name, price) VALUES (?, ?)", (n)) | EThere are two ? placeholders but the values are not given as a tuple with two items, so the second value is missing and the query fails. It should be (n, p). | |
| 6cursor.execute("INSERT INTO products (name, price) VALUES (?, ?)", (n, p)) conn.close() | Fcursor.execute("INSERT INTO students (firstName, house) VALUES (?, ?)", (first, house)) |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
cursor.execute("INSERT INTO products (name, price) VALUES (?, ?)", (n, p)) — Adds a new record using ? placeholders filled safely from a tuple of values. The new row is only saved to the database file once conn.commit() is called.q = "INSERT INTO products (name) VALUES (?)"
cursor.execute(q, (name,))
conn.commit()q = "INSERT INTO products (name) VALUES (?)"
cursor.execute(q, (name,))
conn.commit()cursor.execute(q, (name,))
conn.commit()name = "Ruler"
cursor.execute(q, (name,))
conn.commit()q = "INSERT INTO products (name) VALUES (?)"
cursor.execute(q, (name,))
conn.commit()