【发布时间】:2010-05-04 15:50:41
【问题描述】:
我在我的应用程序中创建了一个 SQLiteDatabase 并用一些数据填充它。我可以使用终端连接到我的 AVD,当我从文章中发出 select * 时;我得到了表中所有行的列表,一切看起来都很好。但是,在我的代码中,当我查询我的表时,我得到一个游标,其中包含我的表列,但数据行为零。这是我的代码..
mDbHelper.open();
Cursor articles = mDbHelper.fetchAllArticles();
startManagingCursor(articles);
Cursor feeds = mDbHelper.fetchAllFeeds();
startManagingCursor(feeds);
mDbHelper.close();
int titleColumn = articles.getColumnIndex("title");
int feedIdColumn = articles.getColumnIndex("feed_id");
int feedTitleColumn = feeds.getColumnIndex("title");
/* Check if our result was valid. */
if (articles != null) {
int count = articles.getCount();
/* Check if at least one Result was returned. */
if (articles.moveToFirst()) {
在上面的代码中,我的 Cursor 文章返回了我的 4 列,但是当我调用 getCount() 时它返回零,即使我可以从命令行看到该表中的数百行数据。知道我在这里可能做错了什么吗?
另外.. 这是我的 fetchAllArticles 代码..
public Cursor fetchAllArticles() {
return mDb.query(ARTICLES_TABLE, new String[] {ARTICLE_KEY_ROWID, ARTICLE_KEY_FEED_ID, ARTICLE_KEY_TITLE,
ARTICLE_KEY_URL}, null, null, null, null, null);
}
【问题讨论】:
-
您是否尝试移动 mDbHelper.close(); ?还要放断点,看看这里是否 Cursorarticles = mDbHelper.fetchAllArticles();您实际上正在获取数据。
标签: android database sqlite cursor