MySQL 9.1.0
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 bool /* is_greeting */) override {
66 return stdx::unexpected(ErrorResponse(1064, what_, "HY000"));
67 }
68
69 void set_session_ssl_info(const SSL * /* ssl */) override {}
70
71 private:
72 std::string what_;
73 };
74
75 std::unique_ptr<StatementReaderBase> operator()();
76
77 private:
78 std::string filename_;
79 std::vector<std::string> module_prefixes_;
80 std::map<std::string, std::function<std::string()>> session_;
81 std::shared_ptr<MockServerGlobalScope> global_scope_;
82};
83
85 public:
87
89 std::string filename, std::vector<std::string> module_prefixes,
90 std::map<std::string, std::function<std::string()>> session_data,
91 std::shared_ptr<MockServerGlobalScope> shared_globals);
92
95
98
99 /**
100 * handle the clients statement
101 *
102 * @param statement statement-text of the current clients
103 * COM_QUERY/StmtExecute
104 * @param protocol protocol to send response to
105 */
106 void handle_statement(const std::string &statement,
107 ProtocolBase *protocol) override;
108
109 std::chrono::microseconds get_default_exec_time() override;
110
111 ~DuktapeStatementReader() override;
112
113 std::vector<AsyncNotice> get_async_notices() override;
114
116 bool with_tls) override;
117
118 private:
121
122 std::chrono::microseconds server_greeting_exec_time();
123
124 void set_session_ssl_info(const SSL *ssl) override;
125
126 struct Pimpl;
127 std::unique_ptr<Pimpl> pimpl_;
128 bool has_notices_{false};
129
131};
132} // namespace server_mock
133
134#endif
std::vector< AsyncNotice > get_async_notices() override
Definition: duktape_statement_reader.h:62
stdx::expected< handshake_data, ErrorResponse > handshake(bool) override
Definition: duktape_statement_reader.h:64
std::string what_
Definition: duktape_statement_reader.h:72
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:69
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:81
std::map< std::string, std::function< std::string()> > session_
Definition: duktape_statement_reader.h:80
std::string filename_
Definition: duktape_statement_reader.h:78
std::vector< std::string > module_prefixes_
Definition: duktape_statement_reader.h:79
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:128
Definition: duktape_statement_reader.h:84
DuktapeStatementReader & operator=(const DuktapeStatementReader &)=delete
stdx::expected< handshake_data, ErrorResponse > handshake(bool with_tls) override
Definition: duktape_statement_reader.cc:1077
void handle_statement(const std::string &statement, ProtocolBase *protocol) override
handle the clients statement
Definition: duktape_statement_reader.cc:1202
DuktapeStatementReader(DuktapeStatementReader &&)
std::unique_ptr< Pimpl > pimpl_
Definition: duktape_statement_reader.h:126
std::chrono::microseconds server_greeting_exec_time()
Definition: duktape_statement_reader.cc:1050
std::chrono::microseconds get_default_exec_time() override
Returns the default execution time in microseconds.
Definition: duktape_statement_reader.cc:1322
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:953
void set_session_ssl_info(const SSL *ssl) override
Definition: duktape_statement_reader.cc:1425
stdx::expected< classic_protocol::message::server::Greeting, std::error_code > server_greeting()
Definition: duktape_statement_reader.cc:1025
HandshakeState
Definition: duktape_statement_reader.h:86
DuktapeStatementReader & operator=(DuktapeStatementReader &&)
std::vector< AsyncNotice > get_async_notices() override
Definition: duktape_statement_reader.cc:1326
DuktapeStatementReader(const DuktapeStatementReader &)=delete
~DuktapeStatementReader() override
Definition: duktape_statement_reader.cc:972
bool has_notices_
Definition: duktape_statement_reader.h:128
HandshakeState handshake_state_
Definition: duktape_statement_reader.h:130
Definition: statement_reader.h:96
Definition: statement_reader.h:394
Definition: expected.h:286
constexpr value_type ssl
Definition: classic_protocol_constants.h:49
Definition: mock_server_component.h:36
classic_protocol::message::server::Error ErrorResponse
Definition: statement_reader.h:85
Definition: gcs_xcom_synode.h:64
unexpected(E) -> unexpected< E >
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2894
const char * filename
Definition: pfs_example_component_population.cc:67
Definition: duktape_statement_reader.cc:519
Definition: mysqlslap.cc:219