Search in sources :

Example 6 with Query

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);
}
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)6 QueryParser (com.orgzly.android.query.QueryParser)3 InternalQueryParser (com.orgzly.android.query.user.InternalQueryParser)3 Book (com.orgzly.android.Book)2 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 NavigationView (android.support.design.widget.NavigationView)1 Fragment (android.support.v4.app.Fragment)1 SearchView (android.support.v7.widget.SearchView)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 TextView (android.widget.TextView)1 Shelf (com.orgzly.android.Shelf)1 AgendaCursor (com.orgzly.android.provider.AgendaCursor)1 Condition (com.orgzly.android.query.Condition)1 SqlQuery (com.orgzly.android.query.sql.SqlQuery)1 SqliteQueryBuilder (com.orgzly.android.query.sql.SqliteQueryBuilder)1 DottedQueryBuilder (com.orgzly.android.query.user.DottedQueryBuilder)1 DottedQueryParser (com.orgzly.android.query.user.DottedQueryParser)1 InternalQueryBuilder (com.orgzly.android.query.user.InternalQueryBuilder)1