square / sqlbrite

A lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operations.

Home Page:https://square.github.io/sqlbrite/3.x/sqlbrite/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mapToOne issue.

kiranbollepalli opened this issue · comments

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);
          }
        });

you probably want to use mapToOneOrNull or mapToOneOrDefault instead of mapToOne