Esempio n. 1
0
  /**
   * 删除一条消息
   *
   * @param msg
   * @return Boolean
   */
  public Boolean delete(MessageInfo msg) {
    Boolean boolRtn = false;
    if (null == msg) {
      return boolRtn;
    }

    SQLiteDatabase dbMaster = null;
    try {
      dbMaster = helper.getWritableDatabase();
      dbMaster.beginTransaction();
      String msgId = msg.getMessageId();
      dbMaster.delete("t_message", "" + "msgId" + " == ?", new String[] {msgId});

      dbMaster.setTransactionSuccessful();
      boolRtn = true;
    } catch (SQLException e) {
      LogUtil.info(e.toString());
    } finally {
      if (null != dbMaster) {
        dbMaster.endTransaction();
      }
      // dbMaster.close();
    }
    return boolRtn;
  }
Esempio n. 2
0
 /** 更新消息的已读状态 */
 public void updateMessageReadState(MessageInfo info) {
   SQLiteDatabase dbSlaver = helper.getReadableDatabase();
   ContentValues values = new ContentValues();
   values.put("isRead", info.getIsRead());
   String whereClause = "messageid=?";
   String[] whereArgs = {info.getMessageId()};
   int row = dbSlaver.update("t_message", values, whereClause, whereArgs);
 }
Esempio n. 3
0
 /** 修改录音文件的路径 */
 public boolean updateAudioFilePathByMessageId(MessageInfo info) {
   SQLiteDatabase dbMaster = null;
   try {
     dbMaster = helper.getWritableDatabase();
     ContentValues values = new ContentValues();
     values.put("audioFilePath", info.getAudioFilePath());
     String whereClause = "messageid=?";
     String[] whereArgs = {info.getMessageId()};
     int row = dbMaster.update("t_message", values, whereClause, whereArgs);
     if (row > 0) {
       return true;
     }
   } catch (Exception e) {
   }
   return false;
 }
Esempio n. 4
0
  /**
   * 新增一条消息
   *
   * @param msg 消息体
   * @return msgId 消息存储的唯一ID
   */
  public void saveMsg(MessageInfo msg) {
    SQLiteDatabase dbMaster = null;
    try {
      dbMaster = helper.getWritableDatabase();
      dbMaster.beginTransaction();

      dbMaster.execSQL(
          IMDbHelper.INSERT_MESSAGE_SQL,
          new Object[] {
            msg.getMessageId(),
            msg.getFromuserId(),
            msg.getTouserId(),
            msg.getIsRequireEncryption(),
            msg.getIsEncryptedOnServer(),
            msg.getIsRead(),
            msg.getTimesTamp(),
            msg.getIsReadacked(),
            msg.getIsDeliveredacked(),
            msg.getContentType(),
            msg.getContent(),
            msg.getConversationId(),
            msg.getSenderName(),
            msg.getExt(),
            msg.getDeliveryState(),
            msg.getIsAnonymous(),
            msg.getMessageType(),
            msg.getDuration(),
            msg.getPortraitImg(),
            msg.getAudioFilePath()
          });

      dbMaster.setTransactionSuccessful();
    } catch (SQLException e) {
      LogUtil.info(e.toString());

    } finally {
      if (null != dbMaster) {
        dbMaster.endTransaction();
      }
      // dbMaster.close();
    }
  }