# name : error_pad.patch # introduced : 12 # maintainer : Oleg # #!!! notice !!! # Any small change to this file in the main branch # should be done or reviewed by the maintainer! --- a/extra/comp_err.c +++ b/extra/comp_err.c @@ -32,11 +32,12 @@ #include #include -#define MAX_ROWS 1000 +#define MAX_ROWS 5000 #define HEADER_LENGTH 32 /* Length of header in errmsg.sys */ #define DEFAULT_CHARSET_DIR "../sql/share/charsets" #define ER_PREFIX "ER_" #define WARN_PREFIX "WARN_" +#define PADD_PREFIX "PADD_" static char *OUTFILE= (char*) "errmsg.sys"; static char *HEADERFILE= (char*) "mysqld_error.h"; static char *NAMEFILE= (char*) "mysqld_ername.h"; @@ -91,6 +92,7 @@ const char *sql_code1; /* sql state */ const char *sql_code2; /* ODBC state */ struct errors *next_error; /* Pointer to next error */ + my_bool is_padding; /* If true - padd this er_name while er_code != d_code*/ DYNAMIC_ARRAY msg; /* All language texts for this error */ }; @@ -129,6 +131,7 @@ static struct languages *parse_charset_string(char *str); +static struct errors *parse_padd_string(char *ptr, int er_count); static struct errors *parse_error_string(char *ptr, int er_count); static struct message *parse_message_string(struct message *new_message, char *str); @@ -253,6 +256,11 @@ for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error) { + if (tmp_error->is_padding) + { + er_last= tmp_error->d_code; + continue; + } /* generating mysqld_error.h fprintf() will automatically add \r on windows @@ -345,12 +353,29 @@ "language\n", tmp_error->er_name, tmp_lang->lang_short_name); goto err; } - if (copy_rows(to, tmp->text, row_nr, start_pos)) + if (tmp_error->is_padding) { - fprintf(stderr, "Failed to copy rows to %s\n", outfile); - goto err; + uint padd_to= tmp_error->d_code; + char* padd_message= tmp->text; + while ((row_nr+er_offset) < padd_to) + { + if (copy_rows(to, padd_message,row_nr,start_pos)) + { + fprintf(stderr, "Failed to copy rows to %s\n", outfile); + goto err; + } + row_nr++; + } + } + else + { + if (copy_rows(to, tmp->text, row_nr, start_pos)) + { + fprintf(stderr, "Failed to copy rows to %s\n", outfile); + goto err; + } + row_nr++; } - row_nr++; } /* continue with header of the errmsg.sys file */ @@ -501,14 +526,26 @@ DBUG_RETURN(0); continue; } - if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX)) + if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX) || is_prefix(str, PADD_PREFIX)) { - if (!(current_error= parse_error_string(str, rcount))) + if (is_prefix(str, PADD_PREFIX)) { - fprintf(stderr, "Failed to parse the error name string\n"); - DBUG_RETURN(0); + if (!(current_error= parse_padd_string(str, rcount))) + { + fprintf(stderr, "Failed to parse the error pad string\n"); + DBUG_RETURN(0); + } + rcount= current_error->d_code - er_offset; /* Count number of unique errors */ + } + else + { + if (!(current_error= parse_error_string(str, rcount))) + { + fprintf(stderr, "Failed to parse the error name string\n"); + DBUG_RETURN(0); + } + rcount++; /* Count number of unique errors */ } - rcount++; /* Count number of unique errors */ /* add error to the list */ *tail_error= current_error; @@ -849,78 +886,122 @@ DBUG_RETURN(new_message); } +static struct errors* create_new_error(my_bool is_padding, char *er_name, int d_code, const char *sql_code1, const char *sql_code2) +{ + struct errors *new_error; + DBUG_ENTER("create_new_error"); + /* create a new element */ + new_error= (struct errors *) my_malloc(sizeof(*new_error), MYF(MY_WME)); + if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0)) + DBUG_RETURN(0); /* OOM: Fatal error */ + new_error->is_padding= is_padding; + DBUG_PRINT("info", ("is_padding: %s", (is_padding ? "true" : "false"))); + new_error->er_name= er_name; + DBUG_PRINT("info", ("er_name: %s", er_name)); + new_error->d_code= d_code; + DBUG_PRINT("info", ("d_code: %d", d_code)); + new_error->sql_code1= sql_code1; + DBUG_PRINT("info", ("sql_code1: %s", sql_code1)); + new_error->sql_code2= sql_code2; + DBUG_PRINT("info", ("sql_code2: %s", sql_code2)); + DBUG_RETURN(new_error); +} /* - Parsing the string with error name and codes; returns the pointer to + Parsing the string with padd syntax (name + error to pad); returns the pointer to the errors struct */ -static struct errors *parse_error_string(char *str, int er_count) +static struct errors *parse_padd_string(char* str, int er_count) { - struct errors *new_error; + char *er_name; + uint d_code; + char *start; DBUG_ENTER("parse_error_string"); DBUG_PRINT("enter", ("str: %s", str)); - /* create a new element */ - new_error= (struct errors *) my_malloc(sizeof(*new_error), MYF(MY_WME)); + start= str; + str= skip_delimiters(str); - if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0)) + /* getting the error name */ + + if (!(er_name= get_word(&str))) DBUG_RETURN(0); /* OOM: Fatal error */ - /* getting the error name */ str= skip_delimiters(str); - if (!(new_error->er_name= get_word(&str))) + if (!(d_code= parse_error_offset(start))) + { + fprintf(stderr, "Failed to parse the error pad string '%s' '%s' (d_code doesn't parse)!\n",er_name,str); + DBUG_RETURN(0); + } + if (d_code < (uint)(er_offset + er_count)) + { + fprintf(stderr, "Error to padding less current error number!\n"); + DBUG_RETURN(0); + } + DBUG_RETURN(create_new_error(TRUE,er_name,d_code,empty_string,empty_string)); +} + +/* + Parsing the string with error name and codes; returns the pointer to + the errors struct +*/ + +static struct errors *parse_error_string(char *str, int er_count) +{ + char *er_name; + int d_code; + const char *sql_code1= empty_string; + const char *sql_code2= empty_string; + DBUG_ENTER("parse_error_string"); + DBUG_PRINT("enter", ("str: %s", str)); + + str= skip_delimiters(str); + + /* getting the error name */ + + if (!(er_name= get_word(&str))) DBUG_RETURN(0); /* OOM: Fatal error */ - DBUG_PRINT("info", ("er_name: %s", new_error->er_name)); str= skip_delimiters(str); /* getting the code1 */ - - new_error->d_code= er_offset + er_count; - DBUG_PRINT("info", ("d_code: %d", new_error->d_code)); + d_code= er_offset + er_count; str= skip_delimiters(str); /* if we reached EOL => no more codes, but this can happen */ if (!*str) { - new_error->sql_code1= empty_string; - new_error->sql_code2= empty_string; DBUG_PRINT("info", ("str: %s", str)); - DBUG_RETURN(new_error); + goto complete_create; } - /* getting the sql_code 1 */ - - if (!(new_error->sql_code1= get_word(&str))) + if (!(sql_code1= get_word(&str))) DBUG_RETURN(0); /* OOM: Fatal error */ - DBUG_PRINT("info", ("sql_code1: %s", new_error->sql_code1)); str= skip_delimiters(str); /* if we reached EOL => no more codes, but this can happen */ if (!*str) { - new_error->sql_code2= empty_string; DBUG_PRINT("info", ("str: %s", str)); - DBUG_RETURN(new_error); + goto complete_create; } - /* getting the sql_code 2 */ - if (!(new_error->sql_code2= get_word(&str))) + if (!(sql_code2= get_word(&str))) DBUG_RETURN(0); /* OOM: Fatal error */ - DBUG_PRINT("info", ("sql_code2: %s", new_error->sql_code2)); str= skip_delimiters(str); + if (*str) { fprintf(stderr, "The error line did not end with sql/odbc code!"); DBUG_RETURN(0); } - - DBUG_RETURN(new_error); +complete_create: + DBUG_RETURN(create_new_error(FALSE,er_name,d_code,sql_code1,sql_code2)); }