MySQL  8.0.23
Source Code Documentation
sql_common.h
Go to the documentation of this file.
1 #ifndef SQL_COMMON_INCLUDED
2 #define SQL_COMMON_INCLUDED
3 
4 /* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License, version 2.0,
8  as published by the Free Software Foundation.
9 
10  This program is also distributed with certain software (including
11  but not limited to OpenSSL) that is licensed under separate terms,
12  as designated in a particular file or component or in included license
13  documentation. The authors of MySQL hereby grant you an additional
14  permission to link the program and your derivative works with the
15  separately licensed software that they have included with MySQL.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License, version 2.0, for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25 
26 #define SQL_COMMON_INCLUDED
27 
28 /**
29  @file include/sql_common.h
30 */
31 
32 #include <mysql.h>
33 #include <stddef.h>
34 #include <sys/types.h>
35 
36 #include "errmsg.h"
37 #include "my_command.h"
38 #include "my_compiler.h"
39 #include "my_inttypes.h"
40 #include "my_list.h"
41 #include "mysql_com.h"
42 #ifdef MYSQL_SERVER
43 #include "mysql_com_server.h"
44 #endif
45 struct MEM_ROOT;
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 extern const char *unknown_sqlstate;
52 extern const char *cant_connect_sqlstate;
53 extern const char *not_error_sqlstate;
54 
55 /*
56  Free all memory allocated in MYSQL handle except the
57  current options.
58 */
60 
61 /*
62  Clear connection options stored in MYSQL handle and
63  free memory used by them.
64 */
66 
67 /**
68  The structure is used to hold the state change information
69  received from the server. LIST functions are used for manipulation
70  of the members of the structure.
71 */
73  /** head_node->data is a LEX_STRING which contains the variable name. */
76 };
77 
78 /**
79  Store the change info received from the server in an array of linked lists
80  with STATE_INFO_NODE elements (one per state type).
81 */
82 struct STATE_INFO {
83  /** Array of STATE_NODE_INFO elements (one per state type). */
85 };
86 
87 /*
88  Access to MYSQL::extension member.
89 
90  Note: functions mysql_extension_{init,free}() are defined
91  in client.c.
92 */
93 
94 struct st_mysql_trace_info;
95 
97  struct st_mysql_trace_info *trace_data;
99  /* Struct to track the state of asynchronous operations */
101 #ifdef MYSQL_SERVER
102  // Used by replication to pass around compression context data.
104 #endif
105  struct {
107  char **names;
110 };
111 
112 /* "Constructor/destructor" for MYSQL extension structure. */
115 /* cleanup for the MYSQL extension bind structure */
117 /*
118  Note: Allocated extension structure is freed in mysql_close_free()
119  called by mysql_close().
120 */
121 #define MYSQL_EXTENSION_PTR(H) \
122  ((MYSQL_EXTENSION *)((H)->extension \
123  ? (H)->extension \
124  : ((H)->extension = mysql_extension_init(H))))
125 
126 #define ASYNC_DATA(M) \
127  (NULL != (M) ? (MYSQL_EXTENSION_PTR(M)->mysql_async_context) : NULL)
128 #ifdef MYSQL_SERVER
130  MYSQL_EXTENSION_PTR(mysql)->server_extn = extn;
131 }
132 #endif
133 
135  char *plugin_dir;
137  char *ssl_crl; /* PEM CRL file */
138  char *ssl_crlpath; /* PEM directory of CRL-s? */
143  bool get_server_public_key; /* Former ssl_enforce */
144  char *tls_version; /* TLS version option */
145  long ssl_ctx_flags; /* SSL ctx options flag */
146  unsigned int ssl_mode;
147  unsigned int retry_count;
148  unsigned int ssl_fips_mode; /* SSL fips mode for enforced encryption.*/
155 };
156 
160  const unsigned char *header, size_t header_length,
161  const unsigned char *arg, size_t arg_length,
162  bool skip_check, MYSQL_STMT *stmt);
163  MYSQL_DATA *(*read_rows)(MYSQL *mysql, MYSQL_FIELD *mysql_fields,
164  unsigned int fields);
165  MYSQL_RES *(*use_result)(MYSQL *mysql);
166  void (*fetch_lengths)(unsigned long *to, MYSQL_ROW column,
167  unsigned int field_count);
168  void (*flush_use_result)(MYSQL *mysql, bool flush_all_results);
170 #if !defined(MYSQL_SERVER) && !defined(MYSQL_COMPONENT)
171  MYSQL_FIELD *(*list_fields)(MYSQL *mysql);
172  bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
173  int (*stmt_execute)(MYSQL_STMT *stmt);
174  int (*read_binary_rows)(MYSQL_STMT *stmt);
175  int (*unbuffered_fetch)(MYSQL *mysql, char **row);
176  const char *(*read_statistics)(MYSQL *mysql);
177  bool (*next_result)(MYSQL *mysql);
178  int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
179  void (*free_rows)(MYSQL_DATA *cur);
180 #endif
184  const unsigned char *header, unsigned long header_length,
185  const unsigned char *arg, unsigned long arg_length, bool skip_check,
186  MYSQL_STMT *stmt, bool *error);
188  MYSQL_FIELD *mysql_fields,
189  unsigned int fields,
190  MYSQL_DATA **result);
192  bool flush_all_results);
195  ulong *res);
196 };
197 
198 #define simple_command(mysql, command, arg, length, skip_check) \
199  ((mysql)->methods \
200  ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
201  length, skip_check, NULL) \
202  : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
203  1))
204 #define simple_command_nonblocking(mysql, command, arg, length, skip_check, \
205  error) \
206  (*(mysql)->methods->advanced_command_nonblocking)( \
207  mysql, command, 0, 0, arg, length, skip_check, NULL, error)
208 
209 #define stmt_command(mysql, command, arg, length, stmt) \
210  ((mysql)->methods \
211  ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
212  length, 1, stmt) \
213  : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
214  1))
215 
218  uint fields, bool default_value,
219  uint server_capabilities);
221  unsigned long field_count,
222  unsigned int fields);
223 MYSQL_FIELD *cli_read_metadata(MYSQL *mysql, unsigned long field_count,
224  unsigned int fields);
225 void free_rows(MYSQL_DATA *cur);
226 void free_old_query(MYSQL *mysql);
227 void end_server(MYSQL *mysql);
230  const char *filename, const char *group);
232  const unsigned char *header, size_t header_length,
233  const unsigned char *arg, size_t arg_length,
234  bool skip_check, MYSQL_STMT *stmt);
235 unsigned long cli_safe_read(MYSQL *mysql, bool *is_data_packet);
237  bool *is_data_packet,
238  ulong *res);
239 unsigned long cli_safe_read_with_ok(MYSQL *mysql, bool parse_ok,
240  bool *is_data_packet);
241 void net_clear_error(NET *net);
242 void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net);
243 void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate,
244  const char *err);
245 void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
246 void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate,
247  const char *format, ...)
248  MY_ATTRIBUTE((format(printf, 4, 5)));
249 
250 /* client side of the pluggable authentication */
251 struct MYSQL_PLUGIN_VIO_INFO;
252 
254 int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
255  const char *data_plugin, const char *db);
258 
260 
264 int is_file_or_dir_world_writable(const char *filepath);
265 void read_ok_ex(MYSQL *mysql, unsigned long len);
266 
267 bool fix_param_bind(MYSQL_BIND *param, uint idx);
268 bool mysql_int_serialize_param_data(NET *net, unsigned int param_count,
269  MYSQL_BIND *params, const char **names,
270  unsigned long n_param_sets,
271  uchar **ret_data, ulong *ret_length,
272  uchar send_types_to_server,
273  bool send_named_params,
274  bool send_parameter_set_count);
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 
280 #define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
281 
282 #endif /* SQL_COMMON_INCLUDED */
st_mysql_options_extention
Definition: sql_common.h:134
MYSQL_EXTENSION::trace_data
struct st_mysql_trace_info * trace_data
Definition: sql_common.h:97
set_mysql_error
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
Set the internal error message to mysql handler.
Definition: client.cc:299
STATE_INFO_NODE::current_node
LIST * current_node
Definition: sql_common.h:75
MYSQL_ASYNC
Definition: mysql_async.h:211
st_mysql_options_extention::connection_attributes_length
size_t connection_attributes_length
Definition: sql_common.h:141
mysql_close_free_options
void mysql_close_free_options(MYSQL *mysql)
Definition: client.cc:6848
filepath
static const char * filepath
Definition: myisamlog.cc:93
net_clear_error
void net_clear_error(NET *net)
Clear possible error state of struct NET.
Definition: client.cc:330
default_client_charset_info
CHARSET_INFO * default_client_charset_info
Definition: client.cc:213
set_stmt_errmsg
void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net)
Set statement error code, sqlstate, and error message from NET.
Definition: libmysql.cc:1249
cli_read_metadata_ex
MYSQL_FIELD * cli_read_metadata_ex(MYSQL *mysql, MEM_ROOT *alloc, unsigned long field_count, unsigned int fields)
MYSQL_FIELD
Definition: mysql.h:120
read_ok_ex
void read_ok_ex(MYSQL *mysql, unsigned long len)
my_compiler.h
set_mysql_extended_error
void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate, const char *format,...)
Set an error message on the client.
Definition: client.cc:347
MYSQL_ROW
char ** MYSQL_ROW
Definition: mysql.h:144
CHARSET_INFO
Definition: m_ctype.h:354
send_client_connect_attrs
uchar * send_client_connect_attrs(MYSQL *mysql, uchar *buf)
Definition: client.cc:3856
MYSQL_METHODS::read_query_result
bool(* read_query_result)(MYSQL *mysql)
Definition: sql_common.h:158
st_mysql_options_extention::total_configured_compression_algorithms
unsigned int total_configured_compression_algorithms
Definition: sql_common.h:151
MYSQL_METHODS
Definition: sql_common.h:157
mysql_extension_free
void mysql_extension_free(MYSQL_EXTENSION *)
Definition: client.cc:3223
set_stmt_error
void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate, const char *err)
Set statement error code, sqlstate, and error message from given errcode and sqlstate.
Definition: libmysql.cc:1229
STATE_INFO
Store the change info received from the server in an array of linked lists with STATE_INFO_NODE eleme...
Definition: sql_common.h:82
st_mysql_options_extention::ssl_crlpath
char * ssl_crlpath
Definition: sql_common.h:138
st_mysql_client_plugin
Definition: client_plugin.h:106
free_rows
void free_rows(MYSQL_DATA *cur)
Definition: client.cc:1271
options
static const Query_options options
Definition: sql_show_processlist.cc:65
MYSQL_METHODS::read_query_result_nonblocking
enum net_async_status(* read_query_result_nonblocking)(MYSQL *mysql)
Definition: sql_common.h:181
mysql.h
MYSQL_RES
Definition: mysql.h:336
mysql_client_plugin_init
int mysql_client_plugin_init()
Initializes the client plugin layer.
Definition: client_plugin.cc:319
STATE_INFO_NODE
The structure is used to hold the state change information received from the server.
Definition: sql_common.h:72
fix_param_bind
bool fix_param_bind(MYSQL_BIND *param, uint idx)
Definition: bind_params.cc:397
st_mysql_options_extention::ssl_mode
unsigned int ssl_mode
Definition: sql_common.h:146
cli_safe_read_with_ok
unsigned long cli_safe_read_with_ok(MYSQL *mysql, bool parse_ok, bool *is_data_packet)
Read a packet from server.
Definition: client.cc:1134
MYSQL_METHODS::flush_use_result_nonblocking
enum net_async_status(* flush_use_result_nonblocking)(MYSQL *mysql, bool flush_all_results)
Definition: sql_common.h:191
cli_safe_read_nonblocking
enum net_async_status cli_safe_read_nonblocking(MYSQL *mysql, bool *is_data_packet, ulong *res)
Its a non blocking version of cli_safe_read.
Definition: client.cc:1112
st_mysql_options_extention::enable_cleartext_plugin
bool enable_cleartext_plugin
Definition: sql_common.h:142
MYSQL_METHODS::read_change_user_result_nonblocking
enum net_async_status(* read_change_user_result_nonblocking)(MYSQL *mysql, ulong *res)
Definition: sql_common.h:194
not_error_sqlstate
const char * not_error_sqlstate
Definition: client.cc:200
mysql_read_default_options
void mysql_read_default_options(struct st_mysql_options *options, const char *filename, const char *group)
Definition: client.cc:2022
MYSQL_EXTENSION::mysql_async_context
struct MYSQL_ASYNC * mysql_async_context
Definition: sql_common.h:100
cant_connect_sqlstate
const char * cant_connect_sqlstate
Definition: client.cc:201
is_file_or_dir_world_writable
int is_file_or_dir_world_writable(const char *filepath)
Check if a file/dir is world-writable (only on non-Windows platforms)
Definition: my_path_permissions.cc:42
st_mysql_options_extention::get_server_public_key
bool get_server_public_key
Definition: sql_common.h:143
st_mysql_options_extention::server_public_key_path
char * server_public_key_path
Definition: sql_common.h:140
st_mysql_options_extention::tls_version
char * tls_version
Definition: sql_common.h:144
json_binary::err
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:908
unknown_sqlstate
const char * unknown_sqlstate
Definition: client.cc:199
mysql
static MYSQL mysql
Definition: mysql.cc:153
MYSQL_EXTENSION
Definition: sql_common.h:96
NET_SERVER
Definition: mysql_com_server.h:58
my_list.h
MYSQL_EXTENSION::bind
MYSQL_BIND * bind
Definition: sql_common.h:108
STATE_INFO::info_list
STATE_INFO_NODE info_list[SESSION_TRACK_END+1]
Array of STATE_NODE_INFO elements (one per state type).
Definition: sql_common.h:84
MYSQL_DATA
Definition: mysql.h:162
st_mysql_options_extention::default_auth
char * default_auth
Definition: sql_common.h:136
MYSQL_ROWS
Definition: mysql.h:152
MYSQL_EXTENSION::bind_info
struct MYSQL_EXTENSION::@6 bind_info
net
Definition: buffer.h:39
my_inttypes.h
st_mysql_options_extention::zstd_compression_level
unsigned int zstd_compression_level
Definition: sql_common.h:152
st_mysql_options_extention::ssl_fips_mode
unsigned int ssl_fips_mode
Definition: sql_common.h:148
MEM_ROOT
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
mysql_extension_bind_free
void mysql_extension_bind_free(MYSQL_EXTENSION *ext)
Definition: client.cc:3212
MYSQL_STMT
Definition: mysql.h:667
MYSQL_METHODS::next_result_nonblocking
enum net_async_status(* next_result_nonblocking)(MYSQL *mysql)
Definition: sql_common.h:193
MYSQL_PLUGIN_VIO_INFO
Definition: plugin_auth_common.h:115
errmsg.h
uint
unsigned int uint
Definition: uca-dump.cc:29
mysql_com.h
my_command.h
mysql_int_serialize_param_data
bool mysql_int_serialize_param_data(NET *net, unsigned int param_count, MYSQL_BIND *params, const char **names, unsigned long n_param_sets, uchar **ret_data, ulong *ret_length, uchar send_types_to_server, bool send_named_params, bool send_parameter_set_count)
Serialize the query parameters.
Definition: bind_params.cc:302
end_server
void end_server(MYSQL *mysql)
Definition: client.cc:1805
mysql_extension_init
MYSQL_EXTENSION * mysql_extension_init(MYSQL *)
Definition: client.cc:3192
mysql_reconnect
bool mysql_reconnect(MYSQL *mysql)
Definition: client.cc:6559
uchar
unsigned char uchar
Definition: my_inttypes.h:51
NET
Definition: mysql_com.h:879
command
command
Definition: version_token.cc:278
SESSION_TRACK_END
#define SESSION_TRACK_END
End of enum_session_state_type.
Definition: mysql_com.h:1030
LIST
Definition: my_list.h:35
st_mysql_options_extention::connection_attributes
struct My_hash * connection_attributes
Definition: sql_common.h:139
buf
Definition: buf0block_hint.cc:29
bool
#define bool
Definition: config_static.h:42
libmysql_cleartext_plugin_enabled
bool libmysql_cleartext_plugin_enabled
Definition: client.cc:5185
MYSQL_METHODS::advanced_command_nonblocking
enum net_async_status(* advanced_command_nonblocking)(MYSQL *mysql, enum enum_server_command command, const unsigned char *header, unsigned long header_length, const unsigned char *arg, unsigned long arg_length, bool skip_check, MYSQL_STMT *stmt, bool *error)
Definition: sql_common.h:182
MYSQL
Definition: mysql.h:296
st_mysql_options_extention::ssl_ctx_flags
long ssl_ctx_flags
Definition: sql_common.h:145
STATE_INFO_NODE::head_node
LIST * head_node
head_node->data is a LEX_STRING which contains the variable name.
Definition: sql_common.h:74
MYSQL_EXTENSION_PTR
#define MYSQL_EXTENSION_PTR(H)
Definition: sql_common.h:121
st_mysql_options_extention::connection_compressed
bool connection_compressed
Definition: sql_common.h:153
st_mysql_options_extention::plugin_dir
char * plugin_dir
Definition: sql_common.h:135
cli_read_metadata
MYSQL_FIELD * cli_read_metadata(MYSQL *mysql, unsigned long field_count, unsigned int fields)
net_async_status
net_async_status
Definition: plugin_auth_common.h:130
st_mysql_options_extention::ssl_crl
char * ssl_crl
Definition: sql_common.h:137
mysql_extension_set_server_extn
void mysql_extension_set_server_extn(MYSQL *mysql, NET_SERVER *extn)
Definition: sql_common.h:129
MYSQL_EXTENSION::state_change
STATE_INFO state_change
Definition: sql_common.h:98
st_mysql_options_extention::retry_count
unsigned int retry_count
Definition: sql_common.h:147
MYSQL_METHODS::fetch_lengths
void(* fetch_lengths)(unsigned long *to, MYSQL_ROW column, unsigned int field_count)
Definition: sql_common.h:166
MYSQL_METHODS::read_change_user_result
int(* read_change_user_result)(MYSQL *mysql)
Definition: sql_common.h:169
cli_advanced_command
bool cli_advanced_command(MYSQL *mysql, enum enum_server_command command, const unsigned char *header, size_t header_length, const unsigned char *arg, size_t arg_length, bool skip_check, MYSQL_STMT *stmt)
Definition: client.cc:1279
st_mysql_options_extention::load_data_dir
char * load_data_dir
Definition: sql_common.h:154
MYSQL_METHODS::read_rows_nonblocking
enum net_async_status(* read_rows_nonblocking)(MYSQL *mysql, MYSQL_FIELD *mysql_fields, unsigned int fields, MYSQL_DATA **result)
Definition: sql_common.h:187
st_mysql_options_extention::compression_algorithm
char * compression_algorithm
Definition: sql_common.h:150
cli_safe_read
unsigned long cli_safe_read(MYSQL *mysql, bool *is_data_packet)
Read a packet from server.
Definition: client.cc:1267
MYSQL_EXTENSION::names
char ** names
Definition: sql_common.h:107
MYSQL_EXTENSION::server_extn
NET_SERVER * server_extn
Definition: sql_common.h:103
mpvio_info
void mpvio_info(MYSQL_VIO vio, MYSQL_PLUGIN_VIO_INFO *info)
st_mysql_options
Definition: mysql.h:222
privilege_status::error
@ error
mysql_com_server.h
MYSQL_EXTENSION::n_params
uint n_params
Definition: sql_common.h:106
result
struct result result
Definition: result.h:33
st_mysql_options_extention::tls_ciphersuites
char * tls_ciphersuites
Definition: sql_common.h:149
unpack_fields
MYSQL_FIELD * unpack_fields(MYSQL *mysql, MYSQL_ROWS *data, MEM_ROOT *alloc, uint fields, bool default_value, uint server_capabilities)
Definition: client.cc:2407
mysql_client_plugin_deinit
void mysql_client_plugin_deinit()
Deinitializes the client plugin layer.
Definition: client_plugin.cc:359
enum_server_command
enum_server_command
A list of all MySQL protocol commands.
Definition: my_command.h:47
free_old_query
void free_old_query(MYSQL *mysql)
Definition: client.cc:1544
My_hash
Definition: client.cc:3852
info
Log info(cout, "NOTE")
MYSQL_METHODS::advanced_command
bool(* advanced_command)(MYSQL *mysql, enum enum_server_command command, const unsigned char *header, size_t header_length, const unsigned char *arg, size_t arg_length, bool skip_check, MYSQL_STMT *stmt)
Definition: sql_common.h:159
mysql_close_free
void mysql_close_free(MYSQL *mysql)
Definition: client.cc:6890
MYSQL_BIND
Definition: mysql.h:640
run_plugin_auth
int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, const char *data_plugin, const char *db)
Client side of the plugin driver authentication.
Definition: client.cc:5223
MYSQL_VIO
#define MYSQL_VIO
Definition: mysql_com.h:866
filename
const char * filename
Definition: pfs_example_component_population.cc:64
mysql_client_builtins
struct st_mysql_client_plugin * mysql_client_builtins[]
Definition: client.cc:3827
MYSQL_METHODS::flush_use_result
void(* flush_use_result)(MYSQL *mysql, bool flush_all_results)
Definition: sql_common.h:168