Closed danmarsden closed 11 months ago
Why do you want to do this? What have you done. Sure, I am capable of RTC, but it would be easier to review this request if you explain.
Hey Tim, the 'reason' for this is covered in issue #114 is that what you're asking?
That is what I was asking.
I don't like the proposed fix.
I understand why you want to chagne the behaviour when used as a web service, but I don't think we should change other cases. Therefore, why not change just the web service code, and ensure the header row is always output in PHP, rather than messing with the SQL?
If this behaviour is important enough to implement, it is important enough to have an automated test.
Alos, not really your problem, but if you could add a separat commit to fix the CI build (I think it just needs a DB version bump) then that would save me time.
Happy to look at adding tests, but.. any idea how to get the column names without using sql like this? If the query is something like 'select * from {table}' we have to execute the sql to get the list of columns.. and moodle doesn't have a show columns type api that let's us get a list if columns based on some sql.. it has to return rows.
Oh yes. I was forgetting how this work. Too may things going on.
So, the issue is, if the report is being shown on-screen, we don't want the no rows behaviour to change. (Worth a Behat test to verify the current behaviour)
And, if this is a scheduled report, it is a feature that a file is only saved on disc if the report returned any data.
So, we only want the 'create empty file' behaviour in the web service case (that is, when the call to report_customsql_generate_csv comes from report_customsql_pluginfile in lib.php).
I agree it is hard to work out how to test the download behaviour. Possibly a custom Behat step like Then downloading customsql report "Query name" returns a file with headers "frog,toad"
. You can probably use behat_general::download_file_from_link to help implement that.
Thanks Tim - when I first initially wrote that SQL to add the extra null row I didn't like it either but I couldn't find a better way to do it! - you're right - it shouldn't be changing the normal view of the report (I forgot that the same function was used to print the report on the view page) - I've added some code to make that only happen on the pluginfile call. I'll look to see what extra behat tests I can add later too. (I've also adjusted the sql slightly - my earlier tests on mysql used a slightly different alias and I'd also forgotten the word "ignore" was a reserved word in mysql.)
That is looking good now Dan. Just two minor quibbles which I would like to see fixed before I merge this.
I assume you got a phonecall just after posting that... or you mean the missing behat tests? - or you have comments still in a draft form... or the quibbles are because you're reviewing code way too late in the night... :-)
thanks Tim - basic changes implemented - haven't managed to write behat tests yet but will try to find some time today/tomorrow to add some in...
Hey Tim - I've just quickly dropped in a new behat test on that branch but I don't think the custom step is working quite right and I've obviously missed something/got a typo in there.... let me know if you spot the issue, otherwise I'll try to come back to this next week when I get some time.
that should be passing now... after trimming the bom and fixing a few typos...
Hi Tim, hi Dan,
I would like to quickly confirm that the current patch in this PR solves the issue which I reported in #114 successfully.
Thanks @abias - @timhunt let me know if there's anything else you need here.
Hi @timhunt ,
we are eagerly waiting for this PR to land in an official release so we can use it in one of our instanced officially. Is there any chance that you could have a final look and push this over the line?
Thanks in advance for your work!
hi @timhunt
I've just tested this and it works great. The sql is weird but I can not see a better way of doing it without improving core, and I did propose this here but I still don't know how viable it is in every db driver:
https://tracker.moodle.org/browse/MDL-64387
Is there anything else blocking this from landing we can sort?
Merged manually, with some small tweaks.
awesome - thanks heaps Tim! - hope you have a great break over Christmas! :-)
@timhunt - Many thanks for merging this PR!
Would you mind to push out a new release to https://moodle.org/plugins/report_customsql/versions which contains this fix as well? Our customer who paid for this fix prefers to install official releases.
Many thanks for your time!
here's a method that allows us to use the plugins normal methods for printing columns in a report by adding a record of null values to the report when the main query is empty.
Hopefully it makes sense - seems to work cross db for me but would be good to test further - I'll see if we can get some other folks to test too.