Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Note, I haven't tested this, but you can probably avoid the question mark confusion by replacing them with "{0} {1} {2}" in the relevant places and then changing the last line to cursor.execute(query.format(vars)). That should take care of your only "con" (I hope). Commented Mar 31, 2018 at 12:28
  • Yes, using format would be nice but I'm not sure whether the query string formatted that way would be safe from SQL injection. Commented Apr 2, 2018 at 8:31
  • Yeah, that's a fair point and it could certainly get a bit tricky. Perhaps testing it on something entirely expendable would be wise ... no doubt a Comp. Sci. undergrad will wander past soon enough. ;) Commented Apr 4, 2018 at 2:15
  • 3
    @Ben if you do cursor.execute(query.format(vars)) you do not profit from prepared statements anymore so you are vulnerable to many kind of problems, starting with the fact that if the parameters are not just numbers you need to double quote them in the SQL query. Commented Aug 30, 2018 at 21:51