I got a problem with a function.
I've got a function to find the max(id) of a table and it works but with another table it doesn't work.
First, my database :
`//MAGASIN
public static final String MAGASIN_TABLE_CREATE = "CREATE TABLE "+ MAGASIN_TABLE_NAME + " ("+
MAGASIN_KEY + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
MAGASIN_NOM + " TEXT NOT NULL, " +
MAGASIN_ADRESSE + " TEXT);";`
`
//LISTE`
public static final String LISTE_TABLE_CREATE = "CREATE TABLE "+ LISTE_TABLE_NAME + " (" +
LISTE_KEY + " INTEGER PRIMARY KEY AUTOINCREMENT, "+
LISTE_NAME + " TEXT NOT NULL, "+
LISTE_DATE_CREATION + " TEXT, "+
LISTE_DATE_LAST_MODIFICATION + " TEXT, "+
LISTE_IS_FINAL + " INTEGER, " +
LISTE_NUM_MAGASIN + " INTEGER, " +
"FOREIGN KEY("+ LISTE_NUM_MAGASIN +") REFERENCES MAGASIN("+ MAGASIN_KEY +"));";
After that my first function which works :
public int selectMaxNumMagasin()
{
Cursor cursor = mDb.rawQuery("select numMagasin as _id from magasin order by _id desc limit 1",null);
int max;
if (cursor == null)
{
max = 1;
return max;
}
else
{
cursor.moveToFirst();
max = cursor.getInt(0) + 1;
cursor.close();
return max;
}
}
And finally the last one which doesn't works
`
public int selectMaxNumListe()
{
Cursor cursor = mDb.rawQuery("select numListe as _id from liste order by _id desc limit 1",null);
int max;
if (cursor == null)
{
max = 1;
return max;
}
else
{
cursor.moveToFirst();
max = cursor.getInt(0);
max += 1;
cursor.close();
return max;
}
}`
I've done some tests it seems to be the
cursor.getInt(0);
that got stuck.
Hope someone will find a solution, thanks ;)