开发者

Cursor returns zero rows from query to table

I've created an SQLiteDatabase in my app and populated it with some data. I can connect to my AVD with a terminal and when I issue select * from articles; I get a list of all the rows in my table and everything looks fine. However, in my code when I query my table, I get a cursor back that has my tables columns, but zero rows of data. Here is my code..

 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()) {

In the above code, my Cursor articles returns with my 4 columns, but when I call getCount() it returns zero, even though I can see hundreds of rows of data in that table from command line. Any idea what I might be doing wrong here?

Also.. here is my code for fetchAllArticles..

public Cursor fetchAllArticles() {

    return mDb.query(ARTICLES_TABLE, new String[] {ARTICLE_KEY_ROWID, ARTICLE_KEY_FEED_ID, ARTICLE_KEY_TITLE,
            ARTICLE_KEY_U开发者_开发知识库RL}, null, null, null, null, null);
}


try moving mDbHelper.close(); to the end Also - could you post fetch method src ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜