Last active
December 29, 2016 13:44
-
-
Save 5pecia1/38f7d2e41f4cd852cf4def07da07724f to your computer and use it in GitHub Desktop.
log all values(records) in Cursor on Android
This file contains 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
private void logAllValuesInCursor(Cursor cursor) { | |
if (cursor.moveToFirst()) { | |
do { | |
logAllValuesInCurrentCursor(cursor); | |
} while (cursor.moveToNext()); | |
} else { | |
Log.e("test_file", "cursor is empty"); | |
} | |
} | |
private void logAllValuesInCurrentCursor(Cursor cursor) { | |
for (String columnName : cursor.getColumnNames()) { | |
int columnIndex = cursor.getColumnIndex(columnName); | |
String result = ""; | |
switch (cursor.getType(columnIndex)) { | |
case Cursor.FIELD_TYPE_BLOB: | |
byte[] recordBlob = cursor.getBlob(columnIndex); | |
result += "field_type : BLOB, value : " + recordBlob; //TODO customize | |
break; | |
case Cursor.FIELD_TYPE_FLOAT: | |
float recordFloat = cursor.getFloat(columnIndex); | |
result += "field_type : FLOAT, value : " + recordFloat; | |
break; | |
case Cursor.FIELD_TYPE_INTEGER: | |
int recordInt = cursor.getInt(columnIndex); | |
result += "field_type : INTEGER, value : " + recordInt; | |
break; | |
case Cursor.FIELD_TYPE_STRING: | |
String recordString = cursor.getString(columnIndex); | |
result += "field_type : STRING, value : " + recordString; | |
break; | |
case Cursor.FIELD_TYPE_NULL: | |
result += "field_type : NULL"; | |
break; | |
default: | |
break; | |
} | |
Log.i("test_file", "column_name : " + columnName + ", " + result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment