Resolver.query从错误的表中返回行

时间:2014-06-14 21:09:31

标签: android sqlite cursor

我正在尝试从我创建的表中返回一些行,但是我的查询是从错误的表中返回数据,我想我的匹配器做错了,但是我看不清楚。< / p>

我的匹配器看起来像这样:

private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
static {
    // A player
    sURIMatcher.addURI(PlayerStatsContract.AUTHORITY, PlayerStatsContract.Player.BASE_PATH, PLAYERS);
    sURIMatcher.addURI(PlayerStatsContract.AUTHORITY, PlayerStatsContract.Player.BASE_PATH + "/#", PLAYER_ID);

    // A match
    sURIMatcher.addURI(PlayerStatsContract.AUTHORITY, PlayerStatsContract.Match.BASE_PATH, MATCHES);
    sURIMatcher.addURI(PlayerStatsContract.AUTHORITY, PlayerStatsContract.Match.BASE_PATH + "/#", MATCH_ID);

    // Stats on a match.
    sURIMatcher.addURI(PlayerStatsContract.AUTHORITY, PlayerStatsContract.MatchStats.BASE_PATH, MATCH_STATS);
    sURIMatcher.addURI(PlayerStatsContract.AUTHORITY, PlayerStatsContract.MatchStats.BASE_PATH + "/#", MATCH_STATS_ID);

}

而我正在创建抓取数据的方法的类看起来像这样:

public static final class MatchStats implements BaseColumns {
    public static final String BASE_PATH = "matchstats";
    public static final Uri CONTENT_URI = Uri.withAppendedPath(PlayerStatsContract.CONTENT_URI, BASE_PATH);

    public static final String TABLE_NAME = "matchstats";

    public static final String COLUMN_MATCH     = "match_id";
    public static final String COLUMN_PLAYER   = "player";
    public static final String COLUMN_STAT          = "stat_id";
    public static final String COLUMN_STAT_SUCCESS  = "stat_success";
    public static final String COLUMN_STAT_FAIL     = "stat_fail";

    public static final int COLUMN_MATCH_INDEX     = 1;
    public static final int COLUMN_PLAYER_INDEX   = 2;
    public static final int COLUMN_STAT_INDEX          = 3;
    public static final int COLUMN_STAT_SUCCESS_INDEX  = 4;
    public static final int COLUMN_STAT_FAIL_INDEX     = 5;

    public static void statSuccess(Context context, Integer matchId, Long playerId, Integer statId) {
        final ContentResolver resolver = context.getContentResolver();

        Cursor c = resolver.query(
                MatchStats.CONTENT_URI,
                new String[]{COLUMN_MATCH, COLUMN_PLAYER, COLUMN_STAT, COLUMN_STAT_SUCCESS, COLUMN_STAT_FAIL},
                COLUMN_PLAYER + " = ?, " + COLUMN_MATCH + " = ?, " + COLUMN_STAT + " = ? ",
                new String[]{playerId.toString(), matchId.toString(), statId.toString()},
                null);

,结果是来自另一个表的数据,供参考设置如下:

public static final class Player implements BaseColumns {
    public static final String BASE_PATH = "players";
    public static final Uri CONTENT_URI = Uri.withAppendedPath(PlayerStatsContract.CONTENT_URI, Player.BASE_PATH);

    public static final String TABLE_NAME = "player";
    public static final String COLUMN_NAME_NAME = "name";
    public static final String COLUMN_NAME_IMAGE_PATH = "image_path";
}

我是否正确设置了匹配器?

0 个答案:

没有答案