|
|
|
|
|
by benwilber0
416 days ago
|
|
Aren't there other benefits to server-side parameter binding besides just SQL-injection safety? For instance, using PG's extended protocol (binary) instead of just raw SQL strings. Caching parameterized prepared statements, etc. Also: db.execute(t"QUERY WHERE name = {name}")
Is dangerously close to: db.execute(f"QUERY WHERE name = {name}")
A single character difference and now you've just made yourself trivially injectible.I don't think this new format specifier is in any way applicable to SQL queries. |
|
> Caching parameterized prepared statements, etc.
Templates give you all the data you need to also build things like cacheable parameterized prepared statements. For DB engines that support named parameters you can even get the interpolation expression to auto-name parameters (get the string "name" from your example as the name of the variable filling the slot) for additional debugging/sometimes caching benefits.