dimanche 28 février 2016

Row in SQLite database not getting deleted after a specified amount of time

I have a table with one row. I would like to delete this row after one hour. Within this row, I store the timestamp with the specified format as 'COULMN_DATE'. I got the query that should work from here:

Delete a row in a table after an hour it is inserter using sql query

And I call it like this in my onCreate() function within my databaseHandler class, and I made sure I also updated my database version beforehand. I replaced hour to minutes for checking purposes:

 db.execSQL("DELETE FROM " + TABLE_PRODUCTS +" 
              WHERE "+ COLUMN_DATE +" < DATETIME('NOW', '-1 minutes')");

But after inserting a timestamp, waiting a couple of minutes, and then restarting the application to check whether the data was deleted, it was still there. Is it because I am calling it in the wrong place? If so, where should this query be done?

Aucun commentaire:

Enregistrer un commentaire