Search in sources :

Example 1 with CrossProcessCursorWrapper

use of net.sqlcipher.CrossProcessCursorWrapper in project android-database-sqlcipher by sqlcipher.

the class SQLiteDatabase method rawQuery.

/**
     * Runs the provided SQL and returns a {@link Cursor} over the result set.
     *
     * @param sql the SQL query. The SQL string must not be ; terminated
     * @param args You may include ?s in where clause in the query,
     *     which will be replaced by the values from args. The
     *     values will be bound by their type.
     *
     * @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.
     *
     * @throws SQLiteException if there is an issue executing the sql or the SQL string is invalid
     * @throws IllegalStateException if the database is not open
     */
public Cursor rawQuery(String sql, Object[] args) {
    if (!isOpen()) {
        throw new IllegalStateException("database not open");
    }
    long timeStart = 0;
    if (Config.LOGV || mSlowQueryThreshold != -1) {
        timeStart = System.currentTimeMillis();
    }
    SQLiteDirectCursorDriver driver = new SQLiteDirectCursorDriver(this, sql, null);
    Cursor cursor = null;
    try {
        cursor = driver.query(mFactory, args);
    } finally {
        if (Config.LOGV || mSlowQueryThreshold != -1) {
            // Force query execution
            int count = -1;
            if (cursor != null) {
                count = cursor.getCount();
            }
            long duration = System.currentTimeMillis() - timeStart;
            if (Config.LOGV || duration >= mSlowQueryThreshold) {
                Log.v(TAG, "query (" + duration + " ms): " + driver.toString() + ", args are <redacted>, count is " + count);
            }
        }
    }
    return new CrossProcessCursorWrapper(cursor);
}
Also used : CrossProcessCursorWrapper(net.sqlcipher.CrossProcessCursorWrapper) Cursor(net.sqlcipher.Cursor)

Example 2 with CrossProcessCursorWrapper

use of net.sqlcipher.CrossProcessCursorWrapper in project android-database-sqlcipher by sqlcipher.

the class SQLiteDatabase method rawQueryWithFactory.

/**
     * Runs the provided SQL and returns a cursor over the result set.
     *
     * @param cursorFactory the cursor factory to use, or null for the default factory
     * @param sql the SQL query. The SQL string must not be ; terminated
     * @param selectionArgs You may include ?s in where clause in the query,
     *     which will be replaced by the values from selectionArgs. The
     *     values will be bound as Strings.
     * @param editTable the name of the first table, which is editable
     *
     * @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.
     *
     * @throws SQLiteException if there is an issue executing the sql or the SQL string is invalid
     * @throws IllegalStateException if the database is not open
     */
public Cursor rawQueryWithFactory(CursorFactory cursorFactory, String sql, String[] selectionArgs, String editTable) {
    if (!isOpen()) {
        throw new IllegalStateException("database not open");
    }
    long timeStart = 0;
    if (Config.LOGV || mSlowQueryThreshold != -1) {
        timeStart = System.currentTimeMillis();
    }
    SQLiteCursorDriver driver = new SQLiteDirectCursorDriver(this, sql, editTable);
    Cursor cursor = null;
    try {
        cursor = driver.query(cursorFactory != null ? cursorFactory : mFactory, selectionArgs);
    } finally {
        if (Config.LOGV || mSlowQueryThreshold != -1) {
            // Force query execution
            int count = -1;
            if (cursor != null) {
                count = cursor.getCount();
            }
            long duration = System.currentTimeMillis() - timeStart;
            if (Config.LOGV || duration >= mSlowQueryThreshold) {
                Log.v(TAG, "query (" + duration + " ms): " + driver.toString() + ", args are <redacted>, count is " + count);
            }
        }
    }
    return new CrossProcessCursorWrapper(cursor);
}
Also used : CrossProcessCursorWrapper(net.sqlcipher.CrossProcessCursorWrapper) Cursor(net.sqlcipher.Cursor)

Aggregations

CrossProcessCursorWrapper (net.sqlcipher.CrossProcessCursorWrapper)2 Cursor (net.sqlcipher.Cursor)2