db-overhaul: different hack for type info (api level problem inside)

This commit is contained in:
Vincent Breitmoser 2014-04-04 11:39:23 +02:00
parent a1e13f7893
commit a9f868a5e7

View File

@ -69,26 +69,14 @@ public class ProviderHelper {
HashMap<String, Object> result = new HashMap<String, Object>(proj.length); HashMap<String, Object> result = new HashMap<String, Object>(proj.length);
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
// this is a HACK because we don't have Cursor.getType (which is api level 11)
CursorWindow cursorWindow;
if(cursor instanceof CursorWrapper) {
cursorWindow = ((SQLiteCursor) ((CursorWrapper) cursor).getWrappedCursor()).getWindow();
} else {
cursorWindow = ((SQLiteCursor) cursor).getWindow();
}
int pos = 0; int pos = 0;
for(String p : proj) { for(String p : proj) {
if (cursorWindow.isNull(0, pos)) { switch(cursor.getType(pos)) {
result.put(p, cursor.isNull(pos)); case Cursor.FIELD_TYPE_NULL: result.put(p, cursor.isNull(pos)); break;
} else if (cursorWindow.isLong(0, pos)) { case Cursor.FIELD_TYPE_INTEGER: result.put(p, cursor.getLong(pos)); break;
result.put(p, cursor.getLong(pos)); case Cursor.FIELD_TYPE_FLOAT: result.put(p, cursor.getFloat(pos)); break;
} else if (cursorWindow.isFloat(0, pos)) { case Cursor.FIELD_TYPE_STRING: result.put(p, cursor.getString(pos)); break;
result.put(p, cursor.getFloat(pos)); case Cursor.FIELD_TYPE_BLOB: result.put(p, cursor.getBlob(pos)); break;
} else if (cursorWindow.isString(0, pos)) {
result.put(p, cursor.getString(pos));
} else if (cursorWindow.isBlob(0, pos)) {
result.put(p, cursor.getBlob(pos));
} }
pos += 1; pos += 1;
} }