我有一个数据库,每分钟都会插入一个新值,我想每分钟连续获取最新的插入值
cursor = connection.cursor ()
cursor.execute ("select time from gbp_inr_min order by id desc limit 1")
while True:
row = cursor.fetchone
print (row)
time.sleep(60)
connection.close ()
sys.exit()
每当我运行此代码时,它都会在刚开始显示NONE
之后就给出正确的输出
答案 0 :(得分:0)
您需要运行查询
cursor.execute ("select time from gbp_inr_min order by id desc limit 1")
每次循环,因为在此行之后不再执行查询,因此,游标只能获取在执行时返回的行(因为您的查询已经LIMIT 1
,因此仅返回一行就可以了。)