android.database.CursorWindow

Here are the examples of the java api class android.database.CursorWindow taken from open source projects.

1. SQLiteAndroidDatabase#bindPreHoneycomb()

Project: react-native-sqlite-storage
File: 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));
    } else if (cursorWindow.isBlob(pos, i)) {
        row.put(key, new String(Base64.encode(cursor.getBlob(i), Base64.DEFAULT)));
    } else {
        // string
        row.put(key, cursor.getString(i));
    }
}

2. SQLitePlugin#bindPreHoneycomb()

Project: react-native-sqlite-storage
File: SQLitePlugin.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));
    } else if (cursorWindow.isBlob(pos, i)) {
        row.put(key, new String(Base64.encode(cursor.getBlob(i), Base64.DEFAULT)));
    } else {
        // string
        row.put(key, cursor.getString(i));
    }
}

3. SQLiteCursor#awc_clearOrCreateWindow()

Project: squidb
File: SQLiteCursor.java
/* 
    ** The AbstractWindowClass contains protected methods clearOrCreateWindow() and
    ** closeWindow(), which are used by the android.database.sqlite.* version of this
    ** class. But, since they are marked with "@hide", the following replacement 
    ** versions are required.
    */
private void awc_clearOrCreateWindow(String name) {
    CursorWindow win = getWindow();
    if (win == null) {
        win = new CursorWindow(name);
        setWindow(win);
    } else {
        win.clear();
    }
}

4. SQLiteConnection#collectDbStats()

Project: squidb
File: SQLiteConnection.java
/**
     * Collects statistics about database connection memory usage.
     *
     * @param dbStatsList The list to populate.
     */
void collectDbStats(ArrayList<DbStats> dbStatsList) {
    // Get information about the main database.
    int lookaside = nativeGetDbLookaside(mConnectionPtr);
    long pageCount = 0;
    long pageSize = 0;
    try {
        pageCount = executeForLong("PRAGMA page_count;", null, null);
        pageSize = executeForLong("PRAGMA page_size;", null, null);
    } catch (SQLiteException ex) {
    }
    dbStatsList.add(getMainDbStatsUnsafe(lookaside, pageCount, pageSize));
    // Get information about attached databases.
    // We ignore the first row in the database list because it corresponds to
    // the main database which we have already described.
    CursorWindow window = new CursorWindow("collectDbStats");
    try {
        executeForCursorWindow("PRAGMA database_list;", null, window, 0, 0, false, null);
        for (int i = 1; i < window.getNumRows(); i++) {
            String name = window.getString(i, 1);
            String path = window.getString(i, 2);
            pageCount = 0;
            pageSize = 0;
            try {
                pageCount = executeForLong("PRAGMA " + name + ".page_count;", null, null);
                pageSize = executeForLong("PRAGMA " + name + ".page_size;", null, null);
            } catch (SQLiteException ex) {
            }
            String label = "  (attached) " + name;
            if (!path.isEmpty()) {
                label += ": " + path;
            }
            dbStatsList.add(new DbStats(label, pageCount, pageSize, 0, 0, 0, 0));
        }
    } catch (SQLiteException ex) {
    } finally {
        window.close();
    }
}