javascript - Python sqlite3 不更新某些表而其他表得到更新
问题描述
我正在使用 Python 后端flask
和sqlite3
. 我的大部分程序都在工作,但我有一个烧瓶函数,在单击按钮时调用并与ajax
请求并行执行。它有 3 行 sqlite 更新 3 个不同的表,但只有最后一个在表中进行更改。这是功能:
@app.route('/add_slot',methods=["POST","GET"])
def add_slot():
conn = sqlite3.connect("example.db")
sem = request.json["sem"]
sec = request.json["sec"]
sub = request.json["sub"]
teacher = request.json["teacher"]
room_no = request.json["room_no"]
time = int(request.json["time"])
day = int(request.json["day"])
cur = conn.execute("select assign_slot from teacher where teacher_name = '" + teacher + "'")
slots = cur.fetchall()[0][0]
slots = slots[:(day-1)*10 + time-1] + "1" + slots[(day-1)*10 + time:]
cur = conn.execute("select availability from room where room_no = " + room_no)
avail = cur.fetchall()[0][0]
avail = avail[:(day-1)*10 + time-1] + "0" + avail[(day-1)*10 + time:]
conn.execute("update room set availability = '" + avail + "' where room_no = " + room_no)
conn.execute("update teacher set assign_slot = '" + slots + "' where teacher_name = '" + teacher + "'")
conn.execute("update tt set subject_name = '" + sub + "', teacher_name = '" + teacher + "', room_no = " + room_no + " where semester = " + sem + " and section = '" + sec + "' and time_ = " + str(time) + " and day = " + str(day))
conn.commit()
conn.close()
return
而调用该函数的JS代码为:
The last sql line is working, which updates the table tt, but others don't. I tried executing the sql statements independently on the powershell, putting the same values for the variables as passed when the function is called, and they work in the powershell. So, why are they not working in the program?
function send_data(){
$.ajax({
type:'POST',
url:'/add_slot' ,
contentType: 'application/json;charset=UTF-8',
data : {'sec':document.getElementById("sec").value,'sem':document.getElementById("sem").value,'sub':document.getElementById("sub").value,'day':document.getElementById("sel1").value,'time':document.getElementById("sel2").value,'teacher':document.getElementById("sel3").value,'room_no':document.getElementById("sel_r").value}
});
close_popup();
initial_processing();
}
解决方案
推荐阅读
- scala - scala 找不到 java.sql.Date 我不知道为什么
- cookies - 在用户的所有浏览器之间共享
- karate - 空手道:迭代Url支持分页是否可行
- javascript - 如何重新编号 Landsat 8 波段以便我可以与 Landsat 4-7 图像合并?
- flutter - 颤振导航栏未选择的文本颜色未显示
- java - 如何在反应式 Spring Security OAuth2 中信任自定义证书?
- javascript - 从 Xrm.Page 删除后表单中托管的 WebResource 从上下文访问
- sql - 优化案例表达式
- docker - 詹金斯 - 码头工人:找不到命令
- html - CSS Cascade: !important 与动画