-
-
Save anonymous/763eb2d58e1765235ae5aed5f616f661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import os | |
DB_FILENAME = "dbapi_question.sqlite" | |
os.chdir(os.path.dirname(os.path.realpath(__file__))) | |
try: | |
os.remove(DB_FILENAME) | |
except: | |
pass | |
# 0. Create DB | |
db = sqlite3.connect(DB_FILENAME) | |
db.execute(""" | |
CREATE TABLE books( | |
id integer, | |
name text) | |
""") | |
db.execute(""" | |
INSERT INTO books(id,name) VALUES (1,"Test Name") | |
""") | |
db.commit() | |
# 1. Works | |
db.execute("UPDATE books SET name=? WHERE id=?", | |
("Second Name", 1)) | |
db.commit() | |
# 2. Doesn't work | |
db.execute("UPDATE books SET ?=? WHERE id=?", | |
("name", "Third Name", 1)) | |
db.commit() | |
db.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment