Example usage for android.database.sqlite SQLiteQueryBuilder setTables

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

Introduction

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

Prototype

public void setTables(String inTables) 

Source Link

Document

Sets the list of tables to query.

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);
    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  w  ww . j a  va2 s  .c  o m
            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 www.  j a v  a  2 s.c om*/
        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:com.hyunnyapp.easycursor.sqlcursor.querymodels.SelectQueryModel.java

@Override
protected Cursor executeQueryInternal(final SQLiteDatabase db) {
    final SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(getTables());
    builder.setDistinct(isDistinct());/*from   www.j  ava 2 s. c o m*/

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        builder.setStrict(isStrict());
    }

    return builder.query(db, getProjectionIn(), getSelection(), getSelectionArgs(), getGroupBy(), getHaving(),
            getSortOrder(), getLimit());
}

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://  ww  w.  j av a  2s.  c  om
        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 w w  .  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 = 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:/*  w  w  w .ja  v a2  s. co  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;
}

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

/**
 * Performs a database query./* w w  w.j  a v a 2 s. com*/
 *
 * @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./*from w  w  w. j  a v  a 2s .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);

    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:org.mozilla.labs.Soup.provider.AppsProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    qb.setTables(APPS_TABLE_NAME);

    switch (sUriMatcher.match(uri)) {
    case APPS:/*from w w w.  j a  v  a  2 s.  c  o  m*/
        qb.setProjectionMap(sAppsProjectionMap);
        break;

    case APP_ID:
        qb.setProjectionMap(sAppsProjectionMap);
        qb.appendWhere(Apps._ID + "=" + uri.getPathSegments().get(1));
        break;

    case LIVE_FOLDER_APPS:
        qb.setProjectionMap(sLiveFolderProjectionMap);
        break;

    default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    // If no sort order is specified use the default
    String orderBy;
    if (TextUtils.isEmpty(sortOrder)) {
        orderBy = AppsContract.Apps.DEFAULT_SORT_ORDER;
    } else {
        orderBy = sortOrder;
    }

    // Get the database and run the query
    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);

    // Tell the cursor what uri to watch, so it knows when its source data
    // changes
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}