Loading client/mysqltest.c +53 −19 Original line number Diff line number Diff line Loading @@ -16,12 +16,14 @@ /* mysqltest test tool * See the "MySQL Test framework manual" for more information * http://dev.mysql.com/doc/mysqltest/en/index.html * * Written by: * Sasha Pachev <sasha@mysql.com> * Matt Wagner <matt@mysql.com> * Monty * Jani * Magnus **/ #define MTEST_VERSION "2.7" Loading Loading @@ -1332,6 +1334,7 @@ static void do_exec(struct st_query *query) query->first_argument, query->expected_errno[0].code.errnum); } dynstr_free(&ds_cmd); free_replace(); DBUG_VOID_RETURN; } Loading Loading @@ -1757,22 +1760,32 @@ static my_bool match_delimiter(int c, const char* delim, uint length) } static void read_until_EOF(DYNAMIC_STRING* ds) static void read_until_delimiter(DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_delimiter) { int c; DBUG_ENTER("read_until_EOF"); DBUG_ENTER("read_until_delimiter"); DBUG_PRINT("enter", ("delimiter: %s, length: %d", ds_delimiter->str, ds_delimiter->length)); if (ds_delimiter->length > MAX_DELIMITER) die("Max delimiter length(%d) exceeded", MAX_DELIMITER); /* Read from file until delimiter EOF is found */ /* Read from file until delimiter is found */ while (1) { c= my_getc(cur_file->file); if (c == '\n') cur_file->lineno++; if (feof(cur_file->file)) die("End of file encountered before 'EOF' delimiter was found"); die("End of file encountered before '%s' delimiter was found", ds_delimiter->str); if (match_delimiter(c, "EOF", 3)) if (match_delimiter(c, ds_delimiter->str, ds_delimiter->length)) { DBUG_PRINT("exit", ("Found EOF")); DBUG_PRINT("exit", ("Found delimiter '%s'", ds_delimiter->str)); break; } dynstr_append_mem(ds, (const char*)&c, 1); Loading @@ -1788,7 +1801,7 @@ static void read_until_EOF(DYNAMIC_STRING* ds) command called command DESCRIPTION write_file <file_name>; write_file <file_name> [<delimiter>]; <what to write line 1> <...> < what to write line n> Loading @@ -1800,18 +1813,23 @@ static void read_until_EOF(DYNAMIC_STRING* ds) < what to write line n> EOF Write everything between the "write_file" command and EOF to "file_name" Write everything between the "write_file" command and 'delimiter' to "file_name" NOTE! Overwrites existing file Default <delimiter> is EOF */ static void do_write_file(struct st_query *command) { DYNAMIC_STRING ds_content; DYNAMIC_STRING ds_filename; DYNAMIC_STRING ds_delimiter; const struct command_arg write_file_args[] = { "filename", ARG_STRING, TRUE, &ds_filename, "File to write to", "delimiter", ARG_STRING, FALSE, &ds_delimiter, "Delimiter to read until" }; DBUG_ENTER("do_write_file"); Loading @@ -1820,12 +1838,17 @@ static void do_write_file(struct st_query *command) write_file_args, sizeof(write_file_args)/sizeof(struct command_arg)); /* If no delimiter was provided, use EOF */ if (ds_delimiter.length == 0) dynstr_set(&ds_delimiter, "EOF"); init_dynamic_string(&ds_content, "", 1024, 1024); read_until_EOF(&ds_content); read_until_delimiter(&ds_content, &ds_delimiter); DBUG_PRINT("info", ("Writing to file: %s", ds_filename.str)); str_to_file(ds_filename.str, ds_content.str, ds_content.length); dynstr_free(&ds_content); dynstr_free(&ds_filename); dynstr_free(&ds_delimiter); DBUG_VOID_RETURN; } Loading @@ -1836,22 +1859,17 @@ static void do_write_file(struct st_query *command) command command handle DESCRIPTION perl; perl [<delimiter>]; <perlscript line 1> <...> <perlscript line n> EOF Execute everything after "perl" until EOF as perl. Execute everything after "perl" until <delimiter> as perl. Useful for doing more advanced things but still being able to execute it on all platforms. The function sets delimiter to EOF and remembers that this is a perl command by setting "perl mode". The following lines will then be parsed as any normal query, but when searching for command in get_query_type, this function will be called again since "perl mode" is on and the perl script can be executed. Default <delimiter> is EOF */ static void do_perl(struct st_query *command) Loading @@ -1860,10 +1878,23 @@ static void do_perl(struct st_query *command) char buf[FN_REFLEN]; FILE *res_file; DYNAMIC_STRING ds_script; DYNAMIC_STRING ds_delimiter; const struct command_arg perl_args[] = { "delimiter", ARG_STRING, FALSE, &ds_delimiter, "Delimiter to read until" }; DBUG_ENTER("do_perl"); check_command_args(command, command->first_argument, perl_args, sizeof(perl_args)/sizeof(struct command_arg)); /* If no delimiter was provided, use EOF */ if (ds_delimiter.length == 0) dynstr_set(&ds_delimiter, "EOF"); init_dynamic_string(&ds_script, "", 1024, 1024); read_until_EOF(&ds_script); read_until_delimiter(&ds_script, &ds_delimiter); DBUG_PRINT("info", ("Executing perl: %s", ds_script.str)); Loading Loading @@ -1894,6 +1925,7 @@ static void do_perl(struct st_query *command) error= pclose(res_file); handle_command_error(command, WEXITSTATUS(error)); dynstr_free(&ds_script); dynstr_free(&ds_delimiter); DBUG_VOID_RETURN; } Loading Loading @@ -2693,6 +2725,7 @@ static void free_replace_regex() { if (glob_replace_regex) { delete_dynamic(&glob_replace_regex->regex_arr); my_free(glob_replace_regex->even_buf,MYF(MY_ALLOW_ZERO_PTR)); my_free(glob_replace_regex->odd_buf,MYF(MY_ALLOW_ZERO_PTR)); my_free((char*) glob_replace_regex,MYF(0)); Loading Loading @@ -4164,6 +4197,7 @@ static int reg_replace(char** buf_p, int* buf_len_p, char *pattern, str_p= str_end; } } my_free((gptr)subs, MYF(0)); my_regfree(&r); *res_p= 0; *buf_p= buf; Loading mysql-test/r/mysqltest.result +4 −0 Original line number Diff line number Diff line Loading @@ -478,3 +478,7 @@ mysqltest: At line 1: Missing required argument 'to_file' to command 'copy_file' hello hello hello mysqltest: At line 1: Max delimiter length(16) exceeded hello hello End of tests mysql-test/t/mysqltest.test +26 −0 Original line number Diff line number Diff line Loading @@ -1182,6 +1182,18 @@ remove_file non_existing_file; --error 1 --exec echo "write_file filename \";" | $MYSQL_TEST 2>&1 write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; Content for test_file1 EOF file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp END_DELIMITER; Content for test_file1 contains EOF END_DELIMITER file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; # ---------------------------------------------------------------------------- # test for file_exist # ---------------------------------------------------------------------------- Loading Loading @@ -1226,6 +1238,17 @@ remove_file $MYSQLTEST_VARDIR/tmp/file2.tmp; print "hello\n"; EOF --perl EOF print "hello\n"; EOF --perl DELIMITER print "hello\n"; DELIMITER --error 1 --exec echo "perl TOO_LONG_DELIMITER ;" | $MYSQL_TEST 2>&1 perl; print "hello\n"; EOF Loading @@ -1234,3 +1257,6 @@ perl; # Print "hello" print "hello\n"; EOF --echo End of tests Loading
client/mysqltest.c +53 −19 Original line number Diff line number Diff line Loading @@ -16,12 +16,14 @@ /* mysqltest test tool * See the "MySQL Test framework manual" for more information * http://dev.mysql.com/doc/mysqltest/en/index.html * * Written by: * Sasha Pachev <sasha@mysql.com> * Matt Wagner <matt@mysql.com> * Monty * Jani * Magnus **/ #define MTEST_VERSION "2.7" Loading Loading @@ -1332,6 +1334,7 @@ static void do_exec(struct st_query *query) query->first_argument, query->expected_errno[0].code.errnum); } dynstr_free(&ds_cmd); free_replace(); DBUG_VOID_RETURN; } Loading Loading @@ -1757,22 +1760,32 @@ static my_bool match_delimiter(int c, const char* delim, uint length) } static void read_until_EOF(DYNAMIC_STRING* ds) static void read_until_delimiter(DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_delimiter) { int c; DBUG_ENTER("read_until_EOF"); DBUG_ENTER("read_until_delimiter"); DBUG_PRINT("enter", ("delimiter: %s, length: %d", ds_delimiter->str, ds_delimiter->length)); if (ds_delimiter->length > MAX_DELIMITER) die("Max delimiter length(%d) exceeded", MAX_DELIMITER); /* Read from file until delimiter EOF is found */ /* Read from file until delimiter is found */ while (1) { c= my_getc(cur_file->file); if (c == '\n') cur_file->lineno++; if (feof(cur_file->file)) die("End of file encountered before 'EOF' delimiter was found"); die("End of file encountered before '%s' delimiter was found", ds_delimiter->str); if (match_delimiter(c, "EOF", 3)) if (match_delimiter(c, ds_delimiter->str, ds_delimiter->length)) { DBUG_PRINT("exit", ("Found EOF")); DBUG_PRINT("exit", ("Found delimiter '%s'", ds_delimiter->str)); break; } dynstr_append_mem(ds, (const char*)&c, 1); Loading @@ -1788,7 +1801,7 @@ static void read_until_EOF(DYNAMIC_STRING* ds) command called command DESCRIPTION write_file <file_name>; write_file <file_name> [<delimiter>]; <what to write line 1> <...> < what to write line n> Loading @@ -1800,18 +1813,23 @@ static void read_until_EOF(DYNAMIC_STRING* ds) < what to write line n> EOF Write everything between the "write_file" command and EOF to "file_name" Write everything between the "write_file" command and 'delimiter' to "file_name" NOTE! Overwrites existing file Default <delimiter> is EOF */ static void do_write_file(struct st_query *command) { DYNAMIC_STRING ds_content; DYNAMIC_STRING ds_filename; DYNAMIC_STRING ds_delimiter; const struct command_arg write_file_args[] = { "filename", ARG_STRING, TRUE, &ds_filename, "File to write to", "delimiter", ARG_STRING, FALSE, &ds_delimiter, "Delimiter to read until" }; DBUG_ENTER("do_write_file"); Loading @@ -1820,12 +1838,17 @@ static void do_write_file(struct st_query *command) write_file_args, sizeof(write_file_args)/sizeof(struct command_arg)); /* If no delimiter was provided, use EOF */ if (ds_delimiter.length == 0) dynstr_set(&ds_delimiter, "EOF"); init_dynamic_string(&ds_content, "", 1024, 1024); read_until_EOF(&ds_content); read_until_delimiter(&ds_content, &ds_delimiter); DBUG_PRINT("info", ("Writing to file: %s", ds_filename.str)); str_to_file(ds_filename.str, ds_content.str, ds_content.length); dynstr_free(&ds_content); dynstr_free(&ds_filename); dynstr_free(&ds_delimiter); DBUG_VOID_RETURN; } Loading @@ -1836,22 +1859,17 @@ static void do_write_file(struct st_query *command) command command handle DESCRIPTION perl; perl [<delimiter>]; <perlscript line 1> <...> <perlscript line n> EOF Execute everything after "perl" until EOF as perl. Execute everything after "perl" until <delimiter> as perl. Useful for doing more advanced things but still being able to execute it on all platforms. The function sets delimiter to EOF and remembers that this is a perl command by setting "perl mode". The following lines will then be parsed as any normal query, but when searching for command in get_query_type, this function will be called again since "perl mode" is on and the perl script can be executed. Default <delimiter> is EOF */ static void do_perl(struct st_query *command) Loading @@ -1860,10 +1878,23 @@ static void do_perl(struct st_query *command) char buf[FN_REFLEN]; FILE *res_file; DYNAMIC_STRING ds_script; DYNAMIC_STRING ds_delimiter; const struct command_arg perl_args[] = { "delimiter", ARG_STRING, FALSE, &ds_delimiter, "Delimiter to read until" }; DBUG_ENTER("do_perl"); check_command_args(command, command->first_argument, perl_args, sizeof(perl_args)/sizeof(struct command_arg)); /* If no delimiter was provided, use EOF */ if (ds_delimiter.length == 0) dynstr_set(&ds_delimiter, "EOF"); init_dynamic_string(&ds_script, "", 1024, 1024); read_until_EOF(&ds_script); read_until_delimiter(&ds_script, &ds_delimiter); DBUG_PRINT("info", ("Executing perl: %s", ds_script.str)); Loading Loading @@ -1894,6 +1925,7 @@ static void do_perl(struct st_query *command) error= pclose(res_file); handle_command_error(command, WEXITSTATUS(error)); dynstr_free(&ds_script); dynstr_free(&ds_delimiter); DBUG_VOID_RETURN; } Loading Loading @@ -2693,6 +2725,7 @@ static void free_replace_regex() { if (glob_replace_regex) { delete_dynamic(&glob_replace_regex->regex_arr); my_free(glob_replace_regex->even_buf,MYF(MY_ALLOW_ZERO_PTR)); my_free(glob_replace_regex->odd_buf,MYF(MY_ALLOW_ZERO_PTR)); my_free((char*) glob_replace_regex,MYF(0)); Loading Loading @@ -4164,6 +4197,7 @@ static int reg_replace(char** buf_p, int* buf_len_p, char *pattern, str_p= str_end; } } my_free((gptr)subs, MYF(0)); my_regfree(&r); *res_p= 0; *buf_p= buf; Loading
mysql-test/r/mysqltest.result +4 −0 Original line number Diff line number Diff line Loading @@ -478,3 +478,7 @@ mysqltest: At line 1: Missing required argument 'to_file' to command 'copy_file' hello hello hello mysqltest: At line 1: Max delimiter length(16) exceeded hello hello End of tests
mysql-test/t/mysqltest.test +26 −0 Original line number Diff line number Diff line Loading @@ -1182,6 +1182,18 @@ remove_file non_existing_file; --error 1 --exec echo "write_file filename \";" | $MYSQL_TEST 2>&1 write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; Content for test_file1 EOF file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp END_DELIMITER; Content for test_file1 contains EOF END_DELIMITER file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; # ---------------------------------------------------------------------------- # test for file_exist # ---------------------------------------------------------------------------- Loading Loading @@ -1226,6 +1238,17 @@ remove_file $MYSQLTEST_VARDIR/tmp/file2.tmp; print "hello\n"; EOF --perl EOF print "hello\n"; EOF --perl DELIMITER print "hello\n"; DELIMITER --error 1 --exec echo "perl TOO_LONG_DELIMITER ;" | $MYSQL_TEST 2>&1 perl; print "hello\n"; EOF Loading @@ -1234,3 +1257,6 @@ perl; # Print "hello" print "hello\n"; EOF --echo End of tests