【发布时间】:2019-02-28 18:54:47
【问题描述】:
这个想法是在值更改后显示一个消息框。 query 变量的 COUNT(*) 当前为 0。当程序在无限循环中运行以检查是否有任何更改时,会创建一个新请求,并且计数现在应该为 1。
但是,这不会发生。控制台不断打印No new Tickets。
为什么在后台发生变化时query (row)变量没有更新?
如果我终止程序并重新运行它,它将获得新值。
while True:
#if this count increases by 1 send a notification in python that there is a new ticket
query = """
SELECT COUNT(*)#q.id, q.Name, q.Description, t.Created, t.Subject
FROM
Queues as q
LEFT JOIN Tickets as t
on q.id = t.Queue
LEFT JOIN Users as u
on u.id = t.Owner
WHERE
q.id = 1 AND u.id = 10 AND t.Status = 'New'
AND
STR_TO_DATE(t.Created, "%Y-%m-%d") = CURDATE();
"""
cursor = conn.cursor()
cursor.execute(query)
row = cursor.fetchone()
#Debug for printing the current count
print row[0]
#if the current count of unowned and status ="new" tickets is greater than 0 send a notification.
if(row[0] > 0):
ctypes.windll.user32.MessageBoxW(0, u"New Ticket Available", u"NEW TICKET", 1)
else:
print "No new Tickets"
time.sleep(5)
【问题讨论】:
标签: python mysql python-2.7