diff --git a/client/mysqltest.c b/client/mysqltest.c index 86ef3525d1e..04d1f59dd4c 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -273,7 +273,7 @@ enum enum_commands { Q_DISABLE_PARSING, Q_ENABLE_PARSING, Q_REPLACE_REGEX, Q_REMOVE_FILE, Q_FILE_EXIST, Q_WRITE_FILE, Q_COPY_FILE, Q_PERL, Q_DIE, Q_EXIT, - Q_CHMOD_FILE, Q_APPEND_FILE, + Q_CHMOD_FILE, Q_APPEND_FILE, Q_CAT_FILE, Q_UNKNOWN, /* Unknown command. */ Q_COMMENT, /* Comments, ignored. */ @@ -358,6 +358,7 @@ const char *command_names[]= "exit", "chmod", "append_file", + "cat_file", 0 }; @@ -2161,6 +2162,50 @@ void do_append_file(struct st_command *command) } +/* + SYNOPSIS + do_cat_file + command called command + + DESCRIPTION + cat_file ; + + Print the given file to result log + +*/ + +void do_cat_file(struct st_command *command) +{ + int fd; + uint len; + byte buff[512]; + static DYNAMIC_STRING ds_filename; + const struct command_arg cat_file_args[] = { + "filename", ARG_STRING, TRUE, &ds_filename, "File to read from" + }; + DBUG_ENTER("do_cat_file"); + + check_command_args(command, + command->first_argument, + cat_file_args, + sizeof(cat_file_args)/sizeof(struct command_arg), + ' '); + + DBUG_PRINT("info", ("Reading from, file: %s", ds_filename.str)); + + if ((fd= my_open(ds_filename.str, O_RDONLY, MYF(0))) < 0) + die("Failed to open file %s", ds_filename.str); + while((len= my_read(fd, &buff, + sizeof(buff), MYF(0))) > 0) + { + dynstr_append_mem(&ds_res, buff, len); + } + my_close(fd, MYF(0)); + dynstr_free(&ds_filename); + DBUG_VOID_RETURN; +} + + /* SYNOPSIS do_perl @@ -5927,6 +5972,7 @@ int main(int argc, char **argv) case Q_FILE_EXIST: do_file_exist(command); break; case Q_WRITE_FILE: do_write_file(command); break; case Q_APPEND_FILE: do_append_file(command); break; + case Q_CAT_FILE: do_cat_file(command); break; case Q_COPY_FILE: do_copy_file(command); break; case Q_CHMOD_FILE: do_chmod_file(command); break; case Q_PERL: do_perl(command); break; diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 3ddb82d4a8d..a8b5a5ef353 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -509,6 +509,10 @@ mysqltest: At line 1: Missing required argument 'filename' to command 'write_fil mysqltest: At line 1: End of file encountered before 'EOF' delimiter was found mysqltest: At line 1: End of line junk detected: "write_file filename "; " +Some data +for cat_file command +of mysqltest +mysqltest: At line 1: Failed to open file non_existing_file mysqltest: At line 1: Missing required argument 'filename' to command 'file_exists' mysqltest: At line 1: Missing required argument 'from_file' to command 'copy_file' mysqltest: At line 1: Missing required argument 'to_file' to command 'copy_file' diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 2182ea6cb0b..f98389effa3 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -1503,6 +1503,20 @@ append_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; Appended text on nonexisting file EOF +# ---------------------------------------------------------------------------- +# test for cat_file +# ---------------------------------------------------------------------------- + +--write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp +Some data +for cat_file command +of mysqltest +EOF +cat_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; + +--error 1 +--exec echo "cat_file non_existing_file;" | $MYSQL_TEST 2>&1 + # ---------------------------------------------------------------------------- # test for file_exist # ----------------------------------------------------------------------------