I am trying to retrieve the unique _id from my table that i have created in SQLite. But it does not seem to like it and Im not sure what Im doing wrong here, any advice would be appreciated
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
THIS method returns the EXERCISE ID, that corresponds to the exercise
passed and Bodypart passed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public int getExerciseID(String exercise, String bodyPart) {
SQLiteDatabase db = myDBHelper.getWritableDatabase();
String query = "SELECT " + myDBHelper.COLUMN_ID + " FROM " + myDBHelper.TABLE_EXERCISES + " WHERE " +
myDBHelper.COLUMN_BODYPARTNAME + "= \"" + bodyPart + " \"" + " AND " +
myDBHelper.COLUMN_EXERCISENAME + "= \"" + exercise + " \";";
Cursor c = db.rawQuery(query, null);
/*return exerciseID= c.getInt(c.getColumnIndex(myDBHelper.COLUMN_ID));*/
int exerciseID = -1;
c.moveToFirst();
while (!c.isAfterLast()) {
if (c.getString(c.getColumnIndex(myDBHelper.COLUMN_ID)) != null) {
exerciseID= c.getInt(c.getColumnIndex(myDBHelper.COLUMN_ID));
}
c.moveToNext();
}
return exerciseID;
}
Aucun commentaire:
Enregistrer un commentaire