MySQL 8.3.0
Source Code Documentation
services.h
Go to the documentation of this file.
1#ifndef SERVICES_INCLUDED
2#define SERVICES_INCLUDED
3/* Copyright (c) 2015, 2023, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
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, version 2.0, 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 @file plugin/rewriter/services.h
27
28 Conversion layer between the parser service and this plugin. This plugin is
29 written in C++, while the parser service is written in C.
30
31 The layer handles:
32
33 - Copying between server and plugin memory. This is necessary on some
34 platforms (e.g. Windows) where dynamically linked libraries have their own
35 heap.
36
37 - Wrapping raw const char * in std::string classes.
38*/
39
41#include <string>
42#include <vector>
43
44#include "my_inttypes.h"
45
46namespace services {
47
48class Session {
49 public:
50 Session(MYSQL_THD current_session);
51
53
54 private:
57};
58
59class Digest {
61
62 public:
63 /**
64 Copies the digest buffer from the server.
65
66 @retval false Server reported success.
67 @retval true Server reported failure.
68 */
69 bool load(MYSQL_THD thd);
70
71 /// Needed because we use a C hash table to store digests.
72 const uchar *c_ptr() const { return m_buf; }
73};
74
76 public:
77 virtual ~Literal_visitor() = default;
78 virtual bool visit(MYSQL_ITEM item) = 0;
79};
80
81/**
82 This class may inherited and passed to parse() in order to handle conditions
83 raised by the server.
84*/
86 public:
87 /**
88 This function will be called by the server via this API before raising a
89 condition. The Condition_handler subclass may then decide to handle the
90 condition by returning true, in which case the server does not raise it.
91
92 @param sql_errno The condition number.
93 @param sqlstate The SQLSTATE, allocated in the server.
94 @param message The condition's message, allocated in the server.
95
96 @retval true The condition is handled entirely by this object.
97 @retval false The condition is not handled.
98 */
99 virtual bool handle(int sql_errno, const char *sqlstate,
100 const char *message) = 0;
101
102 virtual ~Condition_handler() = 0;
103};
104
105std::string print_digest(const uchar *digest);
106
107void set_current_database(MYSQL_THD thd, const std::string &db);
108
109bool parse(MYSQL_THD thd, const std::string &query, bool is_prepared,
111
112bool parse(MYSQL_THD thd, const std::string &query, bool is_prepared);
113
115
117
118bool visit_parse_tree(MYSQL_THD thd, Literal_visitor *visitor);
119
120/// Prints an Item as an std::string.
121std::string print_item(MYSQL_ITEM item);
122
124
125std::vector<int> get_parameter_positions(MYSQL_THD thd);
126} // namespace services
127
128#endif // SERVICES_INCLUDED
#define MYSQL_THD
Definition: backup_page_tracker.h:37
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:933
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4548
This class may inherited and passed to parse() in order to handle conditions raised by the server.
Definition: services.h:85
virtual bool handle(int sql_errno, const char *sqlstate, const char *message)=0
This function will be called by the server via this API before raising a condition.
Definition: services.h:59
bool load(MYSQL_THD thd)
Copies the digest buffer from the server.
Definition: services.cc:48
const uchar * c_ptr() const
Needed because we use a C hash table to store digests.
Definition: services.h:72
uchar m_buf[PARSER_SERVICE_DIGEST_LENGTH]
Definition: services.h:60
Definition: services.h:75
virtual ~Literal_visitor()=default
virtual bool visit(MYSQL_ITEM item)=0
Definition: services.h:48
Session(MYSQL_THD current_session)
Definition: services.cc:52
MYSQL_THD thd()
Definition: services.h:52
MYSQL_THD m_current_session
Definition: services.h:56
MYSQL_THD m_previous_session
Definition: services.h:55
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:51
static char * query
Definition: myisam_ftdump.cc:46
Definition: services.cc:39
int get_number_params(MYSQL_THD thd)
Definition: services.cc:98
string print_item(MYSQL_ITEM item)
Prints an Item as an std::string.
Definition: services.cc:131
bool visit_parse_tree(MYSQL_THD thd, Literal_visitor *visitor)
Definition: services.cc:108
std::vector< int > get_parameter_positions(MYSQL_THD thd)
Definition: services.cc:161
string print_digest(const unsigned char *digest)
Definition: services.cc:41
string get_current_query_normalized(MYSQL_THD thd)
Definition: services.cc:138
bool parse(MYSQL_THD thd, const string &query, bool is_prepared, Condition_handler *handler)
Definition: services.cc:80
void set_current_database(MYSQL_THD thd, const string &db)
Definition: services.cc:75
bool is_supported_statement(MYSQL_THD thd)
Definition: services.cc:91
Plugin service that provides access to the parser and some operations on the parse tree.
#define PARSER_SERVICE_DIGEST_LENGTH
Definition: service_parser.h:44