jeudi 21 avril 2016

How to insert into sqlite (python) when my variable has single quote in it? [duplicate]

This question already has an answer here:

I am trying to insert data into database using sqlite in python. Now when I have a single quote in my variable, it gives error like

data = "This is my apple's seed."
cursor.execute("insert into tableName (ColName) values ('%s')" %data)
sqlite3.OperationalError: near "s": syntax error

I know that this problem occurred because I didn't escape characteres properly. How do I do that?

Aucun commentaire:

Enregistrer un commentaire