Last active
March 7, 2016 13:52
-
-
Save kassim/c340cbfc5243db3a4826 to your computer and use it in GitHub Desktop.
A support method for the API 11 method Cursor.getType(int i) - for a cursor retuned by an SQL query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DbCompat { | |
protected static final int FIELD_TYPE_BLOB = 4; | |
protected static final int FIELD_TYPE_FLOAT = 2; | |
protected static final int FIELD_TYPE_INTEGER = 1; | |
protected static final int FIELD_TYPE_NULL = 0; | |
protected static final int FIELD_TYPE_STRING = 3; | |
public static int getType(Cursor cursor, int i) throws Exception { | |
SQLiteCursor sqLiteCursor = (SQLiteCursor) cursor; | |
CursorWindow cursorWindow = sqLiteCursor.getWindow(); | |
int pos = cursor.getPosition(); | |
int type = -1; | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment