MySQL 8.4.0
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
32struct CHARSET_INFO;
33
35 private:
36 /** Pointer to Srv_session class */
38
39 /** Pointer to the group_replication plugin structure */
40 void *m_plugin;
41
42 /** send result in string or native types */
44
45 /* The charset for the input string data */
47
48 /**
49 Executes a server command in a session.
50
51 @param rset resulted obtained after executing query
52 @param cs_txt_bin send result in string or native types
53 i.e. to CS_TEXT_REPRESENTATION or
54 CS_BINARY_REPRESENTATION
55 @param cs_charset charset for the string data input
56 @param cmd command service data input structure containing
57 command details (query/database/session id..).
58 Check include/mysql/com_data.h for more details.
59 @param cmd_type command type default set is COM_QUERY
60
61 @return the sql error number
62 @retval 0 OK
63 @retval >0 SQL Error Number returned from MySQL Service API
64 @retval -1 Internal server session failed or was killed
65 @retval -2 Internal API failure
66 */
67 long execute_internal(Sql_resultset *rset, enum cs_text_or_binary cs_txt_bin,
68 const CHARSET_INFO *cs_charset, COM_DATA cmd,
69 enum enum_server_command cmd_type);
70
71 /**
72 Wait for server to be in SERVER_OPERATING state
73
74 @param total_timeout number of seconds to wait for
75 session server
76
77 @return session server availability
78 @retval 0 session server is in SERVER_OPERATING state
79 @retval 1 timeout
80 @retval -1 session server shutdown in progress
81 */
82 int wait_for_session_server(ulong total_timeout);
83
84 /**
85 Configures the session's session variables.
86
87 @return the sql error number
88 @retval 0 OK
89 @retval >0 SQL Error Number returned from MySQL Service API
90 @retval <0 local errors
91 */
92 long configure_session();
93
94 public:
95 /**
96 Sql_service_interface constructor - Non-threaded version
97
98 Initializes sql_service_context class
99
100 @param cs_txt_bin send result in string or native types
101 i.e. to CS_TEXT_REPRESENTATION or
102 CS_BINARY_REPRESENTATION
103 @param cs_charset charset for the string data input
104 */
107 const CHARSET_INFO *cs_charset = &my_charset_utf8mb3_general_ci);
108
109 /**
110 Sql_service_interface destructor
111 */
113
114 /**
115 Opens an server session for internal server connection.
116
117 @return the operation status
118 @retval 0 OK
119 @retval !=0 Error
120 */
121 int open_session();
122
123 /**
124 Opens an threaded server session for internal server connection.
125
126 @param plugin_ptr a plugin pointer passed the connection thread.
127
128 @return the operation status
129 @retval 0 OK
130 @retval !=0 Error
131 */
132 int open_thread_session(void *plugin_ptr);
133
134 /**
135 Executes a server command in a session.
136
137 @note the command type here is COM_QUERY
138
139 @param query_string query to be executed
140
141 @return the sql error number
142 @retval 0 OK
143 @retval >0 SQL Error Number returned from MySQL Service API
144 @retval <0 local errors
145 */
146 long execute_query(std::string query_string);
147
148 /**
149 Executes a server command in a session.
150
151 @param sql_string query to be executed
152 @param rset resulted obtained after executing query
153 @param cs_txt_bin send result in string or native types
154 i.e. to CS_TEXT_REPRESENTATION or
155 CS_BINARY_REPRESENTATION
156 @param cs_charset charset for the string data input
157
158 @note the command type here is COM_QUERY
159
160 @return the sql error number
161 @retval 0 OK
162 @retval >0 SQL Error Number returned from MySQL Service API
163 @retval <0 local errors
164 */
165 long execute_query(
166 std::string sql_string, Sql_resultset *rset,
168 const CHARSET_INFO *cs_charset = &my_charset_utf8mb3_general_ci);
169
170 /**
171 Executes a server command in a session.
172
173 @param cmd command service data input structure containing
174 command details (query/database/session id..).
175 Check include/mysql/com_data.h for more details.
176 @param cmd_type command type default set is COM_QUERY
177 @param rset resulted obtained after executing query
178 @param cs_txt_bin send result in string or native types
179 i.e. to CS_TEXT_REPRESENTATION or
180 CS_BINARY_REPRESENTATION
181 @param cs_charset charset for the string data input
182
183 @return the sql error number
184 @retval 0 OK
185 @retval >0 SQL Error Number returned from MySQL Service API
186 @retval <0 local errors
187 */
188 long execute(COM_DATA cmd, enum enum_server_command cmd_type,
189 Sql_resultset *rset,
191 const CHARSET_INFO *cs_charset = &my_charset_utf8mb3_general_ci);
192
193 /**
194 Set send result type to CS_TEXT_REPRESENTATION or
195 CS_BINARY_REPRESENTATION
196
197 @param field_type send result in string or native types
198 i.e. to CS_TEXT_REPRESENTATION or
199 CS_BINARY_REPRESENTATION
200 */
202 m_txt_or_bin = field_type;
203 }
204
205 /**
206 set charset for the string data input(com_query for example)
207
208 @param charset charset for the string data input
209 */
211
212 /**
213 Returns whether the session was killed
214
215 @retval 0 not killed
216 @retval 1 killed
217 */
219 return srv_session_info_killed(session);
220 }
221
222 /**
223 Returns the ID of a session.
224
225 @return thread ID
226 */
227 uint64_t get_session_id() {
229 }
230
231 /**
232 Returns the MYSQL_SESSION object.
233
234 @return thread ID
235 */
237
238 /**
239 Set the session associated user.
240
241 @param user the user to change to
242
243 @retval 0 all ok
244 @retval 1 error
245 */
246 int set_session_user(const char *user);
247
248 /**
249 Check if the server is running without user privileges
250
251 @retval true the server is skipping the grant table
252 @retval false user privileges are working normally
253 */
254 bool is_acl_disabled();
255};
256
257extern bool sql_service_interface_init();
258extern bool sql_service_interface_deinit();
259
260#endif // SQL_SERVICE_INTERFACE_INCLUDE
Definition: sql_resultset.h:74
Definition: sql_service_interface.h:34
~Sql_service_interface()
Sql_service_interface destructor.
Definition: sql_service_interface.cc:44
bool is_acl_disabled()
Check if the server is running without user privileges.
Definition: sql_service_interface.cc:281
long execute_query(std::string query_string)
Executes a server command in a session.
Definition: sql_service_interface.cc:192
void set_charset(const CHARSET_INFO *charset)
set charset for the string data input(com_query for example)
Definition: sql_service_interface.h:210
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:129
MYSQL_SESSION m_session
Pointer to Srv_session class.
Definition: sql_service_interface.h:37
int is_session_killed(MYSQL_SESSION session)
Returns whether the session was killed.
Definition: sql_service_interface.h:218
int wait_for_session_server(ulong total_timeout)
Wait for server to be in SERVER_OPERATING state.
Definition: sql_service_interface.cc:235
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:40
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:223
int set_session_user(const char *user)
Set the session associated user.
Definition: sql_service_interface.cc:262
MYSQL_SESSION get_session()
Returns the MYSQL_SESSION object.
Definition: sql_service_interface.h:236
uint64_t get_session_id()
Returns the ID of a session.
Definition: sql_service_interface.h:227
void * m_plugin
Pointer to the group_replication plugin structure.
Definition: sql_service_interface.h:40
int open_thread_session(void *plugin_ptr)
Opens an threaded server session for internal server connection.
Definition: sql_service_interface.cc:87
const CHARSET_INFO * m_charset
Definition: sql_service_interface.h:46
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:201
int open_session()
Opens an server session for internal server connection.
Definition: sql_service_interface.cc:66
enum cs_text_or_binary m_txt_or_bin
send result in string or native types
Definition: sql_service_interface.h:43
long configure_session()
Configures the session's session variables.
Definition: sql_service_interface.cc:122
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_utf8mb3_general_ci
Definition: ctype-utf8.cc:5795
enum_server_command
A list of all MySQL protocol commands.
Definition: my_command.h:48
char * user
Definition: mysqladmin.cc:66
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:311
bool sql_service_interface_init()
Definition: sql_service_interface.cc:294
Definition: m_ctype.h:423
Definition: com_data.h:104