Java Code Examples for android.database.sqlite.SQLiteQueryBuilder

The following examples show how to use android.database.sqlite.SQLiteQueryBuilder. These examples are extracted from open source projects. 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
private void removeItem(final String itemId) {
    final SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(DatabaseHelper.TABLE_NAME_ITEMS);
    builder.appendWhere(Item.Columns._ID + " = ?"); //We use ? to avoid SQL Injection.
    final String[] selectionArgs = {itemId}; //TODO: locale-independent?
    final Cursor c = builder.query(getDb(), PROJECTION_REMOVE_ITEM,
            null, selectionArgs,
            null, null, null);

    final String[] imageUris = new String[3];
    if (c.moveToFirst()) {
        imageUris[0] = c.getString(0);
        imageUris[1] = c.getString(1);
        imageUris[2] = c.getString(2);
    }

    c.close();

    removeItem(itemId, imageUris);
}
 
Example 2
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
	MyLog.entry("uri = " + uri);

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

	final SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
	builder.setTables(CapturedPlayerInfoDescriptor.TABLE_NAME);

	switch (path) {
		case ALL:
			break;
		default:
			throw new IllegalArgumentException("Unknown URI " + uri);
	}

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

	MyLog.exit();
	return cursor;
}
 
Example 3
@Override
public Cursor query(Uri uri, String[] strings, String s, String[] strings1, String s1) {
    switch (sUriMatcher.match(uri)) {
        case 1:
            s1 = (TextUtils.isEmpty(s1)) ? BaseColumns._ID + " _ASC" : s1;
            break;
        case 2:
            s = s + BaseColumns._ID + " = " + uri.getLastPathSegment();
    }
    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(TABLE);
    Cursor c = qb.query(db, strings, s, strings1, null, null,
            s1);
    return c;
}
 
Example 4
/**
    * ****************************** WISHLIST COMPONENT QUERIES *****************************************
    */

/*
 * Get all wishlist components
 */
   public WishlistComponentCursor queryWishlistsComponent() {

       QueryHelper qh = new QueryHelper();
       qh.Distinct = false;
       qh.Table = S.TABLE_WISHLIST_COMPONENT;
       qh.Columns = null;
       qh.Selection = null;
       qh.SelectionArgs = null;
       qh.GroupBy = null;
       qh.Having = null;
       qh.OrderBy = null;
       qh.Limit = null;

       // Multithread issues workaround
       SQLiteQueryBuilder qb = builderWishlistComponent();
       Cursor cursor = qb.query(
               getWritableDatabase(), qh.Columns, qh.Selection, qh.SelectionArgs, qh.GroupBy, qh.Having, qh.OrderBy, qh.Limit);

       return new WishlistComponentCursor(cursor);
   }
 
Example 5
Source Project: android-test   Source File: FlightsContentProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Cursor query(@NonNull Uri uri, String[] projection, String where, String[] args,
    String sortOrder) {
  checkNotNull(uri);
  SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder();
  sqlBuilder.setTables(FlightsDatabaseContract.TABLE_NAME);
  switch (URI_MATCHER.match(uri)) {
    case FLIGHTS_ALL:
      break;
    case FLIGHT_ONE:
      sqlBuilder.appendWhere(FlightsColumns._ID + " = " + uri.getLastPathSegment());
      break;
    default:
      throw new IllegalArgumentException("Unrecognized uri: " + uri);
  }
  String sort = TextUtils.isEmpty(sortOrder) ? FlightsColumns.FLIGHT_CUSTOMER : sortOrder;
  SQLiteDatabase database = dbHelper.getWritableDatabase();

  Cursor c = sqlBuilder.query(database, projection, where, args, null, null, sort);
  c.setNotificationUri(context.getContentResolver(), uri);
  return c;
}
 
Example 6
Source Project: letv   Source File: DownloadContentProvider.java    License: Apache License 2.0 6 votes vote down vote up
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    switch (URI_MATCHER.match(uri)) {
        case 100:
            qb.setTables("worldcup_download_info");
            break;
        case 101:
            qb.setTables("worldcup_downlod_thread_info");
            break;
        default:
            throw new IllegalStateException("Unknown URL: " + uri.toString());
    }
    Cursor c = qb.query(this.sqliteDataBase.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder);
    if (c != null) {
        c.setNotificationUri(getContext().getContentResolver(), uri);
    }
    return c;
}
 
Example 7
/**
 * @param selection     A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows
 * @param selectionArgs You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.
 * @return a cursor over the result set coulms are those specified by {@link BooksInformationDbHelper#BOOK_LISTING_PROJECTION}
 */
private Cursor queryBookListing(String selection, String[] selectionArgs) {

    SQLiteDatabase db = this.getReadableDatabase();
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(BOOKS_JOIN_AUTHORS);


    return builder.query(db,
            BOOK_LISTING_PROJECTION,
            selection,
            selectionArgs,
            null,
            null,
            null);
}
 
Example 8
Source Project: AppCodeArchitecture   Source File: DataProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    synchronized (obj) {
        SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
        queryBuilder.setTables(matchTable(uri));

        SQLiteDatabase db = getDBHelper().getReadableDatabase();
        Cursor cursor = queryBuilder.query(db,
                projection,
                selection,
                selectionArgs,
                null,
                null,
                sortOrder);
        cursor.setNotificationUri(getContext().getContentResolver(), uri);
        return cursor;
    }
}
 
Example 9
public WishlistComponentCursor queryWishlistComponents(long id) {

        String[] wcColumns = null;
        String wcSelection = "wc." + S.COLUMN_WISHLIST_COMPONENT_WISHLIST_ID + " = ?";
        String[] wcSelectionArgs = new String[]{String.valueOf(id)};
        String wcGroupBy = null;
        String wcHaving = null;
        String wcOrderBy = "wc." + S.COLUMN_WISHLIST_COMPONENT_COMPONENT_ID + " ASC";
        String wcLimit = null;

        // Multithread issues workaround
        SQLiteQueryBuilder qb = builderWishlistComponent();
        Cursor cursor = qb.query(
                getWritableDatabase(), wcColumns, wcSelection, wcSelectionArgs, wcGroupBy, wcHaving, wcOrderBy, wcLimit);

        return new WishlistComponentCursor(cursor);
    }
 
Example 10
Source Project: cannonball-android   Source File: PoemProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = dbHelper.getWritableDatabase();
    final SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder.setTables(PoemContract.TABLE);

    switch (sUriMatcher.match(uri)) {
        case POEMS:
            return 0;
        case POEMS_ID:
            final String[] args = { uri.getLastPathSegment() };
            final int count
                    = db.delete(PoemContract.TABLE, PoemContract.Columns.ID + " = ?", args);
            if (count != 0)
                getContext().getContentResolver().notifyChange(uri, null);
            return count;
        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
    }
}
 
Example 11
Source Project: protrip   Source File: PlacesProvider.java    License: 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 12
Source Project: Cangol-appcore   Source File: DaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
private Cursor query(SQLiteDatabase db, QueryBuilder queryBuilder, String... columns) {
    if (mShowSql) {
        Log.d(mTableName, SQLiteQueryBuilder.buildQueryString(queryBuilder.isDistinctValue(),
                queryBuilder.getTable(),
                columns,
                queryBuilder.getWhere(),
                queryBuilder.getGroupByValue(),
                queryBuilder.getHavingValue(),
                queryBuilder.getOrderByValue(),
                queryBuilder.getLimitValue()));
    }

    return db.query(queryBuilder.isDistinctValue(),
            queryBuilder.getTable(),
            columns,
            queryBuilder.getSelection(),
            queryBuilder.getSelectionArgs(),
            queryBuilder.getGroupByValue(),
            queryBuilder.getHavingValue(),
            queryBuilder.getOrderByValue(),
            queryBuilder.getLimitValue());
}
 
Example 13
Source Project: LibreTasks   Source File: RegisteredAppDbAdapter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return a Cursor that contains all RegisteredApp records which matches the parameters.
 * 
 * @param appName
 *          is the application name or null to fetch any appName.
 * @param pkgName
 *          is the package name or null to fetch any pkgName.
 * @param enabled
 *          is whether the application is activated or null to fetch any enabled status.
 * @return a Cursor that contains all RegisteredApp records which matches the parameters.
 */
public Cursor fetchAll(String appName, String pkgName, Boolean enabled) {
  SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
  qb.setTables(DATABASE_TABLE);
  qb.appendWhere("1=1");
  if (appName != null) {
    qb.appendWhere(" AND " + KEY_APPNAME + " = ");
    qb.appendWhereEscapeString(appName);
  }
  if (pkgName != null) {
    qb.appendWhere(" AND " + KEY_PKGNAME + " = ");
    qb.appendWhereEscapeString(pkgName);
  }
  if (enabled != null) {
    qb.appendWhere(" AND " + KEY_ENABLED + " = " + (enabled ? 1 : 0));
  }
  // Not using additional selections, selectionArgs, groupBy, having, orderBy, set them to null.
  return qb.query(database, KEYS, null, null, null, null, null);
}
 
Example 14
Source Project: Material-Movies   Source File: DbProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();

    switch (uriMatcher.match(uri)) {
        case MOVIES_ID:
            queryBuilder.appendWhere(DbConstants.Movies.ID + "="
                    + uri.getLastPathSegment());
        case MOVIES:
            queryBuilder.setTables(DbConstants.Movies.TABLE_NAME);
            if (TextUtils.isEmpty(sortOrder)) {
                sortOrder = DbConstants.Movies.DEFAULT_SORT_ORDER;
            }
            break;

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

    Cursor c = queryBuilder.query(database, projection, selection, selectionArgs, null,
            null, sortOrder);
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}
 
Example 15
Source Project: Cheerleader   Source File: OfflinerProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {
    try {
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

        switch (sUriMatcher.match(uri)) {
            case CACHE:
                qb.setTables(OfflinerDBHelper.TABLE_CACHE);
                break;
            default:
                throw new IllegalArgumentException(UNKNOWN_URI + uri);
        }

        SQLiteDatabase db = mDbHelper.getReadableDatabase();
        Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);

        c.setNotificationUri(getContext().getContentResolver(), uri);
        return c;
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
    return null;
}
 
Example 16
Source Project: opensudoku   Source File: SudokuDatabase.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Find folder by name. If no folder is found, null is returned.
 *
 * @param folderName
 * @param db
 * @return
 */
public FolderInfo findFolder(String folderName) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    qb.setTables(FOLDER_TABLE_NAME);
    qb.appendWhere(FolderColumns.NAME + " = ?");

    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    try (Cursor c = qb.query(db, null, null,
            new String[]{folderName}, null, null, null)) {

        if (c.moveToFirst()) {
            long id = c.getLong(c.getColumnIndex(FolderColumns._ID));
            String name = c.getString(c.getColumnIndex(FolderColumns.NAME));

            FolderInfo folderInfo = new FolderInfo();
            folderInfo.id = id;
            folderInfo.name = name;

            return folderInfo;
        } else {
            return null;
        }
    }
}
 
Example 17
Source Project: opentasks   Source File: TaskProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Append the selection of the account specified in <code>uri</code> to the an {@link SQLiteQueryBuilder}.
 *
 * @param sqlBuilder
 *         A {@link SQLiteQueryBuilder} that the selection is appended to.
 * @param uri
 *         A {@link Uri} that specifies an account.
 */
protected void selectAccount(SQLiteQueryBuilder sqlBuilder, Uri uri)
{
    String accountName = getAccountName(uri);
    String accountType = getAccountType(uri);

    if (accountName != null)
    {
        sqlBuilder.appendWhere(" AND ");
        sqlBuilder.appendWhere(TaskListSyncColumns.ACCOUNT_NAME);
        sqlBuilder.appendWhere("=");
        sqlBuilder.appendWhereEscapeString(accountName);
    }
    if (accountType != null)
    {
        sqlBuilder.appendWhere(" AND ");
        sqlBuilder.appendWhere(TaskListSyncColumns.ACCOUNT_TYPE);
        sqlBuilder.appendWhere("=");
        sqlBuilder.appendWhereEscapeString(accountType);
    }
}
 
Example 18
Source Project: LibreTasks   Source File: FailedActionsDbAdapter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return a Cursor that contains all FailedAction records which matches the parameters.
 * 
 * @param ruleID
 *          is id of the rule it belongs to, or null to fetch any.
 * @param actionID
 *          is id of its action type, or null to fetch any.
 * @param failureType TYPE + " integer not null, "
    + KEY_COUNT + 
 *          is type of failure or null to fetch any.
 * @return a Cursor that contains all RuleAction records which matches the parameters.
 */
public Cursor fetchAll(Long ruleID, Long actionID, Integer failureType) {
  SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
  qb.setTables(DATABASE_TABLE);
  qb.appendWhere("1=1");
  if (ruleID != null) {
    qb.appendWhere(" AND " + KEY_RULEID + "=" + ruleID);
  }
  if (actionID != null) {
    qb.appendWhere(" AND " + KEY_ACTIONID + "=" + actionID);
  }
  if (failureType != null) {
    qb.appendWhere(" AND " + KEY_FAILURE_TYPE + "=" + failureType);
  }
  // Not using additional selections, selectionArgs, groupBy, having, orderBy, set them to null.
  return qb.query(database, KEYS, null, null, null, null, null);
}
 
Example 19
Source Project: LibreTasks   Source File: FailedActionParameterDbAdapter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return a Cursor that contains all FailedActionParameter records which matches the parameters.
 * 
 * @param failedActionID
 *          is id of failed action it belongs to, or null to fetch any
 * @param actionParameterName
 *          name of action parameter, or null to fetch any
 * @param failedActionParameterData
 *          is the data associated with this parameter, or null to fetch any
 * @return a Cursor that contains all FailedActionParameter records which matches the parameters.
 */
public Cursor fetchAll(Long failedActionID, String actionParameterName, 
    String failedActionParameterData) {

  SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
  qb.setTables(DATABASE_TABLE);
  qb.appendWhere("1=1");
  if (failedActionID != null) {
    qb.appendWhere(" AND " + KEY_FAILEDACTIONID + " = " + failedActionID);
  }
  if (actionParameterName != null) {
    qb.appendWhere(" AND " + KEY_ACTIONPARAMETERNAME + " = " + actionParameterName);
  }
  if (failedActionParameterData != null) {
    qb.appendWhere(" AND " + KEY_FAILEDACTIONPARAMETERDATA + " = ");
    qb.appendWhereEscapeString(failedActionParameterData);
  }
  // Not using additional selections, selectionArgs, groupBy, having, orderBy, set them to null.
  return qb.query(database, KEYS, null, null, null, null, null);
}
 
Example 20
Source Project: Popular-Movies-App   Source File: MoviesProvider.java    License: Apache License 2.0 6 votes vote down vote up
private Cursor getMoviesFromReferenceTable(String tableName, String[] projection, String selection,
                                           String[] selectionArgs, String sortOrder) {

    SQLiteQueryBuilder sqLiteQueryBuilder = new SQLiteQueryBuilder();

    // tableName INNER JOIN movies ON tableName.movie_id = movies._id
    sqLiteQueryBuilder.setTables(
            tableName + " INNER JOIN " + MoviesContract.MovieEntry.TABLE_NAME +
                    " ON " + tableName + "." + MoviesContract.COLUMN_MOVIE_ID_KEY +
                    " = " + MoviesContract.MovieEntry.TABLE_NAME + "." + MoviesContract.MovieEntry._ID
    );

    return sqLiteQueryBuilder.query(dbHelper.getReadableDatabase(),
            projection,
            selection,
            selectionArgs,
            null,
            null,
            sortOrder
    );
}
 
Example 21
private Cursor queryItemNext(final String[] projection, final String selection, final String[] selectionArgs, final String orderBy) {
    // query the database for a single  item that is not yet done:

    //Prepend our ID=? argument to the selection arguments.
    //This lets us use the ? syntax to avoid SQL injection

    final SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(DatabaseHelper.TABLE_NAME_ITEMS);
    builder.setProjectionMap(sItemsProjectionMap);
    builder.appendWhere(WHERE_CLAUSE_NOT_DONE);

    //Default to the order of creation,
    //so we are more likely to get the first record that was created synchronously
    //so we could be sure that it was fully loaded.
    String orderByToUse = orderBy;
    if (orderBy == null || orderBy.isEmpty()) {
        orderByToUse = DatabaseHelper.ItemsDbColumns._ID + " ASC";
    }

    return builder.query(getDb(), projection,
            selection, selectionArgs,
            null, null, orderByToUse, "1");
}
 
Example 22
Source Project: Onosendai   Source File: DbAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<Tweet> findTweetsWithMeta (final int columnId, final MetaType metaType, final String data, final int numberOf) {
	if (!checkDbOpen()) return null;
	Cursor c = null;
	try {
		final SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
		qb.setTables(TBL_TW + " INNER JOIN " + TBL_TM + " ON " + TBL_TW + "." + TBL_TW_ID + " = " + TBL_TM_TWID);
		qb.setDistinct(true);
		c = qb.query(this.mDb,
				new String[] { TBL_TW + "." + TBL_TW_ID, TBL_TW_SID, TBL_TW_USERNAME, TBL_TW_FULLNAME, TBL_TW_USERSUBTITLE, TBL_TW_FULLSUBTITLE, TBL_TW_OWNER_USERNAME, TBL_TW_BODY, TBL_TW_TIME, TBL_TW_AVATAR, TBL_TW_INLINEMEDIA, TBL_TW_QUOTED_SID, TBL_TW_FILTERED },
				TBL_TW + "." + TBL_TW_ID + "=" + TBL_TM_TWID + " AND " + TBL_TM_TYPE + "=" + metaType.getId() + " AND " + TBL_TM_DATA + "=?"
						+ (columnId > Integer.MIN_VALUE ? " AND " + TBL_TW_COLID + "=" + columnId : ""),
				new String[] { data },
				TBL_TW_SID, null, TBL_TW_TIME + " desc", String.valueOf(numberOf));
		return readTweets(c, false);
	}
	finally {
		IoHelper.closeQuietly(c);
	}
}
 
Example 23
Source Project: hackerskeyboard   Source File: UserBigramDictionary.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Query the database
 */
private Cursor query(String selection, String[] selectionArgs) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    // main INNER JOIN frequency ON (main._id=freq.pair_id)
    qb.setTables(MAIN_TABLE_NAME + " INNER JOIN " + FREQ_TABLE_NAME + " ON ("
            + MAIN_TABLE_NAME + "." + MAIN_COLUMN_ID + "=" + FREQ_TABLE_NAME + "."
            + FREQ_COLUMN_PAIR_ID +")");

    qb.setProjectionMap(sDictProjectionMap);

    // Get the database and run the query
    SQLiteDatabase db = sOpenHelper.getReadableDatabase();
    Cursor c = qb.query(db,
            new String[] { MAIN_COLUMN_WORD1, MAIN_COLUMN_WORD2, FREQ_COLUMN_FREQUENCY },
            selection, selectionArgs, null, null, null);
    return c;
}
 
Example 24
Source Project: WiFiAfterConnect   Source File: WifiAuthDatabase.java    License: Apache License 2.0 5 votes vote down vote up
private long getAuthParamRowId (SQLiteDatabase db, long hostId, String name){
	long rowId = -1;
	SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
	builder.setTables(WIFI_AUTH_PARAMS_TABLE_NAME);
	Cursor c = builder.query(db, new String[] {COLUMN_ID}, COLUMN_HOST_ID + " = ? And " + COLUMN_PARAM_NAME + " = ?", new String[] {Long.toString(hostId), name}, null, null, null); 
	if (c.moveToFirst())
		rowId = c.getLong(0);
	c.close();
	return rowId;
}
 
Example 25
private SQLiteQueryBuilder builderHuntingReward() {
//		SELECT h._id AS _id, h.item_id, h.monster_id,
//		h.condition, h.rank, h.stack_size, h.percentage,
//		i.name AS iname, m.name AS mname
//		FROM hunting_rewards AS h
//		LEFT OUTER JOIN items AS i ON h.item_id = i._id
//		LEFT OUTER JOIN monsters AS m ON h.monster_id = m._id;

        String h = "h";
        String i = "i";
        String m = "m";

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

        projectionMap.put("_id", h + "." + S.COLUMN_HUNTING_REWARDS_ID + " AS " + "_id");
        projectionMap.put(S.COLUMN_HUNTING_REWARDS_ITEM_ID, h + "." + S.COLUMN_HUNTING_REWARDS_ITEM_ID);
        projectionMap.put(S.COLUMN_HUNTING_REWARDS_MONSTER_ID, h + "." + S.COLUMN_HUNTING_REWARDS_MONSTER_ID);
        projectionMap.put(S.COLUMN_HUNTING_REWARDS_CONDITION, h + "." + S.COLUMN_HUNTING_REWARDS_CONDITION);
        projectionMap.put(S.COLUMN_HUNTING_REWARDS_RANK, h + "." + S.COLUMN_HUNTING_REWARDS_RANK);
        projectionMap.put(S.COLUMN_HUNTING_REWARDS_STACK_SIZE, h + "." + S.COLUMN_HUNTING_REWARDS_STACK_SIZE);
        projectionMap.put(S.COLUMN_HUNTING_REWARDS_PERCENTAGE, h + "." + S.COLUMN_HUNTING_REWARDS_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(S.COLUMN_MONSTERS_TRAIT, m + "." + S.COLUMN_MONSTERS_TRAIT);
        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_HUNTING_REWARDS + " AS h" + " LEFT OUTER JOIN " + S.TABLE_ITEMS + " AS i" + " ON " + "h." +
                S.COLUMN_HUNTING_REWARDS_ITEM_ID + " = " + "i." + S.COLUMN_ITEMS_ID + " LEFT OUTER JOIN " + S.TABLE_MONSTERS +
                " AS m " + " ON " + "h." + S.COLUMN_HUNTING_REWARDS_MONSTER_ID + " = " + "m." + S.COLUMN_MONSTERS_ID);

        QB.setProjectionMap(projectionMap);
        return QB;
    }
 
Example 26
Source Project: android   Source File: TrackingContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {

    // Using SQLiteQueryBuilder instead of query() method
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();

    // Check if the caller has requested a column which does not exists
    checkColumns(projection);

    // Set the table
    queryBuilder.setTables(TrackingTable.TABLE_TRACKING);

    int uriType = sURIMatcher.match(uri);
    switch (uriType) {
        case TRACKING:
            break;
        case TRACKING_ID:
            // Adding the ID to the original query
            queryBuilder.appendWhere(TrackingTable.COLUMN_ID + "="
                    + uri.getLastPathSegment());
            break;
        default:
            throw new IllegalArgumentException("Unknown URI: " + uri);
    }

    SQLiteDatabase db = database.getWritableDatabase();
    Cursor cursor = queryBuilder.query(db, projection, selection,
            selectionArgs, null, null, sortOrder);
    // Make sure that potential listeners are getting notified
    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;
}
 
Example 27
Source Project: io2015-codelabs   Source File: RecipeContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
public Cursor getRecipe(Uri uri) {
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder.setTables(RecipeTable.TABLE);
    String[] projection = { RecipeTable.ID, RecipeTable.TITLE,
            RecipeTable.DESCRIPTION, RecipeTable.PHOTO,
            RecipeTable.PREP_TIME};
    SQLiteDatabase db = database.getReadableDatabase();
    queryBuilder.appendWhere(RecipeTable.ID + "='"
            + uri.getLastPathSegment() + "'");
    Cursor cursor = queryBuilder.query(db, projection, null,
            null, null, null, null);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;
}
 
Example 28
public MobileServer getMobileServer(long id){
    SQLiteDatabase db = this.getReadableDatabase();

    MobileServer mobileServer = new MobileServer();
    mobileServer.setId(id);

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    qb.setTables(TABLE_SERVERS +
            " JOIN " + TABLE_MOBILE_SERVERS +
            " USING(" + COLUMN_ID + ")");

    Cursor c = qb.query(db,
            new String[]{COLUMN_IS_ENABLED,
                    COLUMN_CERTIFICATE_ID,
                    COLUMN_IP_OR_HOSTNAME,
                    COLUMN_PORT_NUMBER,
                    COLUMN_ROAMING_ALLOWED},
            COLUMN_ID + "=?", new String[]{String.valueOf(id)},
            null, null, null);

    if (c.moveToFirst()){
        mobileServer.setIsEnabled(intToBool(c.getInt(0)));
        mobileServer.setCertificateId(c.getLong(1));
        mobileServer.setIpOrHostname(c.getString(2));
        mobileServer.setPortNumber(c.getInt(3));
        mobileServer.setRoamingAllowed(intToBool(c.getInt(4)));
    }

    c.close();
    db.close();
    return mobileServer;
}
 
Example 29
public BluetoothServer getBluetoothServer(long id){
    SQLiteDatabase db = this.getReadableDatabase();

    BluetoothServer bluetoothServer = new BluetoothServer();
    bluetoothServer.setId(id);

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    qb.setTables(TABLE_SERVERS +
            " JOIN " + TABLE_BLUETOOTH_SERVERS +
            " USING(" + COLUMN_ID + ")");

    Cursor c = qb.query(db,
            new String[]{COLUMN_IS_ENABLED,
                    COLUMN_CERTIFICATE_ID,
                    COLUMN_BLUETOOTH_MAC_ADDRESS,
                    COLUMN_BLUETOOTH_NAME},
            COLUMN_ID + "=?", new String[]{String.valueOf(id)},
            null, null, null);

    if (c.moveToFirst()){
        bluetoothServer.setIsEnabled(intToBool(c.getInt(0)));
        bluetoothServer.setCertificateId(c.getLong(1));
        bluetoothServer.setBluetoothMacAddress(c.getString(2));
        bluetoothServer.setBluetoothName(c.getString(3));
    }

    c.close();
    db.close();
    return bluetoothServer;
}
 
Example 30
Source Project: io2015-codelabs   Source File: RecipeContentProvider.java    License: Apache License 2.0 5 votes vote down vote up
public Cursor getRecipe(Uri uri) {
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder.setTables(RecipeTable.TABLE);
    String[] projection = { RecipeTable.ID, RecipeTable.TITLE,
            RecipeTable.DESCRIPTION, RecipeTable.PHOTO,
            RecipeTable.PREP_TIME};
    SQLiteDatabase db = database.getReadableDatabase();
    queryBuilder.appendWhere(RecipeTable.ID + "='"
            + uri.getLastPathSegment() + "'");
    Cursor cursor = queryBuilder.query(db, projection, null,
            null, null, null, null);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;
}