Ejemplo n.º 1
0
 public Map<String, Integer> getAllInventory() {
   Map<String, Integer> res = new LinkedHashMap<String, Integer>();
   SQLiteDatabase db = helper.getReadableDatabase();
   Cursor c =
       db.query("Inventory", new String[] {"productId", "amount"}, null, null, null, null, null);
   try {
     while (c.moveToNext()) {
       String productId = c.getString(0);
       int amount = c.getInt(1);
       res.put(productId, amount);
     }
   } finally {
     c.close();
   }
   return res;
 }
Ejemplo n.º 2
0
 public int getInventoryAmount(String productId) {
   SQLiteDatabase db = helper.getReadableDatabase();
   Cursor c =
       db.query(
           "Inventory",
           new String[] {"amount"},
           "productId=?",
           new String[] {productId},
           null,
           null,
           null);
   try {
     if (c.moveToNext()) {
       return c.getInt(0);
     }
     return 0;
   } finally {
     c.close();
   }
 }