python - SQLAlchemy 中的使用 flush() 和 commit() 有什么区别
PHP中文网
PHP中文网 2017-04-17 13:40:32
0
2
858

commit()flush() 实现的功能都一样,为什么两个要写两种,有什么特殊的区别呢?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
伊谢尔伦

Who said these two things have the same function?
In SQLAlchemy, a Session (can be regarded as) is a transaction. Each operation (basically) corresponds to one or more SQL statements. These SQL statements need to be sent to the database server to be actually executed, and the entire transaction needs to be committed to really take effect. , if not submitted, once your program hangs, all uncommitted transactions will be rolled back to the state before the transaction started.
Flush is to send the SQL statements that the client has not sent to the database server, and commit is to tell the database server to commit the transaction.
Simply put, you can see the effect in this Session after flushing, and you can see the effect in other Sessions after committing.

洪涛

The functions are different.
Simply put:
Flush pre-commit is equal to being submitted to the database memory and has not yet been written to the database file;
Commit means writing the contents in the memory directly, and you can provide queries;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template