Edgewall Software

Version 4 (modified by mpotter@…, 14 years ago) ( diff )

Corrected syntax highlighting in one of the SQL samples.

Custom Reports Configuration

TracReports#CreatingCustomReports describes how to create custom reports.

This page contains SQL for reports that may be of interest to many users.

User Report

When one visits a Trac system as a user of a product and not as a developer of the product, one often wants to search for those tickets of personal interest. Such tickets could be defined as those tickets where the user is the Reporter, in the CC or additionally as a commenter.

Query for Report:

SELECT 
  DISTINCT 
   p.value AS __color__,
   (CASE status 
      WHEN 'closed' THEN 'color: #777; background: #ddd; border-color: #ccc;'
    END) AS __style__,
   id AS ticket, summary, component, milestone, status, resolution, 
   t.time AS created, changetime AS modified,
   priority AS _priority, reporter AS _reporter, cc AS _cc
  FROM ticket t
  LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
  LEFT JOIN ticket_change tc ON id = tc.ticket
  WHERE reporter = '$USER' 
   OR cc LIKE '$USER,%'
   OR cc LIKE '% $USER'
   OR cc LIKE '% $USER,%'
   OR cc = '$USER'
   OR (tc.author='$USER' AND tc.field = 'comment')
  ORDER BY
    (status = 'closed'), 
    (CASE status
       WHEN 'closed' THEN changetime
       ELSE (-1) * CAST(p.value AS int)
    END) DESC

To include tickets that the user made any changes to, whether a comment was included or not, change the following:

  • Report.sql

     
    1515   OR cc LIKE '% $USER'
    1616   OR cc LIKE '% $USER,%'
    1717   OR cc = '$USER'
    18    OR (tc.author='$USER' AND tc.field = 'comment')
     18   OR tc.author='$USER'
    1919  ORDER BY
    2020    (status = 'closed'),
    2121    (CASE status

To exclude tickets that the user made comments to and thus just those they are the reporter or in the CC, delete the following:

  • Report.sql

     
    99   priority AS _priority, reporter AS _reporter, cc AS _cc
    1010  FROM ticket t
    1111  LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
    12   LEFT JOIN ticket_change tc ON id = tc.ticket
    1312  WHERE reporter = '$USER'
    1413   OR cc LIKE '$USER,%'
    1514   OR cc LIKE '% $USER'
    1615   OR cc LIKE '% $USER,%'
    1716   OR cc = '$USER'
    18    OR (tc.author='$USER' AND tc.field = 'comment')
    1917  ORDER BY
    2018    (status = 'closed'),
    2119    (CASE status

Non Ticket Reports

SQL reports do not have to be limited to tickets. They can report on revisions, wiki pages, or user activity.

User Changesets

The follow report will lists all of the changes for the current user, or add "?USER=user" to the end of the URL to report on another user.

SELECT 
   "changeset" AS _realm, rev as id, 
   time AS date, time, 
   SUBSTR(message, 1, 80 )AS message
FROM revision
WHERE author='$USER'
ORDER BY time DESC

This report only gives the first 80 characters of the check-in message. To give the full message, make the following change:

  • Report.sql

     
    11 SELECT
    22    "changeset" AS _realm, rev as id,
    33    time AS date, time,
    4     SUBSTR(message, 1, 80 )AS message
     4    message AS _message_
    55 FROM revision
    66 WHERE author='$USER'
    77 ORDER BY time DESC

Wiki Changes

This reports the wiki pages ever modified by the current user, or add "?USER=user" to the end of the URL to report on another user. Version is the highest version that the user modified.

SELECT 
   "wiki" AS _realm, 
   name AS id, 
   max(version) AS Version,
   time AS date, time, 
   comment
FROM wiki
WHERE author='$USER'
GROUP BY name

For wiki pages that were last modified by the current user:

SELECT 
   "wiki" AS _realm, 
   wiki.name AS id, 
   time AS date, time, 
   comment
FROM wiki,
 (SELECT max(version) AS maxVer, name
  FROM wiki
  GROUP BY name) maxResults
WHERE wiki.name = maxResults.name
 AND version = maxVer
 AND author = '$USER'
ORDER BY wiki.name
Note: See TracWiki for help on using the wiki.