我正在尝试创建一个分数数据库,当他们通过调用updatescore()获胜时,将玩家的分数增加1.主键和玩家编号相同(我可能需要在某些时候重新构建数据库),最后一列是“得分”.
下面是最初设置得分的代码(这个工作),获得得分的方法(也正常)和更新得分的方法,将相关的球员得分增加1.这是不起作用的部分,我有什么不同的地方吗?谢谢.
/** Add a record to the database of two player scores * @param playerId * @param playerscore **/ public void addscore (int playerId,int playerscore) { sqliteDatabase database = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(ID,playerId); values.put(PLAYERNUM,playerId); values.put(score,playerscore); database.insert(TABLE_2PscoreS,null,values); database.close(); } // Get the score public int getscore (int playerId) { sqliteDatabase database = this.getReadableDatabase(); Cursor cursor = database.query(TABLE_2PscoreS,COLUMNS," player = ?",new String[] {String.valueOf(playerId) },null); //null = groupby,having,orderby,limit if (cursor !=null) { cursor.moveToFirst(); } int output = cursor.getInt(2); return output; } // Increment score by 1 public void updatescore (int playerId) { sqliteDatabase database = this.getWritableDatabase(); int playerscore = getscore(playerId); int playerscoreInc = playerscore ++; ContentValues values = new ContentValues(); values.put("score",playerscoreInc); database.update(TABLE_2PscoreS,values,PLAYERNUM+" = ?",new String[] {String.valueOf(playerId)} ); database.close(); }