开发者

How to delete old rows from sqlite database on android?

I have a parameter, where user can choose for which period of time data should be stored. I read it in days variable. Date and time, when record was added to the database is stored in KEY_DATE_ADDED, it is created like:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  // sql date format
Date date = new Date();
initialValues.put(KEY_DATE_ADDED, dateFormat.format(date));

Then I do the following:

mDb.delete(DATABASE_TABLE, 
           "date(now) > date(" + KEY_DATE_ADDED + ",+" + days + " days)",
           null);

and it doesn't work. Actual query (where part) looks like:

WHERE date(now) > date(date_added,+10 days)

What is incorrect here? Looks like instead of date_added something else should be here. I wanted to use SQL data formatting to avoid re-formatting dates several times.开发者_如何学Python

Is there any GUI for Android database to test SQL queries on the actual data?


ok, I should use date('now') > date('date_added','+10 days')


Keep in mind that may also need to periodically use the VACUUM command to actually reduce the size of the database.

http://www.sqlite.org/lang_vacuum.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜