例如这段代码:
db = SQLAlchemy()
def myfunction(a):
#somechanges in database
if a == 2:
return
db.session.commit()
myfunction(2) # there were some changes here that were not committed neither rolled back
myfunction(4) # Here the changes were committed.
我的问题是,第二次调用中的第二次更改是否会提交第一次更改?
提前致谢
答案 0 :(得分:1)
对myFunction(4)
的调用中执行的更改将覆盖对myFunction(2)
的调用中执行的更改。这是更新数据,提交与否的情况。
为了添加行和列,不会覆盖数据。在函数调用myFunction(4)
之前提交将不会产生任何影响。
答案 1 :(得分:-1)
如果您阅读the tutorial,您会发现该会话具有dirty
属性:
db = SQLAlchemy()
def myfunction(a):
#somechanges in database
if a == 2:
return
db.session.commit()
myfunction(2) # there were some changes here that were not committed neither rolled back
print(db.session.dirty)
myfunction(4) # Here the changes were committed.
它告诉你什么?