Parameterized Queries In Sqlite3 Using Question Marks
I am using sqlite3 module with Python and have this code so far. In the database I have stored daily weather conditions, and now I need my code to replace some rows with updated da
Solution 1:
You are mixin up a parameterized query with string operations. First, that's highly insecure and second, you have created a problem with your syntax (you missed a comma after your query string). Try this instead:
new_data = ('12 Mar 2014', 'sunny', 20, 12, '12 Mar 2014',)
conn = sqlite3.connect(database_file)
c = conn.cursor()
c.execute("UPDATE weather SET datetime = ?, condition = ?, high = ?, low = ? WHERE datetime = ?", new_data)
More details can be found here: https://docs.python.org/2/library/sqlite3.html
Post a Comment for "Parameterized Queries In Sqlite3 Using Question Marks"