MySQL 8.0.39
Source Code Documentation
mysql_command_services_imp.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 2024, 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
40 MYSQL *mysql = nullptr;
41};
42
44 MYSQL_RES *mysql_res = nullptr;
45};
46
47/**
48 This structure is used by mysql command service.
49 session_svc and is_thd_associated is set in cssm_begin_connect()
50 command_consumer_services is set by
51 mysql_service_mysql_command_options::set() api,
52 if it is nullptr then the default mysql_test_consumer services will be set.
53 data is allocated in mysql_text_consumer_factory_v1 service start() api,
54 and this data is retrived by csi_read_rows().
55 This information is used by mysql_text_consumer service apis.
56 mcs_thd, mcs_protocol, mcs_user_name, mcs_password, mcs_tcpip_port,
57 mcs_db and mcs_client_flag will be set by mysql_service_mysql_command_options
58 set() api.
59*/
62 bool is_thd_associated; /* this is used to free session_svc,
63 if it was allocated. */
64 MYSQL_DATA *data = nullptr;
67 MYSQL_THD mcs_thd = nullptr;
68 const char *mcs_protocol = nullptr;
69 const char *mcs_user_name = nullptr;
70 const char *mcs_host_name = nullptr;
71 const char *mcs_password = nullptr;
73 const char *mcs_db = nullptr;
74 uint32_t mcs_client_flag = 0;
75};
76
77#define MYSQL_COMMAND_SERVICE_EXTN(H) \
78 reinterpret_cast<struct mysql_command_service_extn *>( \
79 MYSQL_EXTENSION_PTR(H)->mcs_extn)
80
81/**
82 An implementation of mysql command services apis.
83*/
85 public:
86 /* mysql_command_factory service apis */
87 static DEFINE_BOOL_METHOD(init, (MYSQL_H * mysql_h));
88 static DEFINE_BOOL_METHOD(connect, (MYSQL_H mysql_h));
89 static DEFINE_BOOL_METHOD(reset, (MYSQL_H mysql_h));
90 static DEFINE_BOOL_METHOD(close, (MYSQL_H mysql_h));
91 static DEFINE_BOOL_METHOD(commit, (MYSQL_H mysql_h));
92 static DEFINE_BOOL_METHOD(autocommit, (MYSQL_H mysql_h, bool mode));
93 static DEFINE_BOOL_METHOD(rollback, (MYSQL_H mysql_h));
94
95 /* mysql_command_thread service apis */
96 static DEFINE_BOOL_METHOD(init, (void));
97 static DEFINE_METHOD(void, end, (void));
98
99 /* mysql_command_options service apis */
100 static DEFINE_BOOL_METHOD(set, (MYSQL_H mysql, int option, const void *arg));
101 static DEFINE_BOOL_METHOD(get, (MYSQL_H mysql, int option, const void *arg));
102
103 /* mysql_command_query service apis */
104 static DEFINE_BOOL_METHOD(query, (MYSQL_H mysql, const char *stmt_str,
105 unsigned long length));
106 static DEFINE_BOOL_METHOD(affected_rows, (MYSQL_H mysql, uint64_t *rows));
107
108 /* mysql_command_query_result service apis */
110 (MYSQL_H mysql, MYSQL_RES_H *mysql_res));
112 (MYSQL_H mysql, MYSQL_RES_H *mysql_res));
113 static DEFINE_BOOL_METHOD(free_result, (MYSQL_RES_H mysql_res));
115 static DEFINE_METHOD(int, next_result, (MYSQL_H mysql));
118 static DEFINE_BOOL_METHOD(fetch_lengths, (MYSQL_RES_H res_h, ulong **length));
119
120 /* mysql_command_field_info service apis */
122 (MYSQL_RES_H res_h, MYSQL_FIELD_H *field_h));
124 (MYSQL_RES_H res_h, unsigned int *num_fields));
126 (MYSQL_RES_H res_h, MYSQL_FIELD_H **fields_h));
128 (MYSQL_H mysql_h, unsigned int *num_fields));
129
130 /* mysql_command_error_info service apis */
131 static DEFINE_BOOL_METHOD(sql_errno, (MYSQL_H mysql_h, unsigned int *err_no));
132 static DEFINE_BOOL_METHOD(sql_error, (MYSQL_H mysql_h, char **errmsg));
134 (MYSQL_H mysql_h, char **sqlstate_errmsg));
135
136 /* mysql_command_field_metadata service APIs */
138 (MYSQL_FIELD_H field_h, int metadata, void *data));
139};
140
141/** This is a wrapper class of all the mysql_text_consumer services refs */
143 public:
144 SERVICE_TYPE(mysql_text_consumer_factory_v1) * factory_srv;
145 SERVICE_TYPE(mysql_text_consumer_metadata_v1) * metadata_srv;
146 SERVICE_TYPE(mysql_text_consumer_row_factory_v1) * row_factory_srv;
147 SERVICE_TYPE(mysql_text_consumer_error_v1) * error_srv;
148 SERVICE_TYPE(mysql_text_consumer_get_null_v1) * get_null_srv;
149 SERVICE_TYPE(mysql_text_consumer_get_integer_v1) * get_integer_srv;
150 SERVICE_TYPE(mysql_text_consumer_get_longlong_v1) * get_longlong_srv;
151 SERVICE_TYPE(mysql_text_consumer_get_decimal_v1) * get_decimal_srv;
152 SERVICE_TYPE(mysql_text_consumer_get_double_v1) * get_double_srv;
153 SERVICE_TYPE(mysql_text_consumer_get_date_time_v1) * get_date_time_srv;
154 SERVICE_TYPE(mysql_text_consumer_get_string_v1) * get_string_srv;
155 SERVICE_TYPE(mysql_text_consumer_client_capabilities_v1) *
157};
158
159#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:142
const mysql_service_mysql_text_consumer_get_string_v1_t * get_string_srv
Definition: mysql_command_services_imp.h:154
const mysql_service_mysql_text_consumer_factory_v1_t * factory_srv
Definition: mysql_command_services_imp.h:144
const mysql_service_mysql_text_consumer_error_v1_t * error_srv
Definition: mysql_command_services_imp.h:147
const mysql_service_mysql_text_consumer_client_capabilities_v1_t * client_capabilities_srv
Definition: mysql_command_services_imp.h:156
const mysql_service_mysql_text_consumer_get_null_v1_t * get_null_srv
Definition: mysql_command_services_imp.h:148
const mysql_service_mysql_text_consumer_metadata_v1_t * metadata_srv
Definition: mysql_command_services_imp.h:145
const mysql_service_mysql_text_consumer_row_factory_v1_t * row_factory_srv
Definition: mysql_command_services_imp.h:146
const mysql_service_mysql_text_consumer_get_integer_v1_t * get_integer_srv
Definition: mysql_command_services_imp.h:149
const mysql_service_mysql_text_consumer_get_decimal_v1_t * get_decimal_srv
Definition: mysql_command_services_imp.h:151
const mysql_service_mysql_text_consumer_get_date_time_v1_t * get_date_time_srv
Definition: mysql_command_services_imp.h:153
const mysql_service_mysql_text_consumer_get_longlong_v1_t * get_longlong_srv
Definition: mysql_command_services_imp.h:150
const mysql_service_mysql_text_consumer_get_double_v1_t * get_double_srv
Definition: mysql_command_services_imp.h:152
An implementation of mysql command services apis.
Definition: mysql_command_services_imp.h:84
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:875
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:901
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:977
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:301
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:321
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:111
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:171
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:1001
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:853
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:99
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:749
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:772
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:91
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:830
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:1049
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:797
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:721
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:1024
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:925
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:151
static mysql_service_status_t field_metadata_get(MYSQL_FIELD_H field_h, int metadata, void *data) noexcept
Definition: mysql_command_services_imp.cc:1133
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:378
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:278
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:1120
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:1071
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:1093
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:951
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
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: instrumented_condition_variable.h:32
mode
Definition: file_handle.h:60
#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: mysql.h:339
Definition: mysql.h:299
Definition: mysql_command_services_imp.h:39
Definition: mysql_command_services_imp.h:43
MYSQL_RES * mysql_res
Definition: mysql_command_services_imp.h:44
This structure is used by mysql command service.
Definition: mysql_command_services_imp.h:60
bool is_thd_associated
Definition: mysql_command_services_imp.h:62
void * command_consumer_services
Definition: mysql_command_services_imp.h:65
const char * mcs_user_name
Definition: mysql_command_services_imp.h:69
MYSQL_SESSION session_svc
Definition: mysql_command_services_imp.h:61
const char * mcs_protocol
Definition: mysql_command_services_imp.h:68
SRV_CTX_H * consumer_srv_data
Definition: mysql_command_services_imp.h:66
const char * mcs_password
Definition: mysql_command_services_imp.h:71
uint32_t mcs_client_flag
Definition: mysql_command_services_imp.h:74
int mcs_tcpip_port
Definition: mysql_command_services_imp.h:72
MYSQL_THD mcs_thd
Definition: mysql_command_services_imp.h:67
MYSQL_DATA * data
Definition: mysql_command_services_imp.h:64
const char * mcs_host_name
Definition: mysql_command_services_imp.h:70
const char * mcs_db
Definition: mysql_command_services_imp.h:73