mapToOne issue.
kiranbollepalli opened this issue · comments
Kiran Bollepalli commented
Hi,
I am trying to get data corresponding to given filter date string. If db has matching records it is returning fine, But if it is not found it is not returning anything. Could you tell me how to handle it?
Note: for one "filterMonth" i will have one record only at max, cant have multiple so i am trying to use "mapToOne".
String query = "SELECT * FROM "
+ Db.CustomerDashboardDetailsTable.TABLE_NAME
+ " WHERE "
+ Db.CustomerDashboardDetailsTable.COLUMN_FILTER_DATE
+ " LIKE "
+ " '"
+ filterMonth
+ "' ";
Timber.e("getCustomerDashboardDetailsForMonth : query " + query);
return mDb.createQuery(Db.CustomerDashboardDetailsTable.TABLE_NAME, query)
.mapToOne(new Func1<Cursor, CustomerInvoiceAndPaymentDetailsResponse>() {
@Override public CustomerInvoiceAndPaymentDetailsResponse call(Cursor cursor) {
Timber.i("Cursor : " + cursor.getCount());
return Db.CustomerDashboardDetailsTable.parseCursor(cursor);
}
});
Alec Kazakova commented
you probably want to use mapToOneOrNull
or mapToOneOrDefault
instead of mapToOne