Sugar ORM for Android cant find my column name

╄→尐↘猪︶ㄣ 提交于 2019-12-09 05:44:09

问题


Well I'm trying to select all entities where entitie_id = *some id*

I do this with this rule:

List<NodeSugar> nodesugars = NodeSugar.find(NodeSugar.class, "entitie_id = ? ", String.valueOf(nodeid));

I know I should get some results back and I get an error. this error:

E/SQLiteLog﹕ (1) no such column: entitie_id

I know the column exists because I can set it in a different part of code.

Where am I going wrong?


回答1:


You should be able to query with "entitieid".

Sugar ORM does some conversion when it creates the columns in the tables. Here is a basic example:

String firstName; //creates column first_name
int entitie_id;   //creates column entitieid

The documentation only specifies the conversion from camel case to underscore separation. I had to figure the other one out.




回答2:


You can use NamingHelper.toSQLNameDefault() to wrap column names when building queries. Try:

List<NodeSugar> nodesugars = NodeSugar.find(NodeSugar.class, NamingHelper.toSQLNameDefault("entitie_id") + " = ? ", String.valueOf(nodeid));

NamingHelper is used in the Sugar ORM library to create tables and column names:

https://github.com/satyan/sugar/blob/master/library/src/main/java/com/orm/helper/NamingHelper.java



来源:https://stackoverflow.com/questions/29647446/sugar-orm-for-android-cant-find-my-column-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!