~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/derror.cc

  • Committer: Monty Taylor
  • Date: 2008-07-02 14:35:48 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: monty@inaugust.com-20080702143548-onj30ry0sugr01uw
Removed all references to THREAD.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
  Read language depeneded messagefile
22
22
*/
23
23
 
24
 
#include <drizzled/server_includes.h>
25
 
#include <mysys/mysys_err.h>
26
 
#include <drizzled/drizzled_error_messages.h>
 
24
#include "mysql_priv.h"
 
25
#include "mysys_err.h"
27
26
 
 
27
static bool read_texts(const char *file_name,const char ***point,
 
28
                       uint error_messages);
28
29
static void init_myfunc_errs(void);
29
30
 
30
 
 
31
 
 
32
31
/**
33
32
  Read messages from errorfile.
34
33
 
45
44
 
46
45
bool init_errmessage(void)
47
46
{
 
47
  const char **errmsgs, **ptr;
 
48
  DBUG_ENTER("init_errmessage");
 
49
 
 
50
  /*
 
51
    Get a pointer to the old error messages pointer array.
 
52
    read_texts() tries to free it.
 
53
  */
 
54
  errmsgs= my_error_unregister(ER_ERROR_FIRST, ER_ERROR_LAST);
 
55
 
 
56
  /* Read messages from file. */
 
57
  if (read_texts(ERRMSG_FILE, &errmsgs, ER_ERROR_LAST - ER_ERROR_FIRST + 1) &&
 
58
      !errmsgs)
 
59
  {
 
60
    if (!(errmsgs= (const char**) my_malloc((ER_ERROR_LAST-ER_ERROR_FIRST+1)*
 
61
                                            sizeof(char*), MYF(0))))
 
62
      DBUG_RETURN(TRUE);
 
63
    for (ptr= errmsgs; ptr < errmsgs + ER_ERROR_LAST - ER_ERROR_FIRST; ptr++)
 
64
          *ptr= "";
 
65
  }
48
66
 
49
67
  /* Register messages for use with my_error(). */
50
 
  if (my_error_register(drizzled_error_messages,
51
 
                        ER_ERROR_FIRST, ER_ERROR_LAST))
 
68
  if (my_error_register(errmsgs, ER_ERROR_FIRST, ER_ERROR_LAST))
52
69
  {
53
 
    return(true);
 
70
    x_free((uchar*) errmsgs);
 
71
    DBUG_RETURN(TRUE);
54
72
  }
55
73
 
 
74
  errmesg= errmsgs;                     /* Init global variabel */
56
75
  init_myfunc_errs();                   /* Init myfunc messages */
57
 
  return(false);
 
76
  DBUG_RETURN(FALSE);
58
77
}
59
78
 
60
79
 
61
80
/**
 
81
  Read text from packed textfile in language-directory.
 
82
 
 
83
  If we can't read messagefile then it's panic- we can't continue.
 
84
 
 
85
  @todo
 
86
    Convert the character set to server system character set
 
87
*/
 
88
 
 
89
static bool read_texts(const char *file_name,const char ***point,
 
90
                       uint error_messages)
 
91
{
 
92
  register uint i;
 
93
  uint count,funktpos,textcount;
 
94
  size_t length;
 
95
  File file;
 
96
  char name[FN_REFLEN];
 
97
  uchar *buff;
 
98
  uchar head[32],*pos;
 
99
  const char *errmsg;
 
100
  DBUG_ENTER("read_texts");
 
101
 
 
102
  funktpos=0;
 
103
  if ((file=my_open(fn_format(name,file_name,language,"",4),
 
104
                    O_RDONLY | O_SHARE | O_BINARY,
 
105
                    MYF(0))) < 0)
 
106
    goto err; /* purecov: inspected */
 
107
 
 
108
  funktpos=1;
 
109
  if (my_read(file,(uchar*) head,32,MYF(MY_NABP))) goto err;
 
110
  if (head[0] != (uchar) 254 || head[1] != (uchar) 254 ||
 
111
      head[2] != 2 || head[3] != 1)
 
112
    goto err; /* purecov: inspected */
 
113
  textcount=head[4];
 
114
 
 
115
  if (!head[30])
 
116
  {
 
117
    sql_print_error("Character set information not found in '%s'. \
 
118
Please install the latest version of this file.",name);
 
119
    goto err1;
 
120
  }
 
121
  
 
122
  /* TODO: Convert the character set to server system character set */
 
123
  if (!get_charset(head[30],MYF(MY_WME)))
 
124
  {
 
125
    sql_print_error("Character set #%d is not supported for messagefile '%s'",
 
126
                    (int)head[30],name);
 
127
    goto err1;
 
128
  }
 
129
  
 
130
  length=uint2korr(head+6); count=uint2korr(head+8);
 
131
 
 
132
  if (count < error_messages)
 
133
  {
 
134
    sql_print_error("\
 
135
Error message file '%s' had only %d error messages,\n\
 
136
but it should contain at least %d error messages.\n\
 
137
Check that the above file is the right version for this program!",
 
138
                    name,count,error_messages);
 
139
    VOID(my_close(file,MYF(MY_WME)));
 
140
    DBUG_RETURN(1);
 
141
  }
 
142
 
 
143
  x_free((uchar*) *point);              /* Free old language */
 
144
  if (!(*point= (const char**)
 
145
        my_malloc((size_t) (length+count*sizeof(char*)),MYF(0))))
 
146
  {
 
147
    funktpos=2;                                 /* purecov: inspected */
 
148
    goto err;                                   /* purecov: inspected */
 
149
  }
 
150
  buff= (uchar*) (*point + count);
 
151
 
 
152
  if (my_read(file, buff, (size_t) count*2,MYF(MY_NABP)))
 
153
    goto err;
 
154
  for (i=0, pos= buff ; i< count ; i++)
 
155
  {
 
156
    (*point)[i]= (char*) buff+uint2korr(pos);
 
157
    pos+=2;
 
158
  }
 
159
  if (my_read(file, buff, length, MYF(MY_NABP)))
 
160
    goto err;
 
161
 
 
162
  for (i=1 ; i < textcount ; i++)
 
163
  {
 
164
    point[i]= *point +uint2korr(head+10+i+i);
 
165
  }
 
166
  VOID(my_close(file,MYF(0)));
 
167
  DBUG_RETURN(0);
 
168
 
 
169
err:
 
170
  switch (funktpos) {
 
171
  case 2:
 
172
    errmsg= "Not enough memory for messagefile '%s'";
 
173
    break;
 
174
  case 1:
 
175
    errmsg= "Can't read from messagefile '%s'";
 
176
    break;
 
177
  default:
 
178
    errmsg= "Can't find messagefile '%s'";
 
179
    break;
 
180
  }
 
181
  sql_print_error(errmsg, name);
 
182
err1:
 
183
  if (file != FERR)
 
184
    VOID(my_close(file,MYF(MY_WME)));
 
185
  DBUG_RETURN(1);
 
186
} /* read_texts */
 
187
 
 
188
 
 
189
/**
62
190
  Initiates error-messages used by my_func-library.
63
191
*/
64
192
 
65
193
static void init_myfunc_errs()
66
194
{
67
195
  init_glob_errs();                     /* Initiate english errors */
68
 
 
 
196
  if (!(specialflag & SPECIAL_ENGLISH))
69
197
  {
70
198
    EE(EE_FILENOTFOUND)   = ER(ER_FILE_NOT_FOUND);
71
199
    EE(EE_CANTCREATEFILE) = ER(ER_CANT_CREATE_FILE);