diff options
Diffstat (limited to 'client/mysqltest.cc')
-rw-r--r-- | client/mysqltest.cc | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc index d94023ccd0c..189da40dbf6 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -12,7 +12,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ /* mysqltest @@ -30,6 +31,7 @@ Monty Jani Holyfoot + And many others */ #define MTEST_VERSION "3.3" @@ -262,7 +264,7 @@ struct st_connection pthread_cond_t cond; pthread_t tid; int query_done; - my_bool has_thread; + my_bool has_thread, mutex_inited; #endif /*EMBEDDED_LIBRARY*/ }; @@ -474,6 +476,7 @@ TYPELIB command_typelib= {array_elements(command_names),"", command_names, 0}; DYNAMIC_STRING ds_res; +struct st_command *curr_command= 0; char builtin_echo[FN_REFLEN]; @@ -782,10 +785,12 @@ static int do_send_query(struct st_connection *cn, const char *q, int q_len, if (flags & QUERY_REAP_FLAG) return mysql_send_query(cn->mysql, q, q_len); - if (pthread_mutex_init(&cn->mutex, NULL) || - pthread_cond_init(&cn->cond, NULL)) + if (!cn->mutex_inited && + (pthread_mutex_init(&cn->mutex, NULL) || + pthread_cond_init(&cn->cond, NULL))) die("Error in the thread library"); + cn->mutex_inited= 1; cn->cur_query= q; cn->cur_query_len= q_len; cn->query_done= 0; @@ -815,9 +820,20 @@ static void wait_query_thread_end(struct st_connection *con) } } +static void free_embedded_data(struct st_connection *con) +{ + if (con->mutex_inited) + { + con->mutex_inited= 0; + pthread_mutex_destroy(&con->mutex); + pthread_cond_destroy(&con->cond); + } +} + #else /*EMBEDDED_LIBRARY*/ #define do_send_query(cn,q,q_len,flags) mysql_send_query(cn->mysql, q, q_len) +#define free_embedded_data(next_con) do { } while(0) #endif /*EMBEDDED_LIBRARY*/ @@ -1171,6 +1187,7 @@ void close_connections() if (next_con->util_mysql) mysql_close(next_con->util_mysql); my_free(next_con->name, MYF(MY_ALLOW_ZERO_PTR)); + free_embedded_data(next_con); } my_free(connections, MYF(MY_WME)); DBUG_VOID_RETURN; @@ -2288,9 +2305,16 @@ void var_query_set(VAR *var, const char *query, const char** query_end) init_dynamic_string(&ds_query, 0, (end - query) + 32, 256); do_eval(&ds_query, query, end, FALSE); - if (mysql_real_query(mysql, ds_query.str, ds_query.length)) - die("Error running query '%s': %d %s", ds_query.str, - mysql_errno(mysql), mysql_error(mysql)); + if (mysql_real_query(mysql, ds_query.str, ds_query.length)) + { + handle_error (curr_command, mysql_errno(mysql), mysql_error(mysql), + mysql_sqlstate(mysql), &ds_res); + /* If error was acceptable, return empty string */ + dynstr_free(&ds_query); + eval_expr(var, "", 0); + DBUG_VOID_RETURN; + } + if (!(res= mysql_store_result(mysql))) die("Query '%s' didn't return a result set", ds_query.str); dynstr_free(&ds_query); @@ -2391,8 +2415,15 @@ void var_set_query_get_value(struct st_command *command, VAR *var) /* Run the query */ if (mysql_real_query(mysql, ds_query.str, ds_query.length)) - die("Error running query '%s': %d %s", ds_query.str, - mysql_errno(mysql), mysql_error(mysql)); + { + handle_error (curr_command, mysql_errno(mysql), mysql_error(mysql), + mysql_sqlstate(mysql), &ds_res); + /* If error was acceptable, return empty string */ + dynstr_free(&ds_query); + eval_expr(var, "", 0); + DBUG_VOID_RETURN; + } + if (!(res= mysql_store_result(mysql))) die("Query '%s' didn't return a result set", ds_query.str); @@ -3046,7 +3077,7 @@ void do_remove_file(struct st_command *command) ' '); DBUG_PRINT("info", ("removing file: %s", ds_filename.str)); - error= my_delete(ds_filename.str, MYF(disable_warnings ? 0 : MY_WME)) != 0; + error= my_delete_allow_opened(ds_filename.str, MYF(disable_warnings ? 0 : MY_WME)) != 0; handle_command_error(command, error, my_errno); dynstr_free(&ds_filename); DBUG_VOID_RETURN; @@ -4543,13 +4574,14 @@ static int my_kill(int pid, int sig) command called command DESCRIPTION - shutdown [<timeout>] + shutdown_server [<timeout>] */ void do_shutdown_server(struct st_command *command) { - int timeout=60, pid; + long timeout=60; + int pid; DYNAMIC_STRING ds_pidfile_name; MYSQL* mysql = cur_con->mysql; static DYNAMIC_STRING ds_timeout; @@ -4564,8 +4596,9 @@ void do_shutdown_server(struct st_command *command) if (ds_timeout.length) { - timeout= atoi(ds_timeout.str); - if (timeout == 0) + char* endptr; + timeout= strtol(ds_timeout.str, &endptr, 10); + if (*endptr != '\0') die("Illegal argument for timeout: '%s'", ds_timeout.str); } dynstr_free(&ds_timeout); @@ -4607,7 +4640,7 @@ void do_shutdown_server(struct st_command *command) DBUG_PRINT("info", ("Process %d does not exist anymore", pid)); DBUG_VOID_RETURN; } - DBUG_PRINT("info", ("Sleeping, timeout: %d", timeout)); + DBUG_PRINT("info", ("Sleeping, timeout: %ld", timeout)); my_sleep(1000000L); } @@ -4985,6 +5018,7 @@ void do_close_connection(struct st_command *command) mysql_close(con->mysql); con->mysql= 0; + free_embedded_data(con); if (con->util_mysql) mysql_close(con->util_mysql); @@ -6219,7 +6253,7 @@ void print_version(void) void usage() { print_version(); - printf("MySQL AB, by Sasha, Matt, Monty & Jani\n"); + printf("MySQL AB, by Sasha, Matt, Monty & Jani and others\n"); printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("Runs a test against the mysql server and compares output with a results file.\n\n"); printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname); @@ -8287,6 +8321,8 @@ int main(int argc, char **argv) { command->last_argument= command->first_argument; processed = 1; + /* Need to remember this for handle_error() */ + curr_command= command; switch (command->type) { case Q_CONNECT: do_connect(command); @@ -9888,7 +9924,7 @@ int find_set(REP_SETS *sets,REP_SET *find) return i; } } - return i; /* return new postion */ + return i; /* return new position */ } /* find if there is a found_set with same table_offset & found_offset @@ -9908,7 +9944,7 @@ int find_found(FOUND_SET *found_set,uint table_offset, int found_offset) found_set[i].table_offset=table_offset; found_set[i].found_offset=found_offset; found_sets++; - return -i-2; /* return new postion */ + return -i-2; /* return new position */ } /* Return 1 if regexp starts with \b or ends with \b*/ |