use of android.database.sqlite.SQLiteQueryBuilder in project apps-android-commons by commons-app.
the class CategoryContentProvider method query.
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(Category.Table.TABLE_NAME);
int uriType = uriMatcher.match(uri);
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor;
switch(uriType) {
case CATEGORIES:
cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
break;
case CATEGORIES_ID:
cursor = queryBuilder.query(db, Category.Table.ALL_FIELDS, "_id = ?", new String[] { uri.getLastPathSegment() }, null, null, sortOrder);
break;
default:
throw new IllegalArgumentException("Unknown URI" + uri);
}
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
use of android.database.sqlite.SQLiteQueryBuilder in project apps-android-commons by commons-app.
the class ModificationsContentProvider method query.
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(ModifierSequence.Table.TABLE_NAME);
int uriType = uriMatcher.match(uri);
switch(uriType) {
case MODIFICATIONS:
break;
default:
throw new IllegalArgumentException("Unknown URI" + uri);
}
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
use of android.database.sqlite.SQLiteQueryBuilder in project android_frameworks_base by crdroidandroid.
the class SyncStorageEngine method readAndDeleteLegacyAccountInfoLocked.
/**
* Load sync engine state from the old syncmanager database, and then
* erase it. Note that we don't deal with pending operations, active
* sync, or history.
*/
private void readAndDeleteLegacyAccountInfoLocked() {
// Look for old database to initialize from.
File file = mContext.getDatabasePath("syncmanager.db");
if (!file.exists()) {
return;
}
String path = file.getPath();
SQLiteDatabase db = null;
try {
db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
} catch (SQLiteException e) {
}
if (db != null) {
final boolean hasType = db.getVersion() >= 11;
// Copy in all of the status information, as well as accounts.
if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
Slog.v(TAG_FILE, "Reading legacy sync accounts db");
}
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables("stats, status");
HashMap<String, String> map = new HashMap<String, String>();
map.put("_id", "status._id as _id");
map.put("account", "stats.account as account");
if (hasType) {
map.put("account_type", "stats.account_type as account_type");
}
map.put("authority", "stats.authority as authority");
map.put("totalElapsedTime", "totalElapsedTime");
map.put("numSyncs", "numSyncs");
map.put("numSourceLocal", "numSourceLocal");
map.put("numSourcePoll", "numSourcePoll");
map.put("numSourceServer", "numSourceServer");
map.put("numSourceUser", "numSourceUser");
map.put("lastSuccessSource", "lastSuccessSource");
map.put("lastSuccessTime", "lastSuccessTime");
map.put("lastFailureSource", "lastFailureSource");
map.put("lastFailureTime", "lastFailureTime");
map.put("lastFailureMesg", "lastFailureMesg");
map.put("pending", "pending");
qb.setProjectionMap(map);
qb.appendWhere("stats._id = status.stats_id");
Cursor c = qb.query(db, null, null, null, null, null, null);
while (c.moveToNext()) {
String accountName = c.getString(c.getColumnIndex("account"));
String accountType = hasType ? c.getString(c.getColumnIndex("account_type")) : null;
if (accountType == null) {
accountType = "com.google";
}
String authorityName = c.getString(c.getColumnIndex("authority"));
AuthorityInfo authority = this.getOrCreateAuthorityLocked(new EndPoint(new Account(accountName, accountType), authorityName, 0), -1, false);
if (authority != null) {
int i = mSyncStatus.size();
boolean found = false;
SyncStatusInfo st = null;
while (i > 0) {
i--;
st = mSyncStatus.valueAt(i);
if (st.authorityId == authority.ident) {
found = true;
break;
}
}
if (!found) {
st = new SyncStatusInfo(authority.ident);
mSyncStatus.put(authority.ident, st);
}
st.totalElapsedTime = getLongColumn(c, "totalElapsedTime");
st.numSyncs = getIntColumn(c, "numSyncs");
st.numSourceLocal = getIntColumn(c, "numSourceLocal");
st.numSourcePoll = getIntColumn(c, "numSourcePoll");
st.numSourceServer = getIntColumn(c, "numSourceServer");
st.numSourceUser = getIntColumn(c, "numSourceUser");
st.numSourcePeriodic = 0;
st.lastSuccessSource = getIntColumn(c, "lastSuccessSource");
st.lastSuccessTime = getLongColumn(c, "lastSuccessTime");
st.lastFailureSource = getIntColumn(c, "lastFailureSource");
st.lastFailureTime = getLongColumn(c, "lastFailureTime");
st.lastFailureMesg = c.getString(c.getColumnIndex("lastFailureMesg"));
st.pending = getIntColumn(c, "pending") != 0;
}
}
c.close();
// Retrieve the settings.
qb = new SQLiteQueryBuilder();
qb.setTables("settings");
c = qb.query(db, null, null, null, null, null, null);
while (c.moveToNext()) {
String name = c.getString(c.getColumnIndex("name"));
String value = c.getString(c.getColumnIndex("value"));
if (name == null)
continue;
if (name.equals("listen_for_tickles")) {
setMasterSyncAutomatically(value == null || Boolean.parseBoolean(value), 0);
} else if (name.startsWith("sync_provider_")) {
String provider = name.substring("sync_provider_".length(), name.length());
int i = mAuthorities.size();
while (i > 0) {
i--;
AuthorityInfo authority = mAuthorities.valueAt(i);
if (authority.target.provider.equals(provider)) {
authority.enabled = value == null || Boolean.parseBoolean(value);
authority.syncable = 1;
}
}
}
}
c.close();
db.close();
(new File(path)).delete();
}
}
use of android.database.sqlite.SQLiteQueryBuilder in project android_frameworks_base by AOSPA.
the class MtpDatabase method queryRoots.
/**
* Queries roots information.
* @param columnNames Column names defined in {@link android.provider.DocumentsContract.Root}.
* @return Database cursor.
*/
Cursor queryRoots(Resources resources, String[] columnNames) {
final String selection = COLUMN_ROW_STATE + " IN (?, ?) AND " + COLUMN_DOCUMENT_TYPE + " = ?";
final Cursor deviceCursor = mDatabase.query(TABLE_DOCUMENTS, strings(COLUMN_DEVICE_ID), selection, strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_DEVICE), COLUMN_DEVICE_ID, null, null, null);
try {
final SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
builder.setTables(JOIN_ROOTS);
builder.setProjectionMap(COLUMN_MAP_ROOTS);
final MatrixCursor result = new MatrixCursor(columnNames);
final ContentValues values = new ContentValues();
while (deviceCursor.moveToNext()) {
final int deviceId = deviceCursor.getInt(0);
final Cursor storageCursor = builder.query(mDatabase, columnNames, selection + " AND " + COLUMN_DEVICE_ID + " = ?", strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_STORAGE, deviceId), null, null, null);
try {
values.clear();
try (final Cursor deviceRoot = builder.query(mDatabase, columnNames, selection + " AND " + COLUMN_DEVICE_ID + " = ?", strings(ROW_STATE_VALID, ROW_STATE_INVALIDATED, DOCUMENT_TYPE_DEVICE, deviceId), null, null, null)) {
deviceRoot.moveToNext();
DatabaseUtils.cursorRowToContentValues(deviceRoot, values);
}
if (storageCursor.getCount() != 0) {
long capacityBytes = 0;
long availableBytes = 0;
final int capacityIndex = storageCursor.getColumnIndex(Root.COLUMN_CAPACITY_BYTES);
final int availableIndex = storageCursor.getColumnIndex(Root.COLUMN_AVAILABLE_BYTES);
while (storageCursor.moveToNext()) {
// don't calculate corresponding values.
if (capacityIndex != -1) {
capacityBytes += storageCursor.getLong(capacityIndex);
}
if (availableIndex != -1) {
availableBytes += storageCursor.getLong(availableIndex);
}
}
values.put(Root.COLUMN_CAPACITY_BYTES, capacityBytes);
values.put(Root.COLUMN_AVAILABLE_BYTES, availableBytes);
} else {
values.putNull(Root.COLUMN_CAPACITY_BYTES);
values.putNull(Root.COLUMN_AVAILABLE_BYTES);
}
if (storageCursor.getCount() == 1 && values.containsKey(Root.COLUMN_TITLE)) {
storageCursor.moveToFirst();
// Add storage name to device name if we have only 1 storage.
values.put(Root.COLUMN_TITLE, resources.getString(R.string.root_name, values.getAsString(Root.COLUMN_TITLE), storageCursor.getString(storageCursor.getColumnIndex(Root.COLUMN_TITLE))));
}
} finally {
storageCursor.close();
}
final RowBuilder row = result.newRow();
for (final String key : values.keySet()) {
row.add(key, values.get(key));
}
}
return result;
} finally {
deviceCursor.close();
}
}
use of android.database.sqlite.SQLiteQueryBuilder in project K6nele by Kaljurand.
the class AppsContentProvider method query.
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
switch(sUriMatcher.match(uri)) {
case APPS:
qb.setTables(APPS_TABLE_NAME);
qb.setProjectionMap(appsProjectionMap);
break;
case GRAMMARS:
qb.setTables(GRAMMARS_TABLE_NAME);
qb.setProjectionMap(grammarsProjectionMap);
break;
case SERVERS:
qb.setTables(SERVERS_TABLE_NAME);
qb.setProjectionMap(serversProjectionMap);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
Aggregations