您不妨检查贵国数据库的交易孤立程度。 你们描述的行为是,如果将行为定在REPEATABLE-READ,你会期望什么。 你不妨将其改为反恐执行局。
Since the original poster of the problem mentions that he is merely querying the database, it cannot be a commit that was forgotten. Inserting a commit seems to be a workaround though since it causes a new transaction to begin; and a new snapshot may need to be established. Still, having to insert a commit before every select doesn t sound like good programming practices to me.
There is no python code to show since the solution lies in correctly configuring the database.
<><>>> http://dev.mysql.com/doc/refman/5.5/en/set-transaction.html。
REPEATABLE READ
This is the default isolation level for InnoDB. For consistent reads, there is an important difference from the READ COMMITTED isolation level: All consistent reads within the same transaction read the snapshot established by the first read. This convention means that if you issue several plain (nonlocking) SELECT statements within the same transaction, these SELECT statements are consistent also with respect to each other. See Section 14.3.9.2, “Consistent Nonlocking Reads”.
READ COMMITTED
A somewhat Oracle-like isolation level with respect to consistent (nonlocking) reads: Each consistent read, even within the same transaction, sets and reads its own fresh snapshot. See Section 14.3.9.2, “Consistent Nonlocking Reads”.
Checking the configured isolation level:
>mysql > SELECT @@GLOBAL.tx_isolation, @@tx_isolation;
+-----------------------+-----------------+
| @@GLOBAL.tx_isolation | @@tx_isolation |
+-----------------------+-----------------+
| REPEATABLE-READ | REPEATABLE-READ |
+-----------------------+-----------------+
1 row in set (0.01 sec)
Setting the transaction isolation level to READ-COMMITTED
mysql> SET GLOBAL tx_isolation= READ-COMMITTED ;
Query OK, 0 rows affected (0.00 sec)
mysql> SET SESSION tx_isolation= READ-COMMITTED ;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @@GLOBAL.tx_isolation, @@tx_isolation;
+-----------------------+----------------+
| @@GLOBAL.tx_isolation | @@tx_isolation |
+-----------------------+----------------+
| READ-COMMITTED | READ-COMMITTED |
+-----------------------+----------------+
1 row in set (0.01 sec)
mysql>
并再次提出申请......