public boolean likeMessage(String message,boolean like){
  SQLiteDatabase db=getWritableDatabase();
  if (db != null && message != null) {
    int likedStatus=like ? FALSE : TRUE;
    Cursor c=db.rawQuery("SELECT " + COL_LIKES + " FROM "+ TABLE+ " WHERE "+ COL_DELETED+ "="+ FALSE+ " AND "+ COL_LIKED+ "="+ likedStatus+ " AND "+ COL_MESSAGE+ " ='"+ Utils.makeTextSafeForSQL(message)+ "';",null);
    c.moveToFirst();
    if (c.getCount() > 0) {
      int likes=c.getInt(c.getColumnIndex(COL_LIKES)) + (like ? 1 : -1);
      c.close();
      likes=Math.max(0,likes);
      db.execSQL("UPDATE " + TABLE + " SET "+ COL_LIKED+ "="+ (like ? TRUE : FALSE)+ ","+ COL_LIKES+ "="+ likes+ " WHERE "+ COL_DELETED+ " ="+ FALSE+ " AND "+ COL_LIKED+ "="+ likedStatus+ " AND "+ COL_MESSAGE+ " ='"+ Utils.makeTextSafeForSQL(message)+ "';");
      return true;
    }
  }
  log.debug("Message was not edited, either message or database is null. [" + message + "]");
  return false;
}

public boolean likeMessage ( String message , boolean like ) { SQLiteDatabase db = getWritableDatabase ( ) ; if ( db != null && message != null ) { int likedStatus = like ? FALSE : TRUE ; Cursor c = db . rawQuery ( "SELECT " + COL_LIKES + " FROM " + TABLE + " WHERE " + COL_DELETED + "=" + FALSE + " AND " + COL_LIKED + "=" + likedStatus + " AND " + COL_MESSAGE + " ='" + Utils . makeTextSafeForSQL ( message ) + "';" , null ) ; c . moveToFirst ( ) ; if ( c . getCount ( ) > 0 ) { int likes = c . getInt ( c . getColumnIndex ( COL_LIKES ) ) + ( like ? 1 : - 1 ) ; c . close ( ) ; likes = Math . max ( 0 , likes ) ; db . execSQL ( "UPDATE " + TABLE + " SET " + COL_LIKED + "=" + ( like ? TRUE : FALSE ) + "," + COL_LIKES + "=" + likes + " WHERE " + COL_DELETED + " =" + FALSE + " AND " + COL_LIKED + "=" + likedStatus + " AND " + COL_MESSAGE + " ='" + Utils . makeTextSafeForSQL ( message ) + "';" ) ; return true ; } } log . debug ( "Message was not edited, either message or database is null. [" + message + "]" ) ; return false ; }
updating the priority of a message by either + 1 or - 1 and set the message state as liked or not liked
