SQLite Cursor never has fields in it

2019-09-08 06:22发布

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

2条回答
时光不老,我们不散
2楼-- · 2019-09-08 06:48

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

查看更多
聊天终结者
3楼-- · 2019-09-08 06:53

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

查看更多
登录 后发表回答