mysqltest: use a dynamically growing command buffer
This commit is contained in:
parent
c362ea3ffd
commit
32b7d456d5
@ -6501,8 +6501,6 @@ static inline bool is_escape_char(char c, char in_string)
|
|||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
read_line
|
read_line
|
||||||
buf buffer for the read line
|
|
||||||
size size of the buffer i.e max size to read
|
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
This function actually reads several lines and adds them to the
|
This function actually reads several lines and adds them to the
|
||||||
@ -6520,10 +6518,15 @@ static inline bool is_escape_char(char c, char in_string)
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int read_line(char *buf, int size)
|
static char *read_command_buf= NULL;
|
||||||
|
static size_t read_command_buflen= 0;
|
||||||
|
static const size_t max_multibyte_length= 6;
|
||||||
|
|
||||||
|
int read_line()
|
||||||
{
|
{
|
||||||
char c, last_quote=0, last_char= 0;
|
char c, last_quote=0, last_char= 0;
|
||||||
char *p= buf, *buf_end= buf + size - 1;
|
char *p= read_command_buf;
|
||||||
|
char *buf_end= read_command_buf + read_command_buflen - max_multibyte_length;
|
||||||
int skip_char= 0;
|
int skip_char= 0;
|
||||||
my_bool have_slash= FALSE;
|
my_bool have_slash= FALSE;
|
||||||
|
|
||||||
@ -6531,10 +6534,21 @@ int read_line(char *buf, int size)
|
|||||||
R_COMMENT, R_LINE_START} state= R_LINE_START;
|
R_COMMENT, R_LINE_START} state= R_LINE_START;
|
||||||
DBUG_ENTER("read_line");
|
DBUG_ENTER("read_line");
|
||||||
|
|
||||||
|
*p= 0;
|
||||||
start_lineno= cur_file->lineno;
|
start_lineno= cur_file->lineno;
|
||||||
DBUG_PRINT("info", ("Starting to read at lineno: %d", start_lineno));
|
DBUG_PRINT("info", ("Starting to read at lineno: %d", start_lineno));
|
||||||
for (; p < buf_end ;)
|
while (1)
|
||||||
{
|
{
|
||||||
|
if (p >= buf_end)
|
||||||
|
{
|
||||||
|
my_ptrdiff_t off= p - read_command_buf;
|
||||||
|
read_command_buf= (char*)my_realloc(read_command_buf,
|
||||||
|
read_command_buflen*2, MYF(MY_FAE));
|
||||||
|
p= read_command_buf + off;
|
||||||
|
read_command_buflen*= 2;
|
||||||
|
buf_end= read_command_buf + read_command_buflen - max_multibyte_length;
|
||||||
|
}
|
||||||
|
|
||||||
skip_char= 0;
|
skip_char= 0;
|
||||||
c= my_getc(cur_file->file);
|
c= my_getc(cur_file->file);
|
||||||
if (feof(cur_file->file))
|
if (feof(cur_file->file))
|
||||||
@ -6570,7 +6584,7 @@ int read_line(char *buf, int size)
|
|||||||
cur_file->lineno++;
|
cur_file->lineno++;
|
||||||
|
|
||||||
/* Convert cr/lf to lf */
|
/* Convert cr/lf to lf */
|
||||||
if (p != buf && *(p-1) == '\r')
|
if (p != read_command_buf && *(p-1) == '\r')
|
||||||
p--;
|
p--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6585,9 +6599,9 @@ int read_line(char *buf, int size)
|
|||||||
}
|
}
|
||||||
else if ((c == '{' &&
|
else if ((c == '{' &&
|
||||||
(!my_strnncoll_simple(charset_info, (const uchar*) "while", 5,
|
(!my_strnncoll_simple(charset_info, (const uchar*) "while", 5,
|
||||||
(uchar*) buf, min(5, p - buf), 0) ||
|
(uchar*) read_command_buf, min(5, p - read_command_buf), 0) ||
|
||||||
!my_strnncoll_simple(charset_info, (const uchar*) "if", 2,
|
!my_strnncoll_simple(charset_info, (const uchar*) "if", 2,
|
||||||
(uchar*) buf, min(2, p - buf), 0))))
|
(uchar*) read_command_buf, min(2, p - read_command_buf), 0))))
|
||||||
{
|
{
|
||||||
/* Only if and while commands can be terminated by { */
|
/* Only if and while commands can be terminated by { */
|
||||||
*p++= c;
|
*p++= c;
|
||||||
@ -6721,8 +6735,6 @@ int read_line(char *buf, int size)
|
|||||||
*p++= c;
|
*p++= c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
die("The input buffer is too small for this query.x\n" \
|
|
||||||
"check your query or increase MAX_QUERY and recompile");
|
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6867,12 +6879,8 @@ bool is_delimiter(const char* p)
|
|||||||
terminated by new line '\n' regardless how many "delimiter" it contain.
|
terminated by new line '\n' regardless how many "delimiter" it contain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MAX_QUERY (256*1024*2) /* 256K -- a test in sp-big is >128K */
|
|
||||||
static char read_command_buf[MAX_QUERY];
|
|
||||||
|
|
||||||
int read_command(struct st_command** command_ptr)
|
int read_command(struct st_command** command_ptr)
|
||||||
{
|
{
|
||||||
char *p= read_command_buf;
|
|
||||||
struct st_command* command;
|
struct st_command* command;
|
||||||
DBUG_ENTER("read_command");
|
DBUG_ENTER("read_command");
|
||||||
|
|
||||||
@ -6888,8 +6896,7 @@ int read_command(struct st_command** command_ptr)
|
|||||||
die("Out of memory");
|
die("Out of memory");
|
||||||
command->type= Q_UNKNOWN;
|
command->type= Q_UNKNOWN;
|
||||||
|
|
||||||
read_command_buf[0]= 0;
|
if (read_line())
|
||||||
if (read_line(read_command_buf, sizeof(read_command_buf)))
|
|
||||||
{
|
{
|
||||||
check_eol_junk(read_command_buf);
|
check_eol_junk(read_command_buf);
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
@ -6898,6 +6905,7 @@ int read_command(struct st_command** command_ptr)
|
|||||||
if (opt_result_format_version == 1)
|
if (opt_result_format_version == 1)
|
||||||
convert_to_format_v1(read_command_buf);
|
convert_to_format_v1(read_command_buf);
|
||||||
|
|
||||||
|
char *p= read_command_buf;
|
||||||
DBUG_PRINT("info", ("query: '%s'", read_command_buf));
|
DBUG_PRINT("info", ("query: '%s'", read_command_buf));
|
||||||
if (*p == '#')
|
if (*p == '#')
|
||||||
{
|
{
|
||||||
@ -9025,6 +9033,8 @@ int main(int argc, char **argv)
|
|||||||
init_win_path_patterns();
|
init_win_path_patterns();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
read_command_buf= (char*)my_malloc(read_command_buflen= 65536, MYF(MY_FAE));
|
||||||
|
|
||||||
init_dynamic_string(&ds_res, "", 2048, 2048);
|
init_dynamic_string(&ds_res, "", 2048, 2048);
|
||||||
init_alloc_root(&require_file_root, 1024, 1024);
|
init_alloc_root(&require_file_root, 1024, 1024);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user