sqlite in python

sqlite in python

在PySQLite中的文档 http://docs.python.org/library/sqlite3.html?highlight=pysqlite#controlling-transactions

 

By default, the sqlite3 module opens transactions implicitly before a Data Modification Language (DML) statement (i.e. INSERT/UPDATE/DELETE/REPLACE), and commits transactions implicitly before a non-DML, non-query statement (i. e. anything other than SELECT or the aforementioned).
默认情况下, sqlite3模块,在每次数据修改语句(DML)(比如 INSERT/UPDATE/DELETE/REPLACE)中,都隐含打开一个事务, 并在 非数据修改语句(比如 DELETE等) 之前, 隐含地提交这个事务

 

所以, python中, 只需要在在connection 被close前, commit一次就好了, 不要每次execute都commit

 
This method commits the current transaction. If you don’t call this method, anything you did since the last call to commit() is not visible from other database connections. If you wonder why you don’t see the data you’ve written to the database, please check you didn’t forget to call this method.

如果不调用commit(),数据对其他的进程的数据库连接是不可见的

如果执行insert语句后, 又执行了select, 那么就不必commit了,因为会自动commit一次

 

reference:http://zhiwei.li/text/2010/08/sqlite%E6%8F%92%E5%85%A5%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/

posted on 2010-08-23 07:32  lexus 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2010/08/23/1806106.html

你可能感兴趣的:(sqlite in python)