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