change user_id primary key in database, use keyring rather than unified query in consolidate

This commit is contained in:
Vincent Breitmoser 2015-03-11 18:28:36 +01:00
parent 82a2a76a33
commit 9ff4d7b2bc
3 changed files with 26 additions and 14 deletions

View File

@ -109,6 +109,15 @@ public class WrappedUserAttribute implements Serializable {
}
public byte[][] getSubpackets() {
UserAttributeSubpacket[] subpackets = mVector.toSubpacketArray();
byte[][] ret = new byte[subpackets.length][];
for (int i = 0; i < subpackets.length; i++) {
ret[i] = subpackets[i].getData();
}
return ret;
}
private void readObjectNoData() throws ObjectStreamException {
}

View File

@ -53,7 +53,7 @@ import java.io.IOException;
*/
public class KeychainDatabase extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "openkeychain.db";
private static final int DATABASE_VERSION = 8;
private static final int DATABASE_VERSION = 9;
static Boolean apgHack = false;
private Context mContext;
@ -61,7 +61,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
String KEY_RINGS_PUBLIC = "keyrings_public";
String KEY_RINGS_SECRET = "keyrings_secret";
String KEYS = "keys";
String USER_PACKETS = "user_ids";
String USER_PACKETS = "user_packets";
String CERTS = "certs";
String API_APPS = "api_apps";
String API_ACCOUNTS = "api_accounts";
@ -119,8 +119,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
+ UserPacketsColumns.IS_REVOKED + " INTEGER, "
+ UserPacketsColumns.RANK+ " INTEGER, "
+ "PRIMARY KEY(" + UserPacketsColumns.MASTER_KEY_ID + ", " + UserPacketsColumns.USER_ID + "), "
+ "UNIQUE (" + UserPacketsColumns.MASTER_KEY_ID + ", " + UserPacketsColumns.RANK + "), "
+ "PRIMARY KEY(" + UserPacketsColumns.MASTER_KEY_ID + ", " + UserPacketsColumns.RANK + "), "
+ "FOREIGN KEY(" + UserPacketsColumns.MASTER_KEY_ID + ") REFERENCES "
+ Tables.KEY_RINGS_PUBLIC + "(" + KeyRingsColumns.MASTER_KEY_ID + ") ON DELETE CASCADE"
+ ")";
@ -267,6 +266,13 @@ public class KeychainDatabase extends SQLiteOpenHelper {
} catch (Exception e) {
// never mind, the column probably already existed
}
case 9:
// tbale name for user_ids changed to user_packets
db.execSQL("DROP TABLE IF EXISTS certs");
db.execSQL("DROP TABLE IF EXISTS user_ids");
db.execSQL(CREATE_USER_PACKETS);
db.execSQL(CREATE_CERTS);
}
// always do consolidate after upgrade

View File

@ -1082,9 +1082,8 @@ public class ProviderHelper {
log.add(LogType.MSG_CON_SAVE_SECRET, indent);
indent += 1;
final Cursor cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(), new String[]{
KeyRings.PRIVKEY_DATA, KeyRings.FINGERPRINT, KeyRings.HAS_ANY_SECRET
}, KeyRings.HAS_ANY_SECRET + " = 1", null, null);
final Cursor cursor = mContentResolver.query(KeyRingData.buildSecretKeyRingUri(),
new String[]{ KeyRingData.KEY_RING_DATA }, null, null, null);
if (cursor == null) {
log.add(LogType.MSG_CON_ERROR_DB, indent);
@ -1106,8 +1105,7 @@ public class ProviderHelper {
if (cursor.isAfterLast()) {
return false;
}
ring = new ParcelableKeyRing(KeyFormattingUtils.convertFingerprintToHex(cursor.getBlob(1)), cursor.getBlob(0)
);
ring = new ParcelableKeyRing(cursor.getBlob(0));
cursor.moveToNext();
return true;
}
@ -1144,9 +1142,9 @@ public class ProviderHelper {
log.add(LogType.MSG_CON_SAVE_PUBLIC, indent);
indent += 1;
final Cursor cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(), new String[]{
KeyRings.PUBKEY_DATA, KeyRings.FINGERPRINT
}, null, null, null);
final Cursor cursor = mContentResolver.query(
KeyRingData.buildPublicKeyRingUri(),
new String[]{ KeyRingData.KEY_RING_DATA }, null, null, null);
if (cursor == null) {
log.add(LogType.MSG_CON_ERROR_DB, indent);
@ -1168,8 +1166,7 @@ public class ProviderHelper {
if (cursor.isAfterLast()) {
return false;
}
ring = new ParcelableKeyRing(KeyFormattingUtils.convertFingerprintToHex(cursor.getBlob(1)), cursor.getBlob(0)
);
ring = new ParcelableKeyRing(cursor.getBlob(0));
cursor.moveToNext();
return true;
}