Created
June 24, 2011 20:20
-
-
Save mobibob/1045593 to your computer and use it in GitHub Desktop.
Android cursor dump
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 dumpCursor(Cursor myCursor) { | |
if (myCursor == null) { | |
Logs.w(TAG, "Null cursor"); | |
} else { | |
try { | |
if (myCursor.moveToFirst()) { | |
String [] columns = myCursor.getColumnNames(); | |
StringBuilder sbHeader = new StringBuilder(); | |
for (String columnName : columns) { | |
sbHeader.append(columnName).append(", "); | |
} | |
Logs.i(TAG, sbHeader.toString()); | |
do { | |
StringBuilder sbRow = new StringBuilder(); | |
for (String columnName : columns) { | |
sbRow.append(myCursor.getString(myCursor.getColumnIndex(columnName))).append(", "); | |
} | |
Logs.i(TAG, sbRow.toString()); | |
} while (myCursor.moveToNext()); | |
} else { | |
Logs.w(TAG, "Empty cursor"); | |
} | |
} catch (Exception ex) { | |
Logs.e(TAG, ex.toString()); | |
} finally { | |
if (!myCursor.isClosed()) { | |
myCursor.moveToFirst(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment