类android.database.CursorWindow源码实例Demo

下面列出了怎么用android.database.CursorWindow的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: android_9.0.0_r45   文件: SQLiteSession.java
/**
 * 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
    }
}
 
源代码2 项目: AvI   文件: SQLiteAndroidDatabase.java
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));
    }
}
 
源代码3 项目: delion   文件: SQLiteCursor.java
/**
 * 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);
    }
}
 
源代码4 项目: AndroidChromium   文件: SQLiteCursor.java
/**
 * 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);
    }
}
 
源代码5 项目: 365browser   文件: SQLiteCursor.java
/**
 * 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);
    }
}
 
源代码6 项目: squidb   文件: SQLiteSession.java
/**
 * 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
    }
}
 
源代码7 项目: android_dbinspector   文件: DatabaseHelper.java
/**
 * 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);
    }
}
 
源代码8 项目: android-chromium   文件: SQLiteCursor.java
/**
 * 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);
    }
}
 
源代码9 项目: android-chromium   文件: SQLiteCursor.java
/**
 * 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);
    }
}
 
@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);
}
 
@Override
public CursorWindow getWindow() {
    if (mCursor instanceof CrossProcessCursor) {
        final CrossProcessCursor crossProcessCursor = (CrossProcessCursor)mCursor;
        return crossProcessCursor.getWindow();
    }

    return null;
}
 
源代码12 项目: delion   文件: SQLiteCursor.java
/**
 * 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;
    }
}
 
源代码13 项目: AndroidChromium   文件: SQLiteCursor.java
/**
 * 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;
    }
}
 
源代码14 项目: Zom-Android-XMPP   文件: ImpsProvider.java
@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();
    }
}
 
源代码15 项目: Pix-Art-Messenger   文件: CursorUtils.java
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);
        }
    }
}
 
源代码16 项目: 365browser   文件: SQLiteCursor.java
/**
 * 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;
    }
}
 
源代码17 项目: BobEngine   文件: DBType.java
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;
}
 
源代码18 项目: Conversations   文件: CursorUtils.java
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);
        }
    }
}
 
源代码19 项目: android-chromium   文件: SQLiteCursor.java
/**
 * 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;
    }
}
 
源代码20 项目: android-chromium   文件: SQLiteCursor.java
/**
 * 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;
    }
}
 
源代码21 项目: android_9.0.0_r45   文件: SQLiteConnection.java
/**
 * 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();
    }
}
 
源代码22 项目: android_9.0.0_r45   文件: SQLiteCursor.java
@Override
public void setWindow(CursorWindow window) {
    super.setWindow(window);
    mCount = NO_COUNT;
}
 
源代码23 项目: delion   文件: SQLiteCursor.java
@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();
    }
}
 
源代码24 项目: AndroidChromium   文件: SQLiteCursor.java
@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();
    }
}
 
源代码25 项目: 365browser   文件: SQLiteCursor.java
@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();
    }
}
 
源代码26 项目: squidb   文件: SQLiteConnection.java
private static native long nativeExecuteForCursorWindow(
long connectionPtr, long statementPtr, CursorWindow win,
int startPos, int requiredPos, boolean countAllRows);
 
源代码27 项目: squidb   文件: SQLiteConnection.java
/**
 * 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,
                            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();
    }
}
 
源代码28 项目: squidb   文件: SQLiteCursor.java
@Override
public void setWindow(CursorWindow window) {
    super.setWindow(window);
    mCount = NO_COUNT;
}
 
源代码29 项目: MiBandDecompiled   文件: FastCursor.java
public FastCursor(CursorWindow cursorwindow)
{
    window = cursorwindow;
    count = cursorwindow.getNumRows();
}
 
源代码30 项目: android-chromium   文件: SQLiteCursor.java
@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();
    }
}
 
 类所在包