Java Code Examples for android.database.sqlite.SQLiteQueryBuilder#setProjectionMap()

The following examples show how to use android.database.sqlite.SQLiteQueryBuilder#setProjectionMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomContentProvider.java    From OpenCircle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(TABLE_NAME);

    switch (uriMatcher.match(uri)) {
        case uriCode:
            qb.setProjectionMap(values);
            break;
        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
    }
    if (sortOrder == null || sortOrder == "") {
        sortOrder = id;
    }
    Cursor c = qb.query(db, projection, selection, selectionArgs, null,
            null, sortOrder);
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}
 
Example 2
Source File: PlacesProvider.java    From protrip with MIT License 6 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder.setTables(sqLiteOpenHelper.TABLE_NAME);
    switch (uriMatcher.match(uri)){
        case PLACES_ID:
            queryBuilder.setProjectionMap(PlaceMap);
            break;
        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
    }
    if (sortOrder == null || sortOrder == ""){
        sortOrder = sqLiteOpenHelper.ID;
    }

    Cursor cursor = queryBuilder.query(database, projection, selection,
            selectionArgs, null, null, sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
 
Example 3
Source File: SettingsProvider.java    From Demo_Public with MIT License 6 votes vote down vote up
@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(Settings.TABLE_NAME);

    switch (sUriMatcher.match(uri)){
        case SETTINGS:
            qb.setProjectionMap(sProjectionMap);
            break;
        case SETTINGS_ID:
            qb.setProjectionMap(sProjectionMap);
            qb.appendWhere(
                    Settings._ID +"="+uri.getPathSegments().get(1)
            );
            break;
        default:
            throw new IllegalArgumentException("Unknown uri: "+uri);
    }

    SQLiteDatabase db = mOPenHelper.getReadableDatabase();
    Cursor c = qb.query(db,projection,selection,selectionArgs,null,null,sortOrder);
    c.setNotificationUri(getContext().getContentResolver(),uri);
    return c;
}
 
Example 4
Source File: VCardManager.java    From yiim_v2 with GNU General Public License v2.0 5 votes vote down vote up
public Cursor query(SQLiteDatabase db, int type, Uri uri,
		String[] projection, String selection, String[] selectionArgs,
		String sortOrder) {

	SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
	qb.setTables(TABLE_NAME);

	if (type == UriType.VCARD.getCode()) {
		qb.setProjectionMap(mProjectionMap);
	} else if (type == UriType.VCARD_ID.getCode()) {
		qb.setProjectionMap(mProjectionMap);
		qb.appendWhere(VCardColumns._ID + "="
				+ uri.getPathSegments().get(1));
	} else if (type == UriType.LIVE_FOLDER_VCARD.getCode()) {
		qb.setProjectionMap(mLiveFolderProjectionMap);
	} else {
		throw new IllegalArgumentException("Unknown URI " + uri);
	}

	// If no sort order is specified use the default
	String orderBy;
	if (TextUtils.isEmpty(sortOrder)) {
		orderBy = VCardColumns.DEFAULT_SORT_ORDER;
	} else {
		orderBy = sortOrder;
	}

	// Get the database and run the query
	Cursor c = qb.query(db, projection, selection, selectionArgs, null,
			null, orderBy);

	return c;
}
 
Example 5
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
private SQLiteQueryBuilder builderArenaQuest() {
//		SELECT a._id AS _id, a.name AS aname, a.location_id, a.reward.,
//		a.num_participants, a.time_s, a.time_a, a.time_b,
//		l.name AS lname
//		FROM arena_quests AS a
//		LEFT OUTER JOIN locations AS l on a.location_id = l._id;

        String a = "a";
        String l = "l";

        HashMap<String, String> projectionMap = new HashMap<String, String>();

        projectionMap.put("_id", a + "." + S.COLUMN_ARENA_QUESTS_ID + " AS " + "_id");
        projectionMap.put(S.COLUMN_ARENA_QUESTS_NAME, a + "." + S.COLUMN_ARENA_QUESTS_NAME + " AS " + a + S.COLUMN_ARENA_QUESTS_NAME);
        projectionMap.put(S.COLUMN_ARENA_QUESTS_GOAL, a + "." + S.COLUMN_ARENA_QUESTS_GOAL);
        projectionMap.put(S.COLUMN_ARENA_QUESTS_LOCATION_ID, a + "." + S.COLUMN_ARENA_QUESTS_LOCATION_ID);
        projectionMap.put(S.COLUMN_ARENA_QUESTS_REWARD, a + "." + S.COLUMN_ARENA_QUESTS_REWARD);
        projectionMap.put(S.COLUMN_ARENA_QUESTS_NUM_PARTICIPANTS, a + "." + S.COLUMN_ARENA_QUESTS_NUM_PARTICIPANTS);
        projectionMap.put(S.COLUMN_ARENA_QUESTS_TIME_S, a + "." + S.COLUMN_ARENA_QUESTS_TIME_S);
        projectionMap.put(S.COLUMN_ARENA_QUESTS_TIME_A, a + "." + S.COLUMN_ARENA_QUESTS_TIME_A);
        projectionMap.put(S.COLUMN_ARENA_QUESTS_TIME_B, a + "." + S.COLUMN_ARENA_QUESTS_TIME_B);

        projectionMap.put(l + S.COLUMN_LOCATIONS_NAME, l + "." + S.COLUMN_LOCATIONS_NAME + " AS " + l + S.COLUMN_LOCATIONS_NAME);

        //Create new querybuilder
        SQLiteQueryBuilder QB = new SQLiteQueryBuilder();

        QB.setTables(S.TABLE_ARENA_QUESTS + " AS a" + " LEFT OUTER JOIN " + S.TABLE_LOCATIONS +
                " AS l " + " ON " + "a." + S.COLUMN_ARENA_QUESTS_LOCATION_ID + " = " + "l." + S.COLUMN_LOCATIONS_ID);

        QB.setProjectionMap(projectionMap);
        return QB;
    }
 
Example 6
Source File: LocalyticsProvider.java    From Beats with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Performs a query.
 * <p>
 * Note: this method may perform disk operations.
 *
 * @param tableName name of the table operate on. Must be one of the recognized tables. Cannot be null.
 * @param projection The list of columns to include. If null, then all columns are included by default.
 * @param selection A filter to apply to all rows, like the SQLite WHERE clause. Passing null will query all rows. This param
 *            may contain ? symbols, which will be replaced by values from the {@code selectionArgs} param.
 * @param selectionArgs An optional string array of replacements for ? symbols in {@code selection}. May be null.
 * @param sortOrder How the rows in the cursor should be sorted. If null, then the sort order is undefined.
 * @return Cursor for the query. To the receiver: Don't forget to call .close() on the cursor when finished with it.
 * @throws IllegalArgumentException if tableName is null or not a valid table name.
 */
public Cursor query(final String tableName, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder)
{
    if (Constants.IS_PARAMETER_CHECKING_ENABLED)
    {
        if (!isValidTable(tableName))
        {
            throw new IllegalArgumentException(String.format("tableName %s is invalid", tableName)); //$NON-NLS-1$
        }
    }

    if (Constants.IS_LOGGABLE)
    {
        Log.v(Constants.LOG_TAG, String.format("Query table: %s, projection: %s, selection: %s, selectionArgs: %s", tableName, Arrays.toString(projection), selection, Arrays.toString(selectionArgs))); //$NON-NLS-1$
    }

    final SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(tableName);

    if (projection != null && 1 == projection.length && BaseColumns._COUNT.equals(projection[0]))
    {
        qb.setProjectionMap(sCountProjectionMap);
    }

    final Cursor result = qb.query(mDb, projection, selection, selectionArgs, null, null, sortOrder);

    if (Constants.IS_LOGGABLE)
    {
        Log.v(Constants.LOG_TAG, "Query result is: " + DatabaseUtils.dumpCursorToString(result)); //$NON-NLS-1$
    }

    return result;
}
 
Example 7
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
private SQLiteQueryBuilder builderItemToSkillTree() {
//		SELECT itst._id AS _id, itst.item_id, itst.skill_tree_id,
//		itst.point_value, i.name AS iname, s.name AS sname
//		FROM item_to_skill_tree AS itst
//		LEFT OUTER JOIN items AS i ON itst.item_id = i._id
//		LEFT OUTER JOIN skill_trees AS s ON itst.skill_tree_id = s._id;
//		LEFT OUTER JOIN armor AS a ON i._id = a._id 
//		LEFT OUTER JOIN decorations AS d ON i._id = d._id;

        String itst = "itst";
        String i = "i";
        String s = "s";

        HashMap<String, String> projectionMap = new HashMap<String, String>();

        projectionMap.put("_id", itst + "." + S.COLUMN_ITEM_TO_SKILL_TREE_ID + " AS " + "_id");
        projectionMap.put(S.COLUMN_ITEM_TO_SKILL_TREE_ITEM_ID, itst + "." + S.COLUMN_ITEM_TO_SKILL_TREE_ITEM_ID);
        projectionMap.put(S.COLUMN_ITEM_TO_SKILL_TREE_SKILL_TREE_ID, itst + "." + S.COLUMN_ITEM_TO_SKILL_TREE_SKILL_TREE_ID);
        projectionMap.put(S.COLUMN_ITEM_TO_SKILL_TREE_POINT_VALUE, itst + "." + S.COLUMN_ITEM_TO_SKILL_TREE_POINT_VALUE);

        projectionMap.put(i + S.COLUMN_ITEMS_NAME, i + "." + S.COLUMN_ITEMS_NAME + " AS " + i + S.COLUMN_ITEMS_NAME);
        projectionMap.put(S.COLUMN_ITEMS_ICON_NAME, i + "." + S.COLUMN_ITEMS_ICON_NAME);
        projectionMap.put(S.COLUMN_ITEMS_TYPE, i + "." + S.COLUMN_ITEMS_TYPE);
        projectionMap.put(S.COLUMN_ITEMS_SUB_TYPE, i + "." + S.COLUMN_ITEMS_SUB_TYPE);
        projectionMap.put(S.COLUMN_ITEMS_RARITY, i + "." + S.COLUMN_ITEMS_RARITY);
        projectionMap.put(s + S.COLUMN_SKILL_TREES_NAME, s + "." + S.COLUMN_SKILL_TREES_NAME + " AS " + s + S.COLUMN_SKILL_TREES_NAME);

        //Create new querybuilder
        SQLiteQueryBuilder QB = new SQLiteQueryBuilder();

        QB.setTables(S.TABLE_ITEM_TO_SKILL_TREE + " AS itst" + " LEFT OUTER JOIN " + S.TABLE_ITEMS + " AS i" + " ON " + "itst." +
                S.COLUMN_ITEM_TO_SKILL_TREE_ITEM_ID + " = " + "i." + S.COLUMN_ITEMS_ID + " LEFT OUTER JOIN " + S.TABLE_SKILL_TREES +
                " AS s " + " ON " + "itst." + S.COLUMN_ITEM_TO_SKILL_TREE_SKILL_TREE_ID + " = " + "s." + S.COLUMN_SKILL_TREES_ID +
                " LEFT OUTER JOIN " + S.TABLE_ARMOR + " AS a" + " ON " + "i." + S.COLUMN_ITEMS_ID + " = " + "a." + S.COLUMN_ARMOR_ID +
                " LEFT OUTER JOIN " + S.TABLE_DECORATIONS + " AS d" + " ON " + "i." + S.COLUMN_ITEMS_ID + " = " + "d." +
                S.COLUMN_DECORATIONS_ID);

        QB.setProjectionMap(projectionMap);
        return QB;
    }
 
Example 8
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
private SQLiteQueryBuilder builderWeaponTreeChild() {
//		SELECT i2._id, i2.name
//		FROM items AS i1
//		LEFT OUTER JOIN components AS c ON i1._id = c.component_item_id 
//		JOIN weapons AS w2 ON w2._id = c.created_item_id 
//		LEFT OUTER JOIN items AS i2 ON i2._id = w2._id
//
//		WHERE i1._id = '_id';

        String i1 = "i1";
        String i2 = "i2";
        String w2 = "w2";
        String c = "c";

        HashMap<String, String> projectionMap = new HashMap<String, String>();

        projectionMap.put("_id", i2 + "." + S.COLUMN_ITEMS_ID + " AS " + "_id");
        projectionMap.put(S.COLUMN_ITEMS_NAME, i2 + "." + S.COLUMN_ITEMS_NAME);

        //Create new querybuilder
        SQLiteQueryBuilder QB = new SQLiteQueryBuilder();

        QB.setTables(S.TABLE_ITEMS + " AS i1" + " LEFT OUTER JOIN " + S.TABLE_COMPONENTS + " AS c" +
                        " ON " + "i1." + S.COLUMN_ITEMS_ID + " = " + "c." + S.COLUMN_COMPONENTS_COMPONENT_ITEM_ID +
                        " JOIN " + S.TABLE_WEAPONS + " AS w2" + " ON " + "w2." + S.COLUMN_WEAPONS_ID + " = " +
                        "c." + S.COLUMN_COMPONENTS_CREATED_ITEM_ID + " LEFT OUTER JOIN " + S.TABLE_ITEMS +
                        " AS i2" + " ON " + "i2." + S.COLUMN_ITEMS_ID + " = " + "w2." + S.COLUMN_WEAPONS_ID
        );

        QB.setProjectionMap(projectionMap);
        return QB;
    }
 
Example 9
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
private SQLiteQueryBuilder builderQuestReward() {
//		SELECT qr._id AS _id, qr.quest_id, qr.item_id, 
//		qr.reward_slot, qr.percentage, qr.stack_size,
//		q.name AS qname, q.hub, q.stars, i.name AS iname
//		FROM quest_rewards AS qr
//		LEFT OUTER JOIN quests AS q ON qr.quest_id = q._id
//		LEFT OUTER JOIN items AS i ON qr.item_id = i._id;

        String qr = "qr";
        String i = "i";
        String q = "q";

        HashMap<String, String> projectionMap = new HashMap<String, String>();

        projectionMap.put("_id", qr + "." + S.COLUMN_QUEST_REWARDS_ID + " AS " + "_id");
        projectionMap.put(S.COLUMN_QUEST_REWARDS_ITEM_ID, qr + "." + S.COLUMN_QUEST_REWARDS_ITEM_ID);
        projectionMap.put(S.COLUMN_QUEST_REWARDS_QUEST_ID, qr + "." + S.COLUMN_QUEST_REWARDS_QUEST_ID);
        projectionMap.put(S.COLUMN_QUEST_REWARDS_REWARD_SLOT, qr + "." + S.COLUMN_QUEST_REWARDS_REWARD_SLOT);
        projectionMap.put(S.COLUMN_QUEST_REWARDS_PERCENTAGE, qr + "." + S.COLUMN_QUEST_REWARDS_PERCENTAGE);
        projectionMap.put(S.COLUMN_QUEST_REWARDS_STACK_SIZE, qr + "." + S.COLUMN_QUEST_REWARDS_STACK_SIZE);

        projectionMap.put(i + S.COLUMN_ITEMS_NAME, i + "." + S.COLUMN_ITEMS_NAME + " AS " + i + S.COLUMN_ITEMS_NAME);
        projectionMap.put(S.COLUMN_ITEMS_ICON_NAME, i + "." + S.COLUMN_ITEMS_ICON_NAME);
        projectionMap.put(q + S.COLUMN_QUESTS_NAME, q + "." + S.COLUMN_QUESTS_NAME + " AS " + q + S.COLUMN_QUESTS_NAME);
        projectionMap.put(S.COLUMN_QUESTS_HUB, q + "." + S.COLUMN_QUESTS_HUB);
        projectionMap.put(S.COLUMN_QUESTS_STARS, q + "." + S.COLUMN_QUESTS_STARS);

        //Create new querybuilder
        SQLiteQueryBuilder QB = new SQLiteQueryBuilder();

        QB.setTables(S.TABLE_QUEST_REWARDS + " AS qr" + " LEFT OUTER JOIN " + S.TABLE_ITEMS + " AS i" + " ON " + "qr." +
                S.COLUMN_QUEST_REWARDS_ITEM_ID + " = " + "i." + S.COLUMN_ITEMS_ID + " LEFT OUTER JOIN " + S.TABLE_QUESTS +
                " AS q " + " ON " + "qr." + S.COLUMN_QUEST_REWARDS_QUEST_ID + " = " + "q." + S.COLUMN_QUESTS_ID);

        QB.setProjectionMap(projectionMap);
        return QB;
    }
 
Example 10
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
private SQLiteQueryBuilder builderMogaWoodsReward() {
//		SELECT mwr._id AS _id, mwr.monster_id, mwr.item_id,
//		mwr.time, mwr.commodity_stars, mwr.kill_percentage,
//		mwr.capture_percentage, 
//		i.name AS iname, m.name AS mname 
//		FROM moga_woods_rewards AS mwr
//		LEFT OUTER JOIN monsters AS m ON mwr.monster_id = m._id 
//		LEFT OUTER JOIN items AS i ON mwr.item_id = i._id;

        String mwr = "mwr";
        String i = "i";
        String m = "m";

        HashMap<String, String> projectionMap = new HashMap<String, String>();

        projectionMap.put("_id", mwr + "." + S.COLUMN_MOGA_WOODS_REWARDS_ID + " AS " + "_id");
        projectionMap.put(S.COLUMN_MOGA_WOODS_REWARDS_ITEM_ID, mwr + "." + S.COLUMN_MOGA_WOODS_REWARDS_ITEM_ID);
        projectionMap.put(S.COLUMN_MOGA_WOODS_REWARDS_MONSTER_ID, mwr + "." + S.COLUMN_MOGA_WOODS_REWARDS_MONSTER_ID);
        projectionMap.put(S.COLUMN_MOGA_WOODS_REWARDS_TIME, mwr + "." + S.COLUMN_MOGA_WOODS_REWARDS_TIME);
        projectionMap.put(S.COLUMN_MOGA_WOODS_REWARDS_COMMODITY_STARS, mwr + "." + S.COLUMN_MOGA_WOODS_REWARDS_COMMODITY_STARS);
        projectionMap.put(S.COLUMN_MOGA_WOODS_REWARDS_KILL_PERCENTAGE, mwr + "." + S.COLUMN_MOGA_WOODS_REWARDS_KILL_PERCENTAGE);
        projectionMap.put(S.COLUMN_MOGA_WOODS_REWARDS_CAPTURE_PERCENTAGE, mwr + "." + S.COLUMN_MOGA_WOODS_REWARDS_CAPTURE_PERCENTAGE);

        projectionMap.put(i + S.COLUMN_ITEMS_NAME, i + "." + S.COLUMN_ITEMS_NAME + " AS " + i + S.COLUMN_ITEMS_NAME);
        projectionMap.put(i + S.COLUMN_ITEMS_ICON_NAME, i + "." + S.COLUMN_ITEMS_ICON_NAME + " AS " + i + S.COLUMN_ITEMS_ICON_NAME);
        projectionMap.put(m + S.COLUMN_MONSTERS_NAME, m + "." + S.COLUMN_MONSTERS_NAME + " AS " + m + S.COLUMN_MONSTERS_NAME);
        projectionMap.put(m + S.COLUMN_MONSTERS_FILE_LOCATION, m + "." + S.COLUMN_MONSTERS_FILE_LOCATION + " AS " + m + S.COLUMN_MONSTERS_FILE_LOCATION);

        //Create new querybuilder
        SQLiteQueryBuilder QB = new SQLiteQueryBuilder();

        QB.setTables(S.TABLE_MOGA_WOODS_REWARDS + " AS mwr" + " LEFT OUTER JOIN " + S.TABLE_ITEMS + " AS i" + " ON " + "mwr." +
                S.COLUMN_MOGA_WOODS_REWARDS_ITEM_ID + " = " + "i." + S.COLUMN_ITEMS_ID + " LEFT OUTER JOIN " + S.TABLE_MONSTERS +
                " AS m " + " ON " + "mwr." + S.COLUMN_MOGA_WOODS_REWARDS_MONSTER_ID + " = " + "m." + S.COLUMN_MONSTERS_ID);

        QB.setProjectionMap(projectionMap);
        return QB;
    }
 
Example 11
Source File: LoaderThrottle.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Handle incoming queries.
 */
@Override
public Cursor query(Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {

    // Constructs a new query builder and sets its table name
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(MainTable.TABLE_NAME);

    switch (mUriMatcher.match(uri)) {
        case MAIN:
            // If the incoming URI is for main table.
            qb.setProjectionMap(mNotesProjectionMap);
            break;

        case MAIN_ID:
            // The incoming URI is for a single row.
            qb.setProjectionMap(mNotesProjectionMap);
            qb.appendWhere(MainTable._ID + "=?");
            selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
                    new String[] { uri.getLastPathSegment() });
            break;

        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
    }


    if (TextUtils.isEmpty(sortOrder)) {
        sortOrder = MainTable.DEFAULT_SORT_ORDER;
    }

    SQLiteDatabase db = mOpenHelper.getReadableDatabase();

    Cursor c = qb.query(db, projection, selection, selectionArgs,
            null /* no group */, null /* no filter */, sortOrder);

    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}
 
Example 12
Source File: CityProvider.java    From sms-ticket with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    switch (sUriMatcher.match(uri)) {
        case CITIES:
            qb.setTables(DatabaseHelper.CITY_TABLE_NAME);
            qb.setProjectionMap(sProjectionMap);
            break;
        case CITY_ID:
            qb.setTables(DatabaseHelper.CITY_TABLE_NAME);
            qb.setProjectionMap(sProjectionMap);
            qb.appendWhere(Cities._ID + "=" + uri.getPathSegments().get(1));
            break;
        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
    }

    // If no sort order is specified use the default
    String orderBy;
    if (TextUtils.isEmpty(sortOrder)) {
        orderBy = Cities.DEFAULT_SORT_ORDER;
    } else {
        orderBy = sortOrder;
    }

    // Get the database and run the query
    SQLiteDatabase db = DatabaseHelper.get(getContext()).getReadableDatabase();
    Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);

    // Tell the cursor what uri to watch, so it knows when its source data changes
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}
 
Example 13
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
private SQLiteQueryBuilder builderGathering() {
//		SELECT g._id AS _id, g.item_id, g.location_id, g.area,
//		g.site, g.site_set, g.site_set_percentage,
//		g.site_set_gathers_min, g.site_set_gathers_max, g.rank,
//		g.percentage, i.name AS iname, l.name AS lname
//		FROM gathering AS g
//		LEFT OUTER JOIN items AS i ON g.item_id = i._id
//		LEFT OUTER JOIN locations AS l on g.location_id = l._id;

        String g = "g";
        String i = "i";
        String l = "l";

        HashMap<String, String> projectionMap = new HashMap<String, String>();

        projectionMap.put("_id", g + "." + S.COLUMN_GATHERING_ID + " AS " + "_id");
        projectionMap.put(S.COLUMN_GATHERING_ITEM_ID, g + "." + S.COLUMN_GATHERING_ITEM_ID);
        projectionMap.put(S.COLUMN_GATHERING_LOCATION_ID, g + "." + S.COLUMN_GATHERING_LOCATION_ID);
        projectionMap.put(S.COLUMN_GATHERING_AREA, g + "." + S.COLUMN_GATHERING_AREA);
        projectionMap.put(S.COLUMN_GATHERING_SITE, g + "." + S.COLUMN_GATHERING_SITE);
        projectionMap.put(S.COLUMN_GATHERING_RANK, g + "." + S.COLUMN_GATHERING_RANK);
        projectionMap.put(S.COLUMN_GATHERING_RATE, g + "." + S.COLUMN_GATHERING_RATE);

        projectionMap.put(i + S.COLUMN_ITEMS_NAME, i + "." + S.COLUMN_ITEMS_NAME + " AS " + i + S.COLUMN_ITEMS_NAME);
        projectionMap.put(S.COLUMN_ITEMS_ICON_NAME, i + "." + S.COLUMN_ITEMS_ICON_NAME);
        projectionMap.put(l + S.COLUMN_LOCATIONS_NAME, l + "." + S.COLUMN_LOCATIONS_NAME + " AS " + l + S.COLUMN_LOCATIONS_NAME);
        projectionMap.put(l + S.COLUMN_LOCATIONS_MAP, l + "." + S.COLUMN_LOCATIONS_MAP + " AS " + l + S.COLUMN_LOCATIONS_MAP);

        //Create new querybuilder
        SQLiteQueryBuilder QB = new SQLiteQueryBuilder();

        QB.setTables(S.TABLE_GATHERING + " AS g" + " LEFT OUTER JOIN " + S.TABLE_ITEMS + " AS i" + " ON " + "g." +
                S.COLUMN_GATHERING_ITEM_ID + " = " + "i." + S.COLUMN_ITEMS_ID + " LEFT OUTER JOIN " + S.TABLE_LOCATIONS +
                " AS l " + " ON " + "g." + S.COLUMN_GATHERING_LOCATION_ID + " = " + "l." + S.COLUMN_LOCATIONS_ID);

        QB.setProjectionMap(projectionMap);
        return QB;
    }
 
Example 14
Source File: RosterGroupManager.java    From yiim_v2 with GNU General Public License v2.0 5 votes vote down vote up
public Cursor query(SQLiteDatabase db, int type, Uri uri,
		String[] projection, String selection, String[] selectionArgs,
		String sortOrder) {

	SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
	qb.setTables(TABLE_NAME);

	if (type == UriType.ROSTER_GROUP.getCode()) {
		qb.setProjectionMap(mProjectionMap);
	} else if (type == UriType.ROSTER_GROUP_ID.getCode()) {
		qb.setProjectionMap(mProjectionMap);
		qb.appendWhere(RosterGroupColumns._ID + "="
				+ uri.getPathSegments().get(1));
	} else if (type == UriType.LIVE_FOLDER_ROSTER_GROUP.getCode()) {
		qb.setProjectionMap(mLiveFolderProjectionMap);
	} else {
		throw new IllegalArgumentException("Unknown URI " + uri);
	}

	// If no sort order is specified use the default
	String orderBy;
	if (TextUtils.isEmpty(sortOrder)) {
		orderBy = RosterGroupColumns.DEFAULT_SORT_ORDER;
	} else {
		orderBy = sortOrder;
	}

	// Get the database and run the query
	Cursor c = qb.query(db, projection, selection, selectionArgs, null,
			null, orderBy);

	return c;
}
 
Example 15
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
private SQLiteQueryBuilder builderHabitat(boolean Distinct) {
    String h = "h";
    String m = "m";
    String l = "l";

    HashMap<String, String> projectionMap = new HashMap<String, String>();

    projectionMap.put("_id", h + "." + S.COLUMN_HABITAT_ID + " AS " + "_id");
    projectionMap.put("start_area", h + "." + S.COLUMN_HABITAT_START + " AS " + "start_area");
    projectionMap.put("move_area", h + "." + S.COLUMN_HABITAT_AREAS + " AS " + "move_area");
    projectionMap.put("rest_area", h + "." + S.COLUMN_HABITAT_REST + " AS " + "rest_area");

    projectionMap.put(l + S.COLUMN_LOCATIONS_ID, l + "." + S.COLUMN_LOCATIONS_ID + " AS " + l + S.COLUMN_LOCATIONS_ID);
    projectionMap.put(l + S.COLUMN_LOCATIONS_NAME, l + "." + S.COLUMN_LOCATIONS_NAME + " AS " + l + S.COLUMN_LOCATIONS_NAME);
    projectionMap.put(l + S.COLUMN_LOCATIONS_MAP, l + "." + S.COLUMN_LOCATIONS_MAP + " AS " + l + S.COLUMN_LOCATIONS_MAP);

    projectionMap.put(m + S.COLUMN_MONSTERS_ID, m + "." + S.COLUMN_MONSTERS_ID + " AS " + m + S.COLUMN_MONSTERS_ID);
    projectionMap.put(m + S.COLUMN_MONSTERS_SORT_NAME, m + "." + S.COLUMN_MONSTERS_SORT_NAME + " AS " + m + S.COLUMN_MONSTERS_SORT_NAME);
    projectionMap.put(m + S.COLUMN_MONSTERS_NAME, m + "." + S.COLUMN_MONSTERS_NAME + " AS " + m + S.COLUMN_MONSTERS_NAME);
    projectionMap.put(m + S.COLUMN_MONSTERS_CLASS, m + "." + S.COLUMN_MONSTERS_CLASS + " AS " + m + S.COLUMN_MONSTERS_CLASS);
    projectionMap.put(m + S.COLUMN_MONSTERS_FILE_LOCATION, m + "." + S.COLUMN_MONSTERS_FILE_LOCATION + " AS " + m + S.COLUMN_MONSTERS_FILE_LOCATION);

    //Create new querybuilder
    SQLiteQueryBuilder QB = new SQLiteQueryBuilder();

    QB.setTables(S.TABLE_HABITAT + " AS h" + " LEFT OUTER JOIN " + S.TABLE_MONSTERS + " AS m" + " ON " + "h." +
            S.COLUMN_HABITAT_MONSTER_ID + " = " + "m." + S.COLUMN_MONSTERS_ID + " LEFT OUTER JOIN " + S.TABLE_LOCATIONS +
            " AS l " + " ON " + "h." + S.COLUMN_HABITAT_LOCATION_ID + " = " + "l." + S.COLUMN_LOCATIONS_ID);

    QB.setDistinct(Distinct);
    QB.setProjectionMap(projectionMap);
    return QB;
}
 
Example 16
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
private SQLiteQueryBuilder builderMonsterToQuest(boolean Distinct) {
//		SELECT mtq._id AS _id, mtq.monster_id, mtq.quest_id,
//		mtq.unstable, m.name AS mname, q.name AS qname,
//		q.hub, q.stars
//		FROM monster_to_quest AS mtq
//		LEFT OUTER JOIN monsters AS m ON mtq.monster_id = m._id
//		LEFT OUTER JOIN quests AS q ON mtq.quest_id = q._id;

        String mtq = "mtq";
        String m = "m";
        String q = "q";

        HashMap<String, String> projectionMap = new HashMap<String, String>();

        projectionMap.put("_id", mtq + "." + S.COLUMN_MONSTER_TO_QUEST_ID + " AS " + "_id");

        projectionMap.put(S.COLUMN_MONSTER_TO_QUEST_MONSTER_ID, mtq + "." + S.COLUMN_MONSTER_TO_QUEST_MONSTER_ID);
        projectionMap.put(S.COLUMN_MONSTER_TO_QUEST_QUEST_ID, mtq + "." + S.COLUMN_MONSTER_TO_QUEST_QUEST_ID);
        projectionMap.put(S.COLUMN_MONSTER_TO_QUEST_UNSTABLE, mtq + "." + S.COLUMN_MONSTER_TO_QUEST_UNSTABLE);

        projectionMap.put(m + S.COLUMN_MONSTERS_NAME, m + "." + S.COLUMN_MONSTERS_NAME + " AS " + m + S.COLUMN_MONSTERS_NAME);
        projectionMap.put(S.COLUMN_MONSTERS_TRAIT, m + "." + S.COLUMN_MONSTERS_TRAIT);
        projectionMap.put(S.COLUMN_MONSTERS_FILE_LOCATION, m + "." + S.COLUMN_MONSTERS_FILE_LOCATION);
        projectionMap.put(q + S.COLUMN_QUESTS_NAME, q + "." + S.COLUMN_QUESTS_NAME + " AS " + q + S.COLUMN_QUESTS_NAME);
        projectionMap.put(S.COLUMN_QUESTS_HUB, q + "." + S.COLUMN_QUESTS_HUB);
        projectionMap.put(S.COLUMN_QUESTS_STARS, q + "." + S.COLUMN_QUESTS_STARS);

        //Create new querybuilder
        SQLiteQueryBuilder QB = new SQLiteQueryBuilder();

        QB.setTables(S.TABLE_MONSTER_TO_QUEST + " AS mtq" + " LEFT OUTER JOIN " + S.TABLE_MONSTERS + " AS m" + " ON " + "mtq." +
                S.COLUMN_MONSTER_TO_QUEST_MONSTER_ID + " = " + "m." + S.COLUMN_MONSTERS_ID + " LEFT OUTER JOIN " + S.TABLE_QUESTS +
                " AS q " + " ON " + "mtq." + S.COLUMN_MONSTER_TO_QUEST_QUEST_ID + " = " + "q." + S.COLUMN_QUESTS_ID);

        QB.setDistinct(Distinct);
        QB.setProjectionMap(projectionMap);
        return QB;
    }
 
Example 17
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 4 votes vote down vote up
private SQLiteQueryBuilder builderWeapon() {
//		SELECT w._id AS _id, w.wtype, w.creation_cost, w.upgrade_cost, w.attack, w.max_attack,
//		w.elemental_attack, w.awakened_elemental_attack, w.defense, w.sharpness, w.affinity,
//		w.horn_notes, w.shelling_type, w.charge_levels, w.allowed_coatings, w.recoil, w.reload_speed,
//		w.rapid_fire, w.normal_shots, w.status_shots, w.elemental_shots, w.tool_shots, w.num_slots,
//		w.sharpness_file, 
//		i.name, i.jpn_name, i.type, i.rarity, i.carry_capacity, i.buy, i.sell, i.description,
//		i.icon_name, i.armor_dupe_name_fix, w.special_ammo
//		FROM weapons AS w LEFT OUTER JOIN	items AS i ON w._id = i._id;

        String w = "w";
        String i = "i";

        HashMap<String, String> projectionMap = new HashMap<String, String>();

        projectionMap.put("_id", w + "." + S.COLUMN_WEAPONS_ID + " AS " + "_id");
        projectionMap.put(S.COLUMN_WEAPONS_WTYPE, w + "." + S.COLUMN_WEAPONS_WTYPE);
        projectionMap.put(S.COLUMN_WEAPONS_CREATION_COST, w + "." + S.COLUMN_WEAPONS_CREATION_COST);
        projectionMap.put(S.COLUMN_WEAPONS_UPGRADE_COST, w + "." + S.COLUMN_WEAPONS_UPGRADE_COST);
        projectionMap.put(S.COLUMN_WEAPONS_ATTACK, w + "." + S.COLUMN_WEAPONS_ATTACK);
        projectionMap.put(S.COLUMN_WEAPONS_MAX_ATTACK, w + "." + S.COLUMN_WEAPONS_MAX_ATTACK);
        projectionMap.put(S.COLUMN_WEAPONS_ELEMENT, w + "." + S.COLUMN_WEAPONS_ELEMENT);
        projectionMap.put(S.COLUMN_WEAPONS_AWAKEN, w + "." + S.COLUMN_WEAPONS_AWAKEN);
        projectionMap.put(S.COLUMN_WEAPONS_ELEMENT_2, w + "." + S.COLUMN_WEAPONS_ELEMENT_2);
        projectionMap.put(S.COLUMN_WEAPONS_AWAKEN_ATTACK, w + "." + S.COLUMN_WEAPONS_AWAKEN_ATTACK);
        projectionMap.put(S.COLUMN_WEAPONS_ELEMENT_ATTACK, w + "." + S.COLUMN_WEAPONS_ELEMENT_ATTACK);
        projectionMap.put(S.COLUMN_WEAPONS_ELEMENT_2_ATTACK, w + "." + S.COLUMN_WEAPONS_ELEMENT_2_ATTACK);
		projectionMap.put(S.COLUMN_WEAPONS_DEFENSE, w + "." + S.COLUMN_WEAPONS_DEFENSE);
		projectionMap.put(S.COLUMN_WEAPONS_SHARPNESS, w + "." + S.COLUMN_WEAPONS_SHARPNESS);
		projectionMap.put(S.COLUMN_WEAPONS_AFFINITY, w + "." + S.COLUMN_WEAPONS_AFFINITY);
		projectionMap.put(S.COLUMN_WEAPONS_HORN_NOTES, w + "." + S.COLUMN_WEAPONS_HORN_NOTES);
		projectionMap.put(S.COLUMN_WEAPONS_SHELLING_TYPE, w + "." + S.COLUMN_WEAPONS_SHELLING_TYPE);
		projectionMap.put(S.COLUMN_WEAPONS_PHIAL, w + "." + S.COLUMN_WEAPONS_PHIAL);
		projectionMap.put(S.COLUMN_WEAPONS_CHARGES, w + "." + S.COLUMN_WEAPONS_CHARGES);
		projectionMap.put(S.COLUMN_WEAPONS_COATINGS, w + "." + S.COLUMN_WEAPONS_COATINGS);
		projectionMap.put(S.COLUMN_WEAPONS_RECOIL, w + "." + S.COLUMN_WEAPONS_RECOIL);
		projectionMap.put(S.COLUMN_WEAPONS_RELOAD_SPEED, w + "." + S.COLUMN_WEAPONS_RELOAD_SPEED);
		projectionMap.put(S.COLUMN_WEAPONS_RAPID_FIRE, w + "." + S.COLUMN_WEAPONS_RAPID_FIRE);
		projectionMap.put(S.COLUMN_WEAPONS_DEVIATION, w + "." + S.COLUMN_WEAPONS_DEVIATION);
		projectionMap.put(S.COLUMN_WEAPONS_AMMO, w + "." + S.COLUMN_WEAPONS_AMMO);
		projectionMap.put(S.COLUMN_WEAPONS_NUM_SLOTS, w + "." + S.COLUMN_WEAPONS_NUM_SLOTS);
		projectionMap.put(S.COLUMN_WEAPONS_FINAL, w + "." + S.COLUMN_WEAPONS_FINAL);
        projectionMap.put(S.COLUMN_WEAPONS_TREE_DEPTH, w + "." + S.COLUMN_WEAPONS_TREE_DEPTH);
        projectionMap.put(S.COLUMN_WEAPONS_PARENT_ID, w + "." + S.COLUMN_WEAPONS_PARENT_ID);
        projectionMap.put(S.COLUMN_WEAPONS_SPECIAL_AMMO, w + "." + S.COLUMN_WEAPONS_SPECIAL_AMMO);

        projectionMap.put(S.COLUMN_ITEMS_NAME, i + "." + S.COLUMN_ITEMS_NAME);
        projectionMap.put(S.COLUMN_ITEMS_JPN_NAME, i + "." + S.COLUMN_ITEMS_JPN_NAME);
        projectionMap.put(S.COLUMN_ITEMS_TYPE, i + "." + S.COLUMN_ITEMS_TYPE);
        projectionMap.put(S.COLUMN_ITEMS_SUB_TYPE, i + "." + S.COLUMN_ITEMS_SUB_TYPE);
        projectionMap.put(S.COLUMN_ITEMS_RARITY, i + "." + S.COLUMN_ITEMS_RARITY);
        projectionMap.put(S.COLUMN_ITEMS_CARRY_CAPACITY, i + "." + S.COLUMN_ITEMS_CARRY_CAPACITY);
        projectionMap.put(S.COLUMN_ITEMS_BUY, i + "." + S.COLUMN_ITEMS_BUY);
        projectionMap.put(S.COLUMN_ITEMS_SELL, i + "." + S.COLUMN_ITEMS_SELL);
        projectionMap.put(S.COLUMN_ITEMS_DESCRIPTION, i + "." + S.COLUMN_ITEMS_DESCRIPTION);
        projectionMap.put(S.COLUMN_ITEMS_ICON_NAME, i + "." + S.COLUMN_ITEMS_ICON_NAME);
        projectionMap.put(S.COLUMN_ITEMS_ARMOR_DUPE_NAME_FIX, i + "." + S.COLUMN_ITEMS_ARMOR_DUPE_NAME_FIX);

        //Create new querybuilder
        SQLiteQueryBuilder QB = new SQLiteQueryBuilder();

        QB.setTables(S.TABLE_WEAPONS + " AS w" + " LEFT OUTER JOIN " + S.TABLE_ITEMS + " AS i" + " ON " + "w." +
                S.COLUMN_WEAPONS_ID + " = " + "i." + S.COLUMN_ITEMS_ID);

        QB.setProjectionMap(projectionMap);
        return QB;
    }
 
Example 18
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 4 votes vote down vote up
private SQLiteQueryBuilder builderDecoration() {
//		 SELECT i._id AS item_id, i.name, i.jpn_name, i.type, i.rarity, i.carry_capacity, i.buy, i.sell, i.description, 
//		 i.icon_name, i.armor_dupe_name_fix, d.num_slots, s1._id AS skill_1_id, s1.name AS skill_1_name, its1.point_value 
//		 AS skill_1_point, s2._id AS skill_1_id, s2.name AS skill_2_name, its2.point_value AS skill_2_point
//		 FROM decorations AS d LEFT OUTER JOIN items AS i ON d._id = i._id
//		 LEFT OUTER JOIN item_to_skill_tree AS its1 ON i._id = its1.item_id and its1.point_value > 0
//		 LEFT OUTER JOIN skill_trees AS s1 ON its1.skill_tree_id = s1._id
//		 LEFT OUTER JOIN item_to_skill_tree AS its2 ON i._id = its2.item_id and s1._id != its2.skill_tree_id
//		 LEFT OUTER JOIN skill_trees AS s2 ON its2.skill_tree_id = s2._id;

        HashMap<String, String> projectionMap = new HashMap<String, String>();
        projectionMap.put("_id", "i." + S.COLUMN_ITEMS_ID + " AS " + "_id");
        projectionMap.put("item_name", "i." + S.COLUMN_ITEMS_NAME + " AS " + "item_name");
        projectionMap.put(S.COLUMN_ITEMS_JPN_NAME, "i." + S.COLUMN_ITEMS_JPN_NAME);
        projectionMap.put(S.COLUMN_ITEMS_TYPE, "i." + S.COLUMN_ITEMS_TYPE);
        projectionMap.put(S.COLUMN_ITEMS_SUB_TYPE, "i." + S.COLUMN_ITEMS_SUB_TYPE);
        projectionMap.put(S.COLUMN_ITEMS_RARITY, "i." + S.COLUMN_ITEMS_RARITY);
        projectionMap.put(S.COLUMN_ITEMS_CARRY_CAPACITY, "i." + S.COLUMN_ITEMS_CARRY_CAPACITY);
        projectionMap.put(S.COLUMN_ITEMS_BUY, "i." + S.COLUMN_ITEMS_BUY);
        projectionMap.put(S.COLUMN_ITEMS_SELL, "i." + S.COLUMN_ITEMS_SELL);
        projectionMap.put(S.COLUMN_ITEMS_DESCRIPTION, "i." + S.COLUMN_ITEMS_DESCRIPTION);
        projectionMap.put(S.COLUMN_ITEMS_ICON_NAME, "i." + S.COLUMN_ITEMS_ICON_NAME);
        projectionMap.put(S.COLUMN_ITEMS_ARMOR_DUPE_NAME_FIX, "i." + S.COLUMN_ITEMS_ARMOR_DUPE_NAME_FIX);
        projectionMap.put(S.COLUMN_DECORATIONS_NUM_SLOTS, "d." + S.COLUMN_DECORATIONS_NUM_SLOTS);
        projectionMap.put("skill_1_id", "s1." + S.COLUMN_SKILL_TREES_ID + " AS " + "skill_1_id");
        projectionMap.put("skill_1_name", "s1." + S.COLUMN_SKILL_TREES_NAME + " AS " + "skill_1_name");
        projectionMap.put("skill_1_point_value", "its1." + S.COLUMN_ITEM_TO_SKILL_TREE_POINT_VALUE + " AS " + "skill_1_point_value");
        projectionMap.put("skill_2_id", "s2." + S.COLUMN_SKILL_TREES_ID + " AS " + "skill_2_id");
        projectionMap.put("skill_2_name", "s2." + S.COLUMN_SKILL_TREES_NAME + " AS " + "skill_2_name");
        projectionMap.put("skill_2_point_value", "its2." + S.COLUMN_ITEM_TO_SKILL_TREE_POINT_VALUE + " AS " + "skill_2_point_value");

        //Create new querybuilder
        SQLiteQueryBuilder QB = new SQLiteQueryBuilder();

        QB.setTables(S.TABLE_DECORATIONS + " AS d" + " LEFT OUTER JOIN " + S.TABLE_ITEMS + " AS i" + " ON " + "d." +
                S.COLUMN_DECORATIONS_ID + " = " + "i." + S.COLUMN_ITEMS_ID + " LEFT OUTER JOIN " + S.TABLE_ITEM_TO_SKILL_TREE +
                " AS its1 " + " ON " + "i." + S.COLUMN_ITEMS_ID + " = " + "its1." + S.COLUMN_ITEM_TO_SKILL_TREE_ITEM_ID + " AND " +
                "its1." + S.COLUMN_ITEM_TO_SKILL_TREE_POINT_VALUE + " > 0 " + " LEFT OUTER JOIN " + S.TABLE_SKILL_TREES + " AS s1" +
                " ON " + "its1." + S.COLUMN_ITEM_TO_SKILL_TREE_SKILL_TREE_ID + " = " + "s1." + S.COLUMN_SKILL_TREES_ID +
                " LEFT OUTER JOIN " + S.TABLE_ITEM_TO_SKILL_TREE + " AS its2 " + " ON " + "i." + S.COLUMN_ITEMS_ID + " = " +
                "its2." + S.COLUMN_ITEM_TO_SKILL_TREE_ITEM_ID + " AND " + "s1." + S.COLUMN_SKILL_TREES_ID + " != " +
                "its2." + S.COLUMN_ITEM_TO_SKILL_TREE_SKILL_TREE_ID + " LEFT OUTER JOIN " + S.TABLE_SKILL_TREES + " AS s2" +
                " ON " + "its2." + S.COLUMN_ITEM_TO_SKILL_TREE_SKILL_TREE_ID + " = " + "s2." + S.COLUMN_SKILL_TREES_ID);

        QB.setProjectionMap(projectionMap);
        return QB;
    }
 
Example 19
Source File: CapturedPlayerFriendProvider.java    From PADListener with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
	MyLog.entry("uri = " + uri);

	final SQLiteDatabase db = getDbHelper().getReadableDatabase();
	final CapturedPlayerFriendDescriptor.Paths path = CapturedPlayerFriendDescriptor.matchUri(uri);

	final SQLiteQueryBuilder builder = new SQLiteQueryBuilder();

	switch (path) {
		case ALL:
			builder.setTables(CapturedPlayerFriendDescriptor.TABLE_NAME);
			break;
		case ALL_WITH_INFO:
			final Map<String, String> columnMap = new HashMap<String, String>();
			fillColumnMapWithPrefix(columnMap, CapturedPlayerFriendDescriptor.TABLE_NAME, "", CapturedPlayerFriendDescriptor.Fields.values());

			final StringBuilder tableBuilder = new StringBuilder(CapturedPlayerFriendDescriptor.TABLE_NAME);

			final String leader1TableAlias = "L1";
			fillColumnMapWithPrefix(columnMap, leader1TableAlias, CapturedPlayerFriendDescriptor.ALL_WITH_INFO_LEADER1_PREFIX, CapturedPlayerFriendLeaderDescriptor.Fields.values());
			tableBuilder.append(" LEFT OUTER JOIN ").append(CapturedPlayerFriendLeaderDescriptor.TABLE_NAME).append(" ").append(leader1TableAlias);
			tableBuilder.append(" ON ");
			tableBuilder.append(CapturedPlayerFriendDescriptor.TABLE_NAME).append(".").append(CapturedPlayerFriendDescriptor.Fields.LEADER1_ID.getColName());
			tableBuilder.append(" = ");
			tableBuilder.append(leader1TableAlias).append(".").append(CapturedPlayerFriendLeaderDescriptor.Fields._ID.getColName());
			tableBuilder.append("");

			final String leader1InfoTableAlias = "L1_INFO";
			fillColumnMapWithPrefix(columnMap, leader1InfoTableAlias, CapturedPlayerFriendDescriptor.ALL_WITH_INFO_LEADER1_INFO_PREFIX, MonsterInfoDescriptor.Fields.values());
			tableBuilder.append(" LEFT OUTER JOIN ").append(MonsterInfoDescriptor.TABLE_NAME).append(" ").append(leader1InfoTableAlias);
			tableBuilder.append(" ON ");
			tableBuilder.append(leader1TableAlias).append(".").append(CapturedPlayerFriendLeaderDescriptor.Fields.ID_JP.getColName());
			tableBuilder.append(" = ");
			tableBuilder.append(leader1InfoTableAlias).append(".").append(MonsterInfoDescriptor.Fields.ID_JP.getColName());
			tableBuilder.append("");

			final String leader2TableAlias = "L2";
			fillColumnMapWithPrefix(columnMap, leader2TableAlias, CapturedPlayerFriendDescriptor.ALL_WITH_INFO_LEADER2_PREFIX, CapturedPlayerFriendLeaderDescriptor.Fields.values());
			tableBuilder.append(" LEFT OUTER JOIN ").append(CapturedPlayerFriendLeaderDescriptor.TABLE_NAME).append(" ").append(leader2TableAlias);
			tableBuilder.append(" ON ");
			tableBuilder.append(CapturedPlayerFriendDescriptor.TABLE_NAME).append(".").append(CapturedPlayerFriendDescriptor.Fields.LEADER2_ID.getColName());
			tableBuilder.append(" = ");
			tableBuilder.append(leader2TableAlias).append(".").append(CapturedPlayerFriendLeaderDescriptor.Fields._ID.getColName());
			tableBuilder.append("");

			final String leader2InfoTableAlias = "L2_INFO";
			fillColumnMapWithPrefix(columnMap, leader2InfoTableAlias, CapturedPlayerFriendDescriptor.ALL_WITH_INFO_LEADER2_INFO_PREFIX, MonsterInfoDescriptor.Fields.values());
			tableBuilder.append(" LEFT OUTER JOIN ").append(MonsterInfoDescriptor.TABLE_NAME).append(" ").append(leader2InfoTableAlias);
			tableBuilder.append(" ON ");
			tableBuilder.append(leader2TableAlias).append(".").append(CapturedPlayerFriendLeaderDescriptor.Fields.ID_JP.getColName());
			tableBuilder.append(" = ");
			tableBuilder.append(leader2InfoTableAlias).append(".").append(MonsterInfoDescriptor.Fields.ID_JP.getColName());
			tableBuilder.append("");

			builder.setTables(tableBuilder.toString());
			builder.setProjectionMap(columnMap);
			break;
		default:
			throw new IllegalArgumentException("Unknown URI " + uri);
	}

	final Cursor cursor = builder.query(db, projection, selection, null, null, null, sortOrder);
	cursor.setNotificationUri(getContext().getContentResolver(), uri);

	MyLog.exit();
	return cursor;
}
 
Example 20
Source File: DevicesProvider.java    From device-database with Apache License 2.0 4 votes vote down vote up
@Override
public Cursor query(@NonNull Uri uri,
                    String[] projection,
                    String selection,
                    String[] selectionArgs,
                    String sortOrder) throws IllegalArgumentException {
    Cursor cursor;
    if (projection == null) {
        throw new IllegalArgumentException("Projection can't be null");
    }

    sortOrder = (sortOrder == null ? BaseColumns._ID : sortOrder);

    SQLiteDatabase database = helper.getReadableDatabase();

    final int code = URI_MATCHER.match(uri);
    switch (code) {
        case CODE_ALL_DEVICES:
        case CODE_ALL_MANUFACTURERS:
            cursor = database.query(URI_CODE_TABLE_MAP.get(code),
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
            break;
        case CODE_DEVICE_ID:
        case CODE_MANUFACTURER_ID:
            if (selection == null) {
                selection = BaseColumns._ID
                        + " = "
                        + uri.getLastPathSegment();
            } else {
                throw new IllegalArgumentException("Selection must " +
                        "be null when specifying ID as part of uri.");
            }
            cursor = database.query(URI_CODE_TABLE_MAP.get(code),
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
            break;
        case CODE_DEVICE_MANUFACTURER:
            SQLiteQueryBuilder builder = new SQLiteQueryBuilder();

            builder.setTables(String
                    .format("%s INNER JOIN %s ON (%s.%s=%s.%s)",
                    DevicesOpenHelper.Tables.DEVICE,
                    DevicesOpenHelper.Tables.MANUFACTURER,
                    DevicesOpenHelper.Tables.DEVICE,
                    DevicesContract.Device.MANUFACTURER_ID,
                    DevicesOpenHelper.Tables.MANUFACTURER,
                    DevicesContract.Manufacturer._ID));

            final Map<String, String> projectionMap = new HashMap<>();
            projectionMap.put(DevicesContract.DeviceManufacturer.MODEL,
                    DevicesContract.DeviceManufacturer.MODEL);

            projectionMap
                    .put(DevicesContract.DeviceManufacturer.SHORT_NAME,
                    DevicesContract.DeviceManufacturer.SHORT_NAME);

            projectionMap
                    .put(DevicesContract.DeviceManufacturer.DEVICE_ID,
                    String.format("%s.%s AS %s",
                            DevicesOpenHelper.Tables.DEVICE,
                            DevicesContract.Device._ID,
                            DevicesContract.DeviceManufacturer.DEVICE_ID));

            projectionMap.put(DevicesContract
                    .DeviceManufacturer.MANUFACTURER_ID,
                    String.format("%s.%s AS %s",
                            DevicesOpenHelper.Tables.MANUFACTURER,
                            DevicesContract.Manufacturer._ID,
                            DevicesContract
                                    .DeviceManufacturer.MANUFACTURER_ID));

            builder.setProjectionMap(projectionMap);

            cursor = builder.query(database,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);

            break;
        default:
            throw new IllegalArgumentException("Invalid Uri: " + uri);
    }

    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}