cursor.execute('SELECT * FROM users WHERE id = ?', (2,)) row = cursor.fetchone()
# This works because SQLite converts: cursor.execute('SELECT * FROM books WHERE rating = ?', ('4.5',)) # But it's cleaner to use the correct Python type: cursor.execute('SELECT * FROM books WHERE rating = ?', (4.5,)) sqlite3 tutorial query python fixed
The cursor is iterable, which is memory‑efficient: cursor
cursor.execute('UPDATE users SET email = ? WHERE id = ?', ('jane2@example.com', 2)) conn.commit() )) The cursor is iterable
If you use the raw conn.commit() and conn.close() , ensure they are in a finally block or use try/finally .
connection = sqlite3.connect('library.db', isolation_level=None)