简体   繁体   中英

Reset SQLite database by certain time

Is there a way to reset (delete/create) a SQLite database/table on a certain time? for example consider a table that track how much money you have spent on that day, then at midnight it reset to 0. TIA

In theory, you could schedule an alarm .

However, as long as your app isn't run, nobody will look at the table and be able to detect whether it's empty or not. Therefore, the easiest way to handle this is to check the database when the app/activity is started, and if the last access is from a date older than today, delete everything.

As a rule you probably do not want to store calculated data in a database. Store date/time and amount for each transaction and then calculate the total spent for whatever date/time range you would like.

Something like:

SELECT SUM(transactionamt)
FROM table
WHERE datetime >= 'startime'
AND datetime <= 'endtime';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM