为什么我不能从Python更新SQLite数据库中的数据?

为什么我不能从Python更新SQLite数据库中的数据?,python,sqlite,Python,Sqlite,我正试图从flaskpython更新或更确切地说修改SQLite数据库的特定单元格中的现有数据。但是我不能更新。同时,我没有收到任何错误,而这样做。同时,我能够在表的新行中插入新数据 服务器端代码: @app.route("/") @app.route("/<state>") def get_post_javascript_data(state=None): connection = sqlite3.connect('/home/pi/toggle7.db')

我正试图从flaskpython更新或更确切地说修改SQLite数据库的特定单元格中的现有数据。但是我不能更新。同时,我没有收到任何错误,而这样做。同时,我能够在表的新行中插入新数据

服务器端代码:

@app.route("/")
@app.route("/<state>")
def get_post_javascript_data(state=None):
        connection = sqlite3.connect('/home/pi/toggle7.db')
        cursor = connection.cursor()
        load = 'light5'
        status = 'ON'
        if state == 'Load1on':
                sock.send('Load1ON')
                print ("sent: Load1ON")
                try:
                     cursor.execute("UPDATE user1 SET load = 'light5' WHERE id='1'")
                     connection.commit()
                     message = "success"
                except:
                     connection.rollback()
                     message = "failure"
                finally:
                     connection.close()
                     print (message)
@app.route(“/”)
@附件路线(“/”)
def get_post_javascript_数据(状态=无):
connection=sqlite3.connect('/home/pi/toggle7.db')
cursor=connection.cursor()
负载='light5'
状态='ON'
如果状态=='Load1on':
sock.send('Load1ON')
打印(“已发送:加载1 on”)
尝试:
execute(“updateuser1 SET load='light5',其中id='1'”)
commit()连接
message=“成功”
除:
连接。回滚()
message=“失败”
最后:
连接。关闭()
打印(信息)
updateuser1 SET load='light5'其中id='1'
此命令更新
id
列中具有值
'1'
的所有行。 如果什么都没有发生,那么这意味着没有这样的争吵

如果
id
列包含数字,则必须搜索数字:

。。。其中id=1
您应该始终使用参数来避免类似这样的格式化问题(以及SQL注入攻击):

cursor.execute('updateuser1 SET load=?WHERE id=?',['light5',1])
updateuser1 SET load='light5'其中id='1'
此命令更新
id
列中具有值
'1'
的所有行。 如果什么都没有发生,那么这意味着没有这样的争吵

如果
id
列包含数字,则必须搜索数字:

。。。其中id=1
您应该始终使用参数来避免类似这样的格式化问题(以及SQL注入攻击):

cursor.execute('updateuser1 SET load=?WHERE id=?',['light5',1])

有人能说说为什么这个问题被否决了吗?这阻碍了我进一步提问。有人能说一下为什么这个问题被否决了吗?这阻碍了我进一步提问。