'ptyhon mysql the query result is always the same (in loop)
The Percentages tab is regularly updated every 60 seconds by another python process. In the cycle every 10 seconds I check the table but I always have only one result.
from pickle import TRUE
import ccxt
import mysql.connector
from datetime import datetime, date
import time
mydb = mysql.connector.connect(
host="127.0.0.1",
user="xxxxx",
password="xxxxxx",
database="xxxx"
)
mycursor = mydb.cursor()
cl = 0
while True:
now = datetime.now()
date_time = now.strftime("%m/%d/%Y %H:%M:%S")
cls = str(cl)
print (date_time + ' start ' + cls + ' cycle\n')
sql= "select * from Percentuali order by Id desc limit 1"
mycursor.execute(sql)
myresult = mycursor.fetchone()
print (myresult)
# end ---------------
Output:
(203, datetime.datetime(2022, 4, 29, 12, 15, 11), -0.0222675, None)
(203, datetime.datetime(2022, 4, 29, 12, 15, 11), -0.0222675, None)
(203, datetime.datetime(2022, 4, 29, 12, 15, 11), -0.0222675, None)
(203, datetime.datetime(2022, 4, 29, 12, 15, 11), -0.0222675, None)
... every time.
I'm testing on a raspberry with mariadb 10 (10.0.28-MariaDB-2 + b1 Raspbian testing-staging) and use heidisql to verify that the update is successful
Solution 1:[1]
Resolved:
sql= "select * from Percentuali order by Id desc limit 1"
mycursor.execute(sql)
myresult = mycursor.fetchone()
mydb.commit()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jakob Liskow |
