use of com.orgzly.android.query.Query in project orgzly-android by orgzly.
the class Provider method runUserQuery.
private Cursor runUserQuery(SQLiteDatabase db, String queryString, String sortOrder) {
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, queryString, sortOrder);
QueryParser parser = new InternalQueryParser();
Query query = parser.parse(queryString);
SqliteQueryBuilder queryBuilder = new SqliteQueryBuilder(getContext());
SqlQuery sqlQuery = queryBuilder.build(query);
// If order hasn't been passed, try getting it from the query.
if (sortOrder == null) {
sortOrder = sqlQuery.getOrderBy();
}
List<String> selections = new ArrayList<>();
// if (!TextUtils.isEmpty(sqlQuery.getSelection())) {
if (query.getCondition() != null) {
selections.add(sqlQuery.getSelection());
}
if (query.getOptions().getAgendaDays() > 0) {
selections.add(DatabaseUtils.WHERE_NOTES_WITH_TIMES);
}
if (!selections.isEmpty() || !query.getSortOrders().isEmpty()) {
selections.add(DatabaseUtils.WHERE_EXISTING_NOTES);
}
String selection = selections.isEmpty() ? "0" : TextUtils.join(" AND ", selections);
String[] selectionArgs = sqlQuery.getSelectionArgs().toArray(new String[sqlQuery.getSelectionArgs().size()]);
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, query, query.getCondition(), sqlQuery.getOrderBy(), selection, selectionArgs, sortOrder);
return db.query(DbNoteView.VIEW_NAME, null, selection, selectionArgs, null, null, sortOrder);
}
Aggregations