我想實現一個使用原始查詢的函數,但遇到了一些麻煩。我正在嘗試做一個簡單的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