MySQL 8.0.39
Source Code Documentation
expected_errors.h
Go to the documentation of this file.
1#ifndef EXPECTED_ERRORS_INCLUDED
2#define EXPECTED_ERRORS_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
28
29#include <memory>
30#include <string>
31#include <vector>
32
33#define MAX_ERROR_COUNT 20
34
35/// Class representing a list of error codes passed as argument to
36/// mysqltest command <code>--error</code>.
38 public:
39 typedef std::vector<std::unique_ptr<Error>>::iterator iterator;
40
41 Expected_errors() = default;
42 ~Expected_errors() = default;
43
44 iterator begin() { return m_errors.begin(); }
45 iterator end() { return m_errors.end(); }
46
47 /// Return a sqlstate of the first error in the list.
48 ///
49 /// @retval SQLSTATE string
50 const char *sqlstate() { return m_errors[0]->sqlstate(); }
51
52 /// Return an error type of the first error in the list.
53 ///
54 /// @retval Error type (ERR_ERRNO or ERR_SQLSTATE)
55 error_type type() { return m_errors[0]->type(); }
56
57 /// Return length of the list containing errors.
58 ///
59 /// @retval Length value
60 std::size_t count() { return m_errors.size(); }
61
62 /// Return list of error codes
63 ///
64 /// @retval List of error codes
65 std::string error_list();
66
67 /// Return list of error codes in the list
68 ///
69 /// @retval List of error codes
70 std::vector<std::uint32_t> errors();
71
72 /// Return an error code of the first error in the list.
73 ///
74 /// @retval Error code
75 unsigned int error_code() { return m_errors[0]->error_code(); }
76
77 /// Add a new error to the existing list of errors.
78 ///
79 /// @param sqlstate SQLSTATE string
80 /// @param type Error type
81 void add_error(const char *sqlstate, error_type type);
82
83 /// Add a new error to the existing list of errors.
84 ///
85 /// @param error_code Error number
86 /// @param type Error type
87 void add_error(std::uint32_t error_code, error_type type);
88
89 /// Delete all errors from the vector.
90 void clear_list() { m_errors.clear(); }
91
92 private:
93 // List containing expected errors
94 std::vector<std::unique_ptr<Error>> m_errors;
95};
96
97#endif // EXPECTED_ERRORS_INCLUDED
Class representing a list of error codes passed as argument to mysqltest command –error.
Definition: expected_errors.h:37
Expected_errors()=default
iterator end()
Definition: expected_errors.h:45
void clear_list()
Delete all errors from the vector.
Definition: expected_errors.h:90
iterator begin()
Definition: expected_errors.h:44
const char * sqlstate()
Return a sqlstate of the first error in the list.
Definition: expected_errors.h:50
unsigned int error_code()
Return an error code of the first error in the list.
Definition: expected_errors.h:75
std::vector< std::unique_ptr< Error > > m_errors
Definition: expected_errors.h:94
void add_error(const char *sqlstate, error_type type)
Add a new error to the existing list of errors.
Definition: expected_errors.cc:48
~Expected_errors()=default
std::vector< std::unique_ptr< Error > >::iterator iterator
Definition: expected_errors.h:39
error_type type()
Return an error type of the first error in the list.
Definition: expected_errors.h:55
std::string error_list()
Return list of error codes.
Definition: expected_errors.cc:26
std::size_t count()
Return length of the list containing errors.
Definition: expected_errors.h:60
std::vector< std::uint32_t > errors()
Return list of error codes in the list.
Definition: expected_errors.cc:40
This file declares the Error class.
error_type
Definition: error.h:36