moosh icon indicating copy to clipboard operation
moosh copied to clipboard

`sql-run` wraps result rows in excess PHP code

Open phette23 opened this issue 3 years ago • 0 comments

  • moosh version: 0.30
  • moodle version: 3.8.2
    • database: MySQL
  • php version: PHP 7.2.24-0ubuntu0.18.04.7
  • operating system: Linux 4.15.0-88-generic #88-Ubuntu SMP x86_64 GNU/Linux

Actual behaviour

sql-run produces a bunch of extra PHP around its results e.g.

$ moosh sql-run 'SELECT DISTINCT plugin FROM {config_plugins}'
Record 1
stdClass Object
(
    [plugin] => analytics
)

Record 2
stdClass Object
(
    [plugin] => antivirus_clamav
)
...

This is true whether one column is returned, as above, or multiple, where it becomes even more difficult to strip out the excess text and format the results one-per-line. I'm sure this is happening due to a limitation of the Moodle SQL APIs but I wonder if some processing in moosh could help return more UNIX-friendly, line-oriented data.

Expected behaviour

It's almost impossible to use that text output by itself, you have to use further utilities to strip out the useless lines and array key. It'd be much more convenient if the actual SQL query results were returned, one tuple per line:

$ moosh sql-run 'SELECT DISTINCT plugin FROM {config_plugins}'
plugin
analytics
antivirus_clamav
...

Or, for multiple columns, make them quoted and comma-separated:

$ moosh sql-run 'SELECT * FROM {config_plugins} WHERE value LIKE "%,%"'
id,plugin,name,value
150,backup,backup_async_message,"Hi {user_firstname},<br> Your {operation} (ID: {backupid}) has completed successfully. <br><br>You can access it here: {link}."
156,analytics,defaulttimesplittingsevaluation,"\core\analytics\time_splitting\quarters_accum,\core\analytics\time_splitting\quarters,\core\analytics\time_splitting\single_range"
...

Steps to reproduce

run moosh -sql-run 'SELECT DISTINCT plugin FROM {config_plugins}' or pretty much any other sql-run query that returns results.

phette23 avatar May 04 '21 19:05 phette23