--- client/mysql.cc.orig 2007-09-15 22:09:53.000000000 +0300 +++ client/mysql.cc 2007-09-15 22:19:14.000000000 +0300 @@ -240,72 +240,73 @@ char cmd_char; /* msql command character */ int (*func)(String *str,char *); /* Function to call to do the job. */ bool takes_params; /* Max parameters for command */ + bool place_at_beginning; /* Command character place in input. */ const char *doc; /* Documentation for this function. */ } COMMANDS; static COMMANDS commands[] = { - { "?", '?', com_help, 1, "Synonym for `help'." }, - { "clear", 'c', com_clear, 0, "Clear command."}, - { "connect",'r', com_connect,1, + { "?", '?', com_help, 1, 0, "Synonym for `help'." }, + { "clear", 'c', com_clear, 0, 0, "Clear command."}, + { "connect",'r', com_connect,1, 1, "Reconnect to the server. Optional arguments are db and host." }, - { "delimiter", 'd', com_delimiter, 1, + { "delimiter", 'd', com_delimiter, 1, 1, "Set statement delimiter. NOTE: Takes the rest of the line as new delimiter." }, #ifdef USE_POPEN - { "edit", 'e', com_edit, 0, "Edit command with $EDITOR."}, + { "edit", 'e', com_edit, 0, 1, "Edit command with $EDITOR."}, #endif - { "ego", 'G', com_ego, 0, + { "ego", 'G', com_ego, 0, 0, "Send command to mysql server, display result vertically."}, - { "exit", 'q', com_quit, 0, "Exit mysql. Same as quit."}, - { "go", 'g', com_go, 0, "Send command to mysql server." }, - { "help", 'h', com_help, 1, "Display this help." }, + { "exit", 'q', com_quit, 0, 1, "Exit mysql. Same as quit."}, + { "go", 'g', com_go, 0, 0, "Send command to mysql server." }, + { "help", 'h', com_help, 1, 0, "Display this help." }, #ifdef USE_POPEN - { "nopager",'n', com_nopager,0, "Disable pager, print to stdout." }, + { "nopager",'n', com_nopager,0, 1, "Disable pager, print to stdout." }, #endif - { "notee", 't', com_notee, 0, "Don't write into outfile." }, + { "notee", 't', com_notee, 0, 1, "Don't write into outfile." }, #ifdef USE_POPEN - { "pager", 'P', com_pager, 1, + { "pager", 'P', com_pager, 1, 1, "Set PAGER [to_pager]. Print the query results via PAGER." }, #endif - { "print", 'p', com_print, 0, "Print current command." }, - { "prompt", 'R', com_prompt, 1, "Change your mysql prompt."}, - { "quit", 'q', com_quit, 0, "Quit mysql." }, - { "rehash", '#', com_rehash, 0, "Rebuild completion hash." }, - { "source", '.', com_source, 1, + { "print", 'p', com_print, 0, 0, "Print current command." }, + { "prompt", 'R', com_prompt, 1, 1, "Change your mysql prompt."}, + { "quit", 'q', com_quit, 0, 1, "Quit mysql." }, + { "rehash", '#', com_rehash, 0, 1, "Rebuild completion hash." }, + { "source", '.', com_source, 1, 1, "Execute an SQL script file. Takes a file name as an argument."}, - { "status", 's', com_status, 0, "Get status information from the server."}, + { "status", 's', com_status, 0, 1,"Get status information from the server."}, #ifdef USE_POPEN - { "system", '!', com_shell, 1, "Execute a system shell command."}, + { "system", '!', com_shell, 1, 1, "Execute a system shell command."}, #endif - { "tee", 'T', com_tee, 1, + { "tee", 'T', com_tee, 1, 1, "Set outfile [to_outfile]. Append everything into given outfile." }, - { "use", 'u', com_use, 1, + { "use", 'u', com_use, 1, 1, "Use another database. Takes database name as argument." }, - { "charset", 'C', com_charset, 1, + { "charset", 'C', com_charset, 1, 0, "Switch to another charset. Might be needed for processing binlog with multi-byte charsets." }, - { "warnings", 'W', com_warnings, 0, + { "warnings", 'W', com_warnings, 0, 1, "Show warnings after every statement." }, - { "nowarning", 'w', com_nowarnings, 0, + { "nowarning", 'w', com_nowarnings, 0, 1, "Don't show warnings after every statement." }, /* Get bash-like expansion for some commands */ - { "create table", 0, 0, 0, ""}, - { "create database", 0, 0, 0, ""}, - { "drop", 0, 0, 0, ""}, - { "select", 0, 0, 0, ""}, - { "insert", 0, 0, 0, ""}, - { "replace", 0, 0, 0, ""}, - { "update", 0, 0, 0, ""}, - { "delete", 0, 0, 0, ""}, - { "explain", 0, 0, 0, ""}, - { "show databases", 0, 0, 0, ""}, - { "show fields from", 0, 0, 0, ""}, - { "show keys from", 0, 0, 0, ""}, - { "show tables", 0, 0, 0, ""}, - { "load data from", 0, 0, 0, ""}, - { "alter table", 0, 0, 0, ""}, - { "set option", 0, 0, 0, ""}, - { "lock tables", 0, 0, 0, ""}, - { "unlock tables", 0, 0, 0, ""}, - { (char *)NULL, 0, 0, 0, ""} + { "create table", 0, 0, 0, 0, ""}, + { "create database", 0, 0, 0, 0, ""}, + { "drop", 0, 0, 0, 0, ""}, + { "select", 0, 0, 0, 0, ""}, + { "insert", 0, 0, 0, 0, ""}, + { "replace", 0, 0, 0, 0, ""}, + { "update", 0, 0, 0, 0, ""}, + { "delete", 0, 0, 0, 0, ""}, + { "explain", 0, 0, 0, 0, ""}, + { "show databases", 0, 0, 0, 0, ""}, + { "show fields from", 0, 0, 0, 0, ""}, + { "show keys from", 0, 0, 0, 0, ""}, + { "show tables", 0, 0, 0, 0, ""}, + { "load data from", 0, 0, 0, 0, ""}, + { "alter table", 0, 0, 0, 0, ""}, + { "set option", 0, 0, 0, 0, ""}, + { "lock tables", 0, 0, 0, 0, ""}, + { "unlock tables", 0, 0, 0, 0, ""}, + { (char *)NULL, 0, 0, 0, 0, ""} }; static const char *load_default_groups[]= { "mysql","client",0 }; @@ -337,9 +338,10 @@ static void fix_history(String *final_command); #endif -static COMMANDS *find_command(char *name,char cmd_name); +static COMMANDS *find_command(char *name,char cmd_name, + bool at_input_beginning); static bool add_line(String &buffer,char *line,char *in_string, - bool *ml_comment); + bool *ml_comment,bool *at_input_beginning); static void remove_cntrl(String &buffer); static void print_table_data(MYSQL_RES *result); static void print_table_data_html(MYSQL_RES *result); @@ -1073,7 +1075,8 @@ char *line; char in_string=0; ulong line_number=0; - bool ml_comment= 0; + bool ml_comment= 0; + bool at_input_beginning= 1; COMMANDS *com; status.exit_status=1; @@ -1159,7 +1162,8 @@ (We want to allow help, print and clear anywhere at line start */ if ((named_cmds || glob_buffer.is_empty()) - && !ml_comment && !in_string && (com=find_command(line,0))) + && !ml_comment && !in_string + && (com=find_command(line,0,at_input_beginning))) { if ((*com->func)(&glob_buffer,line) > 0) break; @@ -1171,7 +1175,7 @@ #endif continue; } - if (add_line(glob_buffer,line,&in_string,&ml_comment)) + if (add_line(glob_buffer,line,&in_string,&ml_comment,&at_input_beginning)) break; } /* if in batch mode, send last query even if it doesn't end with \g or go */ @@ -1198,7 +1202,7 @@ } -static COMMANDS *find_command(char *name,char cmd_char) +static COMMANDS *find_command(char *name,char cmd_char,bool at_input_beginning) { uint len; char *end; @@ -1246,7 +1250,8 @@ (uchar*)commands[i].name,len) && !commands[i].name[len] && (!end || (end && commands[i].takes_params))) || - !name && commands[i].cmd_char == cmd_char)) + (!name && (commands[i].cmd_char == cmd_char) + && (commands[i].place_at_beginning ? at_input_beginning : 1)))) { DBUG_PRINT("exit",("found command: %s", commands[i].name)); DBUG_RETURN(&commands[i]); @@ -1257,7 +1262,7 @@ static bool add_line(String &buffer,char *line,char *in_string, - bool *ml_comment) + bool *ml_comment, bool *at_input_beginning) { uchar inchar; char buff[80], *pos, *out; @@ -1300,7 +1305,7 @@ if (!*ml_comment && inchar == '\\' && !(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)) { - // Found possbile one character command like \c + // Found possible one character command like \c if (!(inchar = (uchar) *++pos)) break; // readline adds one '\' @@ -1310,7 +1315,7 @@ *out++= (char) inchar; continue; } - if ((com=find_command(NullS,(char) inchar))) + if ((com=find_command(NullS,(char) inchar, at_input_beginning))) { const String tmp(line,(uint) (out-line), charset_info); buffer.append(tmp); @@ -1345,9 +1350,12 @@ } else { - sprintf(buff,"Unknown command '\\%c'.",inchar); - if (put_info(buff,INFO_ERROR) > 0) - DBUG_RETURN(1); + if (at_input_beginning) + { + sprintf(buff,"Unknown command '\\%c'.",inchar); + if (put_info(buff,INFO_ERROR) > 0) + DBUG_RETURN(1); + } *out++='\\'; *out++=(char) inchar; continue; @@ -1361,7 +1369,7 @@ uint old_delimiter_length= delimiter_length; if (out != line) buffer.append(line, (uint) (out - line)); // Add this line - if ((com= find_command(buffer.c_ptr(), 0))) + if ((com= find_command(buffer.c_ptr(), 0, at_input_beginning))) { if (com->func == com_delimiter) { @@ -1427,6 +1435,7 @@ need_space= 0; } *out++= (char) inchar; + at_input_beginning= 0; } } }