Operation Python MySQL database Ⅳ

The enforcement branch

Transaction mechanism to ensure data consistency.

Transaction should have four properties: atomicity, consistency, isolation, durability. These four properties are usually called ACID properties.

  • Atomicity (atomicity). A transaction is an indivisible unit of work, all operations in the transaction include either do or do not do.
  • Consistency (consistency). The database transaction must be changed from one consistent state to another consistent state. Consistency and atomicity are closely related.
  • Isolation (isolation). Execution of a transaction can not be other transactions interference. I.e., operation and use of the data inside a transaction other concurrent transactions are isolated and can not interfere with each other between the respective transaction executed concurrently.
  • Persistence (durability). Persistent, also known as permanent (permanence), means that once a transaction commits, changing the data in the database http://www.weixiu3721.com/ it should be permanent. The next operation or other faults should not have any effect on them.

Python DB API 2.0 provides two methods of transaction commit or rollback.

Example:

 

 

For transactional database, database programming in Python, when the establishment of the cursor will automatically start up a database transaction invisible.

commit () method all the updates cursor, rollback () method of the current cursor rolls back all operations. Every method to start a new business.


Error Handling

API defines a number of errors and abnormal operation of the database DB, the following table lists the errors and exceptions:

 

 

Guess you like

Origin www.cnblogs.com/danjiu/p/11927251.html