SQLite 游标中从来没有字段
我正在尝试从 SQLite 数据库中的表中检索字段。我已经使用 sqlite3 命令验证了数据是否在表中,并使用调试器针对“数据库”对象内引用的数据库运行我从游标中获得的查询。
这是我的代码:
openForRead();
Cursor cursor = database.query(DATABASE_TABLE,
null, // All columns
null,
null,
null,
null,
"((" + latitude + " - " + KEY_LAT + ") * (" + latitude + " - " + KEY_LAT + ") + ( "
+ longitude + " - " + KEY_LONG + ") * ( " + longitude + " - "+ KEY_LONG + "))",
"10"
);
close();
该代码生成一个 SQL 查询,例如:
SELECT * FROM airport ORDER BY ((35.9314068 - latitude) * (35.9314068 - latitude) + ( -115.09285366 - longitude) * ( -115.09285366 - longitude)) LIMIT 10
表中现在只有 5 个机场,因此我不会超出某些内存限制或类似的内容。
当我在 sqlite3 中运行该查询时,我得到了数据。
为什么我的光标总是空的?即使我将所有内容设置为空,它也是空的(这应该只返回所有内容..)
I am trying to retrieve fields from a table in a SQLite database. I've verified that the data is in the table by using the sqlite3 command and running the query which I got out of the Cursor using the debugger against the database referenced inside my "database" object.
Here is my code:
openForRead();
Cursor cursor = database.query(DATABASE_TABLE,
null, // All columns
null,
null,
null,
null,
"((" + latitude + " - " + KEY_LAT + ") * (" + latitude + " - " + KEY_LAT + ") + ( "
+ longitude + " - " + KEY_LONG + ") * ( " + longitude + " - "+ KEY_LONG + "))",
"10"
);
close();
This code generates a SQL query such as:
SELECT * FROM airport ORDER BY ((35.9314068 - latitude) * (35.9314068 - latitude) + ( -115.09285366 - longitude) * ( -115.09285366 - longitude)) LIMIT 10
I only have 5 airports in the table right now, so I'm not going over some memory limit or anything like that.
When I run that query in sqlite3 I get the data back.
Why is my Cursor always empty? It's empty even if I set everything to null (which should just return everything..)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您给出的列名称是正确的...
make sure the column names u are giving is correct...
在从游标中读取数据之前,我关闭了数据库连接。显然你不能这样做。现在我知道了!
I was closing the database connection before reading the data out of the Cursor. Apparently you can't do that. Now I know!