Bug #57776 mysql command line client: command \e executes statement then opens editor
Submitted: 27 Oct 2010 16:02 Modified: 9 Nov 2010 20:29
Reporter: Kai Sautter (Basic Quality Contributor) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:5.1.41, 5.1.50 OS:Linux
Assigned to: CPU Architecture:Any
Tags: qc

[27 Oct 2010 16:02] Kai Sautter
Description:
Invoking the external editor from the command line using command \e, will first execute the statement then open the editor and then try to re-execute the edited statement (asking for another delimiter (";")), if the statement ends with ";". Whilst it is syntactically correct, that ";" ends the statement and sending the line, will execute the statement, this behaviour is unexpected and might be harmful. If the command "\e" would be purely statement oriented, the editor should be empty, if "\e" is preceded by ";". Yet the statement is executed and transferred to the editor, but without the delimiter.

If more than one statement is supplied within the same line, only the last statement will be transferred to the editor.

Furthermore, the edited statement is not added to the statement history, available with the up key on the command line. Only the statement delimiter added after terminating the editor will be shown. Thus the edited statement is lost for re-use.

How to repeat:
open mysql command line client
select database
type statement, e.g. select * from sometable;\e
quit the editor
confirm the statement (you don't see) with delimiter or abort with \c
type line with two statements, e.g. select * from sometable; select count(*) from sometable;\e
confirm the statement (you don't see) with delimiter or abort with \c

Suggested fix:
Do not execute the statement preceded by \e prior to opening the editor, even if the statement is delimited. Alternatively transfer the full input line to the editor without execution or only transfer the last un-delimited statement to the editor.
[7 Nov 2010 13:52] Valeriy Kravchuk
Thank you for the problem report. Verified on Ubuntu.
[9 Nov 2010 20:29] Konstantin Osipov
\e works as intended. It is only meaningful to use it without any other text on the line.
If you would like to open the editor,