Contributed Ad-hoc not working

Contributed Ad-hoc not working

by Otaku Dude -
Number of replies: 1

Hi,

There is a report on the contributed list (3.6), that generates a report on badges issued. When I try to run it via the Ad-Hoc plugin I get an error.

Query:

SELECT u.username, b.name AS badgename, 

CASE WHEN b.courseid IS NOT NULL THEN 

(SELECT c.shortname 

 FROM prefix_course AS c 

 WHERE c.id = b.courseid) 

WHEN b.courseid IS NULL THEN "*" 

END AS Context

CASE 

 WHEN t.criteriatype = 1 AND t.method = 1 THEN "Activity Completion (All)" 

 WHEN t.criteriatype = 1 AND t.method = 2 THEN "Activity Completion (Any)" 

 WHEN t.criteriatype = 2 AND t.method = 2 THEN "Manual Award" 

 WHEN t.criteriatype = 4 AND t.method = 1 THEN "Course Completion (All)" 

 WHEN t.criteriatype = 4 AND t.method = 2 THEN "Course Completion (Any)" 

 ELSE CONCAT ('Other: ', t.criteriatype) 

END AS Criteriatype, 

DATE_FORMAT( FROM_UNIXTIME( d.dateissued ) , '%Y-%m-%d' ) AS dateissued, 

DATE_FORMAT( FROM_UNIXTIME( d.dateexpire ), '%Y-%m-%d' ) AS dateexpires, 

CONCAT ('<a target="_new" href="%%WWWROOT%%/badges/badge.php?hash=',d.uniquehash,'">link</a>') AS Details 

FROM prefix_badge_issued AS d JOIN prefix_badge AS b ON d.badgeid = b.id 

JOIN prefix_user AS u ON d.userid = u.id 

JOIN prefix_badge_criteria AS t ON b.id = t.badgeid 

WHERE t.criteriatype <> 0 

ORDER BY u.username


Error Message:

Error when executing the query: ERROR: Incorrect number of query parameters. Expected 1, got 0.

I'd be really grateful for any help with this.

Thanks,

Nige.


Average of ratings: -
In reply to Otaku Dude

Re: Contributed Ad-hoc not working

by Randy Thornton -
Picture of Documentation writers

The issue is one of the peculiarities of the Ad-hoc report plugin: it will not accept the use of ? as the parameter inside regular text, which is used in the final SELECT statement in the CONCAT right before the FROM section to create the URL link to the badge itself using its hash.

Instead, as the notes on the Ad-hoc page say, you need to replace the ? with either %%Q%% or with a CHAR(63) which is the ASCII equivalent.

The query works fine as is in Config Reports (or Adminer or phpMyAdmin, etc.) which does not have this oddity. You just need to make that substitution. See attachment for example.

Attachment screenshot_7785.jpg
Average of ratings: Useful (1)