每次我尝试以下代码,都会出现“near”?“:语法错误”的错误。我尝试了多种方法,包括将其放入变量中进行准备。
在Python中,这是否可能?还是我想得太歪了?
import sqlite3
sqlite_file = 'DATABASE.db'
conn = sqlite3.connect(sqlite_file)
c = conn.cursor()
word = ()
question = int(input("What would you like to see?"))
if question == 1:
word = ("Batchnumbers")
if question == 2:
word = ("Worker IDs")
c.execute('SELECT * FROM ?', (word))
data = c.fetchall()
for x in range(len(data)):
print(data[x])
sqlite3
中没有安全执行以表名作为参数的SQL查询的选项,使用字符串插值也是不安全的,请在此处检查,因为他们提供了示例--> https://dev59.com/x3A75IYBdhLWcg3wg5fs - eagle