0

May be this is a newbie question but want to confirm as this is important for my app:

I'm using MySQLdb on Python and my code looks like:

db = MySQLdb.connect("localhost","root","",test)
cursor = db.cursor()


cursor.execute("UPDATE users SET address = 'Something' WHERE name = 'Someone'")
db.query("SELECT * FROM users WHERE address = 'Something'")
sample=db.store_result().fetch_row(maxrows=0)

So the question is, will sample contain the row that was changed by the uncommitted update?

In the real app, I am making some complex queries with subclauses like GROUP_CONCAT, etc. Will all these work with uncommitted updates? (In the sense that can these work on the rows updated by uncommitted updates)

  • Where is the BEGIN and COMMIT? – Rick James Apr 6 '16 at 5:13
0

tl;dr Yes, sample will contain the rows that were just updated.

Please note that you're not in a transaction context. So every query is an implicit transaction in this specific case.

Assuming you did have a begin somewhere sample would still see the rows because it's the same connection and the same transaction.

If you started the transaction and opened a separate connection or you had a concurrent process/request it would only see the rows without commit if your mysql is running with READ-UNCOMMITTED transaction level.

You can check the global settings by:

mysql> show global variables like 'tx_isolation';

It can also be set for individual connection:

mysql> set tx_isolation='READ-UNCOMMITTED';

I hope this answers your question.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.