ORMLite DISTINCT 与 Where 条件

ORMLite DISTINCT With Where Condition

我正在使用 ORMLite 开发一个 android 项目,但我有一个问题需要解决。下面有一张图片,我如何在 ORMLite 中使用 DISTINCT sql 查询? 我有一些参数给出了 where 条件,根据这个条件我得到了号码列表...

在这张图片中,您将看到一些数字,其中一些数字是相同的,但我不想得到相同的数字,所以我如何在 ORMLite 中使用 DISTINCT 和 where 条件。

感谢您的帮助

另外我的一些代码是这样的:

  private void modalShowEbat() {
    dbHelper = (DBHelper) OpenHelperManager.getHelper(this, DBHelper.class);
    RuntimeExceptionDao<Segment, Integer> segmentDao = dbHelper.getSegmentExceptionDao();
    List<Segment> list = segmentDao.queryForEq(Constant.QUERY_SEGMENT, editTextSegment.getText().toString().trim());

    final CharSequence items[] = new CharSequence[list.size()];
    for (int i = 0; i < list.size(); i++) {
        items[i] = list.get(i).getColumnEbat();
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Segment seçiniz");
    builder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // the user clicked on colors[which]
            editTextEbat.setText(items[which].toString());
            if (alertDialog != null && alertDialog.isShowing()) {
                alertDialog.dismiss();
            }
        }
    });
    alertDialog = builder.create();
    alertDialog.show();
}

This is my image of result

使用这个 -

segmentDao.queryBuilder().distinct().where().eq("name", "value").query();

你好,我用下面的代码解决了我的问题。也许你可以说这是很长的路要走。我写了如下代码,因为我不能做其他方式(在 ORMLite 或其他 ORMLite 的方法中使用 .distinct() 方法)

如果您有任何其他方法可以解决此问题,我正在等待您的建议。谢谢大家,编码愉快...

private void modalShowEbat() {
    dbHelper = (DBHelper) OpenHelperManager.getHelper(this, DBHelper.class);
    RuntimeExceptionDao<Segment, Integer> segmentDao = dbHelper.getSegmentExceptionDao();
    List<Segment> list = segmentDao.queryForEq(Constant.QUERY_SEGMENT, editTextSegment.getText().toString().trim());

    GenericRawResults<String[]> rawResults = segmentDao.queryRaw("SELECT DISTINCT Ebat FROM Segment WHERE Segment = ? ", editTextSegment.getText().toString().trim());
    final CharSequence items[] = new CharSequence[list.size()];
    int i = 0;
    for (String[] resultColumns : rawResults) {
        String author = resultColumns[0];
        items[i] = author;
        i++;
    }
    int newLenght = 0;
    for (int j = 0; j < items.length; j++) {
        if (items[j] != null) {
            newLenght++;
        }
    }
    final CharSequence newItems[] = new CharSequence[newLenght];
    for (int j = 0; j < newLenght; j++) {
        if (items[j] != null) {
            newItems[j] = items[j];
        }
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Choose Segment");
    builder.setSingleChoiceItems(newItems, 0, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // the user clicked on colors[which]
            editTextEbat.setText(newItems[which].toString());
            if (alertDialog != null && alertDialog.isShowing()) {
                alertDialog.dismiss();
            }
        }
    });
    alertDialog = builder.create();
    alertDialog.show();
}