From d82db7aa38fba31de26575a1822da0a3a539a16b Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Sat, 13 Mar 2010 14:41:29 +0100 Subject: [PATCH] Database: Helper method for loading an identity by id --- src/org/yaaic/db/Database.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/org/yaaic/db/Database.java b/src/org/yaaic/db/Database.java index fe2649f..b533171 100644 --- a/src/org/yaaic/db/Database.java +++ b/src/org/yaaic/db/Database.java @@ -22,6 +22,7 @@ package org.yaaic.db; import java.util.HashMap; +import org.yaaic.model.Identity; import org.yaaic.model.Server; import org.yaaic.model.Status; @@ -290,4 +291,37 @@ public class Database extends SQLiteOpenHelper null ); } + + /** + * Get an identity by its id + * + * @param identityId + * @return + */ + public Identity getIdentityById(int identityId) + { + Cursor cursor = this.getReadableDatabase().query( + IdentityConstants.TABLE_NAME, + IdentityConstants.ALL, + IdentityConstants._ID + "=" + identityId, + null, + null, + null, + null + ); + + if (cursor.moveToNext()) { + Identity identity = new Identity(); + + identity.setNickname(cursor.getString(cursor.getColumnIndex(IdentityConstants.NICKNAME))); + identity.setIdent(cursor.getString(cursor.getColumnIndex(IdentityConstants.IDENT))); + identity.setRealName(cursor.getString(cursor.getColumnIndex(IdentityConstants.REALNAME))); + + cursor.close(); + + return identity; + } + + return null; + } }