游标从查询返回零行到表

时间:2022-06-01 21:40:15

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

我在我的应用程序中创建了一个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()) {

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?

在上面的代码中,我的Cursor文章返回了我的4列,但是当我调用getCount()时它返回零,即使我可以从命令行看到该表中的数百行数据。知道我在这里做错了什么吗?

Also.. here is my code for fetchAllArticles..

另外..这是我的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);
}

1 个解决方案

#1


3  

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

尝试移动mDbHelper.close();到最后还 - 你可以发布fetch方法src吗?

#1


3  

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

尝试移动mDbHelper.close();到最后还 - 你可以发布fetch方法src吗?