MySQL 26.10.0
Source Code Documentation
mysql_command_services_imp.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 2026, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_COMMAND_SERVICES_IMP_H
25#define MYSQL_COMMAND_SERVICES_IMP_H
26
27#include <include/my_inttypes.h>
28#include <include/mysql.h>
34
35// Use an internal MySQL server user
36#define MYSQL_SESSION_USER "mysql.session"
37#define MYSQL_SYS_HOST "localhost"
38
43};
44
46 MYSQL *mysql = nullptr;
47 const MYSQL_METHODS *client_methods = nullptr;
48 // A failed mysql_real_connect() frees MYSQL::extension.
49 // Keep these settings here so they survive the failure.
50 // The handle owns the user and host name copies.
51 char *user_name = nullptr;
52 char *host_name = nullptr;
53 bool admin_session = true;
56};
57
59 MYSQL_RES *mysql_res = nullptr;
60};
61
62/**
63 This structure is used by mysql command service.
64 session_svc and is_thd_associated is set in cssm_begin_connect()
65 command_consumer_services is set by
66 mysql_service_mysql_command_options::set() api,
67 if it is nullptr then the default mysql_test_consumer services will be set.
68 data is allocated in mysql_text_consumer_factory_v1 service start() api.
69 csi_read_rows() transfers it for mysql_store_result(); mysql_use_result()
70 consumes it through use_result_cursor until EOF or mysql_free_result().
71 This information is used by mysql_text_consumer service apis.
72 mcs_thd, mcs_protocol, mcs_password, mcs_tcpip_port, mcs_db and
73 mcs_client_flag will be set by mysql_service_mysql_command_options set() api.
74*/
77 bool is_thd_associated; /* this is used to free session_svc,
78 if it was allocated. */
79 MYSQL_DATA *data = nullptr;
83 MYSQL_THD mcs_thd = nullptr;
84 const char *mcs_protocol = nullptr;
85 const char *mcs_password = nullptr;
87 const char *mcs_db = nullptr;
88 uint32_t mcs_client_flag = 0;
89 bool mcs_admin_session = true;
90 bool no_lock_registry = false;
91 /*
92 Remember whether set() chose default or custom services after service
93 names are resolved to pointers. Only the default factory context is a
94 Dom_ctx, and only custom capabilities or explicit client flags opt into
95 session tracking.
96 */
99};
100
101#define MYSQL_COMMAND_SERVICE_EXTN(H) \
102 reinterpret_cast<struct mysql_command_service_extn *>( \
103 MYSQL_EXTENSION_PTR(H)->mcs_extn)
104
105/**
106 An implementation of mysql command services apis.
107*/
109 public:
110 /** Check whether a literal bind value accepts a loopback address family. */
111 static bool bind_address_accepts_loopback(const char *bind_address,
112 bool use_ipv4);
113
114 /* mysql_command_factory service apis */
115 static DEFINE_BOOL_METHOD(init, (MYSQL_H * mysql_h));
116 static DEFINE_BOOL_METHOD(connect, (MYSQL_H mysql_h));
117 static DEFINE_BOOL_METHOD(reset, (MYSQL_H mysql_h));
118 static DEFINE_BOOL_METHOD(close, (MYSQL_H mysql_h));
119 static DEFINE_BOOL_METHOD(commit, (MYSQL_H mysql_h));
120 static DEFINE_BOOL_METHOD(autocommit, (MYSQL_H mysql_h, bool mode));
121 static DEFINE_BOOL_METHOD(rollback, (MYSQL_H mysql_h));
122
123 /* mysql_command_thread service apis */
124 static DEFINE_BOOL_METHOD(init, (void));
125 static DEFINE_METHOD(void, end, (void));
126
127 /* mysql_command_options service apis */
128 static DEFINE_BOOL_METHOD(set, (MYSQL_H mysql, int option, const void *arg));
129 static DEFINE_BOOL_METHOD(get, (MYSQL_H mysql, int option, const void *arg));
130
131 /* mysql_command_query service apis */
132 static DEFINE_BOOL_METHOD(query, (MYSQL_H mysql, const char *stmt_str,
133 unsigned long length));
134 static DEFINE_BOOL_METHOD(affected_rows, (MYSQL_H mysql, uint64_t *rows));
135
136 /* mysql_command_query_result service apis */
138 (MYSQL_H mysql, MYSQL_RES_H *mysql_res));
140 (MYSQL_H mysql, MYSQL_RES_H *mysql_res));
141 static DEFINE_BOOL_METHOD(free_result, (MYSQL_RES_H mysql_res));
143 static DEFINE_METHOD(int, next_result, (MYSQL_H mysql));
146 static DEFINE_BOOL_METHOD(fetch_lengths, (MYSQL_RES_H res_h, ulong **length));
147
148 /* mysql_command_field_info service apis */
150 (MYSQL_RES_H res_h, MYSQL_FIELD_H *field_h));
152 (MYSQL_RES_H res_h, unsigned int *num_fields));
154 (MYSQL_RES_H res_h, MYSQL_FIELD_H **fields_h));
156 (MYSQL_H mysql_h, unsigned int *num_fields));
157
158 /* mysql_command_error_info service apis */
159 static DEFINE_BOOL_METHOD(sql_errno, (MYSQL_H mysql_h, unsigned int *err_no));
160 static DEFINE_BOOL_METHOD(sql_error, (MYSQL_H mysql_h, char **errmsg));
162 (MYSQL_H mysql_h, char **sqlstate_errmsg));
163
164 /* mysql_command_field_metadata service APIs */
166 (MYSQL_FIELD_H field_h, int metadata, void *data));
167};
168
169/** This is a wrapper class of all the mysql_text_consumer services refs */
171 public:
172 SERVICE_TYPE(mysql_text_consumer_factory_v1) * factory_srv;
173 SERVICE_TYPE(mysql_text_consumer_metadata_v1) * metadata_srv;
174 SERVICE_TYPE(mysql_text_consumer_row_factory_v1) * row_factory_srv;
175 SERVICE_TYPE(mysql_text_consumer_error_v1) * error_srv;
176 SERVICE_TYPE(mysql_text_consumer_get_null_v1) * get_null_srv;
177 SERVICE_TYPE(mysql_text_consumer_get_integer_v1) * get_integer_srv;
178 SERVICE_TYPE(mysql_text_consumer_get_longlong_v1) * get_longlong_srv;
179 SERVICE_TYPE(mysql_text_consumer_get_decimal_v1) * get_decimal_srv;
180 SERVICE_TYPE(mysql_text_consumer_get_double_v1) * get_double_srv;
181 SERVICE_TYPE(mysql_text_consumer_get_date_time_v1) * get_date_time_srv;
182 SERVICE_TYPE(mysql_text_consumer_get_string_v1) * get_string_srv;
183 SERVICE_TYPE(mysql_text_consumer_client_capabilities_v1) *
185};
186
187#endif /* MYSQL_COMMAND_SERVICES_IMP_H */
#define MYSQL_THD
Definition: backup_page_tracker.h:38
This is a wrapper class of all the mysql_text_consumer services refs.
Definition: mysql_command_services_imp.h:170
const mysql_service_mysql_text_consumer_get_string_v1_t * get_string_srv
Definition: mysql_command_services_imp.h:182
const mysql_service_mysql_text_consumer_factory_v1_t * factory_srv
Definition: mysql_command_services_imp.h:172
const mysql_service_mysql_text_consumer_error_v1_t * error_srv
Definition: mysql_command_services_imp.h:175
const mysql_service_mysql_text_consumer_client_capabilities_v1_t * client_capabilities_srv
Definition: mysql_command_services_imp.h:184
const mysql_service_mysql_text_consumer_get_null_v1_t * get_null_srv
Definition: mysql_command_services_imp.h:176
const mysql_service_mysql_text_consumer_metadata_v1_t * metadata_srv
Definition: mysql_command_services_imp.h:173
const mysql_service_mysql_text_consumer_row_factory_v1_t * row_factory_srv
Definition: mysql_command_services_imp.h:174
const mysql_service_mysql_text_consumer_get_integer_v1_t * get_integer_srv
Definition: mysql_command_services_imp.h:177
const mysql_service_mysql_text_consumer_get_decimal_v1_t * get_decimal_srv
Definition: mysql_command_services_imp.h:179
const mysql_service_mysql_text_consumer_get_date_time_v1_t * get_date_time_srv
Definition: mysql_command_services_imp.h:181
const mysql_service_mysql_text_consumer_get_longlong_v1_t * get_longlong_srv
Definition: mysql_command_services_imp.h:178
const mysql_service_mysql_text_consumer_get_double_v1_t * get_double_srv
Definition: mysql_command_services_imp.h:180
An implementation of mysql command services apis.
Definition: mysql_command_services_imp.h:108
static mysql_service_status_t use_result(MYSQL_H mysql, MYSQL_RES_H *mysql_res) noexcept
static int next_result(MYSQL_H mysql) noexcept
Calls mysql_next_result api to returns/initiates the next result in multiple-result executions.
Definition: mysql_command_services_imp.cc:1103
static mysql_service_status_t result_metadata(MYSQL_RES_H res_h) noexcept
Calls mysql_result_metadata api to check whether a result set has metadata.
Definition: mysql_command_services_imp.cc:1129
static mysql_service_status_t fetch_field(MYSQL_RES_H res_h, MYSQL_FIELD_H *field_h) noexcept
Calls mysql_fetch_field api to returns the type of next table field.
Definition: mysql_command_services_imp.cc:1205
static bool bind_address_accepts_loopback(const char *bind_address, bool use_ipv4)
Check whether a literal bind value accepts a loopback address family.
Definition: mysql_command_services_imp.cc:131
static mysql_service_status_t autocommit(MYSQL_H mysql_h, bool mode) noexcept
Calls mysql_autocommit api to toggles autocommit mode on/off.
Definition: mysql_command_services_imp.cc:407
static mysql_service_status_t rollback(MYSQL_H mysql_h) noexcept
Calls mysql_rollback api to rolls back the transaction.
Definition: mysql_command_services_imp.cc:427
static mysql_service_status_t connect(MYSQL_H mysql_h) noexcept
Calls mysql_real_connect api to connect to a MySQL server.
Definition: mysql_command_services_imp.cc:150
static mysql_service_status_t close(MYSQL_H mysql_h) noexcept
Calls mysql_close api to closes a server connection.
Definition: mysql_command_services_imp.cc:358
static mysql_service_status_t num_fields(MYSQL_RES_H res_h, unsigned int *num_fields) noexcept
Calls mysql_num_fields api to returns the number of columns in a result set.
Definition: mysql_command_services_imp.cc:1229
static mysql_service_status_t more_results(MYSQL_H mysql) noexcept
Calls mysql_more_results api to checks whether any more results exist.
Definition: mysql_command_services_imp.cc:1081
static void end(void) noexcept
Calls session deinit_thread() to deinitialize a physical thread that has been using the session servi...
Definition: mysql_command_services_imp.cc:127
static mysql_service_status_t query(MYSQL_H mysql, const char *stmt_str, unsigned long length) noexcept
Calls mysql_real_query api to executes an SQL query specified as a counted string.
Definition: mysql_command_services_imp.cc:977
static mysql_service_status_t affected_rows(MYSQL_H mysql, uint64_t *rows) noexcept
Calls mysql_affected_rows api to return the number of rows changed/deleted/inserted by the last UPDAT...
Definition: mysql_command_services_imp.cc:1000
static mysql_service_status_t init(void) noexcept
Calls session init_thread() to initialize a physical thread to use the session service.
Definition: mysql_command_services_imp.cc:119
static mysql_service_status_t free_result(MYSQL_RES_H mysql_res) noexcept
Calls mysql_free_result api to frees memory used by a result set.
Definition: mysql_command_services_imp.cc:1058
static mysql_service_status_t field_count(MYSQL_H mysql_h, unsigned int *num_fields) noexcept
Calls mysql_field_count api to returns the number of columns for the most resent statement.
Definition: mysql_command_services_imp.cc:1277
static mysql_service_status_t store_result(MYSQL_H mysql, MYSQL_RES_H *mysql_res) noexcept
Calls mysql_store_result api to retrieves a complete result set.
Definition: mysql_command_services_imp.cc:1025
static mysql_service_status_t get(MYSQL_H mysql, int option, const void *arg) noexcept
Calls mysql_get_option api to returns the value of a mysql_options() option.
Definition: mysql_command_services_imp.cc:930
static mysql_service_status_t fetch_fields(MYSQL_RES_H res_h, MYSQL_FIELD_H **fields_h) noexcept
Calls mysql_fetch_fields api to returns an array of all field structures.
Definition: mysql_command_services_imp.cc:1252
static mysql_service_status_t fetch_row(MYSQL_RES_H res_h, char ***row) noexcept
Calls mysql_fetch_row api to fetches the next row from the result set.
Definition: mysql_command_services_imp.cc:1153
static mysql_service_status_t reset(MYSQL_H mysql_h) noexcept
Calls mysql_reset_connection api to resets the connection to clear session state.
Definition: mysql_command_services_imp.cc:334
static mysql_service_status_t field_metadata_get(MYSQL_FIELD_H field_h, int metadata, void *data) noexcept
Definition: mysql_command_services_imp.cc:1372
static mysql_service_status_t set(MYSQL_H mysql, int option, const void *arg) noexcept
Calls mysql_options api to sets connect options for connection-establishment functions such as real_c...
Definition: mysql_command_services_imp.cc:496
static mysql_service_status_t commit(MYSQL_H mysql_h) noexcept
Calls mysql_commit api to commits the transaction.
Definition: mysql_command_services_imp.cc:384
static mysql_service_status_t sql_state(MYSQL_H mysql_h, char **sqlstate_errmsg) noexcept
Calls mysql_sqlstate api to return the SQLSTATE error code for the last error.
Definition: mysql_command_services_imp.cc:1355
static mysql_service_status_t sql_errno(MYSQL_H mysql_h, unsigned int *err_no) noexcept
Calls mysql_errno api to return the number of most recently invoked mysql function.
Definition: mysql_command_services_imp.cc:1299
static mysql_service_status_t sql_error(MYSQL_H mysql_h, char **errmsg) noexcept
Calls mysql_error api to return the error message of most recently invoked mysql function.
Definition: mysql_command_services_imp.cc:1327
static mysql_service_status_t fetch_lengths(MYSQL_RES_H res_h, ulong **length) noexcept
Calls mysql_fetch_lengths api to Returns the lengths of all columns in the current row.
Definition: mysql_command_services_imp.cc:1179
Some integer typedefs for easier portability.
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient.
struct SRV_CTX_H_imp * SRV_CTX_H
Definition: mysql_command_consumer.h:31
struct MYSQL_H_imp * MYSQL_H
Definition: mysql_command_services.h:33
struct MYSQL_RES_H_imp * MYSQL_RES_H
Definition: mysql_command_services.h:34
struct MYSQL_FIELD_H_imp * MYSQL_FIELD_H
Definition: mysql_command_services.h:35
#define MYSQL_ROW_H
Definition: mysql_command_services.h:37
mysql_command_connection_mode
Definition: mysql_command_services_imp.h:39
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Definition: system_info_linux.cc:46
mode
Definition: file_handle.h:61
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:76
Specifies macros to define Service Implementations.
#define DEFINE_BOOL_METHOD(name, args)
A short macro to define method that returns bool, which is the most common case.
Definition: service_implementation.h:88
#define DEFINE_METHOD(retval, name, args)
A macro to ensure method implementation has required properties, that is it does not throw exceptions...
Definition: service_implementation.h:79
These are the common definitions between the plugin service for sessions and the component service ex...
class Srv_session * MYSQL_SESSION
Definition: service_srv_session_bits.h:37
Definition: mysql.h:163
Definition: sql_common.h:209
Definition: mysql.h:343
Definition: mysql.h:153
Definition: mysql.h:303
Definition: mysql_command_services_imp.h:45
bool admin_session
Definition: mysql_command_services_imp.h:53
const MYSQL_METHODS * client_methods
Definition: mysql_command_services_imp.h:47
char * host_name
Definition: mysql_command_services_imp.h:52
mysql_command_connection_mode connection_mode
Definition: mysql_command_services_imp.h:54
char * user_name
Definition: mysql_command_services_imp.h:51
Definition: mysql_command_services_imp.h:58
MYSQL_RES * mysql_res
Definition: mysql_command_services_imp.h:59
This structure is used by mysql command service.
Definition: mysql_command_services_imp.h:75
bool is_thd_associated
Definition: mysql_command_services_imp.h:77
void * command_consumer_services
Definition: mysql_command_services_imp.h:81
SRV_CTX_H consumer_srv_data
Definition: mysql_command_services_imp.h:82
bool mcs_admin_session
Definition: mysql_command_services_imp.h:89
MYSQL_ROWS * use_result_cursor
Definition: mysql_command_services_imp.h:80
bool has_custom_client_capabilities_service
Definition: mysql_command_services_imp.h:98
MYSQL_SESSION session_svc
Definition: mysql_command_services_imp.h:76
const char * mcs_protocol
Definition: mysql_command_services_imp.h:84
bool has_custom_consumer_factory
Definition: mysql_command_services_imp.h:97
bool no_lock_registry
Definition: mysql_command_services_imp.h:90
const char * mcs_password
Definition: mysql_command_services_imp.h:85
uint32_t mcs_client_flag
Definition: mysql_command_services_imp.h:88
int mcs_tcpip_port
Definition: mysql_command_services_imp.h:86
MYSQL_THD mcs_thd
Definition: mysql_command_services_imp.h:83
MYSQL_DATA * data
Definition: mysql_command_services_imp.h:79
const char * mcs_db
Definition: mysql_command_services_imp.h:87