MySQL 8.0.30
Source Code Documentation
derror.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
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
31#ifdef EXTRA_CODE_FOR_UNIT_TESTING
32#include "mysqld_error.h"
33#endif
34
35/**
36 A record describing an error message.
37*/
38struct {
39 const char *name; ///< MySQL error symbol ("ER_STARTUP")
40 uint mysql_errno; ///< MySQL error code (consecutive within sections)
41 const char *text; ///< MySQL error message
42 const char *odbc_state; ///< SQL state
43 const char *jdbc_state; ///< JBDC state
44 uint error_index; ///< consecutive. 0 for obsolete.
45} typedef server_error;
46
47class THD;
48struct CHARSET_INFO;
49
50/**
51 Character set of the buildin error messages loaded from errmsg.sys.
52*/
54
56 const char *language;
57 const char **errmsgs;
58
59 public:
60 MY_LOCALE_ERRMSGS(const char *lang_par)
61 : language(lang_par), errmsgs(nullptr) {}
62
63 /** Return error message string for a given error number. */
64 const char *lookup(int mysql_errno);
65
66#ifdef EXTRA_CODE_FOR_UNIT_TESTING
67 bool replace_msg(int mysql_errno, const char *new_msg) {
68 int offset = 0; // Position where the current section starts in the array.
69 int num_sections =
70 sizeof(errmsg_section_start) / sizeof(errmsg_section_start[0]);
71 for (int i = 0; i < num_sections; i++) {
72 if (mysql_errno < (errmsg_section_start[i] + errmsg_section_size[i])) {
73 errmsgs[mysql_errno - errmsg_section_start[i] + offset] = new_msg;
74 return false;
75 }
76 offset += errmsg_section_size[i];
77 }
78 return true;
79 }
80#endif
81
82 /** Has the error message file been successfully loaded? */
83 bool is_loaded() const { return errmsgs != nullptr; }
84
85 /** Deallocate error message strings. */
86 void destroy();
87
88 /** Read the error message file and initialize strings. */
89 bool read_texts();
90
91 /** What language is this error message set for? */
92 const char *get_language() const { return language; }
93};
94
95#ifdef CHECK_ERRMSG_FORMAT
96// The number and type of arguments to error messages is
97// now checked at compile time.
98#include "mysqld_errmsg.h"
99#define ER_DEFAULT(X) X##_MSG
100#define ER_THD(T, X) X##_MSG
101#else
102const char *ER_DEFAULT(int mysql_errno);
103const char *ER_THD(const THD *thd, int mysql_errno);
104#endif // CHECK_ERRMSG_FORMAT
105
106// Use these in place of ER_DEFAULT/ER_THD when the error number is not known at
107// compile time. Avoid using these if at all possible.
108const char *ER_DEFAULT_NONCONST(int mysql_errno);
109const char *ER_THD_NONCONST(const THD *thd, int mysql_errno);
110
113
114const char *mysql_errno_to_symbol(int mysql_errno);
115int mysql_symbol_to_errno(const char *error_symbol);
117
119
120/**
121 Read the error message file, initialize and register error messages
122 for all languages.
123
124 @retval true if initialization failed, false otherwise.
125*/
126bool init_errmessage();
127
128/**
129 Unregister error messages for all languages.
130*/
131void deinit_errmessage();
132
133#endif /* DERROR_INCLUDED */
Definition: derror.h:55
const char * lookup(int mysql_errno)
Return error message string for a given error number.
Definition: derror.cc:86
const char * get_language() const
What language is this error message set for?
Definition: derror.h:92
const char ** errmsgs
Definition: derror.h:57
bool is_loaded() const
Has the error message file been successfully loaded?
Definition: derror.h:83
MY_LOCALE_ERRMSGS(const char *lang_par)
Definition: derror.h:60
const char * language
Definition: derror.h:56
void destroy()
Deallocate error message strings.
Definition: derror.cc:348
bool read_texts()
Read the error message file and initialize strings.
Definition: derror.cc:218
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
int errmsgs_reload(THD *thd)
CHARSET_INFO * error_message_charset_info
Character set of the buildin error messages loaded from errmsg.sys.
Definition: derror.cc:50
int mysql_symbol_to_errno(const char *error_symbol)
Definition: sql_state.cc:54
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:155
int mysql_errno_to_builtin(uint mysql_errno)
Find the error message record for a given MySQL error code in the array of registered messages.
Definition: derror.cc:65
const char * ER_THD(const THD *thd, int mysql_errno)
Definition: derror.cc:102
const char * ER_DEFAULT(int mysql_errno)
Definition: derror.cc:98
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:174
const char * ER_DEFAULT_NONCONST(int mysql_errno)
Definition: derror.cc:106
const char * mysql_errno_to_symbol(int mysql_errno)
Definition: sql_state.cc:50
const char * ER_THD_NONCONST(const THD *thd, int mysql_errno)
Definition: derror.cc:110
bool init_errmessage()
Read the error message file, initialize and register error messages for all languages.
Definition: derror.cc:180
void deinit_errmessage()
Unregister error messages for all languages.
Definition: derror.cc:202
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
Some integer typedefs for easier portability.
unsigned int STDCALL mysql_errno(MYSQL *mysql)
Definition: client.cc:8990
Definition: m_ctype.h:354
A record describing an error message.
Definition: derror.h:38
uint mysql_errno
MySQL error code (consecutive within sections)
Definition: derror.h:40
uint error_index
consecutive. 0 for obsolete.
Definition: derror.h:44
const char * name
MySQL error symbol ("ER_STARTUP")
Definition: derror.h:39
const char * jdbc_state
JBDC state.
Definition: derror.h:43
const char * odbc_state
SQL state.
Definition: derror.h:42
const char * text
MySQL error message.
Definition: derror.h:41
unsigned int uint
Definition: uca-dump.cc:29