The execute function can recognize it as a t-string and prevent SQL injection if the name is coming from user input. f-strings immediately evaluate to a string, whereas t-strings evaluate to a template object which requires further processing to turn it into a string.
Then the useful part is the extra execute function you have to write (it's not just a substitute like in the comment) and an extra function can confirm the safety of a value going into a f-string just as well.
I get the general case, but even then it seems like an implicit anti-pattern over doing db.execute(f"QUERY WHERE name = {safe(name)}")
ds_|10 months ago
Tenoke|10 months ago
I get the general case, but even then it seems like an implicit anti-pattern over doing db.execute(f"QUERY WHERE name = {safe(name)}")
teruakohatu|10 months ago
sureglymop|10 months ago
burky|10 months ago
Tenoke|10 months ago
sim7c00|10 months ago
imagine writing a SqL where u put user input into query string directly.
now remember its 2025, lie down try not to cry.
evertedsphere|10 months ago