将ORMlite与SQLite结合使用的Android应用程序。这是我从表中删除一些行的方法:
private static boolean apply(Dao<NotificationInvoice, Integer> invoiceDao) {
boolean isSuccess = false;
try {
String sql ="DELETE from notification where ownerkey not in ("123","456")";
GenericRawResults<String[]> rawResults = invoiceDao.queryRaw(sql);
isSuccess = true;
} catch (SQLException e) {
if (BuildConfig.DEBUG)
Log.e(TAG, e.getMessage(), e);
}
return isSuccess;
}
有效。从表中成功删除N条记录。真好 问题是:如何在不执行第二次查询的情况下获取已删除的行数?
答案 0 :(得分:1)
您可以使用 OrmLite 中的DeleteBuilder
。
DeleteBuilder deleteBuilder = invoiceDao.deleteBuilder();
deleteBuilder.where().notIn("ownerkey", new String[]{"123", "457"});
deleteCount = deleteBuilder.delete()