コミットとロールバック
□未翻訳
□翻訳中
■翻訳完了(細田謙二)
■レビュー(Omi Chiba)
コミットとロールバック
いかなる作成、削除、挿入、切捨て、削除、更新操作も、コミットコマンドが発行されるまでは、実際にはコミットされません。
No create, drop, insert, truncate, delete, or update operation is actually committed until you issue the commit command
1.
>>> db.commit()
確認のため、新規のレコードを挿入してみましょう:
To check it let's insert a new record:
1.
2.
>>> db.person.insert(name="Bob")
2
そしてロールバックします。つまり、最後にコミットした時点からのすべての操作を無効にします:
and roll back, i.e., ignore all operations since the last commit:
1.
>>> db.rollback()
再び挿入すると、前回の挿入はロールバックされたので、カウンタは再び2に設定されます。
If you now insert again, the counter will again be set to 2, since the previous insert was rolled back.
1.
2.
>>> db.person.insert(name="Bob")
2
モデル、ビュー、コントローラ内のコードは、web2pyのコードにおいて次のように囲まれます:
Code in models, views and controllers is enclosed in web2py code that looks like this:
1.
2.
3.
4.
5.
6.
7.
8.
9.
try:
execute models, controller function and view
except:
rollback all connections
log the traceback
send a ticket to the visitor
else:
commit all connections
save cookies, sessions and return the page
web2pyにおいてコミットやロールバックを明示的に呼び出す必要は、より細かい制御を望まない限りありません。
There is no need to ever call commit or rollback explicitly in web2py unless one needs more granular control.