MySQL  8.0.19
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
Item
Definition: item.h:665
services::Session
Definition: services.h:48
services
Definition: services.cc:39
services::get_number_params
int get_number_params(MYSQL_THD thd)
Definition: services.cc:99
services::Session::m_current_session
MYSQL_THD m_current_session
Definition: services.h:56
services::Condition_handler::~Condition_handler
virtual ~Condition_handler()=0
Definition: services.cc:57
services::print_digest
string print_digest(const unsigned char *digest)
Definition: services.cc:41
services::Condition_handler
This class may inherited and passed to parse() in order to handle conditions raised by the server.
Definition: services.h:85
services::Digest::m_buf
uchar m_buf[PARSER_SERVICE_DIGEST_LENGTH]
Definition: services.h:60
services::Digest::c_ptr
const uchar * c_ptr() const
Needed because we use a C hash table to store digests.
Definition: services.h:72
handler
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:3991
my_inttypes.h
services::get_parameter_positions
std::vector< int > get_parameter_positions(MYSQL_THD thd)
Definition: services.cc:162
services::parse
bool parse(MYSQL_THD thd, const string &query, bool is_prepared, Condition_handler *handler)
Definition: services.cc:81
service_parser.h
uchar
unsigned char uchar
Definition: my_inttypes.h:51
services::Literal_visitor
Definition: services.h:75
services::get_current_query_normalized
string get_current_query_normalized(MYSQL_THD thd)
Definition: services.cc:139
services::Session::m_previous_session
MYSQL_THD m_previous_session
Definition: services.h:55
query
static char * query
Definition: myisam_ftdump.cc:44
services::Digest
Definition: services.h:59
MYSQL_THD
#define MYSQL_THD
Definition: backup_page_tracker.h:15
services::Condition_handler::handle
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.
services::Digest::load
bool load(MYSQL_THD thd)
Copies the digest buffer from the server.
Definition: services.cc:49
services::Session::thd
MYSQL_THD thd()
Definition: services.h:52
services::is_supported_statement
bool is_supported_statement(MYSQL_THD thd)
Definition: services.cc:92
services::visit_parse_tree
bool visit_parse_tree(MYSQL_THD thd, Literal_visitor *visitor)
Definition: services.cc:109
services::set_current_database
void set_current_database(MYSQL_THD thd, const string &db)
Definition: services.cc:76
services::Literal_visitor::~Literal_visitor
virtual ~Literal_visitor()
Definition: services.h:77
PARSER_SERVICE_DIGEST_LENGTH
#define PARSER_SERVICE_DIGEST_LENGTH
Definition: service_parser.h:44
services::print_item
string print_item(MYSQL_ITEM item)
Prints an Item as an std::string.
Definition: services.cc:132
services::Session::Session
Session(MYSQL_THD current_session)
Definition: services.cc:53
services::Literal_visitor::visit
virtual bool visit(MYSQL_ITEM item)=0