From 7a8db90425dc32ab8f31eb609bfe73999e6dec3e Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 11 Mar 2014 00:14:04 +0100 Subject: [PATCH] join cert info into query routines --- .../keychain/provider/KeychainProvider.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java index bd74de1d7..095887433 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -485,6 +485,8 @@ public class KeychainProvider extends ContentProvider { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); SQLiteDatabase db = mApgDatabase.getReadableDatabase(); + String groupBy = null; + int match = mUriMatcher.match(uri); // screw that switch @@ -677,8 +679,25 @@ public class KeychainProvider extends ContentProvider { case PUBLIC_KEY_RING_USER_ID: case SECRET_KEY_RING_USER_ID: - qb.setTables(Tables.USER_IDS); - qb.appendWhere(UserIdsColumns.KEY_RING_ROW_ID + " = "); + qb.setTables(Tables.USER_IDS + + " LEFT JOIN " + Tables.CERTS + + " ON (" + + Tables.USER_IDS + "." + UserIds.KEY_RING_ROW_ID + " = " + + Tables.CERTS + "." + Certs.KEY_RING_ROW_ID + + " AND " + Tables.USER_IDS + "." + UserIds.RANK + " = " + + Tables.CERTS + "." + Certs.RANK + + ")"); + + groupBy = Tables.USER_IDS + "." + UserIds.RANK; + + HashMap pmap = new HashMap(); + pmap.put(UserIds._ID, Tables.USER_IDS + "." + UserIds._ID); + pmap.put(UserIds.USER_ID, Tables.USER_IDS + "." + UserIds.USER_ID); + pmap.put(UserIds.RANK, Tables.USER_IDS + "." + UserIds.RANK); + pmap.put("verified", "COUNT(" + Tables.CERTS + "." + Certs._ID + ") AS verified"); + qb.setProjectionMap(pmap); + + qb.appendWhere(Tables.USER_IDS + "." + UserIdsColumns.KEY_RING_ROW_ID + " = "); qb.appendWhereEscapeString(uri.getPathSegments().get(2)); break; @@ -725,7 +744,7 @@ public class KeychainProvider extends ContentProvider { orderBy = sortOrder; } - Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy); + Cursor c = qb.query(db, projection, selection, selectionArgs, groupBy, null, orderBy); // Tell the cursor what uri to watch, so it knows when its source data changes c.setNotificationUri(getContext().getContentResolver(), uri);