光标的奇怪问题 - Android
这是我的 DataBase 类中的一个方法:
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);
}
我的 SQLite 数据库有 6 个表:
- table1 => rowid、标题、内容、收藏夹
- 表2 => rowid、标题、内容、收藏夹
- 表3 => rowid、标题、内容、收藏夹
- 表4 => rowid、标题、内容、收藏夹
- 表5 => rowid、标题、内容、收藏夹
- 表6 => rowid、title、fav
在我的活动中,我这样写:
Cursor cursor = myDbHelper.fetchFavTitles();
并且应用程序强制关闭!
知道我错在哪里吗?
更新
这是LogCat的快照,我无法理解它,我用android.database
过滤了输出:
我想要做的是获取 title
(类型:TEXT)具有值 TRUE 的收藏夹(类型:BOOL) 来自所有表并将它们显示在一个 ListView
中(使用 SimpleCursorAdapter)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在不确切了解您要做什么的情况下,我猜您需要将查询更改为:
这将从每个表中获取“fav = TRUE”的所有结果,并将它们全部放入一个结果集中。如果您不想重复,可以将“UNION ALL”更改为“UNION”。现在您的查询失败,因为“SELECT rowid as _id, title”不知道从哪个表中提取“title”字段。
Without understanding exactly what you're going for, I'm guessing you need to change your query to:
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.