【问题标题】:How to get distinct values from BoxStore Objectbox database in android如何从 android 中的 BoxStore Objectbox 数据库中获取不同的值
【发布时间】:2017-10-30 11:58:48
【问题描述】:

我无法在 android 的 green dao 的 Objectbox 数据库中编写查询来获取不同的值

【问题讨论】:

  • 您是否正在寻找(一个)特定属性的不同值?
  • 是的,我需要在数据库中存储不同的年份
  • 对于新的研究人员,此属性现已添加到 ObjectBox 中:String[] names = userBox.query().build().property(User_.firstName).distinct().findStrings(); from here

标签: android greendao objectbox


【解决方案1】:

通过此功能请求跟踪获取不同的值: https://github.com/objectbox/objectbox-java/issues/198

我们目前正在收集需求,因此请随时在此处发表评论。

【讨论】:

    【解决方案2】:

    不知道是否有任何 BuildIn 方法可以做同样的事情,但我能够只使用 SQL 来计算不同的值。可能对你有帮助。

    String query = "SELECT COUNT (DISTINCT "
                                    + HomeDao.Properties.VisiblePageId.columnName+
                                    ") from "
                                    + HomeDao.TABLENAME
                                    + " where "
                                    + HomeDao.Properties.IsVisible.columnName + " = 1 and "
                                    + HomeDao.Properties.IsActive.columnName + " = 1";
                            Integer count = 0;
    
                            Cursor cursor =
                                    MainApplication.getInstance().getDaoSession().getDatabase().rawQuery(
                                            query, null
                                    );
    
                            if(cursor.moveToFirst()){
                                count = cursor.getInt(0);
                            }
                            cursor.close();
    

    【讨论】:

    • 嗨,greendao 中有 Distinct 选项,但在 BoxStore objectbox 中,我无论如何都找不到任何方法,谢谢您的回复
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 2021-06-13
    • 2023-03-09
    • 1970-01-01
    • 2021-01-25
    • 1970-01-01
    相关资源
    最近更新 更多