java - ORMLite - 将项目添加到表末尾

标签 java android sqlite ormlite

我有 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/

相关文章:

android - 使用身份验证拒绝 Firebase 权限(读取和写入)

php - 让 map 接受动态生成的 KML 文件?

java - 使用 Square 的 Retrofit Client,是否可以取消正在进行的请求?如果有怎么办?

java - selenium.waitForPageToLoad 似乎没有在等待

java - 通过Matlab和Java驱动程序从MongoDB(gridfs)读取数据

java - 元素不会出现在具有 GridLayout 或 FlowLayout 的面板中,但具有 setBounds 时它们会出现在面板中

java - Firestore Recycler 未在应用屏幕上显示任何结果且没有错误

具有多个where的android sqlite查询

java - Android中的SQLite如何更新特定行

java - NullPointerException:尝试在空对象引用 [Database Sqlite] 上调用虚拟方法