]>
Commit | Line | Data |
---|---|---|
b4e1fa2c AM |
1 | # name : error_pad.patch |
2 | # introduced : 12 | |
3 | # maintainer : Oleg | |
4 | # | |
5 | #!!! notice !!! | |
6 | # Any small change to this file in the main branch | |
7 | # should be done or reviewed by the maintainer! | |
db82db79 AM |
8 | --- a/extra/comp_err.c |
9 | +++ b/extra/comp_err.c | |
10 | @@ -32,11 +32,12 @@ | |
b4e1fa2c AM |
11 | #include <assert.h> |
12 | #include <my_dir.h> | |
13 | ||
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"; | |
db82db79 | 24 | @@ -91,6 +92,7 @@ |
b4e1fa2c AM |
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 */ | |
30 | }; | |
31 | ||
db82db79 | 32 | @@ -129,6 +131,7 @@ |
b4e1fa2c AM |
33 | |
34 | ||
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, | |
39 | char *str); | |
db82db79 | 40 | @@ -253,6 +256,11 @@ |
b4e1fa2c AM |
41 | |
42 | for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error) | |
43 | { | |
44 | + if (tmp_error->is_padding) | |
45 | + { | |
46 | + er_last= tmp_error->d_code; | |
47 | + continue; | |
48 | + } | |
49 | /* | |
50 | generating mysqld_error.h | |
51 | fprintf() will automatically add \r on windows | |
db82db79 | 52 | @@ -345,12 +353,29 @@ |
b4e1fa2c AM |
53 | "language\n", tmp_error->er_name, tmp_lang->lang_short_name); |
54 | goto err; | |
55 | } | |
56 | - if (copy_rows(to, tmp->text, row_nr, start_pos)) | |
57 | + if (tmp_error->is_padding) | |
58 | { | |
59 | - fprintf(stderr, "Failed to copy rows to %s\n", outfile); | |
60 | - goto err; | |
61 | + uint padd_to= tmp_error->d_code; | |
62 | + char* padd_message= tmp->text; | |
63 | + while ((row_nr+er_offset) < padd_to) | |
64 | + { | |
65 | + if (copy_rows(to, padd_message,row_nr,start_pos)) | |
66 | + { | |
67 | + fprintf(stderr, "Failed to copy rows to %s\n", outfile); | |
68 | + goto err; | |
69 | + } | |
70 | + row_nr++; | |
71 | + } | |
72 | + } | |
73 | + else | |
74 | + { | |
75 | + if (copy_rows(to, tmp->text, row_nr, start_pos)) | |
76 | + { | |
77 | + fprintf(stderr, "Failed to copy rows to %s\n", outfile); | |
78 | + goto err; | |
79 | + } | |
80 | + row_nr++; | |
81 | } | |
82 | - row_nr++; | |
83 | } | |
84 | ||
85 | /* continue with header of the errmsg.sys file */ | |
db82db79 | 86 | @@ -501,14 +526,26 @@ |
b4e1fa2c AM |
87 | DBUG_RETURN(0); |
88 | continue; | |
89 | } | |
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)) | |
92 | { | |
93 | - if (!(current_error= parse_error_string(str, rcount))) | |
94 | + if (is_prefix(str, PADD_PREFIX)) | |
95 | { | |
96 | - fprintf(stderr, "Failed to parse the error name string\n"); | |
97 | - DBUG_RETURN(0); | |
98 | + if (!(current_error= parse_padd_string(str, rcount))) | |
99 | + { | |
d8778560 | 100 | + fprintf(stderr, "Failed to parse the error pad string\n"); |
b4e1fa2c AM |
101 | + DBUG_RETURN(0); |
102 | + } | |
103 | + rcount= current_error->d_code - er_offset; /* Count number of unique errors */ | |
104 | + } | |
105 | + else | |
106 | + { | |
107 | + if (!(current_error= parse_error_string(str, rcount))) | |
108 | + { | |
109 | + fprintf(stderr, "Failed to parse the error name string\n"); | |
110 | + DBUG_RETURN(0); | |
111 | + } | |
112 | + rcount++; /* Count number of unique errors */ | |
113 | } | |
114 | - rcount++; /* Count number of unique errors */ | |
115 | ||
116 | /* add error to the list */ | |
117 | *tail_error= current_error; | |
db82db79 | 118 | @@ -849,78 +886,122 @@ |
b4e1fa2c AM |
119 | DBUG_RETURN(new_message); |
120 | } | |
121 | ||
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) | |
123 | +{ | |
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); | |
141 | +} | |
142 | ||
143 | /* | |
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 | |
146 | the errors struct | |
147 | */ | |
148 | ||
149 | -static struct errors *parse_error_string(char *str, int er_count) | |
150 | +static struct errors *parse_padd_string(char* str, int er_count) | |
151 | { | |
152 | - struct errors *new_error; | |
153 | + char *er_name; | |
154 | + uint d_code; | |
155 | + char *start; | |
156 | DBUG_ENTER("parse_error_string"); | |
157 | DBUG_PRINT("enter", ("str: %s", str)); | |
158 | ||
159 | - /* create a new element */ | |
160 | - new_error= (struct errors *) my_malloc(sizeof(*new_error), MYF(MY_WME)); | |
161 | + start= str; | |
162 | + str= skip_delimiters(str); | |
163 | ||
164 | - if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0)) | |
165 | + /* getting the error name */ | |
166 | + | |
167 | + if (!(er_name= get_word(&str))) | |
168 | DBUG_RETURN(0); /* OOM: Fatal error */ | |
169 | ||
170 | - /* getting the error name */ | |
171 | str= skip_delimiters(str); | |
172 | ||
173 | - if (!(new_error->er_name= get_word(&str))) | |
174 | + if (!(d_code= parse_error_offset(start))) | |
175 | + { | |
d8778560 | 176 | + fprintf(stderr, "Failed to parse the error pad string '%s' '%s' (d_code doesn't parse)!\n",er_name,str); |
b4e1fa2c AM |
177 | + DBUG_RETURN(0); |
178 | + } | |
179 | + if (d_code < (uint)(er_offset + er_count)) | |
180 | + { | |
181 | + fprintf(stderr, "Error to padding less current error number!\n"); | |
182 | + DBUG_RETURN(0); | |
183 | + } | |
184 | + DBUG_RETURN(create_new_error(TRUE,er_name,d_code,empty_string,empty_string)); | |
185 | +} | |
186 | + | |
187 | +/* | |
188 | + Parsing the string with error name and codes; returns the pointer to | |
189 | + the errors struct | |
190 | +*/ | |
191 | + | |
192 | +static struct errors *parse_error_string(char *str, int er_count) | |
193 | +{ | |
194 | + char *er_name; | |
195 | + int d_code; | |
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)); | |
200 | + | |
201 | + str= skip_delimiters(str); | |
202 | + | |
203 | + /* getting the error name */ | |
204 | + | |
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)); | |
208 | ||
209 | str= skip_delimiters(str); | |
210 | ||
211 | /* getting the code1 */ | |
212 | - | |
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; | |
216 | ||
217 | str= skip_delimiters(str); | |
218 | ||
219 | /* if we reached EOL => no more codes, but this can happen */ | |
220 | if (!*str) | |
221 | { | |
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; | |
227 | } | |
228 | - | |
229 | /* getting the sql_code 1 */ | |
230 | - | |
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)); | |
235 | ||
236 | str= skip_delimiters(str); | |
237 | ||
238 | /* if we reached EOL => no more codes, but this can happen */ | |
239 | if (!*str) | |
240 | { | |
241 | - new_error->sql_code2= empty_string; | |
242 | DBUG_PRINT("info", ("str: %s", str)); | |
243 | - DBUG_RETURN(new_error); | |
244 | + goto complete_create; | |
245 | } | |
246 | - | |
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)); | |
252 | ||
253 | str= skip_delimiters(str); | |
254 | + | |
255 | if (*str) | |
256 | { | |
257 | fprintf(stderr, "The error line did not end with sql/odbc code!"); | |
258 | DBUG_RETURN(0); | |
259 | } | |
260 | - | |
261 | - DBUG_RETURN(new_error); | |
262 | +complete_create: | |
263 | + DBUG_RETURN(create_new_error(FALSE,er_name,d_code,sql_code1,sql_code2)); | |
264 | } | |
265 | ||
266 |