Reports: Ad-hoc database queries

report_customsql
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.
2080 sites
1k downloads
70 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.

Screenshots

Screenshot #0

Contributors

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
  • Tim at Lone Pine Koala Sanctuary
    Fri, 19 Jan 2018, 3:07 AM
    Sorry, I can't think why that would be happening. You will probably need to debug it. Message size is a good guess. What size is that column in the DB?
  • Panthers fan
    Fri, 19 Jan 2018, 3:42 AM
    If I'm reading the information_schema correctly (still learning my way around SQL), the field mdl_message.fullmessagehtml is a longtext and character_maximum_length is 4294967295 (4G). So, its probably (!) not the message size. By my meager calculations, the message is at most 350K.

    For debugging, other than enabling $CFG->showcronsql and $CFG->showcrondebugging, what else would help? My complicating factor is we only have email enabled on our production system. So I can't enable debugging for too long.

    Thanks,

    Richard
  • Panthers fan
    Fri, 19 Jan 2018, 6:12 AM
    Some more information - after doing some more debugging, I noticed the following in the SQL debug output:

    eventdata as \stdClass is deprecated. Please use core\message\message instead.
    line 67 of /lib/messagelib.php: call to debugging()
    line 641 of /report/customsql/locallib.php: call to message_send()
    line 582 of /report/customsql/locallib.php: call to report_customsql_send_email_notification()
    line 131 of /report/customsql/locallib.php: call to report_customsql_email_report()
    line 78 of /report/customsql/classes/task/run_reports.php: call to report_customsql_generate_csv()
    line 104 of /lib/cronlib.php: call to report_customsql\task\run_reports->execute()
    line 292 of /lib/cronlib.php: call to cron_run_inner_scheduled_task()
    line 91 of /admin/tool/task/schedule_task.php: call to cron_run_single_task()

    What caught my eye is the report_customsql_send_email_notification call.

    Richard
  • Panthers fan
    Sat, 20 Jan 2018, 6:18 AM
    Fixed it. After a LOT of debugging (and reading lots of documentation), I updated my.cnf with group_concat_max_len=8M and max_allowed_packet=16M. So far, so good - I'm finally getting emails with the large report in my Inbox.
    Keeping my fingers crossed. Thanks for your help...
    Richard
  • Picture of Michael Milette
    Wed, 31 Jan 2018, 5:31 AM
    Hi Tim and Mahmoud,

    Will there be a version of Ad-hoc Database Queries compatible with Moodle 3.2 and beyond? If so, when do you think we can expect to see an updated 3.4 compatible version?

    Michael
  • Tim at Lone Pine Koala Sanctuary
    Sat, 17 Mar 2018, 5:14 AM
    I have finally done a 3.2+ compatible version.
  • Picture of Blair F.
    Wed, 4 Apr 2018, 7:05 AM
    Hi, Tim. I noticed that the last update stripped away the report name from the email report. They all show up as "Query" now. Was that intentional, or should I do a bug report?
  • Tim at Lone Pine Koala Sanctuary
    Wed, 4 Apr 2018, 5:36 PM
    I don't think that was an intentional change. A but report would be good. A patch would be even better, if you can do one smile
  • Picture of Blair F.
    Thu, 5 Apr 2018, 5:22 AM
    Unfortunately, I don't have the skills to help you out with that, Tim. sad

    I've submitted a bug report. I hope I did it right. I think I've only ever done one before.
    https://tracker.moodle.org/browse/CONTRIB-7238
  • Picture of Quentin Leguay
    Thu, 19 Apr 2018, 1:49 AM
    Hello, thanks for your work.

    I've been looking for information about the "Export csv report to path / directory" functionnality but couldn't find any.
    What kind of path is expected? A local path from the server root? Where can I export my file?
    The contextual help (in Portuguese) didn't seem to be filled. Maybe I can help with that once I understand the feature.
    Thanks
  • Tim at Lone Pine Koala Sanctuary
    Thu, 19 Apr 2018, 11:48 PM
    It is a path on the local server. Here is how the setting is used in the code https://github.com/moodleou/moodle-report_customsql/blob/master/locallib.php#L670. (That could be a file path that is a mount of a network disc, or similar.)
  • Picture of Quentin Leguay
    Sat, 21 Apr 2018, 3:00 AM
    Thank you very much for the help smile
  • Picture of Adam Gogo
    Wed, 20 Jun 2018, 2:57 AM
    I have started to work with this plugin, which I found to be incredibly useful (thank you to the developers).

    However, I have had to make some small modifications on my version to get it working the way I need and I want to share my feedback.

    In the locallib.php file, I found that the subject line for the emails that get sent is not currently pulling the query name (display name) which it is coded to do. I modified these lines in mine by changing "report_customsql_plain_text_report_name($report->displayname)" in the code to "report_customsql_plain_text_report_name($report)" since the "report_customsql_plain_text_report_name()" function looks at the $report object as a whole and then returns the query name.

    Hope this is helpful,

    ~Adam Gogo
  • Tim at Lone Pine Koala Sanctuary
    Wed, 20 Jun 2018, 9:03 PM
    Ah! We just foudn this bug ourselves last week, and our fix, which is the same as yours, is just going through testing.
  • Picture of Adam Gogo
    Thu, 21 Jun 2018, 1:35 AM
    Glad to hear that it was found.

    I'm currently looking deeper into the code, and I am looking at some enhancements to meet my needs (maybe something you would be interested in). One is to have a flag to determine if emails are sent out or not if the result set is empty (helps with sending alerts).

    The other is to add an hourly option to the schedule to assist with hourly scheduled reports. This for me is useful when writing queries that will be used as alerts to specific users (mostly for teachers). I'm still working out the logic for this one.
1 2 3 4 5 6 7 8 9 10 11 12 13
Please login to post comments