MySQL 8.4.3
Source Code Documentation
derror.h
Go to the documentation of this file.
1/* Copyright (c) 2006, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef DERROR_INCLUDED
25#define DERROR_INCLUDED
26
27#include <stddef.h>
28#include <sys/types.h>
29
30#include "my_inttypes.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*/
39struct {
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
48class THD;
49struct 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 successfully loaded? */
84 bool is_loaded() const { return errmsgs != nullptr; }
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#ifdef CHECK_ERRMSG_FORMAT
97// The number and type of arguments to error messages is
98// now checked at compile time.
99#include "mysqld_errmsg.h"
100#define ER_DEFAULT(X) X##_MSG
101#define ER_THD(T, X) X##_MSG
102#else
103const char *ER_DEFAULT(int mysql_errno);
104const char *ER_THD(const THD *thd, int mysql_errno);
105#endif // CHECK_ERRMSG_FORMAT
106
107// Use these in place of ER_DEFAULT/ER_THD when the error number is not known at
108// compile time. Avoid using these if at all possible.
109const char *ER_DEFAULT_NONCONST(int mysql_errno);
110const char *ER_THD_NONCONST(const THD *thd, int mysql_errno);
111
114
115const char *mysql_errno_to_symbol(int mysql_errno);
116int mysql_symbol_to_errno(const char *error_symbol);
118
120
121/**
122 Read the error message file, initialize and register error messages
123 for all languages.
124
125 @retval true if initialization failed, false otherwise.
126*/
127bool init_errmessage();
128
129/**
130 Unregister error messages for all languages.
131*/
132void deinit_errmessage();
133
134#endif /* DERROR_INCLUDED */
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Definition: derror.h:56
const char * lookup(int mysql_errno)
Return error message string for a given error number.
Definition: derror.cc:88
const char * get_language() const
What language is this error message set for?
Definition: derror.h:93
const char ** errmsgs
Definition: derror.h:58
bool is_loaded() const
Has the error message file been successfully loaded?
Definition: derror.h:84
MY_LOCALE_ERRMSGS(const char *lang_par)
Definition: derror.h:61
const char * language
Definition: derror.h:57
void destroy()
Deallocate error message strings.
Definition: derror.cc:337
bool read_texts()
Read the error message file and initialize strings.
Definition: derror.cc:220
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
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:52
int mysql_symbol_to_errno(const char *error_symbol)
Definition: sql_state.cc:55
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:157
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:67
const char * ER_THD(const THD *thd, int mysql_errno)
Definition: derror.cc:104
const char * ER_DEFAULT(int mysql_errno)
Definition: derror.cc:100
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:176
const char * ER_DEFAULT_NONCONST(int mysql_errno)
Definition: derror.cc:108
const char * mysql_errno_to_symbol(int mysql_errno)
Definition: sql_state.cc:51
const char * ER_THD_NONCONST(const THD *thd, int mysql_errno)
Definition: derror.cc:112
bool init_errmessage()
Read the error message file, initialize and register error messages for all languages.
Definition: derror.cc:182
void deinit_errmessage()
Unregister error messages for all languages.
Definition: derror.cc:204
Some integer typedefs for easier portability.
unsigned int STDCALL mysql_errno(MYSQL *mysql)
Definition: client.cc:9174
Definition: m_ctype.h:423
A record describing an error message.
Definition: derror.h:39
uint mysql_errno
MySQL error code (consecutive within sections)
Definition: derror.h:41
uint error_index
consecutive. 0 for obsolete.
Definition: derror.h:45
const char * name
MySQL error symbol ("ER_STARTUP")
Definition: derror.h:40
const char * jdbc_state
JBDC state.
Definition: derror.h:44
const char * odbc_state
SQL state.
Definition: derror.h:43
const char * text
MySQL error message.
Definition: derror.h:42