Ejemplo n.º 1
0
  /** getting all products */
  public List<Product> getAllProducts() {
    List<Product> products = new ArrayList<Product>();
    String selectQuery = "SELECT  * FROM " + TABLE_PRODUCTS;

    Log.e(LOG, selectQuery);

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (c.moveToFirst()) {
      do {
        Product pd = new Product();
        pd.setId(c.getInt((c.getColumnIndex(KEY_ID))));
        pd.setName((c.getString(c.getColumnIndex(KEY_NAME))));
        pd.setCode((c.getString(c.getColumnIndex(KEY_CODE))));
        pd.setImage((c.getString(c.getColumnIndex(KEY_IMAGEN))));
        pd.setCompany_id((c.getInt(c.getColumnIndex(KEY_COMPANY_ID))));
        pd.setCategory_id((c.getInt(c.getColumnIndex(KEY_CATEGORY_ID))));
        pd.setCategory_name((c.getString(c.getColumnIndex(KEY_CATEGORY_NAME))));
        // adding to todo list
        products.add(pd);
      } while (c.moveToNext());
    }
    return products;
  }
Ejemplo n.º 2
0
 /**
  * @param name
  * @return
  */
 public Product getProductName(String name) {
   SQLiteDatabase db = this.getReadableDatabase();
   String selectQuery = "SELECT  * FROM " + TABLE_PRODUCTS + " WHERE " + KEY_NAME + " = " + name;
   Log.e(LOG, selectQuery);
   Cursor c = db.rawQuery(selectQuery, null);
   if (c != null) c.moveToFirst();
   Product pd = new Product();
   pd.setId(c.getInt(c.getColumnIndex(KEY_ID)));
   pd.setName((c.getString(c.getColumnIndex(KEY_NAME))));
   pd.setCode((c.getString(c.getColumnIndex(KEY_CODE))));
   pd.setImage((c.getString(c.getColumnIndex(KEY_IMAGEN))));
   pd.setCompany_id((c.getInt(c.getColumnIndex(KEY_COMPANY_ID))));
   pd.setCategory_id((c.getInt(c.getColumnIndex(KEY_CATEGORY_ID))));
   pd.setCategory_name((c.getString(c.getColumnIndex(KEY_CATEGORY_NAME))));
   return pd;
 }