私は、次のダオクラスがあります。更新クエリが機能していませんか?
@Dao
public interface AchievementDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertIntoDatabase(AchievementModel... achievementModel);
@Query("SELECT * FROM achievements WHERE game = :game")
AchievementModel[] getAchievementDataForGame(String game);
@Query("UPDATE achievements SET pointsAchieved = pointsAchieved + :points WHERE achievementKey = :achievementKey")
void updatePointsForKey(double points, String achievementKey);
@Query("SELECT * FROM achievements WHERE achievementKey LIKE :achievementKey")
AchievementModel getAchievementForKey(String achievementKey);
}
と、次のモデルクラス:DAOクラスで
@Entity(tableName = "achievements", indices = {@Index(value = {"achievementKey"}, unique = true)})
public class AchievementModel {
@PrimaryKey @NonNull
private String achievementKey;
private String title;
private String description;
private double pointsAchieved;
private int imageId;
private int viewType;
private String game;
public AchievementModel(@NonNull String achievementKey, String title, String description,
double pointsAchieved, int imageId, int viewType, String game) {
this.achievementKey = achievementKey;
this.title = title;
this.description = description;
this.pointsAchieved = pointsAchieved;
this.imageId = imageId;
this.viewType = viewType;
this.game = game;
}
@NonNull
public String getAchievementKey() {
return achievementKey;
}
public void setAchievementKey(@NonNull String achievementKey) {
this.achievementKey = achievementKey;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public double getPointsAchieved() {
return pointsAchieved;
}
public void setPointsAchieved(double pointsAchieved) {
this.pointsAchieved = pointsAchieved;
}
public int getImageId() {
return imageId;
}
public void setImageId(int imageId) {
this.imageId = imageId;
}
public int getViewType() {
return viewType;
}
public void setViewType(int viewType) {
this.viewType = viewType;
}
public String getGame() {
return game;
}
public void setGame(String game) {
this.game = game;
}
}
最初の2つのクエリ最後の2つのクエリupdatePointsForKeyとgetAchievementForKeyであるのに対し、絶対的に正常に動作しているが働いていない。彼らはバックグラウンドスレッドから正しく呼び出されています。助けてください。質問についてさらに情報が必要な場合は教えてください。
2番目のものは[]です(選択であるため)。最初の1つはたぶん@Query( "UPDATE achievements SET pointsAchieved + =:points WHERE achievementKey =:achievementKey")を試してみてください。 – Ko2r
ちょっと@ Ko2r!今すぐ動作している2番目のクエリを修正していただきありがとうございます。一方、最初のクエリの解決策は機能しませんでした。それは糸くずのエラーを与えている –