android - How to execute a query that gets only one value from the column? -


i trying retrieve unique _id table have created in sqlite. not seem , im not sure im doing wrong here, advice appreciated

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method returns exercise id, corresponds exercise passed , bodypart passed ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ public int getexerciseid(string exercise, string bodypart) {      sqlitedatabase db = mydbhelper.getwritabledatabase();       string query = "select " + mydbhelper.column_id + " " + mydbhelper.table_exercises + " " +             mydbhelper.column_bodypartname + "=  \"" + bodypart + "  \"" + " , " +             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; } 

why giving \"" in query string. escape character not required.

i not clear query. can try query this.

string query="select distinct exercise_id **yourtablename** **your_condition** limit 1 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -