我有一个图书馆管理应用程序。我没有使用ORM(这是用于数据库项目,不允许使用ORM)要签出我正在进行表单验证的书。像这样:
class CheckoutForm(Form):
book_id = TextField('book_id', validators = [Required()])
branch_id = TextField('branch_id', validators = [Required()])
card_no = TextField('card_no',validators = [Required()])
def __init__(self, *args, **kwargs):
Form.__init__(self, *args, **kwargs)
def validate(self):
rv = Form.validate(self)
if not rv:
return False
# Get total copies of the book check if not 0
cur.execute("""select SUM(No_of_copies) from book b, book_copies c where b.Book_id = c.Book_id and
b.Book_id = %s and c.Branch_id = %s""",\
(self.book_id.data.strip(), self.branch_id.data.strip()))
copies = cur.fetchone()[0]
if copies == 0:
self.branch_id.errors.append("Book not at this Branch.")
return False
# Get total available copies of the book in given branch check if not 0
cur.execute("""select count(*) from book_loans l, book b, book_copies c where b.Book_id = l.Book_id and b.Book_id = c.Book_id and Date_in is NULL and b.Book_id = %s and c.Branch_id = %s""",(self.book_id.data.strip(),self.branch_id.data.strip()) )
checked_out = cur.fetchone()[0]
print checked_out
avail_copies = copies - checked_out
print avail_copies
if avail_copies <= 0:
self.branch_id.errors.append("No copies available right now.")
return False
现在,如果我手动删除book_loans表中的行,如果我不重新启动应用程序,我会继续看到avail_copies和副本的旧值(在db更改之前)。为什么会这样?