List of usage examples for android.database.sqlite SQLiteQueryBuilder SQLiteQueryBuilder
public SQLiteQueryBuilder()
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 {/* w w w . jav a 2s . 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 a2 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.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:/*from w ww.j av 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. j av a 2s .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; }
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);//from www . j av a2 s .com switch (sUriMatcher.match(uri)) { case APPS: 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; }
From source file:org.thomnichols.android.gmarks.GmarksProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); // Log.d(TAG, "Managed query: " + uri); String groupBy = null;//w ww. j a v a2 s. c om String orderBy = null; String limit = null; switch (sUriMatcher.match(uri)) { case BOOKMARKS_URI: qb.setTables(BOOKMARKS_TABLE_NAME); qb.setProjectionMap(bookmarksProjectionMap); String labelID = uri.getQueryParameter("label_id"); if (labelID != null) { qb.setTables("bookmarks join bookmark_labels on bookmarks._id = bookmark_labels.bookmark_id"); qb.appendWhere("bookmark_labels.label_id=?"); selectionArgs = (String[]) ArrayUtils.addAll(selectionArgs, new String[] { labelID }); } break; case BOOKMARK_SEARCH_URI: case BOOKMARK_SEARCH_SUGGEST_URI: String query = null; if (sUriMatcher.match(uri) == BOOKMARK_SEARCH_SUGGEST_URI) { qb.setProjectionMap(searchSuggestProjectionMap); // path looks like "search_suggest_query/[query]?limit=50 query = uri.getLastPathSegment(); limit = uri.getQueryParameter("limit"); if (sortOrder == null) sortOrder = Bookmark.Columns.SORT_MODIFIED; } else query = uri.getQueryParameter("q"); if (query != null) { qb.setTables("bookmarks join bookmarks_FTS on bookmarks._id = bookmarks_FTS.docid"); qb.appendWhere("bookmarks_FTS MATCH ?"); if (selectionArgs == null) selectionArgs = new String[] { query }; else selectionArgs = (String[]) ArrayUtils.addAll(selectionArgs, new String[] { query }); } else if (selectionArgs == null || selectionArgs.length < 1) throw new IllegalArgumentException("No search criteria given for query!"); break; case BOOKMARK_ID_URI: qb.setTables(BOOKMARKS_TABLE_NAME); qb.setProjectionMap(bookmarksProjectionMap); qb.appendWhere(Bookmark.Columns._ID + "=" + uri.getPathSegments().get(1)); break; case LABELS_URI: qb.setTables("labels join bookmark_labels on labels._id = bookmark_labels.label_id"); groupBy = "label"; if (sortOrder == null) sortOrder = Label.Columns.DEFAULT_SORT_ORDER; qb.setProjectionMap(labelsProjectionMap); break; case LIVE_FOLDER_BOOKMARKS_URI: qb.setTables(BOOKMARKS_TABLE_NAME); qb.setProjectionMap(sLiveFolderProjectionMap); String labelId = uri.getQueryParameter("label_id"); if (labelId != null) { qb.setTables("bookmarks join bookmark_labels on bookmarks._id = bookmark_labels.bookmark_id"); qb.appendWhere("bookmark_labels.label_id=?"); selectionArgs = (String[]) ArrayUtils.addAll(selectionArgs, new String[] { labelId }); } sortOrder = "modified DESC"; // for some reason this gets set to 'name ASC' break; case BOOKMARK_LISTS_URI: qb.setTables(BookmarkList.TABLE_NAME); qb.setProjectionMap(listsProjectionMap); if (sortOrder == null) sortOrder = BookmarkList.Columns.DEFAULT_SORT_ORDER; String type = uri.getQueryParameter(BookmarkList.PARAM_CATEGORY); if (BookmarkList.LISTS_PRIVATE.equals(type)) qb.appendWhere("owned=1"); else if (BookmarkList.LISTS_SHARED.equals(type)) qb.appendWhere("shared=1"); else if (BookmarkList.LISTS_PUBLIC.equals(type)) qb.appendWhere("publshed=1"); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } // If no sort order is specified use the default if (TextUtils.isEmpty(sortOrder)) { orderBy = Bookmark.Columns.DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } // Get the database and run the query SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, groupBy, null, orderBy, limit); // Tell the cursor what uri to watch, so it knows when its source data changes c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
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());/*w w w. j av a 2 s. c om*/ builder.setDistinct(isDistinct()); 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.amazonaws.mobileconnectors.s3.transferutility.TransferDBBase.java
/** * Query records from the database.//from w w w . j a v a2s .co m * * @param uri A Uri indicating which part of data to query. * @param projection The projection of columns. * @param selection The "where" clause of sql. * @param selectionArgs Strings in the "where" clause. * @param sortOrder Sorting order of the query. * @param type Type of transfers to query. * @return A Cursor pointing to records. */ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); // TODO: currently all methods calling this pass null to projection. // In the future we want to update projection to be more specific for // performance and must handle that here. queryBuilder.setTables(TransferTable.TABLE_TRANSFER); final int uriType = uriMatcher.match(uri); switch (uriType) { case TRANSFERS: queryBuilder.appendWhere(TransferTable.COLUMN_PART_NUM + "=" + 0); break; case TRANSFER_ID: queryBuilder.appendWhere(TransferTable.COLUMN_ID + "=" + uri.getLastPathSegment()); break; case TRANSFER_PART: queryBuilder.appendWhere(TransferTable.COLUMN_MAIN_UPLOAD_ID + "=" + uri.getLastPathSegment()); break; case TRANSFER_STATE: queryBuilder.appendWhere(TransferTable.COLUMN_STATE + "="); queryBuilder.appendWhereEscapeString(uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } ensureDatabaseOpen(); final Cursor cursor = queryBuilder.query(database, projection, selection, selectionArgs, null, null, sortOrder); return cursor; }
From source file:com.appsimobile.appsii.module.apps.AppsProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); // Generate the body of the query int match = sURLMatcher.match(uri); switch (match) { // loads all tagged-apps in a given tag. case TABLE_APPS_ITEM: long id = ContentUris.parseId(uri); qb.setTables(TaggedAppColumns.TABLE_NAME + "," + TagColumns.TABLE_NAME); qb.setProjectionMap(sAppsProjectionMap); qb.appendWhere(TaggedAppColumns.TAG_ID + "=" + id + " AND "); qb.appendWhere("taggedApps.tag_id=tags._id"); break;//from w w w .ja va 2 s . c o m // loads all tagged apps case TABLE_APPS: qb.setTables(TaggedAppColumns.TABLE_NAME + "," + TagColumns.TABLE_NAME); qb.setProjectionMap(sAppsProjectionMap); qb.appendWhere("taggedApps.tag_id=tags._id"); break; // loads items in the launch history table case TABLE_HISTORY: qb.setTables(LaunchHistoryColumns.TABLE_NAME); qb.setProjectionMap(sHistoryProjectionMap); break; // loads all tags case TABLE_TAGS: qb.setTables(TagColumns.TABLE_NAME); qb.setProjectionMap(sTagsProjectionMap); break; default: throw new IllegalArgumentException("Invalid uri: " + uri); } return qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); }
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 .java2 s . 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; }