use of android.database.sqlite.SQLiteQueryBuilder in project carat by amplab.
the class CaratSampleDB method query.
/**
* Performs a database query.
*
* @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, String groupBy, String having, String sortOrder) {
/*
* 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(SAMPLES_VIRTUAL_TABLE);
builder.setProjectionMap(mColumnMap);
Cursor cursor = builder.query(db, columns, selection, selectionArgs, groupBy, having, sortOrder);
if (cursor == null) {
return null;
} else if (!cursor.moveToFirst()) {
cursor.close();
return null;
}
return cursor;
}
use of android.database.sqlite.SQLiteQueryBuilder in project Shuttle by timusus.
the class CustomArtworkContentProvider method query.
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
// Using SQLiteQueryBuilder instead of query() method
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
// Check if the caller has requested a column which does not exists
checkColumns(projection);
// Set the table
queryBuilder.setTables(CustomArtworkTable.TABLE_ARTIST_ART);
int uriType = sURIMatcher.match(uri);
switch(uriType) {
case CUSTOM_ARTWORK:
break;
default:
throw new IllegalArgumentException("Unknown URI: " + uri);
}
SQLiteDatabase db = database.getWritableDatabase();
Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
// Make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
use of android.database.sqlite.SQLiteQueryBuilder in project 9GAG by stormzhang.
the class DataProvider method query.
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
synchronized (DBLock) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
String table = matchTable(uri);
queryBuilder.setTables(table);
SQLiteDatabase db = getDBHelper().getReadableDatabase();
Cursor cursor = // The database to
queryBuilder.query(// The database to
db, // The columns to return from the queryFromDB
projection, // The columns for the where clause
selection, // The values for the where clause
selectionArgs, // don't group the rows
null, // don't filter by row groups
null, // The sort order
sortOrder);
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
}
use of android.database.sqlite.SQLiteQueryBuilder in project greenDAO by greenrobot.
the class SimpleEntityContentProvider method query.
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
int uriType = sURIMatcher.match(uri);
switch(uriType) {
case SIMPLEENTITY_DIR:
queryBuilder.setTables(TABLENAME);
break;
case SIMPLEENTITY_ID:
queryBuilder.setTables(TABLENAME);
queryBuilder.appendWhere(PK + "=" + uri.getLastPathSegment());
break;
default:
throw new IllegalArgumentException("Unknown URI: " + uri);
}
Database db = getDatabase();
Cursor cursor = queryBuilder.query(((StandardDatabase) db).getSQLiteDatabase(), projection, selection, selectionArgs, null, null, sortOrder);
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
use of android.database.sqlite.SQLiteQueryBuilder in project cardslib by gabrielemariotti.
the class CardCursorProvider method query.
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
Log.d(TAG, "query(uri=" + uri + ", proj=" + Arrays.toString(projection) + ")");
// Open a read-only database.
SQLiteDatabase db = myOpenHelper.getWritableDatabase();
// Replace these with valid SQL statements if necessary.
String groupBy = null;
String having = null;
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
String rowID = "";
// If this is a row query, limit the result set to the passed in row.
switch(uriMatcher.match(uri)) {
case CardCursor_SINGLE_ROW:
queryBuilder.setTables(CardCursorSQLiteOpenHelper.Tables.CardCursor);
rowID = uri.getPathSegments().get(1);
queryBuilder.appendWhere(CardCursorContract.CardCursor.KeyColumns.KEY_ID + "=" + rowID);
break;
case CardCursor_ALLROWS:
queryBuilder.setTables(CardCursorSQLiteOpenHelper.Tables.CardCursor);
if (TextUtils.isEmpty(sortOrder)) {
sortOrder = CardCursorContract.CardCursor.DEFAULT_SORT;
}
break;
default:
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, groupBy, having, sortOrder);
// Make sure that potential listeners are getting notified
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
Aggregations