Skip to content

Commit 61a116a

Browse files
author
Karan Popali
committed
Fixed inter process blob transfer issue.
1 parent e0699ce commit 61a116a

File tree

3 files changed

+60
-67
lines changed

3 files changed

+60
-67
lines changed

src/net/sqlcipher/AbstractCursor.java

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -209,40 +209,7 @@ public final boolean moveToPosition(int position) {
209209
* @param window
210210
*/
211211
public void fillWindow(int position, android.database.CursorWindow window) {
212-
if (position < 0 || position >= getCount()) {
213-
return;
214-
}
215-
window.acquireReference();
216-
try {
217-
int oldpos = mPos;
218-
mPos = position - 1;
219-
window.clear();
220-
window.setStartPosition(position);
221-
int columnNum = getColumnCount();
222-
window.setNumColumns(columnNum);
223-
while (moveToNext() && window.allocRow()) {
224-
for (int i = 0; i < columnNum; i++) {
225-
String field = getString(i);
226-
if (field != null) {
227-
if (!window.putString(field, mPos, i)) {
228-
window.freeLastRow();
229-
break;
230-
}
231-
} else {
232-
if (!window.putNull(mPos, i)) {
233-
window.freeLastRow();
234-
break;
235-
}
236-
}
237-
}
238-
}
239-
240-
mPos = oldpos;
241-
} catch (IllegalStateException e){
242-
// simply ignore it
243-
} finally {
244-
window.releaseReference();
245-
}
212+
DatabaseUtils.cursorFillWindow(this, position, window);
246213
}
247214

248215
public final boolean move(int offset) {

src/net/sqlcipher/CrossProcessCursorWrapper.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,7 @@ public CursorWindow getWindow() {
1616

1717
@Override
1818
public void fillWindow(int position, CursorWindow window) {
19-
if (position < 0 || position > getCount()) {
20-
return;
21-
}
22-
window.acquireReference();
23-
try {
24-
moveToPosition(position - 1);
25-
window.clear();
26-
window.setStartPosition(position);
27-
int columnNum = getColumnCount();
28-
window.setNumColumns(columnNum);
29-
while (moveToNext() && window.allocRow()) {
30-
for (int i = 0; i < columnNum; i++) {
31-
String field = getString(i);
32-
if (field != null) {
33-
if (!window.putString(field, getPosition(), i)) {
34-
window.freeLastRow();
35-
break;
36-
}
37-
} else {
38-
if (!window.putNull(getPosition(), i)) {
39-
window.freeLastRow();
40-
break;
41-
}
42-
}
43-
}
44-
}
45-
} catch (IllegalStateException e) {
46-
// simply ignore it
47-
} finally {
48-
window.releaseReference();
49-
}
19+
DatabaseUtils.cursorFillWindow(this, position, window);
5020
}
5121

5222
@Override

src/net/sqlcipher/DatabaseUtils.java

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package net.sqlcipher;
1818

19-
import android.database.Cursor;
20-
2119
import net.sqlcipher.database.SQLiteAbortException;
2220
import net.sqlcipher.database.SQLiteConstraintException;
2321
import net.sqlcipher.database.SQLiteDatabase;
@@ -1137,6 +1135,64 @@ public void close() {
11371135
}
11381136
}
11391137

1138+
public static void cursorFillWindow(final Cursor cursor,
1139+
int position, final android.database.CursorWindow window) {
1140+
if (position < 0 || position >= cursor.getCount()) {
1141+
return;
1142+
}
1143+
final int oldPos = cursor.getPosition();
1144+
final int numColumns = cursor.getColumnCount();
1145+
window.clear();
1146+
window.setStartPosition(position);
1147+
window.setNumColumns(numColumns);
1148+
if (cursor.moveToPosition(position)) {
1149+
do {
1150+
if (!window.allocRow()) {
1151+
break;
1152+
}
1153+
for (int i = 0; i < numColumns; i++) {
1154+
final int type = cursor.getType(i);
1155+
final boolean success;
1156+
switch (type) {
1157+
case Cursor.FIELD_TYPE_NULL:
1158+
success = window.putNull(position, i);
1159+
break;
1160+
1161+
case Cursor.FIELD_TYPE_INTEGER:
1162+
success = window.putLong(cursor.getLong(i), position, i);
1163+
break;
1164+
1165+
case Cursor.FIELD_TYPE_FLOAT:
1166+
success = window.putDouble(cursor.getDouble(i), position, i);
1167+
break;
1168+
1169+
case Cursor.FIELD_TYPE_BLOB: {
1170+
final byte[] value = cursor.getBlob(i);
1171+
success = value != null ? window.putBlob(value, position, i)
1172+
: window.putNull(position, i);
1173+
break;
1174+
}
1175+
1176+
default: // assume value is convertible to String
1177+
case Cursor.FIELD_TYPE_STRING: {
1178+
final String value = cursor.getString(i);
1179+
success = value != null ? window.putString(value, position, i)
1180+
: window.putNull(position, i);
1181+
break;
1182+
}
1183+
}
1184+
if (!success) {
1185+
window.freeLastRow();
1186+
break;
1187+
}
1188+
}
1189+
position += 1;
1190+
} while (cursor.moveToNext());
1191+
}
1192+
cursor.moveToPosition(oldPos);
1193+
}
1194+
1195+
11401196
/**
11411197
* Creates a db and populates it with the sql statements in sqlStatements.
11421198
*

0 commit comments

Comments
 (0)