diff options
author | unknown <ram@mysql.r18.ru> | 2003-09-08 10:53:51 +0500 |
---|---|---|
committer | unknown <ram@mysql.r18.ru> | 2003-09-08 10:53:51 +0500 |
commit | 2b185547447b507cc042e90289aa39b73de9a16f (patch) | |
tree | cc29f8c5e8b28ad711e25a6d0dbdfe4f995aa0d3 /client/mysqltest.c | |
parent | 7c835f0a5269283011584bb3f04cbf8a8efd7848 (diff) | |
download | mariadb-git-2b185547447b507cc042e90289aa39b73de9a16f.tar.gz |
#1169: Add --exec command to mysqltest
Diffstat (limited to 'client/mysqltest.c')
-rw-r--r-- | client/mysqltest.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c index 3b814b27810..7b5aee49bd5 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -204,6 +204,7 @@ Q_WAIT_FOR_SLAVE_TO_STOP, Q_REQUIRE_VERSION, Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS, Q_ENABLE_INFO, Q_DISABLE_INFO, +Q_EXEC, Q_UNKNOWN, /* Unknown command. */ Q_COMMENT, /* Comments, ignored. */ Q_COMMENT_WITH_COMMAND @@ -267,6 +268,7 @@ const char *command_names[]= "disable_warnings", "enable_info", "disable_info", + "exec", 0 }; @@ -840,6 +842,66 @@ int do_source(struct st_query* q) return open_file(name); } +/* + Execute given command. + + SYNOPSIS + do_exec() + q called command + + DESCRIPTION + If one uses --exec command [args] command in .test file + we will execute the command and record its output. + + RETURN VALUES + 0 ok + 1 error +*/ + +int do_exec(struct st_query* q) +{ + int error= 0; + DYNAMIC_STRING *ds; + DYNAMIC_STRING ds_tmp; + char buf[1024]; + FILE *res_file; + char *cmd= q->first_argument; + + while (*cmd && my_isspace(charset_info, *cmd)) + cmd++; + if (!*cmd) + die("Missing argument in exec\n"); + + if (q->record_file[0]) + { + init_dynamic_string(&ds_tmp, "", 16384, 65536); + ds= &ds_tmp; + } + else + ds= &ds_res; + + if (!(res_file= popen(cmd, "r")) && q->abort_on_error) + die("popen() failed\n"); + while (fgets(buf, sizeof(buf), res_file)) + dynstr_append(ds, buf); + pclose(res_file); + if (record) + { + if (!q->record_file[0] && !result_file) + die("At line %u: Missing result file", start_lineno); + if (!result_file) + str_to_file(q->record_file, ds->str, ds->length); + } + else if (q->record_file[0]) + { + error= check_result(ds, q->record_file, q->require_file); + } + if (ds == &ds_tmp) + dynstr_free(&ds_tmp); + + return error; +} + int var_query_set(VAR* v, const char* p, const char** p_end) { char* end = (char*)((p_end && *p_end) ? *p_end : p + strlen(p)); @@ -2584,6 +2646,9 @@ int main(int argc, char **argv) case Q_PING: (void) mysql_ping(&cur_con->mysql); break; + case Q_EXEC: + (void) do_exec(q); + break; default: processed = 0; break; } } |