我是 android 新手,我无法理解 sqlite 数据库中的删除功能。我使用字符串创建了我的数据库
private static final String TABLE_NAME="NameInfo";
private static final String POSITION_DB ="_id";
private static final String Name_DB ="name";
private static final String JSONOBJECT_DB="json";
private static final String TIMESTAMP_DB="time";
private static final String USERRATING_DB="userrating";
private static final String DATABASE_NAME ="database.db";
private final String createDb ="create table if not exists "+TABLE_NAME +" ("
+ POSITION_DB + " integer primary key, "
+ NAME_DB + " text not null, "
+ JSONOBJECT_DB + " text not null, "
+ USERRATING_DB + " text not null, "
+TIMESTAMP_DB + " text not null); ";
现在,当我启动我的应用程序时,我希望删除超过 2 天前添加的所有行
所以我打算做这样的事情
long currentdate =new date().getTime();
然后检查表中每一行的 currenttime-Long.Valueof(TIMESTAMP_DB) 字段之间的差异,如果大于 2*24*60*60,则删除该行
有人可以告诉我如何使用以下功能来实现上述功能
public int delete (String table, String whereClause, String[] whereArgs)
我不确定我应该在 whereClause 和 whereArgs 中写什么。
如果有人能告诉我比这更好、更简单的方法,我将不胜感激。
PS我也试过用execSQL语句做,但不能写完整的查询database.execSQL("Delete * from "+TABLE_NAME+" WHERE = "+currentdate - Long.ValueOf(?) >2*24*60*60 ;")
提前致谢。