我正在尝试对我构建的数据库运行查询,但我遇到了一个奇怪的问题 当我运行查询(按名称)并提取结果。 如果我在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;
}
我做错了什么???