1 # name : error_pad.patch
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
8 diff -ruN a/extra/comp_err.c b/extra/comp_err.c
9 --- a/extra/comp_err.c 2011-04-09 18:48:04.000000000 +0400
10 +++ b/extra/comp_err.c 2011-04-09 18:48:56.000000000 +0400
15 -#define MAX_ROWS 1000
16 +#define MAX_ROWS 5000
17 #define HEADER_LENGTH 32 /* Length of header in errmsg.sys */
18 #define DEFAULT_CHARSET_DIR "../sql/share/charsets"
19 #define ER_PREFIX "ER_"
20 #define WARN_PREFIX "WARN_"
21 +#define PADD_PREFIX "PADD_"
22 static char *OUTFILE= (char*) "errmsg.sys";
23 static char *HEADERFILE= (char*) "mysqld_error.h";
24 static char *NAMEFILE= (char*) "mysqld_ername.h";
26 const char *sql_code1; /* sql state */
27 const char *sql_code2; /* ODBC state */
28 struct errors *next_error; /* Pointer to next error */
29 + my_bool is_padding; /* If true - padd this er_name while er_code != d_code*/
30 DYNAMIC_ARRAY msg; /* All language texts for this error */
36 static struct languages *parse_charset_string(char *str);
37 +static struct errors *parse_padd_string(char *ptr, int er_count);
38 static struct errors *parse_error_string(char *ptr, int er_count);
39 static struct message *parse_message_string(struct message *new_message,
43 for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
45 + if (tmp_error->is_padding)
47 + er_last= tmp_error->d_code;
51 generating mysqld_error.h
52 fprintf() will automatically add \r on windows
54 "language\n", tmp_error->er_name, tmp_lang->lang_short_name);
57 - if (copy_rows(to, tmp->text, row_nr, start_pos))
58 + if (tmp_error->is_padding)
60 - fprintf(stderr, "Failed to copy rows to %s\n", outfile);
62 + uint padd_to= tmp_error->d_code;
63 + char* padd_message= tmp->text;
64 + while ((row_nr+er_offset) < padd_to)
66 + if (copy_rows(to, padd_message,row_nr,start_pos))
68 + fprintf(stderr, "Failed to copy rows to %s\n", outfile);
76 + if (copy_rows(to, tmp->text, row_nr, start_pos))
78 + fprintf(stderr, "Failed to copy rows to %s\n", outfile);
86 /* continue with header of the errmsg.sys file */
91 - if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX))
92 + if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX) || is_prefix(str, PADD_PREFIX))
94 - if (!(current_error= parse_error_string(str, rcount)))
95 + if (is_prefix(str, PADD_PREFIX))
97 - fprintf(stderr, "Failed to parse the error name string\n");
99 + if (!(current_error= parse_padd_string(str, rcount)))
101 + fprintf(stderr, "Failed to parse the error pad string\n");
104 + rcount= current_error->d_code - er_offset; /* Count number of unique errors */
108 + if (!(current_error= parse_error_string(str, rcount)))
110 + fprintf(stderr, "Failed to parse the error name string\n");
113 + rcount++; /* Count number of unique errors */
115 - rcount++; /* Count number of unique errors */
117 /* add error to the list */
118 *tail_error= current_error;
119 @@ -847,78 +884,122 @@
120 DBUG_RETURN(new_message);
123 +static struct errors* create_new_error(my_bool is_padding, char *er_name, int d_code, const char *sql_code1, const char *sql_code2)
125 + struct errors *new_error;
126 + DBUG_ENTER("create_new_error");
127 + /* create a new element */
128 + new_error= (struct errors *) my_malloc(sizeof(*new_error), MYF(MY_WME));
129 + if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0))
130 + DBUG_RETURN(0); /* OOM: Fatal error */
131 + new_error->is_padding= is_padding;
132 + DBUG_PRINT("info", ("is_padding: %s", (is_padding ? "true" : "false")));
133 + new_error->er_name= er_name;
134 + DBUG_PRINT("info", ("er_name: %s", er_name));
135 + new_error->d_code= d_code;
136 + DBUG_PRINT("info", ("d_code: %d", d_code));
137 + new_error->sql_code1= sql_code1;
138 + DBUG_PRINT("info", ("sql_code1: %s", sql_code1));
139 + new_error->sql_code2= sql_code2;
140 + DBUG_PRINT("info", ("sql_code2: %s", sql_code2));
141 + DBUG_RETURN(new_error);
145 - Parsing the string with error name and codes; returns the pointer to
146 + Parsing the string with padd syntax (name + error to pad); returns the pointer to
150 -static struct errors *parse_error_string(char *str, int er_count)
151 +static struct errors *parse_padd_string(char* str, int er_count)
153 - struct errors *new_error;
157 DBUG_ENTER("parse_error_string");
158 DBUG_PRINT("enter", ("str: %s", str));
160 - /* create a new element */
161 - new_error= (struct errors *) my_malloc(sizeof(*new_error), MYF(MY_WME));
163 + str= skip_delimiters(str);
165 - if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0))
166 + /* getting the error name */
168 + if (!(er_name= get_word(&str)))
169 DBUG_RETURN(0); /* OOM: Fatal error */
171 - /* getting the error name */
172 str= skip_delimiters(str);
174 - if (!(new_error->er_name= get_word(&str)))
175 + if (!(d_code= parse_error_offset(start)))
177 + fprintf(stderr, "Failed to parse the error pad string '%s' '%s' (d_code doesn't parse)!\n",er_name,str);
180 + if (d_code < (uint)(er_offset + er_count))
182 + fprintf(stderr, "Error to padding less current error number!\n");
185 + DBUG_RETURN(create_new_error(TRUE,er_name,d_code,empty_string,empty_string));
189 + Parsing the string with error name and codes; returns the pointer to
193 +static struct errors *parse_error_string(char *str, int er_count)
197 + const char *sql_code1= empty_string;
198 + const char *sql_code2= empty_string;
199 + DBUG_ENTER("parse_error_string");
200 + DBUG_PRINT("enter", ("str: %s", str));
202 + str= skip_delimiters(str);
204 + /* getting the error name */
206 + if (!(er_name= get_word(&str)))
207 DBUG_RETURN(0); /* OOM: Fatal error */
208 - DBUG_PRINT("info", ("er_name: %s", new_error->er_name));
210 str= skip_delimiters(str);
212 /* getting the code1 */
214 - new_error->d_code= er_offset + er_count;
215 - DBUG_PRINT("info", ("d_code: %d", new_error->d_code));
216 + d_code= er_offset + er_count;
218 str= skip_delimiters(str);
220 /* if we reached EOL => no more codes, but this can happen */
223 - new_error->sql_code1= empty_string;
224 - new_error->sql_code2= empty_string;
225 DBUG_PRINT("info", ("str: %s", str));
226 - DBUG_RETURN(new_error);
227 + goto complete_create;
230 /* getting the sql_code 1 */
232 - if (!(new_error->sql_code1= get_word(&str)))
233 + if (!(sql_code1= get_word(&str)))
234 DBUG_RETURN(0); /* OOM: Fatal error */
235 - DBUG_PRINT("info", ("sql_code1: %s", new_error->sql_code1));
237 str= skip_delimiters(str);
239 /* if we reached EOL => no more codes, but this can happen */
242 - new_error->sql_code2= empty_string;
243 DBUG_PRINT("info", ("str: %s", str));
244 - DBUG_RETURN(new_error);
245 + goto complete_create;
248 /* getting the sql_code 2 */
249 - if (!(new_error->sql_code2= get_word(&str)))
250 + if (!(sql_code2= get_word(&str)))
251 DBUG_RETURN(0); /* OOM: Fatal error */
252 - DBUG_PRINT("info", ("sql_code2: %s", new_error->sql_code2));
254 str= skip_delimiters(str);
258 fprintf(stderr, "The error line did not end with sql/odbc code!");
262 - DBUG_RETURN(new_error);
264 + DBUG_RETURN(create_new_error(FALSE,er_name,d_code,sql_code1,sql_code2));