Search in sources :

Example 1 with SqliteQueryBuilder

use of com.orgzly.android.query.sql.SqliteQueryBuilder 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);
}
Also used : InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) QueryParser(com.orgzly.android.query.QueryParser) InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) SqlQuery(com.orgzly.android.query.sql.SqlQuery) Query(com.orgzly.android.query.Query) SqlQuery(com.orgzly.android.query.sql.SqlQuery) SqliteQueryBuilder(com.orgzly.android.query.sql.SqliteQueryBuilder) ArrayList(java.util.ArrayList)

Aggregations

Query (com.orgzly.android.query.Query)1 QueryParser (com.orgzly.android.query.QueryParser)1 SqlQuery (com.orgzly.android.query.sql.SqlQuery)1 SqliteQueryBuilder (com.orgzly.android.query.sql.SqliteQueryBuilder)1 InternalQueryParser (com.orgzly.android.query.user.InternalQueryParser)1 ArrayList (java.util.ArrayList)1