光标返回-1计数,但项目是present? [英] Cursor returns a count of -1, but items are present?
问题描述
我使用的SQLite数据库来存储从其获取我的应用程序的数据,以及如何检查重复的条目。我试图找回在那里的标题匹配的所有条目,因为这样的:
I am using an SQLite database to store and retreive my app data, and what to check for duplicate entries. I attempt to retrieve all entries where the titles match, as such:
Cursor c = mDb.query(DatabaseHelper.GOALS_TABLE_NAME,
new String[] { Goals.GOAL_ID, Goals.TITLE },
Goals.TITLE + "='" + title + "'", null, null, null,
null, null);
其中title是一个比较的。
where title is the one to compare against.
这个查询运行,但光标给出-1计数。没有where子句的调用也返回-1,但我知道数据present,因为我可以列表视图绑定到它。
This query runs, but the cursor gives a count of -1. A call without the where clause also returns -1, but I know data is present, as I am able to bind a list view to it.
有我丢失的东西,我必须以某种方式填充光标?
Is there something I am missing, do I have to populate the cursor somehow?
由于提前,
Venatu
推荐答案
当你做了查询()
的光标
立即返回。该查询本身没有运行。只有当你做一些事情,需要将查询执行的数据加载。尝试(例如, moveToFirst()
)之前调用 getCount将()
第一执行另一种方法,看看有没有变化的东西。
When you do a query()
, the Cursor
is returned immediately. The query itself is not yet run. Only when you do something that requires a data load will the query be executed. Try executing another method first (e.g., moveToFirst()
) before calling getCount()
and see if that changes things.
这篇关于光标返回-1计数,但项目是present?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!