2017-11-07 10 views
0

私は、次のダオクラスがあります。更新クエリが機能していませんか?

@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であるのに対し、絶対的に正常に動作しているが働いていない。彼らはバックグラウンドスレッドから正しく呼び出されています。助けてください。質問についてさらに情報が必要な場合は教えてください。

+0

2番目のものは[]です(選択であるため)。最初の1つはたぶん@Query( "UPDATE achievements SET pointsAchieved + =:points WHERE achievementKey =:achievementKey")を試してみてください。 – Ko2r

+0

ちょっと@ Ko2r!今すぐ動作している2番目のクエリを修正していただきありがとうございます。一方、最初のクエリの解決策は機能しませんでした。それは糸くずのエラーを与えている –

答えて

0

更新クエリでvoidの代わりにintが返される可能性があります。どう思いますか?

+0

まだ動作しません。私はそれが更新された行番号を返すと思うが、それはちょうど0を返していると思います。データベースは更新されていません。 –

+0

追加せずに更新しようとすると、何か変わりますか? +が問題かどうか、IDであるかどうかを確認するだけです... – Ko2r

+0

これは、私が追加せずに更新しようとしたときと同じ結果をもたらします。つまり、dbは更新されません。一方私が次のコードを実行すると、UPDATEアチーブメントSET pointsAchieved = pointsAchieved + 1.0 WHERE achievementKey = \ "some_string \" "'それは絶対にうまくいっています。理由を知らない。私の議論は正しく合格しています。 –

関連する問題