开发者

Strange Problem with Cursor - Android

This is a method In my DataBase Class:

public Cursor fetchFavTitles() {
    return myDataBase.rawQuery("SELECT rowid as _id, title
        FROM table1 JOIN table2 JOIN table3 JOIN table4 JOIN table5 JOIN table6
        WHERE fav = TRUE", null);
}

My SQLite database has 6 tables:

  1. table1 => rowid, title, content, fav
  2. table2 => rowid, title, content, fav
  3. table3 => rowid, title, content, fav
  4. table4 => rowid, title, content, fav
  5. table5 => rowid, title, content, fav
  6. table6 => rowid, title, fav

In my activity, I wrote this:

Cursor cursor = myDbHelper.fetchFavTitles();

and the application开发者_高级运维 forces the close!

Any idea where I'm mistaken ?

UPDATE

This is a snapshot of the LogCat, I couldn't understand it, I filtered the output with android.database:

Strange Problem with Cursor - Android

What I am trying to do is getting the title (type: TEXT) that have a fav (type: BOOL) with value TRUE From all the tables and display them in one ListView (using SimpleCursorAdapter).


Without understanding exactly what you're going for, I'm guessing you need to change your query to:

SELECT rowid as _id, title
        FROM table1 
        WHERE fav = TRUE
UNION ALL
SELECT rowid as _id, title
        FROM table2
        WHERE fav = TRUE
UNION ALL
SELECT rowid as _id, title
        FROM table3
        WHERE fav = TRUE
UNION ALL   
SELECT rowid as _id, title
        FROM table4 
        WHERE fav = TRUE
UNION ALL       
SELECT rowid as _id, title
        FROM table5 
        WHERE fav = TRUE
UNION ALL       
SELECT rowid as _id, title
        FROM table6 
        WHERE fav = TRUE

This will take all the results where 'fav = TRUE' from each of the tables and put them all into one result set. If you don't want duplicates, you can change 'UNION ALL' to 'UNION'. Right now your query is failing because 'SELECT rowid as _id, title' doesn't know which of your tables to pull the 'title' field from.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜