As i have discovered, doing raw query does not work well often, and it is not recommended:
db.execSQL("update userData set " + hero_whose_score_to_update + "="
+ second_player_score + " where name=" + "'" + getUsername2() + "'");
Instead i tried using db.update
ContentValues cv = new ContentValues();
cv.put(hero2_whose_score_to_update, second_player_score);
db.update("userData", cv, "where name = ", null);
I dont' know exactly how to write it, but i want this:
hero_whose_score_to_update is a string - one of "hero1_score", ..."hero6_score";
second_player_score is int, and it will be some number.
But what is next 2 arguments in update()? whereClause and whereArgs. I have read the api for update(), but it is still not clear, an example would do much better.
I suspect i should put in whereClause a username,but how should it look?
db.update("userData", cv, "where name = 'john'", null);
or
cv.put("hero3_score", 34) ;
db.update("userData", cv, "where name= ?", 'jonn') ;
Aucun commentaire:
Enregistrer un commentaire