Search in sources :

Example 1 with SupportSQLiteQuery

use of androidx.sqlite.db.SupportSQLiteQuery in project Rocket by mozilla-tw.

the class HistoryProvider method insertWithUrlUnique.

private long insertWithUrlUnique(SupportSQLiteDatabase db, ContentValues values) {
    long id = -1;
    Cursor c = null;
    try {
        SupportSQLiteQuery query = SupportSQLiteQueryBuilder.builder(Tables.BROWSING_HISTORY).columns(null).selection(BrowsingHistory.URL + " = ?", new String[] { values.getAsString(BrowsingHistory.URL) }).groupBy(null).having(null).orderBy(null).create();
        c = db.query(query);
        if (c != null) {
            if (c.moveToFirst()) {
                id = c.getLong(c.getColumnIndex(BrowsingHistory._ID));
                values.put(BrowsingHistory.VIEW_COUNT, c.getLong((c.getColumnIndex(BrowsingHistory.VIEW_COUNT))) + 1);
                if (db.update(Tables.BROWSING_HISTORY, OnConflictStrategy.ROLLBACK, values, BrowsingHistory._ID + " = ?", new String[] { Long.toString(id) }) == 0) {
                    id = -1;
                }
            } else {
                values.put(BrowsingHistory.VIEW_COUNT, 1);
                id = db.insert(Tables.BROWSING_HISTORY, OnConflictStrategy.ROLLBACK, values);
            }
        }
        return id;
    } finally {
        if (c != null) {
            c.close();
        }
    }
}
Also used : SupportSQLiteQuery(androidx.sqlite.db.SupportSQLiteQuery) Cursor(android.database.Cursor)

Example 2 with SupportSQLiteQuery

use of androidx.sqlite.db.SupportSQLiteQuery in project android-database-sqlcipher by sqlcipher.

the class SQLiteDatabase method query.

@Override
public android.database.Cursor query(final SupportSQLiteQuery supportQuery, CancellationSignal cancellationSignal) {
    String sql = supportQuery.getSql();
    int argumentCount = supportQuery.getArgCount();
    Object[] args = new Object[argumentCount];
    SQLiteDirectCursorDriver driver = new SQLiteDirectCursorDriver(this, sql, null);
    SQLiteQuery query = new SQLiteQuery(this, sql, 0, args);
    supportQuery.bindTo(query);
    return new CrossProcessCursorWrapper(new SQLiteCursor(this, driver, null, query));
}
Also used : CrossProcessCursorWrapper(net.sqlcipher.CrossProcessCursorWrapper) SupportSQLiteQuery(androidx.sqlite.db.SupportSQLiteQuery)

Example 3 with SupportSQLiteQuery

use of androidx.sqlite.db.SupportSQLiteQuery in project Rocket by mozilla-tw.

the class HistoryProvider method query.

@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if (sUriMatcher.match(uri) != BROWSING_HISTORY) {
        throw new IllegalArgumentException("URI: " + uri);
    }
    final SupportSQLiteDatabase db = mDbHelper.getReadableDatabase();
    SupportSQLiteQuery query = SupportSQLiteQueryBuilder.builder(Tables.BROWSING_HISTORY).columns(projection).selection(selection, selectionArgs).orderBy(sortOrder).limit(ProviderUtils.getLimitParam(uri.getQueryParameter("offset"), uri.getQueryParameter("limit"))).create();
    return db.query(query);
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) SupportSQLiteQuery(androidx.sqlite.db.SupportSQLiteQuery)

Aggregations

SupportSQLiteQuery (androidx.sqlite.db.SupportSQLiteQuery)3 Cursor (android.database.Cursor)1 SupportSQLiteDatabase (androidx.sqlite.db.SupportSQLiteDatabase)1 CrossProcessCursorWrapper (net.sqlcipher.CrossProcessCursorWrapper)1