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:
- table1 => rowid, title, content, fav
- table2 => rowid, title, content, fav
- table3 => rowid, title, content, fav
- table4 => rowid, title, content, fav
- table5 => rowid, title, content, fav
- 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
:
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.
精彩评论