Ok, I've been fighting with this for a while now I find it impossible to add string with ' to SQLite database.
I have a simple code that uses pysqlite:
Code:
db_conn = sqlite.connect("test.db")
db_cur = db_conn.cursor()
db_cur.execute("UPDATE test_table SET field_1='%s' WHERE field_2='%s'" % (data, condition))
db_conn.commit()
db_conn.close()
Now, if data is a string:
Code:
It's nice to program with python!
It fails to update it. It seems to be, because of ' char. Without that everything works. Now I've tried to escape that char away with
Code:
data.replace('\'','\\\'')
But it stll fails...
Any ideas? Is there a better way to do escaping for SQL strings?
Bookmarks