From b1a524fddcc486c22513589c26bfd43beee83fc1 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Thu, 25 Oct 2012 13:03:59 +0200 Subject: [PATCH] alter sql.php prompt on line continuation As long as a command is not ended with a database delimiter, sql.php kept appending the line without noticing the users. That is a bit confusing since you might not even know what you are going to run when entering the delimiter. This patch alter the prompt to ' ->' until the command is finished. That is more in line with how MySQL cli handles it. Example: $ php sql.php > SELECT -> * -> from -> job; Query OK, 0 row(s) affected // repeal command: > SELECT * from job Change-Id: Ic18b39d75d4db48d37d485e66f36d691e95934fb --- maintenance/sql.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/maintenance/sql.php b/maintenance/sql.php index 04e98d918d..f970677b1f 100644 --- a/maintenance/sql.php +++ b/maintenance/sql.php @@ -63,12 +63,20 @@ 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 ) { @@ -78,6 +86,7 @@ class MwSql extends Maintenance { try{ $res = $dbw->query( $wholeLine ); $this->sqlPrintResult( $res, $dbw ); + $prompt = $newPrompt; $wholeLine = ''; } catch (DBQueryError $e) { $this->error( $e, true ); -- 2.20.1