dimanche 15 mars 2015

SQLite AUTO_INCREMENT

My table is created like this:



db.execSQL("CREATE TABLE reminder (" +
"id INTEGER PRIMARY_KEY AUTO_INCREMENT," +
"title VARCHAR(100)," +
"content VARCHAR(500)," +
"due LONG," +
"alarm LONG," +
"priority INT" +
");");


and values inserted by:



ContentValues cv=new ContentValues();
cv.put("title",t.title);
cv.put("content",t.content);
cv.put("due",t.date.getTimeInMillis());
cv.put("alarm",(t.alarm==null?0L:t.alarm.getTimeInMillis()));
cv.put("priority",t.severity);
SQLiteDatabase d=getWritableDatabase();
d.insert("reminder",null, cv);
d.close();


But when I try to get my values by:



Task task=new Task();
task.id=c.getInt(0);
task.title=c.getString(1);
task.content=c.getString(2);
Calendar due=new GregorianCalendar();
due.setTimeInMillis(c.getLong(3));
task.date=due;
if(c.getLong(4)!=0){
Calendar alert=new GregorianCalendar();
alert.setTimeInMillis(c.getLong(4));
task.alarm=alert;
}
task.severity=c.getInt(5);
return task;


I get always id equal to zero. Any idea how to fix it?


Aucun commentaire:

Enregistrer un commentaire