下面列出了android.database.sqlite.SQLiteCursorDriver#androidx.sqlite.db.SupportSQLiteQuery 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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;
}
/**
* 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);
}
}
protected LimitOffsetDataSource(RoomDatabase db, SupportSQLiteQuery query,
boolean inTransaction, String... tables) {
this(db, RoomSQLiteQuery.copyFrom(query), inTransaction, tables);
}
/**
* {@inheritDoc}
*/
@Override
public Cursor query(final SupportSQLiteQuery supportQuery) {
return(query(supportQuery, null));
}
@Override
public android.database.Cursor query(final SupportSQLiteQuery supportQuery, CancellationSignal cancellationSignal) {
throw (new RuntimeException("Not implements"));
}
/**
* {@inheritDoc}
*/
@Override
public Cursor query(final SupportSQLiteQuery supportQuery) {
return (query(supportQuery, null));
}
/**
* {@inheritDoc}
*/
@Override
public Cursor query(final SupportSQLiteQuery supportQuery) {
return (query(supportQuery, null));
}
/**
* 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);
}
/**
* 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);
}