0

I have the following setup in flask:

@app.route('/restart/<int:id>')
def feed_info(id):

   con = sqlite3.connect(database)
   con.row_factory = sqlite3.Row
   cur = con.cursor()

   main_q = "UPDATE feed SET update_flag = 1 WHERE id = {};".format(id)
   print(main_q)

   cur.execute(main_q)

   return "Set to update!"

However, even though the SQL seems to work on its own, it doesnt actually make the update when I call the method in Flask.

Any ideas?

NickP
  • 1,354
  • 1
  • 21
  • 51

2 Answers2

1

That is because you need to commit. Add con.commit() after the cur.execute()

applecrusher
  • 5,508
  • 5
  • 39
  • 89
1

You have to do con.commit() after cur.execute() else your changes will not be reflected in database.

Note: Also, you have to do cur.close() and con.close() after your logic to close the database connection. Because most of the Databases have the maximum connection limit, and if you will not close the connection explicitly, it will be alive until it reaches it connection-timeout value

Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126