title: Python MySQLdb loop
body: <p>Here is the pseudo code I am trying to achieve;</p>
  
  <pre><code>connect to db
  
  While True:
  execute query (SELECT * FROM requests WHERE state = 'NOT_STARTED'
  foreach row in rows
    #process each row
  </code></pre>
  
  <p>Here is the code I have;</p>
  
  <pre><code>import sys
  import MySQLdb
  import time
  
  try:
      db = MySQLdb.connect(user='XXXX',
                           passwd='',
                           db='XXX',
                           host='XXX')
  
  except MySQLdb.Error, e:
      raise e
  
  while True:
      cursor = db.cursor()
      #db.begin()
      cursor.execute("SELECT * FROM requests WHERE state = 'NOT_STARTED'")
      res = cursor.fetchone()[0]
      #db.commit()
      #db.close()
  
      print "No records: %d" % res
      time.sleep(3)
  </code></pre>
  
  <p>However, when I update the database, the number of records still shows as 1.</p>