Skip to content

Instantly share code, notes, and snippets.

Created March 12, 2017 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/763eb2d58e1765235ae5aed5f616f661 to your computer and use it in GitHub Desktop.
Save anonymous/763eb2d58e1765235ae5aed5f616f661 to your computer and use it in GitHub Desktop.
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