~percona-dev/percona-server/release-5.5.12-20.3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# 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!
diff -ruN a/extra/comp_err.c b/extra/comp_err.c
--- a/extra/comp_err.c	2011-04-09 18:48:04.000000000 +0400
+++ b/extra/comp_err.c	2011-04-09 18:48:56.000000000 +0400
@@ -30,11 +30,12 @@
 #include <assert.h>
 #include <my_dir.h>
 
-#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";
@@ -89,6 +90,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 */
 };
 
@@ -127,6 +129,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);
@@ -251,6 +254,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
@@ -343,12 +351,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 */
@@ -499,14 +524,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;
@@ -847,78 +884,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));
 }