【发布时间】:2010-07-16 22:10:28
【问题描述】:
我在 SQLite 数据库中为 Android 应用程序创建了一个自定义视图。
我在 Ubuntu 上使用 Sqliteman 来测试我的 SQL 语句,然后再将它们放入我的应用程序中。
我正在尝试对我的视图做一个简单的选择语句。
select 语句在 SQLiteman 中运行良好,但是当我在代码中放入相同的语句时,它会引发错误。
声明:
select * from item_view where parent_item_id = 0;
视图(转换为 Java 字符串):
"create view if not exists item_view as select " +
"item._id, item.status, item.name, item.position, " +
"item.parent_item_id, item.note_id, item.other_id, " +
"note.contents, other.priority " +
"from item, note, other where item.note_id = note._id and item.other_id = other._id"
错误:
07-16 14:21:15.153: ERROR/AndroidRuntime(5054): Caused by: android.database.sqlite.SQLiteException: no such column: parent_item_id: , while compiling: SELECT * FROM item_view WHERE parent_item_id = 0
我首先尝试在我的 select 语句中调用字段 item.parent_item_id,但没有成功。
然后我拉出数据库并用 Sqliteman 打开它。
这些字段按照它们在原始表中的状态列出(_id、状态、名称等)
所以我在 Sqliteman 中运行了上面的 SQL,并且能够毫无问题地检索到适当的数据,但我无法让它在我的应用程序中工作。
我还注意到,将视图作为 DROP TABLE 命令删除在 SQLiteman 中有效,但在我的应用程序中无效。
我想知道我是否可能缺少其他一些特定于 VIEW 的功能。
不过,我在 android 文档或任何 SQL 文档中都没有看到任何内容。
从技术上讲,我可以使用原始表通过更复杂的 SQL 调用来做到这一点,但我的所有表都遵循某些准则,以便我可以动态生成 SQL 调用。我想让视图表工作以保持我的代码统一并始终重复使用相同的调用以避免重复代码引起的维护和其他错误问题。
【问题讨论】: