summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/my_readline.h2
-rw-r--r--client/mysql.cc28
-rw-r--r--client/readline.cc40
3 files changed, 36 insertions, 34 deletions
diff --git a/client/my_readline.h b/client/my_readline.h
index 2e716eec4cf..6052d462ab9 100644
--- a/client/my_readline.h
+++ b/client/my_readline.h
@@ -29,6 +29,6 @@ typedef struct st_line_buffer
} LINE_BUFFER;
extern LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file);
-extern LINE_BUFFER *batch_readline_command(my_string str);
+extern LINE_BUFFER *batch_readline_command(LINE_BUFFER *buffer, my_string str);
extern char *batch_readline(LINE_BUFFER *buffer);
extern void batch_readline_end(LINE_BUFFER *buffer);
diff --git a/client/mysql.cc b/client/mysql.cc
index fe6af909a5a..e4499cc67ec 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -494,7 +494,7 @@ static struct my_option my_long_options[] =
"No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of mysql and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"batch", 'B',
- "Print results with a tab as separator, each row on new line. Doesn't use history file.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ "Don't use history file. Disable interactive behavior. (Enables --silent)", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"character-sets-dir", OPT_CHARSETS_DIR,
"Directory where character sets are.", (gptr*) &charsets_dir,
(gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -515,7 +515,7 @@ static struct my_option my_long_options[] =
(gptr*) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"delimiter", OPT_DELIMITER, "Delimiter to be used.", (gptr*) &delimiter_str,
(gptr*) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- {"execute", 'e', "Execute command and quit. (Output like with --batch).", 0,
+ {"execute", 'e', "Execute command and quit. (Disables --force and history file)", 0,
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"vertical", 'E', "Print the output of a query (rows) vertically.",
(gptr*) &vertical, (gptr*) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
@@ -597,7 +597,7 @@ static struct my_option my_long_options[] =
0, 0, 0},
{"reconnect", OPT_RECONNECT, "Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default.",
(gptr*) &opt_reconnect, (gptr*) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
- {"silent", 's', "Be more silent.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
+ {"silent", 's', "Be more silent. Print results with a tab as separator, each row on new line.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
0, 0},
#ifdef HAVE_SMEM
{"shared_memory_base_name", OPT_SHARED_MEMORY_BASE_NAME,
@@ -755,10 +755,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case 'e':
status.batch= 1;
status.add_to_history= 0;
- batch_readline_end(status.line_buff); // If multiple -e
- if (!(status.line_buff= batch_readline_command(argument)))
+ if (!status.line_buff)
+ ignore_errors= 0; // do it for the first -e only
+ if (!(status.line_buff= batch_readline_command(status.line_buff, argument)))
return 1;
- ignore_errors= 0;
break;
case 'o':
if (argument == disabled_my_option)
@@ -798,12 +798,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
verbose++;
break;
case 'B':
- if (!status.batch)
- {
- status.batch= 1;
- status.add_to_history= 0;
- opt_silent++; // more silent
- }
+ status.batch= 1;
+ status.add_to_history= 0;
+ opt_silent++; // more silent
break;
case 'W':
#ifdef __WIN__
@@ -1108,11 +1105,8 @@ static bool add_line(String &buffer,char *line,char *in_string,
}
else
{
- int error= com_go(&buffer, 0);
- if (error)
- {
- return error < 0 ? 0 : 1; // < 0 is not fatal
- }
+ if (com_go(&buffer, 0) > 0) // < 0 is not fatal
+ return 1;
}
buffer.length(0);
out= line;
diff --git a/client/readline.cc b/client/readline.cc
index f5fbfd8cd0c..52ecb4e5c68 100644
--- a/client/readline.cc
+++ b/client/readline.cc
@@ -31,7 +31,8 @@ static char *intern_read_line(LINE_BUFFER *buffer,ulong *out_length);
LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file)
{
LINE_BUFFER *line_buff;
- if (!(line_buff=(LINE_BUFFER*) my_malloc(sizeof(*line_buff),MYF(MY_WME))))
+ if (!(line_buff=(LINE_BUFFER*)
+ my_malloc(sizeof(*line_buff),MYF(MY_WME | MY_ZEROFILL))))
return 0;
if (init_line_buffer(line_buff,fileno(file),IO_SIZE,max_size))
{
@@ -67,11 +68,12 @@ void batch_readline_end(LINE_BUFFER *line_buff)
}
-LINE_BUFFER *batch_readline_command(my_string str)
+LINE_BUFFER *batch_readline_command(LINE_BUFFER *line_buff, my_string str)
{
- LINE_BUFFER *line_buff;
- if (!(line_buff=(LINE_BUFFER*) my_malloc(sizeof(*line_buff),MYF(MY_WME))))
- return 0;
+ if (!line_buff)
+ if (!(line_buff=(LINE_BUFFER*)
+ my_malloc(sizeof(*line_buff),MYF(MY_WME | MY_ZEROFILL))))
+ return 0;
if (init_line_buffer_from_string(line_buff,str))
{
my_free((char*) line_buff,MYF(0));
@@ -88,7 +90,6 @@ LINE_BUFFER *batch_readline_command(my_string str)
static bool
init_line_buffer(LINE_BUFFER *buffer,File file,ulong size,ulong max_buffer)
{
- bzero((char*) buffer,sizeof(buffer[0]));
buffer->file=file;
buffer->bufread=size;
buffer->max_size=max_buffer;
@@ -100,19 +101,26 @@ init_line_buffer(LINE_BUFFER *buffer,File file,ulong size,ulong max_buffer)
return 0;
}
-
+/*
+ init_line_buffer_from_string can be called on the same buffer
+ several times. the resulting buffer will contain a
+ concatenation of all strings separated by spaces
+*/
static bool init_line_buffer_from_string(LINE_BUFFER *buffer,my_string str)
{
- uint length;
- bzero((char*) buffer,sizeof(buffer[0]));
- length=(uint) strlen(str);
- if (!(buffer->buffer=buffer->start_of_line=buffer->end_of_line=
- (char*)my_malloc(length+2,MYF(MY_FAE))))
+ uint old_length=buffer->end - buffer->buffer;
+ uint length= (uint) strlen(str);
+ if (!(buffer->buffer= buffer->start_of_line= buffer->end_of_line=
+ (char*)my_realloc(buffer->buffer, old_length+length+2,
+ MYF(MY_FAE|MY_ALLOW_ZERO_PTR))))
return 1;
- memcpy(buffer->buffer,str,length);
- buffer->buffer[length]='\n';
- buffer->buffer[length+1]=0;
- buffer->end=buffer->buffer+length+1;
+ buffer->end= buffer->buffer + old_length;
+ if (old_length)
+ buffer->end[-1]=' ';
+ memcpy(buffer->end, str, length);
+ buffer->end[length]= '\n';
+ buffer->end[length+1]= 0;
+ buffer->end+= length+1;
buffer->eof=1;
buffer->max_size=1;
return 0;