I am new to android and i am having trouble understanding the delete function in sqlite database.I have created my database using the string
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); ";
Now when i start my app i want that all rows that were added more than 2 days ago should be deleted
so i am planning to do something like this
long currentdate =new date().getTime();
and than check the difference between currenttime-Long.Valueof(TIMESTAMP_DB) field for each rows of the table and if it is more than 2*24*60*60 than delete that row
Can someone please tell me how can i use the below function to achieve the above
public int delete (String table, String whereClause, String[] whereArgs)
i am not sure what should i write in whereClause and whereArgs.
I would be really grateful if someone can tell me a even better and simple approach than this.
PS i also tried doing by execSQL statement but was not able to write the complete query
by database.execSQL("Delete * from "+TABLE_NAME+" WHERE = "+currentdate - Long.ValueOf(?) >2*24*60*60 ;")
Thanks in advance.