A
A
Alexander Popov2015-09-21 17:50:01
Android
Alexander Popov, 2015-09-21 17:50:01

Switching to Realm, how to execute such a request?

I'm moving the project to realm, how can I query multiple tables in it?
There was a request like this:

public Integer getPrescriptionsCount(Date from, Date to) {
        List<PrescriptionItem> items = new ArrayList<>();
        SQLiteDatabase db = this.getWritableDatabase();
        try {
            String selectQuery = "SELECT  * FROM " + TABLE_PRESCRIPTIONS + "," + TABLE_EXEC_TEMPLATE
                    + " WHERE " + TABLE_PRESCRIPTIONS + "." + KEY_PRESCRIPTIONS_START_DATE + " <= '" + dateFormatWOutTime.format(from) + " 00:00:00' AND ("
                    + TABLE_PRESCRIPTIONS + "." + KEY_PRESCRIPTIONS_END_DATE + " >= '" + dateFormatWOutTime.format(to) + " 99:99:99'"
                    + " OR " + TABLE_PRESCRIPTIONS + "." + KEY_PRESCRIPTIONS_END_DATE + " IS NULL)"
                    + " AND " + TABLE_EXEC_TEMPLATE + "." + KEY_EXEC_TEMPLATE_PRESCRIPTION_ID + " = " + TABLE_PRESCRIPTIONS + "." + KEY_ID
                    + " ORDER BY " + TABLE_EXEC_TEMPLATE + "." + KEY_EXEC_TEMPLATE_DISPLAY_ORDER;

            Log.e(LOG, selectQuery);
            Cursor c = db.rawQuery(selectQuery, null);
            return c.getCount();
        } finally {
            db.close();
        }
    }

how to transfer it to realm?
ps yes, you can't say that the request is adequate, but what web service -> such and database -> such and request (sad)
pps Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question