Open ythy opened 6 years ago
ORMlite not returning the object I just saved
Create a new row in the database from an object. If the object being created uses DatabaseField.generatedId() then the data parameter will be modified and set with the corresponding id from the database. ... Returns: The number of rows updated in the database. This should be 1.
When ORMLite creates the object, the generated ID is then set to the id field afterwards. To find the ID of your new object you get it from the object itself:
// create returns 1 row changed
helper.getWishListDao().create(wl);
// the id field is set on the w1 object after it was created
savedID = w1.getId();
取count的用法, 关键要 setCountOf(true);
QueryBuilder<CardInfo, Integer> qbCount = this.queryBuilder();
qbCount.setCountOf(true);
qbCount.orderBy(orderBy, isAsc);
qbCount.selectRaw("*");
qbCount.setWhere(where);
int count = (int) this.countOf(qbCount.prepare());
Official Website 数据库操作API
生成Config File的路径在项目根目录的
./res/raw
下, 不是./app/src/main/res/raw
下, 需要手动建./res/raw
, 生成.txt
文件后拷贝到相应目录}
@DatabaseField(id = true, columnName="_id") private int id = -1;