Reports: Ad-hoc database queries

Maintained by Tim at Lone Pine Koala Sanctuary Tim Hunt, at the OU (Perry building) Mahmoud Kassaei
This report plugin allows Administrators to set up arbitrary database queries to act as ad-hoc reports. Reports can be of two types, either run on demand, or scheduled to run automatically. Other users with the right capability can go in and see a list of queries that they have access to. Results can be viewed on-screen or downloaded as CSV.
1781 sites
49 fans

This report, created by The Open University, lets Administrators set up arbitrary SQL select queries that anyone with the appropriate permissions can then run. Reports can be set to be runnable on-demand, or automatically run weekly or monthly.

The results are displayed as a fairly plain HTML table, and can also be downloaded as CSV.

The idea is that this lets you quicly set up ad-hoc reports, without having to create a whole new admin report plugin.


Screenshot #0


Tim at Lone Pine Koala Sanctuary
Tim Hunt (Lead maintainer)
at the OU (Perry building)
Mahmoud Kassaei: Developer
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Daniel Wolff
    Tue, 4 Oct 2016, 9:14 PM
    We were able to replicate this functionality (emailing specific reports) by setting up a cron job using mutt. If you look in the moodledata directory the report filenames are named in a predictable way. Thought I would share in case it was useful for others, in this example we are emailing a report created at 3:00 AM everyday at 5:00 AM:
    00 05 * * * root mutt -s "Subject of Email" -a /var/www/moodledata/admin_report_customsql/2/`date +\%Y\%m\%d`-030000.csv -- < /var/www/moodledata/admin_report_customsql/2/message.txt < /var/www/moodledata/admin_report_customsql/2/message.txt
  • Picture of Mohd Radzi Abdul Kadir
    Tue, 11 Oct 2016, 11:20 AM
    I have problem to figure out how to get teacher/teachers name for each course. can anyone give a clue.. here is my simple coding to get list courses..

    FROM prefix_course, prefix_course_categories
    WHERE prefix_course.category =
    AND prefix_course_categories.parent=0
    order by, prefix_course.fullname

    thanks in advance
  • Picture of Roger Domínguez Argemí
    Thu, 19 Jan 2017, 7:53 PM
    Hi Tim,

    Do you know when the plugin will be updated? Thanks!


  • Tim at Lone Pine Koala Sanctuary
    Thu, 19 Jan 2017, 7:54 PM
    You mean for Moodle 3.2? I am afraid the answer is "when I get around to testing it". I am sure it works, but I don't like to mark it as compatible until I have acutally tested.
  • Tim at Lone Pine Koala Sanctuary
    Thu, 19 Jan 2017, 7:55 PM
    If you are able to test it yourself (download the zip for 3.1, and install it manually), then let me know. That would be very helpful. Thanks.
  • Picture of Roger Domínguez Argemí
    Sat, 11 Feb 2017, 6:16 PM
    Hi Tim! We will do it and we will back to you. Thanks smile
  • Panthers fan
    Thu, 23 Feb 2017, 12:44 AM
    Thanks for a great plugin (use it ALL the time). Quick question - any way to tell when a report was last edited (changed)? Thanks again.
  • Tim at Lone Pine Koala Sanctuary
    Thu, 23 Feb 2017, 1:18 AM
    We don't track timemodified in the report_customsql_queries database table. That is probably bad practice. If anyone wants to code that addition, I would happily merge a pull request. I'm afraid I don't have time to do it myself just now.
  • Picture of Pedro Giesel
    Thu, 16 Mar 2017, 10:34 AM
    Hi everyone,
    Is anyone who knows how I can get the students results for all courses?
    I was wondering if I could create a report where I can see the students results for all courses the student is enrolled.

    The student has the OVERVIEW REPORT, where they can access the results of all courses they are enrolled.
    However, the teacher does not have this option to see the results of all courses the student is enrolled.
    Mostly cases, the student is enrolled in the same course as their trainer.

    If someone could help me with that I would be eternally grateful.


  • Picture of Marco S
    Sat, 1 Apr 2017, 6:03 PM
    Hi, how to make a visible border table in email? The output table is without bordered lines.
  • Picture of Anderson Hsu
    Thu, 6 Apr 2017, 8:44 PM
    Dear Support Team,
    We can use sql by use Ad-hoc database queries plugin , but after download the result to csv file (refer to the link , the file content show wrong language as shown as the link:
    How can we adjust the question, and thanks a lot.
    Sat, 13 May 2017, 4:43 AM
    can i export .CSV without headers ?
    Sat, 13 May 2017, 4:44 AM
    can i export .CSV file without double quotation on the strings ?
  • Tim at Lone Pine Koala Sanctuary
    Tue, 16 May 2017, 10:07 PM
    .CSV format recommends double-quoting all the data. Surely it is not hard to remoev the quotes when you load the file? Similarly, if you don't want the headers, just delete the first line.

    I expect that if you really want to make these changes, it is not hard to change the code of this report.
  • Picture of Daemon Hunt
    Wed, 17 May 2017, 4:59 AM
    Agree. Post-processing the csv or changing the report code is not difficult.
1 2 3 4 5 6 7 8 9 10 11
Please login to post comments