Application data must not become SQL syntax. Use a database driver’s parameter binding for values rather than concatenating strings. In Python’s standard SQLite library, assuming connection is an open SQLite connection:
rows = connection.execute(
'SELECT title FROM books WHERE shelf_id = ?', (shelf_id,)
).fetchall()
The placeholder receives a value separately from the statement. Placeholder syntax differs by driver. Parameters generally cannot stand for table names, column names, or SQL keywords: select those from a fixed allowlist rather than accepting arbitrary input. ORMs also need safe APIs; raw SQL or unsafe string construction can still introduce injection. Apply least privilege where the DBMS supports it, protect database files and credentials, and keep tested backups. SQLite file permissions and deployment differ from server account permissions. No single technique replaces security review.
The snippet illustrates a database driver call, not a complete Python program: shelf_id must already hold the value to look up, and the application must open and close the connection. A one-item Python tuple includes the trailing comma. Passwords require a dedicated password-storage design; do not treat a database’s access controls or parameter binding as a substitute for an appropriate password hashing scheme.