1

我正在尝试在我构建的数据库上运行查询,但是当我运行查询(按名称)并提取结果时遇到了一个奇怪的问题。如果我提取 db 中的第一行,则可以使用其他参数运行另一个查询。如果我提取除第一行以外的行,我将无法再访问数据库中的第一行

    Cursor cur =datasource.query( 2,new String[] {"_id","Player","Num_of_wrong_ans","Num_of_drunkness_checks"} , PlayerDatabaseHelper.PLAYER + " =? " ,new String[] {array[1]} , null ); 
            if(cur.moveToFirst())
            {                   
                id = cur.getString(cur.getColumnIndex(PlayerDatabaseHelper.ID));

            }
            cur.close();    

查询方法是这样的:

    public Cursor query( int indicator,String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    String a;
    switch (indicator) 
    { 
    case 1: 
        qb.setTables(PlayerDatabaseHelper.PLAYER_TABLE_NAME); 
        qb.setProjectionMap(projectionMap); 
        break; 
    case 2: 
        qb.setTables(PlayerDatabaseHelper.PLAYER_TABLE_NAME); 
        qb.setProjectionMap(projectionMap); 
        qb.appendWhere(PlayerDatabaseHelper.PLAYER);
        break; 
    default: 
        throw new IllegalArgumentException("Unknown  "); 
    } 

    // Get the database and run the query 
    SQLiteDatabase db = mHelper.getReadableDatabase(); 
    Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, null); 
    return c; 

}    

我究竟做错了什么 ???

4

0 回答 0