From 7e20226b519dd84fcba98ffa678bbad9eff9a8bf Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Sat, 13 Mar 2010 20:28:39 +0100 Subject: [PATCH] Workaround: Remove identity assigned to server if server is deleted until we have some kind of identity manager --- src/org/yaaic/db/Database.java | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/org/yaaic/db/Database.java b/src/org/yaaic/db/Database.java index 3666e32..5fa8c00 100644 --- a/src/org/yaaic/db/Database.java +++ b/src/org/yaaic/db/Database.java @@ -281,6 +281,16 @@ public class Database extends SQLiteOpenHelper */ public void removeServerById(int serverId) { + // XXX: Workaround: Remove identity assigned to this server + // until we have some kind of identity manager + int identityId = this.getIdentityIdByServerId(serverId); + if (identityId != -1) { + this.getWritableDatabase().execSQL( + "DELETE FROM " + IdentityConstants.TABLE_NAME + " WHERE " + IdentityConstants._ID + " = " + identityId + ";" + ); + } + + // Now delete the server entry this.getWritableDatabase().execSQL( "DELETE FROM " + ServerConstants.TABLE_NAME + " WHERE " + ServerConstants._ID + " = " + serverId + ";" ); @@ -361,4 +371,29 @@ public class Database extends SQLiteOpenHelper return null; } + + /** + * Get a server by its id + * + * @param serverId + * @return + */ + private int getIdentityIdByServerId(int serverId) + { + Cursor cursor = this.getReadableDatabase().query( + ServerConstants.TABLE_NAME, + ServerConstants.ALL, + ServerConstants._ID + "=" + serverId, + null, + null, + null, + null + ); + + if (cursor.moveToNext()) { + return cursor.getInt(cursor.getColumnIndex(ServerConstants.IDENTITY)); + } + + return -1; + } }