My code is below, but it crashes my application. I’m still pretty new with working with db, but it seems to make sense. Any signs of why this could be not working?
public void updateLevel(String level){
mDb.rawQuery("UPDATE "+ DATABASE_TABLE + " SET " + KEY_CUR_LEVEL + " = " + level + " WHERE " + KEY_NAME + " = Default", null);
}
Your
Defaultis interpreted as a column name; if it is a string, you have to use'Default'.To avoid formatting problem like this, it is recommended to use parameters, which are written in the SQL command as
?. They get their value from the corresponding entry in the second parameter ofrawQuery(or similar parameters of other SQL functions).This is easier than putting
'around strings, remembering to escape'inside strings, and makes using strings with control characters possible.