Skip to content

Commit b3667f7

Browse files
committed
Add a note about SQL injection
1 parent 2c393fb commit b3667f7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

CONTRIBUTING.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,19 @@ There are a few coding conventions we use in beets:
251251
To fetch Item objects from the database, use lib.items(…) and supply
252252
a query as an argument. Resist the urge to write raw SQL for your
253253
query. If you must use lower-level queries into the database, do
254-
this:
254+
this, for example:
255255

256256
.. code-block:: python
257257
258258
with lib.transaction() as tx:
259-
rows = tx.query("SELECT ")
259+
rows = tx.query("SELECT path FROM items WHERE album_id = ?", (album_id,))
260260
261261
Transaction objects help control concurrent access to the database
262262
and assist in debugging conflicting accesses.
263+
264+
Make sure that variables are passed to the query as a tuple to prevent SQL
265+
injection attacks.
266+
263267
- f-strings should be used instead of the ``%`` operator and ``str.format()``
264268
calls.
265269
- Never ``print`` informational messages; use the

0 commit comments

Comments
 (0)