MySQL  8.0.20
Source Code Documentation
services.h
Go to the documentation of this file.
1 #ifndef SERVICES_INCLUDED
2 #define SERVICES_INCLUDED
3 /* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
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 dynamicly linked libraries have their own
35  heap.
36 
37  - Wrapping raw const char * in std::string classes.
38 */
39 
40 #include <mysql/service_parser.h>
41 #include <string>
42 #include <vector>
43 
44 #include "my_inttypes.h"
45 
46 namespace services {
47 
48 class Session {
49  public:
50  Session(MYSQL_THD current_session);
51 
53 
54  private:
57 };
58 
59 class 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() {}
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 
105 std::string print_digest(const uchar *digest);
106 
107 void set_current_database(MYSQL_THD thd, const std::string &db);
108 
109 bool parse(MYSQL_THD thd, const std::string &query, bool is_prepared,
111 
112 bool parse(MYSQL_THD thd, const std::string &query, bool is_prepared);
113 
115 
117 
118 bool visit_parse_tree(MYSQL_THD thd, Literal_visitor *visitor);
119 
120 /// Prints an Item as an std::string.
121 std::string print_item(MYSQL_ITEM item);
122 
123 std::string get_current_query_normalized(MYSQL_THD thd);
124 
125 std::vector<int> get_parameter_positions(MYSQL_THD thd);
126 } // namespace services
127 
128 #endif // SERVICES_INCLUDED
unsigned char uchar
Definition: my_inttypes.h:51
const uchar * c_ptr() const
Needed because we use a C hash table to store digests.
Definition: services.h:72
Session(MYSQL_THD current_session)
Definition: services.cc:53
bool load(THD *, const dd::String_type &fname, dd::String_type *buf)
Read an sdi file from disk and store in a buffer.
Definition: sdi_file.cc:306
static char * query
Definition: myisam_ftdump.cc:44
bool visit_parse_tree(MYSQL_THD thd, Literal_visitor *visitor)
Definition: services.cc:109
Definition: services.h:75
Some integer typedefs for easier portability.
Plugin service that provides access to the parser and some operations on the parse tree...
MYSQL_THD thd()
Definition: services.h:52
std::vector< int > get_parameter_positions(MYSQL_THD thd)
Definition: services.cc:162
static int handle(int sql_errno, const char *sqlstate, const char *message, void *state)
Bridge function between the C++ API offered by this module and the C API of the parser service...
Definition: services.cc:64
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:3986
#define MYSQL_THD
Definition: backup_page_tracker.h:35
MYSQL_THD m_previous_session
Definition: services.h:55
string print_item(MYSQL_ITEM item)
Prints an Item as an std::string.
Definition: services.cc:132
bool parse(MYSQL_THD thd, const string &query, bool is_prepared, Condition_handler *handler)
Definition: services.cc:81
bool is_supported_statement(MYSQL_THD thd)
Definition: services.cc:92
int get_number_params(MYSQL_THD thd)
Definition: services.cc:99
void set_current_database(MYSQL_THD thd, const string &db)
Definition: services.cc:76
virtual ~Literal_visitor()
Definition: services.h:77
Definition: item.h:740
Definition: services.h:48
This class may inherited and passed to parse() in order to handle conditions raised by the server...
Definition: services.h:85
string get_current_query_normalized(MYSQL_THD thd)
Definition: services.cc:139
Definition: services.h:59
#define PARSER_SERVICE_DIGEST_LENGTH
Definition: service_parser.h:44
string print_digest(const unsigned char *digest)
Definition: services.cc:41
Definition: services.cc:39
MYSQL_THD m_current_session
Definition: services.h:56