如何获取一个表 - 每列?

时间:2016-11-25 19:01:37

标签: android sqlite

我想从TABLE_Meals中获取所有数据。每一栏。所以,例如,我将吃12顿饭。我会把它们标记为饭菜。每顿饭我想要不同的细节 - 描述,尺寸,价格。我想在ArrayList中检索(desc,size,price)特定餐点。

// DETAILS TABLE - Column names
private static final String desc = "Description";
private static final String size = "Size";
private static final String price = "Price";
private static final String mealsId = "meals_id";

// COMMON COLUMN NAMES
private static final String KEY_ID = "id";


// CREATE STATEMENT FOR TABLES
private static final String CREATE_DETAILS = "CREATE TABLE "
        + TABLE_Details + "(" + KEY_ID + " INTEGER PRIMARY KEY,"
        + desc + " TEXT," + size + " TEXT,"
        + price + " TEXT," + mealsId + " INTEGER)";

// CREATING DETAILS -??????????????????
public void addDetails(String d, String s, String p, int id)
{
    ContentValues values=new ContentValues(3);
    values.put(desc, d);
    values.put(size, s);
    values.put(price, p);
    values.put(categoryId, id);
    getWritableDatabase().insert(TABLE_Meals, null, values);
}

 public Cursor getDetails(int id)
{
    Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM " + TABLE_Details + " WHERE " + mealsId + "=" + String.valueOf(id), null);
    return cursor;
}

// FETCH DETAILS
public ArrayList<Details> GetAllDetails(int id)
{
    ArrayList<Details> list = new ArrayList<Details>();
    Cursor cursor =  getDetails(id);
    int i = 0; // Iterator for 'do-while'. While it gets Categories names, it shall catch all the url's from array as well.
    if (cursor.moveToFirst())
    {
        do
        {
            Details det = new Details();
            det.setId(cursor.getInt(cursor.getColumnIndex(KEY_ID)));
            det.getDescription(cursor.getString(cursor.getColumnIndex(desc)));
            det.getSize(cursor.getString(cursor.getColumnIndex(size)));
            det.getPrice(cursor.getString(cursor.getColumnIndex(price)));

            list.add(det);
            i++;
        }
        while (cursor.moveToNext());
    }
    if (cursor != null && !cursor.isClosed())

    {
        cursor.close();
    }
    return list;
}

发生错误:

 det.getDescription(cursor.getString(cursor.getColumnIndex(desc)));
 det.getSize(cursor.getString(cursor.getColumnIndex(size)));
 det.getPrice(cursor.getString(cursor.getColumnIndex(price)));

另外,我很确定ADD DETAILS功能是错误的。有什么想法吗?

0 个答案:

没有答案