1

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>
lupz
  • 3,620
  • 2
  • 27
  • 43
  • Hi and welcome to StackOverflow. You can edit your questions to update them with requested information. I took the code from your comment to the question for you. Please make sure to take the [tour] and read [ask] to get started with this community. Happy coding :) – lupz Jan 25 '21 at 09:09

1 Answers1

0

I believe when making selections to the database, you should use the buffered=True argument.

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.

conaticus
  • 301
  • 1
  • 4
  • 14