jeudi 4 février 2016

Why dose update creates new id in database?

I am trying to update the record, whenever I am updating a record new id is generated with the updated values. The update should happen to the same id. What can be the reason?

Create table :

 public void createTable(SQLiteDatabase db){
    String CREATE_EVENTS_TABLE = "CREATE TABLE " + TABLE_EVENTS + "("
            + KEY_ID + " INTEGER PRIMARY KEY,"
            + KEY_TITLE + " TEXT,"
            + KEY_FROM_DATE + " DATE,"
            + KEY_TO_DATE + " DATE,"
            + KEY_DAY_OF_WEEK + " TEXT,"
            + KEY_LOCATION + " TEXT,"
            + KEY_NOTIFICATION_TIME + " DATE" + ")";

    db.execSQL(CREATE_EVENTS_TABLE);
}

update function :

 public int updateEvent(EventData event) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_TITLE,event.getTitle());
    values.put(KEY_FROM_DATE,event.getFromDate());
    values.put(KEY_TO_DATE,event.getToDate());
    values.put(KEY_DAY_OF_WEEK,event.getDayOfWeek());
    values.put(KEY_LOCATION,event.getLocation());
    values.put(KEY_NOTIFICATION_TIME,event.getNotificationTime());


    // updating row
    return db.update(TABLE, values, KEY_ID + " = ?",
            new String[] { String.valueOf(event.getId()) });
}

Calling update function :

    db = new EventTableHelper(getApplicationContext());
        eventData = new EventData();


 db.updateEvent(eventData);

Thank you.

Aucun commentaire:

Enregistrer un commentaire