android.database.CursorWindow Java Examples

The following examples show how to use android.database.CursorWindow. 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: SQLiteCursor.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Put the value in given window. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded.
 */
private boolean putValue(CursorWindow window, Object value, int pos, int column) {
    if (value == null) {
        return window.putNull(pos, column);
    } else if (value instanceof Long) {
        return window.putLong((Long) value, pos, column);
    } else if (value instanceof String) {
        return window.putString((String) value, pos, column);
    } else if (value instanceof byte[] && ((byte[]) value).length > 0) {
        return window.putBlob((byte[]) value, pos, column);
    } else if (value instanceof Double) {
        return window.putDouble((Double) value, pos, column);
    } else {
        return window.putNull(pos, column);
    }
}
 
Example #2
Source File: SQLiteCursor.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Put the value in given window. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded.
 */
private boolean putValue(CursorWindow window, Object value, int pos, int column) {
    if (value == null) {
        return window.putNull(pos, column);
    } else if (value instanceof Long) {
        return window.putLong((Long) value, pos, column);
    } else if (value instanceof String) {
        return window.putString((String) value, pos, column);
    } else if (value instanceof byte[] && ((byte[]) value).length > 0) {
        return window.putBlob((byte[]) value, pos, column);
    } else if (value instanceof Double) {
        return window.putDouble((Double) value, pos, column);
    } else {
        return window.putNull(pos, column);
    }
}
 
Example #3
Source File: SQLiteSession.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Executes a statement and populates the specified {@link CursorWindow}
 * with a range of results.  Returns the number of rows that were counted
 * during query execution.
 *
 * @param sql The SQL statement to execute.
 * @param bindArgs The arguments to bind, or null if none.
 * @param window The cursor window to clear and fill.
 * @param startPos The start position for filling the window.
 * @param requiredPos The position of a row that MUST be in the window.
 * If it won't fit, then the query should discard part of what it filled
 * so that it does.  Must be greater than or equal to <code>startPos</code>.
 * @param countAllRows True to count all rows that the query would return
 * regagless of whether they fit in the window.
 * @param connectionFlags The connection flags to use if a connection must be
 * acquired by this operation.  Refer to {@link SQLiteConnectionPool}.
 * @param cancellationSignal A signal to cancel the operation in progress, or null if none.
 * @return The number of rows that were counted during query execution.  Might
 * not be all rows in the result set unless <code>countAllRows</code> is true.
 *
 * @throws SQLiteException if an error occurs, such as a syntax error
 * or invalid number of bind arguments.
 * @throws OperationCanceledException if the operation was canceled.
 */
public int executeForCursorWindow(String sql, Object[] bindArgs,
        CursorWindow window, int startPos, int requiredPos, boolean countAllRows,
        int connectionFlags, CancellationSignal cancellationSignal) {
    if (sql == null) {
        throw new IllegalArgumentException("sql must not be null.");
    }
    if (window == null) {
        throw new IllegalArgumentException("window must not be null.");
    }

    if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) {
        window.clear();
        return 0;
    }

    acquireConnection(sql, connectionFlags, cancellationSignal); // might throw
    try {
        return mConnection.executeForCursorWindow(sql, bindArgs,
                window, startPos, requiredPos, countAllRows,
                cancellationSignal); // might throw
    } finally {
        releaseConnection(); // might throw
    }
}
 
Example #4
Source File: SQLiteAndroidDatabase.java    From AvI with MIT License 6 votes vote down vote up
private void bindPreHoneycomb(JSONObject row, String key, Cursor cursor, int i) throws JSONException {
    // Since cursor.getType() is not available pre-honeycomb, this is
    // a workaround so we don't have to bind everything as a string
    // Details here: http://stackoverflow.com/q/11658239
    SQLiteCursor sqLiteCursor = (SQLiteCursor) cursor;
    CursorWindow cursorWindow = sqLiteCursor.getWindow();
    int pos = cursor.getPosition();
    if (cursorWindow.isNull(pos, i)) {
        row.put(key, JSONObject.NULL);
    } else if (cursorWindow.isLong(pos, i)) {
        row.put(key, cursor.getLong(i));
    } else if (cursorWindow.isFloat(pos, i)) {
        row.put(key, cursor.getDouble(i));
    /* ** Read BLOB as Base-64 DISABLED in this branch:
    } else if (cursorWindow.isBlob(pos, i)) {
        row.put(key, new String(Base64.encode(cursor.getBlob(i), Base64.DEFAULT)));
    // ** Read BLOB as Base-64 DISABLED to HERE. */
    } else { // string
        row.put(key, cursor.getString(i));
    }
}
 
Example #5
Source File: SQLiteCursor.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Put the value in given window. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded.
 */
private boolean putValue(CursorWindow window, Object value, int pos, int column) {
    if (value == null) {
        return window.putNull(pos, column);
    } else if (value instanceof Long) {
        return window.putLong((Long) value, pos, column);
    } else if (value instanceof String) {
        return window.putString((String) value, pos, column);
    } else if (value instanceof byte[] && ((byte[]) value).length > 0) {
        return window.putBlob((byte[]) value, pos, column);
    } else if (value instanceof Double) {
        return window.putDouble((Double) value, pos, column);
    } else {
        return window.putNull(pos, column);
    }
}
 
Example #6
Source File: DatabaseHelper.java    From android_dbinspector with Apache License 2.0 6 votes vote down vote up
/**
 * Compat method so we can get type of column on API < 11.
 * Source: http://stackoverflow.com/a/20685546/2643666
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static int getColumnType(Cursor cursor, int col) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        SQLiteCursor sqLiteCursor = (SQLiteCursor) cursor;
        CursorWindow cursorWindow = sqLiteCursor.getWindow();
        int pos = cursor.getPosition();
        int type = -1;
        if (cursorWindow.isNull(pos, col)) {
            type = FIELD_TYPE_NULL;
        } else if (cursorWindow.isLong(pos, col)) {
            type = FIELD_TYPE_INTEGER;
        } else if (cursorWindow.isFloat(pos, col)) {
            type = FIELD_TYPE_FLOAT;
        } else if (cursorWindow.isString(pos, col)) {
            type = FIELD_TYPE_STRING;
        } else if (cursorWindow.isBlob(pos, col)) {
            type = FIELD_TYPE_BLOB;
        }
        return type;
    } else {
        return cursor.getType(col);
    }
}
 
Example #7
Source File: SQLiteCursor.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Put the value in given window. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded.
 */
private boolean putValue(CursorWindow window, Object value, int pos, int column) {
    if (value == null) {
        return window.putNull(pos, column);
    } else if (value instanceof Long) {
        return window.putLong((Long) value, pos, column);
    } else if (value instanceof String) {
        return window.putString((String) value, pos, column);
    } else if (value instanceof byte[] && ((byte[]) value).length > 0) {
        return window.putBlob((byte[]) value, pos, column);
    } else if (value instanceof Double) {
        return window.putDouble((Double) value, pos, column);
    } else {
        return window.putNull(pos, column);
    }
}
 
Example #8
Source File: SQLiteSession.java    From squidb with Apache License 2.0 6 votes vote down vote up
/**
 * Executes a statement and populates the specified {@link CursorWindow}
 * with a range of results.  Returns the number of rows that were counted
 * during query execution.
 *
 * @param sql The SQL statement to execute.
 * @param bindArgs The arguments to bind, or null if none.
 * @param window The cursor window to clear and fill.
 * @param startPos The start position for filling the window.
 * @param requiredPos The position of a row that MUST be in the window.
 * If it won't fit, then the query should discard part of what it filled
 * so that it does.  Must be greater than or equal to <code>startPos</code>.
 * @param countAllRows True to count all rows that the query would return
 * regagless of whether they fit in the window.
 * @param connectionFlags The connection flags to use if a connection must be
 * acquired by this operation.  Refer to {@link SQLiteConnectionPool}.
 * @param cancellationSignal A signal to cancel the operation in progress, or null if none.
 * @return The number of rows that were counted during query execution.  Might
 * not be all rows in the result set unless <code>countAllRows</code> is true.
 *
 * @throws SQLiteException if an error occurs, such as a syntax error
 * or invalid number of bind arguments.
 * @throws OperationCanceledException if the operation was canceled.
 */
public int executeForCursorWindow(String sql, Object[] bindArgs,
        CursorWindow window, int startPos, int requiredPos, boolean countAllRows,
        int connectionFlags, CancellationSignal cancellationSignal) {
    if (sql == null) {
        throw new IllegalArgumentException("sql must not be null.");
    }
    if (window == null) {
        throw new IllegalArgumentException("window must not be null.");
    }

    if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) {
        window.clear();
        return 0;
    }

    acquireConnection(sql, connectionFlags, cancellationSignal); // might throw
    try {
        return mConnection.executeForCursorWindow(sql, bindArgs,
                window, startPos, requiredPos, countAllRows,
                cancellationSignal); // might throw
    } finally {
        releaseConnection(); // might throw
    }
}
 
Example #9
Source File: SQLiteCursor.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Put the value in given window. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded.
 */
private boolean putValue(CursorWindow window, Object value, int pos, int column) {
    if (value == null) {
        return window.putNull(pos, column);
    } else if (value instanceof Long) {
        return window.putLong((Long) value, pos, column);
    } else if (value instanceof String) {
        return window.putString((String) value, pos, column);
    } else if (value instanceof byte[] && ((byte[]) value).length > 0) {
        return window.putBlob((byte[]) value, pos, column);
    } else if (value instanceof Double) {
        return window.putDouble((Double) value, pos, column);
    } else {
        return window.putNull(pos, column);
    }
}
 
Example #10
Source File: CrossProcessCursorWrapper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public CursorWindow getWindow() {
    if (mCursor instanceof CrossProcessCursor) {
        final CrossProcessCursor crossProcessCursor = (CrossProcessCursor)mCursor;
        return crossProcessCursor.getWindow();
    }

    return null;
}
 
Example #11
Source File: SQLiteCursor.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Fill row with the given value. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded, false if window is full.
 */
private boolean fillRow(CursorWindow window, Object value, int pos, int column) {
    if (putValue(window, value, pos, column)) {
        return true;
    } else {
        window.freeLastRow();
        return false;
    }
}
 
Example #12
Source File: SQLiteCursor.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Fill row with the given value. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded, false if window is full.
 */
private boolean fillRow(CursorWindow window, Object value, int pos, int column) {
    if (putValue(window, value, pos, column)) {
        return true;
    } else {
        window.freeLastRow();
        return false;
    }
}
 
Example #13
Source File: CursorUtils.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
public static void upgradeCursorWindowSize(final Cursor cursor) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
        if (cursor instanceof AbstractWindowedCursor) {
            final AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor) cursor;
            windowedCursor.setWindow(new CursorWindow("4M", 4 * 1024 * 1024));
        }
        if (cursor instanceof SQLiteCursor) {
            ((SQLiteCursor) cursor).setFillWindowForwardOnly(true);
        }
    }
}
 
Example #14
Source File: DBType.java    From BobEngine with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static int getType(Cursor cursor, int i) {
    SQLiteCursor sqLiteCursor = (SQLiteCursor) cursor;
    CursorWindow cursorWindow = sqLiteCursor.getWindow();
    int pos = cursor.getPosition();
    int type = -1;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // Honeycomb or later.
        type = cursor.getType(i);

        if (type == Cursor.FIELD_TYPE_BLOB) {
            type = FIELD_TYPE_BLOB;
        } else if (type == Cursor.FIELD_TYPE_FLOAT) {
            type = FIELD_TYPE_FLOAT;
        } else if (type == Cursor.FIELD_TYPE_INTEGER) {
            type = FIELD_TYPE_INTEGER;
        } else if (type == Cursor.FIELD_TYPE_NULL) {
            type = FIELD_TYPE_NULL;
        } else if (type == Cursor.FIELD_TYPE_STRING) {
            type = FIELD_TYPE_STRING;
        }
    } else {                                           // Before Honeycomb
        if (cursorWindow.isNull(pos, i)) {
            type = FIELD_TYPE_NULL;
        } else if (cursorWindow.isLong(pos, i)) {
            type = FIELD_TYPE_INTEGER;
        } else if (cursorWindow.isFloat(pos, i)) {
            type = FIELD_TYPE_FLOAT;
        } else if (cursorWindow.isString(pos, i)) {
            type = FIELD_TYPE_STRING;
        } else if (cursorWindow.isBlob(pos, i)) {
            type = FIELD_TYPE_BLOB;
        }
    }

    return type;
}
 
Example #15
Source File: SQLiteCursor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Fill row with the given value. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded, false if window is full.
 */
private boolean fillRow(CursorWindow window, Object value, int pos, int column) {
    if (putValue(window, value, pos, column)) {
        return true;
    } else {
        window.freeLastRow();
        return false;
    }
}
 
Example #16
Source File: CursorUtils.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
public static void upgradeCursorWindowSize(final Cursor cursor) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
        if (cursor instanceof AbstractWindowedCursor) {
            final AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor) cursor;
            windowedCursor.setWindow(new CursorWindow("4M", 4 * 1024 * 1024));
        }
        if (cursor instanceof SQLiteCursor) {
            ((SQLiteCursor) cursor).setFillWindowForwardOnly(true);
        }
    }
}
 
Example #17
Source File: CrossProcessCursorWrapper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (mCursor instanceof CrossProcessCursor) {
        final CrossProcessCursor crossProcessCursor = (CrossProcessCursor)mCursor;
        crossProcessCursor.fillWindow(position, window);
        return;
    }

    DatabaseUtils.cursorFillWindow(mCursor, position, window);
}
 
Example #18
Source File: ImpsProvider.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        moveToPosition(position - 1);
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        boolean isFull = false;
        int numRows = 10;

        while (!isFull && --numRows > 0 && moveToNext() && window.allocRow()) {
            for (int i = 0; i < columnNum; i++) {
                String field = getString(i);
                if (field != null) {
                    if (!window.putString(field, getPosition(), i)) {
                        window.freeLastRow();
                        isFull = true;
                        break;
                    }
                } else {
                    if (!window.putNull(getPosition(), i)) {
                        window.freeLastRow();
                        isFull = true;
                        break;
                    }
                }
            }
        }
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example #19
Source File: SQLiteCursor.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Fill row with the given value. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded, false if window is full.
 */
private boolean fillRow(CursorWindow window, Object value, int pos, int column) {
    if (putValue(window, value, pos, column)) {
        return true;
    } else {
        window.freeLastRow();
        return false;
    }
}
 
Example #20
Source File: SQLiteCursor.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Fill row with the given value. If the value type is other than Long,
 * String, byte[] or Double, the NULL will be filled.
 *
 * @return true if succeeded, false if window is full.
 */
private boolean fillRow(CursorWindow window, Object value, int pos, int column) {
    if (putValue(window, value, pos, column)) {
        return true;
    } else {
        window.freeLastRow();
        return false;
    }
}
 
Example #21
Source File: CursorWindowAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public CursorWindowAssert(CursorWindow actual) {
  super(actual, CursorWindowAssert.class);
}
 
Example #22
Source File: SQLiteCursor.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        int oldpos = getPosition();
        moveToPosition(position - 1);
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        while (moveToNext() && window.allocRow()) {
            int pos = getPosition();
            for (int i = 0; i < columnNum; i++) {
                boolean hasRoom = true;
                switch (getColumnType(i)) {
                    case Types.DOUBLE:
                        hasRoom = fillRow(window, Double.valueOf(getDouble(i)), pos, i);
                        break;
                    case Types.NUMERIC:
                        hasRoom = fillRow(window, Long.valueOf(getLong(i)), pos, i);
                        break;
                    case Types.BLOB:
                        hasRoom = fillRow(window, getBlob(i), pos, i);
                        break;
                    case Types.LONGVARCHAR:
                        hasRoom = fillRow(window, getString(i), pos, i);
                        break;
                    case Types.NULL:
                        hasRoom = fillRow(window, null, pos, i);
                        break;
                    default:
                        // Ignore an unknown type.
                }
                if (!hasRoom) {
                    break;
                }
            }
        }
        moveToPosition(oldpos);
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example #23
Source File: SQLiteConnection.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Executes a statement and populates the specified {@link CursorWindow}
 * with a range of results.  Returns the number of rows that were counted
 * during query execution.
 *
 * @param sql The SQL statement to execute.
 * @param bindArgs The arguments to bind, or null if none.
 * @param window The cursor window to clear and fill.
 * @param startPos The start position for filling the window.
 * @param requiredPos The position of a row that MUST be in the window.
 * If it won't fit, then the query should discard part of what it filled
 * so that it does.  Must be greater than or equal to <code>startPos</code>.
 * @param countAllRows True to count all rows that the query would return
 * regagless of whether they fit in the window.
 * @param cancellationSignal A signal to cancel the operation in progress, or null if none.
 * @return The number of rows that were counted during query execution.  Might
 * not be all rows in the result set unless <code>countAllRows</code> is true.
 *
 * @throws SQLiteException if an error occurs, such as a syntax error
 * or invalid number of bind arguments.
 * @throws OperationCanceledException if the operation was canceled.
 */
public int executeForCursorWindow(String sql, Object[] bindArgs,
        CursorWindow window, int startPos, int requiredPos, boolean countAllRows,
        CancellationSignal cancellationSignal) {
    if (sql == null) {
        throw new IllegalArgumentException("sql must not be null.");
    }
    if (window == null) {
        throw new IllegalArgumentException("window must not be null.");
    }

    window.acquireReference();
    try {
        int actualPos = -1;
        int countedRows = -1;
        int filledRows = -1;
        final int cookie = mRecentOperations.beginOperation("executeForCursorWindow",
                sql, bindArgs);
        try {
            final PreparedStatement statement = acquirePreparedStatement(sql);
            try {
                throwIfStatementForbidden(statement);
                bindArguments(statement, bindArgs);
                applyBlockGuardPolicy(statement);
                attachCancellationSignal(cancellationSignal);
                try {
                    final long result = nativeExecuteForCursorWindow(
                            mConnectionPtr, statement.mStatementPtr, window.mWindowPtr,
                            startPos, requiredPos, countAllRows);
                    actualPos = (int)(result >> 32);
                    countedRows = (int)result;
                    filledRows = window.getNumRows();
                    window.setStartPosition(actualPos);
                    return countedRows;
                } finally {
                    detachCancellationSignal(cancellationSignal);
                }
            } finally {
                releasePreparedStatement(statement);
            }
        } catch (RuntimeException ex) {
            mRecentOperations.failOperation(cookie, ex);
            throw ex;
        } finally {
            if (mRecentOperations.endOperationDeferLog(cookie)) {
                mRecentOperations.logOperation(cookie, "window='" + window
                        + "', startPos=" + startPos
                        + ", actualPos=" + actualPos
                        + ", filledRows=" + filledRows
                        + ", countedRows=" + countedRows);
            }
        }
    } finally {
        window.releaseReference();
    }
}
 
Example #24
Source File: SQLiteCursor.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        int oldpos = mPos;
        mPos = position - 1;
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        while (moveToNext() && window.allocRow()) {
            for (int i = 0; i < columnNum; i++) {
                boolean hasRoom = true;
                switch (getColumnType(i)) {
                    case Types.DOUBLE:
                        hasRoom = fillRow(window, Double.valueOf(getDouble(i)), mPos, i);
                        break;
                    case Types.NUMERIC:
                        hasRoom = fillRow(window, Long.valueOf(getLong(i)), mPos, i);
                        break;
                    case Types.BLOB:
                        hasRoom = fillRow(window, getBlob(i), mPos, i);
                        break;
                    case Types.LONGVARCHAR:
                        hasRoom = fillRow(window, getString(i), mPos, i);
                        break;
                    case Types.NULL:
                        hasRoom = fillRow(window, null, mPos, i);
                        break;
                }
                if (!hasRoom) {
                    break;
                }
            }
        }
        mPos = oldpos;
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example #25
Source File: SQLiteCursor.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void setWindow(CursorWindow window) {
    super.setWindow(window);
    mCount = NO_COUNT;
}
 
Example #26
Source File: SQLiteCursor.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        int oldpos = getPosition();
        moveToPosition(position - 1);
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        while (moveToNext() && window.allocRow()) {
            int pos = getPosition();
            for (int i = 0; i < columnNum; i++) {
                boolean hasRoom = true;
                switch (getColumnType(i)) {
                    case Types.DOUBLE:
                        hasRoom = fillRow(window, Double.valueOf(getDouble(i)), pos, i);
                        break;
                    case Types.NUMERIC:
                        hasRoom = fillRow(window, Long.valueOf(getLong(i)), pos, i);
                        break;
                    case Types.BLOB:
                        hasRoom = fillRow(window, getBlob(i), pos, i);
                        break;
                    case Types.LONGVARCHAR:
                        hasRoom = fillRow(window, getString(i), pos, i);
                        break;
                    case Types.NULL:
                        hasRoom = fillRow(window, null, pos, i);
                        break;
                    default:
                        // Ignore an unknown type.
                }
                if (!hasRoom) {
                    break;
                }
            }
        }
        moveToPosition(oldpos);
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example #27
Source File: SQLiteCursor.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        int oldpos = mPos;
        mPos = position - 1;
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        while (moveToNext() && window.allocRow()) {
            for (int i = 0; i < columnNum; i++) {
                boolean hasRoom = true;
                switch (getColumnType(i)) {
                    case Types.DOUBLE:
                        hasRoom = fillRow(window, Double.valueOf(getDouble(i)), mPos, i);
                        break;
                    case Types.NUMERIC:
                        hasRoom = fillRow(window, Long.valueOf(getLong(i)), mPos, i);
                        break;
                    case Types.BLOB:
                        hasRoom = fillRow(window, getBlob(i), mPos, i);
                        break;
                    case Types.LONGVARCHAR:
                        hasRoom = fillRow(window, getString(i), mPos, i);
                        break;
                    case Types.NULL:
                        hasRoom = fillRow(window, null, mPos, i);
                        break;
                }
                if (!hasRoom) {
                    break;
                }
            }
        }
        mPos = oldpos;
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example #28
Source File: SQLiteCursor.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void fillWindow(int position, CursorWindow window) {
    if (position < 0 || position > getCount()) {
        return;
    }
    window.acquireReference();
    try {
        int oldpos = getPosition();
        moveToPosition(position - 1);
        window.clear();
        window.setStartPosition(position);
        int columnNum = getColumnCount();
        window.setNumColumns(columnNum);
        while (moveToNext() && window.allocRow()) {
            int pos = getPosition();
            for (int i = 0; i < columnNum; i++) {
                boolean hasRoom = true;
                switch (getColumnType(i)) {
                    case Types.DOUBLE:
                        hasRoom = fillRow(window, Double.valueOf(getDouble(i)), pos, i);
                        break;
                    case Types.NUMERIC:
                        hasRoom = fillRow(window, Long.valueOf(getLong(i)), pos, i);
                        break;
                    case Types.BLOB:
                        hasRoom = fillRow(window, getBlob(i), pos, i);
                        break;
                    case Types.LONGVARCHAR:
                        hasRoom = fillRow(window, getString(i), pos, i);
                        break;
                    case Types.NULL:
                        hasRoom = fillRow(window, null, pos, i);
                        break;
                    default:
                        // Ignore an unknown type.
                }
                if (!hasRoom) {
                    break;
                }
            }
        }
        moveToPosition(oldpos);
    } catch (IllegalStateException e) {
        // simply ignore it
    } finally {
        window.releaseReference();
    }
}
 
Example #29
Source File: FastCursor.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public FastCursor(CursorWindow cursorwindow)
{
    window = cursorwindow;
    count = cursorwindow.getNumRows();
}
 
Example #30
Source File: SQLiteCursor.java    From squidb with Apache License 2.0 4 votes vote down vote up
@Override
public void setWindow(CursorWindow window) {
    super.setWindow(window);
    mCount = NO_COUNT;
}