I have a simple script that reads and prints one record. My problem is that the script dont see updates to that record done from anywhere else.
conn = MySQLdb.connect ( ... )
while 1:
cursor = conn.cursor()
cursor.execute("SELECT * FROM user WHERE id=1")
while 1:
row = cursor.fetchone()
if row == None:
break
print row
time.sleep(2)
This script prints the same thing even after I do a "UPDATE user set forename='something' WHERE id=1;" from the mysql shell. Is this the right behaviour? Or is there something I can do to make the select get the changes?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I had the same problem, and conn.rollback() definitely fixed the issue; however, could you please provide a better explanation about why this was the fix?
It seems almost counter-intuitive to rollback any transaction when you are dealing with two applications feeding each other information through the database.
-- Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I have a simple script that reads and prints one record. My problem is that the script dont see updates to that record done from anywhere else.
conn = MySQLdb.connect ( ... )
while 1:
cursor = conn.cursor()
cursor.execute("SELECT * FROM user WHERE id=1")
while 1:
row = cursor.fetchone()
if row == None:
break
print row
time.sleep(2)
This script prints the same thing even after I do a "UPDATE user set forename='something' WHERE id=1;" from the mysql shell. Is this the right behaviour? Or is there something I can do to make the select get the changes?
Try doing a conn.rollback() before sleeping. Presumably you are using InnoDB tables.
http://en.wikipedia.org/wiki/ACID
I had the same problem, and conn.rollback() definitely fixed the issue; however, could you please provide a better explanation about why this was the fix?
It seems almost counter-intuitive to rollback any transaction when you are dealing with two applications feeding each other information through the database.
-- Mike