database - Python distributed transactions like Java Transaction API (JTA) -
is there solution distributed transactions in python or mysqldb java transaction api (jta)?
i got problem when processing data on multiple databases (maybe different kinds of databases).
how can ensure data consistency?
i know there's java transaction api (jta) in java.
how can python?
you use sql statements xa transaction. not pretty real api, works. don't know if there tm's (transaction managers) available python, write own.
also note in java not required use application server when using xa. example: http://bugs.mysql.com/file.php?id=22190&bug_id=75316
in [1]: import mysql.connector in [2]: c = mysql.connector.connect(host='127.0.0.1',port=5705,user='msandbox',password='msandbox'); in [3]: cur = c.cursor(); in [4]: cur.execute("xa start 'py-xa-001'"); in [5]: cur.execute("insert test.t1 values(1)"); in [6]: cur.execute("xa recover"); in [7]: print(cur.fetchone()); none in [8]: cur.execute("xa end 'py-xa-001'"); in [9]: cur.execute("xa prepare 'py-xa-001'"); in [10]: cur.execute("xa recover"); in [11]: print(cur.fetchone()); (1, 9, 0, u'py-xa-001') in [12]: cur.execute("xa rollback 'py-xa-001'"); in [13]: cur.close() out[13]: true in [14]: c.disconnect()
Comments
Post a Comment