public Message InsertMessage(Message message) { ContentValues values = new ContentValues(); values.put(DataBaseHelper.message_contentType, message.getContentType()); values.put(DataBaseHelper.message_status, message.getStatus()); values.put(DataBaseHelper.message_FK_receiverUserId, message.getFK_receiverUserId()); values.put(DataBaseHelper.message_Content, message.getContent()); values.put(DataBaseHelper.message_FK_senderUserId, message.getFK_senderUserId()); values.put(DataBaseHelper.message_date, message.getDate()); values.put(DataBaseHelper.message_type, message.getType()); values.put(DataBaseHelper.message_messageId, message.getMessageId()); values.put(DataBaseHelper.message_input, message.getInput()); long insertId = database.insert(DataBaseHelper.TABLE_message, null, values); message.setMessageId(insertId); return message; }
public Message GetSingleMessage(Long id) { Cursor cursor = database.query( DataBaseHelper.TABLE_message, allColumns, DataBaseHelper.message_messageId + "=?", new String[] {String.valueOf(id)}, null, null, null); cursor.moveToFirst(); Message message = new Message(); if (cursor.getCount() > 0) message = CursorToMessage(cursor); else message.setMessageId(Long.valueOf(-1)); cursor.close(); return message; }
public Message CursorToMessage(Cursor cursor) { Message message = new Message(); message.setContentType( cursor.getInt(cursor.getColumnIndex(DataBaseHelper.message_contentType))); message.setStatus(cursor.getInt(cursor.getColumnIndex(DataBaseHelper.message_status))); message.setFK_receiverUserId( cursor.getLong(cursor.getColumnIndex(DataBaseHelper.message_FK_receiverUserId))); message.setContent(cursor.getString(cursor.getColumnIndex(DataBaseHelper.message_Content))); message.setFK_senderUserId( cursor.getLong(cursor.getColumnIndex(DataBaseHelper.message_FK_senderUserId))); message.setDate(cursor.getString(cursor.getColumnIndex(DataBaseHelper.message_date))); message.setType(cursor.getInt(cursor.getColumnIndex(DataBaseHelper.message_type))); message.setMessageId(cursor.getLong(cursor.getColumnIndex(DataBaseHelper.message_messageId))); message.setInput(cursor.getInt(cursor.getColumnIndex(DataBaseHelper.message_input))); return message; }