vendredi 6 février 2015

How to update all rows of a column in SQLite database in Android?

I am a new to SQLite database.This is not a duplicate of any other question. I am inserting rows dynamically into a table which has columns like title, tag, date, location etc. I am showing the remaining days from today to the user in a listview. Now my problem is that, I need to update the remaining days column in sqlite table for each day, so that it gets decremented based on the day. How to update all the rows of that remaining days column at once? And how to decrease/update it based on time? This is what I have tried.



public static final String KEY_REMAINING_DAYS = "remainingdays";
public static final int COL_REMAINING_DAYS = 10;
private static final String DATABASE_CREATE_MY_SQL =
"create table " + MY_TABLE
+ " (" + KEY_ROW_ID + " integer primary key autoincrement, "
+ KEY_TAG + " text not null, "
+ KEY_TITLE + " text not null, "
+ KEY_DATE + " text not null, "
+ KEY_LOCATION + " text not null, "
+ KEY_REMAINING_DAYS + " text not null, "
+ ");";





public void update_days() {
String where = "UPDATE "+ MY_TABLE +" SET " + COL_REMAINING_DAYS + " = " + COL_REMAINING_DAYS-1);
db.rawQuery(where, null);
}

Aucun commentaire:

Enregistrer un commentaire