public boolean deleteOrderGoodsByGoodsId(String user_id, OrderGoods orderGoods) { int row = 0; if (service.tableIsExist(user_id, TABLE_ORDER)) { SQLiteDatabase mDb = service.openWritableDatabase(user_id); String sqlString = COLUMN_GOODS_ID + "=" + orderGoods.getGoodsId() + " and " + COLUMN_SHOP_ID + "=\'" + orderGoods.getShopId() + "\'"; row = mDb.delete(TABLE_ORDER, sqlString, null); System.out.println("delete row:" + row); mDb.close(); } service.close(); return row != 0; }
private ArrayList<OrderGoods> readOrderGoodsFromCursor(Cursor cursor) { ArrayList<OrderGoods> orderGoodsArrayList = new ArrayList<OrderGoods>(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { OrderGoods orderGoods = new OrderGoods(); orderGoods.setShopId(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_SHOP_ID))); orderGoods.setGoodsId(cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_GOODS_ID))); orderGoods.setName(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_GOODS_NAME))); orderGoods.setPrice(cursor.getDouble(cursor.getColumnIndexOrThrow(COLUMN_GOODS_PRICE))); orderGoods.setSalePrice( cursor.getDouble(cursor.getColumnIndexOrThrow(COLUMN_GOODS_SALE_PRICE))); orderGoods.setGoodsNumber(cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_GOODS_NUMBER))); orderGoods.setType(cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_GOODS_TYPE))); orderGoodsArrayList.add(orderGoods); } return orderGoodsArrayList; }
public boolean insert(String u_id, OrderGoods orderGoods) { SQLiteDatabase mDb = service.openWritableDatabase(u_id); ContentValues initialValues = new ContentValues(); initialValues.put(COLUMN_SHOP_ID, orderGoods.getShopId()); initialValues.put(COLUMN_GOODS_ID, orderGoods.getGoodsId()); initialValues.put(COLUMN_GOODS_TYPE, orderGoods.getType()); initialValues.put(COLUMN_GOODS_NAME, orderGoods.getName()); initialValues.put(COLUMN_GOODS_PRICE, orderGoods.getPrice()); initialValues.put(COLUMN_GOODS_SALE_PRICE, orderGoods.getSalePrice()); initialValues.put(COLUMN_GOODS_NUMBER, orderGoods.getGoodsNumber()); boolean bool = mDb.insert(TABLE_ORDER, null, initialValues) != -1; System.out.println("insert state:" + bool); mDb.close(); service.close(); return bool; }