MySQL  8.0.19
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, 2019, 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 };
106 
107 /* "Constructor/destructor" for MYSQL extension structure. */
110 /*
111  Note: Allocated extension structure is freed in mysql_close_free()
112  called by mysql_close().
113 */
114 #define MYSQL_EXTENSION_PTR(H) \
115  ((MYSQL_EXTENSION *)((H)->extension \
116  ? (H)->extension \
117  : ((H)->extension = mysql_extension_init(H))))
118 
119 #define ASYNC_DATA(M) \
120  (NULL != (M) ? (MYSQL_EXTENSION_PTR(M)->mysql_async_context) : NULL)
121 #ifdef MYSQL_SERVER
123  MYSQL_EXTENSION_PTR(mysql)->server_extn = extn;
124 }
125 #endif
126 
128  char *plugin_dir;
130  char *ssl_crl; /* PEM CRL file */
131  char *ssl_crlpath; /* PEM directory of CRL-s? */
136  bool get_server_public_key; /* Former ssl_enforce */
137  char *tls_version; /* TLS version option */
138  long ssl_ctx_flags; /* SSL ctx options flag */
139  unsigned int ssl_mode;
140  unsigned int retry_count;
141  unsigned int ssl_fips_mode; /* SSL fips mode for enforced encryption.*/
147 };
148 
152  const unsigned char *header, size_t header_length,
153  const unsigned char *arg, size_t arg_length,
154  bool skip_check, MYSQL_STMT *stmt);
155  MYSQL_DATA *(*read_rows)(MYSQL *mysql, MYSQL_FIELD *mysql_fields,
156  unsigned int fields);
157  MYSQL_RES *(*use_result)(MYSQL *mysql);
158  void (*fetch_lengths)(unsigned long *to, MYSQL_ROW column,
159  unsigned int field_count);
160  void (*flush_use_result)(MYSQL *mysql, bool flush_all_results);
162 #if !defined(MYSQL_SERVER) && !defined(MYSQL_COMPONENT)
163  MYSQL_FIELD *(*list_fields)(MYSQL *mysql);
164  bool (*read_prepare_result)(MYSQL *mysql, MYSQL_STMT *stmt);
165  int (*stmt_execute)(MYSQL_STMT *stmt);
166  int (*read_binary_rows)(MYSQL_STMT *stmt);
167  int (*unbuffered_fetch)(MYSQL *mysql, char **row);
168  const char *(*read_statistics)(MYSQL *mysql);
169  bool (*next_result)(MYSQL *mysql);
170  int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
171  void (*free_rows)(MYSQL_DATA *cur);
172 #endif
176  const unsigned char *header, unsigned long header_length,
177  const unsigned char *arg, unsigned long arg_length, bool skip_check,
178  MYSQL_STMT *stmt, bool *error);
180  MYSQL_FIELD *mysql_fields,
181  unsigned int fields,
182  MYSQL_DATA **result);
184  bool flush_all_results);
187  ulong *res);
188 };
189 
190 #define simple_command(mysql, command, arg, length, skip_check) \
191  ((mysql)->methods \
192  ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
193  length, skip_check, NULL) \
194  : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
195  1))
196 #define simple_command_nonblocking(mysql, command, arg, length, skip_check, \
197  error) \
198  (*(mysql)->methods->advanced_command_nonblocking)( \
199  mysql, command, 0, 0, arg, length, skip_check, NULL, error)
200 
201 #define stmt_command(mysql, command, arg, length, stmt) \
202  ((mysql)->methods \
203  ? (*(mysql)->methods->advanced_command)(mysql, command, 0, 0, arg, \
204  length, 1, stmt) \
205  : (set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate), \
206  1))
207 
210  uint fields, bool default_value,
211  uint server_capabilities);
213  unsigned long field_count,
214  unsigned int fields);
215 MYSQL_FIELD *cli_read_metadata(MYSQL *mysql, unsigned long field_count,
216  unsigned int fields);
217 void free_rows(MYSQL_DATA *cur);
218 void free_old_query(MYSQL *mysql);
219 void end_server(MYSQL *mysql);
222  const char *filename, const char *group);
224  const unsigned char *header, size_t header_length,
225  const unsigned char *arg, size_t arg_length,
226  bool skip_check, MYSQL_STMT *stmt);
227 unsigned long cli_safe_read(MYSQL *mysql, bool *is_data_packet);
229  bool *is_data_packet,
230  ulong *res);
231 unsigned long cli_safe_read_with_ok(MYSQL *mysql, bool parse_ok,
232  bool *is_data_packet);
233 void net_clear_error(NET *net);
234 void set_stmt_errmsg(MYSQL_STMT *stmt, NET *net);
235 void set_stmt_error(MYSQL_STMT *stmt, int errcode, const char *sqlstate,
236  const char *err);
237 void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
238 void set_mysql_extended_error(MYSQL *mysql, int errcode, const char *sqlstate,
239  const char *format, ...)
240  MY_ATTRIBUTE((format(printf, 4, 5)));
241 
242 /* client side of the pluggable authentication */
243 struct MYSQL_PLUGIN_VIO_INFO;
244 
246 int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
247  const char *data_plugin, const char *db);
250 
252 
256 int is_file_or_dir_world_writable(const char *filepath);
257 void read_ok_ex(MYSQL *mysql, unsigned long len);
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 
263 #define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
264 
265 #endif /* SQL_COMMON_INCLUDED */
st_mysql_options_extention
Definition: sql_common.h:127
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:298
STATE_INFO_NODE::current_node
LIST * current_node
Definition: sql_common.h:75
MYSQL_ASYNC
Definition: mysql_async.h:166
st_mysql_options_extention::connection_attributes_length
size_t connection_attributes_length
Definition: sql_common.h:134
mysql_close_free_options
void mysql_close_free_options(MYSQL *mysql)
Definition: client.cc:6809
filepath
static const char * filepath
Definition: myisamlog.cc:91
net_clear_error
void net_clear_error(NET *net)
Clear possible error state of struct NET.
Definition: client.cc:329
default_client_charset_info
CHARSET_INFO * default_client_charset_info
Definition: client.cc:212
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:1246
cli_read_metadata_ex
MYSQL_FIELD * cli_read_metadata_ex(MYSQL *mysql, MEM_ROOT *alloc, unsigned long field_count, unsigned int fields)
Read metadata resultset from server Memory allocated in a given allocator root.
Definition: client.cc:2596
MYSQL_FIELD
Definition: mysql.h:120
read_ok_ex
void read_ok_ex(MYSQL *mysql, unsigned long len)
Read Ok packet along with the server state change information.
Definition: client.cc:750
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:346
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:3902
MYSQL_METHODS::read_query_result
bool(* read_query_result)(MYSQL *mysql)
Definition: sql_common.h:150
st_mysql_options_extention::total_configured_compression_algorithms
unsigned int total_configured_compression_algorithms
Definition: sql_common.h:144
MYSQL_METHODS
Definition: sql_common.h:149
mysql_extension_free
void mysql_extension_free(MYSQL_EXTENSION *)
Definition: client.cc:3242
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:1226
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:131
st_mysql_client_plugin
Definition: client_plugin.h:104
free_rows
void free_rows(MYSQL_DATA *cur)
Definition: client.cc:1275
MYSQL_METHODS::read_query_result_nonblocking
enum net_async_status(* read_query_result_nonblocking)(MYSQL *mysql)
Definition: sql_common.h:173
mysql.h
MYSQL_RES
Definition: mysql.h:335
mysql_client_plugin_init
int mysql_client_plugin_init()
Initializes the client plugin layer.
Definition: client_plugin.cc:318
STATE_INFO_NODE
The structure is used to hold the state change information received from the server.
Definition: sql_common.h:72
st_mysql_options_extention::ssl_mode
unsigned int ssl_mode
Definition: sql_common.h:139
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:1139
MYSQL_METHODS::flush_use_result_nonblocking
enum net_async_status(* flush_use_result_nonblocking)(MYSQL *mysql, bool flush_all_results)
Definition: sql_common.h:183
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:1117
st_mysql_options_extention::enable_cleartext_plugin
bool enable_cleartext_plugin
Definition: sql_common.h:135
MYSQL_METHODS::read_change_user_result_nonblocking
enum net_async_status(* read_change_user_result_nonblocking)(MYSQL *mysql, ulong *res)
Definition: sql_common.h:186
not_error_sqlstate
const char * not_error_sqlstate
Definition: client.cc:199
mysql_read_default_options
void mysql_read_default_options(struct st_mysql_options *options, const char *filename, const char *group)
Definition: client.cc:2059
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:200
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:136
st_mysql_options_extention::server_public_key_path
char * server_public_key_path
Definition: sql_common.h:133
st_mysql_options_extention::tls_version
char * tls_version
Definition: sql_common.h:137
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:198
mysql
static MYSQL mysql
Definition: mysql.cc:152
MYSQL_EXTENSION
Definition: sql_common.h:96
NET_SERVER
Definition: mysql_com_server.h:58
my_list.h
dd::info_schema::options
static const Query_options options
Definition: show_query_builder.cc:48
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:129
MYSQL_ROWS
Definition: mysql.h:152
my_inttypes.h
st_mysql_options_extention::zstd_compression_level
unsigned int zstd_compression_level
Definition: sql_common.h:145
st_mysql_options_extention::ssl_fips_mode
unsigned int ssl_fips_mode
Definition: sql_common.h:141
MEM_ROOT
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
MYSQL_STMT
Definition: mysql.h:666
MYSQL_METHODS::next_result_nonblocking
enum net_async_status(* next_result_nonblocking)(MYSQL *mysql)
Definition: sql_common.h:185
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
end_server
void end_server(MYSQL *mysql)
Definition: client.cc:1800
mysql_extension_init
MYSQL_EXTENSION * mysql_extension_init(MYSQL *)
Definition: client.cc:3225
mysql_reconnect
bool mysql_reconnect(MYSQL *mysql)
Definition: client.cc:6526
uchar
unsigned char uchar
Definition: my_inttypes.h:51
NET
Definition: mysql_com.h:851
command
command
Definition: version_token.cc:278
SESSION_TRACK_END
#define SESSION_TRACK_END
End of enum_session_state_type.
Definition: mysql_com.h:1002
LIST
Definition: my_list.h:35
st_mysql_options_extention::connection_attributes
struct My_hash * connection_attributes
Definition: sql_common.h:132
bool
#define bool
Definition: config_static.h:42
libmysql_cleartext_plugin_enabled
bool libmysql_cleartext_plugin_enabled
Definition: client.cc:5218
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:174
MYSQL
Definition: mysql.h:295
st_mysql_options_extention::ssl_ctx_flags
long ssl_ctx_flags
Definition: sql_common.h:138
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:114
st_mysql_options_extention::connection_compressed
bool connection_compressed
Definition: sql_common.h:146
st_mysql_options_extention::plugin_dir
char * plugin_dir
Definition: sql_common.h:128
cli_read_metadata
MYSQL_FIELD * cli_read_metadata(MYSQL *mysql, unsigned long field_count, unsigned int fields)
Read metadata resultset from server.
Definition: client.cc:2679
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:130
mysql_extension_set_server_extn
void mysql_extension_set_server_extn(MYSQL *mysql, NET_SERVER *extn)
Definition: sql_common.h:122
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:140
MYSQL_METHODS::fetch_lengths
void(* fetch_lengths)(unsigned long *to, MYSQL_ROW column, unsigned int field_count)
Definition: sql_common.h:158
MYSQL_METHODS::read_change_user_result
int(* read_change_user_result)(MYSQL *mysql)
Definition: sql_common.h:161
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:1283
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:179
st_mysql_options_extention::compression_algorithm
char * compression_algorithm
Definition: sql_common.h:143
cli_safe_read
unsigned long cli_safe_read(MYSQL *mysql, bool *is_data_packet)
Read a packet from server.
Definition: client.cc:1271
ulong
unsigned long ulong
Definition: my_inttypes.h:48
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:221
privilege_status::error
@ error
mysql_com_server.h
result
struct result result
Definition: result.h:37
st_mysql_options_extention::tls_ciphersuites
char * tls_ciphersuites
Definition: sql_common.h:142
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:2457
mysql_client_plugin_deinit
void mysql_client_plugin_deinit()
Deinitializes the client plugin layer.
Definition: client_plugin.cc:358
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:1539
My_hash
Definition: client.cc:3898
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:151
mysql_close_free
void mysql_close_free(MYSQL *mysql)
Definition: client.cc:6853
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:5256
MYSQL_VIO
#define MYSQL_VIO
Definition: mysql_com.h:840
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:3871
MYSQL_METHODS::flush_use_result
void(* flush_use_result)(MYSQL *mysql, bool flush_all_results)
Definition: sql_common.h:160