Reputation: 3153
I am inputting a variable of datatype string in Sqlite database with my Python script.So whenever i am inserting that value i am getting Sqlite error:
sqlite3.OperationalError: near "s": syntax error
My variable string is something like this:
file_path=r'James Bond 007 - 07 - On Her Majesty's Secret Service (1969)'
Actually i am getting this file name directly from os.walk
so i can't escape that single string by putting backslash manually.I want some string method which automatically escapes the content inside string.
Upvotes: 3
Views: 2472
Reputation: 11
Using a forward slash seems to work for me but I haven't had any trouble with single quotes.
So:
"\"this seems to work fine.\""
Upvotes: 1
Reputation: 798576
You're doing it wrong.
cursor.execute("INSERT ... (?, ?, ?)", (var1, var2, var3))
Upvotes: 10