コード例 #1
0
 public Order create(Order order) {
   ContentValues values = new ContentValues();
   values.put(OrdersDBOpenHelper.COLUMN_PHONE, order.getPhoneNumber());
   values.put(OrdersDBOpenHelper.COLUMN_ADDRESS, order.getAddress());
   values.put(OrdersDBOpenHelper.COLUMN_CREDITCARD, order.getCreditCardNumber());
   values.put(OrdersDBOpenHelper.COLUMN_ORDER, order.getOrderString());
   values.put(OrdersDBOpenHelper.COLUMN_PRICE, order.getPrice());
   long insertid = database.insert(OrdersDBOpenHelper.TABLE_ORDERS, null, values);
   order.setId(insertid);
   return order;
 }
コード例 #2
0
 public List<Order> findAll() {
   List<Order> orders = new ArrayList<>();
   Cursor cursor =
       database.query(OrdersDBOpenHelper.TABLE_ORDERS, allColumns, null, null, null, null, null);
   if (cursor.getCount() > 0) {
     while (cursor.moveToNext()) {
       Order order = new Order();
       order.setId(cursor.getLong(cursor.getColumnIndex(OrdersDBOpenHelper.COLUMN_ID)));
       order.setPhoneNumber(
           cursor.getString(cursor.getColumnIndex(OrdersDBOpenHelper.COLUMN_PHONE)));
       order.setAddress(
           cursor.getString(cursor.getColumnIndex(OrdersDBOpenHelper.COLUMN_ADDRESS)));
       order.setCreditCardNumber(
           cursor.getString(cursor.getColumnIndex(OrdersDBOpenHelper.COLUMN_CREDITCARD)));
       order.setOrderFromString(
           cursor.getString(cursor.getColumnIndex(OrdersDBOpenHelper.COLUMN_ORDER)));
       order.setPrice(cursor.getString(cursor.getColumnIndex(OrdersDBOpenHelper.COLUMN_PRICE)));
       orders.add(order);
     }
   }
   return orders;
 }