我有 CallItem
对象并使用 ORMLite 数据库。我需要将项目添加到指定表的末尾。我创建这样的新项目:
public void saveCallItem(CallItem contact) throws SQLException {
OrmLiteSqliteOpenHelper dbHelper=DatabaseHandler.getInstance(_context);
dbHelper.getDao(CallItem.class);
HelperFactory.GetHelper().getCallDao().createIfNotExists(contact);
}
但是这个实现将项目添加到表开头。我需要走到最后。我该如何实现这个?
最佳答案
But this implementation adds item to the table beginning. I need to the end. How can I implement this?
SQL 数据库不保证任何特定的顺序,并且可以自由地重用表中先前删除的空间。 ORMLite 只是将项目插入数据库,而 SQLite 则决定将其放在开头。
如果您希望按特定顺序退回商品,则应使用 QueryBuilder.orderBy(...)
method 在查询中添加订单。 。您可以添加一个 generated-id 字段,然后按该字段进行排序,这应该会给您带来您想要的结果。
关于java - ORMLite - 将项目添加到表末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19568361/