在Trac自定义报告中包含已关闭的日期

时间:2012-10-26 19:30:02

标签: sqlite report trac

我正在使用以下内容显示已关闭的门票,顶部有新关闭的门票:

SELECT 
   p.value AS __color__,
   id AS ticket, 
   summary, 
   component,
   version,
   milestone,
   t.type AS type, 
   owner, 
   status,
   time AS created,
   changetime AS _changetime,
   description AS _description,
   reporter AS _reporter
  FROM ticket t
  LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
  WHERE status = 'closed'
  ORDER BY changetime DESC, time DESC, CAST(p.value AS integer), milestone, t.type, time

以下是目前显示的列:

Ticket
Summary
Component
Version
Milestone
Type
Owner
Status
Created

我想添加关闭日期到报告视图(可能还有第三列显示日期差异)。我该怎么做?

2 个答案:

答案 0 :(得分:2)

要在报表视图上显示字段,而不仅仅是RSS源,请从列名称中删除前导下划线。 changetime AS _changetime是违规行;尝试将其更改为changetime AS closed。注意:您可能需要像datetime(changetime/1000000, 'unixepoch') AS closed一样修复它。

要获取日期差异,请尝试减去两列,每列包含在对SQLite julianday函数的调用中,如julianday('now') - julianday(changetime/1000000, 'unixepoch') AS closedago

答案 1 :(得分:1)

添加已关闭日期并不像我想象的那么简单。以下示例将告诉您诀窍:

SELECT p.value AS __color__,
       ticket, summary, component, version, milestone, t.type, owner,
       t.time AS created,
       MAX(tc.time) as date
  FROM ticket_change tc
  LEFT JOIN ticket t ON tc.ticket=id
  LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
 WHERE field='status'
   AND newvalue='closed'
 GROUP by ticket
 ORDER BY tc.time DESC, t.time DESC, CAST(p.value AS integer), milestone, t.type

您需要在“ticket_change”数据库表和最后一次排序中使用JOIN来可靠地获取最后结束日期。