summaryrefslogtreecommitdiff
path: root/maintenance/sql.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2013-08-12 09:28:15 +0200
committerPierre Schmitz <pierre@archlinux.de>2013-08-12 09:28:15 +0200
commit08aa4418c30cfc18ccc69a0f0f9cb9e17be6c196 (patch)
tree577a29fb579188d16003a209ce2a2e9c5b0aa2bd /maintenance/sql.php
parentcacc939b34e315b85e2d72997811eb6677996cc1 (diff)
Update to MediaWiki 1.21.1
Diffstat (limited to 'maintenance/sql.php')
-rw-r--r--maintenance/sql.php34
1 files changed, 27 insertions, 7 deletions
diff --git a/maintenance/sql.php b/maintenance/sql.php
index 04e98d91..11699909 100644
--- a/maintenance/sql.php
+++ b/maintenance/sql.php
@@ -33,13 +33,19 @@ class MwSql extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = "Send SQL queries to a MediaWiki database";
+ $this->addOption( 'cluster', 'Use an external cluster by name', false, true );
}
public function execute() {
- $dbw = wfGetDB( DB_MASTER );
- if ( $this->hasArg() ) {
- $fileName = $this->getArg();
- $file = fopen( $fileName, 'r' );
+ // Get a DB handle (with this wiki's DB select) from the appropriate load balancer
+ if ( $this->hasOption( 'cluster' ) ) {
+ $lb = wfGetLBFactory()->getExternalLB( $this->getOption( 'cluster' ) );
+ $dbw = $lb->getConnection( DB_MASTER ); // master for external LB
+ } else {
+ $dbw = wfGetDB( DB_MASTER ); // master for primary LB for this wiki
+ }
+ if ( $this->hasArg( 0 ) ) {
+ $file = fopen( $this->getArg( 0 ), 'r' );
if ( !$file ) {
$this->error( "Unable to open input file", true );
}
@@ -63,26 +69,39 @@ class MwSql extends Maintenance {
}
$wholeLine = '';
- while ( ( $line = Maintenance::readconsole() ) !== false ) {
+ $newPrompt = '> ';
+ $prompt = $newPrompt;
+ while ( ( $line = Maintenance::readconsole( $prompt ) ) !== false ) {
+ if( !$line ) {
+ # User simply pressed return key
+ continue;
+ }
$done = $dbw->streamStatementEnd( $wholeLine, $line );
$wholeLine .= $line;
if ( !$done ) {
+ $wholeLine .= ' ';
+ $prompt = ' -> ';
continue;
}
if ( $useReadline ) {
- readline_add_history( $wholeLine );
+ # Delimiter is eated by streamStatementEnd, we add it
+ # up in the history (bug 37020)
+ readline_add_history( $wholeLine . $dbw->getDelimiter() );
readline_write_history( $historyFile );
}
try{
$res = $dbw->query( $wholeLine );
$this->sqlPrintResult( $res, $dbw );
+ $prompt = $newPrompt;
$wholeLine = '';
} catch (DBQueryError $e) {
- $this->error( $e, true );
+ $doDie = ! Maintenance::posix_isatty( 0 );
+ $this->error( $e, $doDie );
}
}
+ wfWaitForSlaves();
}
/**
@@ -93,6 +112,7 @@ class MwSql extends Maintenance {
public function sqlPrintResult( $res, $db ) {
if ( !$res ) {
// Do nothing
+ return;
} elseif ( is_object( $res ) && $res->numRows() ) {
foreach ( $res as $row ) {
$this->output( print_r( $row, true ) );