1
我绝对是SQL新手,但我觉得插入非常简单。SQLITE3插入错误
insert(1, 2)
我得到的错误:
OperationalError: near "'1'": syntax error
所有字段是文本,是否可以帮助我通过下面我想不通的问题
def insert(title, name):
time = datetime.now()
conn = sqlite3.connect('test.db')
c = conn.cursor()
query = """INSERT INTO test ('{}', '{}', '{}')""".format(title, name, time)
c.execute(query)
conn.commit()
。
在此先感谢
不要将参数传递给使用字符串连接,'format',''''等的查询。您很容易受到SQL注入的影响。改用参数化查询。 'c.execute(“INSERT INTO test VALUES(?,?,?)”,(title,name,time))' –
done!十分感谢您的建议 – kmomo