androidx.sqlite.db.SupportSQLiteQuery Java Examples

The following examples show how to use androidx.sqlite.db.SupportSQLiteQuery. 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: DBUtil.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Performs the SQLiteQuery on the given database.
 * <p>
 * This util method encapsulates copying the cursor if the {@code maybeCopy} parameter is
 * {@code true} and either the api level is below a certain threshold or the full result of the
 * query does not fit in a single window.
 *
 * @param db          The database to perform the query on.
 * @param sqLiteQuery The query to perform.
 * @param maybeCopy   True if the result cursor should maybe be copied, false otherwise.
 * @param signal      The cancellation signal to be attached to the query.
 * @return Result of the query.
 */
@NonNull
public static Cursor query(@NonNull RoomDatabase db, @NonNull SupportSQLiteQuery sqLiteQuery,
        boolean maybeCopy, @Nullable CancellationSignal signal) {
    final Cursor cursor = db.query(sqLiteQuery, signal);
    if (maybeCopy && cursor instanceof AbstractWindowedCursor) {
        AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor) cursor;
        int rowsInCursor = windowedCursor.getCount(); // Should fill the window.
        int rowsInWindow;
        if (windowedCursor.hasWindow()) {
            rowsInWindow = windowedCursor.getWindow().getNumRows();
        } else {
            rowsInWindow = rowsInCursor;
        }
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || rowsInWindow < rowsInCursor) {
            return CursorUtil.copyAndClose(windowedCursor);
        }
    }

    return cursor;
}
 
Example #2
Source File: SQLiteDatabase.java    From sqlite-android with Apache License 2.0 6 votes vote down vote up
/**
 * Runs the provided SQL and returns a {@link Cursor} over the result set.
 *
 * @param supportQuery the SQL query. The SQL string must not be ; terminated
 * @param signal A signal to cancel the operation in progress, or null if none.
 * If the operation is canceled, then {@link OperationCanceledException} will be thrown
 * when the query is executed.
 * @return A {@link Cursor} object, which is positioned before the first entry. Note that
 * {@link Cursor}s are not synchronized, see the documentation for more details.
 */
@Override
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public Cursor query(SupportSQLiteQuery supportQuery, android.os.CancellationSignal signal) {
    if (signal != null) {
        final CancellationSignal supportCancellationSignal = new CancellationSignal();
        signal.setOnCancelListener(new android.os.CancellationSignal.OnCancelListener() {
            @Override
            public void onCancel() {
                supportCancellationSignal.cancel();
            }
        });
        return query(supportQuery, supportCancellationSignal);
    } else {
        return query(supportQuery, (CancellationSignal) null);
    }
}
 
Example #3
Source File: LimitOffsetDataSource.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
protected LimitOffsetDataSource(RoomDatabase db, SupportSQLiteQuery query,
        boolean inTransaction, String... tables) {
    this(db, RoomSQLiteQuery.copyFrom(query), inTransaction, tables);
}
 
Example #4
Source File: Database.java    From cwac-saferoom with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Cursor query(final SupportSQLiteQuery supportQuery) {
  return(query(supportQuery, null));
}
 
Example #5
Source File: SQLiteDatabase.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public android.database.Cursor query(final SupportSQLiteQuery supportQuery, CancellationSignal cancellationSignal) {
	throw (new RuntimeException("Not implements"));
}
 
Example #6
Source File: KriptonSQLiteDatabaseWrapperImpl.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Cursor query(final SupportSQLiteQuery supportQuery) {
	return (query(supportQuery, null));
}
 
Example #7
Source File: Database.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Cursor query(final SupportSQLiteQuery supportQuery) {
	return (query(supportQuery, null));
}
 
Example #8
Source File: DBUtil.java    From FairEmail with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Performs the SQLiteQuery on the given database.
 * <p>
 * This util method encapsulates copying the cursor if the {@code maybeCopy} parameter is
 * {@code true} and either the api level is below a certain threshold or the full result of the
 * query does not fit in a single window.
 *
 * @param db          The database to perform the query on.
 * @param sqLiteQuery The query to perform.
 * @param maybeCopy   True if the result cursor should maybe be copied, false otherwise.
 * @return Result of the query.
 *
 * @deprecated This is only used in the generated code and shouldn't be called directly.
 */
@Deprecated
@NonNull
public static Cursor query(RoomDatabase db, SupportSQLiteQuery sqLiteQuery, boolean maybeCopy) {
    return query(db, sqLiteQuery, maybeCopy, null);
}
 
Example #9
Source File: SQLiteDatabase.java    From sqlite-android with Apache License 2.0 2 votes vote down vote up
/**
 * Runs the provided SQL and returns a {@link Cursor} over the result set.
 *
 * @param supportQuery the SQL query.
 * @return A {@link Cursor} object, which is positioned before the first entry. Note that
 * {@link Cursor}s are not synchronized, see the documentation for more details.
 */
@Override
public Cursor query(final SupportSQLiteQuery supportQuery) {
    return query(supportQuery, (CancellationSignal) null);
}