MySQL 8.0.33
Source Code Documentation
duktape_statement_reader.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2023, 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,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as 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 included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef MYSQLD_MOCK_DUKTAPE_STATEMENT_READER_INCLUDED
26#define MYSQLD_MOCK_DUKTAPE_STATEMENT_READER_INCLUDED
27
28#include <map>
29#include <string>
30
31#include "mock_session.h"
35#include "statement_reader.h"
36
37namespace server_mock {
38
40 public:
42 std::string filename, std::vector<std::string> module_prefixes,
43 std::map<std::string, std::function<std::string()>> session,
44 std::shared_ptr<MockServerGlobalScope> global_scope)
45 : filename_{std::move(filename)},
46 module_prefixes_{std::move(module_prefixes)},
47 session_{std::move(session)},
48 global_scope_{std::move(global_scope)} {}
49
51 public:
52 FailedStatementReader(std::string what) : what_{std::move(what)} {}
53
54 void handle_statement(const std::string & /* statement */,
55 ProtocolBase * /* protocol */) override {
56 throw std::logic_error("this should not be called.");
57 }
58
59 std::chrono::microseconds get_default_exec_time() override { return {}; }
60
61 std::vector<AsyncNotice> get_async_notices() override { return {}; }
62
64 server_greeting(bool /* with_tls */) override {
66 make_error_code(std::errc::no_such_file_or_directory));
67 }
68
70 return stdx::make_unexpected(ErrorResponse(1064, what_, "HY000"));
71 }
72
73 std::chrono::microseconds server_greeting_exec_time() override {
74 return {};
75 }
76
77 void set_session_ssl_info(const SSL * /* ssl */) override {}
78
79 private:
80 std::string what_;
81 };
82
83 std::unique_ptr<StatementReaderBase> operator()();
84
85 private:
86 std::string filename_;
87 std::vector<std::string> module_prefixes_;
88 std::map<std::string, std::function<std::string()>> session_;
89 std::shared_ptr<MockServerGlobalScope> global_scope_;
90};
91
93 public:
95
97 std::string filename, std::vector<std::string> module_prefixes,
98 std::map<std::string, std::function<std::string()>> session_data,
99 std::shared_ptr<MockServerGlobalScope> shared_globals);
100
103
106
107 /**
108 * handle the clients statement
109 *
110 * @param statement statement-text of the current clients
111 * COM_QUERY/StmtExecute
112 * @param protocol protocol to send response to
113 */
114 void handle_statement(const std::string &statement,
115 ProtocolBase *protocol) override;
116
117 std::chrono::microseconds get_default_exec_time() override;
118
119 ~DuktapeStatementReader() override;
120
121 std::vector<AsyncNotice> get_async_notices() override;
122
124 server_greeting(bool with_tls) override;
125
127
128 std::chrono::microseconds server_greeting_exec_time() override;
129
130 void set_session_ssl_info(const SSL *ssl) override;
131
132 private:
133 struct Pimpl;
134 std::unique_ptr<Pimpl> pimpl_;
135 bool has_notices_{false};
136
138};
139} // namespace server_mock
140
141#endif
std::chrono::microseconds server_greeting_exec_time() override
Definition: duktape_statement_reader.h:73
std::vector< AsyncNotice > get_async_notices() override
Definition: duktape_statement_reader.h:61
std::string what_
Definition: duktape_statement_reader.h:80
std::chrono::microseconds get_default_exec_time() override
Returns the default execution time in microseconds.
Definition: duktape_statement_reader.h:59
void set_session_ssl_info(const SSL *) override
Definition: duktape_statement_reader.h:77
stdx::expected< classic_protocol::message::server::Greeting, std::error_code > server_greeting(bool) override
Definition: duktape_statement_reader.h:64
stdx::expected< handshake_data, ErrorResponse > handshake() override
Definition: duktape_statement_reader.h:69
FailedStatementReader(std::string what)
Definition: duktape_statement_reader.h:52
void handle_statement(const std::string &, ProtocolBase *) override
Returns the data about the next statement from the json file.
Definition: duktape_statement_reader.h:54
Definition: duktape_statement_reader.h:39
std::shared_ptr< MockServerGlobalScope > global_scope_
Definition: duktape_statement_reader.h:89
std::map< std::string, std::function< std::string()> > session_
Definition: duktape_statement_reader.h:88
std::string filename_
Definition: duktape_statement_reader.h:86
std::vector< std::string > module_prefixes_
Definition: duktape_statement_reader.h:87
DuktapeStatementReaderFactory(std::string filename, std::vector< std::string > module_prefixes, std::map< std::string, std::function< std::string()> > session, std::shared_ptr< MockServerGlobalScope > global_scope)
Definition: duktape_statement_reader.h:41
std::unique_ptr< StatementReaderBase > operator()()
Definition: duktape_statement_reader.cc:55
Definition: duktape_statement_reader.h:92
DuktapeStatementReader & operator=(const DuktapeStatementReader &)=delete
void handle_statement(const std::string &statement, ProtocolBase *protocol) override
handle the clients statement
Definition: duktape_statement_reader.cc:1014
DuktapeStatementReader(DuktapeStatementReader &&)
std::unique_ptr< Pimpl > pimpl_
Definition: duktape_statement_reader.h:133
stdx::expected< handshake_data, ErrorResponse > handshake() override
Definition: duktape_statement_reader.cc:936
stdx::expected< classic_protocol::message::server::Greeting, std::error_code > server_greeting(bool with_tls) override
Definition: duktape_statement_reader.cc:806
std::chrono::microseconds get_default_exec_time() override
Returns the default execution time in microseconds.
Definition: duktape_statement_reader.cc:1134
DuktapeStatementReader(std::string filename, std::vector< std::string > module_prefixes, std::map< std::string, std::function< std::string()> > session_data, std::shared_ptr< MockServerGlobalScope > shared_globals)
Definition: duktape_statement_reader.cc:782
void set_session_ssl_info(const SSL *ssl) override
Definition: duktape_statement_reader.cc:1237
HandshakeState
Definition: duktape_statement_reader.h:94
DuktapeStatementReader & operator=(DuktapeStatementReader &&)
std::vector< AsyncNotice > get_async_notices() override
Definition: duktape_statement_reader.cc:1138
DuktapeStatementReader(const DuktapeStatementReader &)=delete
std::chrono::microseconds server_greeting_exec_time() override
Definition: duktape_statement_reader.cc:893
~DuktapeStatementReader() override
Definition: duktape_statement_reader.cc:801
bool has_notices_
Definition: duktape_statement_reader.h:135
HandshakeState handshake_state_
Definition: duktape_statement_reader.h:137
Definition: statement_reader.h:79
Definition: statement_reader.h:347
Definition: expected.h:943
constexpr value_type ssl
Definition: classic_protocol_constants.h:48
std::error_code make_error_code(DynamicLoaderErrc ec)
make error_code from a DynamicLoaderErrc.
Definition: dynamic_loader.cc:78
Definition: mock_server_component.h:35
classic_protocol::message::server::Error ErrorResponse
Definition: statement_reader.h:68
Definition: varlen_sort.h:183
constexpr auto make_unexpected(E &&e) -> unexpected< std::decay_t< E > >
Definition: expected.h:124
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2890
const char * filename
Definition: pfs_example_component_population.cc:66
Definition: duktape_statement_reader.cc:444
Definition: mysqlslap.cc:216