public static List<Banquet> getBanquetsByHotelId(Context context, String hotelId) { DbUtils db = DbUtils.create(context); try { return db.findAll(Selector.from(Banquet.class).where("hotelId", "=", hotelId)); } catch (DbException e) { e.printStackTrace(); return null; } }
public List<Comment> query(int page) { try { List<Comment> list = db.findAll(Selector.from(Comment.class).limit(20 * page)); return list; } catch (DbException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
/*package*/ DownloadManager(Context appContext) { ColumnConverterFactory.registerColumnConverter( HttpHandler.State.class, new HttpHandlerStateConverter()); mContext = appContext; db = DbUtils.create(mContext); try { downloadInfoList = db.findAll(Selector.from(DownloadInfo.class)); } catch (DbException e) { LogUtils.e(e.getMessage(), e); } if (downloadInfoList == null) { downloadInfoList = new ArrayList<DownloadInfo>(); } }
private void testDb() { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Parent parent = new Parent(); parent.name = "测试"; parent.isVIP = false; parent.setAdmin(true); parent.setEmail("*****@*****.**"); /*Parent parent2 = new Parent(); parent2.name = "测试2"; parent2.isVIP = false;*/ try { DbUtils db = DbUtils.create(this); db.configAllowTransaction(true); Child child = new Child(); child.name = "child name"; // db.saveBindingId(parent); // child.parent = new SQLiteLazyLoader<Parent>(Child.class, "parentId", parent.getId()); child.parent = parent; try { Parent test = db.findFirst(parent); // 通过entity的属性查找 LogUtils.d("wyouflf :" + test); } catch (Exception e) { LogUtils.e(e.getMessage(), e); } parent.setTime(new Date()); parent.setTime2(new java.sql.Date(new Date().getTime())); db.saveBindingId(child); // 保存对象关联数据库生成的id List<Child> children = db.findAll(Selector.from(Child.class)); LogUtils.d("wyouflf size:" + children.size()); if (children.size() > 0) { LogUtils.d("wyouflf child:" + children.get(children.size() - 1).parent); } List<Parent> list = db.findAll( Selector.from(Parent.class) .where(WhereBuilder.b("id", "<", 54)) .orderBy("id") .limit(10)); LogUtils.d("wyouflf size:" + list.size()); if (list.size() > 0) { LogUtils.d("wyouflf parent:" + list.get(list.size() - 1).toString()); } // parent.name = "hahaha123"; // db.update(parent); Parent entity = db.findById(Parent.class, parent.getId()); LogUtils.d("wyouflf parent:" + entity.toString()); List<DbModel> dbModels = db.findDbModelAll( Selector.from(Parent.class).groupBy("name").select("name", "count(name)")); LogUtils.d("wyouflf:" + dbModels.size()); } catch (DbException e) { LogUtils.e(e.getMessage(), e); } }