#At file:///home/malff/BZR-TREE/mysql-6.0-10143/
2745 Marc Alff 2008-08-05
Bug#10143 (Perror not showing error description)
Before this fix, errors described in sql/share/errmsg.txt were not
displayed by the perror utility.
With this fix, perror now is aware of these errors.
Fixed the code generation for include/mysqld_ername.h to add the error
message text.
Fixed perror to lookup errors in include/mysqld_ername.h.
Note that since the code is automatically generated,
any new error created in sql/share/errmsg.txt (the source code)
will be automatically recognized by perror, preventing the perror utility
to get out of sync with the main source code.
modified:
client/mysqltest.c
extra/comp_err.c
extra/perror.c
mysql-test/r/perror.result
mysql-test/t/perror.test
=== modified file 'client/mysqltest.c'
--- a/client/mysqltest.c 2008-07-24 08:26:24 +0000
+++ b/client/mysqltest.c 2008-08-05 23:26:18 +0000
@@ -3861,12 +3861,13 @@ typedef struct
{
const char *name;
uint code;
+ const char *text;
} st_error;
static st_error global_error_names[] =
{
#include <mysqld_ername.h>
- { 0, 0 }
+ { 0, 0, 0 }
};
uint get_errcode_from_name(char *error_name, char *error_end)
=== modified file 'extra/comp_err.c'
--- a/extra/comp_err.c 2008-04-09 00:56:49 +0000
+++ b/extra/comp_err.c 2008-08-05 23:26:18 +0000
@@ -199,11 +199,33 @@ int main(int argc, char *argv[])
}
+static int print_escaped_string(FILE *f, const char *str)
+{
+ const char *tmp = str;
+
+ while (tmp[0] != 0)
+ {
+ switch (tmp[0])
+ {
+ case '\\': fprintf(f, "\\\\"); break;
+ case '\'': fprintf(f, "\\\'"); break;
+ case '\"': fprintf(f, "\\\""); break;
+ case '\n': fprintf(f, "\\n"); break;
+ case '\r': fprintf(f, "\\r"); break;
+ default: fprintf(f, "%c", tmp[0]);
+ }
+ tmp++;
+ }
+}
+
+
static int create_header_files(struct errors *error_head)
{
uint er_last;
FILE *er_definef, *sql_statef, *er_namef;
struct errors *tmp_error;
+ struct message *er_msg;
+ const char *er_text;
DBUG_ENTER("create_header_files");
LINT_INIT(er_last);
@@ -245,8 +267,12 @@ static int create_header_files(struct er
"{ %-40s,\"%s\", \"%s\" },\n", tmp_error->er_name,
tmp_error->sql_code1, tmp_error->sql_code2);
/*generating er_name file */
- fprintf(er_namef, "{ \"%s\", %d },\n", tmp_error->er_name,
+ er_msg= find_message(tmp_error, default_language, FALSE);
+ er_text = (er_msg ? er_msg->text : "");
+ fprintf(er_namef, "{ \"%s\", %d, \"", tmp_error->er_name,
tmp_error->d_code);
+ print_escaped_string(er_namef, er_text);
+ fprintf(er_namef, "\" },\n");
}
/* finishing off with mysqld_error.h */
=== modified file 'extra/perror.c'
--- a/extra/perror.c 2008-03-28 19:59:20 +0000
+++ b/extra/perror.c 2008-08-05 23:26:18 +0000
@@ -184,11 +184,51 @@ static const char *get_ha_error_msg(int
return NullS;
}
+typedef struct
+{
+ const char *name;
+ uint code;
+ const char *text;
+} st_error;
+
+static st_error global_error_names[] =
+{
+#include <mysqld_ername.h>
+ { 0, 0, 0 }
+};
+
+/**
+ Lookup an error by code in the global_error_names array.
+ @param code the code to lookup
+ @param [out] name_ptr the error name, when found
+ @param [out] msg_ptr the error text, when found
+ @return 1 when found, otherwise 0
+*/
+int get_ER_error_msg(uint code, const char **name_ptr, const char **msg_ptr)
+{
+ st_error *tmp_error;
+
+ tmp_error= & global_error_names[0];
+
+ while (tmp_error->name != NULL)
+ {
+ if (tmp_error->code == code)
+ {
+ *name_ptr= tmp_error->name;
+ *msg_ptr= tmp_error->text;
+ return 1;
+ }
+ tmp_error++;
+ }
+
+ return 0;
+}
int main(int argc,char *argv[])
{
int error,code,found;
const char *msg;
+ const char *name;
char *unknown_error = 0;
MY_INIT(argv[0]);
@@ -291,6 +331,14 @@ int main(int argc,char *argv[])
else
puts(msg);
}
+ if (get_ER_error_msg(code, & name, & msg))
+ {
+ found= 1;
+ if (verbose)
+ printf("MySQL error code %3d (%s): %s\n", code, name, msg);
+ else
+ puts(msg);
+ }
if (!found)
{
fprintf(stderr,"Illegal error code: %d\n", code);
=== modified file 'mysql-test/r/perror.result'
--- a/mysql-test/r/perror.result 2006-08-01 09:29:10 +0000
+++ b/mysql-test/r/perror.result 2008-08-05 23:26:18 +0000
@@ -1 +1,6 @@
Illegal error code: 10000
+MySQL error code 1062 (ER_DUP_ENTRY): Duplicate entry '%-.192s' for key %d
+MySQL error code 1076 (ER_READY): %s: ready for connections.
+Version: '%s' socket: '%s' port: %d
+MySQL error code 1459 (ER_TABLE_NEEDS_UPGRADE): Table upgrade required. Please do "REPAIR TABLE `%-.32s`" to fix it!
+MySQL error code 1461 (ER_MAX_PREPARED_STMT_COUNT_REACHED): Can't create more than max_prepared_stmt_count statements (current value: %lu)
=== modified file 'mysql-test/t/perror.test'
--- a/mysql-test/t/perror.test 2006-08-01 09:29:10 +0000
+++ b/mysql-test/t/perror.test 2008-08-05 23:26:18 +0000
@@ -17,3 +17,17 @@ enable_query_log;
# As there is no error code defined for 10000, expect error
--error 1
--exec $MY_PERROR 10000 2>&1
+
+#
+# Bug#10143 (Perror not showing error description)
+#
+
+# test reported case
+--exec $MY_PERROR 1062 2>&1
+
+# test errors that contain characters to escape in the text.
+--exec $MY_PERROR 1076 2>&1
+--exec $MY_PERROR 1459 2>&1
+--exec $MY_PERROR 1461 2>&1
+
+
| Thread |
|---|
| • bzr commit into mysql-6.0-bugteam branch (marc.alff:2745) Bug#10143 | Marc Alff | 6 Aug |