Menu

connections and update

Help
daftness
2006-10-09
2012-09-19
  • daftness

    daftness - 2006-10-09

    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?

     
    • Andy Dustman

      Andy Dustman - 2006-10-09

      Try doing a conn.rollback() before sleeping. Presumably you are using InnoDB tables.

      http://en.wikipedia.org/wiki/ACID

       
      • mwade

        mwade - 2007-07-27

        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

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.