flask sqlite无法从数据库中删除行

时间:2013-11-16 10:17:12

标签: 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):
                    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)

正在正确执行并从其中一个表中删除所需的行。

我不知道我做错了什么

0 个答案:

没有答案