Example usage for android.database.sqlite SQLiteQueryBuilder query

List of usage examples for android.database.sqlite SQLiteQueryBuilder query

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteQueryBuilder query.

Prototype

public Cursor query(SQLiteDatabase db, String[] projectionIn, String selection, String[] selectionArgs,
        String groupBy, String having, String sortOrder) 

Source Link

Document

Perform a query by combining all current settings and the information passed into this method.

Usage

From source file:org.emergent.android.weave.syncadapter.SyncCache.java

private static Cursor query(SQLiteDatabase db, String tableName, String[] projectionin, String whereClause,
        String[] selectionArgs) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(tableName);//  w  w w  . j  a  v  a 2s .co m
    return qb.query(db, projectionin, whereClause, selectionArgs, null, null, null /* sortOrder */);
}

From source file:com.nadmm.airports.library.LibraryMainFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mViewPager = (ViewPager) findViewById(R.id.content_pager);
    mViewPager.setOnPageChangeListener(this);

    mTabsAdapter = new TabsAdapter(getActivity(), getChildFragmentManager(), mViewPager);

    SQLiteDatabase db = getDatabase(DatabaseManager.DB_LIBRARY);
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(BookCategories.TABLE_NAME);
    Cursor c = builder.query(db, new String[] { "*" }, null, null, null, null, BookCategories._ID);
    if (c.moveToFirst()) {
        do {//from   ww w .  j  a  va 2 s  .c om
            String code = c.getString(c.getColumnIndex(BookCategories.CATEGORY_CODE));
            String name = c.getString(c.getColumnIndex(BookCategories.CATEGORY_NAME));
            Bundle args = new Bundle();
            args.putString(BookCategories.CATEGORY_CODE, code);
            mTabsAdapter.addTab(name, LibraryPageFragment.class, args);
        } while (c.moveToNext());
    }

    // Setup list navigation mode
    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    String[] titles = mTabsAdapter.getPageTitles();
    NavAdapter adapter = new NavAdapter(actionBar.getThemedContext(), R.string.library, titles);
    actionBar.setListNavigationCallbacks(adapter, this);
    actionBar.setDisplayShowTitleEnabled(false);

    if (savedInstanceState != null) {
        // Workaround for race conditions in ViewPager
        // See: http://code.google.com/p/android/issues/detail?id=29472
        final int lastPos = savedInstanceState.getInt("libtab");
        mViewPager.post(new Runnable() {

            @Override
            public void run() {
                setCurrentPage(lastPos);
            }
        });
    }
}

From source file:com.nadmm.airports.library.LibraryActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setActionBarTitle("Library", null);

    mReceivers = new HashMap<>();
    mReceiver = new BroadcastReceiver() {

        @Override/*from w w w  .  jav a2 s  .com*/
        public void onReceive(Context context, Intent intent) {
            String category = intent.getStringExtra(LibraryService.CATEGORY);
            BroadcastReceiver receiver = mReceivers.get(category);
            if (receiver != null) {
                receiver.onReceive(context, intent);
            }

            // Show the PDF here as the Fragment requesting it may be paused
            String action = intent.getAction();

            if (action.equals(LibraryService.ACTION_GET_BOOK)) {
                String path = intent.getStringExtra(LibraryService.PDF_PATH);
                mPending = false;
                if (path != null) {
                    SystemUtils.startPDFViewer(LibraryActivity.this, path);
                }
            }
        }
    };
    mFilter = new IntentFilter();
    mFilter.setPriority(10);
    mFilter.addAction(LibraryService.ACTION_CHECK_BOOKS);
    mFilter.addAction(LibraryService.ACTION_GET_BOOK);
    mFilter.addAction(LibraryService.ACTION_DOWNLOAD_PROGRESS);

    SQLiteDatabase db = getDatabase(DatabaseManager.DB_LIBRARY);
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(DatabaseManager.BookCategories.TABLE_NAME);
    Cursor c = builder.query(db, new String[] { "*" }, null, null, null, null,
            DatabaseManager.BookCategories._ID);
    populateTabs(c);

    //setBackgroundTask( new LibraryCategoryTask() ).execute( "" );
}

From source file:edu.nd.darts.cimon.database.CimonDatabaseAdapter.java

/**
 * Perform query on database using pre-constructed query builder.
 *  /*from ww  w.  j av a  2  s . c om*/
 * @param queryBuilder     query to perform on database
 * @param projection       the list of columns to put into the cursor. If null all 
 *                           columns are included
 * @param selection        A selection criteria to apply when filtering rows. If null 
 *                           then all rows are included
 * @param selectionArgs    You may include ?s in selection, which will be replaced by 
 *                           the values from selectionArgs, in order that they appear 
 *                           in the selection. The values will be bound as Strings
 * @param sortOrder        How the rows in the cursor should be sorted. If null then 
 *                           the provider is free to define the sort order
 * @return    a Cursor or null
 */
public synchronized Cursor query(SQLiteQueryBuilder queryBuilder, String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {
    Cursor cursor = queryBuilder.query(database, projection, selection, selectionArgs, null, null, sortOrder);

    return cursor;
}

From source file:com.example.android.tvleanback2.data.VideoDatabase.java

/**
 * Performs a database query./*from  w w  w  . j  a  v a 2 s  . c o  m*/
 *
 * @param selection     The selection clause
 * @param selectionArgs Selection arguments for "?" components in the selection
 * @param columns       The columns to return
 * @return A Cursor over all rows matching the query
 */
private Cursor query(String selection, String[] selectionArgs, String[] columns) {
    /* The SQLiteBuilder provides a map for all possible columns requested to
     * actual columns in the database, creating a simple column alias mechanism
     * by which the ContentProvider does not need to know the real column names
     */
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(FTS_VIRTUAL_TABLE);
    builder.setProjectionMap(COLUMN_MAP);

    return builder.query(mDatabaseOpenHelper.getReadableDatabase(), columns, selection, selectionArgs, null,
            null, null);
}

From source file:com.example.android.dragonTV.data.VideoDatabase.java

/**
 * Performs a database query./*w w w .ja  v a2 s .co m*/
 *
 * @param selection     The selection clause
 * @param selectionArgs Selection arguments for "?" components in the selection
 * @param columns       The columns to return
 * @return A Cursor over all rows matching the query
 */
private Cursor query(String selection, String[] selectionArgs, String[] columns) {
    /* The SQLiteBuilder provides a map for all possible columns requested to
     * actual columns in the database, creating a simple column alias mechanism
     * by which the ContentProvider does not need to know the real column names
     */
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(FTS_VIRTUAL_TABLE);
    builder.setProjectionMap(COLUMN_MAP);

    Cursor cursor = new PaginatedCursor(builder.query(mDatabaseOpenHelper.getReadableDatabase(), columns,
            selection, selectionArgs, null, null, null));

    if (cursor == null) {
        return null;
    } else if (!cursor.moveToFirst()) {
        cursor.close();
        return null;
    }
    return cursor;
}

From source file:com.money.manager.ex.MmxContentProvider.java

private Cursor query_internal(Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sortOrder) {/*w  w w.j  a  v  a2  s .  c o  m*/
    Timber.d("Querying URI: %s", uri);

    // find object from uri
    Object sourceObject = getObjectFromUri(uri);

    initializeDependencies();

    SQLiteDatabase database = openHelper.get().getReadableDatabase();
    if (database == null) {
        Timber.e("Database could not be opened");
        return null;
    }

    Cursor cursor;

    // check type of instance data set
    if (Dataset.class.isInstance(sourceObject)) {
        Dataset dataset = ((Dataset) sourceObject);

        //            logQuery(dataset, projection, selection, selectionArgs, sortOrder);

        switch (dataset.getType()) {
        case QUERY:
            String query = prepareQuery(dataset.getSource(), projection, selection, sortOrder);
            cursor = database.rawQuery(query, selectionArgs);
            break;
        case SQL:
            cursor = database.rawQuery(selection, selectionArgs);
            break;
        case TABLE:
        case VIEW:
            SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
            queryBuilder.setTables(dataset.getSource());
            cursor = queryBuilder.query(database, projection, selection, selectionArgs, null, null, sortOrder);
            break;
        default:
            throw new IllegalArgumentException("Type of dataset not defined");
        }
    } else {
        throw new IllegalArgumentException("Object sourceObject of mapContent is not instance of dataset");
    }

    // notify listeners waiting for the data is ready
    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    if (!cursor.isClosed()) {
        Timber.d("Rows returned: %d", cursor.getCount());
    }

    return cursor;
}

From source file:com.manning.androidhacks.hack043.provider.MySQLContentProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    switch (sUriMatcher.match(uri)) {
    case ITEM:// w ww . ja  v  a 2s  .  c o  m
        qb.setTables(TABLE_NAME);
        qb.setProjectionMap(projectionMap);
        break;
    case ITEM_ID:
        qb.setTables(TABLE_NAME);
        qb.setProjectionMap(projectionMap);
        qb.appendWhere(COLUMN_ID + "=" + uri.getPathSegments().get(1));
        break;
    default:
        throw new RuntimeException("Unknown URI");
    }

    SQLiteDatabase db = getDatabaseHelper().getReadableDatabase();
    Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);

    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}

From source file:com.manning.androidhacks.hack043.provider.BatchNumbersContentProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    switch (sUriMatcher.match(uri)) {
    case ITEM://  w ww. ja v  a2s  .c o m
        qb.setTables(TABLE_NAME);
        qb.setProjectionMap(projectionMap);
        break;
    case ITEM_ID:
        qb.setTables(TABLE_NAME);
        qb.setProjectionMap(projectionMap);
        qb.appendWhere(COLUMN_ID + "=" + uri.getPathSegments().get(1));
        break;
    default:
        throw new RuntimeException("Unknown URI");
    }

    SQLiteDatabase db = dbHelper.getReadableDatabase();
    Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);

    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}

From source file:com.manning.androidhacks.hack023.provider.TodoContentProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    switch (sUriMatcher.match(uri)) {
    case TODO://from  w w  w .ja  v  a2 s .c o m
        qb.setTables(TODO_TABLE_NAME);
        qb.setProjectionMap(projectionMap);
        break;
    case TODO_ID:
        qb.setTables(TODO_TABLE_NAME);
        qb.setProjectionMap(projectionMap);
        qb.appendWhere(COLUMN_ID + "=" + uri.getPathSegments().get(1));
        break;
    default:
        throw new RuntimeException("Unknown URI");
    }

    SQLiteDatabase db = dbHelper.getReadableDatabase();
    Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);

    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}