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 robolectric by robolectric.
the class SQLiteQueryBuilderTest method setUp.
@Before
public void setUp() throws Exception {
database = SQLiteDatabase.create(null);
database.execSQL("create table " + TABLE_NAME + " (" + COL_VALUE + " TEXT, " + COL_GROUP + " INTEGER" + ")");
ContentValues values = new ContentValues();
values.put(COL_VALUE, "record1");
values.put(COL_GROUP, 1);
firstRecordId = database.insert(TABLE_NAME, null, values);
assertThat(firstRecordId).isGreaterThan(0);
values.clear();
values.put(COL_VALUE, "record2");
values.put(COL_GROUP, 1);
long secondRecordId = database.insert(TABLE_NAME, null, values);
assertThat(secondRecordId).isGreaterThan(0).isNotEqualTo(firstRecordId);
values.clear();
values.put(COL_VALUE, "won't be selected");
values.put(COL_GROUP, 2);
database.insert(TABLE_NAME, null, values);
builder = new SQLiteQueryBuilder();
builder.setTables(TABLE_NAME);
builder.appendWhere(COL_VALUE + " <> ");
builder.appendWhereEscapeString("won't be selected");
}
use of android.database.sqlite.SQLiteQueryBuilder in project cw-omnibus by commonsguy.
the class Provider method query.
@Override
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sort) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(TABLE);
String orderBy;
if (TextUtils.isEmpty(sort)) {
orderBy = Constants.DEFAULT_SORT_ORDER;
} else {
orderBy = sort;
}
Cursor c = qb.query(db.getReadableDatabase(), projection, selection, selectionArgs, null, null, orderBy);
c.setNotificationUri(getContext().getContentResolver(), url);
return (c);
}
use of android.database.sqlite.SQLiteQueryBuilder in project cw-advandroid by commonsguy.
the class Provider method query.
@Override
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sort) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(TABLE);
String orderBy;
if (TextUtils.isEmpty(sort)) {
orderBy = Constants.DEFAULT_SORT_ORDER;
} else {
orderBy = sort;
}
Cursor c = qb.query(db.getReadableDatabase(), projection, selection, selectionArgs, null, null, orderBy);
c.setNotificationUri(getContext().getContentResolver(), url);
return (c);
}
use of android.database.sqlite.SQLiteQueryBuilder in project cw-advandroid by commonsguy.
the class Provider method query.
@Override
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sort) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(TABLE);
String orderBy;
if (TextUtils.isEmpty(sort)) {
orderBy = Constants.DEFAULT_SORT_ORDER;
} else {
orderBy = sort;
}
Cursor c = qb.query(db.getReadableDatabase(), projection, selection, selectionArgs, null, null, orderBy);
c.setNotificationUri(getContext().getContentResolver(), url);
return (c);
}
Aggregations