Reputation: 28050
I am using Python MySQLdb module. I am querying a table every 1 seconds. New rows are being added to this table all the time. The code is as follows;
def main():
connectMySqlDb_tagem()
while True:
queryTable()
time.sleep(1)
closeDBconnection()
The problem with the code is that the query does not return the latest rows. It always return the same rows. To solve this problem, I have to close the MySQL connection and make a new MySQL connection everytime. The workable code looks like this;
def main():
while True:
connectMySqlDb_tagem()
queryTable()
closeDBconnection()
time.sleep(1)
How can I avoid making a new connection everytime in order to get the latest rows?
Upvotes: 1
Views: 65
Reputation: 473883
Pass SQL_NO_CACHE in your SELECT
query, or turn it off on a session level:
cursor.execute("SET SESSION query_cache_type = OFF")
See also:
Hope that helps.
Upvotes: 1
Reputation: 1511
try:
connection.commit()
instead of disconnecting and reconnecting and see if it solves your problem.
Upvotes: 0