我想实现一个使用原始查询的函数,但遇到了一些麻烦。我正在尝试做一个简单的select * from recipes where _id = 1
。我知道这行存在,因为当我运行查询select * from recipes
时,我得到了预期的结果列表。但是当我使用where
条款时,我没有得到任何结果。如果我在数据库的另一个表上做了where
子句,我会得到预期的结果。Android原始查询
任何人都可以告诉我我哪里出了问题吗?
表创建
//Recipe create statement
private static final String CREATE_TABLE_RECIPES = "CREATE TABLE "
+ RECIPE_TABLE + "("
+ KEY_ID + " INTEGER AUTO INCREMENT,"
+ KEY_CODE + " INTEGER AUTO INCREMENT PRIMARY KEY,"
+ KEY_RECIPE_NAME + " TEXT" + ")";
查询
return db.rawQuery("select * from recipes where _id = 1",null);
把结果到列表
Cursor cursor = adapter.possibleRecipes();
//String[] columns = new String[] {db.KEY_NAME, db.KEY_CODE, db.KEY_ROWID};
String[] columns = new String[] {adapter.KEY_RECIPE_NAME, adapter.KEY_ID};
int[] to = new int[] {R.id.recipe_name, R.id.recipe_code};
SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter(this,R.layout.row1, cursor, columns, to, 0);
ListView recipeList = (ListView) findViewById(R.id.possibleRecipeList);
recipeList.setAdapter(myCursorAdapter);
我已更新上面的查询,但没有\ n和\ t – Hayes121