MySQL  8.0.12
Source Code Documentation
derror.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20  The lines above are intentionally left blank
21 */
22 
23 #ifndef DERROR_INCLUDED
24 #define DERROR_INCLUDED
25 
26 #include <stddef.h>
27 #include <sys/types.h>
28 
29 #include "my_inttypes.h"
30 #include "my_macros.h"
31 
32 #ifdef EXTRA_CODE_FOR_UNIT_TESTING
33 #include "mysqld_error.h"
34 #endif
35 
36 /**
37  A record describing an error message.
38 */
39 struct {
40  const char *name; ///< MySQL error symbol ("ER_STARTUP")
41  uint mysql_errno; ///< MySQL error code (consecutive within sections)
42  const char *text; ///< MySQL error message
43  const char *odbc_state; ///< SQL state
44  const char *jdbc_state; ///< JBDC state
45  uint error_index; ///< consecutive. 0 for obsolete.
46 } typedef server_error;
47 
48 class THD;
49 struct CHARSET_INFO;
50 
51 /**
52  Character set of the buildin error messages loaded from errmsg.sys.
53 */
55 
57  const char *language;
58  const char **errmsgs;
59 
60  public:
61  MY_LOCALE_ERRMSGS(const char *lang_par)
62  : language(lang_par), errmsgs(nullptr) {}
63 
64  /** Return error message string for a given error number. */
65  const char *lookup(int mysql_errno);
66 
67 #ifdef EXTRA_CODE_FOR_UNIT_TESTING
68  bool replace_msg(int mysql_errno, const char *new_msg) {
69  int offset = 0; // Position where the current section starts in the array.
70  int num_sections =
71  sizeof(errmsg_section_start) / sizeof(errmsg_section_start[0]);
72  for (int i = 0; i < num_sections; i++) {
73  if (mysql_errno < (errmsg_section_start[i] + errmsg_section_size[i])) {
74  errmsgs[mysql_errno - errmsg_section_start[i] + offset] = new_msg;
75  return false;
76  }
77  offset += errmsg_section_size[i];
78  }
79  return true;
80  }
81 #endif
82 
83  /** Has the error message file been sucessfully loaded? */
84  bool is_loaded() const { return errmsgs != NULL; }
85 
86  /** Deallocate error message strings. */
87  void destroy();
88 
89  /** Read the error message file and initialize strings. */
90  bool read_texts();
91 
92  /** What language is this error message set for? */
93  const char *get_language() const { return language; }
94 };
95 
96 const char *ER_DEFAULT(int mysql_errno);
97 const char *ER_THD(const THD *thd, int mysql_errno);
98 
101 const char *error_message_for_client(int mysql_errno);
103 
104 const char *mysql_errno_to_symbol(int mysql_errno);
105 int mysql_symbol_to_errno(const char *error_symbol);
106 
107 int errmsgs_reload(THD *thd);
108 
109 /**
110  Read the error message file, initialize and register error messages
111  for all languages.
112 
113  @retval true if initialization failed, false otherwise.
114 */
115 bool init_errmessage();
116 
117 /**
118  Unregister error messages for all languages.
119 */
120 void deinit_errmessage();
121 
122 #endif /* DERROR_INCLUDED */
Some common macros.
uint mysql_errno
MySQL error code (consecutive within sections)
Definition: derror.h:41
const char * jdbc_state
JBDC state.
Definition: derror.h:44
void deinit_errmessage()
Unregister error messages for all languages.
Definition: derror.cc:197
MY_LOCALE_ERRMSGS(const char *lang_par)
Definition: derror.h:61
const char * mysql_errno_to_symbol(int mysql_errno)
Definition: sql_state.cc:51
Some integer typedefs for easier portability.
#define C_MODE_START
Definition: my_macros.h:39
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
A record describing an error message.
Definition: derror.h:39
int mysql_symbol_to_errno(const char *error_symbol)
Definition: sql_state.cc:55
const char ** errmsgs
Definition: derror.h:58
const char * language
Definition: derror.h:57
int errmsgs_reload(THD *thd)
bool init_errmessage()
Read the error message file, initialize and register error messages for all languages.
Definition: derror.cc:175
const char * text
MySQL error message.
Definition: derror.h:42
void destroy()
Release resources and free memory occupied by the table share.
Definition: table.cc:507
const char * error_message_for_error_log(int mysql_errno)
Get the error-message corresponding to the given MySQL error-code, or nullptr if no message is availa...
Definition: derror.cc:149
const char * odbc_state
SQL state.
Definition: derror.h:43
unsigned int STDCALL mysql_errno(MYSQL *mysql)
Definition: client.cc:5998
const char * name
MySQL error symbol ("ER_STARTUP")
Definition: derror.h:40
unsigned int uint
Definition: uca-dump.cc:29
const char * ER_DEFAULT(int mysql_errno)
Definition: derror.cc:98
char * lookup(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *null_value, char *error)
Definition: udf_example.cc:645
Definition: m_ctype.h:372
const char * error_message_for_client(int mysql_errno)
Get the error-message corresponding to the given MySQL error-code, or nullptr if no message is availa...
Definition: derror.cc:168
bool is_loaded() const
Has the error message file been sucessfully loaded?
Definition: derror.h:84
Definition: derror.h:56
CHARSET_INFO * error_message_charset_info
Character set of the buildin error messages loaded from errmsg.sys.
Definition: derror.cc:51
uint error_index
consecutive. 0 for obsolete.
Definition: derror.h:45
#define C_MODE_END
Definition: my_macros.h:40
const char * ER_THD(const THD *thd, int mysql_errno)
Definition: derror.cc:102
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:747
const char * get_language() const
What language is this error message set for?
Definition: derror.h:93