SQLite for Android自定义表视图(SQL VIEW,而不是Android视图)的
发布时间:2020-12-12 19:06:19 所属栏目:百科 来源:网络整理
导读:我在一个 Android应用程序的SQLite数据库中创建了一个自定义视图. 我在Ubuntu上使用Sqliteman来测试我的SQL语句,然后再将它们放入我的应用程序中. 我正在尝试在我的视图上做一个简单的select语句. select语句在SQLiteman中运行正常但是当我在我的代码中放入
我在一个
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 我首先尝试在我的select语句中调用字段item.parent_item_id,但这不起作用. 从技术上讲,我可以使用原始表进行更复杂的SQL调用,但我的所有表都遵循某些指导原则,以便我可以动态生成SQL调用.我希望视图表可以保持我的代码统一,并始终重复使用相同的调用,以避免重复代码中的维护和其他错误问题. 事实证明,您需要专门命名您正在创建的每个字段,以便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,other where item.note_id = note._id and item.other_id = other._id" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |