MySQL 8.0.39
Source Code Documentation
services.h
Go to the documentation of this file.
1#ifndef SERVICES_INCLUDED
2#define SERVICES_INCLUDED
3/* Copyright (c) 2015, 2024, 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 designed to work 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 either included with
15 the program or referenced in the documentation.
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
26/**
27 @file plugin/rewriter/services.h
28
29 Conversion layer between the parser service and this plugin. This plugin is
30 written in C++, while the parser service is written in C.
31
32 The layer handles:
33
34 - Copying between server and plugin memory. This is necessary on some
35 platforms (e.g. Windows) where dynamically linked libraries have their own
36 heap.
37
38 - Wrapping raw const char * in std::string classes.
39*/
40
42#include <string>
43#include <vector>
44
45#include "my_inttypes.h"
46
47namespace services {
48
49class Session {
50 public:
51 Session(MYSQL_THD current_session);
52
54
55 private:
58};
59
60class Digest {
62
63 public:
64 /**
65 Copies the digest buffer from the server.
66
67 @retval false Server reported success.
68 @retval true Server reported failure.
69 */
70 bool load(MYSQL_THD thd);
71
72 /// Needed because we use a C hash table to store digests.
73 const uchar *c_ptr() const { return m_buf; }
74};
75
77 public:
78 virtual ~Literal_visitor() = default;
79 virtual bool visit(MYSQL_ITEM item) = 0;
80};
81
82/**
83 This class may inherited and passed to parse() in order to handle conditions
84 raised by the server.
85*/
87 public:
88 /**
89 This function will be called by the server via this API before raising a
90 condition. The Condition_handler subclass may then decide to handle the
91 condition by returning true, in which case the server does not raise it.
92
93 @param sql_errno The condition number.
94 @param sqlstate The SQLSTATE, allocated in the server.
95 @param message The condition's message, allocated in the server.
96
97 @retval true The condition is handled entirely by this object.
98 @retval false The condition is not handled.
99 */
100 virtual bool handle(int sql_errno, const char *sqlstate,
101 const char *message) = 0;
102
103 virtual ~Condition_handler() = 0;
104};
105
106std::string print_digest(const uchar *digest);
107
108void set_current_database(MYSQL_THD thd, const std::string &db);
109
110bool parse(MYSQL_THD thd, const std::string &query, bool is_prepared,
112
113bool parse(MYSQL_THD thd, const std::string &query, bool is_prepared);
114
116
118
119bool visit_parse_tree(MYSQL_THD thd, Literal_visitor *visitor);
120
121/// Prints an Item as an std::string.
122std::string print_item(MYSQL_ITEM item);
123
125
126std::vector<int> get_parameter_positions(MYSQL_THD thd);
127} // namespace services
128
129#endif // SERVICES_INCLUDED
#define MYSQL_THD
Definition: backup_page_tracker.h:38
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:853
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4414
This class may inherited and passed to parse() in order to handle conditions raised by the server.
Definition: services.h:86
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:60
bool load(MYSQL_THD thd)
Copies the digest buffer from the server.
Definition: services.cc:49
const uchar * c_ptr() const
Needed because we use a C hash table to store digests.
Definition: services.h:73
uchar m_buf[PARSER_SERVICE_DIGEST_LENGTH]
Definition: services.h:61
Definition: services.h:76
virtual ~Literal_visitor()=default
virtual bool visit(MYSQL_ITEM item)=0
Definition: services.h:49
Session(MYSQL_THD current_session)
Definition: services.cc:53
MYSQL_THD thd()
Definition: services.h:53
MYSQL_THD m_current_session
Definition: services.h:57
MYSQL_THD m_previous_session
Definition: services.h:56
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
static char * query
Definition: myisam_ftdump.cc:45
Definition: services.cc:40
int get_number_params(MYSQL_THD thd)
Definition: services.cc:99
string print_item(MYSQL_ITEM item)
Prints an Item as an std::string.
Definition: services.cc:132
bool visit_parse_tree(MYSQL_THD thd, Literal_visitor *visitor)
Definition: services.cc:109
std::vector< int > get_parameter_positions(MYSQL_THD thd)
Definition: services.cc:162
string print_digest(const unsigned char *digest)
Definition: services.cc:42
string get_current_query_normalized(MYSQL_THD thd)
Definition: services.cc:139
bool parse(MYSQL_THD thd, const string &query, bool is_prepared, Condition_handler *handler)
Definition: services.cc:81
void set_current_database(MYSQL_THD thd, const string &db)
Definition: services.cc:76
bool is_supported_statement(MYSQL_THD thd)
Definition: services.cc:92
Plugin service that provides access to the parser and some operations on the parse tree.
#define PARSER_SERVICE_DIGEST_LENGTH
Definition: service_parser.h:45