I use flask framework and with this code i get the last insert data,but i want to display continuously the last insert. When i reboot the flask framework i get it.Any help?
app.py
@app.route("/sensor" , methods=['POST','GET'])
def sensor():
cursor = db.cursor()
cursor.execute("SELECT Id,temperature,humidity FROM Bseonsor WHERE Id=(SELECT MAX(Id) FROM Bseonsor)")
results = cursor.fetchall()
return render_template('sensor.html',results=results)
sensor.html
<div>
<table border="1" cellpadding="5" cellspacing="5">
{% for row in results %}
<tr> {{ row[1] }} {{ row[2] }} </tr>
{% endfor %}
</table>
</div>
I believe when making selections to the database, you should use the
buffered=Trueargument.Note about selections: Also in the above program, the specified the size is 2 to fetch two records. Also, we set buffered=True in connection. Cursor () method to avoid MySQL Unread result error.
About mysql-connector selections
It should look something like this:
cursor = db.cursor(buffered=True)This can be a bit of a pain when trying to use prepared SQL though.