如何ORMLite重命名列?

编程入门 行业动态 更新时间:2024-10-25 05:25:38
本文介绍了如何ORMLite重命名列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们怎样才能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重命名列?

本文发布于:2023-10-16 16:04:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1498057.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重命名   ORMLite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!