mercredi 16 décembre 2015

update not working in SQLite Database in Android Application

I am working on a android project. In which I have used SMS Scheduling. For that I have created SQLite Database. In database created SMSTABLE. In SMSTABLE, there is a column name "status". Which defines whether it is draft message, scheduled,sent or unsent message. For draft status = 0, for scheduled status = 1, for sent status = 2,for unsent status = 3. By default status value is set to 1. When I update status for draft it doesn't work(update into db).

Following are some parts of my code of DBHepler Class:

private final String DATABASE_CREATE_SMS_TABLE = "create table " + DATABASE_SMS_TABLE
        + " ("
        + KEY_ID + " integer primary key autoincrement, "
        + KEY_MESSAGE + " text, "
        + KEY_DATE + " text, "
        + KEY_START_TIME_MILLIS + " long, "
        + KEY_END_TIME_MILLIS + " long, "
        + KEY_MSG_PARTS + " integer default 0, "
        + KEY_STATUS + " integer default 1, "
        + KEY_REPEAT_MODE + " integer, "
        + KEY_REPEAT_STRING + " text);";


 /***
 * @param message
 * @param date
 * @param parts        //* @param timeInMilis
 * @param repeatMode
// * @param repeatString
 * @return smsId for the newly scheduled SMS
 * @detail Schedules a new SMS using the details passed as parameters
 */
public long scheduleSms(String message, String date, int parts, long startTimeInMilis, long endTimeInMilis, int repeatMode) {
    ContentValues addValues = new ContentValues();

    addValues.put(KEY_MESSAGE, message);
    addValues.put(KEY_DATE, date);
    // addValues.put(KEY_TIME_MILLIS, timeInMilis);
    addValues.put(KEY_START_TIME_MILLIS, startTimeInMilis);
    addValues.put(KEY_END_TIME_MILLIS, endTimeInMilis);
    addValues.put(KEY_MSG_PARTS, parts);
    addValues.put(KEY_REPEAT_MODE, repeatMode);
 //   addValues.put(KEY_REPEAT_STRING, repeatString);

    return db.insert(DATABASE_SMS_TABLE, null, addValues);
}

/***
 * @param smsId
 * @detail Sets an SMS as Draft
 */
public void setAsDraft(long smsId) {
    setStatus(smsId, Constants.SMS_STATUS_DRAFT);
}


/***
 * @param smsId
 * @param status
 * @detail Sets a particular status for an SMS. Status is passed as parameter
 */
public void setStatus(long smsId, int status) {
    ContentValues cv = new ContentValues();
    cv.put(KEY_STATUS, status);

    db.update(DATABASE_SMS_TABLE, cv, KEY_ID + "=" + smsId, null);
}

Aucun commentaire:

Enregistrer un commentaire