-
Notifications
You must be signed in to change notification settings - Fork 10
To Cursor
Siim Kinks edited this page Nov 21, 2016
·
1 revision
To get a raw android.database.Cursor for query, just call toCursor on the query builder API. Then one can either parse each row manually or call getFromCurrentPosition(Cursor) which parses current cursor position according to defined query.
import static com.siimkinks.sqlitemagic.AuthorTable.AUTHOR;
CompiledCursorSelect<Author, SelectN> compiledQuery = Select
.from(AUTHOR)
.toCursor();
Cursor cursor = null;
try {
cursor = compiledQuery.execute();
while (cursor.moveToNext()) {
// parse result manually or
Author currentPosAuthor = cursorSelect.getFromCurrentPosition(cursor);
}
} finally {
// always close the cursor!
if (cursor != null) {
cursor.close();
}
}
// or using try-with-resources
try (Cursor cursor = cursorSelect.execute()) {
while (cursor.moveToNext()) {
// parse result manually or
Author currentPosAuthor = cursorSelect.getFromCurrentPosition(cursor);
}
}