Edgewall Software
Modify

Opened 18 years ago

Closed 17 years ago

#3393 closed defect (worksforme)

Error in Custom Report using subquery

Reported by: anonymous Owned by: daniel
Priority: normal Milestone:
Component: report system Version: 0.9.5
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

I created a custom report using the following SQLite query

SELECT p.value AS __color__,
  id AS ticket, summary, component, version, milestone, t.severity AS severity,
  (CASE status WHEN 'assigned' THEN owner||' *' ELSE owner END) AS owner,
  (CASE WHEN strftime('%%s','now') - changetime > 86400
        THEN round((strftime('%%s','now') - changetime)/86400,0) || ' days'
        WHEN strftime('%%s','now') - changetime > 3600
        THEN round((strftime('%%s','now') - changetime)/3600,0) || ' hours'
        ELSE (strftime('%%s','now') - changetime)/60 || ' mins'
  END) AS Modified,
  (SELECT author FROM ticket_change WHERE ticket = t.id AND field = 'comment' LIMIT 1) AS Modified_By,
  description AS _description,
  reporter AS _reporter
FROM ticket t, enum p
WHERE status IN ('new', 'assigned', 'reopened')
  AND p.name = t.priority AND p.type = 'priority'
ORDER BY changetime desc, p.value, milestone, t.severity, time 

The query executes correctly in SQLite, but trac complains about the subquery saying:
Report execution failed: no such column: t.id

Attachments (0)

Change History (3)

comment:1 by sid, 17 years ago

Yep, this did not work for me either. But by making the subquery a table instead (and changing %%s to %s), the query now works and displays active tickets by last modified date correctly:

SELECT p.value AS __color__,
  id AS ticket, summary, component, version, milestone, t.severity AS severity,
  (CASE status WHEN 'assigned' THEN owner||' *' ELSE owner END) AS owner,
  (CASE WHEN strftime('%s','now') - changetime > 86400
        THEN round((strftime('%s','now') - changetime)/86400,0) || ' days'
        WHEN strftime('%s','now') - changetime > 3600
        THEN round((strftime('%s','now') - changetime)/3600,0) || ' hours'
        ELSE (strftime('%s','now') - changetime)/60 || ' mins'
  END) AS Modified,
  author as Modified_By,
  description AS _description,
  reporter AS _reporter
FROM ticket t, enum p,
     (SELECT ticket, author, MAX(time) FROM ticket_change WHERE field = 'comment' GROUP BY ticket) tc
WHERE status IN ('new', 'assigned', 'reopened')
  AND p.name = t.priority AND p.type = 'priority'
  AND t.id = tc.ticket
ORDER BY changetime desc, p.value, milestone, t.severity, time

(tested and working on 0.10 release)

comment:2 by sid, 17 years ago

I propose closing this as a worksforme.

comment:3 by sid, 17 years ago

Resolution: worksforme
Status: newclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain daniel.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from daniel to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.