【发布时间】:2015-08-08 03:27:46
【问题描述】:
我正在使用以下代码获取通知列表(总行数为 21):
List<Notification> list = new ArrayList<Notification>();
Cursor c = _db.query(TABLE_NAME, COL_ALL, null, null, null, null, order, get_limitStr(offset));
if(c != null && c.moveToFirst())
{
while(!c.isAfterLast())
{
Notification model = cursorToModel(c);
if(model != null)
{
list.add(model);
}
c.moveToNext();
}
c.close();
}
生成的 offset = 0 查询是
SELECT Id, Token, Title, Read, Message, Image, CreateDate, CreateDateFA FROM Notifications ORDER BY CreateDate DESC LIMIT 20,0
它按预期工作并返回 20 行,当我将偏移量增加 1(偏移量 = 1)时,它只返回 1 行,这是正确的,但问题是当偏移量大于 1 时,查询将是
SELECT Id, Token, Title, Read, Message, Image, CreateDate, CreateDateFA FROM Notifications ORDER BY CreateDate DESC LIMIT 20,2
我认为它应该跳过 20 * 2 行,然后开始从那里获取行,这要么是我的想法,要么是我的查询是错误的。我在这里做错了什么?谢谢
【问题讨论】:
-
我不明白你想要什么,但可以在这里找到答案:sqlite.org/lang_select.html#limitoffset
标签: java android sqlite android-sqlite