SQLite 游标中从来没有字段

发布于 2024-12-16 02:18:23 字数 869 浏览 4 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哭了丶谁疼 2024-12-23 02:18:23

确保您给出的列名称是正确的...

make sure the column names u are giving is correct...

放低过去 2024-12-23 02:18:23

在从游标中读取数据之前,我关闭了数据库连接。显然你不能这样做。现在我知道了!

I was closing the database connection before reading the data out of the Cursor. Apparently you can't do that. Now I know!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文