MySQL 8.2.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, 2023, 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 also distributed 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 included with MySQL.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License, version 2.0, for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25
26/// @file
27///
28/// This file declares the Error class.
29
30#include <cstdint>
31#include <cstring>
32
33#include "mysql_com.h" // SQLSTATE_LENGTH
34
36
37/// Class representing an error.
38///
39/// Contains following information
40/// * Error code
41/// * Error type
42/// * SQLSTATE
43///
44/// If an error type value is
45/// * ERR_ERRNO, then SQLSTATE value is "00000"
46/// * ERR_SQLSTATE, then error code value is 0
47class Error {
48 public:
49 Error(std::uint32_t error_code, const char *sqlstate, error_type type) {
51 this->m_type = type;
52 std::strcpy(this->m_sqlstate, sqlstate);
53 }
54
55 /// Return a sqlstate for an error.
56 ///
57 /// @retval SQLSTATE string
58 const char *sqlstate() { return m_sqlstate; }
59
60 /// Return an error code
61 ///
62 /// @retval Error code
63 std::uint32_t error_code() { return m_error_code; }
64
65 /// Return an error type
66 ///
67 /// @retval Error type (ERR_ERRNO or ERR_SQLSTATE)
68 error_type type() { return m_type; }
69
70 private:
71 std::uint32_t m_error_code;
73 char m_sqlstate[SQLSTATE_LENGTH + 1]; // '\0' terminated string
74};
75
76#endif // ERROR_INCLUDED
Class representing an error.
Definition: error.h:47
const char * sqlstate()
Return a sqlstate for an error.
Definition: error.h:58
error_type m_type
Definition: error.h:72
char m_sqlstate[SQLSTATE_LENGTH+1]
Definition: error.h:73
Error(std::uint32_t error_code, const char *sqlstate, error_type type)
Definition: error.h:49
error_type type()
Return an error type.
Definition: error.h:68
std::uint32_t m_error_code
Definition: error.h:71
std::uint32_t error_code()
Return an error code.
Definition: error.h:63
error_type
Definition: error.h:35
@ ERR_SQLSTATE
Definition: error.h:35
@ ERR_ERRNO
Definition: error.h:35
Common definition between mysql server & client.
#define SQLSTATE_LENGTH
Definition: mysql_com.h:74