public long isTagPostExists(int post_id) {
    SQLiteDatabase database = null;
    long count = 0;
    try {
      String sql =
          "SELECT COUNT(*) FROM "
              + DbAdapter.TAG_POSTS_TABLE_NAME
              + " where "
              + DbAdapter.TP_ID
              + "="
              + post_id;

      dbHelper = new DbAdapter(context);
      database = dbHelper.getReadableDatabase();
      SQLiteStatement statement = database.compileStatement(sql);
      count = statement.simpleQueryForLong();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        database.close();
      } catch (Exception e) {
      }
    }
    return count;
  }
  public long getTagPostsCount() {
    SQLiteDatabase database = null;
    Cursor c = null;
    long count = 0;
    try {
      String[] cols = {DbAdapter.TP_ID};

      dbHelper = new DbAdapter(context);
      database = dbHelper.getReadableDatabase();
      c = database.query(DbAdapter.TAG_POSTS_TABLE_NAME, cols, null, null, null, null, null);
      count = c.getCount();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        if (!c.isClosed()) {
          c.close();
        }
      } catch (Exception e) {
      }
      try {
        database.close();
      } catch (Exception e) {
      }
    }
    return count;
  }
 public TagPostsDAO opnToWrite() {
   dbHelper = new DbAdapter(context);
   database = dbHelper.getWritableDatabase();
   return this;
 }
  public ArrayList<PostRowItem> getTagPosts() {
    SQLiteDatabase database = null;
    Cursor cursor = null;
    ArrayList<PostRowItem> postsList = null;
    try {
      postsList = new ArrayList<PostRowItem>();
      String[] cols = {
        DbAdapter.TP_ID,
        DbAdapter.TP_TITLE,
        DbAdapter.TP_DATE,
        DbAdapter.TP_ICON_URL,
        DbAdapter.TP_AUTHOR_NAME,
        DbAdapter.TP_CONTENT,
        DbAdapter.TP_SCREEN_IMAGE_URL,
        DbAdapter.TP_COMMENT_COUNT,
        DbAdapter.TP_URL,
        DbAdapter.TP_EXCERPT,
        DbAdapter.TP_COMMENTS,
        DbAdapter.TP_TAGS
      };

      dbHelper = new DbAdapter(context);
      database = dbHelper.getReadableDatabase();
      cursor =
          database.query(
              DbAdapter.TAG_POSTS_TABLE_NAME,
              cols,
              null,
              null,
              null,
              null,
              DbAdapter.TP_DATE + " DESC");
      PostRowItem item;
      if (cursor.moveToFirst()) {
        do {
          item = new PostRowItem();

          item.setPost_id(cursor.getInt(cursor.getColumnIndex(DbAdapter.TP_ID)));
          item.setTitle(cursor.getString(cursor.getColumnIndex(DbAdapter.TP_TITLE)));
          item.setDate(cursor.getString(cursor.getColumnIndex(DbAdapter.TP_DATE)));
          item.setPost_icon_url(cursor.getString(cursor.getColumnIndex(DbAdapter.TP_ICON_URL)));
          item.setAuthor(cursor.getString(cursor.getColumnIndex(DbAdapter.TP_AUTHOR_NAME)));
          item.setContent(cursor.getString(cursor.getColumnIndex(DbAdapter.TP_CONTENT)));
          item.setPost_banner(
              cursor.getString(cursor.getColumnIndex(DbAdapter.TP_SCREEN_IMAGE_URL)));
          item.setComment_count(cursor.getInt(cursor.getColumnIndex(DbAdapter.TP_COMMENT_COUNT)));
          item.setPost_url(cursor.getString(cursor.getColumnIndex(DbAdapter.TP_URL)));
          item.setPost_des(cursor.getString(cursor.getColumnIndex(DbAdapter.TP_EXCERPT)));
          item.setCommentsArray(cursor.getString(cursor.getColumnIndex(DbAdapter.TP_COMMENTS)));
          item.setTagsArray(cursor.getString(cursor.getColumnIndex(DbAdapter.TP_TAGS)));

          postsList.add(item);
        } while (cursor.moveToNext());
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        if (!cursor.isClosed()) {
          cursor.close();
        }
      } catch (Exception e) {
      }
      try {
        database.close();
      } catch (Exception e) {
      }
    }
    return postsList;
  }