AttachmentsSizeSQL

From Request Tracker Wiki
Jump to navigation Jump to search

Found on my disk SQL that fetches attachments sizes from RT DB. It's not that trivial as we store it in headers. May be someone would find this useful. Works with mysql 4.1.x --RuslanZakirov

SELECT id, IF(
      LOCATE('Content-Length:', Headers),
      CAST(TRIM(
        SUBSTRING_INDEX(
          SUBSTRING_INDEX(Headers, 'Content-Length:', -1),
          "\n",
          1
        )
      ) AS UNSIGNED INTEGER),
      BINARY LENGTH(Content)
    ) ContentLength
FROM Attachments;