From 135b586378d50124815cfd71e097ad1782117ae0 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Aug 2007 10:39:48 +0200 Subject: [PATCH 1/4] Fix spelling errors --- client/mysqltest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 337a31ad7af..0b1565af16d 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -499,11 +499,11 @@ void handle_no_error(struct st_command*); pthread_attr_t cn_thd_attrib; /* - send_one_query executes query in separate thread what is + send_one_query executes query in separate thread, which is necessary in embedded library to run 'send' in proper way. This implementation doesn't handle errors returned by mysql_send_query. It's technically possible, though - i don't see where it is needed. + I don't see where it is needed. */ pthread_handler_t send_one_query(void *arg) { From 050256c2d74b4b358670039e92b33cf2051b9559 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Aug 2007 11:20:36 +0200 Subject: [PATCH 2/4] Remove NOT_YET code Update comments Add more tests for "let from query" client/mysqltest.c: Remove NOT_YET code Update comments mysql-test/r/mysqltest.result: Add more tests for "let from query" mysql-test/t/mysqltest.test: Add more tests for "let from query" --- client/mysqltest.c | 30 ++++++------------------------ mysql-test/r/mysqltest.result | 12 ++++++++++++ mysql-test/t/mysqltest.test | 34 ++++++++++++++++++---------------- 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 0b1565af16d..7e10c040851 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1777,40 +1777,22 @@ void var_query_set(VAR *var, const char *query, const char** query_end) die("Query '%s' didn't return a result set", ds_query.str); dynstr_free(&ds_query); - if ((row = mysql_fetch_row(res)) && row[0]) + if ((row= mysql_fetch_row(res)) && row[0]) { /* - Concatenate all row results with tab in between to allow us to work - with results from many columns (for example from SHOW VARIABLES) + Concatenate all fields in the first row with tab in between + and assign that string to the $variable */ DYNAMIC_STRING result; uint i; ulong *lengths; -#ifdef NOT_YET - MYSQL_FIELD *fields= mysql_fetch_fields(res); -#endif - init_dynamic_string(&result, "", 2048, 2048); + init_dynamic_string(&result, "", 512, 512); lengths= mysql_fetch_lengths(res); - for (i=0; i < mysql_num_fields(res); i++) + for (i= 0; i < mysql_num_fields(res); i++) { - if (row[0]) + if (row[i]) { -#ifdef NOT_YET - /* Add to _ */ - uint j; - char var_col_name[MAX_VAR_NAME_LENGTH]; - uint length= snprintf(var_col_name, MAX_VAR_NAME_LENGTH, - "$%s_%s", var->name, fields[i].name); - /* Convert characters not allowed in variable names to '_' */ - for (j= 1; j < length; j++) - { - if (!my_isvar(charset_info,var_col_name[j])) - var_col_name[j]= '_'; - } - var_set(var_col_name, var_col_name + length, - row[i], row[i] + lengths[i]); -#endif /* Add column to tab separated string */ dynstr_append_mem(&result, row[i], lengths[i]); } diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 300ca69f2b4..513216c062e 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -280,6 +280,18 @@ let $B = changed value of B; var2: content of variable 1 var3: content of variable 1 content of variable 1 length of var3 is longer than 0 +var1 +hi 1 hi there +var2 +2 +var2 again +2 +var3 two columns with same name +1 2 3 +var4 from query that returns NULL +var5 from query that returns no row +failing query in let +mysqltest: At line 1: Error running query 'failing query': 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'failing query' at line 1 mysqltest: At line 1: Missing required argument 'filename' to command 'source' mysqltest: At line 1: Could not open file ./non_existingFile mysqltest: In included file "MYSQLTEST_VARDIR/tmp/recursive.sql": At line 1: Source directives are nesting too deep diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 9c29840ba9b..20140307e57 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -736,38 +736,40 @@ if (`select length("$var3") > 0`) # Test to assign let from query # let $=``; # ---------------------------------------------------------------------------- ---disable_parsing echo var1; let $var1= `select "hi" as "Col", 1 as "Column1", "hi there" as Col3`; echo $var1; -echo $var1_Col; -echo $var1_Column1; -echo $var1_Col3; echo var2; let $var2= `select 2 as "Column num 2"`; echo $var2; -echo $var2_Column num 2; -echo $var2_Column; echo var2 again; let $var2= `select 2 as "Column num 2"`; echo $var2; -echo $var2_Column num 2; -echo $var2_Column_num_2; -echo $var2_Column; echo var3 two columns with same name; let $var3= `select 1 as "Col", 2 as "Col", 3 as "var3"`; echo $var3; -echo $var3_Col; -echo $var3_Col; -echo $var3_var3; -#echo failing query in let; -#--error 1 -#--exec echo "let $var2= `failing query;`" | $MYSQL_TEST 2>&1 ---enable_parsing +echo var4 from query that returns NULL; +let $var4= `select NULL`; + +echo var5 from query that returns no row; +let $var5= `SHOW VARIABLES LIKE "nonexisting_variable"`; + +echo failing query in let; +--write_file $MYSQLTEST_VARDIR/tmp/let.sql +let $var2= `failing query`; +echo $var2; +EOF + +--error 1 +--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/let.sql 2>&1 + +remove_file $MYSQLTEST_VARDIR/tmp/let.sql; + + # ---------------------------------------------------------------------------- # Test source command # ---------------------------------------------------------------------------- From 275a80302173140f93579caa857a48b5e4a291ed Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Aug 2007 13:42:00 +0200 Subject: [PATCH 3/4] Add missing ' Extend buffer size to allow for longer log messages --- client/mysqltest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 7e10c040851..1659c7e6ac5 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1006,7 +1006,7 @@ void warning_msg(const char *fmt, ...) void log_msg(const char *fmt, ...) { va_list args; - char buff[512]; + char buff[1024]; size_t len; DBUG_ENTER("log_msg"); @@ -2269,7 +2269,7 @@ void do_exec(struct st_command *command) if (command->abort_on_error) { - log_msg("exec of '%s failed, error: %d, status: %d, errno: %d", + log_msg("exec of '%s' failed, error: %d, status: %d, errno: %d", ds_cmd.str, error, status, errno); die("command \"%s\" failed", command->first_argument); } From c35318cee16459c96be5803e80e2a2d9857615b3 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Aug 2007 11:56:30 +0200 Subject: [PATCH 4/4] Bug#29547 mysql-test-run to retrieve warnings for failed command - Run "SHOW WARNINGS" when mysqltest fails and display all but the last warning(since it's the same as "last error") on stderr - Fix typo client/mysqltest.c: - Display any warnings produced prior to the error that caused mysqltest to die. - Fix typo "cur_con" -> "con_slot" - Move initialization of the "cur_con" pointer to just before it's initialized so it can be used to check if a connection to mysql exist. --- client/mysqltest.c | 85 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 1659c7e6ac5..1d481f33f47 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -235,7 +235,7 @@ struct st_connection #endif /*EMBEDDED_LIBRARY*/ }; struct st_connection connections[128]; -struct st_connection* cur_con, *next_con, *connections_end; +struct st_connection* cur_con= NULL, *next_con, *connections_end; /* List of commands in mysqltest @@ -604,6 +604,77 @@ void do_eval(DYNAMIC_STRING *query_eval, const char *query, } +/* + Show any warnings just before the error. Since the last error + is added to the warning stack, only print @@warning_count-1 warnings. + + NOTE! This function should be safe to call when an error + has occured and this any further errors will be ignored(although logged) + + SYNOPSIS + show_warnings_before_error + mysql - connection to use + +*/ + +static void show_warnings_before_error(MYSQL* mysql) +{ + MYSQL_RES* res; + const char* query= "SHOW WARNINGS"; + DBUG_ENTER("show_warnings_before_error"); + + if (!mysql) + DBUG_VOID_RETURN; + + if (mysql_query(mysql, query)) + { + log_msg("Error running query '%s': %d %s", + query, mysql_errno(mysql), mysql_error(mysql)); + DBUG_VOID_RETURN; + } + + if ((res= mysql_store_result(mysql)) == NULL) + { + /* No result set returned */ + DBUG_VOID_RETURN; + } + + if (mysql_num_rows(res) <= 1) + { + /* Don't display the last row, it's "last error" */ + } + else + { + MYSQL_ROW row; + unsigned int row_num= 0; + unsigned int num_fields= mysql_num_fields(res); + + fprintf(stderr, "\nWarnings from just before the error:\n"); + while ((row= mysql_fetch_row(res))) + { + unsigned int i; + unsigned long *lengths= mysql_fetch_lengths(res); + + if (++row_num >= mysql_num_rows(res)) + { + /* Don't display the last row, it's "last error" */ + break; + } + + for(i= 0; i < num_fields; i++) + { + fprintf(stderr, "%.*s ", lengths[i], + row[i] ? row[i] : "NULL"); + } + fprintf(stderr, "\n"); + } + } + mysql_free_result(res); + + DBUG_VOID_RETURN; +} + + enum arg_type { ARG_STRING, @@ -903,6 +974,13 @@ void die(const char *fmt, ...) if (result_file_name && ds_warning_messages.length) dump_warning_messages(); + /* + Help debugging by displaying any warnings that might have + been produced prior to the error + */ + if (cur_con) + show_warnings_before_error(&cur_con->mysql); + cleanup_and_exit(1); } @@ -1010,7 +1088,6 @@ void log_msg(const char *fmt, ...) size_t len; DBUG_ENTER("log_msg"); - memset(buff, 0, sizeof(buff)); va_start(args, fmt); len= my_vsnprintf(buff, sizeof(buff)-1, fmt, args); va_end(args); @@ -4044,7 +4121,7 @@ void do_connect(struct st_command *command) mysql_options(&con_slot->mysql, MYSQL_SET_CHARSET_NAME, charset_info->csname); if (opt_charsets_dir) - mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_DIR, + mysql_options(&con_slot->mysql, MYSQL_SET_CHARSET_DIR, opt_charsets_dir); #ifdef HAVE_OPENSSL @@ -6471,7 +6548,6 @@ int main(int argc, char **argv) connections_end= connections + (sizeof(connections)/sizeof(struct st_connection)) - 1; next_con= connections + 1; - cur_con= connections; #ifdef EMBEDDED_LIBRARY /* set appropriate stack for the 'query' threads */ @@ -6547,6 +6623,7 @@ int main(int argc, char **argv) if (cursor_protocol_enabled) ps_protocol_enabled= 1; + cur_con= connections; if (!( mysql_init(&cur_con->mysql))) die("Failed in mysql_init()"); if (opt_compress)