我在基于Android的应用程序中使用OrmLite进行数据库管理时使用了这些表。OrmLite:高级其中逻辑
我想这取决于有多少产品类型FOLDER我有有数组列表的x号是什么。
所以在这种情况下,我想要一个productId等于parentId的产品列表。 所以我希望有一个列表,其中
if(productType = FOLDER) {
if(productId = parentId){
//add product
}
}
基本上我想结束了,在这种情况下,三个列表,每个包含的产品列表,其中parentId的是每一个产品相同。
我已经尝试了很多东西,并且其中一些比其他的更好,但是我想运行的代码实际上会抛出一个空指针。
DatabaseHelper dbHelper = getHelper();
List<Product> productsParents = null;
try {
Dao<Product, Integer> dao = dbHelper.getDao();
PreparedQuery<Product> prepQu = dao.queryBuilder().where()
.eq("parentId", dao.queryBuilder().selectColumns("productId").where()
.eq("productType", ProductType.FOLDER).prepare()).prepare();
productsParents = dao.query(prepQu);
} catch (SQLException e) {
...
}
这个代码不工作,因为productParents返回null,它不会做我想做的,即使它是一个轻微的暗示。如果有人知道如何在代码中做到这一点,也可能是足够的,或者更可能是java和ormlite的混合。
我在找什么,我喜欢缩写RTFM。 –
RTFM是旧派。很多较新的黑客甚至不知道它@JoakimEngstrom。 :-) – Gray