android.database.sqlite.SQLiteQueryBuilder Java Examples

The following examples show how to use android.database.sqlite.SQLiteQueryBuilder. 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: ItemsContentProvider.java    From android-galaxyzoo with GNU General Public License v3.0 7 votes vote down vote up
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
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 6 votes vote down vote up
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 #3
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 6 votes vote down vote up
/**
    * ****************************** 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 #4
Source File: CapturedPlayerInfoProvider.java    From PADListener with GNU General Public License v2.0 6 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 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 #5
Source File: FlightsContentProvider.java    From android-test with 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 File: MessageQueueProvider.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #7
Source File: DownloadContentProvider.java    From letv with 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 #8
Source File: BooksInformationDbHelper.java    From IslamicLibraryAndroid with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @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 #9
Source File: DataProvider.java    From AppCodeArchitecture with 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 #10
Source File: UserBigramDictionary.java    From hackerskeyboard with 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 #11
Source File: PoemProvider.java    From cannonball-android with 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 #12
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 #13
Source File: RegisteredAppDbAdapter.java    From LibreTasks with 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 File: DbAdapter.java    From Onosendai with 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 #15
Source File: ItemsContentProvider.java    From android-galaxyzoo with GNU General Public License v3.0 6 votes vote down vote up
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 #16
Source File: MoviesProvider.java    From Popular-Movies-App with 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 #17
Source File: FailedActionParameterDbAdapter.java    From LibreTasks with 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 #18
Source File: FailedActionsDbAdapter.java    From LibreTasks with 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 File: TaskProvider.java    From opentasks with 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 #20
Source File: SudokuDatabase.java    From opensudoku with 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 #21
Source File: OfflinerProvider.java    From Cheerleader with 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 #22
Source File: DbProvider.java    From Material-Movies with 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 #23
Source File: DaoImpl.java    From Cangol-appcore with 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 #24
Source File: NotesProvider.java    From diva-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Cursor query(Uri uri, String[] projection, String selection,
                    String[] selectionArgs, String sortOrder) {

    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();

    // The table to query
    queryBuilder.setTables(TABLE);
    switch (urimatcher.match(uri)) {
        // maps all database column names
        case PATH_TABLE:
            break;
        case PATH_ID:
            queryBuilder.appendWhere( C_ID + "=" + uri.getLastPathSegment());
            break;
        default:
            throw new IllegalArgumentException("Divanotes(query): Unknown URI " + uri);
    }
    if (sortOrder == null || sortOrder == "") {
        // If no sorting specified by called then sort on title by default
        sortOrder = C_TITLE;
    }
    Cursor cursor = queryBuilder.query(mDB, projection, selection,
                                       selectionArgs, null, null, sortOrder);

     // register to watch a content URI for changes and notify the content resolver
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
 
Example #25
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
private SQLiteQueryBuilder builderWeaponTreeParent() {
//		SELECT i2._id, i2.name
//		FROM items AS i1
//		LEFT OUTER JOIN components AS c ON i1._id = c.created_item_id 
//		JOIN weapons AS w2 ON w2._id = c.component_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_CREATED_ITEM_ID +
                        " JOIN " + S.TABLE_WEAPONS + " AS w2" + " ON " + "w2." + S.COLUMN_WEAPONS_ID + " = " +
                        "c." + S.COLUMN_COMPONENTS_COMPONENT_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 #26
Source File: TrackingContentProvider.java    From android 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) {

    // 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 File: RecentContentProvider.java    From android 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) {

    // 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(RecentTable.TABLE_RECENTS);

    int uriType = sURIMatcher.match(uri);
    switch (uriType) {
        case RECENT:
            break;
        case RECENT_ID:
            // Adding the ID to the original query
            queryBuilder.appendWhere(RecentTable.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, null);
    Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, RecentTable.COLUMN_ID + " DESC");
    // Make sure that potential listeners are getting notified
    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;
}
 
Example #28
Source File: RecipeContentProvider.java    From io2015-codelabs with 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 #29
Source File: MonsterHunterDatabaseHelper.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
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 #30
Source File: RecipeContentProvider.java    From search-samples with 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;
}