diff options
author | Bjorn Munch <bjorn.munch@oracle.com> | 2010-10-04 10:40:28 +0200 |
---|---|---|
committer | Bjorn Munch <bjorn.munch@oracle.com> | 2010-10-04 10:40:28 +0200 |
commit | cd18aa31265ba919203a34bfbaf1d82c9c8f7d87 (patch) | |
tree | 8d0960b1e865d951eb003a09143ebe8828269ef5 /client | |
parent | 34388f53153b309ad4cb925e392c13dfb1bb62dc (diff) | |
parent | ad1824eed030ed1ce3e166c3d9faa02c339e12f7 (diff) | |
download | mariadb-git-cd18aa31265ba919203a34bfbaf1d82c9c8f7d87.tar.gz |
merge from 5.5-mtr
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqltest.cc | 97 |
1 files changed, 81 insertions, 16 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc index eb5c858b45b..5f28c000ac3 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -112,6 +112,7 @@ static my_bool parsing_disabled= 0; static my_bool display_result_vertically= FALSE, display_result_lower= FALSE, display_metadata= FALSE, display_result_sorted= FALSE; static my_bool disable_query_log= 0, disable_result_log= 0; +static my_bool disable_connect_log= 1; static my_bool disable_warnings= 0; static my_bool disable_info= 1; static my_bool abort_on_error= 1; @@ -227,8 +228,9 @@ typedef struct int str_val_len; int int_val; int alloced_len; - int int_dirty; /* do not update string if int is updated until first read */ - int alloced; + bool int_dirty; /* do not update string if int is updated until first read */ + bool is_int; + bool alloced; } VAR; /*Perl/shell-like variable registers */ @@ -286,6 +288,7 @@ enum enum_commands { Q_EVAL_RESULT, Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG, Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG, + Q_ENABLE_CONNECT_LOG, Q_DISABLE_CONNECT_LOG, Q_WAIT_FOR_SLAVE_TO_STOP, Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS, Q_ENABLE_INFO, Q_DISABLE_INFO, @@ -351,6 +354,8 @@ const char *command_names[]= /* Enable/disable that the _result_ from a query is logged to result file */ "enable_result_log", "disable_result_log", + "enable_connect_log", + "disable_connect_log", "wait_for_slave_to_stop", "enable_warnings", "disable_warnings", @@ -763,7 +768,6 @@ end_thread: return 0; } - static void wait_query_thread_done(struct st_connection *con) { DBUG_ASSERT(con->tid); @@ -805,7 +809,6 @@ static int do_send_query(struct st_connection *cn, const char *q, int q_len) return 0; } - static int do_read_query_result(struct st_connection *cn) { DBUG_ASSERT(cn->tid); @@ -844,7 +847,6 @@ static void init_connection_thd(struct st_connection *cn) die("Error in the thread library"); } - #else /*EMBEDDED_LIBRARY*/ #define do_send_query(cn,q,q_len) mysql_send_query(&cn->mysql, q, q_len) @@ -2036,6 +2038,21 @@ static void var_free(void *v) C_MODE_END +void var_set_int(VAR *v, const char *str) +{ + char *endptr; + /* Initially assume not a number */ + v->int_val= 0; + v->is_int= false; + v->int_dirty= false; + if (!str) return; + + v->int_val = (int) strtol(str, &endptr, 10); + /* It is an int if strtol consumed something up to end/space/tab */ + if (endptr > str && (!*endptr || *endptr == ' ' || *endptr == '\t')) + v->is_int= true; +} + VAR *var_init(VAR *v, const char *name, int name_len, const char *val, int val_len) @@ -2070,11 +2087,10 @@ VAR *var_init(VAR *v, const char *name, int name_len, const char *val, memcpy(tmp_var->str_val, val, val_len); tmp_var->str_val[val_len]= 0; } + var_set_int(tmp_var, val); tmp_var->name_len = name_len; tmp_var->str_val_len = val_len; tmp_var->alloced_len = val_alloc_len; - tmp_var->int_val = (val) ? atoi(val) : 0; - tmp_var->int_dirty = 0; return tmp_var; } @@ -2135,7 +2151,7 @@ VAR* var_get(const char *var_name, const char **var_name_end, my_bool raw, if (!raw && v->int_dirty) { sprintf(v->str_val, "%d", v->int_val); - v->int_dirty = 0; + v->int_dirty= false; v->str_val_len = strlen(v->str_val); } if (var_name_end) @@ -2197,7 +2213,7 @@ void var_set(const char *var_name, const char *var_name_end, if (v->int_dirty) { sprintf(v->str_val, "%d", v->int_val); - v->int_dirty= 0; + v->int_dirty=false; v->str_val_len= strlen(v->str_val); } /* setenv() expects \0-terminated strings */ @@ -2267,8 +2283,14 @@ void var_query_set(VAR *var, const char *query, const char** query_end) DBUG_ENTER("var_query_set"); LINT_INIT(res); + /* Only white space or ) allowed past ending ` */ while (end > query && *end != '`') + { + if (*end && (*end != ' ' && *end != '\t' && *end != '\n' && *end != ')')) + die("Spurious text after `query` expression"); --end; + } + if (query == end) die("Syntax error in query, missing '`'"); ++query; @@ -2497,6 +2519,7 @@ void var_set_query_get_value(struct st_command *command, VAR *var) void var_copy(VAR *dest, VAR *src) { dest->int_val= src->int_val; + dest->is_int= src->is_int; dest->int_dirty= src->int_dirty; /* Alloc/realloc data for str_val in dest */ @@ -2580,9 +2603,7 @@ void eval_expr(VAR *v, const char *p, const char **p_end) v->str_val_len = new_val_len; memcpy(v->str_val, p, new_val_len); v->str_val[new_val_len] = 0; - v->int_val=atoi(p); - DBUG_PRINT("info", ("atoi on '%s', returns: %d", p, v->int_val)); - v->int_dirty=0; + var_set_int(v, p); } DBUG_VOID_RETURN; } @@ -2929,6 +2950,8 @@ int do_modify_var(struct st_command *command, die("The argument to %.*s must be a variable (start with $)", command->first_word_len, command->query); v= var_get(p, &p, 1, 0); + if (! v->is_int) + die("Cannot perform inc/dec on a non-numeric value"); switch (op) { case DO_DEC: v->int_val--; @@ -2940,7 +2963,7 @@ int do_modify_var(struct st_command *command, die("Invalid operator to do_modify_var"); break; } - v->int_dirty= 1; + v->int_dirty= true; command->last_argument= (char*)++p; return 0; } @@ -3984,7 +4007,18 @@ void do_perl(struct st_command *command) if (!error) my_delete(temp_file_path, MYF(0)); - handle_command_error(command, WEXITSTATUS(error)); + /* Check for error code that indicates perl could not be started */ + int exstat= WEXITSTATUS(error); +#ifdef __WIN__ + if (exstat == 1) + /* Text must begin 'perl not found' as mtr looks for it */ + abort_not_supported_test("perl not found in path or did not start"); +#else + if (exstat == 127) + abort_not_supported_test("perl not found in path"); +#endif + else + handle_command_error(command, exstat); } dynstr_free(&ds_delimiter); DBUG_VOID_RETURN; @@ -4898,6 +4932,16 @@ void select_connection_name(const char *name) set_current_connection(con); + /* Connection logging if enabled */ + if (!disable_connect_log && !disable_query_log) + { + DYNAMIC_STRING *ds= &ds_res; + + dynstr_append_mem(ds, "connection ", 11); + replace_dynstr_append(ds, name); + dynstr_append_mem(ds, ";\n", 2); + } + DBUG_VOID_RETURN; } @@ -4985,6 +5029,16 @@ void do_close_connection(struct st_command *command) var_set_string("$CURRENT_CONNECTION", con->name); } + /* Connection logging if enabled */ + if (!disable_connect_log && !disable_query_log) + { + DYNAMIC_STRING *ds= &ds_res; + + dynstr_append_mem(ds, "disconnect ", 11); + replace_dynstr_append(ds, ds_connection.str); + dynstr_append_mem(ds, ";\n", 2); + } + DBUG_VOID_RETURN; } @@ -5119,6 +5173,13 @@ int connect_n_handle_errors(struct st_command *command, dynstr_append_mem(ds, delimiter, delimiter_length); dynstr_append_mem(ds, "\n", 1); } + /* Simlified logging if enabled */ + if (!disable_connect_log && !disable_query_log) + { + replace_dynstr_append(ds, command->query); + dynstr_append_mem(ds, ";\n", 2); + } + while (!mysql_real_connect(con, host, user, pass, db, port, sock ? sock: 0, CLIENT_MULTI_STATEMENTS)) { @@ -7436,11 +7497,13 @@ void run_query(struct st_connection *cn, struct st_command *command, int flags) (flags & QUERY_REAP_FLAG)); DBUG_ENTER("run_query"); - init_dynamic_string(&ds_warnings, NULL, 0, 256); - if (cn->pending && (flags & QUERY_SEND_FLAG)) die ("Cannot run query on connection between send and reap"); + if (!(flags & QUERY_SEND_FLAG) && !cn->pending) + die ("Cannot reap on a connection without pending send"); + + init_dynamic_string(&ds_warnings, NULL, 0, 256); /* Evaluate query if this is an eval command */ @@ -8185,6 +8248,8 @@ int main(int argc, char **argv) case Q_DISABLE_ABORT_ON_ERROR: abort_on_error=0; break; case Q_ENABLE_RESULT_LOG: disable_result_log=0; break; case Q_DISABLE_RESULT_LOG: disable_result_log=1; break; + case Q_ENABLE_CONNECT_LOG: disable_connect_log=0; break; + case Q_DISABLE_CONNECT_LOG: disable_connect_log=1; break; case Q_ENABLE_WARNINGS: disable_warnings=0; break; case Q_DISABLE_WARNINGS: disable_warnings=1; break; case Q_ENABLE_INFO: disable_info=0; break; |