PythiloLesson 5 of 8 · progress kept in this browser

Keep SQL values out of SQL syntax

Interpolating a user value into SQL lets quotes change the meaning of the query. Parameters transmit values separately from the statement. They also handle empty strings and embedded quotes without manual escaping. An in-memory SQLite database is enough to practise this boundary, and results should have an explicit order so callers receive predictable output.

import sqlite3
con = sqlite3.connect(":memory:")
row = con.execute("SELECT ?", ("O'Neil",))
print(row.fetchone())
Your task

Write lookup_names(connection, prefix). The connection has people(name TEXT). Return names beginning with the literal prefix, sorted by name. Use a bound parameter. Percent and underscore in the prefix are literal characters, not LIKE wildcards.