SQLite的:看起来像使用MoveToNext工程没有moveToFirst需要 [英] sqlite: looks like moveToNext works without moveToFirst needed

查看:122
本文介绍了SQLite的:看起来像使用MoveToNext工程没有moveToFirst需要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个标准的SQLite光标后,我迭代直通条目使用:

After creating a standard SQLite cursor, I'm iterating thru the entries using:

while (cursor.moveToNext()) {
}

所有的行正确处理。 所有我读过的文档指出需要发出一个 moveToFirst()来保证 你正在指向的光标集的第一条目。

All the rows are being processed correctly. All the documentation I've read states you need to issue a moveToFirst() to ensure that you're pointing to the first entry of the cursor set.

这是工作,即使它不应该, 而另一个版本可能不会有同样的处理?

Is this working even though it shouldn't, and another release may not have the same processing?

推荐答案

没有,这是正常工作。 光标齐读在行指数-1(第一行之前)。如果光标引用多行,通过他们循环使用,而循环正如你所建议的是preferred方法。它会调用使用MoveToNext(),它会移到指数0(第一行),并从那里。

No, this is working correctly. Cursors begin at row index -1 (before the first row). If the Cursor references multiple rows, looping through them with the while loop as you have suggested is the preferred method. It will call moveToNext(), which moves you to index 0 (the first row), and go from there.

如果你的光标只引用一个行,你可以叫 moveToFirst()在它之前读取数据,以确保你是一个有效的指标。无论 moveToFirst()使用MoveToNext()具有相同的效果时,光标第一次创建,并在索引-1。

If your Cursor only references one row, you may call moveToFirst() on it before reading data to ensure that you are on a valid index. Both moveToFirst() and moveToNext() have the same effect when the Cursor is first created and is at index -1.

这篇关于SQLite的:看起来像使用MoveToNext工程没有moveToFirst需要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆