2012-12-27 50 views
0

我做了一个SQLite高分,有3列; rank(int),score(long)和percentage(int)。我试图从列中提取所有数据,并将它们与用户刚刚看到的分数进行比较,看看他们的新分数是否成为排名前十的高分榜。比较来自SQLite数据库的数据 - Android(java)

我想按百分比优先考虑高分首先,然后打分打破任何关系。下面是我开始这样做的地方。我在正确的轨道上吗?我甚至没有在Java之外使用过SQLite,所以这对我来说都是全新的。

非常感谢您的帮助。

//Check if new record makes the top 10. 
public boolean check(int rank, long score, int percentage) { 
    //SQL query to get last score/percentage if highscores has 10 records... 
    long[] scores = new long[9]; 
    int[] percentages = new int[9]; 
    scores = db.execSQL("SELECT " + SCORE + " FROM " + TABLE + ";"); //Error: Type mismatch 
    percentages = db.execSQL("SELECT " + PERCENTAGE + " FROM " + TABLE + ";"); //Error: Type mismatch 
    //Algorithms to compare scores and percentages go here... 
} 

回答

3
scores = db.execSQL("SELECT " + SCORE + " FROM " + TABLE + ";"); 

execSQL返回void。

javadoc

执行一个SQL语句不是SELECT或返回数据的任何其他SQL语句。

您可能需要使用query(或)rawQuery机制来进行选择。