簡體   English   中英

更新查詢不起作用?

[英]update query not working?

我有以下 Dao 類:

@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);
}

以及以下模型類:

@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;
}
}

DAO 類中的前 2 個查詢工作正常,而后 2 個查詢 updatePointsForKey 和 getAchievementForKey 不起作用。 它們是從后台線程正確調用的。 請幫忙。 請告訴我是否需要有關該問題的更多信息。

更新查詢可能返回一個 int 而不是 void ......你怎么看?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM