Skip to content

Fixed inter process blob transfer issue. #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 1 addition & 34 deletions src/net/sqlcipher/AbstractCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,40 +209,7 @@ public final boolean moveToPosition(int position) {
* @param window
*/
public void fillWindow(int position, android.database.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++) {
String field = getString(i);
if (field != null) {
if (!window.putString(field, mPos, i)) {
window.freeLastRow();
break;
}
} else {
if (!window.putNull(mPos, i)) {
window.freeLastRow();
break;
}
}
}
}

mPos = oldpos;
} catch (IllegalStateException e){
// simply ignore it
} finally {
window.releaseReference();
}
DatabaseUtils.cursorFillWindow(this, position, window);
}

public final boolean move(int offset) {
Expand Down
32 changes: 1 addition & 31 deletions src/net/sqlcipher/CrossProcessCursorWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,7 @@ public CursorWindow getWindow() {

@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);
while (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();
break;
}
} else {
if (!window.putNull(getPosition(), i)) {
window.freeLastRow();
break;
}
}
}
}
} catch (IllegalStateException e) {
// simply ignore it
} finally {
window.releaseReference();
}
DatabaseUtils.cursorFillWindow(this, position, window);
}

@Override
Expand Down
60 changes: 58 additions & 2 deletions src/net/sqlcipher/DatabaseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package net.sqlcipher;

import android.database.Cursor;

import net.sqlcipher.database.SQLiteAbortException;
import net.sqlcipher.database.SQLiteConstraintException;
import net.sqlcipher.database.SQLiteDatabase;
Expand Down Expand Up @@ -1137,6 +1135,64 @@ public void close() {
}
}

public static void cursorFillWindow(final Cursor cursor,
int position, final android.database.CursorWindow window) {
if (position < 0 || position >= cursor.getCount()) {
return;
}
final int oldPos = cursor.getPosition();
final int numColumns = cursor.getColumnCount();
window.clear();
window.setStartPosition(position);
window.setNumColumns(numColumns);
if (cursor.moveToPosition(position)) {
do {
if (!window.allocRow()) {
break;
}
for (int i = 0; i < numColumns; i++) {
final int type = cursor.getType(i);
final boolean success;
switch (type) {
case Cursor.FIELD_TYPE_NULL:
success = window.putNull(position, i);
break;

case Cursor.FIELD_TYPE_INTEGER:
success = window.putLong(cursor.getLong(i), position, i);
break;

case Cursor.FIELD_TYPE_FLOAT:
success = window.putDouble(cursor.getDouble(i), position, i);
break;

case Cursor.FIELD_TYPE_BLOB: {
final byte[] value = cursor.getBlob(i);
success = value != null ? window.putBlob(value, position, i)
: window.putNull(position, i);
break;
}

default: // assume value is convertible to String
case Cursor.FIELD_TYPE_STRING: {
final String value = cursor.getString(i);
success = value != null ? window.putString(value, position, i)
: window.putNull(position, i);
break;
}
}
if (!success) {
window.freeLastRow();
break;
}
}
position += 1;
} while (cursor.moveToNext());
}
cursor.moveToPosition(oldPos);
}


/**
* Creates a db and populates it with the sql statements in sqlStatements.
*
Expand Down