如何在Android删除SQLite数据库旧行? [英] How to delete old rows from sqlite database on android?

查看:115
本文介绍了如何在Android删除SQLite数据库旧行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个参数,其中用户可以选择时间数据的时间应存放于其中。
我在变量读它。日期和时间,当记录被添加到数据库存储在 KEY_DATE_ADDED ,这就像创建:

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_ADDED,+ 10
  天)

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

什么是不正确吗?貌似不是 DATE_ADDED 别的东西应该在这里。
我想用 SQL数据格式化以避免重新格式化日期几次。

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.

有没有GUI为Android数据库上的实际数据测试SQL查询?

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

推荐答案

好吧,我应该使用日期('现在')GT;日期('DATE_ADDED','+ 10天)

这篇关于如何在Android删除SQLite数据库旧行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆