在ContentResolver的独特和GROUPBY

在ContentResolver的独特和GROUPBY

本文介绍了安卓:在ContentResolver的独特和GROUPBY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么将是一个明智的方式来增加 DISTINCT 和/或 GROUPBY ContentResolver的 - 基于查询。现在,我要创建自定义的URI为每个特殊情况。有没有更好的办法?(我还计划1.5的最小公分母)

What would be a sensible way to add DISTINCT and/or GROUPBY to ContentResolver- based queries. Right now I have to create custom URI for each special case. Is there a better way?(I still program for 1.5 as lowest common denominator)

推荐答案

由于没有人来回答,我只是要告诉我怎么解决这一点。基本上,我会创建自定义的URI为每种情况,并通过在选择参数的标准。然后的ContentProvider#查询里面我会查明案情,并根据表名,选择参数构造原始查询。

Since no one came to answer I'm just going to tell how I solved this. Basically I would create custom URI for each case and pass the criteria in selection parameter. Then inside ContentProvider#query I would identify the case and construct raw query based on table name and selection parameter.

下面是简单的例子:

switch (URI_MATCHER.match(uri)) {
    case TYPES:
        table = TYPES_TABLE;
        break;
    case TYPES_DISTINCT:
        return db.rawQuery("SELECT DISTINCT type FROM types", null);
    default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }
    return db.query(table, null, selection, selectionArgs, null, null, null);

这篇关于安卓:在ContentResolver的独特和GROUPBY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 03:23