X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=maintenance%2Fsql.php;h=2c8bdb67ce33c4cdcafda2f2412ee97f25479cda;hp=dd05bbe4ad9d74e350082b23c6a6285f74a370c1;hb=a2c8c2969420a0f150c03f76e3a0bf9028fcda43;hpb=e69bcfad17d67da5113cdd75276a5f7b5cefb123 diff --git a/maintenance/sql.php b/maintenance/sql.php index dd05bbe4ad..2c8bdb67ce 100644 --- a/maintenance/sql.php +++ b/maintenance/sql.php @@ -40,6 +40,7 @@ class MwSql extends Maintenance { 'Takes a file name containing SQL as argument or runs interactively.' ); $this->addOption( 'query', 'Run a single query instead of running interactively', false, true ); + $this->addOption( 'json', 'Output the results as JSON instead of PHP objects' ); $this->addOption( 'cluster', 'Use an external cluster by name', false, true ); $this->addOption( 'wikidb', 'The database wiki ID to use if not the current one', false, true ); @@ -175,9 +176,15 @@ class MwSql extends Maintenance { // Do nothing return; } elseif ( is_object( $res ) && $res->numRows() ) { + $out = ''; foreach ( $res as $row ) { - $this->output( print_r( $row, true ) ); + $out .= print_r( $row, true ); + $rows[] = $row; } + if ( $this->hasOption( 'json' ) ) { + $out = json_encode( $rows, JSON_PRETTY_PRINT ); + } + $this->output( $out . "\n" ); } else { $affected = $db->affectedRows(); $this->output( "Query OK, $affected row(s) affected\n" );