MySQL 8.4.0
Source Code Documentation
error.h
Go to the documentation of this file.
1#ifndef ERROR_INCLUDED
2#define ERROR_INCLUDED
3
4// Copyright (c) 2018, 2024, Oracle and/or its affiliates.
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License, version 2.0,
8// as published by the Free Software Foundation.
9//
10// This program is designed to work with certain software (including
11// but not limited to OpenSSL) that is licensed under separate terms,
12// as designated in a particular file or component or in included license
13// documentation. The authors of MySQL hereby grant you an additional
14// permission to link the program and your derivative works with the
15// separately licensed software that they have either included with
16// the program or referenced in the documentation.
17//
18// This program is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License, version 2.0, for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with this program; if not, write to the Free Software
25// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26
27/// @file
28///
29/// This file declares the Error class.
30
31#include <cstdint>
32#include <cstring>
33
34#include "mysql_com.h" // SQLSTATE_LENGTH
35
37
38/// Class representing an error.
39///
40/// Contains following information
41/// * Error code
42/// * Error type
43/// * SQLSTATE
44///
45/// If an error type value is
46/// * ERR_ERRNO, then SQLSTATE value is "00000"
47/// * ERR_SQLSTATE, then error code value is 0
48class Error {
49 public:
50 Error(std::uint32_t error_code, const char *sqlstate, error_type type) {
52 this->m_type = type;
53 std::strcpy(this->m_sqlstate, sqlstate);
54 }
55
56 /// Return a sqlstate for an error.
57 ///
58 /// @retval SQLSTATE string
59 const char *sqlstate() { return m_sqlstate; }
60
61 /// Return an error code
62 ///
63 /// @retval Error code
64 std::uint32_t error_code() { return m_error_code; }
65
66 /// Return an error type
67 ///
68 /// @retval Error type (ERR_ERRNO or ERR_SQLSTATE)
69 error_type type() { return m_type; }
70
71 private:
72 std::uint32_t m_error_code;
74 char m_sqlstate[SQLSTATE_LENGTH + 1]; // '\0' terminated string
75};
76
77#endif // ERROR_INCLUDED
Class representing an error.
Definition: error.h:48
const char * sqlstate()
Return a sqlstate for an error.
Definition: error.h:59
error_type m_type
Definition: error.h:73
char m_sqlstate[SQLSTATE_LENGTH+1]
Definition: error.h:74
Error(std::uint32_t error_code, const char *sqlstate, error_type type)
Definition: error.h:50
error_type type()
Return an error type.
Definition: error.h:69
std::uint32_t m_error_code
Definition: error.h:72
std::uint32_t error_code()
Return an error code.
Definition: error.h:64
error_type
Definition: error.h:36
@ ERR_SQLSTATE
Definition: error.h:36
@ ERR_ERRNO
Definition: error.h:36
Common definition between mysql server & client.
#define SQLSTATE_LENGTH
Definition: mysql_com.h:75