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!
14 -#define MAX_ROWS 1000
15 +#define MAX_ROWS 5000
16 #define HEADER_LENGTH 32 /* Length of header in errmsg.sys */
17 #define DEFAULT_CHARSET_DIR "../sql/share/charsets"
18 #define ER_PREFIX "ER_"
19 #define WARN_PREFIX "WARN_"
20 +#define PADD_PREFIX "PADD_"
21 static char *OUTFILE= (char*) "errmsg.sys";
22 static char *HEADERFILE= (char*) "mysqld_error.h";
23 static char *NAMEFILE= (char*) "mysqld_ername.h";
25 const char *sql_code1; /* sql state */
26 const char *sql_code2; /* ODBC state */
27 struct errors *next_error; /* Pointer to next error */
28 + my_bool is_padding; /* If true - padd this er_name while er_code != d_code*/
29 DYNAMIC_ARRAY msg; /* All language texts for this error */
35 static struct languages *parse_charset_string(char *str);
36 +static struct errors *parse_padd_string(char *ptr, int er_count);
37 static struct errors *parse_error_string(char *ptr, int er_count);
38 static struct message *parse_message_string(struct message *new_message,
42 for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
44 + if (tmp_error->is_padding)
46 + er_last= tmp_error->d_code;
50 generating mysqld_error.h
51 fprintf() will automatically add \r on windows
53 "language\n", tmp_error->er_name, tmp_lang->lang_short_name);
56 - if (copy_rows(to, tmp->text, row_nr, start_pos))
57 + if (tmp_error->is_padding)
59 - fprintf(stderr, "Failed to copy rows to %s\n", outfile);
61 + uint padd_to= tmp_error->d_code;
62 + char* padd_message= tmp->text;
63 + while ((row_nr+er_offset) < padd_to)
65 + if (copy_rows(to, padd_message,row_nr,start_pos))
67 + fprintf(stderr, "Failed to copy rows to %s\n", outfile);
75 + if (copy_rows(to, tmp->text, row_nr, start_pos))
77 + fprintf(stderr, "Failed to copy rows to %s\n", outfile);
85 /* continue with header of the errmsg.sys file */
90 - if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX))
91 + if (is_prefix(str, ER_PREFIX) || is_prefix(str, WARN_PREFIX) || is_prefix(str, PADD_PREFIX))
93 - if (!(current_error= parse_error_string(str, rcount)))
94 + if (is_prefix(str, PADD_PREFIX))
96 - fprintf(stderr, "Failed to parse the error name string\n");
98 + if (!(current_error= parse_padd_string(str, rcount)))
100 + fprintf(stderr, "Failed to parse the error pad string\n");
103 + rcount= current_error->d_code - er_offset; /* Count number of unique errors */
107 + if (!(current_error= parse_error_string(str, rcount)))
109 + fprintf(stderr, "Failed to parse the error name string\n");
112 + rcount++; /* Count number of unique errors */
114 - rcount++; /* Count number of unique errors */
116 /* add error to the list */
117 *tail_error= current_error;
118 @@ -849,78 +886,122 @@
119 DBUG_RETURN(new_message);
122 +static struct errors* create_new_error(my_bool is_padding, char *er_name, int d_code, const char *sql_code1, const char *sql_code2)
124 + struct errors *new_error;
125 + DBUG_ENTER("create_new_error");
126 + /* create a new element */
127 + new_error= (struct errors *) my_malloc(sizeof(*new_error), MYF(MY_WME));
128 + if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0))
129 + DBUG_RETURN(0); /* OOM: Fatal error */
130 + new_error->is_padding= is_padding;
131 + DBUG_PRINT("info", ("is_padding: %s", (is_padding ? "true" : "false")));
132 + new_error->er_name= er_name;
133 + DBUG_PRINT("info", ("er_name: %s", er_name));
134 + new_error->d_code= d_code;
135 + DBUG_PRINT("info", ("d_code: %d", d_code));
136 + new_error->sql_code1= sql_code1;
137 + DBUG_PRINT("info", ("sql_code1: %s", sql_code1));
138 + new_error->sql_code2= sql_code2;
139 + DBUG_PRINT("info", ("sql_code2: %s", sql_code2));
140 + DBUG_RETURN(new_error);
144 - Parsing the string with error name and codes; returns the pointer to
145 + Parsing the string with padd syntax (name + error to pad); returns the pointer to
149 -static struct errors *parse_error_string(char *str, int er_count)
150 +static struct errors *parse_padd_string(char* str, int er_count)
152 - struct errors *new_error;
156 DBUG_ENTER("parse_error_string");
157 DBUG_PRINT("enter", ("str: %s", str));
159 - /* create a new element */
160 - new_error= (struct errors *) my_malloc(sizeof(*new_error), MYF(MY_WME));
162 + str= skip_delimiters(str);
164 - if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0))
165 + /* getting the error name */
167 + if (!(er_name= get_word(&str)))
168 DBUG_RETURN(0); /* OOM: Fatal error */
170 - /* getting the error name */
171 str= skip_delimiters(str);
173 - if (!(new_error->er_name= get_word(&str)))
174 + if (!(d_code= parse_error_offset(start)))
176 + fprintf(stderr, "Failed to parse the error pad string '%s' '%s' (d_code doesn't parse)!\n",er_name,str);
179 + if (d_code < (uint)(er_offset + er_count))
181 + fprintf(stderr, "Error to padding less current error number!\n");
184 + DBUG_RETURN(create_new_error(TRUE,er_name,d_code,empty_string,empty_string));
188 + Parsing the string with error name and codes; returns the pointer to
192 +static struct errors *parse_error_string(char *str, int er_count)
196 + const char *sql_code1= empty_string;
197 + const char *sql_code2= empty_string;
198 + DBUG_ENTER("parse_error_string");
199 + DBUG_PRINT("enter", ("str: %s", str));
201 + str= skip_delimiters(str);
203 + /* getting the error name */
205 + if (!(er_name= get_word(&str)))
206 DBUG_RETURN(0); /* OOM: Fatal error */
207 - DBUG_PRINT("info", ("er_name: %s", new_error->er_name));
209 str= skip_delimiters(str);
211 /* getting the code1 */
213 - new_error->d_code= er_offset + er_count;
214 - DBUG_PRINT("info", ("d_code: %d", new_error->d_code));
215 + d_code= er_offset + er_count;
217 str= skip_delimiters(str);
219 /* if we reached EOL => no more codes, but this can happen */
222 - new_error->sql_code1= empty_string;
223 - new_error->sql_code2= empty_string;
224 DBUG_PRINT("info", ("str: %s", str));
225 - DBUG_RETURN(new_error);
226 + goto complete_create;
229 /* getting the sql_code 1 */
231 - if (!(new_error->sql_code1= get_word(&str)))
232 + if (!(sql_code1= get_word(&str)))
233 DBUG_RETURN(0); /* OOM: Fatal error */
234 - DBUG_PRINT("info", ("sql_code1: %s", new_error->sql_code1));
236 str= skip_delimiters(str);
238 /* if we reached EOL => no more codes, but this can happen */
241 - new_error->sql_code2= empty_string;
242 DBUG_PRINT("info", ("str: %s", str));
243 - DBUG_RETURN(new_error);
244 + goto complete_create;
247 /* getting the sql_code 2 */
248 - if (!(new_error->sql_code2= get_word(&str)))
249 + if (!(sql_code2= get_word(&str)))
250 DBUG_RETURN(0); /* OOM: Fatal error */
251 - DBUG_PRINT("info", ("sql_code2: %s", new_error->sql_code2));
253 str= skip_delimiters(str);
257 fprintf(stderr, "The error line did not end with sql/odbc code!");
261 - DBUG_RETURN(new_error);
263 + DBUG_RETURN(create_new_error(FALSE,er_name,d_code,sql_code1,sql_code2));