这是我想要实现的伪代码;
connect to db
While True:
execute query (SELECT * FROM requests WHERE state = 'NOT_STARTED'
foreach row in rows
#process each row
这是我的代码;
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)
但是,当我更新数据库时,记录数仍显示为1。