MySQL 8.0.37
Source Code Documentation
sql_service_interface.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_SERVICE_INTERFACE_INCLUDE
25#define SQL_SERVICE_INTERFACE_INCLUDE
26
28
29#define MAX_NUMBER_RETRIES 100
30#define SESSION_WAIT_TIMEOUT 2
31
33 private:
34 /** Pointer to Srv_session class */
36
37 /** Pointer to the group_replication plugin structure */
38 void *m_plugin;
39
40 /** send result in string or native types */
42
43 /* The charset for the input string data */
45
46 /**
47 Executes a server command in a session.
48
49 @param rset resulted obtained after executing query
50 @param cs_txt_bin send result in string or native types
51 i.e. to CS_TEXT_REPRESENTATION or
52 CS_BINARY_REPRESENTATION
53 @param cs_charset charset for the string data input
54 @param cmd command service data input structure containing
55 command details (query/database/session id..).
56 Check include/mysql/com_data.h for more details.
57 @param cmd_type command type default set is COM_QUERY
58
59 @return the sql error number
60 @retval 0 OK
61 @retval >0 SQL Error Number returned from MySQL Service API
62 @retval -1 Internal server session failed or was killed
63 @retval -2 Internal API failure
64 */
65 long execute_internal(Sql_resultset *rset, enum cs_text_or_binary cs_txt_bin,
66 const CHARSET_INFO *cs_charset, COM_DATA cmd,
67 enum enum_server_command cmd_type);
68
69 /**
70 Wait for server to be in SERVER_OPERATING state
71
72 @param total_timeout number of seconds to wait for
73 session server
74
75 @return session server availability
76 @retval 0 session server is in SERVER_OPERATING state
77 @retval 1 timeout
78 @retval -1 session server shutdown in progress
79 */
80 int wait_for_session_server(ulong total_timeout);
81
82 /**
83 Configures the session's session variables.
84
85 @return the sql error number
86 @retval 0 OK
87 @retval >0 SQL Error Number returned from MySQL Service API
88 @retval <0 local errors
89 */
90 long configure_session();
91
92 public:
93 /**
94 Sql_service_interface constructor - Non-threaded version
95
96 Initializes sql_service_context class
97
98 @param cs_txt_bin send result in string or native types
99 i.e. to CS_TEXT_REPRESENTATION or
100 CS_BINARY_REPRESENTATION
101 @param cs_charset charset for the string data input
102 */
105 const CHARSET_INFO *cs_charset = &my_charset_utf8mb3_general_ci);
106
107 /**
108 Sql_service_interface destructor
109 */
111
112 /**
113 Opens an server session for internal server connection.
114
115 @return the operation status
116 @retval 0 OK
117 @retval !=0 Error
118 */
119 int open_session();
120
121 /**
122 Opens an threaded server session for internal server connection.
123
124 @param plugin_ptr a plugin pointer passed the connection thread.
125
126 @return the operation status
127 @retval 0 OK
128 @retval !=0 Error
129 */
130 int open_thread_session(void *plugin_ptr);
131
132 /**
133 Executes a server command in a session.
134
135 @note the command type here is COM_QUERY
136
137 @param query_string query to be executed
138
139 @return the sql error number
140 @retval 0 OK
141 @retval >0 SQL Error Number returned from MySQL Service API
142 @retval <0 local errors
143 */
144 long execute_query(std::string query_string);
145
146 /**
147 Executes a server command in a session.
148
149 @param sql_string query to be executed
150 @param rset resulted obtained after executing query
151 @param cs_txt_bin send result in string or native types
152 i.e. to CS_TEXT_REPRESENTATION or
153 CS_BINARY_REPRESENTATION
154 @param cs_charset charset for the string data input
155
156 @note the command type here is COM_QUERY
157
158 @return the sql error number
159 @retval 0 OK
160 @retval >0 SQL Error Number returned from MySQL Service API
161 @retval <0 local errors
162 */
163 long execute_query(
164 std::string sql_string, Sql_resultset *rset,
166 const CHARSET_INFO *cs_charset = &my_charset_utf8mb3_general_ci);
167
168 /**
169 Executes a server command in a session.
170
171 @param cmd command service data input structure containing
172 command details (query/database/session id..).
173 Check include/mysql/com_data.h for more details.
174 @param cmd_type command type default set is COM_QUERY
175 @param rset resulted obtained after executing query
176 @param cs_txt_bin send result in string or native types
177 i.e. to CS_TEXT_REPRESENTATION or
178 CS_BINARY_REPRESENTATION
179 @param cs_charset charset for the string data input
180
181 @return the sql error number
182 @retval 0 OK
183 @retval >0 SQL Error Number returned from MySQL Service API
184 @retval <0 local errors
185 */
186 long execute(COM_DATA cmd, enum enum_server_command cmd_type,
187 Sql_resultset *rset,
189 const CHARSET_INFO *cs_charset = &my_charset_utf8mb3_general_ci);
190
191 /**
192 Set send result type to CS_TEXT_REPRESENTATION or
193 CS_BINARY_REPRESENTATION
194
195 @param field_type send result in string or native types
196 i.e. to CS_TEXT_REPRESENTATION or
197 CS_BINARY_REPRESENTATION
198 */
200 m_txt_or_bin = field_type;
201 }
202
203 /**
204 set charset for the string data input(com_query for example)
205
206 @param charset charset for the string data input
207 */
209
210 /**
211 Returns whether the session was killed
212
213 @retval 0 not killed
214 @retval 1 killed
215 */
217 return srv_session_info_killed(session);
218 }
219
220 /**
221 Returns the ID of a session.
222
223 @return thread ID
224 */
225 uint64_t get_session_id() {
227 }
228
229 /**
230 Returns the MYSQL_SESSION object.
231
232 @return thread ID
233 */
235
236 /**
237 Set the session associated user.
238
239 @param user the user to change to
240
241 @retval 0 all ok
242 @retval 1 error
243 */
244 int set_session_user(const char *user);
245
246 /**
247 Check if the server is running without user privileges
248
249 @retval true the server is skipping the grant table
250 @retval false user privileges are working normally
251 */
252 bool is_acl_disabled();
253};
254
255extern bool sql_service_interface_init();
256extern bool sql_service_interface_deinit();
257
258#endif // SQL_SERVICE_INTERFACE_INCLUDE
Definition: sql_resultset.h:72
Definition: sql_service_interface.h:32
~Sql_service_interface()
Sql_service_interface destructor.
Definition: sql_service_interface.cc:42
bool is_acl_disabled()
Check if the server is running without user privileges.
Definition: sql_service_interface.cc:279
long execute_query(std::string query_string)
Executes a server command in a session.
Definition: sql_service_interface.cc:190
void set_charset(const CHARSET_INFO *charset)
set charset for the string data input(com_query for example)
Definition: sql_service_interface.h:208
long execute_internal(Sql_resultset *rset, enum cs_text_or_binary cs_txt_bin, const CHARSET_INFO *cs_charset, COM_DATA cmd, enum enum_server_command cmd_type)
Executes a server command in a session.
Definition: sql_service_interface.cc:127
MYSQL_SESSION m_session
Pointer to Srv_session class.
Definition: sql_service_interface.h:35
int is_session_killed(MYSQL_SESSION session)
Returns whether the session was killed.
Definition: sql_service_interface.h:216
int wait_for_session_server(ulong total_timeout)
Wait for server to be in SERVER_OPERATING state.
Definition: sql_service_interface.cc:233
Sql_service_interface(enum cs_text_or_binary cs_txt_bin=CS_TEXT_REPRESENTATION, const CHARSET_INFO *cs_charset=&my_charset_utf8mb3_general_ci)
Sql_service_interface constructor - Non-threaded version.
Definition: sql_service_interface.cc:38
long execute(COM_DATA cmd, enum enum_server_command cmd_type, Sql_resultset *rset, enum cs_text_or_binary cs_txt_bin=CS_TEXT_REPRESENTATION, const CHARSET_INFO *cs_charset=&my_charset_utf8mb3_general_ci)
Executes a server command in a session.
Definition: sql_service_interface.cc:221
int set_session_user(const char *user)
Set the session associated user.
Definition: sql_service_interface.cc:260
MYSQL_SESSION get_session()
Returns the MYSQL_SESSION object.
Definition: sql_service_interface.h:234
uint64_t get_session_id()
Returns the ID of a session.
Definition: sql_service_interface.h:225
void * m_plugin
Pointer to the group_replication plugin structure.
Definition: sql_service_interface.h:38
int open_thread_session(void *plugin_ptr)
Opens an threaded server session for internal server connection.
Definition: sql_service_interface.cc:85
const CHARSET_INFO * m_charset
Definition: sql_service_interface.h:44
void set_send_resulttype(enum cs_text_or_binary field_type)
Set send result type to CS_TEXT_REPRESENTATION or CS_BINARY_REPRESENTATION.
Definition: sql_service_interface.h:199
int open_session()
Opens an server session for internal server connection.
Definition: sql_service_interface.cc:64
enum cs_text_or_binary m_txt_or_bin
send result in string or native types
Definition: sql_service_interface.h:41
long configure_session()
Configures the session's session variables.
Definition: sql_service_interface.cc:120
MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_utf8mb3_general_ci
Definition: ctype-utf8.cc:5779
enum_server_command
A list of all MySQL protocol commands.
Definition: my_command.h:48
char * user
Definition: mysqladmin.cc:60
const std::string charset("charset")
cs_text_or_binary
Definition: service_command.h:389
@ CS_TEXT_REPRESENTATION
Definition: service_command.h:390
class Srv_session * MYSQL_SESSION
Definition: service_srv_session_bits.h:37
int srv_session_info_killed(MYSQL_SESSION session)
Returns whether the session was killed.
my_thread_id srv_session_info_get_session_id(MYSQL_SESSION session)
Returns the ID of a session.
bool sql_service_interface_deinit()
Definition: sql_service_interface.cc:309
bool sql_service_interface_init()
Definition: sql_service_interface.cc:292
Definition: m_ctype.h:385
Definition: com_data.h:112