当前位置:  开发笔记 > 数据库 > 正文

SQLite for Android自定义表视图(SQL VIEW,而不是Android视图)的差异?

如何解决《SQLiteforAndroid自定义表视图(SQLVIEW,而不是Android视图)的差异?》经验,为你挑选了1个好方法。

我在一个Android应用程序的SQLite数据库中创建了一个自定义视图.
我在Ubuntu上使用Sqliteman来测试我的SQL语句,然后再把它放在我的应用程序中.
我正在尝试在我的视图上做一个简单的select语句.
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

I first tried calling the field item.parent_item_id in my select statement, but that didn't work.
Then I pulled the db and opened it with Sqliteman.
The fields were listed as they were in the original tables (_id, status, name, etc.)
So I ran the SQL above in Sqliteman and was able to retrieve the appropriate data no problem but I can't get it to work in my app either way.
I also noticed that dropping the view as a DROP TABLE command worked in SQLiteman but not in my app.
I'm wondering if I'm maybe missing some other VIEW specific functionality.
I didn't see any in either the android documentation or any SQL documentation though.

从技术上讲,我可以使用原始表进行更复杂的SQL调用,但我的所有表都遵循某些指导原则,以便我可以动态生成SQL调用.我希望视图表可以保持我的代码统一,并始终重复使用相同的调用,以避免重复代码中的维护和其他错误问题.



1> leetheguy..:

事实证明,您需要专门命名您正在创建的每个字段,以便android可以将其视为常规表.解决方案...

"create view if not exists item_view as select " +
    "item._id as _id, item.status as item_status, item.name as item_name, item.position as item_position, " +
    "item.parent_item_id as item_parent_item_id, item.note_id as item_note_id, item.other_id as item_other_id, " + 
    "note.contents as note_contents, other.priority as other_priority " +
"from item, note, other where item.note_id = note._id and item.other_id = other._id"


我无法强调你对我有多大帮助!一直拔我的头发两个小时试图找到为什么darn android无法找到*绝对*存在的列!
推荐阅读
linjiabin43
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有