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