alter sql.php prompt on line continuation
authorAntoine Musso <hashar@free.fr>
Thu, 25 Oct 2012 11:03:59 +0000 (13:03 +0200)
committerAntoine Musso <hashar@free.fr>
Thu, 25 Oct 2012 11:03:59 +0000 (13:03 +0200)
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

index 04e98d9..f970677 100644 (file)
@@ -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 );