Escaping chars in Python and sqlite

You’re doing it wrong. Literally. You should be using parameters, like this:

c.execute("UPDATE movies SET rating = ? WHERE name = ?", (8.7, "'Allo 'Allo! (1982)"))

Like that, you won’t need to do any quoting at all and (if those values are coming from anyone untrusted) you’ll be 100% safe (here) from SQL injection attacks too.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)