SQLite Cursor never has fields in it

笑着哭i 提交于 2020-01-25 21:32:32

问题


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..)


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/8177938/sqlite-cursor-never-has-fields-in-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!