0

我的数据库处理程序:

 public List<oc_product_display> get_all_oc_product() {
        List<oc_product_display> productList = new ArrayList<oc_product_display>();
        // Select All Query
        String selectQuery = "SELECT oc.product_id, oc_desc.name, oc.model, oc.quantity, oc.image, oc.price, " +
                             "oc_cat.category_id " +
                             "FROM oc_product AS oc " +
                             "JOIN oc_product_description AS oc_desc ON oc_desc.product_id = oc.product_id " +
                             "JOIN oc_product_to_category AS oc_cat ON oc_cat.product_id = oc.product_id ";

        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                Bitmap image = convertBlobToImage(cursor.getBlob(5));
                oc_product_display product = new oc_product_display(Integer.parseInt(cursor.getString(0)), cursor.getString(1),
                                                    cursor.getString(2), Integer.parseInt(cursor.getString(3)),
                                                    image, Float.parseFloat(cursor.getString(6)), 
                                                    Integer.parseInt(cursor.getString(7)));
                productList.add(product);
            } while (cursor.moveToNext());
        }

        // return Contact list
        return productList;
    }

之后,我在活动中调用这个:

   DatabaseHandler db = new DatabaseHandler(this);

            List<oc_product_display> ls = db.get_all_oc_product();

            for(oc_product_display oc : ls){
                Log.e("Info:", oc.get_name());
            }

我没有收到任何错误或价值。我在 SQLiteManager 上执行了相同的查询并得到了结果。有什么问题?

4

0 回答 0