Skip to content

Commit dcfd541

Browse files
committed
added docs about parameterising queries in WhereRaw
1 parent 5be3ea5 commit dcfd541

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

docs/src/piccolo/query_clauses/where.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,29 @@ Rather than using the ``|`` and ``&`` characters, you can use the ``And`` and
167167
WhereRaw
168168
--------
169169

170-
In certain situations you may want to have raw SQL in your where clause. For
171-
example, there could be a Postgres function you need to call.
170+
In certain situations you may want to have raw SQL in your where clause.
172171

173172
.. code-block:: python
174173
175174
from piccolo.columns.combination import WhereRaw
176175
177-
b = Band
178-
b.select().where(
176+
Band.select().where(
179177
WhereRaw("name = 'Pythonistas'")
180178
).run_sync()
181179
180+
It's important to parameterise your SQL statements if the values come from an
181+
untrusted source, otherwise it could lead to a SQL injection attack.
182+
183+
.. code-block:: python
184+
185+
from piccolo.columns.combination import WhereRaw
186+
187+
value = "Could be dangerous"
188+
189+
Band.select().where(
190+
WhereRaw("name = {}", value)
191+
).run_sync()
192+
182193
``WhereRaw`` can be combined into complex queries, just as you'd expect:
183194

184195
.. code-block:: python

0 commit comments

Comments
 (0)