私はこのコードを持っています:
conn = sqlite3.connect("testDB")
curs = conn.cursor()
curs.execute("CREATE TABLE IF NOT EXISTS testTable( col1 VARCHAR, col2 VARCHAR)")
c1 = "value1"
c2 = "value2"
curs.execute("INSERT INTO testTable VALUES (?,?)", (c1, c2))#this works fine
conn.commit()
def inDB(curs, table, col, value):
curs.execute("SELECT * FROM ? WHERE ?=?",(table, col, value)) #problemis here
return bool(curs.fetchone())
print inDB(curs, "testTable", "col1", c1)
それは私にこのエラーを与えます:
Traceback (most recent call last):
File "test.py", line 16, in <module>
print inDB(curs, "testTable", "col1", c1)
File "test.py", line 13, in inDB
curs.execute("SELECT * FROM ? WHERE ?=?",(table, col, value))
sqlite3.OperationalError: near "?": syntax error
これが機能しない理由と、これを修正するにはどうすればよいですか?