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