我们怎样才能ORMLite重命名列名?
How can we rename column name in ORMLite?
我想写从some_table该查询 SELECT ID作为_id
I am trying to write that query SELECT id as _id from some_table
Android的游标适配器要求我们有列名为 _id 和 ORMLite 要求我们有列名为 ID 。
Android Cursor Adapter requires us to have column named _id and ORMLite requires us to have column named id.
我试图写查询并返回光标此查询。
I am trying to write that query and return Cursor from this query.
Dao<NewsArticle, Long> newsArticleDao = ((SomeApp)mContext.getApplicationContext()).getDAOConnection().getDAO( NewsArticle.class); QueryBuilder<NewsArticle, Long> query = newsArticleDao.queryBuilder().selectRaw( "`id` as `_id`"); PreparedQuery<NewsArticle> preparedQuery = query.prepare(); CloseableIterator<NewsArticle> iterator = newsArticleDao.iterator(preparedQuery); AndroidDatabaseResults results = (AndroidDatabaseResults)iterator.getRawResults(); cursor = results.getRawCursor();这是我到目前为止,但是当我通过查询迭代器。
That's what I have so far but I am getting this error when I pass query to iterator.
java.sql.SQLException中:因为调用者期待一个SELECT语句无法编译这个SELECT_RAW声明。检查你的QueryBuilder的方法。
推荐答案我想我必须回答我的问题。
I guess I have to answer my question.
我仍然无法弄清楚如何重命名列,但我找到了解决问题。
I still couldn't figure out how to rename column but I found the solution to problem.
Android的自定义适配器要求 _id 指定的列那是真实的,但 ORMLite 不需要列名是 ID ,我错了。它要你来标记列ID。
Android Custom Adapter requires column named_id that's true but ORMLite doesn't require the column name to be id, I was wrong about that. It wants you to mark a column as id.
在我的模型,我打上我的ID,现在,它就像一个魅力。
In my model, I marked my id and now it works like a charm.
@DatabaseField(id = true) private long _id;更多推荐
如何ORMLite重命名列?
发布评论