MySQL Connector/C++
MySQL connector library for C and C++ applications
error.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, 2024, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0, as
6 * published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms, as
10 * designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * Without limiting anything contained in the foregoing, this file,
17 * which is part of Connector/C++, is also subject to the
18 * Universal FOSS Exception, version 1.0, a copy of which can be found at
19 * https://oss.oracle.com/licenses/universal-foss-exception.
20 *
21 * This program is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License, version 2.0, for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software Foundation, Inc.,
28 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
31#ifndef MYSQLX_ERROR_H
32#define MYSQLX_ERROR_H
33
40#include "common.h"
41#include "detail/error.h"
42
43#include <memory>
44
45
46namespace mysqlx {
47MYSQLX_ABI_BEGIN(2,0)
48
49
61 : public virtual common::Printable
62 , internal::Warning_detail
63{
64public:
65
67
68 enum Level {
71 LEVEL_INFO
72 };
73
74private:
75
76 Warning(Level level, uint16_t code, const string &msg)
77 : Warning_detail(byte(level), code, msg)
78 {
79 }
80
81 Warning(Warning_detail &&init)
82 : Warning_detail(std::move(init))
83 {}
84
85 void print(std::ostream &out) const
86 {
87 try {
88 Warning_detail::print(out);
89 }
90 CATCH_AND_WRAP
91 }
92
93public:
94
100 {
101 return Level(m_level);
102 }
103
108 uint16_t getCode() const
109 {
110 return m_code;
111 }
112
117 const string& getMessage() const
118 {
119 return m_msg;
120 }
121
122
124 friend internal::Result_detail;
126
127 struct Access;
128 friend Access;
129};
130
131
132inline
133void internal::Warning_detail::print(std::ostream &out) const
134{
135 switch (Warning::Level(m_level))
136 {
137 case Warning::LEVEL_ERROR: out << "Error"; break;
138 case Warning::LEVEL_WARNING: out << "Warning"; break;
139 case Warning::LEVEL_INFO: out << "Info"; break;
140 default: out << "<Unknown>"; break;
141 }
142
143 if (m_code)
144 out << " " << m_code;
145
146 out << ": " << m_msg;
147}
148
149
150MYSQLX_ABI_END(2,0)
151} // mysqlx
152
153#endif
An error, warning or other diagnostic information reported by server when executing queries or statem...
Definition: error.h:63
Level
Type of diagnostic information.
Definition: error.h:68
@ LEVEL_WARNING
Warning
Definition: error.h:70
@ LEVEL_ERROR
Error
Definition: error.h:69
const string & getMessage() const
Return diagnostic message reported by server.
Definition: error.h:117
Level getLevel() const
Return level of the diagnostic info stored in this object.
Definition: error.h:99
uint16_t getCode() const
Return error/warning code reported by server.
Definition: error.h:108
Classes used to access query and command execution results.