我正在尝试更新或修改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)
此命令更新
id
列中值为'1'
的所有行。 如果什么都没有发生,那么这就意味着没有这样的争吵。在如果
^{pr2}$id
列包含数字,则必须搜索一个数字:而且您应该始终使用参数来避免格式问题(以及SQL注入攻击):
相关问题 更多 >
编程相关推荐