summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorBjorn Munch <bjorn.munch@oracle.com>2010-10-03 19:37:58 +0200
committerBjorn Munch <bjorn.munch@oracle.com>2010-10-03 19:37:58 +0200
commit687696a97a034dc559e769fbffa19e456f14d5cf (patch)
tree63f01aed8b048ca8480b1dbac85e1e908c86fa81 /client
parente1e838169a83acf352b43981a500684a68bec91a (diff)
parentad7521df31fef3258fe8170c2a07de1d04646f1e (diff)
downloadmariadb-git-687696a97a034dc559e769fbffa19e456f14d5cf.tar.gz
merge from 5.1-mtr
Diffstat (limited to 'client')
-rw-r--r--client/mysqltest.cc74
1 files changed, 68 insertions, 6 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index 936719523ef..38862210cba 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -103,6 +103,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;
@@ -242,7 +243,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*/
};
@@ -273,6 +276,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,
@@ -340,6 +344,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",
@@ -733,8 +739,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);
@@ -745,9 +749,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;
}
@@ -760,6 +765,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*/
@@ -2175,8 +2188,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;
@@ -3834,7 +3853,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;
@@ -4778,6 +4808,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;
}
@@ -4865,6 +4905,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;
}
@@ -4999,6 +5049,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))
{
@@ -5187,6 +5244,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()");
@@ -7307,11 +7365,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
*/
@@ -8052,6 +8112,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;