diff options
author | Michael Widenius <monty@askmonty.org> | 2010-11-23 23:39:59 +0200 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2010-11-23 23:39:59 +0200 |
commit | b52020221e8b4e58d1bc6dd5a5a6f065a6a3a083 (patch) | |
tree | 6068b9d90b4127b1c3608e29913fa82bf1a1f20e /client | |
parent | 7840965db9460e2117c163f3db83aaa247c65203 (diff) | |
parent | 498ee6bd19eabc85dcbd9abebc9cf6aeb79d1985 (diff) | |
download | mariadb-git-b52020221e8b4e58d1bc6dd5a5a6f065a6a3a083.tar.gz |
Merge with MySQL 5.1.52
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqltest.cc | 85 |
1 files changed, 77 insertions, 8 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 7f97dae3694..9df1837db95 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -109,6 +109,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 prepare_warnings_enabled= 0; static my_bool disable_info= 1; @@ -255,7 +256,9 @@ struct st_connection int cur_query_len; pthread_mutex_t mutex; pthread_cond_t cond; + pthread_t tid; int query_done; + my_bool has_thread; #endif /*EMBEDDED_LIBRARY*/ }; @@ -286,6 +289,7 @@ enum enum_commands { Q_DISABLE_RPL_PARSE, 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, @@ -354,6 +358,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", @@ -756,8 +762,6 @@ pthread_handler_t send_one_query(void *arg) static int do_send_query(struct st_connection *cn, const char *q, int q_len, int flags) { - pthread_t tid; - if (flags & QUERY_REAP_FLAG) return mysql_send_query(&cn->mysql, q, q_len); @@ -768,9 +772,10 @@ static int do_send_query(struct st_connection *cn, const char *q, int q_len, cn->cur_query= q; cn->cur_query_len= q_len; cn->query_done= 0; - if (pthread_create(&tid, &cn_thd_attrib, send_one_query, (void*)cn)) + if (pthread_create(&cn->tid, &cn_thd_attrib, send_one_query, (void*)cn)) die("Cannot start new thread for query"); + cn->has_thread= TRUE; return 0; } @@ -783,6 +788,14 @@ static void wait_query_thread_end(struct st_connection *con) pthread_cond_wait(&con->cond, &con->mutex); pthread_mutex_unlock(&con->mutex); } + if (con->has_thread) + { +#ifndef __WIN__ + /* May hang on Windows, but the problem it solves is not seen there */ + pthread_join(con->tid, NULL); +#endif + con->has_thread= FALSE; + } } #else /*EMBEDDED_LIBRARY*/ @@ -2222,8 +2235,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; @@ -3888,7 +3907,18 @@ void do_perl(struct st_command *command) if (!error) my_delete(temp_file_path, MYF(MY_WME)); - handle_command_error(command, WEXITSTATUS(error), my_errno); + /* 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, WEXITSTATUS(error), my_errno); } dynstr_free(&ds_delimiter); DBUG_VOID_RETURN; @@ -4832,6 +4862,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; } @@ -4918,6 +4958,17 @@ void do_close_connection(struct st_command *command) var_set_int("$mysql_get_server_version", 0xFFFFFFFF); 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); + } + dynstr_free(&ds_connection); DBUG_VOID_RETURN; } @@ -5053,6 +5104,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)) { @@ -5243,6 +5301,7 @@ void do_connect(struct st_command *command) #ifdef EMBEDDED_LIBRARY con_slot->query_done= 1; + con_slot->has_thread= FALSE; #endif if (!mysql_init(&con_slot->mysql)) die("Failed on mysql_init()"); @@ -5565,6 +5624,8 @@ int read_line(char *buf, int size) char c, UNINIT_VAR(last_quote); char *p= buf, *buf_end= buf + size - 1; int skip_char= 0; + my_bool have_slash= FALSE; + enum {R_NORMAL, R_Q, R_SLASH_IN_Q, R_COMMENT, R_LINE_START} state= R_LINE_START; DBUG_ENTER("read_line"); @@ -5636,9 +5697,13 @@ int read_line(char *buf, int size) } else if (c == '\'' || c == '"' || c == '`') { - last_quote= c; - state= R_Q; + if (! have_slash) + { + last_quote= c; + state= R_Q; + } } + have_slash= (c == '\\'); break; case R_COMMENT: @@ -7382,11 +7447,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 */ @@ -8127,6 +8194,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_PREPARE_WARNINGS: prepare_warnings_enabled=1; break; |