Python flask sqlite无法从数据库中删除行
使用flask时,我似乎无法从sqlite数据库中删除行Python flask sqlite无法从数据库中删除行,python,sqlite,flask,Python,Sqlite,Flask,使用flask时,我似乎无法从sqlite数据库中删除行 @app.route('/deletePath',methods=['POST']) def deletePath(): if 'toDelPathIndex' in request.form: pathIndex = request.form['toDelPathIndex'] if not isInt(pathIndex):
@app.route('/deletePath',methods=['POST'])
def deletePath():
if 'toDelPathIndex' in request.form:
pathIndex = request.form['toDelPathIndex']
if not isInt(pathIndex):
errorMessage="Given Path Index "+pathIndex+" is not valid"
return render_template('addPath.html',error=errorMessage)
cur = g.db.cursor()
cur.execute('select id,ParentDir from Path')
rows=cur.fetchall()
found=0
for row in rows:
if int(pathIndex) == row[0]:
Dir=row[1]
found = 1
if found == 0:
errorMessage="Given Path Index "+pathIndex+" is not present in database"
return render_template('addPath.html',error=errorMessage)
g.db.execute('delete from Path where id=' + pathIndex)
g.db.commit()
g.db.execute('delete from SnippetDirs where ParentDir=?',(Dir,))
g.db.commit()
return redirect(url_for('addPath_GET'))
else:
errorMessage="Please give me a path index to try and delete"
return render_template('addPath.html',error=errorMessage)
更具体地说,这条线
g.db.execute('delete from SnippetDirs where ParentDir=?',(Dir,))
g.db.execute('delete from Path where id=' + pathIndex)
未按预期工作,因为数据库的大小未减小
而这条线
g.db.execute('delete from SnippetDirs where ParentDir=?',(Dir,))
g.db.execute('delete from Path where id=' + pathIndex)
正在正确执行并从其中一个表中删除所需的行
我不知道我做错了什么提示:如果int(pathIndex)==行[0]:为false,当int(pathIndex)==行[0]:为false时,
Dir的值是多少?
控件不会进入该行,它只打印一条错误消息。