From: Date: June 25 2008 7:38pm Subject: bzr commit into mysql-5.0 branch (chad:2644) Bug#37605 List-Archive: http://lists.mysql.com/commits/48514 X-Bug: 37605 Message-Id: <20080625173853.34C728305D@cornsilk.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit #At file:///home/cmiller/work/mysqlbzr/mysql-5.0-bugteam--bug37605/ 2644 Chad MILLER 2008-06-25 Bug#37605, client displays wrong command prompt after # or -- comment \ in --comment mode In comment-preservation mode of the mysql command-line client, comments are not discarded by the client, and are sent to the server. This fooled the code that tracks what state the prompt should be in. Now, keep a new state variable that tells us whether we should update the state of the prompt or not. After single-line comments, the next prompt should always be the previous state. Rather than keep up with that, let's only conditionally update the prompt. modified: client/mysql.cc per-file messages: client/mysql.cc If we encounter a single-line comment, do not update the prompt state. === modified file 'client/mysql.cc' --- a/client/mysql.cc 2008-06-24 16:05:56 +0000 +++ b/client/mysql.cc 2008-06-25 17:38:43 +0000 @@ -1035,7 +1035,7 @@ static void fix_history(String *final_co static COMMANDS *find_command(char *name,char cmd_name); static bool add_line(String &buffer,char *line,char *in_string, - bool *ml_comment); + bool *ml_comment, bool *prompt_updated); static void remove_cntrl(String &buffer); static void print_table_data(MYSQL_RES *result); static void print_table_data_html(MYSQL_RES *result); @@ -1761,6 +1761,8 @@ static int read_and_execute(bool interac String buffer; #endif + const char *prompt= NULL; + bool prompt_updated= true; char *line; char in_string=0; ulong line_number=0; @@ -1790,15 +1792,19 @@ static int read_and_execute(bool interac } else { - char *prompt= (char*) (ml_comment ? " /*> " : - glob_buffer.is_empty() ? construct_prompt() : - !in_string ? " -> " : - in_string == '\'' ? - " '> " : (in_string == '`' ? - " `> " : - " \"> ")); + + if (prompt == NULL || prompt_updated) + { + if (ml_comment) { prompt= " /*> "; } + else if (glob_buffer.is_empty()) { prompt= construct_prompt(); } + else if (in_string == '\0') { prompt= " -> "; } + else if (in_string == '\'') { prompt= " '> "; } + else if (in_string == '`') { prompt= " `> "; } + else { prompt= " \"> "; } + } + if (opt_outfile && glob_buffer.is_empty()) - fflush(OUTFILE); + fflush(OUTFILE); interrupted_query= 0; @@ -1891,7 +1897,8 @@ static int read_and_execute(bool interac #endif continue; } - if (add_line(glob_buffer,line,&in_string,&ml_comment)) + prompt_updated= true; + if (add_line(glob_buffer, line, &in_string, &ml_comment, &prompt_updated)) break; } /* if in batch mode, send last query even if it doesn't end with \g or go */ @@ -1977,7 +1984,7 @@ static COMMANDS *find_command(char *name static bool add_line(String &buffer,char *line,char *in_string, - bool *ml_comment) + bool *ml_comment, bool *prompt_updated) { uchar inchar; char buff[80], *pos, *out; @@ -2106,6 +2113,7 @@ static bool add_line(String &buffer,char // Add trailing single line comments to this statement buffer.append(pos); pos+= strlen(pos); + *prompt_updated= false; } pos--; @@ -2144,6 +2152,7 @@ static bool add_line(String &buffer,char // comment to end of line if (preserve_comments) buffer.append(pos); + *prompt_updated= false; break; }