0

我制作了一个包含 3 列的 SQLite 高分;排名(整数),分数(长)和百分比(整数)。我正在尝试从列中提取所有数据,并将它们与用户刚刚获得的分数进行比较,以查看他们的新分数是否进入了前 10 名的高分列表。

我希望先按百分比对高分进行优先排序,然后再得分以打破任何平局。下面是我开始这样做的地方。我在正确的轨道上吗?即使在 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...
}
4

1 回答 1

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

execSQL返回无效。

根据javadoc

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

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

于 2012-12-27T17:19:27.627 回答